
function sendRequest(request,url,statusChange){
	request.onreadystatechange = statusChange;
	request.open("GET", url, true);
	request.send(null);
}


function updateAudio(tog, tb){
	if(tb=="b"){ option = "b"; } else { option = "t"; }
	sendRequest(request1,"../_portions/audio.php?function="+tog, updateConnect);
}


function getModels(make, tb){
	if(tb=="b"){ option = "b"; } else { option = "t"; }
	sendRequest(request1,"../_portions/models.php?make="+make, updateModels);
}

function getModelsNoJump(make, tb){
	if(tb=="b"){ option = "b"; } else { option = "t"; }
	sendRequest(request1,"../_portions/models.php?make="+make+"&jumpMode=1", updateModels);
}

function updateModels(){
	if(request1.readyState == 4){
		if(request1.status == 200){
			document.getElementById('models').innerHTML=request1.responseText;
			request1.abort();
		}
	}
}

function slideHide(what, tb){
	if(tb=="b"){ option = "b"; } else { option = "t"; }
	instantHide = new fx.Height(what, {duration: 400});
	hideSwitch = new fx.Height(what, {duration: 400});
	setTimeout("hideSwitch.toggle();", 30);
	setTimeout("instantHide.toggle();", 30);
}

function showhide(id){ 
	if (document.getElementById){ 
		obj = document.getElementById(id);
		if (obj.style.display == "none"){ 
			obj.style.display = ""; 
		} else { 
			obj.style.display = "none"; 
		}
	} 
}


function go(where){ location.href = where; }

function getCart(here, tb){
	if(tb=="b"){ option = "b"; } else { option = "t"; }
	sendRequest(request2,"../_portions/showCart.php?location="+here, updateConnect);
	scrollDivToAnchor("connect");
}

function addToCart(id){

	if(id=="blank"){
		var req="../_portions/closedCart.php";
	} else {
		var qty = document.getElementById('qty').value;
		var req = "../_portions/closedCart.php?new="+id+"&quantity="+qty
	}
	
	sendRequest(request2, req, updateConnect);
}

function getsendToFriend(here, tb){
	if(tb=="b"){ option = "b"; } else { option = "t"; }
	sendRequest(request2,"../_portions/sendToFriend.php?location="+here, updateConnect);
	scrollDivToAnchor("connect");
}

function getjoin(here, tb){
	if(tb=="b"){ option = "b"; } else { option = "t"; }
	sendRequest(request2,"../_portions/mailinglist.php?location="+here, updateConnect);
	scrollDivToAnchor("connect");
}

function getfeedback(here, tb){
	if(tb=="b"){ option = "b"; } else { option = "t"; }
	sendRequest(request2,"../_portions/contact.php?location="+here, updateConnect);
	scrollDivToAnchor("connect");
}

function getlinks(here, tb){
	if(tb=="b"){ option = "b"; } else { option = "t"; }
	sendRequest(request2,"../_portions/links.php?location="+here, updateConnect);
	scrollDivToAnchor("connect");
}

function getcontact(here, tb){
	if(tb=="b"){ option = "b"; } else { option = "t"; }
	sendRequest(request2,"../_portions/contact.php?location="+here, updateConnect);
	scrollDivToAnchor("connect");
}

function getdealer(here, tb){
	if(tb=="b"){ option = "b"; } else { option = "t"; }
	sendRequest(request2,"../_portions/dealerForm.php?location="+here, updateConnect);
	scrollDivToAnchor("connect");
}


function sendcontact(){
	var form = "form";
	var getstr = "checks=";
	var getstr2 = "";
	var obj = document.forms[form].length;
	var checks = document.forms[form];
	for(i=0; i < obj; i++){
		
		if(checks.elements[i].type=="checkbox" && checks.elements[i].checked){
			getstr += checks.elements[i].name;
			getstr += ",";		
		}
		
		if(checks.elements[i].type=="radio" && checks.elements[i].checked){
			var action = checks.elements[i].value;
		}
		
		if(checks.elements[i].type=="text" | checks.elements[i].type =="textarea" | checks.elements[i].type =="select-one"){
			getstr2 += "&"+checks.elements[i].name+"="+encodeURIComponent(checks.elements[i].value);
		}
	}
	
	if(getstr != "checks=" | getstr != "checks=malinglist" | getstr2 !=null){
		getstr = getstr.substring(0,(getstr.length)-1);
		sendRequest(request2,"../_portions/contact.php?"+getstr+getstr2, updateConnect);
	} else {
		alert ("A topic, your name and a valid email address are required.");
	}
}


function sendpaulwall(){

	var req = 7;
	var form = "form";
	var getstr2 = "";
	var obj = document.forms[form].length;
	var checks = document.forms[form];
	for(i=0; i < obj; i++){
		if(checks.elements[i].type=="text" && checks.elements[i].value !="Your Name" && checks.elements[i].value !="Your Email" && checks.elements[i].value !="Your City"){
			getstr2 += "&"+checks.elements[i].name+"="+encodeURIComponent(checks.elements[i].value);
			req--;
		}else if(checks.elements[i].type=="select-one" && checks.elements[i].value != "State" && checks.elements[i].value != "0"){
			getstr2 += "&"+checks.elements[i].name+"="+encodeURIComponent(checks.elements[i].value);
			req--;
		}
	}

	if(getstr2!="" && req=="0"){
		//alert(getstr2);
		sendRequest(request3,"../_portions/paulwall.php?"+getstr2, updatepwForm);
	} else {
		alert('All fields are required');
	}
}


function sendtofriends(){
	var form = "form";
	var getstr = "";
	var obj = document.forms[form].length;
	var checks = document.forms[form];
	for(i=0; i < obj; i++){
		if(checks.elements[i].type=="text" | checks.elements[i].type=="hidden" | checks.elements[i].type=="textarea"){
			
			if(checks.elements[i].value != "Friends Email" && checks.elements[i].value != "Friends Name"){
				getstr += "&"+checks.elements[i].name+"="+encodeURIComponent(checks.elements[i].value);
			}
		}
	}
	
	if(getstr != ""){
		sendRequest(request2,"../_portions/sendtofriend.php?"+getstr, updateConnect);
	} else {
		alert ("A topic, your name and a valid email address are required.");
	}

}


function sendmailinglist(){
	
	var form = "form";
	var getstr2 = "";
	var obj = document.forms[form].length;
	var checks = document.forms[form];
	for(i=0; i < obj; i++){
		if(checks.elements[i].type=="text"){
			getstr2 += "&"+checks.elements[i].name+"="+encodeURIComponent(checks.elements[i].value);
		}
	}
	
	if(getstr2!=""){
		sendRequest(request2,"../_portions/mailinglist.php?"+getstr2, updateConnect);
	} else {
		alert ("Your name and a valid email address are required.");
	}

}


function getDealers(term){
	if(term=='term'){
		var search = document.getElementById('term').value;
		sendRequest(request2,"../_portions/dealer.php?term="+search, updateConnect);
	}else{
		sendRequest(request2,"../_portions/dealer.php?country="+term, updateConnect);
	}
}

function closeAjax() {
	document.getElementById('connect').innerHTML="";
	document.getElementById('connectB').innerHTML="";
}

function updateConnect(){

	if(option == "b"){
		if(request2.readyState == 1){ document.getElementById('connectB').innerHTML="<div class=\"clearGray\"><div class=\"topCornerB\"></div><div class=\"bottomCornerB\"></div>Updating...</div>"; }
		if(request2.readyState == 4){
			if(request2.status == 200){

				document.getElementById('connectB').innerHTML="<div><div class=\"topCornerG\"></div><div class=\"bottomCornerG\"></div>";
				document.getElementById('connectB').innerHTML+=request2.responseText;
				document.getElementById('connectB').innerHTML+="<div class=\"close\"><a onclick=\"closeAjax()\">close</a></div></div>";
				document.getElementById('connect').innerHTML="";
				request2.abort();
			}
		}
	
	} else {
	
		if(request2.readyState == 1){ document.getElementById('connect').innerHTML="<div class=\"clearGray\"><div class=\"topCornerB\"></div><div class=\"bottomCornerB\"></div>Updating...</div>"; }
		if(request2.readyState == 4){
			if(request2.status == 200){
				document.getElementById('connect').innerHTML="<div><div class=\"topCornerG\"></div><div class=\"bottomCornerG\"></div>";
				document.getElementById('connect').innerHTML+=request2.responseText;
				document.getElementById('connect').innerHTML+="<div class=\"close\"><a onclick=\"closeAjax()\">close</a></div></div>";
				document.getElementById('connectB').innerHTML="";
				request2.abort();
			}
		}
	}
}

function updatepwForm(){
	if(request3.readyState == 4){
		if(request3.status == 200){
			document.getElementById('pwForm').innerHTML=request3.responseText;
			request3.abort();
		}
	}
}

function scrollDivToAnchor(anch) {
	var dest = anch;
}


option = "t"