/*-----------------------------------------------------------------------------
-	File Name:
-		Google FS Trans.js
-
-	Description:
-       Translator logic for the custom Google Free serach object		
-
-	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.
------------------------------------------------------------------------------*/
function translateMarkup(docNameStr, siteRootStr, inStr)  {
  var preTransLength = inStr.length;  //remember original length

  if (inStr.indexOf(basicAction) != -1 || inStr.indexOf(customAction) != -1)
  {
    var origStr = String(inStr);
    var firstForm = findTag(origStr,"form",true);
    var translatedTag = "";
    var theAction = "";
    var theEdit = "Google_Free_Custom_Adv.htm";
    while (firstForm != "")  {
      theAction = getTagProp(firstForm,"form","action").toLowerCase();
      if (theAction==basicAction || theAction==customAction)  {
        translatedTag = translateForm(firstForm);
        var beginLock = '<MM:BeginLock translatorClass="WAGF" type="WAGoogleFree" edit="' + theEdit + '" orig="' + WA_translatorEncode(firstForm) + '">\n';    
        var endLock = '<MM:EndLock>';
        translatedTag = beginLock +  translatedTag + endLock;
        inStr = StringReplace(inStr,firstForm,translatedTag);
      }
      origStr = origStr.substring(origStr.indexOf(firstForm)+firstForm.length);
      firstForm = findTag(origStr,"form",true);
    }
  }

  //only return string if changed
  if (inStr.length != preTransLength)
  {
    return inStr;
  }
}

function translateForm(theForm)
{
  var retVal = "";
  var theImg = WA_getConfigurationPath("/shared/Google/FreeSearch/Images/logo_40wht.gif");
  var theSiteSearch = "&nbsp;";
  var imgSrc = getTagProp(theForm,"img","src").toLowerCase();
  var tableBGColor = getTagProp(theForm, "table", "bgcolor");

  var theGoogleSearch = GOOGLESEARCH;
  var theButtonIndex = theForm.search(/<input\s.*"Google Search"/i); //search for English "Google Search" button

  // if japanese or korean, check the language for "Google Search" button.
  if (dreamweaver.appVersion.indexOf('ja') != -1 && theButtonIndex != -1)
  {
      theGoogleSearch = GOOGLESEARCHENGLISH;
  }
  else if (dreamweaver.appVersion.indexOf('ko') != -1 && theButtonIndex != -1)
  {
      theGoogleSearch = GOOGLESEARCHENGLISH;
  }


  if (tableBGColor == "")
  {
    tableBGColor = "#FFFFFF";
  }

  var origForm = theForm;
  var theDomain = "";
  if (imgSrc.indexOf("google_safe.gif") >=0)
  {
    theImg = WA_getConfigurationPath("/shared/Google/FreeSearch/Images/google_safe.gif");
  }
  
  // loop through input tags to see if we are doing a sitesearch
  var theFirstInput = findOpenTag(origForm,"input");
  while (theFirstInput != "")
  {
    if (getTagProp(theFirstInput,"input","name") == "domains")
    {
      theSiteSearch = '&nbsp;<br><input type="radio" name="sitesearch" value=""> '+THREEW+' <input type="radio" name="sitesearch" checked>' + getTagProp(theFirstInput,"input","value") + '<br>';
      break;
    }
    origForm = origForm.substring(origForm.indexOf(theFirstInput)+theFirstInput.length);
    theFirstInput = findOpenTag(origForm,"input");
  }
  
  retVal = '  <form><table cellpadding="0" cellspacing="0" border="0" bgcolor="' + tableBGColor + '">\n' +
           '    <tr>\n' +
           '      <td nowrap>\n' +
           '        <img src="' +  theImg + '" border="0" alt="Google" align="absmiddle">' +
           '      </td>\n' + 
           '      <td nowrap>\n' +           
           '        <input type="text" name="qWA" size="25" maxlength="255" value="">\n' +
           '        <input type="submit" name="btnGWA" style="width:150px" value="'+theGoogleSearch+'">\n' +
                    theSiteSearch +
           '      </td>\n' +
           '    </tr>\n' +
           '  </table></form>\n';

  return retVal;
}
