// JavaScript Document

function overSeaCustMax() {
	alert("Sorry this order is too large for overseas delivery. \r\n  - Please refine your order. \r\n  - Spread your order over two deliveries \r\n\r\nThankyou");
}


function delOpt(query, sat) {
	var opt = document.getElementById('del_det');
	var selOpt = opt.options[opt.selectedIndex].value;
	var path = "?"+query+"&del=";
	var ok;
	
	var d=new Date();
	var weekday=new Array(7);
	weekday[0]="Sunday";
	weekday[1]="Monday";
	weekday[2]="Tuesday";
	weekday[3]="Wednesday";
	weekday[4]="Thursday";
	weekday[5]="Friday";
	weekday[6]="Saturday";
	
	if(sat == 0 && selOpt == 3) {
		alert("If your order is personalised it may take longer to be delivered.");
	}
	
	if(sat == 1 && selOpt == 3) { 
		alert("If you choose next day delivery you will receive your order on Monday. Please choose Saturday delivery to receive your order tommorrow.\r\n\r\nPersonalised products may take longer."); 
	}
	
	if(sat == 2 && selOpt == 3) {
		alert("If you choose next day delivery you will receive your order on Tuesday. Personalised products may take longer.");
	}
	
	window.location = path+selOpt; 
}

function otherOption() {
	
	var otherOpt = document.getElementById("hear");
	if(otherOpt.options[otherOpt.selectedIndex].text == "Other") {
		document.getElementById('other').style.display = "block";
	} else {
		document.getElementById('other').style.display = "none";	
	}
}

function checkSubmit() {
		if (submitcount == 0) {
			submitcount++;
			document.Surv.submit();
		}
	}
	
function wordCounter(field, countfield, maxlimit) {
		wordcounter=0;
		for (x=0;x<field.value.length;x++) {
			if (field.value.charAt(x) == " " && field.value.charAt(x-1) != " ")  {wordcounter++}  // Counts the spaces while ignoring double spaces, usually one in between each word.
			if (wordcounter > 250) {field.value = field.value.substring(0, x);}
			else {countfield.value = maxlimit - wordcounter;}
		}
	}

function textCounter(field, countfield, maxlimit) {
		if (field.value.length > maxlimit) {
			field.value = field.value.substring(0, maxlimit);
		} else {
			countfield.value = maxlimit - field.value.length;
		}
	}
	
function updateForm() {
	document.getElementById("update_img").style.visibility = "visible";
}


