// ------------ VALIDATE EMAIL THIS PAGE ---------//

function validateSendPage(){

	var strYourName		=	document.emailthispage.yourname.value;
	var strYourEmail	=	document.emailthispage.youremail.value;
	var strFriendName	=	document.emailthispage.friendname.value;
	var strFriendEmail	=	document.emailthispage.friendemail.value;

  	var valid = true;

	if(strYourName==''){
		alert('Please enter your name');
		document.emailthispage.yourname.focus();
		valid = false;
		return false;
	}

 	var strYourEmail = document.emailthispage.youremail.value;
  	invalidChars = " /:,;'`^"
  	if (strYourEmail=="") valid = false;  
  	if (!valid) { 
		alert("Please enter your email address"); 
		document.emailthispage.youremail.focus(); 
		valid = false;
		return false;
	}
  	for (i=0;i<invalidChars.length; i++){
    		badChar=invalidChars.charAt(i)
    		if (strYourEmail.indexOf(badChar,0)>-1) valid = false;  
  	}
  	atPos = strYourEmail.indexOf("@",1)
  	if (atPos == -1) valid = false;  
  	if (strYourEmail.indexOf("@",atPos+1) != -1) valid = false;  
  	periodPos = strYourEmail.indexOf(".",atPos)
  	if (periodPos == -1) valid = false;  
  	if (periodPos+3 > strYourEmail.length) valid = false;  
  	if (!valid) { 
		alert("Please enter a valid email address"); document.emailthispage.youremail.focus(); 
		valid = false;
		return false;
	}

	
	if(strFriendName==''){
		alert('Please enter your friend\'s name');
		document.emailthispage.friendname.focus();
		valid = false;
		return false;
	}

 	var strFriendEmail = document.emailthispage.friendemail.value;
  	invalidChars = " /:,;'`^"
  	if (strFriendEmail=="") valid = false;  
  	if (!valid) { 
		alert("Please enter your friend\'s email address"); 
		document.emailthispage.friendemail.focus(); 
		valid = false;
		return false;
	}
  	for (i=0;i<invalidChars.length; i++){
    		badChar=invalidChars.charAt(i)
    		if (strFriendEmail.indexOf(badChar,0)>-1) valid = false;  
  	}
  	atPos = strFriendEmail.indexOf("@",1)
  	if (atPos == -1) valid = false;  
  	if (strFriendEmail.indexOf("@",atPos+1) != -1) valid = false;  
  	periodPos = strFriendEmail.indexOf(".",atPos)
  	if (periodPos == -1) valid = false;  
  	if (periodPos+3 > strFriendEmail.length) valid = false;  
  	if (!valid) { 
		alert("Please enter a valid email address for your friend"); document.emailthispage.friendemail.focus(); 
		valid = false;
		return false;
	}

  	if (valid) return true;
	else return false;
}


// ------------ VALIDATE CONTACT FORM ---------//


function validateContact(){

	var strFirstName	=	document.contact.firstname.value;
	var strLastName		=	document.contact.lastname.value;
	var strEmail		=	document.contact.email.value;
	var strCountryCode	=	document.contact.countrycode.value;
	var strPhone		=	document.contact.phone.value;

  	var valid = true;

	if(strFirstName==''){
		alert('Please enter your first name');
		document.contact.firstname.focus();
		valid = false;
		return false;
	}
	if(strLastName==''){
		alert('Please enter your last name');
		document.contact.lastname.focus();
		valid = false;
		return false;
	}

	if(strCountryCode==''){
		alert('Please select the country code for your phone number');
		document.contact.countrycode.focus();
		valid = false;
		return false;
	}
	if(strPhone==''){
		alert('Please enter your phone number');
		document.contact.phone.focus();
		valid = false;
		return false;
	}

	if(!strPhone==''){
		var validChars = "1234567890() "
		for(var Idx=0; Idx<strPhone.length; Idx++) 
		{ 
			var Char = strPhone.charAt(Idx); 
			var Match = false; 
	
			for(var Idx1=0; Idx1<validChars.length; Idx1++) 
			{ 
				if(Char == validChars.charAt (Idx1)) 
					Match = true; 
			} 
			if (!Match) {
				alert("Please enter a valid phone number (only digits, brackets and spaces are allowed)");
				document.contact.phone.focus(); 
				valid = false;
				return false; 
				}
		} 
	}

 	var strEmail = document.contact.email.value;
  	invalidChars = " /:,;'`^"
  	if (strEmail=="") valid = false;  
  	if (!valid) { 
		alert("Please enter your email address"); 
		document.contact.email.focus(); 
		valid = false;
		return false;
	}
  	for (i=0;i<invalidChars.length; i++){
    		badChar=invalidChars.charAt(i)
    		if (strEmail.indexOf(badChar,0)>-1) valid = false;  
  	}
  	atPos = strEmail.indexOf("@",1)
  	if (atPos == -1) valid = false;  
  	if (strEmail.indexOf("@",atPos+1) != -1) valid = false;  
  	periodPos = strEmail.indexOf(".",atPos)
  	if (periodPos == -1) valid = false;  
  	if (periodPos+3 > strEmail.length) valid = false;  
  	if (!valid) { 
		alert("Please enter a valid email address"); document.contact.email.focus(); 
		valid = false;
		return false;
	}

  	if (valid) return true;
	else return false;
}




// ------------ VALIDATE SUBMIT ARTICLE FORM ---------//


function validateSub(){

	var strName			=	document.subart.name.value;
	var strEmail		=	document.subart.email.value;
	var strFile1		=	document.subart.attachment1.value;
	var strFile2		=	document.subart.attachment2.value;

  	var valid = true;

	if(strName==''){
		alert('Please enter your first name');
		document.subart.name.focus();
		valid = false;
		return false;
	}

 	var strEmail = document.subart.email.value;
  	invalidChars = " /:,;'`^"
  	if (strEmail=="") valid = false;  
  	if (!valid) { 
		alert("Please enter your email address"); 
		document.subart.email.focus(); 
		valid = false;
		return false;
	}
  	for (i=0;i<invalidChars.length; i++){
    		badChar=invalidChars.charAt(i)
    		if (strEmail.indexOf(badChar,0)>-1) valid = false;  
  	}
  	atPos = strEmail.indexOf("@",1)
  	if (atPos == -1) valid = false;  
  	if (strEmail.indexOf("@",atPos+1) != -1) valid = false;  
  	periodPos = strEmail.indexOf(".",atPos)
  	if (periodPos == -1) valid = false;  
  	if (periodPos+3 > strEmail.length) valid = false;  
  	if (!valid) { 
		alert("Please enter a valid email address"); document.subart.email.focus(); 
		valid = false;
		return false;
	}


	if(strFile1==''){
		alert('Select browse to upload your word document');
		document.subart.attachment1.focus();
		valid = false;
		return false;
	}

	if(strFile2==''){
		alert('Select browse to upload your image file');
		document.subart.attachment2.focus();
		valid = false;
		return false;
	}


  	if (valid) return true;
	else return false;
}


// ------------ VALIDATE CAPTCHA ---------//


function validateCaptcha(){

	var strCaptcha			=	document.addcomments.strCAPTCHA.value;

  	var valid = true;

	if(strCaptcha==''){
		alert('Please enter the security validation code');
		document.addcomments.strCAPTCHA.focus();
		valid = false;
		return false;
	}

  	if (valid) return true;
	else return false;
}


// ------------ VALIDATE SUBMIT VIDEO FORM ---------//


function validateVid(){

	var strName			=	document.vidform.name.value;
	var strEmail		=	document.vidform.email.value;
	var strTitle		=	document.vidform.title.value;
	var strCat			=	document.vidform.cid.value;
	var strEmbed		=	document.vidform.embed.value;
	var strURL			=	document.vidform.vurl.value;
	var strDesc			=	document.vidform.desc.value;

  	var valid = true;

	if(strName==''){
		alert('Please enter your name');
		document.vidform.name.focus();
		valid = false;
		return false;
	}

 	var strEmail = document.vidform.email.value;
  	invalidChars = " /:,;'`^"
  	if (strEmail=="") valid = false;  
  	if (!valid) { 
		alert("Please enter your email address"); 
		document.vidform.email.focus(); 
		valid = false;
		return false;
	}
  	for (i=0;i<invalidChars.length; i++){
    		badChar=invalidChars.charAt(i)
    		if (strEmail.indexOf(badChar,0)>-1) valid = false;  
  	}
  	atPos = strEmail.indexOf("@",1)
  	if (atPos == -1) valid = false;  
  	if (strEmail.indexOf("@",atPos+1) != -1) valid = false;  
  	periodPos = strEmail.indexOf(".",atPos)
  	if (periodPos == -1) valid = false;  
  	if (periodPos+3 > strEmail.length) valid = false;  
  	if (!valid) { 
		alert("Please enter a valid email address"); document.vidform.email.focus(); 
		valid = false;
		return false;
	}


	if(strTitle==''){
		alert('Please enter the title of your video');
		document.vidform.title.focus();
		valid = false;
		return false;
	}

	if(strCat==''){
		alert('Please select a category for your video');
		document.vidform.cid.focus();
		valid = false;
		return false;
	}

	if(strEmbed==''){
		alert('Please enter the embed link of your video');
		document.vidform.embed.focus();
		valid = false;
		return false;
	}

	if(strURL==''){
		alert('Please enter the URL of your video');
		document.vidform.vurl.focus();
		valid = false;
		return false;
	}

	if(strDesc==''){
		alert('Please enter the description of your video');
		document.vidform.desc.focus();
		valid = false;
		return false;
	}

  	if (valid) return true;
	else return false;
}


// ------------ VALIDATE PAYMENT FORM ---------//


function validatePayment(){

	var strFirstName	=	document.payment.fname.value;
	var strLastName		=	document.payment.lname.value;
	var strEmail		=	document.payment.email.value;
	var strPhone		=	document.payment.phone.value;
	var strAddress		=	document.payment.address.value;
	var strTown			=	document.payment.town.value;
	var strCounty		=	document.payment.county.value;
	var strPostCode		=	document.payment.postcode.value;
	var strCountry 		=	document.payment.country.value;

  	var valid = true;

	if(strFirstName==''){
		alert('Please enter your first name');
		document.payment.fname.focus();
		valid = false;
		return false;
	}
	if(strLastName==''){
		alert('Please enter your last name');
		document.payment.lname.focus();
		valid = false;
		return false;
	}

 	var strEmail = document.payment.email.value;
  	invalidChars = " /:,;'`^"
  	if (strEmail=="") valid = false;  
  	if (!valid) { 
		alert("Please enter your email address"); 
		document.payment.email.focus(); 
		valid = false;
		return false;
	}
  	for (i=0;i<invalidChars.length; i++){
    		badChar=invalidChars.charAt(i)
    		if (strEmail.indexOf(badChar,0)>-1) valid = false;  
  	}
  	atPos = strEmail.indexOf("@",1)
  	if (atPos == -1) valid = false;  
  	if (strEmail.indexOf("@",atPos+1) != -1) valid = false;  
  	periodPos = strEmail.indexOf(".",atPos)
  	if (periodPos == -1) valid = false;  
  	if (periodPos+3 > strEmail.length) valid = false;  
  	if (!valid) { 
		alert("Please enter a valid email address"); document.payment.email.focus(); 
		valid = false;
		return false;
	}

	if(strPhone==''){
		alert('Please enter your phone number');
		document.payment.phone.focus();
		valid = false;
		return false;
	}

	if(!strPhone==''){
		var validChars = "1234567890() "
		for(var Idx=0; Idx<strPhone.length; Idx++) 
		{ 
			var Char = strPhone.charAt(Idx); 
			var Match = false; 
	
			for(var Idx1=0; Idx1<validChars.length; Idx1++) 
			{ 
				if(Char == validChars.charAt (Idx1)) 
					Match = true; 
			} 
			if (!Match) {
				alert("Please enter a valid phone number (only digits, brackets and spaces are allowed)");
				document.payment.phone.focus(); 
				valid = false;
				return false; 
				}
		} 
	}

	if(strAddress==''){
		alert('Please enter your Address');
		document.payment.address.focus();
		valid = false;
		return false;
	}
	
	if(strTown==''){
		alert('Please enter your Town');
		document.payment.town.focus();
		valid = false;
		return false;
	}
	
	if(strCounty==''){
		alert('Please enter your County');
		document.payment.county.focus();
		valid = false;
		return false;
	}	
	
	if(strPostCode==''){
		alert('Please enter your Postcode');
		document.payment.postcode.focus();
		valid = false;
		return false;
	}	
	
	if(strCountry==''){
		alert('Please enter your country');
		document.payment.country.focus();
		valid = false;
		return false;
	}	

	if(document.payment.terms.checked) 
		{
		valid = true
		}
	else {
	        alert('Please confirm you have read and agree to the Terms and Conditions of Use.');
                valid = false ;
		return false;
	}


  	if (valid) return true;
	else return false;
}



