/*-----------------------------------------------------------------------------
-	File Name:
-		Google_Free_Custom_Adv.js
-
-	Description:
-		Functions for Customizable Google Free Search Advanced Mode.
-
-	This file contains proprietary and confidential information from WebAssist.com
-	corporation.  Any unauthorized reuse, reproduction, or modification without
-	the prior written consent of WebAssist.com is strictly prohibited.
-
-	Copyright 2004 WebAssist.com Corporation.  All rights reserved.
------------------------------------------------------------------------------*/
var CURRENTPAGE = 0;

var theOrig = "";
var updateVersion = false;


function commandButtons()     {
  return new Array();
}

function displayHelp()     {
  var thePage = "";
  switch (CURRENTPAGE)
  {
	default:
	  thePage = "gs_dw_10.htm";
	  break;
  }
  displayContextHelp(thePage);
}

/* Initialize the UI.  First thing that's called on the body load event. */
function initializeUI()     {
  MM.setBusyCursor();
  if (navigator.platform.toLowerCase().indexOf("mac") >= 0)     {
    document.background.document.tabBgWin.src = "../Shared/Google/FreeSearch/Images/AdvancedBG_Mac.gif";
	document.Tab0.document.tabBG.src = "../Shared/Google/FreeSearch/Images/longTabBg_Mac.gif";
	document.Tab0.style = "left:"+MACTAB0LEFT+"px; top:"+MACTABTOP+"px;";
	document.Tab1.document.tabBG.src = "../Shared/Google/FreeSearch/Images/TabBg_Mac.gif";
	document.Tab1.style = "left:"+MACTAB1LEFT+"px; top:"+MACTABTOP+"px;";
	document.Tab2.document.tabBG.src = "../Shared/Google/FreeSearch/Images/longTabBg_Mac.gif";
	document.Tab2.style = "left:"+MACTAB2LEFT+"px; top:"+MACTABTOP+"px;";

	//#173608 Tab label text is too low and looks truncated on the bottom on Mac Japanese. Move the top by a few pixels.
	document.Tab1.document.Tab1Label.style = "position:absolute;top:" + TABLABELTOP + "px;width:69px;height:1px;z-index:9;visibility:inherit; left:0px;text-align:center";
	document.Tab0.document.Tab0Label.style = "position:absolute; width:105px; height:1px; z-index:9; left: 0px; top: " + TABLABELTOP + "0px; visibility:inherit; text-align:center";
	document.Tab2.document.Tab2Label.style = "position:absolute; width:105px; height:1px; z-index:9; left: 0px; top: " + TABLABELTOP + "0px; visibility:inherit; text-align:center";
	
	document.background.style = "top:25px;";

	document.cancel.style = "position:absolute; width:65px; z-index:94; left: "+CANCELLEFT+"px; top: "+BUTTONTOP+"px; visibility: visible";
	document.cancel.document.btnCancel.style = "width:" + CANCELWIDTH + "; height:" + BUTTONHEIGHT + "; font-family:'"+MACFONT+"'; font-size: 10px";
    
	document.OK.style = "position:absolute;  width:55px; z-index:94; left: "+OKLEFT+"px; top: "+BUTTONTOP+"px; visibility: visible";
	document.OK.document.btnOK.style = "width:" + BUTTONWIDTH + "; height:" + BUTTONHEIGHT + "; font-family:'"+MACFONT+"'; font-size: 10px";
    
	document.help.style = "position:absolute; width:55px; z-index:94; left: "+HELPLEFT+"px; top: "+BUTTONTOP+"px; visibility: visible";
	document.help.document.btnHelp.style = "width:" + BUTTONWIDTH + "; height:" + BUTTONHEIGHT + "; font-family:'"+MACFONT+"'; font-size: 10px";
  
    document.walogo.top = 360;
	document.googlelogo.top = 361;
	}
  else
  {
    // Fix the background color for all radio buttons and checkboxes in windows
    document.DomainWP.document.searchRDO[0].style = "background-color: #e3e3e3;";
    document.DomainWP.document.searchRDO[1].style = "background-color: #e3e3e3;";
    document.DomainWP.document.safeSearchCHK.style = "background-color: #e3e3e3;";
  } 

  document.background.visibility = "visible";
  document.Tab0.visibility = "visible";
  document.Tab1.visibility = "visible";
  document.Tab2.visibility = "visible";
  document.OK.visibility = "visible";
  document.cancel.visibility = "visible";
  document.help.visibility = "visible";
  document.googlelogo.visibility = "visible";
  document.walogo.visibility = "visible";
  
  // Get values from the inspected node and populate our UI accordingly
  
  var theDOM = dreamweaver.getDocumentDOM();
  var theSelection = theDOM.getSelectedNode();
  var page1 = document.DomainWP.document;
  var page2 = document.LogoWP.document;
  var page3 = document.ColorWP.document;
  theOrig = theSelection.outerHTML;
  if (theOrig.indexOf("Google_Safe.gif") >= 0)  {
    page1.safeSearchCHK.checked = "checked";
  }

  var tempOrig = theOrig;
  var firstInput = findOpenTag(tempOrig,"input");
  while (firstInput != "")  {
	  var inputName = getTagProp(firstInput,"input","name");
	  var theVal = getTagProp(firstInput,"input","value");
	  switch (inputName.toLowerCase())  {
	    case "domains":
		  if (theVal != "")   {
		    page1.domains.value = theVal;
		    page1.searchRDO[1].checked = "checked";
		  }
		  break;
		case "cof":
		  if (theVal != "" && theVal.indexOf(";") >= 0)  {
		    var theMark  = "";
			var theSet   = "";
		    var cusArray = theVal.split(";");
			for (v = 0; v < cusArray.length; v++)  {
			  theMark = cusArray[v].substring(0, cusArray[v].indexOf(":"));
			  theSet  = trimLeft(trimRight(cusArray[v].substring(cusArray[v].indexOf(":") + 1)));
			  switch (trimLeft(trimRight(theMark.toUpperCase())))  {
			    case "L":
				  page2.logoURL.value = theSet;
				  break;
				case "LW":
				  page2.width.value = theSet;
				  break;
				case "LH":
				  page2.height.value = theSet;
				  break;
				case "AH":
				  var theAlignList = page2.logoAlignLST;      
			      for (var n=0; n<theAlignList.options.length; n++)  {
					if (theSet == theAlignList.options[n].value)  {
						theAlignList.selectedIndex = n;
						break;
					}
				  }
				  break;
				case "GL":
				  var theGBGList = page2.googleBGColorLST;
			      for (var i=0; i<theGBGList.options.length; i++)  {
					if (theSet == theGBGList.options[i].value)  {
						theGBGList.selectedIndex = i;
						break;
					}
				  }
				  break;
				case "BGC":
				  page3.bgColor.value = theSet;
				  page3.bgColorPick.value = theSet;
				  break;
				case "BIMG":
				  page3.bgURL.value = theSet;
				  break;
				case "T":
				  page3.textColor.value = theSet;
				  page3.textColorPick.value = theSet;
				  break;
				case "GALT":
				  page3.altColor.value = theSet;
				  page3.altColorPick.value = theSet;
				  break;
				case "GIMP":
				  page3.importantColor.value = theSet;
				  page3.importantColorPick.value = theSet;
				  break;
				case "GFNT":
				  page3.faintColor.value = theSet;
				  page3.faintColorPick.value = theSet;
				  break;
				case "LC":
				  page3.linkColor.value = theSet;
				  page3.linkColorPick.value = theSet;
				  break;
				case "ALC":
				  page3.activeColor.value = theSet;
				  page3.activeColorPick.value = theSet;
				  break;
				case "VLC":
				  page3.visitedColor.value = theSet;
				  page3.visitedColorPick.value = theSet;
				  break;
				default:
				  break;
			  }
			}
			
		  }
	    default:
		  break;
	  }
  tempOrig = tempOrig.substring(tempOrig.indexOf(firstInput)+firstInput.length); 
  firstInput = findOpenTag(tempOrig,"input");
  }
  
  switchPreview();

  showPageNum(0);
   
  MM.clearBusyCursor();
  
  return true;
}

function insertTag()    {
  var myErrors = validateUI();
  if (myErrors == "")
  {
    updateATC(theOrig);
  }
  else
  {
    alert (myErrors);
  }
}


/******************************** PAGE FUNCTIONS ********************************/
function Pg0_Load()     {
  document.DomainWP.visibility = "visible";
  document.OK.document.btnOK.focus();
  return true;
}
function Pg0_unLoad()     {
  document.DomainWP.visibility = "hidden";
  document.DomainWP.visibility = "visible";
  document.DomainWP.visibility = "hidden";
  return true;
}

function Pg1_Load()     {
  document.LogoWP.visibility = "visible";
  setTimeout("document.LogoWP.document.logoURL.focus()",200);
  return true;
}
function Pg1_unLoad()     {
  document.LogoWP.visibility = "hidden";
  document.LogoWP.visibility = "visible";
  document.LogoWP.visibility = "hidden";
  return true;
}

function Pg2_Load()     {
  document.ColorWP.visibility = "visible";
  setTimeout("document.ColorWP.document.bgColor.focus()",200);
  return true;
}
function Pg2_unLoad()     {
  document.ColorWP.visibility = "hidden";
  document.ColorWP.visibility = "visible";
  document.ColorWP.visibility = "hidden";
  return true;
}

function showPageNum(pageNum)  {
  eval("Pg"+CURRENTPAGE+"_unLoad()");
  if (navigator.platform.toLowerCase().indexOf("mac") >= 0)     {
    eval("document.Tab"+CURRENTPAGE+".document.tabBG.src = document.Tab"+CURRENTPAGE+".document.tabBG.src.substring(0,document.Tab"+CURRENTPAGE+".document.tabBG.src.toLowerCase().lastIndexOf('tabbg'))+'tabBg_Mac.gif'");
  }
  else  {
    eval("document.Tab"+CURRENTPAGE+".document.tabBG.src = document.Tab"+CURRENTPAGE+".document.tabBG.src.substring(0,document.Tab"+CURRENTPAGE+".document.tabBG.src.toLowerCase().lastIndexOf('tabbg'))+'tabBg.gif'");
  }
  CURRENTPAGE = pageNum;
  if (navigator.platform.toLowerCase().indexOf("mac") >= 0)     {
    eval("document.Tab"+CURRENTPAGE+".document.tabBG.src = document.Tab"+CURRENTPAGE+".document.tabBG.src.substring(0,document.Tab"+CURRENTPAGE+".document.tabBG.src.toLowerCase().lastIndexOf('tabbg'))+'tabBgSel_Mac.gif'");
  }
  else  {  
    eval("document.Tab"+CURRENTPAGE+".document.tabBG.src = document.Tab"+CURRENTPAGE+".document.tabBG.src.substring(0,document.Tab"+CURRENTPAGE+".document.tabBG.src.toLowerCase().lastIndexOf('tabbg'))+'tabBgSel.gif'");
  }
  eval("Pg"+CURRENTPAGE+"_Load()");
}
