// JavaScript Document

function emptyEventReq()
	{
	var obj = document.getElementById('event_req').innerHTML;
	if(obj=="Please include estimated number of guests, dates, event required and any preferred locations..."){document.getElementById('event_req').innerHTML = ""};
	}
	
function fillEventReq()
	{
	var obj = document.getElementById('event_req').innerHTML;
	if(obj==""){document.getElementById('event_req').innerHTML = "Please include estimated number of guests, dates, event required and any preferred locations..."};
	}

function contact()
	{
	empty=false;fm=document.details
	checker(fm.name,'Name');
	checker(fm.company,'Company Name')
	checker(fm.tel,'Contact Number')
	check_email(fm.email)
	checker2(fm.event_req,'Event Requirements')
	if(empty==false){fm.submit()}
	}
	
function check_email(obj)
	{
	var emailStr=obj.value;var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)!£$%^&*()+='#~?<>@,;:\\\\\\\"\\.\\[\\]";var validChars="\[^\\s" + specialChars + "\]";var quotedUser="(\"[^\"]*\")";var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+';var word="(" + atom + "|" + quotedUser + ")";var userPat=new RegExp("^" + word + "(\\." + word + ")*$");var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");var matchArray=emailStr.match(emailPat)
	if ((matchArray==null) && empty==false){alert("Email address seems incorrect (check @ and .'s)");empty=true}
	if (empty==false){var user=matchArray [1];var domain=matchArray [2];if (user.match(userPat)==null){alert("The username doesn't seem to be valid.");empty=true}}
	if (empty==false){var IPArray=domain.match(ipDomainPat);if (IPArray!=null){for (var j=1;j<=4;j++){if (IPArray[j]>255){alert("Destination IP address is invalid!");empty=true}}}}
	if (empty==false){var domainArray=domain.match(domainPat);if (domainArray==null){alert("The domain name doesn't seem to be valid.");empty=true}}
	if (empty==false){var atomPat=new RegExp(atom,"g");var domArr=domain.match(atomPat);var len=domArr.length;if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3){alert("The address must end in a three-letter domain, or two letter country.");empty=true}}
	if ((len<2) && empty==false){alert("This address is missing a hostname!");empty=true};
	}

function checker(obj,msg)
	{if(obj.value=='' && empty==false){alert('The ' + msg + ' field must not be blank');empty=true;obj.focus()}}
	
function checker2(obj,msg)
	{if(obj.value=='' || obj.value=="Please include estimated number of guests, dates, event required and any preferred locations..." && empty==false){alert('The ' + msg + ' field must not be blank');empty=true;obj.focus()}}


function showFlash(){
	document.write ('<object type="application/x-shockwave-flash" data="/flash/broad.swf" width="770" height="256">')
	document.write ('<param name="movie" value="/flash/broad.swf"/>')
	document.write ('<param name="wmode" value="transparent"/>')
	document.write ('<img src="/flash/images/1.jpg" alt="" />')
	document.write ('</object>')	
}

var timeout	= 500;
var timein = 0;
var closetimer	= 0;
var currentSub = 0;
var opentimer = 0;


function subOpen(id){
	cancelClose();
	opentimer = window.setTimeout('subOpen2(\''+id+'\')', timein);
	timein = 500;
}

function subOpen2(id){	
	if(opentimer){
		if(currentSub) currentSub.style.display = "none";
		currentSub = document.getElementById(id);
		currentSub.style.display = "block";
	}	
}

function subClose(){
	if(currentSub){
		currentSub.style.display = "none";
	}
}

function subCloseTimer(){
	closetimer = window.setTimeout(subClose, timeout);
}

function cancelClose(){
	if(closetimer){
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

function subCancelClose(){
	subCancelOpen()
	if(closetimer){
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

function subCancelOpen(){
	if(opentimer){
		window.clearTimeout(opentimer);
		opentimer = null;
	}
}

document.onclick = subClose;