function isBlank(v) {
	if ((v.length>0) && (v!=" ")) {
		return false;
	}
	else {
		return true;
	}
}

function isNumber(v) { 
    	if (isNaN(v.replace(/ /g,""))) {
    		return false;
    	}
    	else return true;
}

function isEmail(v) {
	at=v.indexOf('@');
	dot=v.lastIndexOf('.');
	end=v.length;
	subone=v.substring(at+1,dot);
	domainbeforedot=subone.length;
	subtwo=v.substring(dot+1,end);
	domainafterdot=subtwo.length;
   	if (v.indexOf ('@',0) == -1 || v.indexOf ('.',0) == -1  || domainbeforedot < 1 || domainafterdot < 2 ) {
      		return false;
	}
   	else { 
   		return true; 
   	}
}

function isPostcode(v) {
 	size = v.length;
  	//Strip leading spaces
 	while (v.slice(0,1) == " ") {
 		v = v.substr(1,size-1);
 		size = v.length;
 	}
  	//Strip trailing spaces
	while(v.slice(size-1,size)== " ") {
		v = v.substr(0,size-1);
		size = v.length;
	}	
 	if (size < 6 || size > 8){ 
 		//Code length rule
   		return false;
  	}
 	if (!(isNaN(v.charAt(0)))){ 
 		//leftmost character must be alpha character rule
   		return false;
  	}
 	if (isNaN(v.charAt(size-3))){ 
 		//first character of inward code must be numeric rule
   		return false;
  	}
 	if (!(isNaN(v.charAt(size-2)))){ 
 		//second character of inward code must be alpha rule
   		return false;
  	}
 	if (!(isNaN(v.charAt(size-1)))){ 
 		//third character of inward code must be alpha rule
   		return false;
  	}
 	count1 = v.indexOf(" ");
 	count2 = v.lastIndexOf(" ");
 	if (count1 != count2){
 		// only one space rule
  		return false;
  	}
	return true;
}


function chkRadio(f, btnName) {
	var btn = f[btnName]
	var valid

	valid = f[btnName].checked;  // checks the status of a single radio button

	for (var x = 0;x < btn.length; x++)
	{
		valid = btn[x].checked
		if (valid) { break }
	}
	if(!valid)
	{
		return false;
	}
	else
	{
		return true;
	}
}


function chkFieldDefaultText(v, defaultValue, action) {
	if (action == "blur") {
		if (isBlank(v.value)) {
			v.value = defaultValue
		}
	}
	if (action == "click") {
		
		if (v.value == defaultValue) {
			v.value = ""
		}
	}
}

function QAS_Popup(fname)
{
	QAS_PRO = window.open("/qas/popup.asp?CountryCodeName=GBRUnited+Kingdom&fname="+fname,"QAS_PRO", "scrollbars=yes,resizable=yes,width=600,height=450");
}


function chkCatalogueRequest (f) {
	
	if (isBlank(f.Forename.value)) {
		alert("Your first name must be entered");
		f.Forename.focus();
		return false;
	}

	if (isBlank(f.Surname.value)) {
		alert("Your surname must be entered");
		f.Surname.focus();
		return false;
	}

	if (isBlank(f.DeliveryLine2.value)) {
		alert("Please enter your address");
		f.DeliveryLine2.focus();
		return false;
	}

	if (isBlank(f.DeliveryLine4.value)) {
		alert("You must enter the town in which you live");
		f.DeliveryLine4.focus();
		return false;
	}

	if (f.Country.value != 'IE') {
		if (isBlank(f.Postcode.value)) {
			alert("You must enter your postcode");
			f.Postcode.focus();
			return false;
		}
	}
	return true;
}