function trim(str){
   return str.replace(/^\s*|\s*$/g,"");
}
function chkreport()
{
	y=document.frmbroken;
	if(trim(y.message.value)==''){
		alert('Please Enter message')
		y.message.focus()
		return false;
	}
	return true;
}

function chkleft(x){
	if(trim(x.search_text.value)==""){
		alert("Please enter search text");
		x.search_text.focus();
		return false;
	}
	return true;
}

function chksearch_download(x){
	if(trim(x.search_download.value)==""){
		alert("Please enter search text");
		x.search_download.focus();
		return false;
	}
	return true;
}

function chksearchpage(x){
	if(trim(x.search_text.value)==""){
		alert("Please enter search text");
		x.search_text.focus();
		return false;
	}
	return true;
}

function showthis()
{
	ship_val=document.checkout_last.hid_shipping.value;
	tot_basket=document.checkout_last.hid_basket.value;
	total_with_shipping=document.checkout_last.hid_total_with_shipping.value;
	if(document.getElementById('show').checked==true){
		document.getElementById('shiptxt').innerHTML='';
		document.getElementById('hide').style.display='';
		document.getElementById('revised_price').innerHTML='<b>Your Basket Total: &pound; '+eval(tot_basket).toFixed(2)+'</b>';
		document.getElementById('noshipping_txt').style.display='None';
		document.getElementById('hsbcbox').style.display='';
		document.getElementById('okham').style.display='';
		document.getElementById('checkout_last').action="act_checkout.php";
	}else{
		document.getElementById('shiptxt').innerHTML=document.getElementById('ship_txt').value;
		document.getElementById('hide').style.display='none';
		document.checkout_last.ship_country_val.value=222;
		document.getElementById('noshipping_txt').style.display='None';
		document.getElementById('revised_price').innerHTML='<b>Your Basket Total: &pound; '+eval(tot_basket).toFixed(2)+'</b>';
		if(document.checkout_last.hid_bill_add.value !='222')
		{
			total_without_shipping=eval(total_with_shipping)-eval(ship_val);
			price_with_vat=(total_without_shipping)+(total_without_shipping)*(0.2);
			document.getElementById('revised_price').innerHTML='<b>Your Basket Total: &pound; '+price_with_vat.toFixed(2)+'</b>';
			
			document.getElementById('hsbcbox').style.display='None';
			document.getElementById('okham').style.display='None';
			document.getElementById('checkout_last').action="act_checkout1.php";
		}else{
			document.getElementById('hsbcbox').style.display='';
			document.getElementById('okham').style.display='';
			document.getElementById('checkout_last').action="act_checkout.php";
		}
	}
}

function showcredit_info()
{
	if(document.getElementById('credit_info').checked==true){
		document.getElementById('credit_hide').style.display='';
	}else if(document.getElementById('offline_info').checked==true){
		document.getElementById('credit_hide').style.display='none';
	}
}
function validate(y)
{
	if(trim(y.username.value)==""){
		alert("Please enter email address!");
		y.username.focus();
		return false;
	}
	if(!(/^([A-Za-z0-9_\-\.])*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(trim(y.username.value))))
	{
		alert('Please Enter Valid Email Address');
		y.username.focus();
		return false;
	}
	if((trim(y.password.value)==''))
	{
		alert('Please Enter Password')
		y.password.focus()
		return false;
	}
	return true;
	
}
function validateform_changepass(y)
{
	if(trim(y.old_pass.value)==""){
		alert("Enter existing password!");
		y.old_pass.focus();
		return false;
	}
	if(trim(y.new_pass.value)==""){
		alert("Enter new password!");
		y.new_pass.focus();
		return false;
	}
	if(trim(y.new_pass.value) != trim(y.c_pass.value)){
		alert("Confirm password does not match!");
		y.c_pass.focus();
		return false;
	}
	return true;
}

function chk_login_form(y){
	if(trim(y.customers_gender.value)==""){
		alert("Please Select Title!");
		y.customers_gender.focus();
		return false;
	}
	if(trim(y.fname.value)==""){
		alert("Please enter First Name!");
		y.fname.focus();
		return false;
	}
	if(trim(y.lname.value)==""){
		alert("Please enter Last Name!");
		y.lname.focus();
		return false;
	}
	if(trim(y.address1.value)==""){
		alert("Please enter Street Address!");
		y.address1.focus();
		return false;
	}
	if(trim(y.address2.value)==""){
		alert("Please enter Address 2!");
		y.address2.focus();
		return false;
	}
	if(trim(y.city.value)==""){
		alert("Please enter City!");
		y.city.focus();
		return false;
	}
	if(y.country.value !='103'){
		if(trim(y.postcode.value)==""){
			alert("Please enter Post/Zip Code!");
			y.postcode.focus();
			return false;
		}
	}
	if(trim(y.telephone.value)==""){
		alert("Please enter Telephone!");
		y.telephone.focus();
		return false;
	}
	if(trim(y.email_login.value)==""){
		alert("Please enter Email Address!");
		y.email_login.focus();
		return false;
	}
	if(!(/^([A-Za-z0-9_\-\.])*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(trim(y.email_login.value))))
	{
		alert('Please Enter Valid Email Address');
		y.email_login.focus();
		return false;
	}
	if(trim(y.password_login.value)==""){
		alert("Please enter Password!");
		y.password_login.focus();
		return false;
	}
	if(trim(y.password_login.value)!=trim(y.password.value)){
		alert("Both password mismatched!");
		y.password.focus();
		return false;
	}
	return true;
}

function commafy(namea) {
//var re = /(^ ?\s)/
var re = /(^ ?\0)/
var num = namea.value
while (re.test(num)) {
num = num.replace(re, "")
}
return num
}

function checkInput() {
	var key = window.event.keyCode;
	var allowedKeys = new Array(13, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57);
	for (i = 0; i < allowedKeys.length; i++) {
		if ( key == allowedKeys[i] )
		return true;
	}
	return false;
}

function chk_checkout_form(y){
	/*if(trim(y.customers_gender.value)==""){
		alert("Please select Title!");
		y.customers_gender.focus();
		return false;
	}
	if(trim(y.fname.value)==""){
		alert("Please enter First Name!");
		y.fname.focus();
		return false;
	}
	if(trim(y.lname.value)==""){
		alert("Please enter Last Name!");
		y.lname.focus();
		return false;
	}
	if(trim(y.address1.value)==""){
		alert("Please enter Address1!");
		y.address1.focus();
		return false;
	}
	if(trim(y.address2.value)==""){
		alert("Please enter Address2!");
		y.address2.focus();
		return false;
	}
	if(trim(y.city.value)==""){
		alert("Please enter City!");
		y.city.focus();
		return false;
	}
	if(trim(y.postcode.value)==""){
		alert("Please enter Postcode!");
		y.postcode.focus();
		return false;
	}
	if(trim(y.telephone.value)==""){
		alert("Please enter Telephone!");
		y.telephone.focus();
		return false;
	}*/
	/* Checking shipping details */
	if(y.show.checked==true){
		if(trim(y.ship_customers_gender.value)==""){
			alert("Please select Title!");
			y.ship_customers_gender.focus();
			return false;
		}
		if(trim(y.ship_fname.value)==""){
			alert("Please enter First Name!");
			y.ship_fname.focus();
			return false;
		}
		if(trim(y.ship_lname.value)==""){
			alert("Please enter Last Name!");
			y.ship_lname.focus();
			return false;
		}
		if(trim(y.ship_address1.value)==""){
			alert("Please enter Address1!");
			y.ship_address1.focus();
			return false;
		}
		if(trim(y.ship_address2.value)==""){
			alert("Please enter Address2!");
			y.ship_address2.focus();
			return false;
		}
		if(trim(y.ship_city.value)==""){
			alert("Please enter City!");
			y.ship_city.focus();
			return false;
		}
		if(y.ship_country.value !='103'){
			if(trim(y.ship_postcode.value)==""){
				alert("Please enter Postcode!");
				y.ship_postcode.focus();
				return false;
			}
		}
		if(trim(y.ship_telephone.value)==""){
			alert("Please enter Telephone!");
			y.ship_telephone.focus();
			return false;
		}
	}
	if(y.terms.checked==false) {
			alert('You must accept our Terms & conditions.');
			return false;
		}
	/*if(document.getElementById('credit_info').checked==true)
	{
		var errors='';
		
		y.cc_number.value=trim(commafy(y.cc_number));
		y.cc_cvv.value=trim(commafy(y.cc_cvv));
		y.cc_owner.value=trim(commafy(y.cc_owner));
		
		if(!y.cc_number.value){
			errors+=' - Credit Card No  is required\n';
		}
		
		if(!y.cc_cvv.value){
			errors+=' - Security code is required\n';
		}
		if(y.cc_expires1.value==''){
			errors+=' - Expiry date is required\n';
		}
		if(y.cc_expires2.value==''){
			errors+=' - Expiry year is required\n';
		}
		if(!y.cc_owner.value){
			errors+=' - Card holder name is required\n';
		}
		
		var oneDate = new Date() 
		var theYear = oneDate.getFullYear();
		var theMonth = oneDate.getMonth() ;
		theMonth =theMonth +1;
		
		var str=y.cc_expires1.value;
		if (str.indexOf(0)==0){
			str=str.substring(1,2);
		}else{
			str=str;
		}
		
		if (y.cc_expires2.value<theYear){
			errors+=' - The date of the credit card has expired \n';
		}
		if((y.cc_expires2.value==theYear) && (str<theMonth)){
			errors+=' - The date of the credit card has expired \n';
		}
		if(y.cc_number.value!='' && y.cc_cvv.value!='' && y.cc_owner.value!=''){
			if(!is_cc_valid(y.cc_number.value,y.cc_type.value)){
				errors= "Credit Card Number " + y.cc_number.value + " Is Not A Valid "+y.cc_type.value+".\n"; 
			}
		}
		if(y.terms.checked==false) {
			errors+=' - You must accept our Terms & conditions. \n';
		}
		if (errors!=''){
			alert('Please fill in the required fields:\n'+errors);
			return false;
		}
	}*/
	return true;
}
function chk_checkout_google_form(y){
	if(trim(y.customers_gender.value)==""){
		alert("Please select Title!");
		y.customers_gender.focus();
		return false;
	}
	if(trim(y.fname.value)==""){
		alert("Please enter First Name!");
		y.fname.focus();
		return false;
	}
	if(trim(y.lname.value)==""){
		alert("Please enter Last Name!");
		y.lname.focus();
		return false;
	}
	if(trim(y.address1.value)==""){
		alert("Please enter Address1!");
		y.address1.focus();
		return false;
	}
	if(trim(y.address2.value)==""){
		alert("Please enter Address2!");
		y.address2.focus();
		return false;
	}
	if(trim(y.city.value)==""){
		alert("Please enter City!");
		y.city.focus();
		return false;
	}
	if(trim(y.postcode.value)==""){
		alert("Please enter Postcode!");
		y.postcode.focus();
		return false;
	}
	if(trim(y.telephone.value)==""){
		alert("Please enter Telephone!");
		y.telephone.focus();
		return false;
	}
	/* Checking shipping details */
	if(y.show.checked==true){
		if(trim(y.ship_customers_gender.value)==""){
			alert("Please select Title!");
			y.customers_gender.focus();
			return false;
		}
		if(trim(y.ship_fname.value)==""){
			alert("Please enter First Name!");
			y.ship_fname.focus();
			return false;
		}
		if(trim(y.ship_lname.value)==""){
			alert("Please enter Last Name!");
			y.ship_lname.focus();
			return false;
		}
		if(trim(y.ship_address1.value)==""){
			alert("Please enter Address1!");
			y.ship_address1.focus();
			return false;
		}
		if(trim(y.ship_address2.value)==""){
			alert("Please enter Address2!");
			y.ship_address2.focus();
			return false;
		}
		if(trim(y.ship_city.value)==""){
			alert("Please enter City!");
			y.ship_city.focus();
			return false;
		}
		if(trim(y.ship_postcode.value)==""){
			alert("Please enter Postcode!");
			y.ship_postcode.focus();
			return false;
		}
		if(trim(y.ship_telephone.value)==""){
			alert("Please enter Telephone!");
			y.ship_telephone.focus();
			return false;
		}
	}
	
	return true;
}

function validate_home_login(frm)
{
	if(trim(frm.username.value)=='' || trim(frm.username.value)=='Email')
	{
		alert('Please Enter Email')
		frm.username.focus()
		return false;
	}

	if(!(/^([A-Za-z0-9_\-\.])*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(trim(frm.username.value))))
	{
		alert('Please Enter Valid Email Address');
		frm.username.focus();
		return false;
	}
	if(trim(frm.password.value)=='')
	{
		alert('Please Enter Password')
		frm.password.focus()
		return false;
	}
}
function checkregister(y){
	
	if(!(/^([A-Za-z0-9_\-\.])*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(trim(y.email_reg1.value))))
	{
		alert('Please Enter Valid Email Address');
		y.email_reg1.focus();
		return false;
	}
	
	if(trim(y.email_reg1.value)!=trim(y.email_reg2.value)){
		alert("Both Emails mismatched!");
		y.email_reg1.focus();
		return false;
	}
	if(trim(y.password_reg1.value)==""){
		alert("Please enter Password!");
		y.password_reg1.focus();
		return false;
	}
	if(trim(y.password_reg1.value)!=trim(y.password_reg2.value)){
		alert("Both password mismatched!");
		y.password_reg2.focus();
		return false;
	}
	if(trim(y.customers_gender.value)==""){
		alert("Please Select Title!");
		y.customers_gender.focus();
		return false;
	}
	if(trim(y.fname_reg.value)==""){
		alert("Please enter First Name!");
		y.fname_reg.focus();
		return false;
	}
	if(trim(y.lname_reg.value)==""){
		alert("Please enter Last Name!");
		y.lname_reg.focus();
		return false;
	}
	if(trim(y.address_reg1.value)==""){
		alert("Please enter Street Address!");
		y.address_reg1.focus();
		return false;
	}
	
	if(trim(y.city_reg.value)==""){
		alert("Please enter City!");
		y.city_reg.focus();
		return false;
	}
	if(y.country_reg.value !='103'){
		if(trim(y.postcode_reg.value)==""){
			alert("Please enter Post/Zip Code!");
			y.postcode_reg.focus();
			return false;
		}
	}
	if(trim(y.telephone_reg.value)==""){
		alert("Please enter Telephone!");
		y.telephone_reg.focus();
		return false;
	}
	if(trim(y.check_code.value)==""){
		alert("Please enter Verification Code!");
		y.check_code.focus();
		return false;
	}
	if(y.check_code.value.toUpperCase()!=y.mycode.value)
	{
		alert('Entered Verification Code invalid');
		y.check_code.focus();
		y.check_code.value='';
		return false;
	}
	return true;
}
function checkprofile(y){
	
	if(trim(y.customers_gender.value)==""){
		alert("Please Select Title!");
		y.customers_gender.focus();
		return false;
	}
	if(trim(y.fname_reg.value)==""){
		alert("Please enter First Name!");
		y.fname_reg.focus();
		return false;
	}
	if(trim(y.lname_reg.value)==""){
		alert("Please enter Last Name!");
		y.lname_reg.focus();
		return false;
	}
	if(trim(y.address_reg1.value)==""){
		alert("Please enter Street Address!");
		y.address_reg1.focus();
		return false;
	}
	
	if(trim(y.city_reg.value)==""){
		alert("Please enter City!");
		y.city_reg.focus();
		return false;
	}
	if(y.country_reg.value !='103'){
		if(trim(y.postcode_reg.value)==""){
			alert("Please enter Post/Zip Code!");
			y.postcode_reg.focus();
			return false;
		}
	}
	if(trim(y.telephone_reg.value)==""){
		alert("Please enter Telephone!");
		y.telephone_reg.focus();
		return false;
	}
	
	
	return true;
}
function checkcontact(y)
{
	if(trim(y.name.value)==""){
		alert("Please Enter name!");
		y.name.focus();
		return false;
	}
	if(trim(y.telephone.value)==""){
		alert("Please Enter Telephone!");
		y.telephone.focus();
		return false;
	}
	if(!(/^([A-Za-z0-9_\-\.])*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(trim(y.email.value))))
	{
		alert('Please Enter Valid Email Address');
		y.email.focus();
		return false;
	}
}

function chk_email_pass(y)
{
	if(!(/^([A-Za-z0-9_\-\.])*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(trim(y.email.value))))
	{
		alert('Please Enter Valid Email Address');
		y.email.focus();
		return false;
	}
	return true;
}
function textCounter(field, countfield, maxlimit) 
{

	if (field.value.length > maxlimit)
	{ // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
	}
	// otherwise, update 'characters left' counter
	else
	{ 
		countfield.value = maxlimit - field.value.length;
	}
	
}
function chkirlend(y,countryval,fld){
	if(countryval=='103'){
		document.getElementById('remove4irlend_psttxt').style.display='none';
		document.getElementById('remove4irlend_pstbox').style.display='none';
		fld.value='';
	}else{
		document.getElementById('remove4irlend_psttxt').style.display='';
		document.getElementById('remove4irlend_pstbox').style.display='';
	}
	//alert('Hi');
}

function checkenquiries(y){
	if(trim(y.fname.value)==""){
		alert("Please enter first name");
		y.fname.focus();
		return false;
	}
	if(trim(y.name.value)==""){
		alert("Please enter last name");
		y.name.focus();
		return false;
	}
	if(trim(y.address.value)==""){
		alert("Please enter address");
		y.address.focus();
		return false;
	}
	if(trim(y.postcode.value)==""){
		alert("Please enter postcode");
		y.postcode.focus();
		return false;
	}
	if(trim(y.telephone.value)==""){
		alert("Please enter telephone No.");
		y.telephone.focus();
		return false;
	}
	if(!(/^([A-Za-z0-9_\-\.])*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(trim(y.email.value))))
	{
		alert('Please enter valid email address');
		y.email.focus();
		return false;
	}
	if(trim(y.check_code.value)==""){
		alert("Please enter verification code");
		y.check_code.focus();
		return false;
	}
	
	return true;
}
