// JavaScript Document

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function evaswap(obj, val){
  obj.src = val;
}

function clearMailingName(){
  document.mailing.name.value = '';
}

function clearMailingEmail(){
  document.mailing.email.value = '';
}

function clearVoucher(){
  document.cart.voucher.value = '';
}

function check_search(form) 
{					
	if (form.keywords.value == ''){
		alert("Please enter your keywords...");
		form.keywords.focus();
		return false;
	}
}

function check_sidecats(form) {
	if (form.collection_id.value == ''){
		alert("Please select a product...");
		form.collection_id.focus();
	return false;
	}											
}

function check_gift(form) 
{					
	if (form.name1.value == ''){
		alert("Please enter the name of the recipient...");
		form.name1.focus();
		return false;
	}
	if (form.email1.value == ''){
		alert("Please enter the email address of the recipient...");
		form.email1.focus();
		return false;
	}
}

function check_join(form) {
	var emailFilter=/^.+@.+\..{2,3}$/;
	var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/;			
	if (form.title.value == ''){
		alert("Please select your title...");
		form.title.focus();
		return false;
	}
	if (form.forename.value == ''){
		alert("Please enter your forename...");
		form.forename.focus();
		return false;
	}
	if (form.surname.value == ''){
		alert("Please enter your surname...");
		form.surname.focus();
		return false;
	}
	var stripped = form.telephone.value.replace(/[\(\)\.\-\ ]/g, '');
	if (form.telephone.value=='' || isNaN(parseInt(stripped))) {
		alert("Your telephone number is incomplete or contains invalid characters...");
		form.telephone.focus();
		return false;
	}
	if (form.emailmain.value=='' || form.emailmain.value.match(illegalChars) || !(emailFilter.test(form.emailmain.value))){
		alert("Please enter a valid email address...");
		form.emailmain.focus();
		return false;
	}
	if (form.emailmain.value != form.emailconf.value){
		alert("Your email did not match...");
		form.emailconf.focus();
		return false;
	}
	if (form.address1.value == ''){
		alert("Please enter your address...");
		form.address1.focus();
		return false;
	}
	if (form.city.value == ''){
		alert("Please enter your city/town...");
		form.city.focus();
		return false;
	}
	if (form.postcode.value == ''){
		alert("Please enter your postcode...");
		form.postcode.focus();
		return false;
	}
	if (form.username.value.length < 6){
		alert("Please enter a username of at least 6 characters...");
		form.username.focus();
		return false;
	}
	if (form.password.value.length < 6){
		alert("Please enter a password of at least 6 characteres...");
		form.password.focus();
		return false;
	}
	if (form.password.value != form.passwordconf.value){
		alert("Your password did not match...");
		form.passwordconf.focus();
		return false;
	}				
}

function check_forgot_password(form) 
{
var emailFilter=/^.+@.+\..{2,3}$/;
var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/;
var re = /\s/;									
	if (form.postcode.value == ''){
		alert("Please enter your postcode...");
		form.postcode.focus();
		return false;
	}
	if (form.email.value == '' || form.email.value.match(illegalChars) || !(emailFilter.test(form.email.value))){
		alert("Please enter a valid email address...");
		form.email.focus();
		return false;
	}									
}

function check_contact(form) 
{
var emailFilter=/^.+@.+\..{2,3}$/;
var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/;
var re = /\s/;									
	if (form.name.value == ''){
		alert("Please enter your name...");
		form.name.focus();
		return false;
	}
	if (form.email.value=="" || form.email.value.match(illegalChars) || !(emailFilter.test(form.email.value))){
		alert("Please enter a valid email address...");
		form.email.focus();
		return false;
	}
	if (form.subject.value == ''){
		alert("Please enter a subject for your enquiry...");
		form.subject.focus();
		return false;
	}
	if (form.message.value == ''){
		alert("Please enter the nature of your enquiry...");
		form.message.focus();
		return false;
	}
}

function check_checkout(form) 
{
var emailFilter=/^.+@.+\..{2,3}$/;
var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/;
var re = /\s/;									
	if (form.BillingLastName.value == ''){
		alert("Please enter your surname...");
		form.BillingLastName.focus();
		return false;
	}								
	if (form.BillingFirstName.value == ''){
		alert("Please enter your forename...");
		form.BillingFirstName.focus();
		return false;
	}
	if (form.BillingAddress1.value == ''){
		alert("Please your billing address...");
		form.BillingAddress1.focus();
		return false;
	}
	if (form.BillingCity.value == ''){
		alert("Please enter your billing city...");
		form.BillingCity.focus();
		return false;
	}
	if (form.BillingCounty.value == ''){
		alert("Please enter your billing county...");
		form.BillingCounty.focus();
		return false;
	}
	if (form.BillingPostal.value == ''){
		alert("Please enter your billing post code...");
		form.BillingPostal.focus();
		return false;
	}
	var stripped = form.ShopperTel.value.replace(/[\(\)\.\-\ ]/g, '');
	if (form.ShopperTel.value=='' || isNaN(parseInt(stripped))) {
		alert("Your telephone number is incomplete or contain invalid characters...");
		form.ShopperTel.focus();
		return false;
	}
	if (form.ShopperEmail.value=="" || form.ShopperEmail.value.match(illegalChars) || !(emailFilter.test(form.ShopperEmail.value))){
		alert("Please enter a valid email address...");
		form.ShopperEmail.focus();
		return false;
	}
	if (form.ShippingFirstName.value == ''){
		alert("Please enter your surname...");
		form.ShippingFirstName.focus();
		return false;
	}	
	if (form.ShippingLastName.value == ''){
		alert("Please enter your forename...");
		form.ShippingLastName.focus();
		return false;
	}																
	if (form.ShippingAddress1.value == ''){
		alert("Please your shipping address...");
		form.ShippingAddress1.focus();
		return false;
	}
	if (form.ShippingCity.value == ''){
		alert("Please enter your shipping city...");
		form.ShippingCity.focus();
		return false;
	}
	if (form.ShippingCounty.value == ''){
		alert("Please enter your shipping county...");
		form.ShippingCounty.focus();
		return false;
	}
	if (form.ShippingPostal.value == ''){
		alert("Please enter your shipping post code...");
		form.ShippingPostal.focus();
		return false;
	}
}

function check_checkout1(form) 
{
var emailFilter=/^.+@.+\..{2,3}$/;
var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/;
var re = /\s/;									
	if (form.BillingLastName.value == ''){
		alert("Please enter your surname...");
		form.BillingLastName.focus();
		return false;
	}								
	if (form.BillingFirstName.value == ''){
		alert("Please enter your forename...");
		form.BillingFirstName.focus();
		return false;
	}
	if (form.BillingAddress1.value == ''){
		alert("Please your billing address...");
		form.BillingAddress1.focus();
		return false;
	}
	if (form.BillingCity.value == ''){
		alert("Please enter your billing city...");
		form.BillingCity.focus();
		return false;
	}
	if (form.BillingCounty.value == ''){
		alert("Please enter your billing county...");
		form.BillingCounty.focus();
		return false;
	}
	if (form.BillingPostal.value == ''){
		alert("Please enter your billing post code...");
		form.BillingPostal.focus();
		return false;
	}
	var stripped = form.ShopperTel.value.replace(/[\(\)\.\-\ ]/g, '');
	if (form.ShopperTel.value=='' || isNaN(parseInt(stripped))) {
		alert("Your telephone number is incomplete or contain invalid characters...");
		form.ShopperTel.focus();
		return false;
	}
	if (form.ShopperEmail.value=="" || form.ShopperEmail.value.match(illegalChars) || !(emailFilter.test(form.ShopperEmail.value))){
		alert("Please enter a valid email address...");
		form.ShopperEmail.focus();
		return false;
	}
	if (form.ShippingFirstName.value == ''){
		alert("Please enter your surname...");
		form.ShippingFirstName.focus();
		return false;
	}	
	if (form.ShippingLastName.value == ''){
		alert("Please enter your forename...");
		form.ShippingLastName.focus();
		return false;
	}																
	if (form.ShippingAddress1.value == ''){
		alert("Please your shipping address...");
		form.ShippingAddress1.focus();
		return false;
	}
	if (form.ShippingCity.value == ''){
		alert("Please enter your shipping city...");
		form.ShippingCity.focus();
		return false;
	}
	if (form.ShippingCounty.value == ''){
		alert("Please enter your shipping county...");
		form.ShippingCounty.focus();
		return false;
	}
	if (form.ShippingPostal.value == ''){
		alert("Please enter your shipping post code...");
		form.ShippingPostal.focus();
		return false;
	}
	if (form.username.value == ''){
		alert("Please enter a username...");
		form.username.focus();
		return false;
	}
	if (form.password.value == ''){
		alert("Please enter a password...");
		form.password.focus();
		return false;
	}
}

function singleSubmit(trgForm)
{
    trgForm.submitButton.disabled = true;
    trgForm.resetButton.disabled = true;
}

function toggleBillingInfo(trgForm)
{
    if (trgForm.SubmitBilling.checked == true)
    {
        trgForm.ShippingFirstName.value = trgForm.BillingFirstName.value ;
        trgForm.ShippingLastName.value = trgForm.BillingLastName.value ;
        trgForm.ShippingAddress1.value = trgForm.BillingAddress1.value ;
        trgForm.ShippingAddress2.value = trgForm.BillingAddress2.value ;
        trgForm.ShippingCity.value =  trgForm.BillingCity.value ;
		trgForm.ShippingCounty.value =  trgForm.BillingCounty.value ;
        trgForm.ShippingPostal.value = trgForm.BillingPostal.value ;
    }
    else
    {
        trgForm.ShippingFirstName.value = "";
        trgForm.ShippingLastName.value = "";
        trgForm.ShippingAddress1.value = "";
        trgForm.ShippingAddress2.value = "";
        trgForm.ShippingCity.value = "";
		trgForm.ShippingCounty.value = "";
        trgForm.ShippingPostal.value = "";
    }
}

function resetDynamicFields()
{
	document.cpiForm.OrderId.value=Math.round(Math.random()*10000000000);
	document.cpiForm.TimeStamp.value=new Date().valueOf();
}