// ------------ VALIDATE OPEN AN ACCOUNT FORM ---------//

function validateOpenAccount(){

	var strFirstName	=	document.openaccount.firstname.value;
	var strLastName		=	document.openaccount.lastname.value;
	var strEmail		=	document.openaccount.email.value;
	var strCountryCode	=	document.openaccount.countrycode.value;
	var strPhone		=	document.openaccount.phone.value;
	var strCbdate		=	document.openaccount.cbdate.value;
	var strHoursfrom	=	document.openaccount.hoursfrom.value;
	var strHoursto		=	document.openaccount.hoursto.value;

  	var valid = true;

	if(strFirstName==''){
		alert('Please enter your first name');
		document.openaccount.firstname.focus();
		valid = false;
		return false;
	}
	if(strLastName==''){
		alert('Please enter your last name');
		document.openaccount.lastname.focus();
		valid = false;
		return false;
	}

 	var strEmail = document.openaccount.email.value;
  	invalidChars = " /:,;'`^"
  	if (strEmail=="") valid = false;  
  	if (!valid) { 
		alert("Please enter your email address"); 
		document.openaccount.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.openaccount.email.focus(); 
		valid = false;
		return false;
	}

	if(strCountryCode==''){
		alert('Please select the country code for your phone number');
		document.openaccount.countrycode.focus();
		valid = false;
		return false;
	}
	if(strPhone==''){
		alert('Please enter your phone number');
		document.openaccount.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.openaccount.phone.focus(); 
				valid = false;
				return false; 
				}
		} 
	}
	 if(!(document.openaccount.acttype[0].checked || document.openaccount.acttype[1].checked || document.openaccount.acttype[2].checked || document.openaccount.acttype[3].checked)){
		alert("Please select which type of account you are interested in");
		valid = false;
		return false;
	}
	if(strCbdate==''){
		alert('Please select a date for us to contact you');
		document.openaccount.cbdate.focus();
		valid = false;
		return false;
	}
	if(!strCbdate==''){	
		var cbdateArray 	=	new Array();	
		cbdateArray			=	document.openaccount.cbdate.value.split("/");
		var now = new Date();
		var today = new Date(now.getFullYear(),now.getMonth(),now.getDate());
		var cbdate = new Date(cbdateArray[2],cbdateArray[1]-1,cbdateArray[0]);
		if(cbdate < today){
			alert('Please select a date in the future where we can give you a call');
			valid = false;
			return false;		
		}
	}
	if(strHoursfrom==''){
		alert('Please tell us the time from which we can contact you');
		document.openaccount.hoursfrom.focus();
		valid = false;
		return false;
	}
	if(strHoursto==''){
		alert('Please tell us the time until which we can contact you');
		document.openaccount.hoursto.focus();
		valid = false;
		return false;
	}
	if(!strHoursfrom=='' && !strHoursto==''){
		if(strHoursto < strHoursfrom){
		alert('Please check you have entered a correct time period for contact');
		document.openaccount.hoursto.focus();
		valid = false;
		return false;
		}
		if((strHoursto - strHoursfrom) < 1){
		alert('Please allow us a time range of at least 1 hour to contact you');
		document.openaccount.hoursto.focus();
		valid = false;
		return false;
		}
		if(!(cbdate > today) || (cbdate < today)){
			var now = new Date();
			var hournow = now.getHours();
			if((strHoursfrom - hournow) <= 0){
			alert('Please select a time in the future where we can give you a call');
			document.openaccount.hoursfrom.focus();
			valid = false;
			return false;		
			}		
			if((strHoursfrom - hournow) <= 1){
			alert('Please leave us at least an hour to give you a call');
			document.openaccount.hoursfrom.focus();
			valid = false;
			return false;		
			}		
		}	
	}				
	
	if(document.openaccount.tac.checked) 
		{
		valid = true
		}
	else {
	        alert('Please confirm you have read the terms and conditions.');
                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 REGISTER FORM ---------//


function validateRegister(){

	var strFirstName	=	document.register.firstname.value;
	var strLastName		=	document.register.lastname.value;
	var strEmail		=	document.register.email.value;
	var strCountryCode	=	document.register.countrycode.value;
	var strPhone		=	document.register.phone.value;
	var strPass1		=	document.register.pass1.value;
	var strPass2		=	document.register.pass2.value;
	var minLength 		=	6;

  	var valid = true;

	if(strFirstName==''){
		alert('Please enter your firstname');
		document.register.firstname.focus();
		valid = false;
		return false;
	}
	if(strLastName==''){
		alert('Please enter your lastname');
		document.register.lastname.focus();
		valid = false;
		return false;
	}
	if(strCountryCode==''){
		alert('Please select the country code for your phone number');
		document.register.countrycode.focus();
		valid = false;
		return false;
	}
	if(strPhone==''){
		alert('Please enter your phone number');
		document.register.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.register.phone.focus(); 
				valid = false;
				return false; 
				}
		} 
	}
 	var strEmail = document.register.email.value;
  	invalidChars = " /:,;'`^"
  	if (strEmail=="") valid = false;  
  	if (!valid) { 
		alert("Please enter your email address"); 
		document.register.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.register.email.focus(); 
		valid = false;
		return false;
	}
	if(strPass1==''){
		alert('Please enter a password');
		document.register.pass1.focus();
		valid = false;
		return false;
	}
	if(strPass1.length < minLength){
		alert('Your password must be at least ' + minLength + ' characters long.');
		document.register.pass1.focus();
		valid = false;
		return false;
	}
	if(strPass2 != strPass1){
		alert('Your confirm password is different from your password');
		document.register.pass2.focus();
		valid = false;
		return false;
	}	
	if(document.register.tac.checked) 
		{
		valid = true
		}
	else {
	        alert('Please confirm you have read the terms and conditions.');
                valid = false ;
		return false;
	}
  	if (valid) return true;
	else return false;
}

// ------------ VALIDATE My PROFILE FORM ---------//


function validateMyProfile(){

	var strFirstName	=	document.myprofile.firstname.value;
	var strLastName		=	document.myprofile.lastname.value;
	var strEmail		=	document.myprofile.email.value;
	var strCountryCode	=	document.myprofile.countrycode.value;
	var strPhone		=	document.myprofile.phone.value;

	var strCurrPass		=	document.myprofile.currentpass.value;
	var strPass1		=	document.myprofile.pass1.value;
	var strPass2		=	document.myprofile.pass2.value;
	var minLength 		=	6;	

  	var valid = true;

	if(strCurrPass != ''){
		if(strCurrPass.length < minLength){
			alert('Your current password must be at least ' + minLength + ' characters long.');
			document.myprofile.currentpass.focus();
			valid = false;
			return false;
		}	
		if(strPass1==''){
			alert('Please enter a new password');
			document.myprofile.pass1.focus();
			valid = false;
			return false;
		}
		if(strPass1.length < minLength){
			alert('Your new password must be at least ' + minLength + ' characters long.');
			document.myprofile.pass1.focus();
			valid = false;
			return false;
		}
		if(strPass2 != strPass1){
			alert('Your new confirm password is different from your new password');
			document.myprofile.pass2.focus();
			valid = false;
			return false;
		}			
	}
	if(strFirstName==''){
		alert('Please enter your first name');
		document.myprofile.firstname.focus();
		valid = false;
		return false;
	}
	if(strLastName==''){
		alert('Please enter your last name');
		document.myprofile.lastname.focus();
		valid = false;
		return false;
	}
	if(strCountryCode==''){
		alert('Please select the country code for your phone number');
		document.myprofile.countrycode.focus();
		valid = false;
		return false;
	}
	if(strPhone==''){
		alert('Please enter your phone number');
		document.myprofile.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.myprofile.phone.focus(); 
				valid = false;
				return false; 
				}
		} 
	}
 	var strEmail = document.myprofile.email.value;
  	invalidChars = " /:,;'`^"
  	if (strEmail=="") valid = false;  
  	if (!valid) { 
		alert("Please enter your email address"); 
		document.myprofile.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.myprofile.email.focus(); 
		valid = false;
		return false;
	}

  	if (valid) return true;
	else return false;
}

// ------------ VALIDATE My PASSWORD FORM ---------//


function validateMyPassword(){

	var strCurrPass		=	document.mypassword.currentpass.value;
	var strPass1		=	document.mypassword.pass1.value;
	var strPass2		=	document.mypassword.pass2.value;
	var minLength 		=	6;

  	var valid = true;

	if(strCurrPass==''){
		alert('Please enter your current password');
		document.mypassword.currentpass.focus();
		valid = false;
		return false;
	}
	if(strCurrPass.length < minLength){
		alert('Your current password must be at least ' + minLength + ' characters long.');
		document.mypassword.currentpass.focus();
		valid = false;
		return false;
	}	
	if(strPass1==''){
		alert('Please enter a new password');
		document.mypassword.pass1.focus();
		valid = false;
		return false;
	}
	if(strPass1.length < minLength){
		alert('Your new password must be at least ' + minLength + ' characters long.');
		document.mypassword.pass1.focus();
		valid = false;
		return false;
	}
	if(strPass2 != strPass1){
		alert('Your new confirm password is different from your new password');
		document.mypassword.pass2.focus();
		valid = false;
		return false;
	}	

  	if (valid) return true;
	else return false;
}

// ------------ VALIDATE My PROFILE FORM ---------//


function validateForgotPassword(){

	var strEmail		=	document.forgotpassword.email.value;

  	var valid = true;

 	var strEmail = document.forgotpassword.email.value;
  	invalidChars = " /:,;'`^"
  	if (strEmail=="") valid = false;  
  	if (!valid) { 
		alert("Please enter your email address"); 
		document.forgotpassword.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.forgotpassword.email.focus(); 
		valid = false;
		return false;
	}

  	if (valid) return true;
	else return false;
}


function openacccheck(d)	{
	if(document.showlink.oac.checked || document.showlink.oac2.checked || document.showlink.oac3.checked )
		{
		document.getElementById(d).style.display = "";
		}
	else {
		document.getElementById(d).style.display = "none";
		}
}


function validateactivatefoundation()	{
	var strLogin	=	document.activatefoundation.loginactivate.value;
	var strPass1	=	document.activatefoundation.passactivate1.value;
	var strPass2	=	document.activatefoundation.passactivate2.value;

  	var valid = true;

	if(strLogin==''){
		alert('Please enter your Foundation account number');
		document.activatefoundation.loginactivate.focus();
		valid = false;
		return false;
	}
	if(strPass1==''){
		alert('Please enter your Foundation account password');
		document.activatefoundation.passactivate1.focus();
		valid = false;
		return false;
	}
	if(strPass2 != strPass1){
		alert('Your confirm password is different from your password');
		document.activatefoundation.passactivate2.focus();
		valid = false;
		return false;
	}		

  	if (valid) return true;
	else return false;	
}

function validatefoundationlogin()	{
	var strLogin	=	document.foundationlogin.loginf.value;
	var strPass		=	document.foundationlogin.passf.value;

  	var valid = true;

	if(strLogin==''){
		alert('Please enter your Foundation account number');
		document.foundationlogin.loginf.focus();
		valid = false;
		return false;
	}
	if(strPass==''){
		alert('Please enter your Foundation account password');
		document.foundationlogin.passf.focus();
		valid = false;
		return false;
	}

  	if (valid) return true;
	else return false;	
}