function supSearch() {
	if(document.supForm.wedcat_id.options[document.supForm.wedcat_id.selectedIndex].value == "") {
		alert("Please select a supplier type");
	} else {
		document.supForm.submit();
	}
}

function supSearchReturn() {
	if(document.supForm.wedcat_id.options[document.supForm.wedcat_id.selectedIndex].value == "") {
		alert("Please select a supplier type");
		return false;
	} else {
		return true;
	}
}

function venSearch() {
	document.venForm.submit();
}

function venFilter(changedfield) {
	if (changedfield == "Country") {
		document.venForm.Region.selectedIndex = 0;
		document.venForm.County.selectedIndex = 0;
		document.venForm.TownCity.selectedIndex = 0;
	} else if (changedfield == "Region") {
		document.venForm.County.selectedIndex = 0;
		document.venForm.TownCity.selectedIndex = 0;
	} else if (changedfield == "County") {
		document.venForm.TownCity.selectedIndex = 0;
	}
	document.venForm.submit();
}

function supFilter(changedfield) {
	if(document.supForm.wedcat_id.options[document.supForm.wedcat_id.selectedIndex].value == "") {
		alert("Please select a supplier type");
	} else {
		if (changedfield == "Country") {
			document.supForm.Region.selectedIndex = 0;
			document.supForm.County.selectedIndex = 0;
			document.supForm.TownCity.selectedIndex = 0;
		} else if (changedfield == "Region") {
			document.supForm.County.selectedIndex = 0;
			document.supForm.TownCity.selectedIndex = 0;
		} else if (changedfield == "County") {
			document.supForm.TownCity.selectedIndex = 0;
		}
		document.supForm.submit();
	}
}

function lateEnquiry(late_id) {
	window.open("latecontact.asp?late_id="+late_id, "emailpopup", "width=611,height=460,toolbar=0,scrollbars=0")
}

function venueEmail(id) {
	window.open("venueemail.asp?id="+id, "emailpopup", "width=640,height=500,toolbar=0,scrollbars=0")
}

function supplierEmail(id) {
	window.open("supplieremail.asp?id="+id, "emailpopup", "width=640,height=500,toolbar=0,scrollbars=0")
}

function showMore(id) {
	document.getElementById('shorttext_'+id).style.display = 'none';
	document.getElementById('longtext_'+id).style.display = 'block';
}

function showLess(id) {
	document.getElementById('longtext_'+id).style.display = 'none';
	document.getElementById('shorttext_'+id).style.display = 'block';
}

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 doenquiry()
{	
	errormsg='';
	if($F("name")==''){errormsg = errormsg + '\n   - Your Name';}
	if($F("email")==''){errormsg = errormsg + '\n   - Your Email';}
	if($F("telephone")==''){errormsg = errormsg + '\n   - Your Telephone Number';}
	if($F("message")==''){errormsg = errormsg + '\n   - Your Message';}
	if(errormsg.length==0){
		if (! isValidEmail($F("email"))) {
			alert('Invalid email address, please try again.');
			return false;
		}
	}else{
         errormsg = 'The following fields need to be included:\n' + errormsg + '\n';
         alert(errormsg);
         return false;
	}


	var url = "enquirysend.asp";
	var params='email='+$F("email")+'&id='+$F("id")+'&telephone='+$F("telephone")+'&name='+encodeURIComponent($F("name"))+'&message='+encodeURIComponent($F("message"))+'&date_day='+$F("date_day")+'&date_month='+$F("date_month")+'&date_year='+$F("date_year")+'&optin='+$F("optin")+'&Info='+$F("Info")+'&enqtype='+$F("enqtype");
	new Ajax.Request(url, {onComplete:showResponse, onException:showException, onFailure:showException, asynchronous:true, method:"post", evalScripts:false, postBody:params});
	$("submit").hide();
	$("loadicon").show();

	function showResponse(req)
	{	
		if (req.responseText=="1")
		{
			$("loadicon").hide();
			$("contactform").hide();
			$("okmessage").show();
		}
		if (req.responseText=="error")	
		{
			alert("An error has occured. Please try again.");
			$("loadicon").hide();
			$("okmessage").hide();
			$("submit").show();
		}
	}
	function showException()
	{
		alert("Error occured while talking to the server. Please try again.");
		$("loadicon").hide();
		$("okmessage").hide();
		$("submit").show();
		$("name").clear();
		$("email").clear();
	}
}

function valEnquiry() {
	if (document.enqForm.contactname.value == '' || document.enqForm.venuename.value == '' || document.enqForm.contactnumber.value == '' || document.enqForm.emailaddress.value == '') {
		alert("Please ensure all the mandatory fields are filled in.");
		return false;
	}else{
		if (! isValidEmail(document.enqForm.emailaddress.value)) {
        	alert("Please enter a valid email address");
        	return false;
    	}else{
			return true;
		}
	}
}

function galleryPopup(id,gallery_id,thetype) {
	window.open("gallerypic.asp?id="+id+"&gallery_id="+gallery_id+"&thetype="+thetype, "gallerypopup", "width=610,height=620,toolbar=0,scrollbars=0")
}

function swapGal(hidegal,showgal) {
	document.getElementById('gallery'+hidegal).style.display = 'none';
	document.getElementById('gallery'+showgal).style.display = 'block';
}