// JavaScript Document

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_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_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 getEl(id){
	return document.getElementById(id);	
}

function GetXmlHttpObject(){ 
	var objXMLHttp = null
	if (window.XMLHttpRequest){
		objXMLHttp = new XMLHttpRequest()
	} else if (window.ActiveXObject) {
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
} 

function AJAX_handler(aRequestURL, aData, aStateChangeHandler){
	xmlHttp = GetXmlHttpObject()
		
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request")
		return
	} 
	
	xmlHttp.onreadystatechange = aStateChangeHandler
	xmlHttp.open("POST",aRequestURL,true)
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	xmlHttp.send(aData + "&ajax_uid=" + Math.random())	
}

function AJAX_response(){
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		return xmlHttp.responseText
	}
}

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function logout(){
	if(confirm("Are you sure you wish to log out?")){
		window.location = "log-out.php"	
	}
	
}
function confirm_empty_cart(){
	if(confirm("Are you sure you wish to empty your shopping basket?")){
		window.location = "basket-empty.php"	
	}
	
}

function get_radio_value(aField){
 
	for (var i=0; i < aField.length; i++) {
	   if (aField[i].checked)  {
		  var radio_val = aField[i].value;
		}
	}
	return radio_val
}


function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}



function currencyConverter(aAmount){
	settings ='height=180,';
	settings +='width=620,';
	settings +='scrollbars=no,';
	settings +='resizable=no';
	
	window.open('http://www.xe.com/ecc/input.cgi?Template=se&Amount=' + aAmount + '&From=AUD', 'ccwindow', settings)
	
}

function chooser(aWhich, aPly){
	settings ='height=600,';
	settings +='width=940,';
	settings +='scrollbars=yes,';
	settings +='resizable=no';
	
	window.open('chooser.php?which=' + aWhich + '&ply=' + aPly, 'ccwindow', settings)
	
}

function choosen(aWhich, aCode, aTitle){
	getEl("custom_swatch_" + aWhich).src = "yarn-swatches/" + aCode + ".jpg"
	getEl("custom_swatch_" + aWhich).title =  aCode + " - " + aTitle
	getEl("custom_swatch_code_" + aWhich).value =  aCode
	setCheckedValue(document.pattern_config.colour_scheme,4)
	
}

function is_whole_positive_int(aValue){
	tValid = true
	if(aValue == ""){
		aValue = "0"
	}
	if(aValue != "0"){
		if(isNaN(aValue)){
			tValid = false
		} else {
			var nums = /^[0-9]\d*$/
			
			if(!nums.test(aValue)){
				tValid = false
			}
		}		
	}
	return tValid;
}

function validate_qty(aField, aDefault, aMin){
	if(!is_whole_positive_int(aField.value)){
		 
		if(aMin == 0 && parseInt(aField.value) == 0){
			
		} else {
			if(aMin == 0){
				alert("Qty must be a whole number 0 or greater");	
			} else {
				alert("Qty must be a whole number greater than 0");	
			}
		}
		aField.value = aDefault;
	}
}

function validate_yarn_adder(aCode, aPlyCount, aCookie){
	if(aCookie == false){
		alert("Please accept Cookies in your Privacy settings to enable online ordering.\nOnce enabled you will need to reload this page.")
	} else {
		var tValidatedOK = true
		 
		 qty_field = getEl("qty_" + aCode)
		 
		if(qty_field.value == 0){
			tValidatedOK = false
		} else if(!is_whole_positive_int(qty_field.value)){
			tValidatedOK = false
		}
		if(tValidatedOK == false){
				alert("Qty must be a whole number greater than 0");	
		} else { 
			AJAX_handler("yarns_add_cart_ajax.php", "code=" + aCode + "&qty=" + qty_field.value + "&ply_count=" + aPlyCount, yarn_added);
		}	
	}
	
}

 
function yarn_added(){
	if(AJAX_response() != undefined){
		if(AJAX_response() != 'error'){
			arr = AJAX_response().toString().split("||")
		 
			if( arr[1] != undefined){
				getEl("cart_items").innerHTML = arr[0] + " Items | $" + arr[1]
			 	alert(arr[2] + " has been added to your Basket")
			} else {
				alert("A problem was encountered.\nPlease try adding the Yarn again");
			}
		} else {
			 alert("A problem was encountered.\nPlease try adding the Yarn again");
		}
	}
}




function validate_pattern_adder(){
	var tValidatedOK = true
		
	frm = document.pattern_adder
	if(frm.qty.value == 0){
			tValidatedOK = false
	} else if(!is_whole_positive_int(frm.qty.value)){
		tValidatedOK = false
	}
	if(tValidatedOK == false){
			alert("Qty must be a whole number greater than 0");	
	} else { 
		frm.submit()
	}	
	
	
}

function validate_pattern_config(aCustomColours){
	 
	var tValidatedOK = true
	var tMessage = "The following field(s) are required:\n\n"

	 frm = document.pattern_config 
 	
	 if(frm.only_custom_colours_available.value == "true"){
		 if(frm.colour_scheme.checked){
			arr  = frm.custom_colours.value.split(",")
			custom_validated = true
			for(i=0;i<arr.length;i++){
			
				if(getEl("custom_swatch_code_" + arr[i] ).value == ""){
					custom_validated = false						 
				}
			}
			if(!custom_validated){
				tMessage = tMessage + "      Please Choose all the Colours for your Custom Colour Way\n"
				tValidatedOK = false
			}
		 } else {
			tMessage = tMessage + "      Please select a Colour Way\n"
			tValidatedOK = false
		 }
	 } else {
		 
		 if(get_radio_value(frm.colour_scheme) == undefined){
			 tMessage = tMessage + "      Please select a Colour Way\n"
			 tValidatedOK = false
		 } else {
			 
			 if(get_radio_value(frm.colour_scheme) == 4){
				arr  = frm.custom_colours.value.split(",")
				custom_validated = true
				for(i=0;i<arr.length;i++){
					if(getEl("custom_swatch_code_" + arr[i] ).value == ""){
						custom_validated = false						 
					}
				}
				if(!custom_validated){
					tMessage = tMessage + "      Please Choose all the Colours for your Custom Colour Way\n"
					tValidatedOK = false
				}
			 }
		 }
		 
		 
	 }
	 
	
	  
	if(frm.size.length == undefined){
	
		if(frm.size.checked == false){
			tMessage = tMessage + "      Please select a Size\n"
			tValidatedOK = false
				 
		}
	} else {
		 
		if (get_radio_value(frm.size) == undefined){
			tMessage = tMessage + "      Please select a Size\n"
			tValidatedOK = false
		} 
	}
	if(tValidatedOK == false){
			 alert(tMessage)
	} else {
		 frm.submit()
	}	

}

function validate_order_preview(){
	var tValidatedOK = true
	var tMessage = "The following field(s) are required:\n\n"

	 frm = document.order_preview 
	frm.submit()
}

function order_preview_adjust(aWhich, aId, aAmount){
	frm = document.order_preview
	switch(aWhich){
		case "pattern":
			frm.qty.value = parseInt(frm.qty.value) + parseInt(aAmount)
			if(frm.qty.value < 0){
				frm.qty.value = 0	
			} else {
				rrp = parseFloat(frm.rrp.value)
				getEl("cart_product_qty").innerHTML = frm.qty.value
				total =  parseFloat(frm.total.value) + (rrp * parseInt(aAmount))
				getEl("cart_product_price").innerHTML =  "$" + (rrp * parseInt(frm.qty.value)).toFixed(2);
				frm.total.value = total
				getEl("total_display").innerHTML	= "$" + total.toFixed(2);
			} 
			
			 AJAX_handler("basket_adjust_ajax.php", "which=qty_" + frm.cart_item_id.value + "&qty=" + frm.qty.value, basket_adjusted);
			break;
		case "cc":
			frm.elements["qty_cc" + aId].value = parseInt(frm.elements["qty_cc" + aId].value) + parseInt(aAmount)
	
			if(frm.elements["qty_cc" + aId].value < 0){
				frm.elements["qty_cc" + aId].value = 0	
			} else {
				rrp = parseFloat(frm.elements["rrp_cc" + aId].value)
				
				getEl("qty_cc_display" + aId).innerHTML = frm.elements["qty_cc" + aId].value
				total =  parseFloat(frm.total.value) + (rrp * parseInt(aAmount))
				getEl("cc_total" + aId).innerHTML =  "$" + (rrp * parseInt(frm.elements["qty_cc" + aId].value)).toFixed(2);
				frm.total.value = total
				getEl("total_display").innerHTML	= "$" + total.toFixed(2);
			}
			
		 
			
			 AJAX_handler("basket_adjust_ajax.php", "which=qty_" + frm.cart_item_id.value + "_cc" + aId +  "&qty=" + frm.elements["qty_cc" + aId].value, basket_adjusted);
			break;
		case "acs":
			frm.elements["qty_acs" + aId].value = parseInt(frm.elements["qty_acs" + aId].value) + parseInt(aAmount)
	
			if(frm.elements["qty_acs" + aId].value < 0){
				frm.elements["qty_acs" + aId].value = 0	
			} else {
				rrp = parseFloat(frm.elements["rrp_acs" + aId].value)
				
				getEl("qty_acs_display" + aId).innerHTML = frm.elements["qty_acs" + aId].value
				total =  parseFloat(frm.total.value) + (rrp * parseInt(aAmount))
				getEl("acs_total" + aId).innerHTML =  "$" + (rrp * parseInt(frm.elements["qty_acs" + aId].value)).toFixed(2);
				frm.total.value = total
				getEl("total_display").innerHTML	= "$" + total.toFixed(2);
			}
		 
			 AJAX_handler("product_order_preview_accessories_ajax.php", "acs_id=" + aId + "&qty=" + frm.elements["qty_acs" + aId].value + "&cid=" + frm.cart_item_id.value , basket_adjusted);
			break;
	}
	
}



function currencyConverterBasket(){
	settings ='height=180,';
	settings +='width=620,';
	settings +='scrollbars=no,';
	settings +='resizable=no';
	
	window.open('http://www.xe.com/ecc/input.cgi?Template=se&Amount=' + getEl("cart_total_hidden").value + '&From=AUD', 'ccwindow', settings)
	
}

function validate_qty_basket(aField, aDefault, aMin){
	if(!is_whole_positive_int(aField.value)){
		 
		if(aMin == 0 && parseInt(aField.value) == 0){
			
		} else {
			if(aMin == 0){
				alert("Qty must be a whole number 0 or greater");	
			} else {
				alert("Qty must be a whole number greater than 0");	
			}
		}
		aField.value = aDefault;
	}
	
	
}

function basket_adjust(aWhich, aAmount){
	frm = document.form_basket
	tVal =  parseInt(frm.elements[aWhich].value) + parseInt(aAmount)
	if(tVal <= 0){
		tVal = 0;
	} 
	frm.elements[aWhich].value = tVal;
	
	AJAX_handler("basket_adjust_ajax.php", "which=" + aWhich + "&qty=" + tVal, basket_adjusted);
	recalculate_basket();
}

function basket_adjust_typed_in(aField, aType){
	val = document.getElementById(aField).value
	 if(!is_whole_positive_int(val)){
		alert("Qty must be a whole number 0 or greater");	
		document.getElementById(aField).value = 0;		
	}
	AJAX_handler("basket_adjust_ajax.php", "which=" + aField + "&qty=" + val, basket_adjusted);
	recalculate_basket();
}


function basket_adjusted(){
	if(AJAX_response() != undefined){
		if(AJAX_response() != 'error'){
			arr = AJAX_response().toString().split("||")
		 
			if( arr[1] != undefined){
				getEl("cart_items").innerHTML = arr[0] + " Items | $" + arr[1]
				getEl("cart_total_display").innerHTML = "$" + arr[1]
				
			} else {
				alert("A problem was encountered.\nPlease try again");
			}
		} else {
			 alert("A problem was encountered.\nPlease try again");
		}
	}
}



function validate_basket(){
	var tValidatedOK = true
	var tMessage = "All Quantity fields must be a whole number 0 or greater."
	
	frm = document.form_basket
	
	arr_ids = getEl("expected_ids").value.split(",")
	arr_has_colours = getEl("has_colours").value.split(",")
	
	for(i=0; i < arr_ids.length; i++){
		 
		if(!is_whole_positive_int(frm.elements["qty_" + arr_ids[i] ].value)){
			tValidatedOK = false;
		}
		
		has_colours = false
		for(j=0; j < arr_has_colours.length; j++){
			if(arr_has_colours[j] == arr_ids[i]){
			   has_colours = true
			}
		}
		
		if(has_colours) {
			for(j=1; j<=10; j++){
				if(frm.elements["qty_" + arr_ids[i] + "_cc" + j ]){
					if(!is_whole_positive_int(frm.elements["qty_" + arr_ids[i] + "_cc" + j  ].value)){
						tValidatedOK = false;
					}
					 
				}
			}
		}
		
	}
	
	if(tValidatedOK == false){
		alert(tMessage)
	} else {
		frm.submit()
	}
}

function recalculate_basket(){	
	cart_total = 0;
	arr_ids = getEl("expected_ids").value.split(",")
	arr_has_colours = getEl("has_colours").value.split(",")
	
	frm = document.form_basket
	for(i=0; i < arr_ids.length; i++){
		rrp = parseFloat(frm.elements["rrp_" + arr_ids[i] ].value)
		qty =  parseInt(frm.elements["qty_" + arr_ids[i] ].value) 
		getEl("sub_" + arr_ids[i]).innerHTML = "$" + (rrp * qty).toFixed(2);
		
		cart_total = cart_total + (rrp * qty)
		
		has_colours = false
		for(j=0; j < arr_has_colours.length; j++){
			if(arr_has_colours[j] == arr_ids[i]){
			   has_colours = true
			}
		}
		
		if(has_colours) {
			for(j=1; j<=10; j++){
				if(frm.elements["qty_" + arr_ids[i] + "_cc" + j ]){
					rrp = parseFloat(frm.elements["rrp_" + arr_ids[i] + "_cc" + j ].value) 
					qty =  parseInt(frm.elements["qty_" + arr_ids[i] + "_cc" + j ].value) 
					getEl("sub_" + arr_ids[i] + "_cc" + j).innerHTML = "$" + (rrp * qty).toFixed(2);
					
					cart_total = cart_total + (rrp * qty)
				}
			}
		}
		
	}
	
	//getEl("cart_total_display").innerHTML = "$" + cart_total.toFixed(2); 
	getEl("cart_total_hidden").value = cart_total;
}

function check_email(aVal){
	var tValidatedOK = true
	if(aVal != 0){
		var error = false
		email = aVal
		var at="@"
		var dot="."
		var lat=email.indexOf(at)
		var lstr=email.length
		var ldot=email.indexOf(dot)
		if (email.indexOf(at)==-1){
		   error = true;
		}

		if (email.indexOf(at)==-1 || email.indexOf(at)==0 || email.indexOf(at)==lstr){
		   error = true;
		}

		if (email.indexOf(dot)==-1 || email.indexOf(dot)==0 || email.indexOf(dot)==lstr){
		   error = true;
		}

		 if (email.indexOf(at,(lat+1))!=-1){
		   error = true;
		 }

		 if (email.substring(lat-1,lat)==dot || email.substring(lat+1,lat+2)==dot){
		   error = true;
		 }

		 if (email.indexOf(dot,(lat+2))==-1){
		   error = true;
		 }
		
		 if (email.indexOf(" ")!=-1){
		   error = true;
		 }

		if(error){
			tValidatedOK = false;
		} 
	}
	
	return tValidatedOK;
}

function get_postcode_zone(postcode){
	postcode = parseInt(postcode)
	zone = "";
	if(postcode >= 6000 && postcode <= 6214){ zone = "W1"; }
	if(postcode >= 6215 && postcode <= 6699){ zone = "W2"; }
	if(postcode >= 6700 && postcode <= 6799){ zone = "W3"; }
	if(postcode >= 6800 && postcode <= 6999){ zone = "W1"; }
	
	if(postcode >= 7000 && postcode <= 7999){ zone = "T1"; }
	
	if(postcode >= 200 && postcode <= 299){ zone = "N2"; }
	if(postcode >= 1000 && postcode <= 2263){ zone = "N1"; }
	if(postcode >= 2264 && postcode <= 2499){ zone = "N2"; }
	if(postcode >= 2500 && postcode <= 2530){ zone = "N1"; }
	if(postcode >= 2531 && postcode <= 2554){ zone = "N2"; }
	if(postcode >= 2555 && postcode <= 2574){ zone = "N1"; }
	if(postcode >= 2575 && postcode <= 2647){ zone = "N2"; }
	if(postcode == 2648){ zone = "V2"; }
	
	if(postcode >= 2649 && postcode <= 2714){ zone = "N2"; }
	if(postcode == 2715){ zone = "V2"; }
	if(postcode == 2716){ zone = "N2"; }
	if(postcode >= 2717 && postcode <= 2719){ zone = "V2"; }
	if(postcode >= 2720 && postcode <= 2730){ zone = "N2"; }
	if(postcode >= 2731 && postcode <= 2739){ zone = "V2"; }
	if(postcode >= 2740 && postcode <= 2786){ zone = "N1"; }
	if(postcode >= 2787 && postcode <= 2879){ zone = "N2"; }
	if(postcode == 2880){ zone = "S2"; }
	if(postcode >= 2881 && postcode <= 2889){ zone = "N2"; }
	if(postcode == 2890){ zone = "N1"; }
	if(postcode >= 2891 && postcode <= 2898){ zone = "N2"; }
	if(postcode == 2899){ zone = "NF"; }
	if(postcode >= 2900 && postcode <= 2999){ zone = "N2"; }
	
	if(postcode >= 3000 && postcode <= 3220){ zone = "V1"; }
	if(postcode >= 3221 && postcode <= 3334){ zone = "V2"; }
	if(postcode >= 3335 && postcode <= 3341){ zone = "V1"; }
	if(postcode >= 3342 && postcode <= 3424){ zone = "V2"; }
	if(postcode >= 3425 && postcode <= 3443){ zone = "V1"; }
	if(postcode >= 3444 && postcode <= 3688){ zone = "V2"; }
	if(postcode >= 3689 && postcode <= 3690){ zone = "N2"; }
	if(postcode >= 3691 && postcode <= 3749){ zone = "V2"; }
	if(postcode >= 3750 && postcode <= 3811){ zone = "V1"; }
	if(postcode >= 3812 && postcode <= 3909){ zone = "V2"; }
	if(postcode >= 3910 && postcode <= 3920){ zone = "V1"; }
	if(postcode >= 3921 && postcode <= 3925){ zone = "V2"; }
	if(postcode >= 3926 && postcode <= 3944){ zone = "V1"; }
	if(postcode >= 3945 && postcode <= 3971){ zone = "V2"; }
	if(postcode >= 3972 && postcode <= 3978){ zone = "V1"; }
	if(postcode >= 3979){ zone = "V2"; }
	if(postcode >= 3980 && postcode <= 3983){ zone = "V1"; }
	if(postcode >= 3984 && postcode <= 3999){ zone = "V2"; }
	if(postcode >= 8000 && postcode <= 8999){ zone = "V1"; }
	
	
	if(postcode >= 4000 && postcode <= 4224){ zone = "Q1"; }
	if(postcode == 4225){ zone = "N2"; }
	if(postcode >= 4226 && postcode <= 4299){ zone = "Q1"; }
	if(postcode >= 4300 && postcode <= 4449){ zone = "Q2"; }
	if(postcode >= 4450 && postcode <= 4499){ zone = "Q3"; }
	if(postcode >= 4500 && postcode <= 4549){ zone = "Q1"; }
	if(postcode >= 4550 && postcode <= 4699){ zone = "Q2"; }
	if(postcode >= 4700 && postcode <= 4805){ zone = "Q3"; }
	if(postcode >= 4806 && postcode <= 4899){ zone = "Q4"; }
	if(postcode >= 9000 && postcode <= 9299){ zone = "Q1"; }
	if(postcode >= 9400 && postcode <= 9596){ zone = "Q1"; }
	if(postcode >= 9597 && postcode <= 9599){ zone = "Q2"; }
	if(postcode >= 9700 && postcode <= 9799){ zone = "Q1"; }
	if(postcode >= 9880 && postcode <= 9919){ zone = "Q2"; }
	if(postcode >= 9920 && postcode <= 9959){ zone = "Q3"; }
	if(postcode >= 9960 && postcode <= 9999){ zone = "Q4"; }
	
	if(postcode >= 5000 && postcode <= 5199){ zone = "S1"; }
	if(postcode >= 5200 && postcode <= 5749){ zone = "S2"; }
	if(postcode >= 5800 && postcode <= 5999){ zone = "S1"; }
	
	if(postcode >= 800 && postcode <= 999){ zone = "NT1"; }

	return zone;
}

function validate_subscribe(){
	var tValidatedOK = true
	var tMessage = "The following field(s) are required:\n"
	
	tForm = document.frmSubscribe
	if (trim(tForm.email.value)  == ""){
		tMessage += "          Your Email Address\n"
		tValidatedOK = false
	} else 	if (!check_email(tForm.email.value)  ){
		tMessage += "          A Valid Email Address\n"
		tValidatedOK = false
	} 
	 
			
	if(tValidatedOK == false){
		alert(tMessage)
	} else {
	
		tForm.submit()
	}
	
}
	  


function validate_signup(){
	var tValidatedOK = true
	var tMessage = "The following field(s) are required:\n"
	
	tForm = document.frmSignUp
	if (trim(tForm.email.value)  == ""){
		tMessage += "          Your Email Address\n"
		tValidatedOK = false
	} else 	if (!check_email(tForm.email.value)  ){
		tMessage += "          A Valid Email Address\n"
		tValidatedOK = false
	} 
	 
	if (trim(tForm.password.value)  == ""){
		tMessage += "          Your Password\n"
		tValidatedOK = false
	} 
	
	if (trim(tForm.confirm_password.value)  == ""){
		tMessage += "          Confirm Password\n"
		tValidatedOK = false
	}
	 
	if(trim(tForm.confirm_password.value) != trim(tForm.password.value)){
		tMessage += "          Your Password and Your Confirm Password do not match.\n          Please Re-enter your Password\n"
		tValidatedOK = false
	}
	 
	if (tForm.country_id.value  == 10){
		if (get_postcode_zone(tForm.postcode.value)  == ""){
			tMessage += "          A Valid Postcode/Zip Code\n"
			tValidatedOK = false
		} 
	}
			
	if(tValidatedOK == false){
		alert(tMessage)
	} else {
	
		tForm.submit()
	}
	
}


function validate_myaccount(){
	var tValidatedOK = true
	var tMessage = "The following field(s) are required:\n"
	
	tForm = document.frmMyAccount 
	if (trim(tForm.email.value)  == ""){
		tMessage += "          Your Email Address\n"
		tValidatedOK = false
	} else 	if (!check_email(tForm.email.value)  ){
		tMessage += "          A Valid Email Address\n"
		tValidatedOK = false
	} 
	 
	if (trim(tForm.password.value)  != ""){
	 
		if (trim(tForm.confirm_password.value)  == ""){
			tMessage += "          Confirm Password\n"
			tValidatedOK = false
		}
	 
		if(trim(tForm.confirm_password.value) != trim(tForm.password.value)){
			tMessage += "          Your Password and Your Confirm Password do not match.\n          Please Re-enter your Password\n"
			tValidatedOK = false
		}
	}
	 
	if (tForm.country_id.value  == 10){
		if (get_postcode_zone(tForm.postcode.value)  == ""){
			tMessage += "          A Valid Postcode/Zip Code\n"
			tValidatedOK = false
		} 
	}
			
	if(tValidatedOK == false){
		alert(tMessage)
	} else {
	
		tForm.submit()
	}
	
}


function validate_delivery_details(){
	var tValidatedOK = true
	var tMessage = "The following field(s) are required:\n"
	
	tForm = document.frmDeliveryDetails
	
	if (tForm.firstname.value  == ""){
		tMessage += "          Your First Name\n"
		tValidatedOK = false
	}
	
	if (tForm.lastname.value  == ""){
		tMessage += "          Your Last Name\n"
		tValidatedOK = false
	}
	
	
	
	if (tForm.email.value  == ""){
		tMessage += "          Your Email Address\n"
		tValidatedOK = false
	}
	
	if (tForm.address_1.value  == ""){
		tMessage += "          Your Address\n"
		tValidatedOK = false
	}
	
	if (tForm.suburb.value  == ""){
		tMessage += "          Your Suburb\n"
		tValidatedOK = false
	}
	
	if (tForm.country_id.value  == 0){
		tMessage += "          Your Country\n"
		tValidatedOK = false
	}
	
 
	if (tForm.postcode.value  == ""){
		tMessage += "          Your Postcode/Zip Code\n"
		tValidatedOK = false
	}
	if (tForm.country_id.value  == 10){
		if (get_postcode_zone(tForm.postcode.value)  == ""){
			tMessage += "          A Valid Postcode/Zip Code\n"
			tValidatedOK = false
		} 
	}
	
	if(tForm.email_login){
		if (trim(tForm.email_login.value)  != ""){
			 if (!check_email(tForm.email_login.value)  ){
				tMessage += "          A Valid Email Address for Your Account\n"
				tValidatedOK = false
			} 
		 
			if (trim(tForm.password.value)  == ""){
				tMessage += "          Your Password\n"
				tValidatedOK = false
			} 
			
			if (trim(tForm.confirm_password.value)  == ""){
				tMessage += "          Confirm Password\n"
				tValidatedOK = false
			}
			 
			if(trim(tForm.confirm_password.value) != trim(tForm.password.value)){
				tMessage += "          Your Password and Your Confirm Password do not match.\n          Please Re-enter your Password\n"
				tValidatedOK = false
			}
		}
	}
			
	if(tValidatedOK == false){
		alert(tMessage)
	} else {
	
		tForm.submit()
	}
	
}

function validate_card_details(){
	var tValidatedOK = true
	var tMessage = "The following field(s) are required:\n"
		
	tForm = document.frmCardDetails
	 
	if (tForm.cardnumber.value  == ""){
		tMessage += "          Your Credit Card Number\n"
		tValidatedOK = false
	}
	if (tForm.cardname.value  == ""){
		tMessage += "          The Name on your Credit Card\n"
		tValidatedOK = false
	}
	if (tForm.cvn.value  == ""){
		tMessage += "          Your CVN Number of your Credit Card\n"
		tValidatedOK = false
	}

	
	if(tValidatedOK == false){
		alert(tMessage)
	} else {
		tForm.submit()
	}
	
}


function validate_confirmation(){
	tForm = document.frmConfirmation
	tForm.submit()
}
