//-----------------------------------------------------------------------------//
//-------------------------------- MENU STEP ------------------------------//
//-----------------------------------------------------------------------------//
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)
{
	var rvs_is_ie = document.all? true: false;
	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() 
	{
		alert(msgChLang);		
		
		document.forms[0].submit();
		var FrmName = document.getElementById("FrmCreate");
		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 +"/'");

	}
	
	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;
  		}
	}
//-----------------------------------------------------------------------------//
//--------------------------------  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') {
	  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;
	}

	  hiddenFields = "ColorGroupId/" + NavId.value + "/" + hiddenFields + "/rvMoveImage/1/"+getRequstPositionLink();	
  	  eval(targ+".location='" + rvsPreviewUrl + sessID + hiddenFields +"/"+ selObj.name + "/" + selObj.options[selObj.selectedIndex].value+"'");
  	  if (restore) selObj.selectedIndex=0;

}

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 MM_goToURL() { //v3.0
  var NavId = document.getElementById('colorGroupNavId');  
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  hiddenFields = "ColorGroupId/" + NavId.value + "/picture_id/" + document.JumpBox.picture_id.value + "/font_id/" + document.JumpBox.font_id.value + "/navigator_name_id/" + document.JumpBox.navigator_name_id.value;
   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";
}

//-----------------------------------------------------------------------------//
//--------------------------------  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, Location, 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="+Location+", 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' , '');
		}
	}

//-----------------------------------------------------------------------------//
//------------------------ 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 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 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)
{
	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";}
	}
}

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');
     }
        
     document.getElementById('td_' + nameId).setAttribute('class','current');
     document.getElementById('td_' + nameId).setAttribute('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;
    }
    
    //End DiyTemplate System

document.onmousemove=positiontip;
