function showNav(menuName) {
	$('.subNav').hide();
	$('#nav_'+menuName).show();
}

function hideNav(menuName) {
	$('#nav_'+menuName).hide();
}

function showProductDetails(showname, hidename, hidename2) {
	document.getElementById(showname).style.display = 'block';
	document.getElementById(hidename).style.display = 'none';
	document.getElementById(hidename2).style.display = 'none';
	document.getElementById('prodinfo-'+showname+'').src="/images/prodinfo_"+showname+"-active.jpg"
	document.getElementById('prodinfo-'+hidename+'').src="/images/prodinfo_"+hidename+".jpg"
	document.getElementById('prodinfo-'+hidename2+'').src="/images/prodinfo_"+hidename2+".jpg"
}

function isValidEmail(email, required) {
    if (required==undefined) {   // if not specified, assume it's required
        required=true;
    }
    if (email==null) {
        if (required) {
            return false;
        }
        return true;
    }
    if (email.length==0) {  
        if (required) {
            return false;
        }
        return true;
    }
    if (! allValidChars(email)) {  // check to make sure all characters are valid
        return false;
    }
    if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character
        return false;
    } else if (email.lastIndexOf(".") <= email.indexOf("@")) {  // last dot must be after the @
        return false;
    } else if (email.indexOf("@") == email.length) {  // @ must not be the last character
        return false;
    }
	
    return true;
}

function allValidChars(email) {
  var parsed = true;
  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
  for (var i=0; i < email.length; i++) {
    var letter = email.charAt(i).toLowerCase();
    if (validchars.indexOf(letter) != -1)
      continue;
    parsed = false;
    break;
  }
  return parsed;
}

function chkBrochure(submittype) {
	if (document.brochureform.name.value == '' || document.brochureform.address.value == '' || document.brochureform.telephone.value == '') {
		alert("Please fill in your name, address and telephone number.");
		return false;
	}else if(document.brochureform.email.value != document.brochureform.conf_email.value) {
		alert("Your email and confirmed email do not match.");
		return false;
	}else{
		if (submittype == 'friend') {
			_gaq.push(['_trackEvent', 'RAFBrochureContactForm', 'Submit']);
		}else if (submittype == 'contact') {
			_gaq.push(['_trackEvent', 'ContactUsForm', 'Submit']);
		}else{
			_gaq.push(['_trackEvent', 'BrochureContactForm', 'Submit']);
		}
		return true;
//		if (! isValidEmail(document.brochureform.email.value)) {
 //       	alert("Please enter a valid email address");
  //      	return false;
   // 	}else{
//			return true;
//		}
	}
}

function popup(page, width, height) {
	window.open(page, "popup", "width="+width+",height="+height+",toolbars=no,scrollbars=no")
}

function storeJump(theregion) {
	if (theregion) {
		document.location.href = "storesearch.asp?region="+theregion;
	}
}

function viewCol(filename) {
	document.getElementById("prodimg").src = "images/products/"+filename;
}

function doCV2() {
	window.open("cardstrip.html", "cv2", "height=68,width=70,toolbars=no,scrollbars=no")
}

function valPayment() {
	if (document.frmPayment.CardNumber.value == '' || document.frmPayment.CardHolder.value == '' || document.frmPayment.ExpiryDate.value == '' || document.frmPayment.CV2.value == '' || document.frmPayment.bil_address1.value == '' || document.frmPayment.bil_towncity.value == '' || document.frmPayment.bil_postcode.value == '' || document.frmPayment.del_address1.value == '' || document.frmPayment.del_towncity.value == '' || document.frmPayment.del_postcode.value == '') {
		alert("Please fill in all required fields.");
		return false;
	}else{
		document.getElementById('submitbut').disabled = true;
		document.getElementById('submitbut').value = 'Please wait...';
		return true;
	}
}

function signupVal(trackType) {
	if (document.signupform.surname.value == '' || document.signupform.email.value == '' || document.signupform.userpassword.value == '' || document.signupform.address1.value == '' || document.signupform.postcode.value == '') {
		alert("Please fill in your name, email, password, address and postcode.");
		return false;
	}else if(document.signupform.email.value != document.signupform.conf_email.value) {
		alert("Your email and confirmed email do not match.");
		return false;
	}else{
		
	}
}

function chkGuest() {
	if (document.guestform.email.value == '') {
		alert("Please fill in all required fields.");
		return false;
	}
	else{
		if (! isValidEmail(document.guestform.email.value)) {
        	alert("Please enter a valid email address");
        	return false;
    	}else{
			return true;
		}
	}
}

function chkTrade() {
	if (document.tradeform.account_number.value == '' || document.tradeform.password.value == '') {
		alert("Please fill in your username and password.");
		return false;
	}else{
		if (document.tradeform.email.value != document.tradeform.confirmemail.value) {
        	alert("Please ensure your email and confirmed email are the same");if (! isValidEmail(document.signupform.email.value)) {
        	alert("Please enter a valid email address");
        	return false;
    	}else{
			_gaq.push(['_trackEvent', trackType, 'Submit']);
			return true;
		}
			return false;
		} else if (isValidEmail(document.tradeform.email.value) || document.tradeform.email.value == '') {
			return true;
    	}else{
        	alert("Please enter a valid email address or leave the field blank");
        	return false;
		}
	}
}

function showOther(action) {
	document.getElementById("howpurchase_other").style.display = action;
}

function sendEmail() {
	var url = 'sendfriend.asp';
	var pars = 'style_code='+$('style_code').value+'&style_name='+$('style_name').value+"&gender="+$('gender').value+'&senderName='+$('senderName').value+'&recName='+$('recName').value+'&recEmail='+$('recEmail').value;
	//document.write(url+'?'+pars);
	var myAjax = new Ajax.Request(url, {method: 'get', parameters: pars, onSuccess: function(){
		completeEmailer();
	}});
}

function chkEmail() {
	if (isValidEmail(document.orderform.email.value) && document.orderform.emailconfirm.value == document.orderform.email.value) {
		return true;
	}else{
		alert("Please enter a valid email address and ensure you have confirmed it");
		return false;
	}
}

function showEmailer() {
	$('emailoverlay').show();
	$('emaildialogue').show();
	$('senderform').show();
}

function hideEmailer() {
	$('emailoverlay').hide();
	$('emaildialogue').hide();
	$('senderform').hide();
	$('thanks').hide();
}

function completeEmailer() {
	$('senderform').hide();
	$('thanks').show();
}

function printStockists(region) {
	window.open("storesearch-print.asp?region="+escape(region), "print", "height=600,width=700,toolbars=yes,scrollbars=yes")
}

function zoomUpdate(style_code) {
	var zoom = document.getElementById('zoom1');
	document.getElementById('productcode').value = 'qwe';
	style_code = style_code.replace('/','-');
	MagicZoom.update(zoom, '/images/products/'+style_code+'_zoom.jpg', '/images/products/'+style_code+'.jpg', '');
}

function codeUpdate(style_code) {
	document.getElementById('productcode').innerHTML = style_code;
}

function setMenu(style_code) {
	s = document.getElementById('style_code');
    for ( var i = 0; i < s.options.length; i++ ) {
        if ( s.options[i].value == style_code ) {
            s.options[i].selected = true;
            return;
        }
    }
}

function showStock(action) {
	document.getElementById('ie6fixframe').style.display = action;
	document.getElementById('stockGrid').style.display = action;
}

function showTradeStock(action) {
	document.getElementById('ie6fixframe').style.display = action;
	document.getElementById('tradestockGrid').style.display = action;
}

function showTradeStockContinental(action) {
	document.getElementById('ie6fixframecontinental').style.display = action;
	document.getElementById('tradestockGridContinental').style.display = action;
}

function showStockOption(action) {
	document.getElementById(action).style.display = 'block';
}

function showSizes(action) {
	document.getElementById('ie6fixframe').style.display = action;
	document.getElementById('convChart').style.display = action;
}

function displayStock(number) {
	document.getElementById(number).style.display = 'block';
}

function checkStockEmail() {
	if (! isValidEmail(document.StockEmail.email.value)) {
		alert("Please enter a valid email address");
		return false;
	}else{
		return true;
	}
}

function checkStock(str,num)
{	
	if (window.XMLHttpRequest)
	  {// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }
	else
	  {// code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{	
		if (num < 21) {
			document.getElementById("stockgrid").innerHTML=xmlhttp.responseText;
		} else {
			document.getElementById("stockgridcontinental").innerHTML=xmlhttp.responseText;
		}
		}
	  }
	xmlhttp.open("post","stockgrid.asp?num="+num+"&code="+str,true);
	xmlhttp.send();
} 

