// JavaScript Document

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  alert("Please make sure that you set 'Page Scaling' to 'None' when printing the Measuring Chart.\n\nIf you do not print the chart at full size, incorrect measurments will result.\n\nPlease see the instructions on page 2 of the measuring chart.");
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_showHideLayers() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function catrequestvalidate(which) {
	var pass=true;
	which.Submit.value = "Submitting request - Please Wait...";
	which.Submit.disabled=true;
//alert(which.length);
	if (document.images) {
		for (i=0; i<23; i++) {	//step through each variable (field name)
			var tempobj=which.elements[i];
//alert("i="+i+" name="+tempobj.name);
			if(!pass) {
			//alert("Break!");
			//alert("i="+i+" name="+tempobj.name);
				break;
			}
			if (tempobj.name.substring(0,8)=="required") {
//alert(tempobj.name.substring(8,30).toUpperCase());				
				if (tempobj.name.substring(8,30).toUpperCase() == "HEARABOUTUS") {	// this is a special field that requires a further entry like "Which Search Engine" or "Which Publication"
					shortFieldName=tempobj.name.substring(8,30).toUpperCase();
					var k=document.getElementById(tempobj.name);
					var content=k.options[k.selectedIndex].text;
//					alert(i);
//					alert(k.options[k.selectedIndex].text);
//					alert("b");

					if(tempobj.selectedIndex==0) {	// Nothing selected in drop-down
//						alert("Nothing Selected!");
						shortFieldName=tempobj.name.substring(8,30).toUpperCase();
						pass=false;
						break;
					}
					
					if(content == "Advertisement") {
						for (j=0; j<which.length; j++) {
							var tempobj2=which.elements[j];
							if(tempobj2.name == "requiredadvertisement" && tempobj2.selectedIndex==0) {
								shortFieldName=tempobj2.name.substring(8,30).toUpperCase();
//								alert("A");
								pass=false;
								break;
							}
						}
					}
					if(content == "Internet Search") {
						for (j=0; j<which.length; j++) {
							var tempobj2=which.elements[j];
//							alert(tempobj2.name);
							if(tempobj2.name == "requiredsearchengine" && tempobj2.selectedIndex==0) {
								shortFieldName=tempobj2.name.substring(8,30).toUpperCase();
//								alert("B");
								pass=false;
								break;
							}
						}
					}
				
					if(content == "Other") {
						for (j=0; j<which.length; j++) {
							var tempobj2=which.elements[j];
//							alert(tempobj2.name);
							if(tempobj2.name == "requiredother" && tempobj2.value=='') {
								shortFieldName=tempobj2.name.substring(8,30).toUpperCase();
//								alert("B");
								pass=false;
								break;
							}
						}
					}
				
					
				} else {	// this is just a normal field
				
					if (tempobj.name.substring(8,30).toUpperCase() == 'COUNTY' && tempobj.selectedIndex == 0) {
						shortFieldName=tempobj.name.substring(8,30).toUpperCase();
//						alert(tempobj.selectedIndex);
//						alert(which.elements[i+2].name);

						var n = document.getElementById('requiredCountry');
						var country_content = n.options[n.selectedIndex].text;
						
						if (country_content == 'UK') {
//							alert("UK");
							pass=false;
							break;
						} else {
//							alert("Non UK");						
//							break;
						}



					} else {
						if (((tempobj.type=="text"||tempobj.type=="textarea")&&tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&tempobj.selectedIndex==0)) {
							shortFieldName=tempobj.name.substring(8,30).toUpperCase();
	//						alert("shortFieldName = "+shortFieldName);
	//						alert(testDiv(shortFieldName));
							
							if(testDiv(shortFieldName)=="visible" || testDiv(shortFieldName)==undefined) {
	//							alert("C");
								pass=false;
								break;
							}
						}
					}
				}
			}
		}
	}
//alert("Pass: "+pass);
	if (!pass) {
//		shortFieldName=tempobj.name.substring(8,30).toUpperCase();
//alert("1");
//		alert(shortFieldName);
//alert("2");
		if (shortFieldName == "TITLE") {
			alert("Please select a "+shortFieldName);
		} else {
			if (shortFieldName == "STREET") {
				alert("Please enter the address");
			} else {
				if (shortFieldName == "EMAIL") {
					alert("Please enter your email address");
				} else {		
					if (shortFieldName == "HEARABOUTUS") {
						alert("Please tell us where you heard about us");
					} else {
						if (shortFieldName == "CONTACT") {
							alert("Please tell us how we may contact you");
						} else {
							if (shortFieldName == "ADVERTISEMENT") {
								alert("Please tell us where you saw the advertisement");
							} else {
								if (shortFieldName == "SEARCHENGINE") {
									alert("Please tell us which search engine you used");
								} else {
									if (shortFieldName == "OTHER") {
										alert("Please tell us the other way you found us");
									} else {
										alert("Please enter a "+shortFieldName);
									}
								}
							}
						}
					}
				}
			}
		}
		which.Submit.value = "Send catalogue request";
		which.Submit.disabled=false;
//alert("False");
		return false;
	} else {
//alert("True");
		return true;
	}
}	// EOF function checkrequired(which)

function hideDiv(divName) { 
	var divs = document.getElementsByTagName('div'); 
	for(i=0; i<divs.length; i++){ 
		if(divs[i].id.match(divName)) { //if they are 'see' divs 
		
			if (document.getElementById) { // DOM3 = IE5, NS6 
				divs[i].style.visibility="hidden";// show/hide 
			} else {
				if (document.layers) { // Netscape 4 
					document.layers[divs[i]].display = 'hidden'; 
				} else { // IE 4 
					document.all.hideShow.divs[i].visibility = 'hidden'; 
				} 
			} 
		}
	}
}

function toggleCC(divName) { 
	var inputs = document.getElementsByTagName('input'); 
	for(i=0; i<inputs.length; i++){ 
		if(inputs[i].id.match(divName)) { //if they are 'see' divs 
		
			if (document.getElementById) { // DOM3 = IE5, NS6 
				if (inputs[i].style.display=="none") {	
					inputs[i].checked=true;
					inputs[i].style.display="block";
				}else{
					inputs[i].checked=false;
					inputs[i].style.display="none";
				}
			} else {
				if (document.layers) { // Netscape 4 
					document.layers[inputs[i]].display = 'hidden'; 
				} else { // IE 4 
					document.all.hideShow.inputs[i].visibility = 'hidden'; 
				} 
			} 
		}
	}
}


function showDiv(divName) { 
	var divs = document.getElementsByTagName('div'); 
	for(i=0; i<divs.length; i++) { 
		if(divs[i].id.match(divName)) { 
			if (document.getElementById) {
				divs[i].style.visibility="visible"; 
			} else {
				if (document.layers) { // Netscape 4 
					document.layers[divs[i]].display = 'visible'; 
				} else { // IE 4 
					document.all.hideShow.divs[i].visibility = 'visible'; 
				}
			}
		} 
	} 
} 

function testDiv(divName) { 
	var divs = document.getElementsByTagName('div'); 
	for(i=0; i<divs.length; i++) { 
		if(divs[i].id.match(divName)) { 
			if (document.getElementById) {
				return divs[i].style.visibility; 
			} else {
				if (document.layers) { // Netscape 4 
					return document.layers[divs[i]].display; 
				} else { // IE 4 
					return document.all.hideShow.divs[i].visibility; 
				}
			}
		}
	} 
} 

function tmpChk(which) {
	var x=document.getElementById(which.name);
	var content=x.options[x.selectedIndex].text;
	if(content=='Internet Search') {
		showDiv("SEARCHENGINE");
	} else {
		hideDiv("SEARCHENGINE");
	}
	if(content=='Advertisement') {
		showDiv("ADVERTISEMENT");
	} else {
		hideDiv("ADVERTISEMENT");
	}
	if(content=='Other') {
		showDiv("OTHER");
	} else {
		hideDiv("OTHER");
	}
}

function showCat() {
	Lightview.show({ href: '#FLIP', options: { width: 400, topclose: true, autosize: true}});
}

function find_base_url()
{
	
	
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	var new_url = "";
	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		if(pair[0] != "shoeimage" && pair[0] != "shoecolour") {
			if(new_url.length > 0) {
				new_url += "&" + vars[i];
			}else{
				new_url += vars[i];
			}
//			alert(vars[i]);
//			alert(new_url);
		}
	}
	
	return window.location.protocol + "//" + window.location.host + "" + window.location.pathname + "?" + new_url;
	
//	full_url = new String(window.location);
//
//	if(full_url.indexOf("&")<=0) {
//	alert('['+full_url+']');
//		base_url=window.location;
//	} else {
//		if (full_url.indexOf("shoeimage")>=0) {
//			if(full_url.indexOf("shoeimage")>full_url.indexOf("shoesize")){
//				base_url=full_url.substr(0,full_url.indexOf("shoeimage")-1);
//			} else {
//				base_url=full_url.substr(0,full_url.indexOf("shoeimage")-1);
//				base_url=base_url+full_url.substr(full_url.indexOf("shoesize")-1,20);
//			}
//		} else if(full_url.indexOf("shoeimage")<=0){
//			base_url=window.location;
//		}
//	}
}
var qsParm = new Array();
var qp = new Array();
function get_qs() {
	var query = window.location.search.substring(1);
	var parms = query.split('&');
	for (var i=0; i<parms.length; i++) {
		var pos = parms[i].indexOf('=');
		if (pos > 0) {
			qp[i] = new Array();
			var key = parms[i].substring(0,pos);
			var val = parms[i].substring(pos+1);
			qsParm[key] = val;
			qp[i][0] = key;
			qp[i][1] = val;
		}
	}
}

function selectSize(Fitting, Size) {
	if (Fitting == '0') {
		alert("Please select a fitting first");
		return false;
	} else {
		curr_url = new String(window.location);
//		alert(curr_url.substr(0,curr_url.indexOf("?")));
		get_qs();
		qsParm['shoefitting'] = null;
		qsParm['shoesize'] = null;
		qsParm['shoefitting'] = Fitting;
		qsParm['shoesize'] = Size;
		var newQuery = curr_url.substr(0,curr_url.indexOf("?")) + "?";
//		var newQuery = "./products2.php?";
		for (var j=0; j<qp.length; j++) {
			if ((qp[j][0] != "shoefitting") && (qp[j][0] != "shoesize")) {
				if (j > 0) {
					newQuery = newQuery + "&" + qp[j][0] + "=" + qp[j][1];
				} else {
					newQuery = newQuery + qp[j][0] + "=" + qp[j][1];
				}
			}
		}
		newQuery = newQuery + "&shoefitting=" + qsParm['shoefitting']
		newQuery = newQuery + "&shoesize=" + qsParm['shoesize']
		gotoURL = newQuery;
//		alert(gotoURL);
		location.href=gotoURL + "#longDesc";
//		window.location="\" + newQuery + \"";
		return true;
	}
}
function changeImage(Image, Colour)
{
	base_url = find_base_url();
//	alert(base_url);
//	alert(Image);
//	alert('['+base_url+']');
	document.images["LargeShoeImage"].src = Image;
	base_url=base_url+"&shoeimage="+Image+"&shoecolour="+Colour;
//	alert(base_url);

//	alert(navigator.userAgent);
//		alert(base_url);
//	if(navigator.userAgent.toLowerCase().indexOf("safari")>=0) {
//		alert("["+base_url+"]");
//		window.opener.window.location.href=base_url;
//	}else{
		location.href=base_url;
//	}
	return true;
}
function setImage(Image)
{
	document.images["LargeShoeImage"].src = Image;
	return true;
}

function setFeatureImage(Image)
{
	document.images["FeatureImage"].src = Image;
	return true;
}

function changecountry(item){
//	alert(item.value);
	document.forms["checkout_address"].country_code.value = "changed";
	document.forms["checkout_address"].submit();
}


<!--
function checkrequired(what) {
	var pass=true;
	if (document.images) {
		for (i=0;i<what.length;i++) {
			var tempobj=what.elements[i];
			if (tempobj.name=="id[2]") {
				if (((tempobj.type=="text"||tempobj.type=="textarea"||tempobj.type=="hidden")&&(tempobj.value<='1000'||tempobj.value>='1510'))||(tempobj.type.toString().charAt(0)=="s"&&tempobj.selectedIndex==0)){
					pass=false;
					break;
				}
			}
			if (tempobj.name=="colour") {
				if (((tempobj.type=="text"||tempobj.type=="textarea"||tempobj.type=="hidden")&&tempobj.value=='None')||(tempobj.type.toString().charAt(0)=="s"&&tempobj.selectedIndex==0)){
					pass=false;
					break;
				}
			}
			if (tempobj.name=="fitting") {
				if (((tempobj.type=="text"||tempobj.type=="textarea"||tempobj.type=="hidden")&&tempobj.value=='None')||(tempobj.type.toString().charAt(0)=="s"&&tempobj.selectedIndex==0)){
					pass=false;
					break;
				}
			}
			if (tempobj.name=="fitting") {
				if (((tempobj.type=="text"||tempobj.type=="textarea"||tempobj.type=="hidden")&&(tempobj.value=='6E'||tempobj.value=='8E'||tempobj.value=='6E-8E(V)'))||(tempobj.type.toString().charAt(0)=="s"&&tempobj.selectedIndex==0)){
					if (confirm("You have selected a fitting that qualifies for vat relief provided that you, or the person for whom you are making the purchase, meet the criteria for VAT exemption because of a medical condition.\n\nAt the point of checkout, you will be able to claim VAT relief on the product if you are eligible.\n\nIf you require any help, please call us on the number below or click the link at the top of the page for details of how to claim vat relief.\n\nPlease note: We are not able to comment or offer an opinion on individual cases and you should consult your medical advisor.")) {
					} else {
						pass=false;
						break;
					}
				}				
			}
		}
	}


	if (!pass) {
	//shortFieldName=tempobj.name.substring(8,30).toUpperCase();

	if (tempobj.name=="id[2]") {
		alert("Please select a size.");
	}
	if (tempobj.name=="fitting") {
		alert("Please select a fitting.");
	}
	if (tempobj.name=="colour") {
		alert("Please select a colour.");
	}

	return false;

}

else

return true;
}


