/*
this function 'showhide' takes 2 params to show and divs
*/

function showhide(hideDiv, showDiv){
	//$("#" + hideDiv).fadeOut(300);
	//$("#" + showDiv).fadeIn(800);
	$("#" + hideDiv).hide('fast');
	$("#" + showDiv).show('fast');
}

function showBig(parent_id){
	toc = "big-"+parent_id;

	var allDivs = document.getElementsByTagName('img');
	for (i=0; i < allDivs.length; i++){
		if (allDivs[i].id.search("big-") >= 0){
			$("#" + allDivs[i].id).hide('fast');
		}
	}
	$("#" + toc).show('fast');
}

function validateregisterf(){
	fm = document.registerf;
	var regexLetter = /^[a-zA-Z\']+$/;

	if (fm.customer_fname.value.replace(/\s/g, "") == ''){
		alert("Please enter first name.");
		fm.customer_fname.focus();
		return false;
	}

	if(!fm.customer_fname.value.replace(/\s/g, "").match(regexLetter)){
		alert("Only alphabetical characters are allowed for first name.");
		fm.customer_fname.focus();
		return false;
	}

	if (fm.customer_lname.value.replace(/\s/g, "") == ''){
		alert("Please enter last name.");
		fm.customer_lname.focus();
		return false;
	}

	if(!fm.customer_lname.value.replace(/\s/g, "").match(regexLetter)){
		alert("Only alphabetical characters are allowed for last name.");
		fm.customer_lname.focus();
		return false;
	}

	if (fm.customer_email.value.replace(/\s/g, "") == ''){
		alert("Please enter email address.");
		fm.customer_email.focus();
		return false;
	}	

	if(! ValidateEmail(fm.customer_email, ''))
		return false;

	if (fm.customer_username.value.replace(/\s/g, "") == ''){
		alert("Please enter username.");
		fm.customer_username.focus();
		return false;
	}

	if (fm.customer_bill_addr.value.replace(/\s/g, "") == ''){
		alert("Please enter billing address.");
		fm.customer_bill_addr.focus();
		return false;
	}

	if (fm.customer_bill_postcode.value.replace(/\s/g, "") == ''){
		alert("Please enter billing postcode.");
		fm.customer_bill_postcode.focus();
		return false;
	}

	if (fm.customer_bill_city.value.replace(/\s/g, "") == ''){
		alert("Please enter billing city.");
		fm.customer_bill_city.focus();
		return false;
	}

	if (fm.customer_bill_country.value.replace(/\s/g, "") == ''){
		alert("Please select billing country.");
		fm.customer_bill_country.focus();
		return false;
	}

	flag = false;
	for (i=0; i<fm.same_ship.length; i++) {
		if (fm.same_ship[i].checked==true){
			if (fm.same_ship[i].value == '0'){
				if (fm.customer_ship_addr.value.replace(/\s/g, "") == ''){
					alert("Please enter shipping address.");
					fm.customer_ship_addr.focus();
					return false;
				}

				if (fm.customer_ship_postcode.value.replace(/\s/g, "") == ''){
					alert("Please enter shipping postcode.");
					fm.customer_ship_postcode.focus();
					return false;
				}

				if (fm.customer_ship_city.value.replace(/\s/g, "") == ''){
					alert("Please enter shipping city.");
					fm.customer_ship_city.focus();
					return false;
				}

				if (fm.customer_ship_country.value.replace(/\s/g, "") == ''){
					alert("Please enter shipping country.");
					fm.customer_ship_country.focus();
					return false;
				}
			} else {
				fm.customer_ship_country.value = fm.customer_bill_country.value.replace(/\s/g, "");
				fm.customer_ship_city.value = fm.customer_bill_city.value.replace(/\s/g, "");
				fm.customer_ship_postcode.value = fm.customer_bill_postcode.value.replace(/\s/g, "");
				fm.customer_ship_addr.value = fm.customer_bill_addr.value.replace(/\s/g, "");
			}
            flag = true;
         }	
	}
	
	if (!flag){
		alert("Please select shipping address.");
		return false;	
	}
}

function setShip(){
	fm = document.registerf;

	for (i=0; i<fm.same_ship.length; i++) {
		if (fm.same_ship[i].checked==true){
			if (fm.same_ship[i].value == '0'){
				fm.customer_ship_country.selectedIndex = 0;
				fm.customer_ship_city.value = '';
				fm.customer_ship_postcode.value = '';
				fm.customer_ship_addr.value = '';
				if (fm.customer_ship_addr.value.replace(/\s/g, "") == ''){
					alert("Please enter shipping address.");
					fm.customer_ship_addr.focus();
					return false;
				}

				if (fm.customer_ship_postcode.value.replace(/\s/g, "") == ''){
					alert("Please enter shipping postcode.");
					fm.customer_ship_postcode.focus();
					return false;
				}

				if (fm.customer_ship_city.value.replace(/\s/g, "") == ''){
					alert("Please enter shipping city.");
					fm.customer_ship_city.focus();
					return false;
				}

				if (fm.customer_ship_country.value.replace(/\s/g, "") == ''){
					alert("Please enter shipping country.");
					fm.customer_ship_country.focus();
					return false;
				}
			} else {
				var ss = fm.customer_ship_country.options;
				for (j = 0; j < ss.length; j++){
					if (ss[j].value == fm.customer_bill_country.value){
						fm.customer_ship_country.selectedIndex = j;
						break;
					}
				}

				fm.customer_ship_city.value = fm.customer_bill_city.value.replace(/\s/g, "");
				fm.customer_ship_postcode.value = fm.customer_bill_postcode.value.replace(/\s/g, "");
				fm.customer_ship_addr.value = fm.customer_bill_addr.value.replace(/\s/g, "");
			}
            flag = true;
         }	
	}
}

function ValidateEmail(email, formName){
		var atCharPresent = false;
		var dotPresent = false;
		
		for ( var Idx = 0; Idx < email.value.length; Idx++ ){
			if ( email.value.charAt ( Idx ) == '@' )
				atCharPresent = true;
			if ( email.value.charAt ( Idx ) == '.' )
				dotPresent = true;
		}
		if ( !atCharPresent || !dotPresent ){
			alert("Please enter a valid email address.");
			email.focus();
			return false;
			}
	return true;
}

function validatefpf(){
	fm = document.fpf;
	if (fm.customer_username.value.replace(/\s/g, "") == ''){
		alert("Please enter username.");
		fm.customer_username.focus();
		return false;
	}
}

function validateedipf(){
	fm = document.registerf;
	if (fm.customer_fname.value.replace(/\s/g, "") == ''){
		alert("Please enter first name.");
		fm.customer_fname.focus();
		return false;
	}

	if (fm.customer_lname.value.replace(/\s/g, "") == ''){
		alert("Please enter last name.");
		fm.customer_lname.focus();
		return false;
	}

	if (fm.customer_email.value.replace(/\s/g, "") == ''){
		alert("Please enter email address.");
		fm.customer_email.focus();
		return false;
	}	

	if(! ValidateEmail(fm.customer_email, ''))
		return false;

	if (fm.customer_username.value.replace(/\s/g, "") == ''){
		alert("Please enter username.");
		fm.customer_username.focus();
		return false;
	}

	if (fm.customer_bill_addr.value.replace(/\s/g, "") == ''){
		alert("Please enter billing address.");
		fm.customer_bill_addr.focus();
		return false;
	}

	if (fm.customer_bill_postcode.value.replace(/\s/g, "") == ''){
		alert("Please enter billing postcode.");
		fm.customer_bill_postcode.focus();
		return false;
	}

	if (fm.customer_bill_city.value.replace(/\s/g, "") == ''){
		alert("Please enter billing city.");
		fm.customer_bill_city.focus();
		return false;
	}

	if (fm.customer_bill_country.value.replace(/\s/g, "") == ''){
		alert("Please enter billing country.");
		fm.customer_bill_country.focus();
		return false;
	}

	if (fm.customer_ship_addr.value.replace(/\s/g, "") == ''){
		alert("Please enter shipping address.");
		fm.customer_ship_addr.focus();
		return false;
	}

	if (fm.customer_ship_postcode.value.replace(/\s/g, "") == ''){
		alert("Please enter shipping postcode.");
		fm.customer_ship_postcode.focus();
		return false;
	}

	if (fm.customer_ship_city.value.replace(/\s/g, "") == ''){
		alert("Please enter shipping city.");
		fm.customer_ship_city.focus();
		return false;
	}

	if (fm.customer_ship_country.value.replace(/\s/g, "") == ''){
		alert("Please enter shipping country.");
		fm.customer_ship_country.focus();
		return false;
	}
}

var comment_changed2 = 0;
var comment_changedl = 0;
var comment_changedg = 0;

function removeText3(email) {
  if(comment_changed2 == 0) {
    email.value='';
    comment_changed2 = 1;
  }
}

function addText3(email) {
  if(email.value == '') {
    email.value = 'Enter Keyword:';
    comment_changed2 = 0;
  }
}

function removeText2(email) {
  if(comment_changedl == 0) {
    email.value='';
    comment_changedl = 1;
  }
}

function addText2(email) {
  if(email.value == '') {
    email.value = 'Username';
    comment_changedl = 0;
  }
}

function removeTextg(password) {
  if(comment_changedg == 0) {
    password.value='';
    comment_changedg = 1;
  }
}

function addTextg(password) {
  if(password.value == '') {
    password.value = '******';
    comment_changedg = 0;
  }
}


//

function addDelevery(oldtotal, snet){
	charge = snet.replace(snet.substring(snet.indexOf('~')),'');
	charge = parseFloat(charge);
	fm = document.orderFrm;	
	document.getElementById('disTot').innerHTML = '&pound; ' + parseFloat(charge+oldtotal)
	fm.payable_amount.value = parseFloat(charge+oldtotal)
}

//
function validatecontact(){
	fm = document.contactF;
	if (fm.name.value=='Name:' || fm.name.value.replace(/\s/g, "") == ''){
		alert("Please enter full name.");
		fm.name.focus();
		return false;
	}

	if (fm.email.value=='Email Address:' || fm.email.value.replace(/\s/g, "") == ''){
		alert("Please enter email address.");
		fm.email.focus();
		return false;
	}	

	if(! ValidateEmail(fm.email, ''))
		return false;

	if (fm.quiry.value=='Your Query:' || fm.quiry.value.replace(/\s/g, "") == ''){
		alert("Please type your query.");
		fm.quiry.focus();
		return false;
	}
	
	if (fm.keystar_scode.value.replace(/\s/g, "") == ''){
		alert("Please enter security code.");
		fm.keystar_scode.focus();
		return false;
	}	
	

}
