function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

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_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_findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.getElementById(n); return x;
}

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 openfriendwin()
{
	day = new Date();
	id = day.getTime();

	//var mainURL = escape(getmainURL());
	//var mainTitle = getmainTitle();
	var mainURL = escape(location.href);
	var mainTitle = get_title_tag();
	var url = "/scripts/friend.php?Page=" + mainURL + "&Title=" + mainTitle;
	//alert(url);
	window.open(url,'id', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=550,height=600');
}

function get_title_tag()
{
	var t = document.getElementsByTagName('title')[0];
	if ( !!t.childNodes.length ) 
	{
		return t.firstChild.data;
	} 
	else if ( t.innerHTML ) 
	{
		return t.innerHTML;
	}
}

function contactus()
{
	day = new Date();
	id = day.getTime();

	var mainURL = escape(getmainURL());
	var mainTitle = getmainTitle();
	var frame = getmainFrame();

	var url = "/scripts/form1.php?referrer=" + mainURL + "&title=" + mainTitle;
	//alert(url);
	top.window.location.href = url;
}

function quoteme()
{
	day = new Date();
	id = day.getTime();

	var mainURL = escape(getmainURL());
	var mainTitle = getmainTitle();
	var frame = getmainFrame();

	var url = "/scripts/form1.php?Include_Basket=TRUE&referrer=" + mainURL + "&title=" + mainTitle;
	//alert(url);
	top.window.location.href = url;
}

function feedback()
{
	day = new Date();
	id = day.getTime();

	var mainURL = escape(location.href);
	var mainTitle = get_title_tag();

	var url = "/scripts/feedbackform.php?referrer=" + mainURL + "&title=" + mainTitle;
	//alert(url);
	window.open(url,'id', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=650,height=600');
}


function lTrim(sString)
{
	if (sString != undefined)
	{
		while (sString.substring(0,1) == ' ')
		{
			sString = sString.substring(1, sString.length);
		}
	}
	return sString;
}



function rTrim(sString)
{
	if (sString != undefined)
	{
		while (sString.substring(sString.length-1, sString.length) == ' ')
		{
			sString = sString.substring(0,sString.length-1);
		}
	}
	return sString;
}

function trim(sString)
{
	if (sString != undefined)
	{
		while (sString.substring(0,1) == ' ')
		{
			sString = sString.substring(1, sString.length);
		}
		while (sString.substring(sString.length-1, sString.length) == ' ')
		{
			sString = sString.substring(0,sString.length-1);
		}
	}
	return sString;
}


var xmlHttp;

function GetXmlHttpObject()
{
	var xmlHttp=null;
	
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
		//	alert("Mozilla");
	}
	catch (e)
	{
		//Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			//	alert("IE");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			//	alert("IEError");
		}
	}
	
	return xmlHttp;
}

function populate_model()
{
	var make;
	make = document.getElementById('query1').value;
	//alert(make);
	var emulate;
	emulate = document.getElementById('emulate').value;
	//alert(emulate);
	pop_model(make, emulate);
}

function pop_model(make, emulate)
{ 
	xmlHttp=GetXmlHttpObject();
	
	//alert(make);
	
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	
	var url="/scripts/rbvehsel_dd2.php?";
	url=url+"&query1="+make+"&emulate="+emulate;
	
	//alert(url);
	xmlHttp.onreadystatechange = NewModelSel;
	
	xmlHttp.open("GET",url,true)
	
	xmlHttp.send(null)
}

function NewModelSel() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		document.getElementById('vs_model').innerHTML = xmlHttp.responseText;
		//var content = document.getElementById('vs_model').innerHTML;
		//alert(content);
	}
}

function makevisible(cur,which){
//Highlight image script- By Dynamic Drive
//For full source code and more DHTML scripts, visit http://www.dynamicdrive.com
//This credit MUST stay intact for use
strength=(which==0)? 1 : 0.2

if (cur.style.MozOpacity)
cur.style.MozOpacity=strength
else if (cur.filters)
cur.filters.alpha.opacity=strength*100
}

function Apply_roof_bar_checker(Form)
{
	var formname = Form.name;
	var Element;
	var i;
	var type;
	var className;
	var checked;
	var className_counter = 0;
	var checked_counter = 0;
	
	//alert(formname);
	
	for(i = 0; i < Form.length; i++)
	{
		Element = Form.elements[i];
		type = Element.type;
		className = Element.className;
		checked = Element.checked;
		
		if(type == "checkbox")
		{
			//alert(type);
			//alert(className);
			if(className == "Apply_roof_bar_checker")
			{
				//alert(className);
				className_counter = className_counter + 1;
				if(checked)
				{
					checked_counter = checked_counter + 1;
				}
			}
		}
	}
	
	if((className_counter > 0) && (checked_counter > 1))
	{
		alert("You only need one pair of bars so if you don't want both sets please untick one set");
	}
	return true;
}

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);
// cook = document.cookie;
 
 document.cookie = cookieName+"="+escape(cookieValue)
//                 + ";expires="+expire.toGMTString()
                 + ";path=/";
}

function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    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;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

// ====================================================================
//       URLEncode and URLDecode functions
//
// Copyright Albion Research Ltd. 2002
// http://www.albionresearch.com/
//
// You may copy these functions providing that 
// (a) you leave this copyright notice intact, and 
// (b) if you use these functions on a publicly accessible
//     web site you include a credit somewhere on the web site 
//     with a link back to http://www.albionresarch.com/
//
// If you find or fix any bugs, please let us know at albionresearch.com
//
// SpecialThanks to Neelesh Thakur for being the first to
// report a bug in URLDecode() - now fixed 2003-02-19.
// ====================================================================
function URLEncode( plaintext)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

//	var plaintext = document.URLForm.F1.value;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

//	document.URLForm.F2.value = encoded;
	return encoded;
};

function URLDecode( )
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var encoded = document.URLForm.F2.value;
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while
   document.URLForm.F1.value = plaintext;
   return false;
};
