// JavaScript Document


function CheckForm(){
 var name = document.getElementById('Name');
 var address = document.getElementById('Address');
 var contact = document.getElementById('Contact'); 
 var orders = document.getElementById('Order(s)');
 
 	if(CheckName(name,"Your Name is required")){
		return false;
	}
	
	else if(CheckAddress(address,"Your Address is required")){
		return false;
	}
	
	else if(CheckContact(contact,"Your Contact Number is required")){
		return false;
	}
	
	else if(CheckOrders(orders,"Please leave a message")){
		return false;
	}
	
	return true;
}


function CheckName(elem,msg){
	if(elem.value.length == 0){
		alert(msg);
		elem.focus(); // set the focus to this input
		return true;
	}
	else
	return false;
}

function CheckAddress(elem,msg){
	if(elem.value.length == 0){
		alert(msg);
		elem.focus(); // set the focus to this input
		return true;
	}
	return false;
}

function CheckContact(elem,msg){
	if(elem.value.length == 0){
		alert(msg);
		elem.focus(); // set the focus to this input
		return true;
	}
	return false;
}

function CheckOrders(elem,msg){
	if(elem.value.length == 0){
		alert(msg);
		elem.focus(); // set the focus to this input
		return true;
	}
	return false;
}

function focusmoto(a,b,bg){
	a.style.borderColor = b;
	a.style.backgroundColor = bg;
}

function blurmoto(a,b,bg){
	a.style.borderColor = b;
	a.style.backgroundColor = bg;
}

 function loading() {
            var l = document.getElementById('Loading'); // Find the loading object
            l.innerHTML = "<img src='../images/ajax-loader1.gif' >"; // Display some feedback during the process
            ajaxFunction();           
 }


//Browser Support Code

function ajaxFunction(a){
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			var ajaxDisplay = document.getElementById('msg');
			ajaxDisplay.innerHTML = ajaxRequest.responseText;
			var l = document.getElementById('Loading');
            l.innerHTML = ''; // Clear the feedback

		}else if(ajaxRequest.readyState == 3){
			
		}
	}
	var sel = document.getElementById('Total').value;

	var queryString = "?am=" + sel;
	ajaxRequest.open("GET", "../validate.php" + queryString, true);
	ajaxRequest.send(null); 
}