// ------------------------------------ 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;
	}

	//Check if the postcode format is valid
    if (!isPostcodeFormatValid(v)){
 		//if the postcode format is invalid
   		return false;
    }

	return true;
}

function isPostcodeFormatValid(v) {

    //--- Check if the postcode format is valid ---//
    var strPostcode, myregexp
    strPostcode = v.toUpperCase();
    myregexp = new RegExp("^(GIR 0AA|BFPO ([0-9]{1,4})|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]|[A-HK-Y][0-9]([0-9]|[ABEHMNPRV-Y]))|[0-9][A-HJKS-UW]) [0-9][ABD-HJLNP-UW-Z]{2})$") 

    if (myregexp.test(strPostcode)){
        return true;
    }
    else {  
        return false;   
    }
}

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=600,height=450,resizable=0,scrollbars=1,toolbar=0,directories=0,status=0,menubar=0');
}

function chkWebLinks(f) {
	if ((f.keyword.value == '') || (f.keyword.value == 'Enter Code')) {
			alert('You must enter a code to search for');
		return false;
	} else {
		return true;
	}
}




