// ------------------------------------ sets up css for cross browser code

isMac = (navigator.appVersion.indexOf("Mac") != -1);
isWindows = (navigator.appVersion.indexOf("Windows") != -1);


isIE = (navigator.appName == "Microsoft Internet Explorer")
isNN = (navigator.appName == "Netscape")
isIE5 = (navigator.appVersion.indexOf("MSIE 5") != -1)
isSafari = (navigator.appVersion.indexOf("Safari") != -1);
isFirefox = (navigator.userAgent.indexOf("Firefox") != -1);
isMozilla = (navigator.userAgent.indexOf("Gecko") != -1 && navigator.userAgent.indexOf("Netscape") == -1 && navigator.userAgent.indexOf("Firefox") == -1 && navigator.userAgent.indexOf("Safari") == -1);

//if (isNN) {
//	document.write('<link rel="stylesheet" type="text/css" href="' + strRoot + '/style/common/nn.css">');
//}
//if (isMac && isIE) {
//	document.write('<link rel="stylesheet" type="text/css" href="' + strRoot + '/style/common/mac.css">');
//}
//if (isIE5) {
//	document.write('<link rel="stylesheet" type="text/css" href="' + strRoot + '/style/common/ie5.css">');
//}
//if (isSafari) {
//	document.write('<link rel="stylesheet" type="text/css" href="' + strRoot + '/style/common/safari.css">');
//}
//if (isFirefox) {
//	document.write('<link rel="stylesheet" type="text/css" href="' + strRoot + '/style/common/firefox.css">');
//}
//if (isMozilla) {
//	document.write('<link rel="stylesheet" type="text/css" href="' + strRoot + '/style/common/mozilla.css">');
//}
// ------------------------------------ form validation functions

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 || subone.indexOf ('.',0) == 0) {
      		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 = ""
		}
	}
}

// ------------------------------------ popup functions

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 openEmailFriend(url) {
	window.open("/sendemail/sendemail_form.asp?page=" + url,'sendemail','top=140,left=140,width=390,height=460,resizable=0,scrollbars=0,toolbar=0,directories=0,status=0,menubar=0')
}

// ------------------------------------ 



function validateTitleBarKeywordSearch(f){
	if ((f.keyword.value == '') || (f.keyword.value == 'Keyword/Product Ref.')) {
		alert('You must enter a keyword to search for');
		
		return false;
	}

}

function validateKeywordSearch(f){

}

function openContentPopup(url) {
	window.open(url,'content','top=100,left=100,width=520,height=637,resizable=0,scrollbars=yes,toolbar=0,directories=0,status=0,menubar=0');
}

function CompareProduct(c) {
	var intPos
	intPos = document.ProductCompare.ProductCodes.value.indexOf(c.value + "|")
	
	if (intPos > -1 ) {
		document.ProductCompare.ProductCodes.value = document.ProductCompare.ProductCodes.value.replace(c.value + "|","");
	} else {
		var arrProductCodes;
		arrProductCodes = document.ProductCompare.ProductCodes.value.split("|");
		
		if (arrProductCodes.length > 4) {
			alert("Only 4 products can be compared at any one time");
			c.checked = false;
		} else {
			document.ProductCompare.ProductCodes.value = document.ProductCompare.ProductCodes.value + c.value + "|"
		}
	}
}

function SubmitProductCompare() {
	var arrProductCodes;
	arrProductCodes = document.ProductCompare.ProductCodes.value.split("|");
	if (arrProductCodes.length <= 2) {
		alert("Please choose a minimum of 2 products to compare");
	} else {
		document.ProductCompare.submit();
	}
}

function bookmark(title)
{
	url = window.location.href;
	if (window.sidebar) { // firefox
			window.sidebar.addPanel(title, url, "");
		}
	else if(window.opera && window.print) { // opera
		alert("Your browser does not support this function, please bookmark this site manually");
	}
	else if(document.all) {// ie
		window.external.AddFavorite(url, title);
	}
	else {// safari and google chrome
		alert("Your browser does not support this function, please bookmark this site manually");
	}
}
