function submitform()
{
  document.bookingname.submit();
}


var main_url="book_your_course";
$.fn.clearForm = function() {
  return this.each(function() {
	var type = this.type, tag = this.tagName.toLowerCase();
	if (tag == 'form')
	  return $(':input',this).clearForm();
	if (type == 'text' || type == 'password' || tag == 'textarea')
	  this.value = '';
	else if (type == 'checkbox' || type == 'radio')
	  this.checked = false;
	else if (tag == 'select')
	  this.selectedIndex = -1;
  });
};

$(document).ready(function(){
 
	 var err_name="<span style='color:#FF0000'>Please enter your name</span>";
	 var err_email="<span style='color:#FF0000'>Please enter your email</span>";
	 var err_first_name="<span style='color:#FF0000'>Please enter your First Name</span>";
	


 $("#addbasket").click(function () {
		
		
		if (document.bookingname.booklastname.value == "")
		{
			$('.redas').html("<span style='color:#FF0000'> *</span>");
			$('.redas').show();
			$('.name-missing').html("<span style='color:#FF0000'>Please enter your Family Name</span> ");
			$('.name-missing').show();
			$('.xx').html("<span style='color:#FF0000'>Family Name*</span>");
			$('.xx').show();
		} else 
		{
		$('.xx').html("<span style='color:black'>Family Name*</span>");
		$('.xx').show();
		$('.name-missing').hide();
		$('.redas').hide();
		}
		
			
			if (document.bookingname.bookfirstname.value == "")
		{
			$('.fredas').html("<span style='color:#FF0000'> *</span>");
			$('.fredas').show();
			$('.fname-missing').html("<span style='color:#FF0000'>Please enter your Name </span>");
			$('.fname-missing').show();
			$('.fn').html("<span style='color:#FF0000'>First Name*</span>");
			$('.fn').show();
		} else 
		{
		$('.fn').html("<span style='color:black'>First Name*</span>");
		$('.fn').show();
		$('.fname-missing').hide();
		$('.fredas').hide();
		}
			if (document.bookingname.bookaddress.value == "")
		{
			$('.radd').html("<span style='color:#FF0000'> *</span>");
			$('.radd').show();
			$('.addname-missing').html("<span style='color:#FF0000'>Please enter your address</span>");
			$('.addname-missing').show();
			$('.add').html("<span style='color:#FF0000'>Address*</span>");
			$('.add').show();
		} else 
		{
		$('.add').html("<span style='color:black'>Address*</span>");
		$('.add').show();
		$('.addname-missing').hide();
		$('.radd').hide();
		}
		
		
		/*********************************/
		
		

		
			if (document.bookingname.booktown.value == "")
		{
			$('.redcity').html("<span style='color:#FF0000'> *</span>");
			$('.redcity').show();
			$('.cityname-missing').html("<span style='color:#FF0000'>Please enter your Town/City</span>");
			$('.cityname-missing').show();
			$('.cityt').html("<span style='color:#FF0000'>Town/City*</span>");
			$('.cityt').show();
		} else 
		{
		$('.cityt').html("<span style='color:black'>Town/City*</span>");
		$('.cityt').show();
		$('.cityname-missing').hide();
		$('.redcity').hide();
		}
		
		
		if (document.bookingname.bookpostcode.value == "")
		{
			$('.redpost').html("<span style='color:#FF0000'> *</span>");
			$('.redpost').show();
			$('.post-missing').html("<span style='color:#FF0000'>Please enter your Postcode/Zip</span>");
			$('.post-missing').show();
			$('.post').html("<span style='color:#FF0000'>Postcode/Zip*</span>");
			$('.post').show();
		} else 
		{
		$('.post').html("<span style='color:black'>Postcode/Zip*</span>");
		$('.post').show();
		$('.post-missing').hide();
		$('.redpost').hide();
		}
		
		
				if (document.bookingname.bookcountry.value == "")
		{
			$('.redcun').html("<span style='color:#FF0000'> *</span>");
			$('.redcun').show();
			$('.cun-missing').html("<span style='color:#FF0000'>Please enter your Country</span>");
			$('.cun-missing').show();
			$('.cuntry').html("<span style='color:#FF0000'>Country*</span>");
			$('.cuntry').show();
		} else 
		{
		$('.cuntry').html("<span style='color:black'>Country*</span>");
		$('.cuntry').show();
		$('.cun-missing').hide();
		$('.redcun').hide();
		}
		
				
				if (document.bookingname.bookphone.value == "")
		{
			$('.redtel').html("<span style='color:#FF0000'> *</span>");
			$('.redtel').show();
			$('.tel-missing').html("<span style='color:#FF0000'>Please enter your Telephone</span>");
			$('.tel-missing').show();
			$('.tel').html("<span style='color:#FF0000'>Telephone*</span>");
			$('.tel').show();
		} else 
		{
		$('.tel').html("<span style='color:black'>Telephone*</span>");
		$('.tel').show();
		$('.tel-missing').hide();
		$('.redtel').hide();
		}
		
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		var email = document.getElementById('bookemail');
		if (!filter.test(email.value)) 
		{
			$('.email-missing').html(err_email);
			$('.email-missing').show();
			$('.redmail').html("<span style='color:#FF0000'> *</span>");
			$('.redmail').show();
			$('.mal').html("<span style='color:#FF0000'>Email*</span>");
			$('.mal').show();
		} else {
			$('.email-missing').hide();
			$('.redmail').hide();
			$('.mal').html("<span style='color:black'>Email*</span>");
			$('.mal').show();
			}
		
		
		
if (document.bookingname.bookdob.value == "")
		{
			$('.redber').html("<span style='color:#FF0000'> *</span>");
			$('.redber').show();
			$('.dofb-missing').html("<span style='color:#FF0000'>Please enter your Date of Birth</span>");
			$('.dofb-missing').show();
			$('.dabi').html("<span style='color:#FF0000'>Date of Birth*</span>");
			$('.dabi').show();
		} else 
		{
		$('.dabi').html("<span style='color:black'>Date of Birth*</span>");
		$('.dabi').show();
		$('.dofb-missing').hide();
		$('.redber').hide();
		
		}
		if (document.bookingname.booknation.value == "")
		{
			$('.rednat').html("<span style='color:#FF0000'> *</span>");
			$('.rednat').show();
			$('.nat-missing').html("<span style='color:#FF0000'>Please enter your nationality</span>");
			$('.nat-missing').show();
			$('.national').html("<span style='color:#FF0000'>Nationality*</span>");
			$('.national').show();
		} else 
		{
		$('.national').html("<span style='color:black'>Nationality*</span>");
		$('.national').show();
		$('.nat-missing').hide();
		$('.rednat').hide();
		}
			if ((document.bookingname.bookvisa[0].checked==false)&&(document.bookingname.bookvisa[1].checked==false))
		{
			$('.vass').html("<span style='color:#FF0000'> *</span>");
			$('.rednat').show();
			$('.vas-missing').html("<span style='color:#FF0000'>Please chose if you need visa or not  </span>");
			$('.vas-missing').show();
			$('.vasa').html("<span style='color:#FF0000'>Visa Required?*</span>");
			$('.vasa').show();
		} else 
		{
		$('.vasa').html("<span style='color:black'>Visa Required?*</span>");
		$('.national').show();
		$('.vas-missing').hide();
		$('.vass').hide();
		}
	
	/*&&(document.bookingname.bookvisa[0].checked!=false)&&(document.bookingname.bookvisa[1].checked!=false)&&(filter.test(email.value))*/
		
		
if ((document.bookingname.booklastname.value != "")&&(document.bookingname.bookfirstname.value != "")&&(document.bookingname.bookaddress.value != "")&&(document.bookingname.booktown.value != "")&&(document.bookingname.bookpostcode.value != "")&&(document.bookingname.bookcountry.value != "")&&(document.bookingname.bookcountry.value != "")&&(document.bookingname.bookphone.value != "")&&(document.bookingname.bookdob.value != "")&&(document.bookingname.booknation.value != "")&&(filter.test(email.value)))
{
	if((document.bookingname.bookvisa[0].checked==true)||(document.bookingname.bookvisa[1].checked==true))
	{
		if (document.bookingname.bookjobtitle.value != "")
		{
			
			
			if (document.bookingname.bookempname.value == "")
		{
		//	alert("asldka")
			$('.redemp').html("<span style='color:#FF0000'> *</span>");
			$('.redemp').show();
			$('.emp-missing').html("<span style='color:#FF0000'>Please enter your Employers Name</span>");
			$('.emp-missing').show();
			$('.emp').html("<span style='color:#FF0000'>Employers Name*</span>");
			$('.emp').show();
		} else 
		{
		$('.emp').html("<span style='color:black'>Employers Name*</span>");
		$('.emp').show();
		$('.emp-missing').hide();
		$('.redemp').hide();
		}
		
					if (document.bookingname.bookempaddress.value == "")
		{
			$('.redempad').html("<span style='color:#FF0000'> *</span>");
			$('.redempad').show();
			$('.empad-missing').html("<span style='color:#FF0000'>Please enter your Work Address</span>");
			$('.empad-missing').show();
			$('.empadd').html("<span style='color:#FF0000'>Work Address*</span>");
			$('.empadd').show();
		} else 
		{
		$('.empadd').html("<span style='color:black'>Work Address*</span>");
		$('.empadd').show();
		$('.empad-missing').hide();
		$('.redempad').hide();
		}
		
	
		
					if (document.bookingname.bookempphone.value == "")
		{
			$('.redemptem').html("<span style='color:#FF0000'> *</span>");
			$('.redemptem').show();
			$('.emptem-missing').html("<span style='color:#FF0000'>Please enter your Work Telephone</span>");
			$('.emptem-missing').show();
			$('.emptem').html("<span style='color:#FF0000'>Telephone*</span>");
			$('.emptem').show();
		} else 
		{
		$('.emptem').html("<span style='color:black'>Telephone*</span>");
		$('.emptem').show();
		$('.emptem-missing').hide();
		$('.redemptem').hide();
		}
		
		
		
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		var email = document.getElementById('bookempemail');
		if (!filter.test(email.value)) 
		{
			$('.redemailemp').html("<span style='color:#FF0000'> *</span>");
			$('.redemailemp').show();
			$('.mailemp-missing').html("<span style='color:#FF0000'>Please enter your  Work Email</span>");
			$('.mailemp-missing').show();
			$('.empmail').html("<span style='color:#FF0000'>Work Email*</span>");
			$('.empmail').show();
		} else 
		{
		$('.empmail').html("<span style='color:black'>Work Email*</span>");
		$('.empmail').show();
		$('.mailemp-missing').hide();
		$('.redemailemp').hide();
		}
	if ((document.bookingname.bookempname.value  != "")&&(document.bookingname.bookempaddress.value != "")&&(document.bookingname.bookempphone.value!= "")&&filter.test(email.value))
	{
		//alert("zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz");		
		submitform();
		}
			
			}else
			{
		//alert("xsad");		
		submitform();
			}
	}
}
	
});
});
 
 

 
 
 

	


