function goUrl(formName,selectName) {
        var form_info = eval("document." + formName+"."+selectName);
        var url = form_info.options[form_info.selectedIndex].value;
        if (url != '') {
                document.location.href=url;
        }
}
function msgUnit(url,w,h) {
messageUnit = window.open(url,'SpecialInfo','width='+w+',height='+h+',scrollbars=no,menubar=no,resizable=no');
messageUnit.focus()
}

function isBrowserOk()
{
        var agent=navigator.userAgent.toLowerCase();
        var is_aol   = (agent.indexOf("aol") != -1);
        var is_win   = ( (agent.indexOf("win")!=-1) || (agent.indexOf("16bit")!=-1) );
        //current restriction is no AOL on PC:
        if (is_aol && is_win) return false;

        return true;
}


function popupCenteredWindow(url,title,width, height, options, giveFocus){
  var winLeft = ((screen.width) / 2) - (width/2);
  var winUp = ((screen.height) / 2) - (height/2);


  var winOpened = window.open(url,title,"left=" + winLeft + ",top=" + winUp + "," + options);
  if (giveFocus)
   winOpened.focus();
  else
   self.focus();
}

function popupWindow(url,title,options){
  var winOpened = window.open(url,title,options);
  winOpened.focus();
}


//
// Tries to set zip code field from cookie value if possible. This will set the
// values of any input fields on the html by the name of zip or zipcode.
// selects, hiddens, dropdowns, radios, checkboxes, and textareas are exlcuded.
//
/* Added global flag for whether or not a valid zip cookie exists */
var hasCookie = false;
function setZipFromCookie() {
  var fs = document.forms;
  var cookie = document.cookie;
  var cookieName = "zip";
  var cookieVal;
  // return false if cookie does not exist.
  if ( cookie == null || cookie.length < 1) return false;

  var len = cookie.length;
  // try to grab cookie val from cookie.
  for ( var i = 0; i < len ; i++ ) {
    var nameEndIndex = i + cookieName.length;
    // if cookie field with appropriate name is found, try to grab value.
    if ( cookie.substring( i, nameEndIndex ) == cookieName ) {
      var cookieEndIndex = cookie.indexOf(";", nameEndIndex );
      if ( cookieEndIndex == -1 ) cookieEndIndex = len;
      cookieVal = unescape(cookie.substring( nameEndIndex+1, cookieEndIndex ));
    }
  }
  // return false if cookie exists, but does not have zip value.
  if ( cookieVal == null || cookieVal.length < 1 ) {
    return false; // exit function
  }
else {
// else a valid cookie exists, so set the hasCookie flag
hasCookie = true;
}
  // iterate through all forms on this page.
  for ( var i = 0; i < fs.length; i++ ) {
    var f = fs[i];
    var es = f.elements;
    // look a for field named zip or zipcode. It must be either a text or number input.
    for ( var j = 0; j < es.length; j++ ) {
      var e = es[j];
      if ( e != null && (e.name.toLowerCase() == "zip" || e.name.toLowerCase() == "zipcode") ) {
      // set value, return true.
      e.value = cookieVal;
      }
    }
  }
  return true;
}


function getCookieVal(name) {
var fs = document.forms;
var cookie = document.cookie;
// default is "" if cookie does not exist.
var cookieVal = "";
if ( cookie == null || cookie.length < name ) return cookieVal;
var len = cookie.length;
// try to grab cookie val from cookie.
for ( var i = 0; i < len ; i++ ) {
var nameEndIndex = i + name.length;
// if cookie field with appropriate name is found, try to grab value.
if ( cookie.substring( i, nameEndIndex ) == name ) {
var cookieEndIndex = cookie.indexOf(";", nameEndIndex );
if ( cookieEndIndex == -1 ) cookieEndIndex = len;
cookieVal = unescape(cookie.substring( nameEndIndex+1, cookieEndIndex ));
break;
}
}
// return false if cookie exists, but does not have zip value.
return cookieVal;
}

function setCookieVal(name, value, expires, path, domain) {

        var secure = false;
        document.cookie = name + "=" + escape (value) +
        ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
        ((path == null) ? "" : ("; path=" + path)) +
        ((domain == null) ? "" : ("; domain=" + domain)) +
        ((secure == true) ? "; secure" : "");

}


<!--
var time = new Date();
var randnum= (time.getTime());
//-->



 function isZipValid(zip, zipFormElement, alternateErrorMessage)
 {
         var errorMessage="Please enter a valid 5-digit Zip Code";
         if(alternateErrorMessage!=null) errorMessage= alternateErrorMessage;
         if(zip==null || isNaN(zip)|| zip.length!=5)
         {
                alert(errorMessage);
                if(zipFormElement!=null) zipFormElement.focus();
                return false;
         }
         return true;
 }

// the window will popup 1/[multiplier] times
// ie if multiplier=20, the window will popup 1/20th of the time:

function DLhandler(mult, styleid, zip, tid)
{

  if ( !isBrowserOk() )
    return;
  if ( getCookieVal("vpudlclose") == "true" )
    return;
  var dlParam = styleid + "_" + zip;
  if ( dlParam == getCookieVal("dlparam") )
    return;
  if ( Math.ceil(Math.random()*mult) != 1 )
    return;
  setCookieVal("dlparam", dlParam, null, "/", ".edmunds.com");
  var dlURL = "/apps/dl/dealerlocator.xct?dldisplay=stdalone&styleid=" + styleid + "&zip=" + zip + "&usein=n&setbcode=t&" + tid;
  var winLeft = (screen.width/2) - 350;;
  var winUp = (screen.height/2) - 250;

  if (tid.indexOf('ign') == 4){
  var win = window.open(dlURL, "dlvdppopup", "width=800,height=625,location=no,toolbar=no,menubar=yes,scrollbars=yes,status=yes,left=" + winLeft + ",top=" + winUp+",resizable=yes");
}else{
  var win = window.open(dlURL, "dlvdppopup", "width=610,height=625,location=no,toolbar=no,menubar=yes,scrollbars=yes,status=yes,left=" + winLeft + ",top=" + winUp+",resizable=yes");
  }
  self.focus();
}

//scott decker added August 6, 2003
//onload function add
var global_usurpFunctionCall;
var global_usurpFunctionCallArray;
var global_usurpFunctionCount = 0;

function global_usurpOnLoad(){
        if (global_usurpFunctionCall) {
                global_usurpFunctionCall();
        }

        if (global_usurpFunctionCallArray)
        {
                //loop through all onload function calls in this array
                for(var i = 0; i < global_usurpFunctionCount; i++)
                        global_usurpFunctionCallArray[i]();

        }
}

function global_addOnLoadFunction(functionToAdd){

        if (!global_usurpFunctionCallArray)
        {
                global_usurpFunctionCallArray = new Array(1);
        }

        global_usurpFunctionCallArray[global_usurpFunctionCount] = functionToAdd;
        global_usurpFunctionCount++;
}

function dlPopUnder(page, styleid, zip, tid) {
    DLhandler(1,styleid, zip, tid);
    window.location = page;
}

// from trackingscript.js


function setTID(value){
//document.cookie="tid=" + escape(value);

var today = new Date();
//var expdate = new Date(today.getTime() +  5000); //expired in 5 seconds
var expdate = new Date(today.getTime() +  30000); //expired in 30 seconds

if (value.indexOf('edmunds') == 0){
document.cookie="tid=" + escape(value) + "; expires=" + expdate.toGMTString() + ";path=/;domain=.edmunds.com";
}else{
  document.cookie="tid=" + escape(value) + "; expires=" + expdate.toGMTString();
}
 }

function getTID(){

var url = window.location.href;
var TIDfromQueryString =  getParameter(url, 'tid');

if(TIDfromQueryString == "null"){

var dc = document.cookie;
var prefix = "tid=";
var begin = dc.indexOf("; " + prefix);

    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return "";
    }
    else
    {
        begin += 2;
    }
var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }

    var TIDfromCookie = unescape(dc.substring(begin + prefix.length, end));

    // Delete cookie immediately after retrieving for purpose of avoiding receiving incorrect
    // TID value in case of calling previous page from browser’s address field.
    //document.cookie= "tid=" + escape("");
    //DeleteCookie("tid", TIDfromCookie);

    return TIDfromCookie;

    }else{
      return TIDfromQueryString;
    }
 }



function getParameter ( queryString, parameterName ) {

var parameterName = parameterName + "=";
if ( queryString.length > 0 ) {

begin = queryString.indexOf ( parameterName );

if ( begin != -1 ) {

begin += parameterName.length;

end = queryString.indexOf ( "&" , begin );
if ( end == -1 ) {
end = queryString.length
}

var cookieValue = queryString.substring ( begin, end );
//document.cookie= "tid=" + escape(cookieValue);
return unescape (cookieValue);
}

return "null";
}
}

function DeleteCookie (name, value) {
var exp = new Date();
exp.setTime (exp.getTime() - 1);

if(name != null){
document.cookie = name + "=" + value + "; expires=" + exp.toGMTString();
 }
}


function popupPhoto(pageId, pictureId,make,model,synpartner,pageCode,usein,showLead) {

                var useuseflag = '';
                var adareaname = '';
                if (usein == 'e' && pageCode == 'roadtests') {
                        usein = 'n';
                        pageCode = '';
                        adareaname = 'roadmainindex';
                        useuseflag= 'false';
                }

                if (!showLead) {
                    showLead = false;
                }

                window.open('/apps/vdpcontainers/do/PhotoFlipper?pictureId=' + pictureId + '&pageId=' + pageId +
                '&pageCode=' + pageCode +
                '&make=' + make +
                '&synpartner=' + synpartner +
                '&model=' + model +
                '&usein=' + usein +
                '&useuseflag=' + useuseflag +
                '&adareaname=' + adareaname +
                '&showLead=' + showLead,
                '', 'fullscreen=no,toolbar=no,status=yes,menubar=no,scrollbars=no,resizable=no,directories=no,location=no,width=705,height=680');

}

function popupPhotoInsideline(pageId, pictureId,make,model,synpartner,pageCode,usein, showLead) {

                var useuseflag = '';
                var adareaname = '';
                if (usein == 'e' && pageCode == 'roadtests') {
                        usein = 'n';
                        pageCode = '';
                        adareaname = 'roadmainindex';
                        useuseflag= 'false';
                }

                if (!showLead) {
                    showLead = false;
                }

                window.open('/insideline/do/PhotoFlipper?pictureId=' + pictureId + '&pageId=' + pageId +
                '&pageCode=' + pageCode +
                '&make=' + make +
                '&synpartner=' + synpartner +
                '&model=' + model +
                '&usein=' + usein +
                '&useuseflag=' + useuseflag +
                '&adareaname=' + adareaname +
                '&showLead=' + showLead,
                '', 'fullscreen=no,toolbar=no,status=yes,menubar=no,scrollbars=no,resizable=no,directories=no,location=no,width=705,height=680');

}


//from /scripts/pagescript.jsp

function popPffCalc(pffsrcid)
{
url = "http://applications.edmunds.com/servlets/PartnerLogServlet?url=http%3A%2F%2Fwww.peoplefirst.com%2Fdefault.cfm%3FPFFSRCID%3DSRED02CALCPOPTL*TL0003***&partner=PPLFIRST&contract=People+First+Referrals&source=PF.PRICE.CALC.T";
browserVer      = parseInt(navigator.appVersion);
if ( (browserVer >= 3) && (navigator.appName.indexOf("WebTV") == -1) )
{
        this.name       = "main";
        calcWindow      = window.open(url,'calcWin','toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,copyhistory=0,height=440,width=450');
        if (window.focus && (navigator.appVersion.indexOf("MSIE 4") < 0 ))
                setTimeout("calcWindow.focus()",10);
        return(false);
}
else
{
        return(true);
}

}

function popup(popupID) {
url = "http://www.edmunds.com/partners/peoplefirst/financingpopup.html?id=" + popupID;
newWindow = window.open(url,'popup','width=550,height=480,scrollbars=yes,menubar=yes,resizable')
}

function checkEnter(event, formName)
{
        var code = 0;
        var formObject = eval("document." + formName);

        //alert("checkEnter:" + event.keyCode);

        if (event.which)
                code = event.which;
        else
                code = event.keyCode;
        if (code==13)
        {
                //alert("true");
                return true;
        }
        else
        {
                //alert("false");
                return false;
        }
}

var ADD_ZIPCODE = true;
var POPUP_WIDTH = "660";
var POPUP_HEIGHT = "480";

function popupCookiedWindow(cookieName, cookieValue, url, title, options, giveFocus){
        if (getCookieVal(cookieName) == cookieValue)
        {
                //don't do anything
                //they have all ready had a popup
        }
        else
        {
                //set the cookie
                //setCookieVal(cookieName,cookieValue,null,"/",".edmunds.com");
                if (giveFocus == null)
                        giveFocus = false;
                popupCenteredWindow(url,title,options,giveFocus);
        }

}

function popupCenteredWindow(url,title,options, giveFocus){
  var winLeft = (screen.width) / 2;
  var winUp = (screen.height) / 2;


  var winOpened = window.open(url,title,"left=" + winLeft + ",top=" + winUp + "," + options);
  if (giveFocus)
        winOpened.focus();
  else
        self.focus();
}

function powershopperPopupWindow(url,title,options){
  //popDLUnder(1);
  //if (dlPopupWindow)
  //{
  //            dlPopupWindow.focus();
  //            dlPopupWindow = null;
  //}
  popupWindow(url,title,options);
}

function powershopperPopupZipWindow(url,title,options, formObject){
  //popDLUnder(1);
  //if (dlPopupWindow)
  //    dlPopupWindow.focus();
  popupZipWindow(url,title,options, formObject);
}

function popupZipWindow(url,title,options, formObject){
 //get the form object's zip value

 var formObj = eval("document." + formObject);


 if (formObj)
 {
    if (formObj.zip)
   {


     if (!(url.lastIndexOf("&") == url.length))
     {
        popupWindow(url + "&zip="+formObj.zip.value,title,options);
    }
    else
    {
      popupWindow(url + "zip="+formObj.zip.value,title,options);
    }
  }
  else
  if (formObj.zipcode)
   {

     if (!(url.lastIndexOf("&") == url.length))
     {
        popupWindow(url + "&zipcode="+formObj.zipcode.value,title,options);
    }
    else
    {
      popupWindow(url + "zipcode="+formObj.zipcode.value,title,options);
    }
  }
 }
}

//for used
var buySell = 0;
function checkBuySell() {
if (buySell == 0)
  {
        //alert("Please click on the buy or sell button");
        return true;
  } else {
        return true;
  }
  return false;
}

/* Checks cookie now before setting upsAction */
function clickBuySell(val) {
  buySell = 1;

  //alert("buy and sell upsaction:" + document.UPS.upsAction);
// if a valid zip code cookie exists then post the upsaction field
  if (hasCookie) document.UPS.upsAction.value = val;
  document.UPS.submit();
}
/* Checks cookie now before setting upsAction */
function clickBuySell2(val) {
        buySell2 = 1;
        // if a valid zip code cookie exists then post the upsaction field
        if (hasCookie) document.UPS2.upsAction.value = val;
        document.UPS2.submit();
}

/* Checks cookie now before setting upsAction */
function clickBuySell3(val) {
  buySell3 = 1;
// if a valid zip code cookie exists then post the upsaction field
  if (hasCookie) document.UPS3.upsAction.value = val;
  document.UPS3.submit();
}
/* Checks cookie now before setting upsAction */
function clickBuySell4(val) {
        buySell4 = 1;
        // if a valid zip code cookie exists then post the upsaction field
        if (hasCookie) document.UPS4.upsAction.value = val;
        document.UPS4.submit();
}

function clickBuySellGeneric(val, f) {
buySell = 1;
  var dform=f;
  //alert("form:" + dform);
  //alert("form ups:" + dform.upsAction.value);

// if a valid zip code cookie exists then post the upsaction field
  if (hasCookie) dform.upsAction.value = val;
  //alert("got here");
  dform.submit();
}

function popupVideo(popupUrl, width, height) {
    var features = 'fullscreen=no,toolbar=no,status=yes,menubar=no,scrollbars=no,resizable=yes,directories=no,location=no,width='
        + width + ',height=' + height;
    window.open(popupUrl, '', features);
    return true;
}

function submitForm(formName, modelSelectName, zipName) {
  var form = eval("document." + formName);
  var verify = true;
  var errorMessage;
  var selectObject = eval("document." + formName + "." + modelSelectName);
  var zipObject = eval("document." + formName + "." + zipName);
  //alert("selected " + modelSelectName + " equals " + selectObject.options[selectObject.selectedIndex].value);
  if (selectObject.options[selectObject.selectedIndex].value == "") {
    //do nothing, just the select a model index
    errorMessage = "You need to select a make and a model.";
    verify = false;
  } else if (zipObject.value.length != 5 || isNaN(zipObject.value)) {
    verify = false;
    errorMessage = "Please enter a valid 5-digit ZIP Code.  (This application only supports ZIP Codes located in one of the 50 states or the District of Columbia.)";
  }

  if (verify) {
      info = mm_getAllFromModelIndex(selectObject.options[selectObject.selectedIndex].value);
      year = mm_getYearFromIndex(info[2]);
      form.model.value = mm_getNiceName(info[0]);
      form.make.value = mm_getNiceName(mm_getMakeFromIndex(info[1]));
      form.submit();
  } else {
      alert(errorMessage);
  }
}

/*Flash functions to fix firefox issue */
function setFlashWidth(divid, newW){
    document.getElementById(divid).style.width = newW+"px";
}
function setFlashHeight(divid, newH){
    document.getElementById(divid).style.height = newH+"px";
}
function setFlashSize(divid, newW, newH){
    if (document.getElementById(divid)){
        setFlashWidth(divid, newW);
        setFlashHeight(divid, newH);
    }
}

var globalRandNum = Math.floor(Math.random() * 999999999);
function resetGlobalRandNum(){
    globalRandNum = Math.floor(Math.random() * 999999999);
}

/*
 *Counts the remaining allowed characters in a textarea and updates a span with the value.
 *Contents of the textarea are also truncated to fall within the max allowed characters.
 */
function updateCharacterCount(textAreaId, counterSpanId, maxChars, errorMessageSpanId, errorMessage) {
    var theTextArea = document.getElementById(textAreaId);
    var theCounterSpan = document.getElementById(counterSpanId);
    var errorMessageSpan = null;
    if(errorMessageSpanId != null) {
        errorMessageSpan = document.getElementById(errorMessageSpanId);
    }
    var remainingChars = maxChars - theTextArea.value.length;
    if(remainingChars < 0) {
        theCounterSpan.innerHTML="<font color='red'>0</font>"
        if(errorMessageSpan != null) {
            errorMessageSpan.innerHTML="<font color='red'>"+errorMessage+"</font>";
        }
        theTextArea.value = theTextArea.value.substring(0, maxChars);
    } else if(remainingChars ==  0) {
        theCounterSpan.innerHTML="<font color='red'>0</font>"
    } else {
        theCounterSpan.innerHTML=remainingChars;
        if(errorMessageSpan != null) {
            errorMessageSpan.innerHTML="";
        }
    }
}

