﻿function ClearDefaultText(FormElement){
    if(FormElement){
        if(FormElement.title){
            if(FormElement.title==FormElement.value) FormElement.value="";
        }
    }
}

function CloseLeaveSiteDialog(){
    var oDiv=document.getElementById("GlobalLeaveSiteLayer");
    if(oDiv){
        oDiv.style.display="none";
    }
}

function LeaveSite(sUrl){
    var oDiv=document.getElementById("GlobalLeaveSiteLayer");
    if(!oDiv){
        var oDiv=document.createElement("div");
        oDiv.id="GlobalLeaveSiteLayer";
        oDiv.style.display="none";
        document.body.appendChild(oDiv);
    }
    var sHtml="<div id=\"GlobalLeaveSiteLayerTop\">" +
            "<div id=\"GlobalLeaveSiteLayerClose\"><a href=\"javascript:CloseLeaveSiteDialog()\"><img src=\"/images/leave-site/leavesite-close.gif\" width=\"67\" height=\"16\" /></a></div>" +
        "</div>" +
        "<div id=\"GlobalLeaveSiteLayerContent\">&nbsp;" +
            "<div id=\"GlobalLeaveSiteLayerText\">" +
                "<b>You are leaving the Honda Automobile Web Site.</b>" +
                "<br /><br />" +
                "The following link is an independent site.<br />" +
                "American Honda Motor Co. Inc., is not responsible for the content presented by any independent Web site, including advertising claims, special offers, illustrations, names or endorsements." +
                "<br /><br />" +
                "Click the link to continue:<br />" +
                "<div class=\"DottedLink\"><a href=\"" + sUrl + "\" target=\"_blank\" onclick=\"CloseLeaveSiteDialog()\">" + sUrl + "</a></div>" + 
                "<br /><br />" +
                "<a href=\"javascript:CloseLeaveSiteDialog()\" onmouseover=\"SwitchImg('GlobalLeaveSiteCancelButton', '/images/_global/buttons/btn-cancel-over.gif')\" onmouseout=\"SwitchImg('GlobalLeaveSiteCancelButton', '/images/_global/buttons/btn-cancel-off.gif')\"><img src=\"/images/_global/buttons/btn-cancel-off.gif\" id=\"GlobalLeaveSiteCancelButton\" width=\"86\" height=\"21\" /></a>" +
            "</div>" +
        "</div>" +
        "<div id=\"GlobalLeaveSiteLayerBottom\"><img src=\"/images/leave-site/leavesite-bottom.gif\" width=\"569\" height=\"14\" /></div>";
    oDiv.innerHTML=sHtml;
    var x=0;
    var y=0;
    var ScrollX=0;
    var ScrollY=0;
    if( typeof( window.innerWidth ) == 'number' ) {
        x = window.innerWidth;
        y = window.innerHeight;
      } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        x = document.documentElement.clientWidth;
        y = document.documentElement.clientHeight;
      } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        x = document.body.clientWidth;
        y = document.body.clientHeight;
      }
      if( typeof( window.pageYOffset ) == 'number' ) {
        ScrollY = window.pageYOffset;
        ScrollX = window.pageXOffset;
      } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        ScrollY = document.body.scrollTop;
        ScrollX = document.body.scrollLeft;
      } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        ScrollY = document.documentElement.scrollTop;
        ScrollX = document.documentElement.scrollLeft;
      }
      oDiv.style.top=(y/2)-(288/2)+ScrollY;
      oDiv.style.left=(x/2)-(569/2)+ScrollX;
      oDiv.style.display="";
    return false;
}

function OnLoadAppend(FunctionCall){
    OnLoadFunctions[OnLoadFunctions.length]=FunctionCall;
}
function OnLoadExecute(){
    for(var i=0; i<OnLoadFunctions.length; i++){
        eval(OnLoadFunctions[i]);
    }
}

function ReturnToLastPage(){
    var sUrl=GetCookie("CurrentURL");
    if(sUrl!="" && sUrl!=null){
        top.location.href=sUrl;
    }else{
        // Redirect user to home page in http since this page may be in https
        sURL = 'http://' + document.location.host + '/';
        top.location.href = sURL;
    }
}

function SwitchImg(ImageName, ImageSrc){
    if(document.getElementById){
        var ImageObj=document.getElementById(ImageName);
        if(ImageObj){
            ImageObj.src=ImageSrc;
        }
    }
}

function SetCookie(name, value) {
    document.cookie = name + "=" + escape( value ) + ";path=/";
}

function GetCookie(name) {
  var cookie=document.cookie;
  var start=cookie.indexOf(name+"=");
  if(start>=0) 
  {
  	var end = document.cookie.indexOf(";", start);
    if (end == -1) end = cookie.length;
  	return unescape(cookie.substring(start + name.length+1,end));
  }
  else return null;
}


// This function will allow a value to be added/replaced in the "CurrentURL" cookie asynchronously
function SetReturnURLParam(name,value)
{
    var rurl=GetCookie("CurrentURL");
    if(rurl.indexOf("?")>0)
	{
		var urlpart=rurl.split("?")[0];
		var nvarray=rurl.split("?")[1].split("&");
		var finalqs="";
		var found=false;
		for(i=0;i<nvarray.length;i++)
		{
			if(nvarray[i].indexOf(name+"=")==0)
			{
				nvarray[i]=name+"="+value;
				found=true;
			}
			if(nvarray[i].length>0) finalqs+=nvarray[i]+"&";
		}
		if(!found) finalqs+=name+"="+value;
		else finalqs=finalqs.substring(0,finalqs.length-1);
		rurl=urlpart+"?"+finalqs;
	}
    else rurl=rurl+"?"+name+"="+value;

    if(!OverrideCookie) SetCookie("CurrentURL",rurl);
    PageURL = rurl;
}

var OnLoadFunctions=new Array();
window.onload=OnLoadExecute;

// Set the "CurrnetURL" cookie to the page's current URL
if(typeof(OverrideCookie)=="undefined") OverrideCookie=false;
if(!OverrideCookie) SetCookie("CurrentURL" , location.href);
var PageURL = location.href;


// In a lot of places, the Model Name is concatenated with the Trim Name
// (e.g. Accord Sedan LX). In some places, the Model Name is repeated in the
// trim name (e.g. Accord Hybrid Hybrid). This function will look for words in the
// Model Name within the Trim Name and remove them (so Accord Hybrid Hybrid becomes
// Accord Hybrid).
function DedupeModelTrim(sModelName , sTrimName) {
 
    // Split ModelName into individual words
    var aModelWords = sModelName.split(" ");
    
    // Split TrimName into individual words
    var aTrimWords = sTrimName.split(" ");
    
    // Loop through all words in the trim name and see if they match any words in the model name.
    // If they do, remove them from the trim name
    for (var iTrimCount = 0; iTrimCount < aTrimWords.length; iTrimCount++) {
        for (var iModelCount = 0; iModelCount < aModelWords.length; iModelCount++) {
            if (aTrimWords[iTrimCount] == aModelWords[iModelCount]) {
                aTrimWords[iTrimCount] = '';
            }
        }
    }
    
    sTrimName = aTrimWords.join(" ");
   

 
    return sTrimName;
}


function GetQueryStringParamValue(parameter) {
		
		var sLocation = location.href;
		var value;
		var index = sLocation.indexOf(parameter + '=');
		
		if ( index < 0){
			value = "";
		}
		else{
			value = sLocation.substring(index+parameter.length+1, sLocation.length);
			
			if ( value.indexOf('&') > -1){
				value = value.substring(0, value.indexOf('&'));
			}
		}
		
		return value;
}

function TagRand() {
    return Math.floor(Math.random()*60000);
}