// JavaScript Document


var xmlHttp;
var load_style = "background-color:red;color:#ffffff;font-size:12px;font-weight:bold;";
function showModel(str){
	if (str.length==0)	{ 
		document.getElementById("areaModel").innerHTML="";
		return;
	}
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)	{
		alert ("Browser does not support HTTP Request");
		return;
	} 
	document.getElementById("areaModel").innerHTML="<img src='http://www.funkymotors.ie/images/loading.gif' /> <b>loading..</b>";
	var url="http://www.funkymotors.ie/includes/getModel.php";
	url=url+"?make="+str;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged ;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
} 
//show model home
function showModel_home(str){
	if (str.length==0)	{ 
		document.getElementById("areaModel").innerHTML="";
		return;
	}
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)	{
		alert ("Browser does not support HTTP Request");
		return;
	} 
	document.getElementById("areaModel").innerHTML="<img src='http://www.funkymotors.ie/images/loading.gif' /> <b>loading..</b><br />";
	var url="http://www.funkymotors.ie/includes/getModel_home.php";
	url=url+"?make="+str;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged ;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
} 
//end show model home
//show model home txt
function showModel_home_txt(mk,str){
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)	{
		alert ("Browser does not support HTTP Request");
		return;
	} 
	document.getElementById("home_car_models").innerHTML="<p><img src='http://www.funkymotors.ie/images/loading.gif' /> <b>Loading Models Available for "+mk+"..</b></p>";
	var url="http://www.funkymotors.ie/includes/getModel_home_txt.php";
	url=url+"?mk="+mk+"&make="+str;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange = stateChanged_home_txt ;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
} 
function stateChanged_home_txt() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		document.getElementById("home_car_models").innerHTML = xmlHttp.responseText ;
	} 
}
//end show model home txt
function showModel_ad_car(str){
	if (str.length==0)	{ 
		document.getElementById("areaModel").innerHTML="";
		return;
	}
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)	{
		alert ("Browser does not support HTTP Request");
		return;
	} 
	document.getElementById("areaModel").innerHTML="<img src='http://www.funkymotors.ie/images/loading.gif' /> <b>loading models</b><br />";
	var url="http://www.funkymotors.ie/includes/getModel_ad_car.php";
	url=url+"?make="+str;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged ;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
} 
function stateChanged() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		document.getElementById("areaModel").innerHTML=xmlHttp.responseText ;
	} 
}
//car location
function showLocation(str,str1){
	if (str.length==0)	{ 
		document.getElementById("v_carlocation").innerHTML="";
		return;
	}
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)	{
		alert ("Browser does not support HTTP Request");
		return;
	} 
	document.getElementById("v_carlocation").innerHTML="<img src='http://www.funkymotors.ie/images/loading.gif' /> <b>loading..</b>" ;
	var url="http://www.funkymotors.ie/includes/getModel.php";
	url=url+"?make="+str;
	url=url+"&y_car_model="+str1;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange= function () { 
									if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
										document.getElementById('v_carlocation').innerHTML=xmlHttp.responseText ;
									} 
								} ;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
} 
//car sale search function
function showSearchForm(divid){
	if (divid.length==0)	{ 
		document.getElementById(divid).innerHTML="";
		return;
	}
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)	{
		//send to the search page
		window.location = "http://www.funkymotors.ie/Search-Used-Cars.html";
		//alert ("Browser does not support HTTP Request");
		return;
	} 
	document.getElementById(divid).innerHTML="<div style='background-color:red; color:#ffffff;padding:3px; border:1px solid #000000;font-size:14px;'><img src='http://www.funkymotors.ie/images/loading.gif' /> <b>Loading Search Form...</b></div>" ;
	var url="http://www.funkymotors.ie/includes/_x_car_sale_form.php";
	url=url+"?sid="+Math.random();
	xmlHttp.onreadystatechange= function () { 
									if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
										document.getElementById(divid).innerHTML=xmlHttp.responseText ;
									} 
								}; 
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
} 


//cart function
var bustcachevar=1; //bust potential caching of external pages after initial request? (1=yes, 0=no)
var loadedobjects="";
var rootdomain="http://"+window.location.hostname;
var bustcacheparameter="";

function getcontent(url, containerid){
var page_request = false;
	page_request = GetXmlHttpObject();
	//get div id
	  if ( url.indexOf("?") > -1 ){
		var strQueryString = url.substr(url.indexOf("?")).toLowerCase();
		var aQueryString = strQueryString.split("&");
		for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
		  if (aQueryString[iParam].indexOf("p_s_id" + "=") > -1 ){
			var aParam = aQueryString[iParam].split("=");
			strReturn = aParam[1];
			break;
		  }
		}
	  }
	var qs_pid = "added" + strReturn;	
	//
	
	document.getElementById(containerid).innerHTML = '....';
	page_request.onreadystatechange=function(){
		loadpage(page_request, containerid, qs_pid);
	}
	
	if (bustcachevar) //if bust caching of external page
		bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime();
		page_request.open('GET', url+bustcacheparameter, true);
		page_request.send(null);
}

function loadpage(page_request, containerid, qs_pid){ 
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
	
	//document.getElementById(containerid).innerHTML = '<div id="loading">Please wait while loading the products...</div>';
	//document.getElementById(containerid).onLoading=function(){whenLoading(containerid);}
	document.getElementById(containerid).innerHTML=page_request.responseText;
	document.getElementById(containerid).innerHTML="&nbsp;<a href='http://www.funkymotors.ie/shopping_cart.php' title='view shopping cart'><img src='http://www.funkymotors.ie/images/icons/shopping_cart_full_sq.gif' alt='view shopping cart' border='0' /></a>";
	document.getElementById(qs_pid).innerHTML = "<br />&nbsp;&nbsp;Product added to your shopping cart. <a href='http://www.funkymotors.ie/shopping_cart.php' title='view shopping cart'><img src='http://www.funkymotors.ie/images/btn_view_cart.gif' border='0' /></a>";
	document.getElementById(qs_pid).style.display = "block";
}

//end cart function
function GetXmlHttpObject(){ 
	var objXMLHttp=null;
	if (window.XMLHttpRequest)	{
		objXMLHttp=new XMLHttpRequest();
	}else if (window.ActiveXObject){
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	return objXMLHttp;
} 
//other functions
function whenLoading(div){
var e = document.getElementById(); 
e.innerHTML = "<p style='"+load_style+"'>Sending Data...</p>";
}

function whenLoaded(div){
	var e = document.getElementById(); 
	e.innerHTML = "<p style='"+load_style+"'>Data Sent...</p>";
}

function whenInteractive(div){
	var e = document.getElementById(); 
	e.innerHTML = "<p style='"+load_style+"'>getting data...</p>";
}
//function for the home page search bar
function ewd_getcontent(url, containerid){
		xmlhttp_obj = new GetXmlHttpObject();
	document.getElementById(containerid).innerHTML="<img src='http://www.funkymotors.ie/images/loading.gif' /> <b>Loading Data...</b>";
	xmlhttp_obj.onreadystatechange=function(){
		ewd_loadpage(xmlhttp_obj, containerid);
	}
	xmlhttp_obj.open('GET', url, true);
	xmlhttp_obj.send(null);
}

function ewd_loadpage(xmlhttp_obj, containerid){
	if ( xmlhttp_obj.readyState == 4 && xmlhttp_obj.status==200 )
		document.getElementById(containerid).innerHTML=xmlhttp_obj.responseText;
}	