var req;
if(window.XMLHttpRequest){
//For Firefox, Safari, Opera
req = new XMLHttpRequest();
}
else if(window.ActiveXObject){
//For IE 5
req = new ActiveXObject("Microsoft.XMLHTTP");
} else if(window.ActiveXObject){
//For IE 6+
req = new ActiveXObject("Msxml2.XMLHTTP");
}
else{
//Error for an old browser
alert('Your browser is not IE 5 or higher, or Firefox or Safari or Opera');
}

// AJAX OBJECT 
function getXMLHTTP() { 
		var xmlhttp=false;	
		try{
			xmlhttp=new XMLHttpRequest();
		}
		catch(e)	{		
			try{			
				xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e){
				try{
				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch(e1){
					xmlhttp=false;
				}
			}
		}
		 	
		return xmlhttp;
    }

// FIND COURSE LOCATION
function select_course() {		
		 var selectBox = document.home_form.course_id;
		 var course_id = selectBox.options[selectBox.selectedIndex].value;
		 var strURL="ajax/course_location.php?course_id="+course_id;
		 var req = getXMLHTTP();
		
		if (req) {
			
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {						
						document.getElementById('loc').innerHTML=req.responseText;						
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}		
	}


//FIND DATE FOR LOCATION
function select_date() {		
		  var selectBox = document.home_form.location_id;
         var location_id = selectBox.options[selectBox.selectedIndex].value;

         var selectBox = document.home_form.course_id;
		 var course_id = selectBox.options[selectBox.selectedIndex].value;
         var strURL="ajax/course_location_date.php?course_id="+course_id+"&location_id="+location_id;
		 var req = getXMLHTTP();
		
		if (req) {
			
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {						
						document.getElementById('dat').innerHTML=req.responseText;						
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}		
	}

//	SUBMIT COURSE

   function submit_course()
   {
         var selectBox = document.home_form.location_id;
         var location_id = selectBox.options[selectBox.selectedIndex].value;
		 var selectBox = document.home_form.date_avail_id;
         var date_avail_id = selectBox.options[selectBox.selectedIndex].value;
         var selectBox = document.home_form.course_id;
		 var course_id = selectBox.options[selectBox.selectedIndex].value;
         var strURL="ajax/submit_course.php?course_id="+course_id+"&location_id="+location_id+"&date_avail_id="+date_avail_id;
		 var req = getXMLHTTP();
		
		if (req) {
			
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {				
						document.getElementById('sub').innerHTML=req.responseText;						
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}		

   }
function  selectdetails()
{
alert("Please Select Location and Available dates First.");
return false;
}

	function join_courses(type_id,course_id) {		
		 var selectBox = document.join_course_form.location_id;
		 var location_id = selectBox.options[selectBox.selectedIndex].value;
		 var strURL="ajax/selected_location_date.php?location_id="+location_id+"&type_id="+type_id+"&course_id="+course_id;
		 var req = getXMLHTTP();
		
		if (req) {
			
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {					
						document.getElementById('statediv').innerHTML=req.responseText;						
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}		
	}
	function selected_date(type_id,course_id) {	
       
	    var selectBox = document.join_course_form.available_id;
		var available_id = selectBox.options[selectBox.selectedIndex].value;
		 var selectBox = document.join_course_form.location_id;
		 var location_id = selectBox.options[selectBox.selectedIndex].value;
		 select_price(type_id,course_id,location_id);
		 var strURL="ajax/selected_date_payment.php?available_id="+available_id+"&type_id="+type_id+"&course_id="+course_id+"&location_id="+location_id;
		var req = getXMLHTTP();
		
		if (req) {
			
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {						
						document.getElementById('citydiv').innerHTML=req.responseText;						
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}
				
	}
function select_price(type_id,course_id,location_id) {	
	    var selectBox = document.join_course_form.available_id;
		var available_id = selectBox.options[selectBox.selectedIndex].value;	
		var strURL="ajax/selected_date_price.php?available_id="+available_id+"&type_id="+type_id+"&course_id="+course_id+"&location_id="+location_id;
		var req = getXMLHTTP();
		
		if (req) {
			
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {						
						document.getElementById('pricediv').innerHTML=req.responseText;						
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}
				
	}
function validation12(p)
{
if (document.getElementById("first_name_id").value == "")
 {
  hideAllErrors();
  document.getElementById('first_name_Error').innerHTML = "Required: Please enter your First Name!";
  document.getElementById("first_name_id").select();
  document.getElementById("first_name_id").focus();
  return false;
 }
else if (document.getElementById("last_name_id").value == "")
 {
  hideAllErrors();
  document.getElementById('last_name_Error').innerHTML = "Required: Please enter your Last Name!";
  document.getElementById("last_name_id").select();
  document.getElementById("last_name_id").focus();
  return false;
 }

else if (document.getElementById("address_line1_id").value == "")
 {
   hideAllErrors();
   document.getElementById("address_line1_Error").innerHTML = "Required: Please enter your Address!";
   document.getElementById("address_line1_id").select();
   document.getElementById("address_line1_id").focus();
   return false;
  }
else if (document.getElementById("address_line2_id").value == "")
 {
   hideAllErrors();
   document.getElementById("address_line2_Error").innerHTML = "Required: Please enter your Address!";
   document.getElementById("address_line2_id").select();
   document.getElementById("address_line2_id").focus();
   return false;
  }
else if (document.getElementById("post_code_id").value == "")
 {
   hideAllErrors();
   document.getElementById("post_code_Error").innerHTML = "Required: Please enter post code!";
   document.getElementById("post_code_id").select();
   document.getElementById("post_code_id").focus();
   return false;
  }
else if (document.getElementById("telephone_id").value == "")
 {
   hideAllErrors();
   document.getElementById("telephone_Error").innerHTML = "Required: Please enter post code!";
   document.getElementById("telephone_id").select();
   document.getElementById("telephone_id").focus();
   return false;
  }
else if (document.getElementById("email_id").value == "")
 {
   hideAllErrors();
   document.getElementById("email_Error").innerHTML = "Required: Please enter email!";
   document.getElementById("email_id").select();
   document.getElementById("email_id").focus();
   return false;
  }
else  if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById("email_id").value)))
 {
        hideAllErrors();
         document.getElementById("email_Error").innerHTML = "Invalid Email Address!";
         document.getElementById("email_id").select();
         document.getElementById("email_id").focus();
         return false;
   
 }
 else if (document.join_course_form.status_condition_id.checked)
 {
    if(p==1)	 
	{
	var proceed='Proceed to Payment';	
	}
	 if(p==2)	 
	{
	var proceed='Pay deposit';	
	}
	 if(p==3)	 
	{
	var proceed='Pay on Training Day';	
	}
	 
    Formname= document.join_course_form;
	Formname.action	="payment_details.php?proceed="+proceed;
	Formname.submit();
 }
else
{
  alert("Please Agree Terms and Conditions!");  
  return false;
}

}
 
function hideAllErrors()
 {
    document.getElementById("first_name_Error").innerHTML = ""
    document.getElementById("last_name_Error").innerHTML = ""
    document.getElementById("address_line1_Error").innerHTML= ""  
    document.getElementById("address_line2_Error").innerHTML= ""
    document.getElementById("post_code_Error").innerHTML= ""
    document.getElementById("telephone_Error").innerHTML= ""
    document.getElementById("email_Error").innerHTML= ""
    document.getElementById("promotion_code_Error").innerHTML= ""
   
 }
//	select faqs

function faqs_change(type_id,course_id) { 
        select_image(type_id,course_id);
	    var selectBox = document.faqs_form.course_faq;
		var course_faq = selectBox.options[selectBox.selectedIndex].value;	
		var strURL="ajax/selected_faqs.php?course_faq="+course_faq+"&type_id="+type_id+"&course_id="+course_id;
		var req = getXMLHTTP();
		
		if (req) {
			
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {				
						document.getElementById('faqsdiv').innerHTML=req.responseText;						
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}
				
	}
// select image 
function  select_image(type_id,course_id) {
        var selectBox = document.faqs_form.course_faq;
		var course_faq = selectBox.options[selectBox.selectedIndex].value;	
		var strURL="ajax/selected_image.php?course_faq="+course_faq+"&type_id="+type_id+"&course_id="+course_id;
		var req = getXMLHTTP();
		
		if (req) {
			
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {				
						document.getElementById('imagediv').innerHTML=req.responseText;						
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}
				
	}
//contact validation
function contact_validaton()
{
if (document.getElementById("contact_name_id").value == "")
 {
  hideAllErrors_contact();
  document.getElementById('contact_name_Error').innerHTML = "Required: Please enter your Name!";
  document.getElementById("contact_name_id").select();
  document.getElementById("contact_name_id").focus();
  return false;
 }
else if (document.getElementById("contact_telephone_id").value == "")
 {
  hideAllErrors_contact();
  document.getElementById('contact_telephone_Error').innerHTML = "Required: Please enter Telephone Number!";
  document.getElementById("contact_telephone_id").select();
  document.getElementById("contact_telephone_id").focus();
  return false;
 }
else if (document.getElementById("contact_email_id").value == "")
 {
    hideAllErrors_contact();
   document.getElementById("contact_email_Error").innerHTML = "Required: Please enter email!";
   document.getElementById("contact_email_id").select();
   document.getElementById("contact_email_id").focus();
   return false;
  }
else if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById("contact_email_id").value)))
 {
         hideAllErrors_contact();
         document.getElementById("contact_email_Error").innerHTML = "Invalid Email Address!";
         document.getElementById("contact_email_id").select();
         document.getElementById("contact_email_id").focus();
         return false;
  
 }
else if (document.getElementById("contact_comments_id").value == "")
 {
    hideAllErrors_contact();
   document.getElementById("contact_comments_Error").innerHTML = "Required: Please enter comment!";
   document.getElementById("contact_comments_id").select();
   document.getElementById("contact_comments_id").focus();
   return false;
  }
else
{
    Formname= document.contact_form;
	Formname.action	="contact_us-c.htm";
	Formname.submit();
}
}

function hideAllErrors_contact()
{

    document.getElementById("contact_name_Error").innerHTML= ""
    document.getElementById("contact_telephone_Error").innerHTML= ""
    document.getElementById("contact_email_Error").innerHTML= ""
    document.getElementById("contact_comments_Error").innerHTML= ""
}
//Result validation
function resultvalidation()
{
 if (document.getElementById("result_email_id").value == "")
 {
    hideAllErrors_result();
   document.getElementById("result_email_Error").innerHTML = "Please enter email!";
   document.getElementById("result_email_id").select();
   document.getElementById("result_email_id").focus();
   return false;
  }
else if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById("result_email_id").value)))
 {
          hideAllErrors_result();
         document.getElementById("result_email_Error").innerHTML = "Invalid Email Address!";
         document.getElementById("result_email_id").select();
         document.getElementById("result_email_id").focus();
         return false;
 }
else  if (document.getElementById("result_postcode_id").value == "")
 {
    hideAllErrors_result();
   document.getElementById("result_postcode_Error").innerHTML = "Please enter postcode!";
   document.getElementById("result_postcode_id").select();
   document.getElementById("result_postcode_id").focus();
   return false;
  }
    Formname= document.result_form;
	Formname.action	="displayresult.htm";
	Formname.submit();
}

function hideAllErrors_result()
{

    document.getElementById("result_email_Error").innerHTML= ""
    document.getElementById("result_postcode_Error").innerHTML= ""
   
}

//FUNCTION CALL BACK REQUEST 

function request_validaton()
{
if (document.getElementById("first_name_id").value == "")
 {
  hideAllErrors_request();
  document.getElementById('first_name_Error').innerHTML = "Please enter your First Name!";
  document.getElementById("first_name_id").select();
  document.getElementById("first_name_id").focus();
  return false;
 }
else if (document.getElementById("last_name_id").value == "")
 {
  hideAllErrors_request();
  document.getElementById('last_name_Error').innerHTML = "Please enter your Surname!";
  document.getElementById("last_name_id").select();
  document.getElementById("last_name_id").focus();
  return false;
 }
else if (document.getElementById("email_id").value == "")
 {
  hideAllErrors_request();
  document.getElementById('email_Error').innerHTML = "Please enter your Email Address!";
  document.getElementById("email_id").select();
  document.getElementById("email_id").focus();
  return false;
 }
else if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById("email_id").value)))
 {
          hideAllErrors_request();
         document.getElementById("email_Error").innerHTML = "Invalid Email Address!";
         document.getElementById("email_id").select();
         document.getElementById("email_id").focus();
         return false;
 }
else if (document.getElementById("landline_id").value == "")
 {
  hideAllErrors_request();
  document.getElementById('landline_Error').innerHTML = "Please enter Landline telephone number!";
  document.getElementById("landline_id").select();
  document.getElementById("landline_id").focus();
  return false;
 }
else if (document.getElementById("prefered_call_id").value == "0")
 {
  hideAllErrors_request();
  document.getElementById('prefered_Error').innerHTML = "Please Select Prefered Number To Call!";
  document.getElementById("prefered_call_id").focus();
  return false;
 }
else if (document.getElementById("call_back_id").value == "0")
 {
  hideAllErrors_request();
  document.getElementById('call_back_Error').innerHTML = "Please Select When can we call you back?";
  document.getElementById("call_back_id").focus();
  return false;
 }

    Formname= document.call_back_form;
	Formname.action	="CallBack.htm";
	Formname.submit();

}

function hideAllErrors_request()
{

    document.getElementById("first_name_Error").innerHTML= ""
    document.getElementById("last_name_Error").innerHTML= ""
    document.getElementById("email_Error").innerHTML= ""
    document.getElementById("landline_Error").innerHTML= ""
    document.getElementById("prefered_Error").innerHTML= ""
    document.getElementById("call_back_Error").innerHTML= ""

}

