
function cd()
{
 var tmpcookie = new Date();
   chkcookie = (tmpcookie.getTime() + '');
   document.cookie = "chkcookie=" + chkcookie + "; path=/";
    if (document.cookie.indexOf(chkcookie,0) < 0) {
      alert("nocookies.html");
      }
    else {
      alert("cookies.html");
    }


}




//Client side cooKie detection
function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}


function SubmitForm(objForm)
{
    var bValidFields = true;
    

//SELECT
var formObject = objForm.getElementsByTagName("select");//alert(formObjects.length);
	
for(var x = 0;x < formObject.length;x++)
{
		//Check required fields
		if(formObject[x].parentNode.className=="req")
		{
			if(formObject[x].selectedIndex == 0)
			{bValidFields = false;formObject[x].style.color="red";}
			else{formObject[x].style.color="";}
			
		if(formObject[x].options[formObject[x].selectedIndex].value=="Other")
		{
		var strName=formObject[x].name;
		var strID=formObject[x].id;
		
		formObject[x].parentNode.innerHTML="<input type='text' id='"+strID+"' name='"+strName+"'/>"
		}else{};
		}
}		
	
	
// INPUT TYPE TEXT	
var formObjects = objForm.getElementsByTagName("input");//alert(formObjects.length);

for(var x = 0;x < formObjects.length;x++)
{	
				if(formObjects[x].type=="text")
				{
				
				
								        
											//Check for required fields
											if(formObjects[x].parentNode.className=="req" && formObjects[x].value=="")
											{bValidFields = false;formObjects[x].parentNode.parentNode.style.backgroundColor="lightblue";}
											else{
											
											
															//Check if current field requires validation
															switch (formObjects[x].id) 
															{ 
															case "url": 
											                
																if(urlValid(formObjects[x]))
																{formObjects[x].style.borderColor="";}
																else{bValidFields = false; formObjects[x].parentNode.parentNode.style.backgroundColor="lightblue";};
											                     
															break; 
															case "email": 
											                
																if(emailValid(formObjects[x]))
																{formObjects[x].style.borderColor="";}
																else{bValidFields = false; formObjects[x].parentNode.parentNode.style.backgroundColor="lightblue";};
											                     
															break; 
															case "mobile": 
											        	    
																if(ValidatePhone(formObjects[x].value))
																{formObjects[x].style.borderColor="";}
																else{bValidFields = false;formObjects[x].parentNode.parentNode.style.backgroundColor="lightblue";} ; 
											        	    
															break; 
															case "phone": 
											        	    
																if(ValidatePhone(formObjects[x].value))
																{formObjects[x].style.borderColor="";}
																else{bValidFields = false;formObjects[x].parentNode.parentNode.style.backgroundColor="lightblue";}
											        	     
															break; 
												            
															default:
											        			       
        									formObjects[x].parentNode.parentNode.style.backgroundColor=""
												
															}
        									}
			
						}
						else //NOT INPUT TYPE TEXT
						{
						////////////////////////////////////////////////
				
								switch (formObjects[x].type) 
								{ 
								case "radio": 
								 
									if(formObjects[x].parentNode.className=="req")
									{
									var optGroup = objForm.elements[formObjects[x].name];    
									bValidFields=false;

									for(var t=0;t < optGroup.length;t++){
										if(optGroup[t].checked){
										formObjects[x].parentNode.parentNode.style.backgroundColor=""
										//alert(optGroup[t].name);
										bValidFields=true;
										}
									}
									
										if(bValidFields==false)
										{//alert(formObjects[x].parentNode.tagName)
										formObjects[x].parentNode.parentNode.style.backgroundColor="lightblue";x=formObjects.length;break;}
									}
									     
								break; 
								case "checkbox": 
								 
									if(formObjects[x].parentNode.className=="req")
									{
									var optGroup = objForm.elements[formObjects[x].name];    
									bValidFields=false;

									for(var t=0;t < optGroup.length;t++){
										if(optGroup[t].checked){
										formObjects[x].parentNode.parentNode.style.backgroundColor=""
										//alert(optGroup[t].name);
										bValidFields=true;
										}
									}
									
										if(bValidFields==false)
										{//alert(formObjects[x].parentNode.tagName)
										formObjects[x].parentNode.parentNode.style.backgroundColor="lightblue";x=formObjects.length;break;}
									}
									     
								break; 


								default:
								}
		        	   
		
						////////////////////////////////////////////////
						}

}


if(bValidFields==true)
{objForm.submit()}
else
{
alert("Please check the highlighted fields and try again.");}    
}

// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

function setOther(formObj)
{
		var strName=formObj.name;
		var strID=formObj.id;
		if(formObj.options[formObj.selectedIndex].value=="Other"){
		formObj.parentNode.innerHTML="<input type='text' id='"+strID+"' name='"+strName+"'/>"
		}
}

// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
function checkPass(form)
{
if(form.password.value=="")
   {alert("You must enter your original password");return}

if(form.password1.value=="")
   {alert("You Must Specify a New Password");return}
   
   if(form.password1.value==form.password2.value)
   {form.submit()}else
   {alert("The new passwords entered do not match")}
}


function ValidateUserInfo(form) 
{ 
    //alert(ftsLocale);

        var firstname = form.firstname.value; 
        var lastname = form.lastname.value; 
        var address = form.street.value; 

        var postcode = form.postcode.value; 
        
       if(form.username!=null){
         var email = form.username.value; 
         }//var email = form.email.value; 
               
        var phone = form.Tel1.value; 
        var errMsg = ""; 
        var gotFocus = 0; 
        var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i; 
        var numFilter=/^\d*/; 
        
       /*
       if(form.usernam){
       if(!filter.test(email)) 
        { 
                errMsg += "You must enter a valid email address\n"; 
                if ( gotFocus == 0) { 
                        form.email.focus(); 
                        gotFocus = 1; 
                } 
        } 
      }
      */
         if( 0 == firstname.length)      
        { 
                errMsg = "You must enter your first name\n"; 
                if ( gotFocus == 0) { 
                        form.firstname.focus(); 
                        gotFocus = 1; 
                } 
        } 
        
        if( 0 == lastname.length)       
        { 
                errMsg = "You must enter your last name\n"; 
                if ( gotFocus == 0) { 
                        form.lastname.focus(); 
                        gotFocus = 1; 
                } 
        } 
      /*  
        if( 0 == address.length)        
        { 
                errMsg += "You must enter your address\n"; 
                if ( gotFocus == 0) { 
                        form.address.focus(); 
                        gotFocus = 1; 
                } 
        } 

        if( !validateZIP(postcode))     
        { 
        if(ftsLocale=="en-gb"){errMsg += "Please check your Postal Code.\n";} else
	   {errMsg += "Please enter your 5 digit or 5 digit-4 zip code e.g. 12345-1234";}
		if ( gotFocus == 0) { 
                        form.postcode.focus(); 
                        gotFocus = 1; 
                } 
        } 

        if( !ValidatePhone(phone) )     
        { 
                errMsg += "You must enter a valid phone number\n"; 
                if ( gotFocus == 0) { 
                        form.Tel1.focus(); 
                        gotFocus = 1; 
                } 
        } 

        */
        if( errMsg.length > 0 ) 
        { 
                msg = "Please fix the following errors:\n\n"; 
                msg += errMsg; 
                alert( msg); 
                return false;           
        } 
        else 
        { 
                form.submit(); 
        } 
} 


function ValidateRegistration(form)
{

	var firstname = form.firstname.value;
	var lastname = form.lastname.value;
	var housenum = form.HouseNum.value;
	var street = form.street.value;
	//var town = form.town.value;

	var postcode = form.postcode.value;
	var email = form.username.value;
	var password = form.password.value;
	var password2 = form.password2.value;
		
	var phone = form.Tel1.value;
	var phone2 = form.Tel2.value;
	var errMsg = "";
	var gotFocus = 0;
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	var numFilter=/^\d*/;

	if(!filter.test(email))	
	{
		errMsg = "You must enter a valid Email Address\n";
		if ( gotFocus == 0) {
			form.username.focus();
			gotFocus = 1;
		}
	}

	if( 0 == password.length)	
	{
		errMsg += "You must enter a Password\n";
		if ( gotFocus == 0) {
			form.password.focus();
			gotFocus = 1;
		}
	}
	else
	{
		if (password != password2){
			errMsg += "Passwords don't match\n";
			if ( gotFocus == 0) {
				form.password.focus();
				gotFocus = 1;
			}
		}
	}
	
	if( 0 == firstname.length)	
	{
		errMsg += "You must enter your First Name.\n";
		if ( gotFocus == 0) {
			form.firstname.focus();
			gotFocus = 1;
		}
	}
	
	if( 0 == lastname.length)	
	{
		errMsg += "You must enter your Last Name.\n";
		if ( gotFocus == 0) {
			form.lastname.focus();
			gotFocus = 1;
		}
	}
	
	if( 0 == postcode.length)	
	{
	    if(ftsLocale=="en-gb")
	    {errMsg += "You must enter your Post Code.\n";}
	    else{errMsg += "You must enter your Zip code.\n";}
		
		if ( gotFocus == 0) {
			form.postcode.focus();
			gotFocus = 1;
		}
	}

	if( !ValidatePhone(phone) )	
	{
		errMsg += "Home Telephone number is not valid.\n";
		if ( gotFocus == 0) {
			form.Tel1.focus();
			gotFocus = 1;
		}
	}
	if( phone2.length > 0  )	
	{	
		if( !ValidatePhone(phone2) ){
			errMsg += "Work Telephone number is not valid.\n";
			if ( gotFocus == 0) {
				form.Tel2.focus();
				gotFocus = 1;
			}
		}
	}

	if( errMsg.length > 0 )
	{
		msg = "Please fix the following errors:\n\n";
		msg += errMsg;
		alert( msg);
		return false;		
	}
	else
	{
		return true;
	}
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 


function sub_pass_rem(objFrm)
{
if(ValidateEmail(objFrm.email))
{objFrm.submit()}
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 


function toggleMenu( menu ) {
	if( menu.style.display == "none" ) {
		menu.style.display = "";
	} else {
		menu.style.display = "none";
	}
} 

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 


function showMenu( myMenu ) {
    myMenu.style.display="";
}

function hideMenu( myMenu ) {
    myMenu.style.display="none";
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 


function clickSubmit(){
	if(ValidateUserInfo(document.forms["userInfo"]) == true)
	{
		document.forms["userInfo"].submit();
		return true;
	} else {
		return false;
	}
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 


function SubmitRegistration(){
	if(ValidateRegistration(document.forms["regDetails"])== true)
	{
		document.forms["regDetails"].submit();
		return true;
	} else {
		return false;
	}
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 


function SubmitEmailReg(){
   var objForm = document.forms["regEmail"];
   if(ValidateEmail(objForm.username))
	{
	
	if(objForm.password.value=="")
        {alert("Password empty");return}
   
   if(String(objForm.password.value).length < 7)
        {alert("Your password must be at least seven characters or more");return}
   
   if(objForm.password.value!=objForm.password2.value)
        {alert("The passwords entered do not match")}
        else
        {objForm.submit();return true;}
	} else {
		return false;
	}

}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

function SubmitLogin(form){
	var name = form.username.value;
	var password = form.password.value;
	var errMsg = "";
	var gotFocus = 0;
	
	if( 0 == name.length)	
	{
		errMsg = "You must enter your username\n";
		if ( gotFocus == 0) {
			form.username.focus();
			gotFocus = 1;
		}
	}
	
	if( 0 == password.length)	
	{
		errMsg += "You must enter your password\n";
		if ( gotFocus == 0) {
			form.password.focus();
			gotFocus = 1;
		}
	}
	if( errMsg.length > 0 )
	{
		alert( errMsg);
		return false;		
	}
	else
	{
		form.submit();
	}
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 


function updateShipping(){
	
	if(document.forms["user_info"].country.value != "UK United Kingdom" )
	{
		document.forms["user_info"].shipping.value = "£7.00"
	} else {
		document.forms["user_info"].shipping.value = "£0.00"
	}
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

function BuildWorldPayParameters(theform)
{
	var name = "";
	var address = "";
	var tax = ""
	//alert("!");
	var title = theform.title.value;
	var firstname = theform.firstname.value;
	var lastname = theform.lastname.value
	
	var house_num = theform.house_num.value;
	var street = theform.street.value;
	//var town = theform.town.value;
	//var state = theform.state.value;
	var city = theform.city.value;
	
var state = theform.state.value;
	
	var amount = theform.amount.value;
	var tax_rate = theform.MC_taxRate.value;
	
	tax = amount * tax_rate;
	amount = (tax*1) + (amount*1);
	theform.amount.value = amount;
	
	if (title.length != 0){
		name = title;
	}
	if (firstname.length != 0){
		name += " ";
		name += firstname;
	}
	if (lastname.length != 0){
		name += " ";
		name += lastname;
	}
	theform.name.value = name;
	
	if (house_num.length != 0){
		address = house_num;
	}
	if (street.length != 0){
		address += " ";
		address += street;
	}
	if (city.length != 0){
		address += ", ";
		address += city;
	}
	if (state.length != 0){
		address += ", ";
		address += state;
	}
	theform.address.value = address;
	
	theform.submit();
}


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.0
  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 && document.getElementById) x=document.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 fn_display(selID,selTAB)
{
var objTabs=document.all('f_group_tabs').childNodes;
var objGroup=document.all('f_group').childNodes;
for(var x=0;x < objGroup.length;x++)
	{
	objGroup.item(x).style.display="none";
	objTabs.item(x).className="tab_off";
	}
document.all('f_group').all(selID).style.display="";	
selTAB.className="tab_on";	
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

//                                                  Validation Functions

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

function validateZIP(field) {
//alert(ftsLocale);
if(ftsLocale=="en-gb"){return true}
	var valid = "0123456789-";
	var hyphencount = 0;
	var len = 0;

	if (field.length!=5 && field.length!=10) {
		return false;
	}
	for (var i=0; i < field.length; i++) {
		temp = "" + field.substring(i, i+1);
		if (temp == "-") hyphencount++;
		if (valid.indexOf(temp) == "-1") {
			return false;
		}
		if ((hyphencount > 1) || ((field.length==10) && ""+field.charAt(5)!="-")) {
			return false;
		}
	}
	return true;
}  
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

function urlValid(obj){
	var str=obj.value;
	if (str==""){return true;}
	var filter=/^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.){1}([\w]+)(.[\w]+){1,2}$/;
	if (filter.test(str)){return true;}else{return false;}
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

function emailValid(obj){
	var str=obj.value;
	if (str==""){return true;}
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i ;
	if (filter.test(str)){return true;}else{return false;}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

function ValidateEmail(input){
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i ;
	if (filter.test(input.value))
	return true;
	else{
	alert("Please input a valid email address!")
	return false
}
return (testresults)
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

function ValidatePhone(phoneNumber)
{
    var Chars = "0123456789 -";

    if (!phoneNumber) return true;
   
    if (phoneNumber.length == 0){
	return false;
    }

    for (var i = 0; i < phoneNumber.length; i++) {
       if (Chars.indexOf(phoneNumber.charAt(i)) == -1)
          return false;
    }
    return true;
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

