function popupWin(page, width, height) {
	winprops = "toolbar=0,status=1,scrollbars=1,resizable=1,width=" + width + ", height=" + height;
	popup = window.open( page, "popup", winprops);
	popup.focus();
}

// Only allow numbers, return, and backspace in a text field.  Usage: onKeyPress="return only_numbers(event);"
function only_numbers(event) {
	var key;
	if (window.event) {
		key = window.event.keyCode;
	} else if (event) {
		key = event.which;
	} else {
		return true;
	}
	if(key >= 48 && key <= 57 || key == 8 || key == 13) {
		return true;
	} else {
		return false;
	}
}

function dealerLocatorBoxSwitch(el, type)
{
  if(type)
  {
    el.value = "";
    el.maxLength = 5;
    el.style.backgroundColor = "#cfc";
  } else{
    el.maxLength = 10;
    el.style.backgroundColor = "";
  }
}

// Lets us mail using js and doesn't show for spammers
function mailto(user,domain,subject) { 
   email = "mailto:" + user + "@" + domain; 
   if(subject) { email += "?subject=" + subject; }
   window.location = email; 
}

// these are just a quick way to hide the 360 view iframe when the menu hovers over.
function hideDiv()
{
	if (document.getElementById("hideMePlease") != null)
	{
		document.getElementById("hideMePlease").className = "hideMe";
		return true;
	}	
}
function showDiv()
{
	if (document.getElementById("hideMePlease") != null)
	{
		document.getElementById("hideMePlease").className = "showMe";
		return true;
	}	
}

/* add onLoad event */
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

/* XHConn.js */

/** XHConn - Simple XMLHTTP Interface - bfults@gmail.com - 2005-04-08        **
 ** Code licensed under Creative Commons Attribution-ShareAlike License      **
 ** http://creativecommons.org/licenses/by-sa/2.0/                           **/
function XHConn()
{
  var xmlhttp, bComplete = false;
  try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
  catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
  catch (e) { try { xmlhttp = new XMLHttpRequest(); }
  catch (e) { xmlhttp = false; }}}
  if (!xmlhttp) return null;
  this.connect = function(sURL, sMethod, sVars, fnDone)
  {
    if (!xmlhttp) return false;
    bComplete = false;
    sMethod = sMethod.toUpperCase();

    try {
      if (sMethod == "GET")
      {
        xmlhttp.open(sMethod, sURL+"?"+sVars, true);
        sVars = "";
      }
      else
      {
        xmlhttp.open(sMethod, sURL, true);
        xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
        xmlhttp.setRequestHeader("Content-Type",
          "application/x-www-form-urlencoded");
      }
      xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4 && !bComplete)
        {
          bComplete = true;
          fnDone(xmlhttp);
        }};
      xmlhttp.send(sVars);
    }
    catch(z) { return false; }
    return true;
  };
  return this;
}

/* nav_top_fly_out.js */

/* assuming you already have XHConn.js included in your HTML file */
var navFlyOutModel = null;
//var elNavFlyOutModel = null;
var navFlyOutPrefix = "flyOut_";
var navFlyOutIDPrefix = "navTop_";

var HTTPRequestConn = new XHConn();
if (!HTTPRequestConn) alert("XMLHTTP not available. Try a newer/better browser. How about www.getfirefox.com");

var loadFlyOut = function(oXML)  
{
  var temp = oXML.responseText;
//  alert(document.getElementById(navFlyOutPrefix + navFlyOutModel + "").id);
  document.getElementById(navFlyOutPrefix + navFlyOutModel + "").innerHTML = temp;
  if( self.ieHover )
  	ieHover();//setTimeout("ieHover()",50);
}
  
var getFlyOutModelContents = function (navFlyOutModel)
{
  var url = "" + window.location;
  if( url.search(/secure\.suzuki\.com/) != -1 ) { 
  	HTTPRequestConn.connect("../_includes/top_nav_fly_out_loader.php", "GET", "navmodel=" + navFlyOutModel, loadFlyOut);
  } else {
    HTTPRequestConn.connect("/_includes/top_nav_fly_out_loader.php", "GET", "navmodel=" + navFlyOutModel, loadFlyOut);
  }
}

var doFlyOut = function(modelID)
{
  navFlyOutModel = modelID.replace(navFlyOutIDPrefix, "");
  var elNavFlyOutModel = document.getElementById(navFlyOutPrefix + navFlyOutModel);
  //alert(elNavFlyOutModel.id);
  if(elNavFlyOutModel.innerHTML != "") { return; }
  getFlyOutModelContents(navFlyOutModel);
}


function SetCookie(cookieName,cookieValue,nDays) {
	var today = new Date();
	var expire = new Date();
	if (nDays==null || nDays==0) nDays=1;
	expire.setTime(today.getTime() + 3600000*24*nDays);
	document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString() + "; path=/; domain=suzukiauto.com";
}

function chooseHigh() {
	SetCookie("UserPrefBandwidth", "high", 365); // set cookie
	
	if (typeof deactivate != 'undefined') { deactivate(); }	// hide box
}

function chooseLow() {
	SetCookie("UserPrefBandwidth", "low", 365); // set cookie
	
	if (typeof lite_url == 'undefined') {
		var locate = '' + window.location; // make it a string
		var myReg = new RegExp("^(https?://)(.*)?suzukiauto.com(.*)?");
		locate = locate.replace(myReg,"$1" + "ww1." + 'suzukiauto.com' + "$3" );
	} else {
		var locate = lite_url;
	}
	//alert(locate);
	window.location = locate; // redirect to low domain
}