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_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_findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.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 showhide_search_dropdowns (dVal){
	
	if (dVal == '1') {
		if(document.getElementById('frmType')){
			document.getElementById('frmType').style.display = 'block';	
		};

		if(document.getElementById('frmGroup')){
			document.getElementById('frmGroup').style.display = 'none';
		};
		document.forms.frmSearch.iRangeID.selectedIndex=0;
	} else {
		if(document.getElementById('frmType')){
			document.getElementById('frmType').style.display = 'none';	
		};

		if(document.getElementById('frmGroup')){
			document.getElementById('frmGroup').style.display = 'block';
		};
		document.forms.frmSearch.iTypeID.selectedIndex=0;
	}
} 

function do_reload_url(dPage, dGroupID) {
	
	if (dPage != 'collections') {
		dGroupID = document.forms.frmSearch.iGroupID.value
		var iRangeID = document.forms.frmSearch.iRangeID.value
		var iTypeID = document.forms.frmSearch.iTypeID.value
	}
	
	// use this to search with all the currrent form vaules
	// problem is when you reload the page, the range or style might not exist in that category and so you'll return no results
	//var dURL = dPage + '.asp?page=collections&iGroupID=' + dGroupID + '&iRangeID=' + iRangeID + '&iTypeID=' + iTypeID + '&s_lt='
	var dURL = dPage + '.asp?page=collections&iGroupID=' + dGroupID + '&s_lt='
		
	if (document.forms.frmSearch.lt[0].checked == true) {
		dURL = dURL + '1'
	} else {
		dURL = dURL + '2'
	}
	
	window.location = dURL;
}
				
function onLoad(){
	
	if (document.getElementById('frmSearch')) {
		if (document.forms.frmSearch.lt[0].checked == true) {
			document.forms.frmSearch.lt[0].checked = true
			showhide_search_dropdowns ('0');
		} else if (document.forms.frmSearch.lt[1].checked == false){
			document.forms.frmSearch.lt[0].checked = true
			showhide_search_dropdowns ('0');
		} else {
			document.forms.frmSearch.lt[1].checked = true
			showhide_search_dropdowns ('1');
		}
	}
}

function viewLargeFrame(dURL) {
	frmLargeWin=window.open(dURL,"frmLargeWin","width=440,height=300,top=20,left=20,resizable=yes,menubar=no,scrollbars=no,location=no,status=no,toolbar=no,directories=no"); 
	frmLargeWin.focus();
}

function viewBrochureRequest(dURL) {
	frmBrochureRequest=window.open(dURL,"frmBrochureRequest","width=440,height=600,top=20,left=20,resizable=yes,menubar=no,scrollbars=no,location=no,status=no,toolbar=no,directories=no"); 
	frmBrochureRequest.focus();
}


function checkContactForm() {

	var f = document.frm_req_brochure;
	var errors = 0;
	var messages = ""
	
	if(f.txtName.value == "") {
		messages = messages + "• Your name\n";
		errors++;
	}
	if(f.txtAddress_1.value == "") {
		messages = messages + "• the first line of your address\n";
		errors++;
	}
	if(f.txtTownCity.value == "") {
		messages = messages + "• Your town / city\n";
		errors++;
	}
	if(f.txtCounty.value == "") {
		messages = messages + "• Your county\n";
		errors++;
	}
	if(f.txtPostcode.value == "") {
		messages = messages + "• Your Postcode\n";
		errors++;
	}
	//Email address
	if(f.txtEmail.value == "") {
		messages = messages + "• Your email address\n";
		errors++;
	} else if(f.txtEmail.value.indexOf("@") < 0 || f.txtEmail.value.indexOf(".") < 0 || f.txtEmail.value.length < 6) {
		messages = messages + "• A valid email address\n";
		errors++;
	}

	if(errors > 0) {
	
		msg = "Please supply the following " + errors + " piece(s) of information:\n" + messages;
		
		alert(msg);
	
		return false;
	} else {
		return true;
	}
}
