
//-----------------------------------------------------------------------------//
//-------------------------------- MENU STEP ------------------------------//
//-----------------------------------------------------------------------------//
function redirectCountDown( sec , url , setID){
if (!sec) {
window.location = url;
}else {
sec-=1;
        if (setID) {
            document.getElementById(setID).innerHTML = sec;
            setTimeout("redirectCountDown( "+sec+" , '"+url+"' , '"+setID+"')" , 1000);
        }else {
         setTimeout("redirectCountDown( "+sec+" , '"+url+"')" , 1000);
        }
    }
}
function disPlayOnOff(DisplayID){
DisplayID = document.getElementById(DisplayID);
	DisplayID.style.display =  (DisplayID.style.display == 'none') ? '' : 'none';
}
function hightlightRow(text,step)
{	
	var nextStepObj = document.getElementById('nextStep');
	var nextStep = nextStepObj.value;	 
	if(nextStep == 5){nextStep=7; }
	
	if(step == 'CreateStep'){StepElement = 1;}
	else if(step == 'DesignStep'){StepElement = 2;}  
	else if(step == 'StyleStep'){StepElement = 3;}  
	else if(step == 'PageStrucStep'){StepElement = 4;}  
	else if(step == 'SiteContentStep'){StepElement = 5;}  
	else if(step == 'ExtraStep'){StepElement = 6;}  
	else if(step == 'PublishStep'){StepElement = 7;}  
	
	if(nextStep >= StepElement){
		
	var txtStyleObj = document.getElementById(text);
	var stepStyleObj = document.getElementById(step);

	txtStyleObj.style.color = '#FF9000';
	stepStyleObj.style.color = '#004EFF';

	}
}

function unlightRow(text,step)
{	
	var txtStyleObj = document.getElementById(text);
	var stepStyleObj = document.getElementById(step);
	
	txtStyleObj.style.color = '';
	stepStyleObj.style.color = '';
}

function previewFocus(previewUrl)
{
	var isChange = dirtyFormWin();
	
	if(isChange){
		confPreview = confirm(txtConfPre);
		if(confPreview == true){
			openPreviewWin(previewUrl);
		}
		
	}
	else {
		openPreviewWin(previewUrl);
	}
	
}

function openPreviewWin(previewUrl,name)
{
	var rvs_is_ie = document.all? true: false;
	if (name){
	previewWin = window.open(previewUrl, name);
	}else{
	previewWin = window.open(previewUrl, 'previewWindow');
	}
	window.focus();
	if(rvs_is_ie){
		previewWin.resizeTo(window.screen.availWidth, window.screen.availHeight);
 		previewWin.moveTo(0, 0);	
	}
	
	previewWin.focus();
}
//-----------------------------------------------------------------------------//
//--------------------------------  STEP 1 -----------------------------------//
//-----------------------------------------------------------------------------//
	function changLang() 
	{
		windowAlertSetButton(msgChLang);
		
		//document.forms[0].submit();
		var FrmName = document.getElementById("FrmCreate");
		//start conpodb
		if (document.getElementById("frmCretaeDB") != null) {
			var dbHostName = document.getElementById("dbHostName").value;
			var dbProtocal = document.getElementById("dbProtocal").value;
			var dbName = document.getElementById("dbName").value;
			var dbUserName = document.getElementById("dbUserName").value;
			var dbPassword = document.getElementById("Password").value;
			 // var dbValue = "/dbHostName/"+dbHostName+"/dbProtocal/"+dbProtocal+"/dbName/"+dbName+"/dbUserName/"+dbUserName+"/Password/"+dbPassword;
			 var dbValue = "/compoDB[HostName]/"+dbHostName+"/compoDB[Port]/"+dbProtocal+"/compoDB[DatabaseName]/"+dbName+"/compoDB[UserName]/"+dbUserName+"/compoDB[Password]/"+dbPassword;
		} else {
			var dbValue = "";
		}
		//end conpodb
		
		var project_name = "project_name/" + FrmName.project_name.value;
		var project_company = "project_company/" + FrmName.project_company.value;
		var project_slogan = "project_slogan/" + FrmName.project_slogan.value;
		var project_title = "project_title/" + FrmName.project_title.value;
		var project_charset = "project_charset/" + FrmName.project_charset.value;
		var submit_action = "action/" + FrmName.action.value;
		var changLang = "changLang/1" + "/" + project_charset + "/" + submit_action;
		var values = project_name + "/" + project_company + "/" + project_slogan + "/" + project_title + "/" + changLang; 		
		eval("window.location='" + rvsUrl + values + dbValue +"/'");

	}
	
	function sloganBox()
	{
		var objSloganTextBox = document.getElementById('project_slogan');
		var objSloganLabel = document.getElementById('project_slogan_label');
		var noSlogan = document.getElementById('no_slogan');
		
		if(noSlogan.checked == true){
			objSloganTextBox.readOnly = true;
			objSloganTextBox.style.background = "#e2e2e2";
			objSloganLabel.style.color = "#e2e2e2";
		} else if(noSlogan.checked == false){
			objSloganTextBox.readOnly = false;
			objSloganTextBox.style.background = "#f9f9f9";
			objSloganLabel.style.color = "#000000";
		}
		
	}

	function companyBox()
	{
		var objCompanyTextBox = document.getElementById('project_company');
		var objCompanyLabel = document.getElementById('project_company_label');
		var noCompany = document.getElementById('no_company_name');
		
		if(noCompany.checked == true){
			objCompanyTextBox.readOnly = true;
			objCompanyTextBox.style.background = "#e2e2e2";
			objCompanyLabel.style.color = "#e2e2e2";
		} else if(noCompany.checked == false){
			objCompanyTextBox.readOnly = false;
			objCompanyTextBox.style.background = "#f9f9f9";
			objCompanyLabel.style.color = "#000000";
		}
		
	}
	
	function LogoBox()
	{
		var noLogo = document.getElementById('no_logo');
		var objLogo = document.getElementById('project_logo');
		var objLogoLabel = document.getElementById('project_logo_label');
		var objAutoResize = document.getElementById('autoresize_logo');
		var objAutoResizeLabel = document.getElementById('autoresize_logo_label');
		var objUploadButton = document.getElementById('btnUpload');
		
		if(noLogo.checked == true){
			 objLogo.disabled = true;
			 objLogo.style.background = "#e2e2e2";
			 objLogoLabel.style.color = "#e2e2e2";
			 objAutoResize.disabled = true;
			 objAutoResizeLabel.style.color = "#e2e2e2";
			 //objUploadButton.style.visibility = 'hidden';
		} else if(noLogo.checked == false){
			 objLogo.disabled = false;
			 objLogo.style.background = "#f9f9f9";
			 objLogoLabel.style.color = "#000000";
			 objAutoResize.disabled = false;
			 objAutoResizeLabel.style.color = "#000000";
			 //objUploadButton.style.visibility = 'visible';
		}
		
	}
//-----------------------------------------------------------------------------//
//--------------------------------  STEP 2 -----------------------------------//
//-----------------------------------------------------------------------------//
	function MM_jumpMenuStep2(targ,selObj,restore)
	{ 
	  	eval(targ+".location='" + rvsCategoryUrl + sessID + "select_category_id/"+selObj.options[selObj.selectedIndex].value+"/'");
	  	if (restore) selObj.selectedIndex=0;
	}
	
	function chImage(imgId,imgUrl, hrefLink)
	{
		if (document.getElementById(imgId)) {
			var objImg = document.getElementById(imgId);
			objImg.src = imgUrl;
		}				
		
		if (document.getElementById('alink' + imgId)) {
			var objLink = document.getElementById('alink' + imgId);
			objLink.href = hrefLink;
		}		
		
	}
	
	function chViewTemplateUrl(imgId, URL)
	{
	       if (document.getElementById('pview' + imgId)) {
            var pviewLink = document.getElementById('pview' + imgId)  ; 
            pviewLink.setAttribute("popview",URL);
         }
	}
   
	function confirmDelete(linkToDelete) {
		var checkConfirm = confirm('Are you sure to delete template ?');
 		if(checkConfirm == true)
  		{
			window.location = linkToDelete;
  		}
	}
	
	function MM_jumpMenu5(targ,selObj,restore){ //v3.0
	    eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	    if (restore) selObj.selectedIndex=0;
    }
//-----------------------------------------------------------------------------//
//--------------------------------  STEP 3 -----------------------------------//
//-----------------------------------------------------------------------------//
function MM_jumpMenu(targ,selObj,restore){ //v3.0
	var NavId = document.getElementById('colorGroupNavId');  
	hiddenFields = "color_id_hid/"+document.JumpBox.color_id_hid.value;
	if (selObj.name != 'picture_id') {
	  for (i=0;i<document.JumpBox.picture_id.length;i++) {
     	 if (document.JumpBox.picture_id[i].checked) {
     	 	hiddenFields = hiddenFields + "/picture_id/"+document.JumpBox.picture_id[i].value;
     	 	break;
      	 }
      }
	  //hiddenFields = hiddenFields + "/picture_id/"+document.JumpBox.picture_id.value;
	}
	if (selObj.name != 'font_id') {
	  hiddenFields = hiddenFields + "/font_id/"+document.JumpBox.font_id.value;
	}
	if (selObj.name != 'navigator_name_id') {
	  hiddenFields = hiddenFields + "/navigator_name_id/"+document.JumpBox.navigator_name_id.value;
	}
	if (selObj.name != 'position_id') {
      hiddenFields = hiddenFields + "/position_id/"+document.JumpBox.position_id.value;
    }
    if (selObj.name != 'resolution_id') {
      hiddenFields = hiddenFields + "/resolution_id/"+document.JumpBox.resolution_id.value;
    } 
    //Option show or hide navigator 
    if (selObj.name != 'showHide') {
      for (i=0;i<document.JumpBox.showHide.length;i++) {
     	 if (document.JumpBox.showHide[i].checked) {
     	 	hiddenFields = hiddenFields + "/showHide/"+document.JumpBox.showHide[i].value;
     	 	break
      	 }
      }
    }  
    // End Option show or hide navigator
    
	  hiddenFields = "ColorGroupId/" + NavId.value + "/" + hiddenFields + "/rvMoveImage/1/"+getRequstPositionLink();	
	  if (selObj.type =='radio') {
	  //alert(targ+".location='" + rvsPreviewUrl + sessID + hiddenFields +"/"+ selObj.name + "/" + selObj.value+"'");
	  	eval(targ+".location='" + rvsPreviewUrl + sessID + hiddenFields +"/"+ selObj.name + "/" +selObj.value +"'");
	  } else {
	   //alert(targ+".location='" + rvsPreviewUrl + sessID + hiddenFields +"/"+ selObj.name + "/" + selObj.options[selObj.selectedIndex].value+"'");
  	   eval(targ+".location='" + rvsPreviewUrl + sessID + hiddenFields +"/"+ selObj.name + "/" + selObj.options[selObj.selectedIndex].value+"'");
  	  }  
  	  if (restore) selObj.selectedIndex=0;
  	  
  	  disableCheckBoxLogo();
}
//  set Drag And Drop step3
function disableCheckBoxLogo()
{
	document.getElementById('rvMoveLogo').disabled = true;
	document.getElementById('rvMoveCompany').disabled = true;
	document.getElementById('rvMoveSlogan').disabled = true;
}

function closeDefaultBorder()
{
rvMoveLogo = document.getElementById('rvMoveLogo');
rvMoveCompany = document.getElementById('rvMoveCompany');
rvMoveSlogan = document.getElementById('rvMoveSlogan');
parent.preview.defaultBorder('Layer1',rvMoveLogo.checked);
parent.preview.defaultBorder('Layer2',rvMoveCompany.checked);
parent.preview.defaultBorder('Layer3',rvMoveSlogan.checked);
}
//  set Drag And Drop step3
function getRequstPositionLink(){
      Layer1X = document.getElementById('Layer1X').value;
      Layer1Y = document.getElementById('Layer1Y').value;
      
      Layer2X = document.getElementById('Layer2X').value;
      Layer2Y = document.getElementById('Layer2Y').value;
     
      Layer3X = document.getElementById('Layer3X').value;
      Layer3Y = document.getElementById('Layer3Y').value;
      setLayerXY ="Layer1X/"+Layer1X+"/Layer1Y/"+Layer1Y+"/Layer2X/"+Layer2X+"/Layer2Y/"+Layer2Y+"/Layer3X/"+Layer3X+"/Layer3Y/"+Layer3Y;
      return setLayerXY; 
}
function edfaultBorderIf(ID , setClassName){
var setID = document.getElementById(ID);
//setID.setAttribute('class' , setClassName);
 setID.className = setClassName;
}

function switchDefaultClass(setid,setClassName,classPreviewHover){
loadIF = true;
//alert('loadIF-->'+loadIF)
edfaultBorderIf(setid,setClassName);
 try{
    preview.edfaultBorderIf(setid,classPreviewHover);
 }catch(e){}
}

function MM_goToURL() { //v3.0
  var NavId = document.getElementById('colorGroupNavId');  
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
   //define picture_id for radio
   //"/picture_id/" + document.JumpBox.picture_id.value
   for (i=0;i<document.JumpBox.picture_id.length;i++) {
     if (document.JumpBox.picture_id[i].checked) {
     var pictureValue = "/picture_id/"+document.JumpBox.picture_id[i].value;
     break;
     }
   }
   //define navigator showHide for radio
   for (i=0;i<document.JumpBox.showHide.length;i++) {
   	 if (document.JumpBox.showHide[i].checked) {
     var showHideVal = "/showHide/"+document.JumpBox.showHide[i].value;
     break;
     }
   }
   var resolutionVal = "/resolution_id/" + document.JumpBox.resolution_id.value;
   var positionVal = "/position_id/" + document.JumpBox.position_id.value;
   var fontVal = "/font_id/" + document.JumpBox.font_id.value;
   
   var navigatorNameVal = "/navigator_name_id/" + document.JumpBox.navigator_name_id.value;

   hiddenFields = "ColorGroupId/" + NavId.value + resolutionVal + positionVal + pictureValue  + showHideVal + fontVal + navigatorNameVal;
   eval(args[0]+".location='" + rvsPreviewUrl + sessID + hiddenFields + "/color_id/"+args[1]+"/rvMoveImage/1/"+getRequstPositionLink()+"'");
  
   document.JumpBox.color_id_hid.value = args[1];
}

function chageFrmTarget1() {
   document.JumpBox.action = rvsPreviewUrl + sessID;
   document.JumpBox.target = "preview";
   document.JumpBox.submit();
}

function chageFrmTarget2() {
   document.JumpBox.action = rvsSelectStyleUrl + sessID;
   document.JumpBox.target = "_top";
   document.JumpBox.action.value= "edit";
   document.JumpBox.submit();
}

function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent){
        while(1){
          curleft += obj.offsetLeft;
          if(!obj.offsetParent){
            break;}
          obj = obj.offsetParent;
        }
    }else if(obj.x)
        {
        curleft += obj.x;      
        }
    return curleft;
  }

  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent){
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent){
            break;}
          obj = obj.offsetParent;
          
        }
    }else if(obj.y){
        curtop += obj.y;
        }
    return curtop;
  }
  
function colordialog(id) {
	
	var NavIcon = document.getElementById('NavColorIcon');
	var colorPickerDiv = document.getElementById('colorPickerDiv');
	

    var posX = findPosX(NavIcon) ;
    var posY = findPosY(NavIcon) - 40;    
	colorPickerDiv.style.left = posX +'px'; 	
	colorPickerDiv.style.top = posY +'px';

	
	colorPickerDiv.style.visibility = 'visible';

}

function hidePicker(){
	var colorPickerDiv = document.getElementById('colorPickerDiv');
	colorPickerDiv.style.visibility = 'hidden';
}

function changeNavColor(targ,NavColorId,IconId){
  	var NavId = document.getElementById('colorGroupNavId');
  	var NavIcon = document.getElementById('NavColorIcon');  	  
	 NavId.value = NavColorId; 
	 hiddenFields = "color_id_hid/"+document.JumpBox.color_id_hid.value;
	 hiddenFields = hiddenFields + "/picture_id/"+document.JumpBox.picture_id.value;
	 hiddenFields = hiddenFields + "/font_id/"+document.JumpBox.font_id.value;
	 hiddenFields = hiddenFields + "/navigator_name_id/"+document.JumpBox.navigator_name_id.value;	
	 hiddenFields = hiddenFields + "/ColorGroupId/" + NavColorId;	 
 	
     eval(targ+".location='{makeUrl(##,#preview#,#sitebuilder#)}" + "{sessID}" +hiddenFields+"/"+"'");
	 NavIcon.src = "{webRoot}/colorID/colorbar.gif";
}

function reloadSide(){parent.bSubmitted=true;parent.location.reload();}
function reloadOpener(parentload){  
if (parentload) {
window.opener.reloadSide();
}  
    //opener.document.location.reload();
    window.close();
}
//-----------------------------------------------------------------------------//
//--------------------------------  STEP 4 -----------------------------------//
//-----------------------------------------------------------------------------//
	function openDialog(URL, height, width)
	{
       var valHeight = height;
       var valWidth = width;
       var setTop = (screen.height - valHeight) / 2;
       var setLeft = (screen.width - valWidth) / 2;
       window.open(URL ,"LinkOption", "width="+valWidth+", height="+valHeight+", left="+setLeft+", top="+setTop+", resizable=1, scrollbars=1");
    }
    
    function openDialogCenter(URL, Width, Height, ToolBar, Location2, StatusBar, MenuBar, Resizeable, ScrollBars)
    {
       var setLeft = (screen.width - Width) / 2;
       var setTop = (screen.height - Height) / 2;
       try{
            pop = window.open(URL ,"openDialogCenter", "width="+Width+", height="+Height+", left="+setLeft+", top="+setTop+", location="+Location2+", status="+StatusBar+", menubar="+MenuBar+", resizable="+Resizeable+", scrollbars="+ScrollBars+"");
            pop.focus();
       }catch(e){}
       }
//-----------------------------------------------------------------------------//
//--------------------------------  STEP 5 -----------------------------------//
//-----------------------------------------------------------------------------//
	function chPathwayClass(obj, tdId)
	{
		if(obj.checked == true) {
			document.getElementById(tdId).setAttribute('class' , 'group');
			document.getElementById(tdId).setAttribute('className' , 'group');
		} else {
			document.getElementById(tdId).setAttribute('class' , '');
			document.getElementById(tdId).setAttribute('className' , '');
		}
	}

	//---upload 
	function generateRow(webroot,url,current,subAction){
		var d=document.getElementById("divfile");
		var date=new Date();
		var spanName=date.getDate()+''+date.getMonth()+''+date.getHours()+''+date.getMinutes()+''+date.getSeconds();

		for(var i=1;i<5;i++){	
		d.innerHTML+="<form style=\"padding-bottom:3px;\" enctype=\"multipart/form-data\" method=\"post\" action=\""+url+"\" name=\"form\" id=\"form\" target=\""+spanName+i+"\">\r\n<span id=\""+spanName+i+"\">\r\n<input name=\"selFile\" id=\"selFile\" type=\"file\" size =\"40\" onchange=\"doSubmit('"+spanName+i+"','"+webroot+"',this.form)\" />\r\n<input name=\"overwrite\" id=\"overwrite\" type=\"hidden\" value=\"false\" />\r\n<input name=\"span\" id=\"span\" type=\"hidden\" value=\""+spanName+i+"\" />\r\n<input name=\"current_path\" value=\""+current+"\" type=\"hidden\" />\r\n<input name=\"frm[subAction]\" value=\"upLoad\" type=\"hidden\" />\r\n</span>\r\n</form>\r\n<iframe name=\""+spanName+i+"\" style=\"display:none\"></iframe>\r\n\r\n";
		}	
	}

	function displaySuccess(status,fName,fSize,loadto,webroot){
		var trv=document.getElementById(loadto);	
		trv.innerHTML="<br><img src=\""+webroot+"/images/uploadsuc.gif\" width=\"400\" height=\"15\"><br>Status : "+status+"<br>File Name : "+fName+"<br>File Size : "+fSize+" KB";
	}

	function doSubmit(loadto,webroot,form){
		var checkOverwrite=document.getElementById("checkOverwrite").checked;
		if (checkOverwrite == true) {
			form.overwrite.value="true";
		}else{
			form.overwrite.value="false";
		}
		form.submit();
		var trv=document.getElementById(loadto);	
		trv.innerHTML="<br><img src=\""+webroot+"/images/progressBar2.gif\" width=\"400\" height=\"15\"><br>Status : Uploading..";
	}



//-----------------------------------------------------------------------------//
//------------------------ ONLINE FORM :: STEP2 ------------------------//
//-----------------------------------------------------------------------------//
function chkListBox(selObj,idx){ 
	if ((selObj.options[selObj.selectedIndex].value == "listbox") || (selObj.options[selObj.selectedIndex].value == "radiobox")) {
		document.getElementById('seloption_' + idx).disabled = false;
		document.getElementById('seloption_' + idx).value = '1';
	} else {
		document.getElementById('seloption_' + idx).disabled = true;
		document.getElementById('seloption_' + idx).value = '';
	}
}

function chkSubmit(idx){
var error = 0;
/*
	for (i=0;i<idx;i++) {
		chk_title = "if (document.form1.fieldtitle_" + i + ".value == \"\") { error = 1 }";
		chk_name = "if (document.form1.fieldname_" + i + ".value == \"\") { error = 1 }";
		eval(chk_title);
		eval(chk_name);
	}
*/
	if (error > 0) {
		alert("You failed to correctly fill. Please re-enter again!");
		return false;
	} else {
		return true;
	}
}
function locationGo(obj,url){
obj.href = url;
//alert(obj.href)
//return url
}
function textReplace(entry,idx) {
	out = " "; 
	add = "_"; 
	temp = "" + entry; 
	while (temp.indexOf(out)>-1) {
		pos= temp.indexOf(out);
		temp = "" + (temp.substring(0, pos) + add + temp.substring((pos + out.length), temp.length));
	}
	document.getElementById('fieldname_'+idx).value = temp;

}

function chkNum(field,idx) {
	var valid = "0123456789";
	var temp;
	for (var i=0; i<field.value.length; i++) {
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") {
			alert("Invalid entry!  Only numbers are accepted!");
			document.getElementById('seloption_' + idx).value = '1';
			field.focus();
			field.select();
		}
	}

	if (field.value < 1) {
			alert("The value is not less than one.");
			document.getElementById('seloption_' + idx).value = '1';
			field.focus();
			field.select();
	}
}

//-----------------------------------------------------------------------------//
//------------------------------- TOOL TIPS -------------------------------//
//-----------------------------------------------------------------------------//
//Edit the informaiton between the quotes below with the path to your image.
var tooltipImagePath = SGL_JS_WEBROOT + "/themes/default/sitebuilder/images/tooltiparrow.gif";

function addwarning()
{
	var thealinks = document.getElementsByTagName("a");
	if (!thealinks) { return; }
	
	for(var x=0;x!=thealinks.length;x++){
				
		if(thealinks[x].className == "addToolTip" || thealinks[x].getAttribute("rel") == "addToolTip"){
		thealinks[x].setAttribute("tooltiptext",thealinks[x].title);
		thealinks[x].removeAttribute("title");
		thealinks[x].onmouseover=function gomouseover(){ddrivetip(this.getAttribute("tooltiptext"))};
		thealinks[x].onmouseout=function gomouseout(){hideddrivetip();};
		}
	}
}

var offsetfromcursorX=-7; //Customize x offset of tooltip
var offsetfromcursorY=23; //Customize y offset of tooltip

var offsetdivfrompointerX=13; //Customize x offset of tooltip DIV relative to pointer image
var offsetdivfrompointerY=13; //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).

document.write('<div id="theToolTip"></div>'); //write out tooltip DIV
document.write('<img style="visibility: hidden;" id="ToolTipPointer" src="'+tooltipImagePath+'">'); //write out pointer image

var ie=document.all;
var ns6=document.getElementById && !document.all;
var enabletip=false;
if (ie||ns6) {
	var tipobj=document.all? document.all["theToolTip"] : document.getElementById? document.getElementById("theToolTip") : "";
}

var pointerobj=document.all? document.all["ToolTipPointer"] : document.getElementById? document.getElementById("ToolTipPointer") : "";

function ietruebody()
{
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function ddrivetip(thetext, thewidth, thecolor)
{
	if (ns6||ie){
		if (typeof thewidth!=="undefined") {tipobj.style.width=thewidth+"px";}
		if (typeof thecolor!=="undefined" && thecolor!=="") {tipobj.style.backgroundColor=thecolor;}
		tipobj.innerHTML=thetext;
		enabletip=true;
		return false;
	}
}

function positiontip(e)
{
try{
	if (enabletip){
	var nondefaultpos=false;
	var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
	var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
	//Find out how close the mouse is to the corner of the window
	var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20;
	var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20;
	
	var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-e.clientX-offsetfromcursorX;
	var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY;
	
	var leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-1) : -1000;
	
	//if the horizontal distance isn't enough to accomodate the width of the context menu
	if (rightedge<tipobj.offsetWidth) {
		//move the horizontal position of the menu to the left by it's width
		tipobj.style.left=curX-tipobj.offsetWidth+"px";
		nondefaultpos=true;
	} else if (curX<leftedge)	{
			tipobj.style.left="5px";}
	else {
		//position the horizontal position of the menu where the mouse is positioned
		tipobj.style.left=curX+offsetfromcursorX-offsetdivfrompointerX+"px";
		pointerobj.style.left=curX+offsetfromcursorX+"px";
	}
		
	//same concept with the vertical position
	if (bottomedge<tipobj.offsetHeight) {
		tipobj.style.top=curY-tipobj.offsetHeight-offsetfromcursorY+"px";
		nondefaultpos=true;
	} else{
		tipobj.style.top=curY+offsetfromcursorY+offsetdivfrompointerY+"px";
		pointerobj.style.top=curY+offsetfromcursorY+"px";
	}
	tipobj.style.visibility="visible";
	if (!nondefaultpos) {
		pointerobj.style.visibility="visible";
	} else{
		pointerobj.style.visibility="hidden";}
	}
  } catch(e) {
  
  }
}

function hideddrivetip()
{
	if (ns6||ie) {
		enabletip=false;
		tipobj.style.visibility="hidden";
		pointerobj.style.visibility="hidden";
		tipobj.style.left="-1000px";
		tipobj.style.backgroundColor='';
		tipobj.style.width='';
	}
}

    //Star DiyTemplate System
    function diySwichBackground(bgName){
    // function this form = FrmDiyBackGroundStyle
    diybackId=eval("document.FrmDiyBackGroundStyle."+bgName);
   for (i = 0;i < diybackId.length;i++) {
   diybackId[i].checked=false;
   }
    }
    function diyCurrent(nameId) {
     classCurrent=document.getElementsByClassName('current');
     for (i = 0 ;i < classCurrent.length;i++) {
       //classCurrent[i].setAttribute('class','none_current');
      //  classCurrent[i].setAttribute('className','none_current');
        classCurrent[i].className='none_current';
     }
     //document.getElementById('td_' + nameId).setAttribute('class','current');
      //document.getElementById('td_' + nameId).setAttribute('className','current');
       document.getElementById('td_' + nameId).className='current';
    }
    
    function diyCheckSwichTemplate(template_item_id,menustyle_id,realColorSchem,layoutId){
        
       if (menustyle_id == 2) {
            mathmenuHor = layoutId.split('Hor');
            mathstyle = mathmenuHor.length;
            //alert(mathstyle+'hor')
       }
       if (menustyle_id == 1) {
            mathmenuVer = layoutId.split('Ver');
            mathstyle = mathmenuVer.length;
            //alert(mathstyle+'ver')
       }
        if (!realColorSchem || !menustyle_id || !layoutId || mathstyle ==1) {
       var valerror
            if (!realColorSchem) {
                valerror = 'color scheme';
            }
             if (!menustyle_id || mathstyle ==1) {
                valerror = 'template layout style';
            }
             if (!layoutId) {
                valerror = 'template layout style';
            }
             alert('Please select '+valerror);
            return false;
           
       } else {
          return true;
       }
    }
    function diyOpenPreview(URL, height, width)
    {
        
       //If send value color from GET '#' replace empty
       URL = URL.replace(/#/g, '');
       var valHeight = height;
       var valWidth = width;
       var setTop = (screen.height - valHeight) / 2;
       var setLeft = (screen.width - valWidth) / 2;
       
       var menustyle_id = document.getElementById('real_menustyle_id').value;
       var layoutId = document.getElementById('realLayout').value;
       
       var realColorSchem = document.getElementById('realColorSchem').value;
       var template_item_id = document.getElementById('template_item_id').value;
       var mathstyle;
       if (template_item_id) {
            URL = URL + "&template_item_id=" + template_item_id;
       }
       URL = URL + "&menustyle_id=" + menustyle_id + "&selectLayout=" + layoutId + "&selecColorSchem=" + realColorSchem;

      if (diyCheckSwichTemplate(template_item_id,menustyle_id,realColorSchem,layoutId)) {
        openPreview=window.open(URL ,"", "width="+valWidth+", height="+valHeight+", left="+setLeft+", top="+setTop+", resizable=1, scrollbars=1");
      }
    }
    
    function diyGetRealValues(idName, selectId)
    {
        var idName = idName;
        document.getElementById(idName).value = selectId;
    }
    
    
    /*
diy change color box 
*/
function changeColor(objCheckBox,objText) {
    objCheckBox = document.getElementById(objCheckBox);
    objText = document.getElementById(objText);
    //objText.value = (objCheckBox.checked) ? objText.value : null;
	   if (objCheckBox.checked) {
            objText.style.background =objText.value;
        } else {
            objText.style.background  = '';
        }
}
    
    function checkCustomColor(checkbox,text,hidden)
    {
        hidden =  document.getElementById(hidden);
        checkbox = document.getElementById(checkbox);
        text = document.getElementById(text);
        textValue = text.value.replace(/#/g, '');
   
        hidden.value = (checkbox.checked) ? textValue : ''; 
    }
    //End DiyTemplate System
    
    function actionAJExternalGet(url , endEval){
 new Ajax.Request( url, {
            method: 'post',
            onSuccess: function(transport) {
                                eval(endEval);
                            }           

	})
}
function getQuotaUser(url,divId ,msg , rvQuota){
endEval = "displayQuotaUser(transport,'"+divId+"' , '"+msg+"' , "+rvQuota+")";
 actionAJExternalGet(url , endEval);
}
function displayQuotaUser(transport , divId ,msg ,rvQuota){
getTagReturn = transport.responseText;
diskusage = /\<diskusage\>(.*)\<\/diskusage\>/i;
quotamax = /\<quotamax\>(.*)\<\/quotamax\>/i;
diskusageData = parseInt(getTagReturn.match(diskusage)[1]);
quotamaxData = parseInt(getTagReturn.match(quotamax)[1]);
usageDataPer = parseInt((diskusageData/quotamaxData)*100);
msgQuotaUse = msg+' '+diskusageData+'/'+quotamaxData+'M['+usageDataPer+'%]';
	if (usageDataPer >= rvQuota ){
		setOutputWarningBorder(divId , msgQuotaUse , 'WarningBorder_quotaUser');
	}
}

function switchEffectAttributeID(obj , valID, groupID,subGroup)
{
    groupID = document.getElementById(groupID);
   groupIDAttribute =groupID.getElementsByTagName('*');
   for(i=0;i<groupIDAttribute.length;i++){
        if (groupIDAttribute[i].getAttribute(subGroup)) {
                groupIDAttribute[i].setAttribute('id',groupIDAttribute[i].getAttribute(subGroup));
                groupIDAttribute[i].setAttribute('active','0');
        }
    }
if(obj != ''){
obj.setAttribute('id',valID);
obj.setAttribute('active','1');
}
}
function switchEffectAttribute(targetID , focusID , tagType, typeEffect , setClassName ,defaultClass) 
{	
	targetID = document.getElementById(targetID);
	targetIDAttribute =targetID.getElementsByTagName('*');
	for(i=0;i<targetIDAttribute.length;i++){
		if (targetIDAttribute[i].getAttribute(tagType)) {
			if (typeEffect == 'display') {
				targetIDAttribute[i].style.display = 'none';
			} else if (typeEffect == 'class') {
				targetIDAttribute[i].className=defaultClass;
			}
		}
	}
	if (typeEffect == 'display' && focusID != '') {
		document.getElementById(focusID).style.display = '';
	} else if (typeEffect == 'class' && focusID != '') {
		document.getElementById(focusID).className = setClassName;

	}
}

function setOutputWarningBorder(divId , msg ,type){
setDisplayError = document.getElementById(divId);
WarningBorder_q = document.getElementById(''+type);
setError = '<div id ="'+type+'" class="error" align="center"><table border="0" cellspacing="0" cellpadding="0"><tr><td>'+msg+'</td></tr></table></div>';
	if(WarningBorder_q == null) {
		if (setDisplayError.getElementsByClassName('warningBorder')[0] != null  ){
	   		 setDisplayError.getElementsByClassName('warningBorder')[0].innerHTML +=  setError;
		}else {
	   		 setDisplayError.innerHTML = '<div   class="warningBorder" style="margin-bottom: 5px; width:100%" align="center">'+setError+'</div>';
		}
	}else {
		WarningBorder_q.innerHTML =' <table border="0" cellspacing="0" cellpadding="0"><tr><td>'+msg+'</td></tr></table>';
	}
}
cacheTip = {};
mouseOverX = 0;
function getDataShortCut(url, cacheID , targetWidth)
{
	if(!cacheTip[cacheID]) {
    	  ajaxSubmitExtra(url , '' , 'showDataShortCut(#transport#,"'+cacheID+'","'+targetWidth+'")' , 'call_myjs');
	} else {
    	showDataShortCut(cacheTip[cacheID], cacheID, targetWidth);
	}
}

function showDataShortCut(tran, cacheID, targetWidth)
{
imgTarget = document.getElementById('img_'+cacheID);
	cacheTip[cacheID] = tran;
     if (imgTarget.innerHTML = cacheTip[cacheID]) { // valid isset and assign value   if(a = b)
	if(targetWidth){
   		imgWidth =  parseInt(targetWidth)+parseInt(mouseOverX);
     //	document.getElementById('debugShortCutMenuImageWidth').innerHTML = targetWidth
   		if (imgWidth > document.body.clientWidth) {
    	 	imgTarget.style.left = (parseInt(document.body.clientWidth) - parseInt(imgWidth)+(-20))+'px';
    		 }
     }
     	}
}

function ActiveIconsetId(thisDiv,valAtive){
   if(thisDiv.getAttribute('active') =='0'){
        thisDiv.id = valAtive;
  }  
}

function mouseShortCutMenu(e) {
  eTarget = document.all ? event.srcElement : e.target;
  mouseOverX= document.all ? event.clientX : e.clientX;
}
document.write('<div id="rvDivtooltip"  style="visibility: hidden;position:absolute;"></div>'); //write out tooltip DIV
function rvtooltip(e){
try{
eTarget = document.all ? event.srcElement : e.target;

//=== start edit error wysiwyg scroll bar onmousemove edit by darawan 23/06/2552 

 	var mouseOverX= document.all ? event.clientX+ietruebody().scrollLeft : e.pageX;
 	var mouseOverY= document.all ? event.clientY+ietruebody().scrollTop : e.pageY;
	/*
  	windowWid =  document.all?  document.body.clientWidth : window.innerWidth;
  	windowHid = document.all? document.body.clientHeight : window.innerHeight;
	var rightedge= windowWid - mouseOverX
	var bottomedge=windowHid - mouseOverY
 	*/
  	if(eTarget.getAttribute('tooltipid')) {
   	 //document.getElementById('test').innerHTML = mouseOverX +','+mouseOverY
  		if(eTarget.getAttribute('positionX')){
        	mouseOverX = parseInt(mouseOverX)+parseInt(eTarget.getAttribute('positionX'));
   		}
   		if(eTarget.getAttribute('positionY')){
       		mouseOverY = parseInt(mouseOverY)+parseInt(eTarget.getAttribute('positionY'));
   		}
     
  		document.getElementById('rvDivtooltip').style.left= parseInt(mouseOverX) +'px';
  		document.getElementById('rvDivtooltip').style.top = parseInt(mouseOverY)-parseInt(eTarget.offsetHeight)+50+'px';
  		document.getElementById('rvDivtooltip').style.visibility = 'visible';
  	}else{
        if(document.getElementById('rvDivtooltip')){
  	    document.getElementById('rvDivtooltip').style.visibility = 'hidden';
      	}
  	}
  }	catch(e){

  }

  //=== end edit error wysiwyg scroll bar onmousemove edit by darawan 23/06/2552 
}

function rvRegisToolTip(e){
try{
 eTarget = document.all ? event.srcElement : e.target;

  if(eTarget.getAttribute('tooltipid')) {
  	objgetAtr = eTarget.getAttribute('tooltipid');
  	rvtargetTip = document.getElementById(objgetAtr);
document.getElementById('rvDivtooltip').innerHTML = rvtargetTip.innerHTML;
  }
 } catch(e) {

 }
}
function setTimelightboxDeactivate(time) 
{
	//document.getElementById('formCDBloading').style.display ='none'
	setTimeout ( 'lightboxDeactivate()', time );
}

function makeViewLogIF(obj){

		var ifrmviewlogDIV = document.getElementById('ifrmviewlogDIV');
		var ifrmviewlog = '<iframe style="display:none" name="ifrmviewlog" id="ifrmviewlog" src ='+obj.getAttribute('hrefLog')+'></iframe>';
    	ifrmviewlogDIV.innerHTML = ifrmviewlog;

} 
function setRVPositionCenter(obj , objWidth,objHeight){
objWidth = (objWidth)? objWidth:0;
objHeight = (objHeight)? objHeight:0;
obj = document.getElementById(obj);
//document.documentElement.clientWidth;
wd =(((document.documentElement.clientWidth)/2)-(objWidth /2))+'px';
obj.style.left = '0px';
obj.style.left =  wd;
obj.style.top =  (((document.body.clientHeight)/2)-(objHeight /2))+'px';
obj.className = 'shortcuthelpOver';
}
var timeoutImage;
var snapStatus = 1;
setTout = {};
function setTimeSnapShort(func,obj){

setTout[obj] = setTimeout(func+'("'+obj+'")',1000);

}
function eventGen(val){
document.getElementById('eventGen').innerHTML += val;
}
function matchLTGT(strings){
strings = strings.replace(/\</gi ,'&lt;');
strings = strings.replace(/\>/gi ,'&gt;');
return   strings + ' ';
}
function clearTimeSnapShort(obj){
try{
clearTimeout(setTout[obj]);
}catch(e){}
}
function centerSnapshot(objDivSnap , objSpanSnap , width) {
	 cWidth = width/2;
	 objDivSnap = document.getElementById(objDivSnap);
	 objSpanSnap = document.getElementById(objSpanSnap);
	 objSpanSnap.style.left = ((parseInt(objDivSnap.parentNode.offsetWidth)/2)-cWidth) +'px';
	
}
function snapDisplayNone(obj){

document.getElementById(obj).className = 'shortcuthelp';
}
function snapDisplayNoneAll(){
tooltipComponent = document.getElementById('webuy-content');
objTag = tooltipComponent.getElementsByTagName('*');
	for(i=0;i<objTag.length;i++) {
		if(objTag[i].className == 'shortcuthelpOver') {
			objTag[i].className='shortcuthelp';
		}
	}

}
function snapShow(obj){
snapDisplayNoneAll();
if(obj && obj != 'end') {
	document.getElementById(obj).className = 'shortcuthelpOver';
	}

}
function viewLogLoad(a, b){
	document.getElementById(a).style.display = 'none';
	document.getElementById(b).style.display = '';
}

document.onmousemove = mousemoveAPI;
document.onmouseover = rvRegisToolTip;
// connect event header mouse move  this here 
function mousemoveAPI(e) {
mouseShortCutMenu(e);
positiontip(e);
rvtooltip(e);
} 

var userViewLogOpt;
UserViewLogConf = {
    initialize:function(){},
    viewlogsubmit:function(o) {
        loadingActivate();
        this.rvsAjaxExecute(o);
    },
    rvsAjaxExecute:function(o){
        var frmInput;
        //1. open dialog
        //2. set Sitebuilder Request Url
        if (o) {
            frmInput = get(o);
        } else {
            frmInput = '/';
        }
        
        new Ajax.Request( RVS_AJAX_INDEX, {
            method:'post',
            asynchronous:true,
            parameters: frmInput,
            encoding: 'UTF-8',
            
            onComplete: function(transport) {
            
                if (transport.status != 200) {
                    UserViewLogConf.viewlogFail(transport);
                }
            },
            onSuccess: function(transport) {
                UserViewLogConf.viewlogSuccess(transport);
            }
            
        });
    },
    viewlogSuccess:function(o) {
        lightboxDeactivate("windowconfigviewlog");
        userViewLogOpt = o.responseJSON;
     },
    viewlogFail:function(o){
	alert('eee')
    }
}

function setFormLog()
{
    if (!userViewLogOpt) {
        return ;
    }

    redioLog = document.getElementsByName('frmviewlog[log][enabled]');
    redioLog[userViewLogOpt['logstatus']].checked = true;
    logPriority = document.getElementsByName('frmviewlog[log][priority]')[0];
    try{
        eval("userViewLogOpt['priority'] = '" +userViewLogOpt['priority']+"';")
    } catch(e){
        userViewLogOpt['priority'] = userViewLogOpt['priority'].replace(/\\/gi ,'');
    }
    logPriority.value = userViewLogOpt['priority'];
}
//window.onscroll = scrollAPI;
function scrollAPI(e)
{
   //logPesterSrcoll(e);
}
