
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

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 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_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 termsCheck (theForm) {
	with (theForm)	{
		if (!agree_terms.checked) {
			alert('Please agree to our Terms & Conditions before proceeding with your order');
			return false;	
		}
	}//end WITH

}//end function


function presence(field, alertmsg) {
	with (field) {
		if (value == null || value == "") {
			alert(alertmsg);
			return false;
		} else {
			return true;
		}// end if
	}// end with
}// end function


function validate_contactFrm(thisform) {
	with (thisform)	{
		if (presence(contact_name,"Please enter your name") == false) {
			contact_name.focus();
			return false;
		}// end if
		if (presence(contact_address,"Please enter your address") == false) {
			contact_address.focus();
			return false;
		}// end if
		if (presence(contact_number,"Please enter your number") == false) {
			contact_number.focus();
			return false;
		}// end if
		if (presence(contact_email,"Please enter your email address") == false) {
			contact_email.focus();
			return false;
		}// end if
	}//end with
}// end function	

	
function validate_quoteFrm(thisform) {
	with (thisform)	{
		if (presence(order_title,"Please state your title") == false) {
			order_title.focus();
			return false;
		}// end if
		if (presence(order_forename,"Please enter your first name") == false) {
			order_forename.focus();
			return false;
		}// end if
		if (presence(order_surname,"Please enter your surname") == false) {
			order_surname.focus();
			return false;
		}// end if
		if (presence(order_email,"Please enter your email") == false) {
			order_email.focus();
			return false;
		}// end if
		if (presence(order_address1,"Please enter your address") == false) {
			order_address1.focus();
			return false;
		}// end if
		if (presence(order_town,"Please enter your city") == false) {
			order_town.focus();
			return false;
		}// end if
		if (presence(order_county,"Please enter your county/province/state") == false) {
			order_county.focus();
			return false;
		}// end if<br>
		if (presence(order_postcode,"Please enter your Postcode/Zip ") == false) {
			order_postcode.focus();
			return false;
		}// end if
		
		if (order_pmethod.value == 0) {
			alert("Please state your preferred method of payment");
			return false;
		}// end if
		
	}//end with
}// end function	

function validate_subscribeFrm(thisform) {
	with (thisform)	{
		if (presence(title,"Please state your title") == false) {
			title.focus();
			return false;
		}// end if
		if (presence(forename,"Please enter your first name") == false) {
			forename.focus();
			return false;
		}// end if
		if (presence(surname,"Please enter your surname") == false) {
			surname.focus();
			return false;
		}// end if
		if (presence(company,"Please enter your company / trading name") == false) {
			company.focus();
			return false;
		}// end if
		if (presence(email,"Please enter your email") == false) {
			email.focus();
			return false;
		}// end if
		if (presence(telephone1,"Please enter your work telephone number") == false) {
			telephone1.focus();
			return false;
		}// end if
		if (presence(address1,"Please enter your address") == false) {
			address1.focus();
			return false;
		}// end if
		if (presence(town,"Please enter your city") == false) {
			town.focus();
			return false;
		}// end if		
		
	}//end with
}// end function	

function validate_affiliateFrm(thisForm) {	
	with (thisForm)	{
		if (presence(affiliate_title,"Please enter give your title") == false) {
			affiliate_title.focus();
			return false;
		}// end if				
		if (presence(affiliate_forename,"Please enter your first name") == false) {
			affiliate_forename.focus();
			return false;
		}// end if		
		if (presence(affiliate_surname,"Please enter your surname") == false) {
			affiliate_surname.focus();
			return false;
		}// end if	
		
		if (presence(affiliate_email,"Please enter your email") == false) {
			affiliate_email.focus();
			return false;
		}// end if		
		if (presence(affiliate_telephone1,"Please enter your contact phone number") == false) {
			affiliate_telephone1.focus();
			return false;
		}// end if	
		if (presence(affiliate_address1,"Please enter your address") == false) {
			affiliate_address1.focus();
			return false;
		}// end if	
		if (presence(affiliate_town,"Please enter your town/city") == false) {
			affiliate_town.focus();
			return false;
		}// end if
		if (presence(affiliate_postcode,"Please enter your postcode/zipcode") == false) {
			affiliate_postcode.focus();
			return false;
		}// end if		
			
		if (!affiliate_terms.checked) {
			alert("Please agree to the privacy policy terms");
			affiliate_terms.focus();
			return false;
		}// end if
		if (!affiliate_age_verify.checked) {
			alert("Please confirm you are over 18 years of age");
			affiliate_age_verify.focus();
			return false;
		}// end if
		if (!affiliate_service_agree.checked) {
			alert("Please agree to the service level agreement terms");
			affiliate_service_agree.focus();
			return false;
		}// end if
	

		if (presence(site_name,"Please enter the website name") == false) {
			site_name.focus();
			return false;
		}// end if	
		if (presence(site_url,"Please enter your subdomain/URL for your website") == false) {
			site_url.focus();
			return false;
		}// end if	
		
		if (presence(site_description,"Please describe your site") == false) {
			site_description.focus();
			return false;
		}// end if	
		
		if (presence(site_promotion,"Please give your promotion method") == false) {
			site_promotion.focus();
			return false;
		}// end if	
		
		if (presence(site_incentive,"Please describe your incentive or special programme") == false) {
			site_incentive.focus();
			return false;
		}// end if	
	}//end WITH	
	
}//end function

function validate_newsiteFrm(thisForm) {
	with (thisForm)	{
		if (!affiliate_terms.checked) {
			alert("Please agree to the privacy policy terms");
			affiliate_terms.focus();
			return false;
		}// end if
		if (!affiliate_age_verify.checked) {
			alert("Please confirm you are over 18 years of age");
			affiliate_age_verify.focus();
			return false;
		}// end if
		if (!affiliate_service_agree.checked) {
			alert("Please agree to the service level agreement terms");
			affiliate_service_agree.focus();
			return false;
		}// end if
	

		if (presence(affiliate_website_name,"Please enter the website name") == false) {
			affiliate_website_name.focus();
			return false;
		}// end if	
		if (presence(affiliate_url,"Please enter your affiliate url") == false) {
			affiliate_url.focus();
			return false;
		}// end if	
		if (presence(affiliate_promotion_method,"Please give your promotion method") == false) {
			affiliate_promotion_method.focus();
			return false;
		}// end if	
		
		if (presence(affiliate_incentive,"Please describe your incentive or special programme") == false) {
			affiliate_incentive.focus();
			return false;
		}// end if	
	}//end WITH	
}//end function


function validate_affiliateDetailsFrm(thisForm) {
	with (thisForm)	{
		if (presence(affiliate_forename,"Please enter your first name") == false) {
			affiliate_first.focus();
			return false;
		}// end if			

		if (presence(affiliate_surname,"Please enter your surname") == false) {
			affiliate_surname.focus();
			return false;
		}// end if	
		
		if (presence(affiliate_email,"Please enter your email") == false) {
			affiliate_email.focus();
			return false;
		} else {
			if (affiliate_email.value != affiliate_emailverify.value) {
				alert ("Emails do not match");
				affiliate_email.focus();
				return false;
			}// end if
		}// end if
		
		if (presence(affiliate_phone,"Please enter your contact phone number") == false) {
			affiliate_phone.focus();
			return false;
		}// end if	
		if (presence(affiliate_address1,"Please enter your address") == false) {
			affiliate_address1.focus();
			return false;
		}// end if	
		if (presence(affiliate_town,"Please enter your town/city") == false) {
			affiliate_town.focus();
			return false;
		}// end if
		if (presence(affiliate_postcode,"Please enter your postcode/zipcode") == false) {
			affiliate_postcode.focus();
			return false;
		}// end if		
	/*	if (presence(affiliate_country,"Please enter your country") == false) {
			affiliate_country.focus();
			return false;
		}// end if	
	*/		
	}//endWITH	
	
}//end function

function template_criteria(value) {
	if (value == "default") {
		document.getElementById('template_details').style.display = 'none';	
	}// end if
	if (value == "blank_style1" || value == "blank_style2") {
		document.getElementById('template_details').style.display = '';
	}// end if

}//end function