function getVal(param)
{
var strURL=param;
var req = getXMLHTTP();
req.open("GET", strURL, false);
req.send(null);
return req.responseText;
}


function getXMLHTTP() {
        var xmlHttp = false;
        if(window.ActiveXObject) {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        else if(window.XMLHttpRequest) {
                xmlHttp = new XMLHttpRequest();
        }else{
                alert("Please upgrade your browser!");
        }
        return xmlHttp;
}

function ge(a){
	return document.getElementById(a);
}

var check;
var checkTotal=0;
var quoteproceed=false;

function valQuote(){
ge('quote_error').innerHTML='';
check = new Array("name","company","tel","email");
checkTotal=0;
//check.forEach(yo,this);
for(var i=0;i<check.length;i++){
	checkinfo(check[i]);
	
}
//alert(checkTotal);
proceed();

}
function valDemo(){
ge('quote_error').innerHTML='';
check = new Array("contact_name","company","tel","email","text_logo1","addr1","addr2","post_code","emailconf","code");
checkTotal=0;
//check.forEach(yo,this);
for(var i=0;i<check.length;i++){
	checkinfo(check[i]);
	
}
//alert(checkTotal);
proceed();

}
function checkinfo(a){
	switch(a){
		case "email":
		
		if(ge(a).value==''){
			ge('quote_error').style.display="block";	
			ge('quote_error').innerHTML+="Please ensure "+a+" is filled in<br>";	
			checkTotal++;
		}else{
			validate(a);
		}
		break;
		case "emailconf":
		if(ge(a).value != ge('email').value){
		
			ge('quote_error').style.display="block";	
			ge('quote_error').innerHTML+="Please ensure both email entries match<br>";	
			checkTotal++;
		}
		break;
		default:
			if(ge(a).value==''){
				ge('quote_error').style.display="block";
				ge('quote_error').innerHTML+="Please ensure "+a+" is filled in<br>";
				checkTotal++;
				//alert("Please ensure "+a+" is filled in");	
			}
		
		break;
		
	}
	
}

function proceed(){
	//alert(checkTotal);
	if(checkTotal==0){
		//alert("Go");
		ge('form').submit();
	}
}

function validate(a) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = ge(a).value;
   if(reg.test(address) == false) {
      //alert('Invalid Email Address');
	  ge('quote_error').style.display="block";
	  ge('quote_error').innerHTML+="Invalid Email Address<br>";
	  checkTotal++;
      //return false;
   }
}

function displayMakes(a){
	//alert(ge('make').innerHTML);
	ge('make').innerHTML='<option value="-1">Populating</option>';
	//ge('make').innerHTML=getVal("/data/makes/"+a);
	//alert(getVal("/data/makes/"+a));	
	$('#make').html(
        getVal("/data/makes/"+a)
    );
}
function displayModels(a){
	//alert(ge('make').innerHTML);
	ge('model').innerHTML='<option value="-1">Populating</option>';
	//$("#model").html();
	//ge('model').innerHTML=getVal("/data/models/"+a);
	//alert("/data/models/"+a);
	$('#model').html(
        getVal("/data/models/"+a)
    );
    


	//alert(getVal("/data/makes/"+a));	
}
function loadDefaults(){
	//if(ge('type')){
		//displayMakes('cars');
	//}
	
	
}
