// JavaScript Document
/*** 
		Simple jQuery Slideshow Script
		Released by Jon Raasch (jonraasch.com) under FreeBSD license: free to use or modify, not responsible for anything, etc.  Please link out to me if you like it :)
	***/

function slideSwitch() {
	var $active = $('#slideshow DIV.active');

	if ( $active.length == 0 ) $active = $('#slideshow DIV:last');

	// use this to pull the divs in the order they appear in the markup
	var $next =  $active.next().length ? $active.next()
		: $('#slideshow DIV:first');

	$active.addClass('last-active');

	$next.css({opacity: 0.0})
		.addClass('active')
		.animate({opacity: 1.0}, 1000, function() {
			$active.removeClass('active last-active');
		});
}
	
	
function closeItemAdded(){
	if(document.getElementById){
		var el = document.getElementById("itemAdded");
		el.style.display = "none";
	}
}

function showVideo(obj){
	if(document.getElementById){
		var el = document.getElementById(obj);
		var ar = document.getElementsByTagName("div"); //DynamicDrive.com change
		if(el.style.display != "block"){ //DynamicDrive.com change
			for (var i=0; i<ar.length; i++){
				if (ar[i].className=="youtubevideo") //DynamicDrive.com change
				ar[i].style.display = "none";
			}
			el.style.display = "block";
			
		}else{
			el.style.display = "none";			
		}
	}
}

function showDiv(obj){
	if(document.getElementById){
	var el = document.getElementById(obj);
	var ar = document.getElementsByTagName("div"); //DynamicDrive.com change
		if(el.style.display != "block"){ //DynamicDrive.com change
			for (var i=0; i<ar.length; i++){
				if (ar[i].className=="subnavclass") //DynamicDrive.com change
				ar[i].style.display = "none";
			}
			el.style.display = "block";
			
		}else{
			el.style.display = "none";
			
		}
	}
}

function showDivSub(obj){
	if(document.getElementById){
	var el = document.getElementById(obj);
	var ar = document.getElementsByTagName("div"); //DynamicDrive.com change
		if(el.style.display != "block"){ //DynamicDrive.com change
			for (var i=0; i<ar.length; i++){
				if (ar[i].className=="helpclass") //DynamicDrive.com change
				ar[i].style.display = "none";
			}
			el.style.display = "block";
		}else{
			el.style.display = "none";
		}
	}
}

function showCatsDiv(obj){
	if(document.getElementById){
	var el = document.getElementById(obj);
	var ar = document.getElementsByTagName("div"); //DynamicDrive.com change
		if(el.style.display != "block"){ //DynamicDrive.com change
			for (var i=0; i<ar.length; i++){
				if (ar[i].className=="info") //DynamicDrive.com change
				ar[i].style.display = "none";
			}
			el.style.display = "block";
			
		}else{
			el.style.display = "none";
			
		}
	}
}

function openZoomTerms()
{
	var newWindow=window.open("/zoom_terms.asp","","width=600,height=600,resizable=0,status=yes,scrollbars=yes,screenX=100,screenY=100,top=100,left=100'");
}

function openVideo(prod)
{
	var newWindow=window.open("/product_video.asp?prod=" + prod,"","width=705,height=680,resizable=0,status=yes,scrollbars=yes,screenX=100,screenY=100,top=100,left=100'");
}

function check_checkoutreview(form) 
{						
	if (form.optin.checked != true){
		alert("Please read and agree to our terms & conditions");
		form.optin.focus();
		return false;
	}
}

function UpdateResults()
{
	document.filterForm.submit();
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function KW_updateItems(d,o,fn) { //v2.6 By Paul Davis www.kaosweaver.com
  var i,s,l=MM_findObj(d),b,z=o.options[o.selectedIndex].value;
  l.length=0;l.options[0]=new Option('All Job types','0');b=(z!='nill')?eval(z+'_items'):0;
  for(i=0;i<b.length;i++){s=b[i].split("|");l.options[i]=new Option(s[1],s[0]);}
  l.selectedIndex=0;if (!fn) return;eval(fn)
}

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_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 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 MM_jumpMenuGo(objId,targ,restore){ //v9.0
  var selObj = null;  with (document) { 
  if (getElementById) selObj = getElementById(objId);
  if (selObj) eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0; }
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function clearSearch(){
  document.frmSearch.keyword.value = '';
}

function evaswap(obj, val){
  obj.src = val;
}

function addtobasket(trgForm) 
{
	document.getElementById(trgForm).submit();
}

function submitform(trgForm, validator) 
{
	if ( validator != '' )
	{
		eval( "if (" + validator + "('" + trgForm + "')) { document.getElementById('" + trgForm + "').submit(); }" );
	}
	else
	{
		document.getElementById(trgForm).submit();
	}

}

function getForm(form)
{
	if (form.split)
		return document.getElementById(form);
	else
		return form;
}

function check_contact(checkForm) 
{
	var form = getForm(checkForm);
	
	var emailFilter=/^.+@.+\..{2,3}$/;
	var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/;
	var justNumbers = /^[0-9]*$/;
	var re = /\s/;									
	if (form.name.value == ''){
		alert("Please enter your name...");
		form.name.focus();
		return false;
	}
	var stripped = form.telephone.value.replace(/[\(\)\.\-\ ]/g, '');
	if (form.telephone.value == '' || isNaN(parseInt(stripped)) || !(justNumbers.test(stripped))) {
		alert("Your telephone number is incomplete or contains invalid characters...");
		form.telephone.focus();
		return false;
	}		
	if (form.email.value == '' || form.email.value.match(illegalChars) || !(emailFilter.test(form.email.value))){
		alert("Please enter a valid email address...");
		form.email.focus();
		return false;
	}
	if (form.message.value == ''){
		alert("Please enter your enquiry...");
		form.message.focus();
		return false;
	}
	
	return true;
}

function check_enquiry(checkForm) 
{
	var form = getForm(checkForm);
	
	var emailFilter=/^.+@.+\..{2,3}$/;
	var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/;
	var justNumbers = /^[0-9]*$/;
	var re = /\s/;									
	if (form.name.value == ''){
		alert("Please enter your name...");
		form.name.focus();
		return false;
	}
	var stripped = form.telephone.value.replace(/[\(\)\.\-\ ]/g, '');
	if (form.telephone.value == '' || isNaN(parseInt(stripped)) || !(justNumbers.test(stripped))) {
		alert("Your telephone number is incomplete or contains invalid characters...");
		form.telephone.focus();
		return false;
	}		
	if (form.email.value == '' || form.email.value.match(illegalChars) || !(emailFilter.test(form.email.value))){
		alert("Please enter a valid email address...");
		form.email.focus();
		return false;
	}
	if (form.subject.value == ''){
		alert("Please enter your comments...");
		form.subject.focus();
		return false;
	}
	if (form.message.value == ''){
		alert("Please enter your comments...");
		form.message.focus();
		return false;
	}
	
	return true;
}

function check_export(checkForm) 
{
	var form = getForm(checkForm);
	
	var emailFilter=/^.+@.+\..{2,3}$/;
	var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/;
	var justNumbers = /^[0-9]*$/;
	var re = /\s/;
	
	
	if (form.BillingCompanyName.value == ''){
		alert("Please enter your company name...");
		form.BillingCompanyName.focus();
		return false;
	}
	if (form.BillingFirstName.value == ''){
		alert("Please enter your first name...");
		form.BillingFirstName.focus();
		return false;
	}
	if (form.BillingLastName.value == ''){
		alert("Please enter your last name...");
		form.BillingLastName.focus();
		return false;
	}
	if (form.BillingAddress1.value == ''){
		alert("Please enter your address line 1...");
		form.BillingAddress1.focus();
		return false;
	}
	if (form.BillingCity.value == ''){
		alert("Please enter your billing town / city...");
		form.BillingCity.focus();
		return false;
	}
	if (form.BillingCounty.value == ''){
		alert("Please enter your county / state...");
		form.BillingCounty.focus();
		return false;
	}
	if (form.BillingPostal.value == ''){
		alert("Please enter your post code...");
		form.BillingPostal.focus();
		return false;
	}
	var stripped = form.ShopperTel.value.replace(/[\(\)\.\-\ ]/g, '');
	if (form.ShopperTel.value == '' || isNaN(parseInt(stripped)) || !(justNumbers.test(stripped))) {
		alert("Your telephone number is incomplete or contains invalid characters...");
		form.ShopperTel.focus();
		return false;
	}		
	if (form.ShopperEmail.value == '' || form.ShopperEmail.value.match(illegalChars) || !(emailFilter.test(form.ShopperEmail.value))){
		alert("Please enter a valid email address...");
		form.ShopperEmail.focus();
		return false;
	}
	
	return true;
}

function check_catalogue(checkForm) 
{
	var form = getForm(checkForm);
	
	var emailFilter=/^.+@.+\..{2,3}$/;
	var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/;
	var justNumbers = /^[0-9]*$/;
	var re = /\s/;
	
	
	if (form.title.value == ''){
		alert("Please enter your title...");
		form.title.focus();
		return false;
	}
	if (form.fname.value == ''){
		alert("Please enter your first name...");
		form.fname.focus();
		return false;
	}
	if (form.lname.value == ''){
		alert("Please enter your last name...");
		form.lname.focus();
		return false;
	}
	if (form.address1.value == ''){
		alert("Please enter your address line 1...");
		form.address1.focus();
		return false;
	}
	if (form.city.value == ''){
		alert("Please enter your town / city...");
		form.city.focus();
		return false;
	}
	if (form.country.value == ''){
		alert("Please enter your country / region...");
		form.country.focus();
		return false;
	}
	if (form.postcode.value == ''){
		alert("Please enter your post code...");
		form.postcode.focus();
		return false;
	}
	var stripped = form.phone.value.replace(/[\(\)\.\-\ ]/g, '');
	if (form.phone.value == '' || isNaN(parseInt(stripped)) || !(justNumbers.test(stripped))) {
		alert("Your telephone number is incomplete or contains invalid characters...");
		form.phone.focus();
		return false;
	}		
	if (form.email.value == '' || form.email.value.match(illegalChars) || !(emailFilter.test(form.email.value))){
		alert("Please enter a valid email address...");
		form.email.focus();
		return false;
	}
	
	return true;
}

function check_delivery(checkForm) 
{
	var form = getForm(checkForm);
	
	var emailFilter=/^.+@.+\..{2,3}$/;
	var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/;
	var justNumbers = /^[0-9]*$/;
	var re = /\s/;
	
	if (form.ShippingFirstName.value == ''){
		alert("Please enter your first name...");
		form.ShippingFirstName.focus();
		return false;
	}
	if (form.ShippingLastName.value == ''){
		alert("Please enter your last name...");
		form.ShippingLastName.focus();
		return false;
	}
	if (form.ShippingPostal.value == ''){
		alert("Please enter your post code...");
		form.ShippingPostal.focus();
		return false;
	}
	var stripped = form.ShippingTelephone.value.replace(/[\(\)\.\-\ ]/g, '');
	if (form.ShippingTelephone.value == '' || isNaN(parseInt(stripped)) || !(justNumbers.test(stripped))) {
		alert("Your telephone number is incomplete or contains invalid characters...");
		form.ShippingTelephone.focus();
		return false;
	}		
	if (form.ShippingEmail.value == '' || form.ShippingEmail.value.match(illegalChars) || !(emailFilter.test(form.ShippingEmail.value))){
		alert("Please enter a valid email address...");
		form.ShippingEmail.focus();
		return false;
	}
	
	return true;
}

function check_delimanual(checkForm) 
{
	var form = getForm(checkForm);
	
	var emailFilter=/^.+@.+\..{2,3}$/;
	var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/;
	var justNumbers = /^[0-9]*$/;
	var re = /\s/;
	
	if (form.ShippingFirstName.value == ''){
		alert("Please enter your first name...");
		form.ShippingFirstName.focus();
		return false;
	}
	if (form.ShippingLastName.value == ''){
		alert("Please enter your last name...");
		form.ShippingLastName.focus();
		return false;
	}
	if (form.ShippingAddress1.value == ''){
		alert("Please enter your address line 1...");
		form.ShippingAddress1.focus();
		return false;
	}
	if (form.ShippingCity.value == ''){
		alert("Please enter your town / city...");
		form.ShippingCity.focus();
		return false;
	}
	if (form.ShippingPostal.value == ''){
		alert("Please enter your post code...");
		form.ShippingPostal.focus();
		return false;
	}
	var stripped = form.ShippingTelephone.value.replace(/[\(\)\.\-\ ]/g, '');
	if (form.ShippingTelephone.value == '' || isNaN(parseInt(stripped)) || !(justNumbers.test(stripped))) {
		alert("Your telephone number is incomplete or contains invalid characters...");
		form.ShippingTelephone.focus();
		return false;
	}		
	if (form.ShippingEmail.value == '' || form.ShippingEmail.value.match(illegalChars) || !(emailFilter.test(form.ShippingEmail.value))){
		alert("Please enter a valid email address...");
		form.ShippingEmail.focus();
		return false;
	}
	
	return true;
}

function check_address(checkForm) 
{
	var form = getForm(checkForm);
	
	if (form.id_Billing.value == ''){
		alert("Please select your address...");
		return false;
	}
	
	return true;
}

function check_addressdelivery(checkForm) 
{
	var form = getForm(checkForm);
	
	if (form.id_Delivery.value == ''){
		alert("Please select your address...");
		return false;
	}
	
	return true;
}

function check_billing(checkForm) 
{
	var form = getForm(checkForm);
	
	var emailFilter=/^.+@.+\..{2,3}$/;
	var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/;
	var justNumbers = /^[0-9]*$/;
	var re = /\s/;
	
	if (form.BillingFirstName.value == ''){
		alert("Please enter your first name...");
		form.BillingFirstName.focus();
		return false;
	}
	if (form.BillingLastName.value == ''){
		alert("Please enter your last name...");
		form.BillingLastName.focus();
		return false;
	}
	var stripped = form.BillingTelephone.value.replace(/[\(\)\.\-\ ]/g, '');
	if (form.BillingTelephone.value == '' || isNaN(parseInt(stripped)) || !(justNumbers.test(stripped))) {
		alert("Your telephone number is incomplete or contains invalid characters...");
		form.BillingTelephone.focus();
		return false;
	}		
	if (form.BillingEmail.value == '' || form.BillingEmail.value.match(illegalChars) || !(emailFilter.test(form.BillingEmail.value))){
		alert("Please enter a valid email address...");
		form.BillingEmail.focus();
		return false;
	}
	if (form.BillingPostal.value == ''){
		alert("Please enter your post code...");
		form.BillingPostal.focus();
		return false;
	}
	
	return true;
}

function check_billmanual(checkForm) 
{
	var form = getForm(checkForm);
	
	var emailFilter=/^.+@.+\..{2,3}$/;
	var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/;
	var justNumbers = /^[0-9]*$/;
	var re = /\s/;
	
	if (form.BillingFirstName.value == ''){
		alert("Please enter your first name...");
		form.BillingFirstName.focus();
		return false;
	}
	if (form.BillingLastName.value == ''){
		alert("Please enter your last name...");
		form.BillingLastName.focus();
		return false;
	}
	if (form.billingAddress1.value == ''){
		alert("Please enter your address line 1...");
		form.billingAddress1.focus();
		return false;
	}
	if (form.billingCity.value == ''){
		alert("Please enter your town / city...");
		form.billingCity.focus();
		return false;
	}
	if (form.billingPostal.value == ''){
		alert("Please enter your post code...");
		form.billingPostal.focus();
		return false;
	}
	var stripped = form.BillingTelephone.value.replace(/[\(\)\.\-\ ]/g, '');
	if (form.BillingTelephone.value == '' || isNaN(parseInt(stripped)) || !(justNumbers.test(stripped))) {
		alert("Your telephone number is incomplete or contains invalid characters...");
		form.BillingTelephone.focus();
		return false;
	}		
	if (form.BillingEmail.value == '' || form.BillingEmail.value.match(illegalChars) || !(emailFilter.test(form.BillingEmail.value))){
		alert("Please enter a valid email address...");
		form.BillingEmail.focus();
		return false;
	}
	
	return true;
}

function check_accholder(checkForm) 
{
	var form = getForm(checkForm);
	
	var emailFilter=/^.+@.+\..{2,3}$/;
	var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/;
	var justNumbers = /^[0-9]*$/;
	var re = /\s/;
	
	if (form.BillingFirstName.value == ''){
		alert("Please enter your first name...");
		form.BillingFirstName.focus();
		return false;
	}
	if (form.BillingLastName.value == ''){
		alert("Please enter your last name...");
		form.BillingLastName.focus();
		return false;
	}
	if (form.BillingPostal.value == ''){
		alert("Please enter your post code...");
		form.BillingPostal.focus();
		return false;
	}
	var stripped = form.BillingTelephone.value.replace(/[\(\)\.\-\ ]/g, '');
	if (form.BillingTelephone.value == '' || isNaN(parseInt(stripped)) || !(justNumbers.test(stripped))) {
		alert("Your telephone number is incomplete or contains invalid characters...");
		form.BillingTelephone.focus();
		return false;
	}		
	if (form.BillingEmail.value == '' || form.BillingEmail.value.match(illegalChars) || !(emailFilter.test(form.BillingEmail.value))){
		alert("Please enter a valid email address...");
		form.BillingEmail.focus();
		return false;
	}
	
	return true;
}

function check_accmanual(checkForm) 
{
	var form = getForm(checkForm);
	
	var emailFilter=/^.+@.+\..{2,3}$/;
	var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/;
	var justNumbers = /^[0-9]*$/;
	var re = /\s/;
	
	if (form.BillingFirstName.value == ''){
		alert("Please enter your first name...");
		form.BillingFirstName.focus();
		return false;
	}
	if (form.BillingLastName.value == ''){
		alert("Please enter your last name...");
		form.BillingLastName.focus();
		return false;
	}
	if (form.BillingAddress1.value == ''){
		alert("Please enter your address line 1...");
		form.BillingAddress1.focus();
		return false;
	}
	if (form.BillingCity.value == ''){
		alert("Please enter your town / city...");
		form.BillingCity.focus();
		return false;
	}
	if (form.BillingPostal.value == ''){
		alert("Please enter your post code...");
		form.BillingPostal.focus();
		return false;
	}
	var stripped = form.BillingTelephone.value.replace(/[\(\)\.\-\ ]/g, '');
	if (form.BillingTelephone.value == '' || isNaN(parseInt(stripped)) || !(justNumbers.test(stripped))) {
		alert("Your telephone number is incomplete or contains invalid characters...");
		form.BillingTelephone.focus();
		return false;
	}		
	if (form.BillingEmail.value == '' || form.BillingEmail.value.match(illegalChars) || !(emailFilter.test(form.BillingEmail.value))){
		alert("Please enter a valid email address...");
		form.BillingEmail.focus();
		return false;
	}
	
	return true;
}

function check_search(checkForm) 
{
	var form = getForm(checkForm);
		
	if (form.keyword.value == ''){
		alert("Please enter your keywords...");
		form.keyword.focus();
		return false;
	}
	
	return true;
}

function TM_UpperCase(strInput,words){//1.1
    var theString = strInput.value;
    var strOutput = "";// Our temporary string used to build the function's output
    var sp = " ";
    var small = false;
    var smallWords = words.split(",") //words that shouldn't be  capitalized
    theString = theString.replace(/(\s*)([^\s])/,"$2")//remove leading spaces
    theString = theString.toUpperCase();  
    var inputArray = theString.split(sp);
    strOutput = inputArray[0].slice(0,1).toUpperCase()+inputArray[0].slice(1);
    for (i = 1; i < inputArray.length; i++){ 
        small=false;
        for (ii=0;ii<smallWords.length;ii++){
           if(inputArray[i] == smallWords[ii]) small = true;
           }
        if(!small) inputArray[i] = inputArray[i].slice(0,1).toUpperCase()+inputArray[i].slice(1);
        strOutput = strOutput + sp + inputArray[i];  
        }
    strInput.value = strOutput;
}

