// variable to keep actions from being submitted twice
var g_isDispatchCalled = false;

var ns4 = (document.layers)?true:false;
var ns6 = (document.getElementById)?true:false;
var ie4 = (document.all)?true:false;
var ie50 = false;
var ie5 = false;

var jsRoadmapShowing = false;

if (ie4) {
 if ((navigator.userAgent.indexOf('MSIE 5') > 0) || (navigator.userAgent.indexOf('MSIE 6') > 0)) {
  if (navigator.userAgent.indexOf('MSIE 5') > 0) {
    ie50 = true;
  }
  ie5 = true;
 }
 if (ns6) {
  ns6 = false;
 }
}

var _d = new Date();
var TODAY = (_d.getMonth() + 1) + "/" + _d.getDate() + "/" + _d.getFullYear();

function callPopupInternal(loc, name, options)
{
 // if (ie4 && onunload)
  //{
  //  resetExitPopup();
  //}
  window.name = "mainWin";
  return window.open(loc, name, options);
}

function callFamilyPlanPromotionPopup(){
    window.open('http://www.fordvehicles.com/keepitsimple/pricevehicle/index.asp', 'n', 'width=540,height=640,location=no,toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no');
}

function callPopup(myLocation, sScroll, nWidth, nHeight)
{
  var sOptions;
  sOptions = "menubar=0,toolbar=0,location=0,directories=0,status=0,scrollbars=" + sScroll + ",resizable=0,width=" + nWidth + ",height=" + nHeight;
  callPopupInternal(myLocation, 'popupWndow', sOptions);
}

function callPopupWithToolbar(myLocation, sScroll, nWidth, nHeight, sName)
{
  if (!sName) sName = 'popupWndow';
  var sOptions;
  sOptions = "menubar=0,toolbar=1,location=0,directories=0,status=0,scrollbars=" + sScroll + ",resizable=0,width=" + nWidth + ",height=" + nHeight;
  callPopupInternal(myLocation, sName, sOptions);
}

function callPopupWithFullControl(myLocation, nWidth, nHeight, sName)
{
  var sName = 'popupWndow';
  var sOptions;
  sOptions = "menubar=1,toolbar=1,location=1,directories=1,status=1,scrollbars=1,resizable=1,width=" + nWidth + ",height=" + nHeight;
  callPopupInternal(myLocation, sName, sOptions);
}


function callPopupWithToolbarResizable(myLocation, sScroll, nWidth, nHeight, sName)
{
  if (!sName) sName = 'popupWndow';
  var sOptions;
  sOptions = "menubar=0,toolbar=1,location=0,directories=0,status=0,scrollbars=" + sScroll + ",resizable=1,width=" + nWidth + ",height=" + nHeight;
  callPopupInternal(myLocation, sName, sOptions);
}

function callPopupWithMenu(myLocation, sScroll, nWidth, nHeight, sName)
{
  if (!sName) sName = 'popupWndow';
  var sOptions;
  sOptions = "menubar=1,toolbar=0,location=0,directories=0,status=0,scrollbars=" + sScroll + ",resizable=0,width=" + nWidth + ",height=" + nHeight;
  callPopupInternal(myLocation, sName, sOptions);
}

function callPopupWithName(myLocation, sName, sScroll, nWidth, nHeight)
{
  var sOptions;
  sOptions = "menubar=0,toolbar=0,location=0,directories=0,status=0,scrollbars=" + sScroll + ",resizable=0,width=" + nWidth + ",height=" + nHeight;
  callPopupInternal(myLocation, sName, sOptions);
}

function returnPopupWithName(myLocation, sName, sScroll, nWidth, nHeight)
{
  var sOptions;
  sOptions = "menubar=0,toolbar=1,location=0,directories=0,status=0,scrollbars=" + sScroll + ",resizable=0,width=" + nWidth + ",height=" + nHeight;
  return callPopupInternal(myLocation, sName, sOptions);
}

function callPopupWithNameResizable(myLocation, sName, sScroll, nWidth, nHeight)
{
  var sOptions;
  sOptions = "menubar=0,toolbar=0,location=0,directories=0,status=0,scrollbars=" + sScroll + ",resizable=1,width=" + nWidth + ",height=" + nHeight;
  callPopupInternal(myLocation, sName, sOptions);
}


function waitCursor() {
  if ((document.body) && (document.body.style)) {
    document.body.style.cursor = 'wait';
  }
}

function defaultCursor() {
  if ((document.body) && (document.body.style)) {
    document.body.style.cursor = '';
  }
}

function doAction(action) {
  document.mainform.elements[0].name = action;
  // waitCursor();
  document.mainform.submit();
}

function setAction(action, value) {
  document.mainform.elements[0].value = value;
  document.mainform.elements[0].name = action;
}

function setAction2(action, value) {
  document.mainform.elements[1].value = value;
  document.mainform.elements[1].name = action;
}

/**
 * This method is invoked when the current
 * state is to be changed. 
 * @param Name if the state the current state 
 *        is to be set.
 */
function changeCurrentState(value) {
  document.mainform.elements[2].value = value;
}

function configClick(value) {
  var offset = 0;
  if ((ns4)||(ns6)) {
    offset = window.pageYOffset;
  } else {
    offset = self.document.body.scrollTop;
  }
  if (offset > 0) {
    setAction2("_scrollPos",offset);
  }
  doAction2('xefrAction',value);
}

// mapping of JS color map to its default image
var selectedImages = new Object();
function colorShift(imgName, mapObj, id)
{
    if(null==imgName || null==mapObj || null==document.images || null==document.images[imgName]) {
        return;
    }

    // save selected image for defaulting
    if(null==selectedImages[imgName]) {
        selectedImages[imgName] = document.images[imgName].src;
    }

    if(null==id || id=='-1') {
        document.images[imgName].src = selectedImages[imgName];
    } else {
        var idMap = mapObj[id];
        if(null!=idMap) {
            var newImg = idMap['src'];
            if(null!=newImg) {
                document.images[imgName].src = newImg;
            }
        }
    }
}

function preloadMap(mapObj) {
    if(null==mapObj) return;
    for(var i=0; i<mapObj.length; i++) {
        var idMap = mapObj[i];
        if(null!=idMap) {
            var img = new Image();
            img.src = idMap['src'];
        }
    }
}

function scrollRestore(value) {
  window.scrollTo(0,value);
}

function makeTransition(value) {
  doAction2('makeTransition',value);
}

function doAction2(action, value) {
  document.mainform.elements[0].value = value;
  document.mainform.elements[0].name = action;
  // waitCursor();
  document.mainform.submit();
}
function doAction3(action, value) {
  document.getElementById("ProcessZipCode").value="silent";
  doAction2(action, value);
}

function captureZipCode() {
  var lang = jsLanguage;

  if (!lang || '' == lang) {
    lang = 'en';
  }

  if (ie5) {
    if (ie50) {
      target = "/content/ZipcodePrompt" + ((lang == 'es') ? ('_es') : ('')) + ".html";
      return window.showModalDialog(target,"","scroll:no; dialogHeight:235px; dialogWidth:315px");
    } else {
      return window.showModalDialog("/content/ZipcodePrompt.jsp?lang=" + lang,"","scroll:no; dialogHeight:235px; dialogWidth:315px");
    }
  } else {
    return window.prompt(getString("forddirect_js~PleaseEnterZipCode"),"");
  }
}

function validateZip(sZip) {
  if ((sZip == null) || (sZip.length != 5)) return false;
  for(x = 0; x < sZip.length; x++) {
    var c = sZip.charAt(x);
    if (c < '0' || c > '9') return false;
  }
  return true;
}


function showRoadmap() {
  if (jsRoadmapShowing) return;
  jsRoadmapShowing = true;
  var roadmapObj = getDocObj("roadmap");
  var posObj = getImgObj("roadmapStart");
  if ((roadmapObj == null) || (posObj == null))  {
    return;
  }
  var topPos = posObj.getTop();
  roadmapObj.setLeft(10);
  roadmapObj.setTop(topPos + 10);
  roadmapObj.setInnerHTML("<BR clear='all'>" + getString("forddirect_js~CustomerRoadMap"));
  roadmapObj.show();
  if (_isNS && !_isDOM) {
    newDocHeight = (topPos + 10 + roadmapObj.getHeight());
    document.height = newDocHeight;
  }
}

function hideRoadmap() {
  var roadmapObj = getDocObj("roadmap");
  roadmapObj.hide();
}

function printPage()
{
  if (jsHasRoadmap) {
    showRoadmap();
  }
  if(window.print) {
    window.print();
//    hideRoadmap();
  } else {
    alert(getString("forddirect_js~PrintPage"));
  }
  return false;
}

function showIncentives(baseLink, baseZip) {
  if (!baseLink) return;
  var zip;
  if (baseZip && baseZip != "null") {
    zip = baseZip;
  } else {
    zip = captureZipCode();
    if (!validateZip(zip)) {
      alert(getString("forddirect_js~InvalidZipCode"));
      return;
    } else {
      if (document.mainform && document.mainform.zipCode) {
        document.mainform.zipCode.value = zip;
      }
    }
  }
  callPopupInternal(baseLink + zip, 'fvincentives', "menubar=0,toolbar=1,location=0,directories=0,status=0,scrollbars=1,resizable=1,width=620,height=400");
}

function reselectProduct() {
  var left = document.productSelector.selProdLeft.options[document.productSelector.selProdLeft.selectedIndex].value;
  var right = document.productSelector.selProdRight.options[document.productSelector.selProdRight.selectedIndex].value;
  document.location.href = "/FVCompare.jsp?sModel=20" + jsModelNameToken + "&p1=" + left + "&p2=" + right;
}

function showPrintable() {
  callPopupWithName(document.location.href + "&print=1", "_printable",'yes', 660, 400);
}

function showVehicleDetails(vin)
{
    if(null!=vin && vin!='')
    {
        callPopupWithName('/Dispatch.jsp?.CurrentState=' + jsCurrentState + '&populateLocatedVehicle=' + vin,'vehicleDetails','yes',577,600);
        return false;
    }
    return false;
}

function showRegionalSpecials(vin)
{
    if(null!=vin && vin!='')
    {
        callPopupWithName('/Dispatch.jsp?.CurrentState=' + jsCurrentState + '&showRegionalSpecials=' + vin,'regionalSpecials','yes',475,249);
    }
    return false;
}

/// for dynamic div placement ///
var floatObjIsShowing = false;

function showFloatDiv(e, content, xPos, yOffset) {
 floatObj = getDocObj("floatDiv");
 floatObj.setInnerHTML(content);
 placeAndShow(floatObj,e,xPos,yOffset);
 floatObjIsShowing = true;
 return false;
}

function showFloatDiv2(e, xPos, yOffset) {
 floatObj = getDocObj("floatDiv");
 placeAndShow(floatObj,e,xPos,yOffset);
 floatObjIsShowing = true;
 return false;
}

function floatDivIsShowing() {
 return floatObjIsShowing;
}

function dismissFloatDiv() {
 getDocObj("floatDiv").hide();
 floatObjIsShowing = false;
 return false;
}

/// vehicle compare ///
var firstCompareSelection = null;
function vehicleCompare(e, vehA, vehB) {
  // we have two vehicles specified to compare
  if(null!=vehA && null!=vehB) {
    clickCompareButton(false, vehA);
    if(vehA!=vehB) {
      // do the compare
      callPopupWithName('/Dispatch.jsp?.CurrentState=' + jsCurrentState + '&compare=' + vehA + '&compare=' + vehB,'vehicleCompare','yes',620,600);
    }
    hideCompareInfo();
    return false;
  }
  // choosing first or second vehicle
  else if(null!=vehA && null==vehB) {
    if(null == firstCompareSelection) {
      // this is the first vehicle choice
      firstCompareSelection = vehA;
      clickCompareButton(true, vehA);
      showCompareInfo(e);
      return false;
    } else {
      return vehicleCompare(e, firstCompareSelection, vehA);
    }
  }
  else return false;
}

function showCompareInfo(e) {
  var compareDiv = getDocObj("compareDiv");
  placeAndShow(compareDiv,e,130,-35);
}
function hideCompareInfo() {
  var compareDiv = getDocObj("compareDiv");
  compareDiv.hide();
  firstCompareSelection = null;
}

function clickCompareButton(on, vin) {
  if(isFilter && ns4) return;

  if(null!=compareImgOff && null!=compareImgOn)
  {
    document.images[('_i'+vin)].src=(on?compareImgOn.src:compareImgOff.src);
  }
}

function getString(key)
{
  var value = g_strings[jsLanguage][key];

  // if no string for given language, return the key
  if(null==value || ''==value)
  {
    // TODO: debugging
    // alert("Missing JS string resource [key, language] = [" + key + ", " + jsLanguage + "]");
    value = key;
  }

  return value;
}
function changeLanguage()
{
    var lang = ('en' == jsLanguage) ? 'es' : 'en';
    var langURL = '/Dispatch.jsp?.CurrentState=' + jsCurrentState + '&DispatchBindingSet=language&lang=' + lang;

    // if the current state defines a _changeLanguage function, call it instead
    if(window._changeLanguage)
    {
        _changeLanguage(langURL);
    }
    else
    {
        document.location.href=langURL;
    return true;
    }
}

function showPartDisclaimer(disclaimer)
{
    if(null==disclaimer) return;

    var sOptions = 'menubar=0,toolbar=0,location=0,directories=0,status=0,scrollbars=no,resizable=0,width=347,height=161';
    var popup = callPopupInternal('about:blank', 'partDisclaimer', sOptions);

    popup.document.clear();
    popup.document.writeln('<html><head><title>FordDirect.com</title><script language="JavaScript">window.focus();</script></head>');
    popup.document.writeln('<body bgcolor="#FFFFFF" topmargin=0 leftmargin=10 rightmargin=10 bottommargin=0 marginwidth=0 marginheight=0>');
    popup.document.writeln('<img src="/f/img/fd/fd-header-fd-logo.gif" /><br>');
    popup.document.writeln('<span style="color:#222222;font-family:Verdana,Helvetica,sans-serif;font-size:11px;">');
    popup.document.writeln(disclaimer);
    popup.document.writeln('</span>');
    popup.document.writeln('</body></html>');
    popup.document.close();
}

function icOn( imageName )
{
    var image = document[imageName];
    if( image.length > 0 )
    {
        for(i=0; i < image.length; i++)
        {
            image[i].src = "/img/ic/icon_on.gif";
        }
    }
    else
    {
        image.src = "/img/ic/icon_on.gif";
    }
}

function icOff( imageName )
{
    var image = document[imageName];
    if( image.length > 0 )
    {
        for(i=0; i < image.length; i++)
        {
            image[i].src = "/img/ic/icon_off.gif";
        }
    }
    else
    {
        image.src = "/img/ic/icon_off.gif";
    }
}

// links to the specified url only if in netscape 4
function doNS4Link(strURL) {
  if (ns4) {
    window.location.href = strURL;
  }
}

// count the number of digits in a string
function digitCount(text) {
  var count = 0;
  for (i = 0; i < text.length; i++) {
    if(text.charAt(i) >= '0' && text.charAt(i) <= '9') {
      count++;
    }
  }
  return count;
}


function setModelForIncentive(type){
        var model;
    
    if (type == '0')
            model = getModelSelected();
        else
            model = type;
    
    if (model.length == 0)
            return 1;
    
    if(ns4){
            self.document.mainform.selectedModel.value = model;
    }else{
            document.mainform.selectedModel.value = model;
        }

    return 0;
}



function getModelSelected(){
var obj;
if(ns4){
        obj=self.document.mainform.modeltype;
    }else{
        obj=document.mainform.modeltype;
    }
var checkBoxArr = getSelectedRadioValue(obj);
return checkBoxArr;
}

/* 
* Function to dynamically embed the flash object. oeTags is the string version of the embed tag
* This call is made through JavaScript instead of directly putting it in the JSP to fix the IE Patch issue.
* If the line is put directly in the JSP, and the site is accessed using IE, a prompt comes on every flash
* page asking to press enter to run the embedded object. This is because of a patch that IE released recently
* The call though javascript is a workaround for that problem. 
*/
function embedFlashObject(oeTags)
{
   document.write(oeTags);   // embed the flash movie
}

function ibpVehicleCompare(e, vehA, vehB) {
  // we have two vehicles specified to compare
  if(null!=vehA && null!=vehB) {
    if(vehA!=vehB) {
      // do the compare
      callPopupWithNameResizable('/Dispatch.jsp?.CurrentState=' + jsCurrentState + '&compare=' + vehA + '&compare=' + vehB,'vehicleCompare','yes',620,600);
    }
    return false;
  }
  return false;
}

function addSpotLightTag(cat,namePlate) {
    var axel = Math.random()+"";
    var a = axel * 10000000000000;
    var loc=""+window.location;
    var protocol=loc.split(':')[0];
    var iframe = document.createElement('iframe');
    iframe.setAttribute('src',protocol+'://fls.doubleclick.net/activityi;src=690327;type=fvflup;cat='+cat+';u1='+namePlate+';ord='+ a + '?' );
    iframe.setAttribute("frameBorder", "0"); 
    iframe.setAttribute("width", "1"); 
    iframe.setAttribute("height", "1");     
    document.body.appendChild(iframe); 
}

function loadPageInIFrame(frameName,pageURL){
    window.frames[frameName].location.href=pageURL;
}


// RFP - FDRTL - Dealer Call Tracking Implementation Starts

function findDealers(sZip ) {

  	if ( !validateZip( sZip ) )
  	{
		alert( getString( 'forddirect_js~InvalidZipCode' ) );
  	}
  	else
  	{
		setAction2( 'zipCode', sZip );
		document.mainform.processModel.value = 'silent';
		document.mainform.searchParam.value = sZip;
		doAction2( 'processZipCode', '<%=Transitions.FindDealers%>');
  	}
  	
  	/*	<input type="hidden" name="locateDealers_value" value="search"/>
	<input type="hidden" name="locateDealers" value=""/>
	<input type="hidden" name="searchParam" value=""/>*/
}

//last chance window
var lastChance = false;
var isClosed=false;
function showLastChance(){
	if(!lastChance || !isClosed)
		return;
	window.open( '/Dispatch.jsp?.CurrentState=LastChance', 'LastChance', 'status = 1,menubar=1,toolbar=1, height = 400, width = 730, resizable = 1' );
	
}

//just for IE
var alterffourflag=0;
var lastkey=0;
var refreshflag=0;
var ie7=navigator.userAgent.toLowerCase().indexOf('msie 7')!=-1;
function doc_onkeydown(e)
{	e=(e!=null)?e:window.event;
    if(e){ 
        var numcheck;
        keynum = e.keyCode;
        if(lastkey==18 && keynum==115)//||(lastkey==17 && keynum==87))
        { 
            alterffourflag=1;
        }
        if(keynum==116)
        {
            refreshflag=1;
        }   
        lastkey=keynum;
    }
}

function window_onbeforeunload(e){
	isClosed=false;
    if(window.event){ //IE
        if(alterffourflag==1){ 
        	//for Alt+F4,CTRL+W button, all browsers. Alt+F4 wont work in firefox
            //alert("closed ALT+F4/CTRL+W");
            isClosed=true;                
        }else if(ie7==true){
            var offset=0.0;
            var width=0.0;
            if( document.documentElement && ( document.documentElement.clientWidth ))
            {
                //IE 6+ in 'standards compliant mode'
                width = document.documentElement.clientWidth;
                                   
            }
            else if( document.body && ( document.body.offsetWidth))
            {
                        width=document.body.offsetWidth;
            }
               
            offset=20;
            var diff =width-offset;
            if (refreshflag!=1 && width!=0 && window.event.clientY < 0 && (window.event.clientX > (width - offset))||alterffourflag==1) 
            {
                //alert("close IE7");
            	isClosed=true;            
            }
       }
	}
}

//for IE6 & firefox tab close
function window_onunload(e){
    if(window.event && !ie7){ //ie6
        if(window.screenLeft>10003 && window.event.clientX < 0 && window.event.clientY){
            //alert("closed IE6");
            isClosed=true;
        }
    }else if(e!=null && e.target==null && !ie7){ //Firefox
            //alert("closed Firefox Tab");
            isClosed=true;
    }
	
    // FDRTL526 change logic for pop-up window
    // check if it is a pop-up window
    if(window.opener != null) return;

    // if not, show last chance window
    showLastChance();
}

if (window.addEventListener) {
    /** for mozilla. */
    document.addEventListener('keypress', doc_onkeydown, false);
    window.addEventListener('beforeunload', window_onbeforeunload, false);
    window.addEventListener('unload', window_onunload, false);
}else if(window.attachEvent){
    /** IE/Opera. */
    document.attachEvent('onkeypress', doc_onkeydown);
    window.attachEvent('onbeforeunload', window_onbeforeunload);
    window.attachEvent('onunload', window_onunload);
}

// RFP - FDRTL - Dealer Call Tracking Implementation Ends

// Changes for FDRTL513 starts
/**
 * This method is invoked when the current
 * The redirection model percentage has to be changed. 
 */
function validatePercentage(perObj) {
  if((isNaN(perObj.value)||perObj.value<0||perObj.value>100 ))
	{
	  perObj.value=0;
    }
}
// Changes for FDRTL513 ends
//copied the content of encode.js--
		  // The Central Randomizer 1.3 (C) 1997 by Paul Houle (houle@msc.cornell.edu)
// See:  http://www.msc.cornell.edu/~houle/javascript/randomizer.html

var browser = navigator.appName;
var appversion = navigator.appVersion;
var UpgradeBrowser=false;
var EncodedString = "";
rnd.today=new Date();
rnd.seed=rnd.today.getTime();

// Check for known Browser Configs that don't support winHndl.document.formname.submit()
if (browser == 'Microsoft Internet Explorer') 
{
	x=appversion.indexOf('MSIE');
	version=appversion.substring(x+5,x+8);
	if (eval(version) < 5)
	{
		UpgradeBrowser=true;
	}
}

function dispUpgradeBrowser(windowName)
{
	windowProperties = "toolbar=1,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,width=600,height=550";
	winHndl = window.open ("", windowName, windowProperties);
	winHndl = winHndl.document;
		
	winHndl.write("<html><head><title>Upgrade Browser</title><body>");
	winHndl.write("<br><br><br><div align=center>");
	winHndl.write("This page does not function properly with versions of <br>Microsoft Internet Explorer earlier than 5.0<br>");
	winHndl.write("Please upgrade your version of Internet Explorer<br><br>");
	winHndl.write("<a href='http://www.microsoft.com/windows/ie/downloads/default.asp'><img src='http://lmincentives.dealerconnection.com/ServicePortal/images/MSIE_Update.jpg' width=90 height=45 border=2 alt='IE Downloads'></a>");
	winHndl.write("<br><b>Click here to <br>download the latest version of IE!</b>");
	winHndl.write("</div></body></html>");	

	return;
}

function pad (val)
{	
	val = val.toString();
	 
	if (val.length < 2)
	{
		 val = "0"+val.toString();
	}
	
	return val.toString();
}
        
function CallServicePortal(ServiceId, QueryString, windowName, windowProperties)
{
	if (UpgradeBrowser)
	{
		dispUpgradeBrowser(windowName);
		return;
	}
		
	var AddVal;
	var datenow=new Date();
	
	MM = eval(datenow.getMonth() + 1);
	DD = datenow.getDate();
	YY = datenow.getYear().toString();
	hh = datenow.getHours();
	nn = datenow.getMinutes();
	ss = datenow.getSeconds();
	
	YY = YY.substring(2,4);
	
	message=pad(hh)+pad(DD)+pad(YY)+pad(MM)+pad(ss)+pad(nn);
		
	AddVal=((eval(message.substring(0,2))*3600+eval(message.substring(10,12))*60+eval(message.substring(8,10))) % 16) +1;
			
	DateKey=encode(message,0)
	AccessCode=encode("Coolfire Interactive - evitcaretnI eriflooC",AddVal)
	
	winHndl = window.open ("", windowName, windowProperties);
	winHndl = winHndl.document;
	
	winHndl.write("<html><head><title>Incentives</title></head><body onload='document.serviceportal.submit();'>");
	winHndl.write("<form method='post' action='" + window.location.protocol + "//lmincentives.dealerconnection.com/serviceportal/datekey.cfm' name='serviceportal'>");
	winHndl.write("<input type='hidden' name='dk' value='"+DateKey+"'>");
	winHndl.write("<input type='hidden' name='ac' value='"+AccessCode+"'>");
	winHndl.write("<input type='hidden' name='si' value='"+ServiceId+"'>");
	winHndl.write("<input type='hidden' name='qs' value='"+QueryString+"'>");
	winHndl.write("</form>");
	//winHndl.forms[0].submit();
	//winHndl.serviceportal.submit();
	winHndl.write("</body></html>");
	winHndl.close();
}

function rnd() {
        rnd.seed = (rnd.seed*9301+49297) % 233280;
        return rnd.seed/(233280.0);
}

function rand(number) {
        return Math.ceil(rnd()*number);
}

// end central randomizer.

function makeHex(n) { // only works on 0 to 256

 var Digits="0123456789ABCDEF";
 var LSN = Digits.charAt(n % 16);
 var MSN = Digits.charAt(n / 16);
 
 return MSN + LSN;
}

function encode (StringIn,AddVal)
{
	// if method == 1, set hidden field1 and return add value
	// if method ==2, set hidden field2
	
	a = 1;
	StringOut = "";
	
   while (1==1)
   {
   
	    RandLen = (rand(64) + 64);
	    if (RandLen > (StringIn.length - a)) 
		{
			RandLen = StringIn.length - a;
		}
	    
	    if (AddVal==0)
		{
		RandAdd = rand(16);
	    }
		else
		{
		RandAdd=AddVal;	
		}
		
		HexRandAdd = makeHex(RandAdd);
	    	    
		Minus = 0;
	    end = eval(a + RandLen - 1);
		var i;
		
		for(i=a-1;i<=end;i++)
		{
	        val=StringIn.charCodeAt(i);
	       	 
		    if ((val < 32) || (val > 126)) 
			{
	            Minus = Minus + 1;
	        }
			else
			{
	            val = makeHex(val + RandAdd);
	        	StringOut = StringOut + val;
			}
	    }
	    
	    HexRandLen = makeHex(RandLen + 1 - Minus);
	   	    
	    EncodedString = HexRandLen + HexRandAdd + StringOut;
	    
	    StringOut = "";
	    
	    a = a + RandLen;
		
   		if (a >= StringIn.length) 
		{
			break; // Exit While loop
		}	
		
	} // End While (true)
	
	return EncodedString;
	
} // End encode function

// </script> 
 
//copied jsobj.js content
var _isIE, _isNS, _isDOM;

_isIE = (navigator.appName == "Microsoft Internet Explorer");
_isNS = (navigator.appName == "Mozilla" || navigator.appName == "Netscape");
_isDOM = _isNS && (navigator.appVersion.indexOf("4.") == -1);

var allObjs = new Array();


function dom_object(obj) {
	this.docObj = obj;
	this.name = obj.id;
	this.hide = domHide;
	this.show = domShow;
	this.getHeight = domGetHeight;
	this.setTop = domSetTop;
	this.setLeft = domSetLeft;
	this.setInnerHTML = domSetInnerHTML;
	this.unDisplay = domUnDisplay;
}


function ie_object(obj) {
	this.docObj = obj;
	this.name = obj.id;
	this.hide = domHide;
	this.show = domShow;
	this.getHeight = ieGetHeight;
	this.setTop = domSetTop;
	this.setLeft = domSetLeft;
	this.setInnerHTML = domSetInnerHTML;
	this.unDisplay = domUnDisplay;
}

function ns_object(obj) {
	this.docObj = obj;
	this.name = obj.name;
	this.hide = nsHide;
	this.show = nsShow;
	this.setInnerHTML = nsSetInnerHTML;
	this.getHeight = nsGetHeight;
	this.setTop = nsSetTop;
	this.setLeft = nsSetLeft;
	this.unDisplay = nsHide;
}

function ie_image(obj) {
	this.imgObj = obj;
	this.getTop = ieGetImgTop;
	this.getLeft = ieGetImgLeft;
}

function ns_image(obj) {
	this.imgObj = obj;
	this.getTop = nsGetImgTop;
	this.getLeft = nsGetImgLeft;
}

function ieGetImgTop() { return parseInt(this.imgObj.offsetTop); }
function ieGetImgLeft() { return parseInt(this.imgObj.offsetLeft); }
function ieGetHeight() { return parseInt(this.docObj.clientHeight); }
function domHide() { this.docObj.style.visibility = "hidden"; }
function domShow() { this.docObj.style.visibility = "visible"; }
function domSetInnerHTML(s) { this.docObj.innerHTML = s; }
function domGetHeight() { return parseInt(document.defaultView.getComputedStyle(this.docObj, "").getPropertyValue("height")); }
//function domSetHeight(y) { this.docObj.style.height = y + "px"; }
//function domSetWidth(y) { this.docObj.style.width = x + "px"; }
function domUnDisplay() { this.docObj.style.display = 'none'; }
function domSetLeft(x) { this.docObj.style.left = x + "px"; }
function domSetTop (y) { this.docObj.style.top = y + "px"; }

function nsGetImgTop() { return parseInt(this.imgObj.y); }
function nsGetImgLeft() { return parseInt(this.imgObj.x); }
function nsHide() { this.docObj.visibility = "hidden"; }
function nsShow() { this.docObj.visibility = "inherit"; }
function nsGetHeight() { return this.docObj.document.height; }
function nsSetHeight(y) { this.docObj.clip.height = y; }
function nsSetWidth(x) { this.docObj.clip.width = x; }
function nsSetTop(y) { this.docObj.top = y; }
function nsSetLeft(x) { this.docObj.left = x; }
function nsUnDisplay() { this.docObj.clip.left = 0; this.docObj.clip.right = 0; this.docObj.clip.bottom = 0; this.docObj.clip.top = 0; }

function nsSetInnerHTML(s) {
	this.docObj.document.clear();
	this.docObj.document.write(s);
	this.docObj.document.close();
}

function findNSLayer(objName) {
   for (i = 0; i < document.layers.length; i++) {
     if (document.layers[i].name == objName) return document.layers[i];
   }
}

// Note: images not in the same DIV/doc are not
// currently supported under Netscape
function getImgObj(objName) {
  if (allObjs[objName]) return allObjs[objName];
  var theObj = null;
  if (_isIE || _isDOM) {
    if (!document.images[objName]) {
      alert("IE cannot find image " + objName);
      return null;
    }
    theObj = new ie_image(document.images[objName]);
  } else if (_isNS) {
    if (!document.images[objName]) {
      alert("NS cannot find image " + objName);
      // If required, add sub-doc search here
    }
    theObj = new ns_image(document.images[objName]);
  }
  allObjs[objName] = theObj;
  return theObj;
}

function getDocObj(objName) {
  if (allObjs[objName]) return allObjs[objName];
  var theObj = null;
  if (_isIE) {
    if (!document.all[objName]) {
      return null;
    }
    theObj = new ie_object(document.all[objName]);
  } else if (_isDOM) {
    if (!document.getElementById(objName)) {
      return null;
    }
    theObj = new dom_object(document.getElementById(objName));
  } else if (_isNS) {
    var nsLayer = document.layers[objName];
    if (!nsLayer) {
      nsLayer = findNSLayer(objName);
      if (!nsLayer) {
        return null;
      }
    }
    theObj = new ns_object(nsLayer);
  }
  allObjs[objName] = theObj;
  return theObj;
}

// checks if an object with the specified id exists
function doesObjExist(objName) {
  if (allObjs[objName]) return true;
  if (_isIE) {
    if (document.all[objName]) {
      return true;
    }
  } else if (_isDOM) {
    if (document.getElementById(objName)) {
      return true;
    }
  } else if (_isNS) {
    var nsLayer = document.layers[objName];
    if (nsLayer) {
      return true;
    }
  }
  return false;
}

function placeAndShow(o,e,xPos,yOffset) {
 if ( (ns4) || (ie4) || (ns6) ) {
  var y;
  if ((ns4)||(ns6)) {y=e.pageY;}
  if (ie4) {y=event.y;}
  if (ie5) {y=event.y+self.document.body.scrollTop;}
  y = y + yOffset;
  o.setLeft(xPos);
  o.setTop(y);
  o.show();
 }
}

