
var newwin_chat;
function callSupport(strUser, strEmail, strSubject, strMessage, strdeptid, strcsite,strchassis) {		
	
	//var sURL="http://support.ibcjapan.co.jp/setcookie_csite.php?user=" + strUser + "&email=" + strEmail + "&subject=" + strSubject + "&message=" + strMessage + "&deptid=" + strdeptid + "&csite=" + strcsite + "&chassis=" + strchassis+"&siteID=6";
	
	//var sURL="http://192.168.21.143:8082/IBCChat/index.jsp?user_id=NonLogged&siteID=6";
	var sURL="http://chat.ibcjapan.co.jp:8080/IBCChat/index.jsp?siteID=6";
	if (!newwin_chat || newwin_chat.closed) {
		newwin_chat = window.open(sURL,'mywindow', 'status=0,toolbar=0,menubar=0,location=0,screenX=50,screenY=100,width=442,height=390' );

		if(newwin_chat) newwin_chat.focus();
	}
	else{
		if(newwin_chat) newwin_chat.focus();
	}
}

function switchImage(vehicleid, imgSrc, imgScrM) 
	{  
		if (document.images)
		 {	if (imgSrc != "none")
				{ 
					document.images["pic"+vehicleid].src = imgSrc;
					document.getElementById(vehicleid +"_IMAGEPATH_M").value = imgScrM
				}
		}		
	}

function switchSize(vehicleid)
	{		
		var imgScrM = document.getElementById(vehicleid+"_IMAGEPATH_M").value;
		return imgScrM;		
	}

function getUserLocation()
	{
		var temploc=document.getElementById("regionIDlist")
		var optionloc = temploc.options[temploc.selectedIndex].text
		return optionloc
	}	

function showmap()
	{	
		document.getElementById("showmap").style.visibilitiy = "visible";
	}

function dounique()
	{ 
		var date = new Date() ; return date.getTime() ; 
	}

// Hide e-mail from robots
function UsrAtDmn(usr,dmn,className)
	{
		at="@"
		document.write("<a href=\"mailto:" + usr + at + dmn + "\" class=\"" + className + "\">" + usr + at + dmn + "</a>")
	}

function UsrMailChat(usr,dmn,className)
{
		at="@"
		document.write("<a href=\"mailto:" + usr + at + dmn + "\" class=\"" + className + "\">E-mail</a>")
}

	
//Menu Links Button
function MM_preloadImages()
	{
		//v3.0
		var d=document;
		if(d.images)
		{
			if(!d.MM_p) d.MM_p=new Array();
			var i,j=d.MM_p.length,a=MM_preloadImages.arguments;
			for(i=0; i<a.length; i++)
			if (a[i].indexOf("#")!=0)
			{
				d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];
			}
		}
	}
	
function MM_swapImgRestore() 
	{ //v3.0
			var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
	}

function MM_swapImage()
	{ //v3.0
			var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
			if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
	}	

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function body_onload() //not in use
	{
		var cookievalue;
		var value;

			if (cookievalue != null)
			{
				// restore Basic Search settings
				value = getXmlValue(cookievalue, 'SEARCHCRITERIA', 'CHASSIS');
				if (value != null)
					document.vehicleSearch.txtChassis.value = value;
				value = getXmlValue(cookievalue, 'SEARCHCRITERIA', 'MODELGRADE');
				if (value != null)
					document.vehicleSearch.txtModelGrade.value = value;
							
				// restore Preference settings
				value = parseInt(getXmlValue(cookievalue, 'SEARCH', 'INCL_PRICE'));
				if (isNaN(value) == false)
					document.vehicleSearch.optPrices.checked = value == 1;
			}
	}

//On Submit Form Validation

function vehicleSearch_onsubmit(formID)
	{			
		var selectedform = document.getElementById(formID);
		//selectedform.blnFirstTime.value = '0';		
		if (selectedform.optATStockLocation.value == "") 
		{
			if (formID == "basicSearch")
			{
				if (selectedform.qchassis.value != "")
				{				
					return true;
				}
			else
				{
					alert("Please choose the vehicle location");
					return false;
				}
			}
		else
			{
				alert("Please choose the vehicle location");
				return false;
			}			
		}
		else
		{		
			if (formID == "advancedSearch")
			{
			if (!validChassis(selectedform.txtChassis.value))//to check if chassis is valid
				{
					return false;
				}
			else
				{					
					return validateForm(formID);
				}
		}		
			else
			{				
				return validateForm(formID);
			}
		}
		
	}
	
//04/23/2004 - IJC added this function to stripped out invalid characters on a chassisNo
function validChassis(chassisNo)
	{		
		invalidChars = "'"
		var returnString="";
		if (chassisNo == "")
		{
			return true;
	}
		for(i=0; i<chassisNo.length; i++)//stripped out invalid characters
		{
			var c = chassisNo.charAt(i)
			if (invalidChars.indexOf(c) == -1){
				returnString += c;
			}
		}
		document.advancedSearch.txtChassis.value = returnString;
		return true;
	}

function validateForm(formID)
	{			
		var selectedform = document.getElementById(formID);		
		var intKMSmin, intKMSend, intYearStart, intYearEnd, intID;
		if (formID == "basicSearch")
		{
			if ( !valIntTxt(selectedform.txtPriceMin, "First Price in range") ) return false;
			if ( !valIntTxt(selectedform.txtPriceMax, "Second Price in range") ) return false;
			if ( !valLessInt(selectedform.txtPriceMin, "First Price in range", selectedform.txtPriceMax, "Second Price in range")) return false;
			return true;
		}
		else
		{
			if ( !valIntTxt(selectedform.txtKMSMin, "First KMS in range") ) return false;
			if ( !valIntTxt(selectedform.txtKMSMax, "Second KMS in range") ) return false;
			if ( !valLessInt(selectedform.txtKMSMin, "First KMS in range", selectedform.txtKMSMax, "Second KMS in range")) return false;
			if ( !valIntTxt(selectedform.txtPriceMin, "First Price in range") ) return false;
			if ( !valIntTxt(selectedform.txtPriceMax, "Second Price in range") ) return false;
			if ( !valLessInt(selectedform.txtPriceMin, "First Price in range", selectedform.txtPriceMax, "Second Price in range")) return false;
			return true;
		}
	}

function valIntTxt(FormElem, strName)
	{			
		var intValue
		if (FormElem.value == "")
		{				
			intValue = 0;
		}
		else
		{			
			intValue = parseInt(FormElem.value);
			if (isNaN(intValue))
			{
				alert(strName + " must be blank or a number. Can not use: " + FormElem.value);
				return false;
			}
			else
			{
				FormElem.value = intValue; //this takes care of case like "2a" which pass the isNaN test, it takes out bad chars.
			}
		}
		return true;
	}

function valLessInt(txtIntMin, strName1, txtIntMax, strName2)
	{
		var intMin, intMax;
		if (txtIntMin.value != "" && txtIntMax.value != "")
		{
			intMin = parseInt(txtIntMin.value);
			intMax = parseInt(txtIntMax.value);
			if ( intMin > intMax )
				{
				alert(strName1 + " must be less than " + strName2 + " This is not true " + intMin + "<" + intMax);
				return false;
				}
		}
		return true;
	}

function parseLeft(textpls) //not in use
	{
		var int3=0;
		var int4;
		for(int3=0; int3<=textpls.length-1; int3++)
		{
			int4 = escape(textpls.charAt(int3));
			if (int4=='%u2014')
			{
				return textpls.substring(0, int3-1);
				break;
			}
		}
		return "";
	}
	
function checkEnquiry(){
	var name = document.getElementById("name").value;
	var email = document.getElementById("email").value;
	var phoneNum = document.getElementById("phoneNum").value;

	var regionIDlist = document.getElementById("regionIDlist").value;
	var financeOption =document.getElementById("financingOption").value; 
	var tradeOption = document.getElementById("tradein").value;
	var questionText =	document.getElementById("question").value;
	
	//var dealerFlag=document.getElementById("DealerSelect").value;
	var emptyfield = "";
	var spacefield = "";
	
	if (name.charAt(0) == " ") spacefield = (" - Enter Name " + name + "\n");		
	if (name == "") emptyfield += (" - Enter Name " + name + "\n");
		
	if (email != "") {
		if (!CheckStrEmail(email)) return true;
	}else{
		emptyfield += (" - Enter Valid Email " + email + "\n");
	}
	
	if (phoneNum.charAt(0) == " ") spacefield += (" - Enter PhoneNumber " + phoneNum + "\n");
	if (phoneNum == "") emptyfield += (" - Enter Phone Number " + phoneNum + "\n");
	if (regionIDlist == "0") emptyfield += (" - Enter Location \n");
	if (financeOption =="") emptyfield +=  (" - Select Finance Option \n");
	if (tradeOption =="")  emptyfield +=  (" - Select Trade Option \n");
	//if (questionText =="")  emptyfield +=  (" - Enter Comment \n");
	
	//if (dealerFlag == "0") emptyfield += (" - Select a Dealer \n");
	


	var xstring="\n";
	if (emptyfield != "") {
		alert("All Information is required. Please fill up the following empty field(s): \n " + xstring + emptyfield + "");
		}
	else if (spacefield != ""){
		alert("Please remove the space before the field(s) information: \n" + spacefield + "\n");
		}	
	else if (document.getElementById("iddealer").value == "-1")
		alert("Please Select a Dealer");
	else {		
		searchData.SubmitInquiryForm();
	}
}	
	
function PopupImage(strHREF, X, Y)
	{
		if (X == undefined) X = 450;
		if (Y == undefined) Y = 275;
		PopupWin = window.open('', 'mapwin', 'width=' + X + ', height=' + Y)
		PopupWin.document.open()
		PopupWin.document.write('<html><body topmargin="0" leftmargin="0"><center><img src=" ' + strHREF + ' " alt="a car" width="' + X + '" height="'+ Y +'"></img></center></body></html>')
		PopupWin.document.close()
		PopupWin.resizeTo(X, Y + 25)
		PopupWin.focus()
	}
	
 //<!-- Begin -->

function CheckStrEmail(emailStr)
	{
		/* The following pattern is used to check if the entered e-mail address
			fits the user@domain format.  It also is used to separate the username
			from the domain.
		*/

		var emailPat=/^(.+)@(.+)$/;

		/* The following string represents the pattern for matching all special
			characters.  We don't want to allow special characters in the address.
			These characters include ( ) < > @ , ; : \ " . [ ]
		*/

		var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";

		/* The following string represents the range of characters allowed in a
			username or domainname.  It really states which chars aren't allowed.
	   */

		var validChars="\[^\\s" + specialChars + "\]";

		/* The following pattern applies if the "user" is a quoted string (in
			which case, there are no rules about which characters are allowed
			and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
			is a legal e-mail address.
		*/

		var quotedUser="(\"[^\"]*\")";

		/* The following pattern applies for domains that are IP addresses,
			rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
			e-mail address. NOTE: The square brackets are required.
		*/

			var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

		/* The following string represents an atom (basically a series of
			non-special characters.)
		*/

		var atom=validChars + '+';

		/* The following string represents one word in the typical username.
			For example, in john.doe@somewhere.com, john and doe are words.
			Basically, a word is either an atom or quoted string.
		*/

		var word="(" + atom + "|" + quotedUser + ")";

		// The following pattern describes the structure of the user

		var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

		/* The following pattern describes the structure of a normal symbolic
			domain, as opposed to ipDomainPat, shown above.
		*/

		var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

		/* Finally, let's start trying to figure out if the supplied address is valid. */
		/* Begin with the coarse pattern to simply break up user@domain into
			different pieces that are easy to analyze.
		*/

		var matchArray=emailStr.match(emailPat);

		if (matchArray==null)
		{
			/* Too many/few @'s or something; basically, this address doesn't
				even fit the general mould of a valid e-mail address.
			*/
			 
			alert("Email address seems incorrect (check @ and .'s)");
			return false;
		}

		var user=matchArray[1];
		var domain=matchArray[2];

		// See if "user" is valid

		if (user.match(userPat)==null)
		{
			// user is not valid
			//alert("The username doesn't seem to be valid.")
			//use friendlier message
			alert("The email address doesn't seem to be valid.");
			return false;
		}

		/* if the e-mail address is at an IP address (as opposed to a symbolic
			host name) make sure the IP address is valid.
		*/

		var IPArray=domain.match(ipDomainPat);

		if (IPArray!=null)
		{
			// this is an IP address
			for (var i=1;i<=4;i++)
			{
				if (IPArray[i]>255)
				{
					//alert("Destination IP address is invalid!")
					//use friendlier message
					alert("The email address doesn't seem to be valid.");
					return false;
				}
			}
		return true;
		}

		// Domain is symbolic name
		var domainArray=domain.match(domainPat);

		if (domainArray==null)
		{
			//alert("The domain name doesn't seem to be valid.")
			//use friendlier message
			alert("The email address doesn't seem to be valid.");
			return false;
		}

		/* domain name seems valid, but now make sure that it ends in a
		   three-letter word (like com, edu, gov) or a two-letter word,
		   representing country (uk, nl), and that there's a hostname preceding
		   the domain or country.
		*/

		/* Now we need to break up the domain to get a count of how many atoms
		   it consists of.
		*/

		var atomPat=new RegExp(atom,"g");
		var domArr=domain.match(atomPat);
		var len=domArr.length;

		if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3)
		{
		   // the address must end in a two letter or three letter word.
		   //alert("The address must end in a three-letter domain, or two letter country.")
		   //use friendlier message
		   alert("The email address doesn't seem to be valid.");
		   return false;
		}

		// Make sure there's a host name preceding the domain.
		if (len<2)
		{
		   var errStr="This address is missing a hostname!";
		   //alert(errStr)
		   //use friendlier message
		   alert("The email address doesn't seem to be valid.");
		   return false;
		}

		// If we've gotten this far, everything's valid!
		return true;
	}
//  End -->	

/* for menu*/
function setClassName(objId, className) {
    	document.getElementById(objId).className = className;
}
//End-->

//for Quality control page
function Nxtpage(toPageNo){
    document.getElementById("QCMI_Page1").style.display="none";
	document.getElementById("QCMI_Page2").style.display="none"; 
	document.getElementById(toPageNo).style.display="block";
} 


function setHomepage()
{
 if (document.all)
    {
        document.body.style.behavior='url(#default#homepage)';
  document.body.setHomePage('http://www.motohound.co.nz');
 
    }
    else if (window.sidebar)
    {
    if(window.netscape)
    {
         try
   {  
            netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");  
         }  
         catch(e)  
         {  
			alert("Browser can't support said action ,if you want to enable,please enter about:config in your address line, and change the value of signed.applets.codebase_principal_support to true");  
         }
    } 
    var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);
    prefs.setCharPref('browser.startup.homepage','http://www.motohound.co.nz');
 }
}
