//function to enable pseudo hover class in IE

sfHover = function( objID ) 
{
	var sfEls = document.getElementById( objID ).getElementsByTagName("li");
	for (var i=0; i<sfEls.length; i++)
	{
		sfEls[i].onmouseover = function()
		{
			this.className+=(this.className.length>0? " ": "") + "sfhover";
		}
		sfEls[i].onmouseout = function()
		{
			this.className=this.className.replace(new RegExp("( ?|^)sfhover\\b"), "");
		}
	} 
}

sfHover2 = function( objID ) 
{
	var sfEls = document.getElementById( objID );
	sfEls.onmouseover = function()
	{
		this.className+=(this.className.length>0? " ": "") + "sfhover";
	}
	sfEls.onmouseout = function()
	{
		this.className=this.className.replace(new RegExp("( ?|^)sfhover\\b"), "");
	}
}

if (window.attachEvent)
{
	window.attachEvent("onload", function () { sfHover("topNav"); } );
}

function vgo(address) {
	document.location.href = address;
}

function countryChange(countrycode) {
	document.location.href = 'index.asp?Country='+countrycode;
}

function countyChange(countyid) {
	document.location.href = 'index.asp?County='+countyid+'&Country='+document.searchform.Country.value;
}

function popup(thepage,thewidth,theheight,thetoolbar,thescrollbars) {
	window.open(thepage, "popup", "width="+thewidth+",height="+theheight+",toolbar="+thetoolbar+",scrollbars="+thescrollbars)
}

function roomPopup(room_id) {
	window.open("roompic.asp?room_id="+room_id, "roompopup", "width=610,height=610,toolbar=0,scrollbars=0")
}

function galleryPopup(venue_id,gallery_id) {
	window.open("gallerypic.asp?venue_id="+venue_id+"&gallery_id="+gallery_id, "gallerypopup", "width=610,height=620,toolbar=0,scrollbars=0")
}

function venueEmail(venue_id) {
	window.open("venueemail.asp?id="+venue_id, "emailpopup", "width=700,height=550,toolbar=0,scrollbars=0")
}

function venueBrochure(venue_id) {
	window.open("requestbrochure.asp?id="+venue_id, "brochurepopup", "width=700,height=550,toolbar=0,scrollbars=0")
}

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 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 qsSubmit(changedfield) {
	if (changedfield == "Country") {
		document.searchform.Region.selectedIndex = 0;
		document.searchform.County.selectedIndex = 0;
		document.searchform.TownCity.selectedIndex = 0;
	} else if (changedfield == "Region") {
		document.searchform.County.selectedIndex = 0;
		document.searchform.TownCity.selectedIndex = 0;
	} else if (changedfield == "County") {
		document.searchform.TownCity.selectedIndex = 0;
	}
	document.searchform.submit()
}

function idjump(id) {
	document.location.href = '/venue.asp?id='+id+"&nav=london";
}

function lqsSubmit(changedfield) {
	for(i=0; i<document.searchform.elements.length; i++) {
		if (document.searchform.elements[i].name != changedfield && document.searchform.elements[i].name != '' && document.searchform.elements[i].name != 'VenueType') {
			document.searchform.elements[i].selectedIndex = 0;
		}
	}
	document.searchform.submit()
}

function lqsVenue() {
	okay = false;
	for(i=0; i<document.searchform.elements.length; i++) {
		if (document.searchform.elements[i].name != '' && document.searchform.elements[i].name != 'VenueType' && document.searchform.elements[i].selectedIndex != 0) {
			//alert(document.searchform.elements[i].name & ": " & document.searchform.elements[i].selectedIndex);
			okay = true;
		}
	}
	
	if (okay == true) {
		document.searchform.submit()
	}else{
		alert("Please select a location");
	}
}

function londonAdvertise(area) {
	window.open("londonadvertise.asp?area="+area, "emailpopup", "width=530,height=430,toolbar=0,scrollbars=0")
}