// setdatequick is to create a SQL server date from a single text box - to allow 01/04/04 entry
function setdatequick(frm, datefld, initial) {
	var datefield = document.getElementById(datefld); var datefield1 = document.getElementById(datefld + "1");
	var datefieldlast = document.getElementById(datefld+"last"); var datefieldlast1 = document.getElementById(datefld + "last1");
	var datestr = datefield1.value;
	if(datestr=="") { datefield.value=''; return; }
	if((datestr.length>5)&&(datestr.indexOf("/")==-1)&&(!isNaN(datestr))) { datestr = datestr.substr(0,2)+"/"+datestr.substr(2,2)+"/"+datestr.substr(4); }
	datestr = datestr.replace("-","/");
	datestr = datestr.replace("-","/");
	datefield1.value = datestr;
	if((datestr.indexOf("/")==-1)||(datestr.indexOf("/",5)==-1)||(datestr.indexOf("/")==datestr.indexOf("/",5))) {alert("Please enter dates in dd/mm/yyyy or ddmmyyyy format"); return;}
	var x = datestr.split("/"); var thisday = x[0]; var thismon = x[1]; var thisyea = x[2];
	// irrespective of the rest of the date values, update the year to a 4 figure year
	if ((thisyea<=100)&&(isNaN(parseFloat(thisyea))==false)) { if(thisyea>=31) thisyea=(1900 + parseFloat(thisyea)); else thisyea=(2000 + parseFloat(thisyea)); }
	if (isNaN(parseInt(thisday))||thismon==0||isNaN(parseFloat(thisyea))) { datefield.value=''; datefield1.value=''; }
	else{ if (thisday.length==1) thisday=("0" + thisday);
		if ((isDate(""+thisyea+thismon+thisday+"")==false)||thisyea<1900||thisyea>2050||thismon>12) {
			alert(" "+thisday+"/"+thismon+"/"+thisyea+" is not a valid date"); datefield.value = datefieldlast.value; datefield1.value = datefieldlast1.value;
			}
		else  {var thisDate = new Date(); 
			if((datefld=="empDob")&&((thisDate.getFullYear()-thisyea)<15)) alert("Sorry, but that would make the age less than 16 - please try again");
			else {
				datefield.value = (""+thisyea+thismon+thisday+""); datefield1.value = (""+thisday+"/"+thismon+"/"+thisyea+""); 
				datefieldlast.value = datefield.value; datefieldlast1.value = datefield1.value; 
				}
			}
		}
}
function timecheck(thisfld, timetype) {
	thistime = thisfld.value; 
	if(timetype=='h') maxval = 23; else maxval = 59;
	if(thistime=="" || isNaN(thistime)) thistime=0; else thistime = parseInt(thistime)
	if(thistime<0 || thistime >maxval) thistime=0;
	if(thistime < 10) thistime = "0" + thistime;
	thisfld.value=thistime;
}

function clearsearch(thisfield, defval, leaving) {
	if(thisfield.value==defval && !leaving) thisfield.value='';
	else { if(thisfield.value==''&&leaving) thisfield.value=defval; }
}
function searchcheck(thisform, defval, checkfield) {
	if(checkfield.value==defval) checkfield.value = '';
	return true; 
}
// setdate is to create a SQL server date from a series of 2 text boxes and a select menu
// All fields use the same stem for naming to facilitate the generic nature of the function
function setdate(frm,datefld) {
	var thisobj = ("document." + frm);
	var thisday = eval(thisobj + "." + datefld + "1.value");
	var thismon = eval(thisobj+"."+datefld+"2.options["+thisobj+"."+datefld+"2.selectedIndex].value");
	var thisyea = eval(thisobj + "." + datefld + "3.value");
	// irrespective of the rest of the date values, update the year to a 4 figure year
  	if ((thisyea<=100)&&(isNaN(parseInt(thisyea))==false))
		{if(thisyea>=31)
			{thisyea=(1900 + parseInt(thisyea));}
		else
			{thisyea=(2000 + parseInt(thisyea));}
		 eval(thisobj + "." + datefld + "3.value="+thisyea);
		}

	if (isNaN(parseInt(thisday))||thismon==0||isNaN(parseInt(thisyea)))
		{ eval(thisobj+"."+datefld+".value=''");}
	else
		{ 
		  if (thisday.length==1) thisday=("0" + thisday);
		  if (isDate(""+thisyea+thismon+thisday+"")==false) {
			alert(" "+thisday+"/"+thismon+"/"+thisyea+" is not a valid date");
			eval(thisobj+"."+datefld+".value=''");
			}
		  else  {var thisDate = new Date();
			if((datefld=="empDob")&&((thisDate.getFullYear()-thisyea)<15))
				{alert("Sorry, but that would make the age less than 16 - please try again");}
			else {thisfld = eval(thisobj+"."+datefld);thisfld.value=(""+thisyea+thismon+thisday+"");}
			}
		}
}

// Whereas this one allows the month to be a hidden or text field for year only choices
function setdateyr(frm,datefld) {
	var thisobj = ("document." + frm);
	var thisday = eval(thisobj + "." + datefld + "1.value");
	var thismon = eval(thisobj+"."+datefld+"2.value");
	if (thismon.length==1) thismon=("0" + thismon);
	var thisyea = eval(thisobj + "." + datefld + "3.value");
	// irrespective of the rest of the date values, update the year to a 4 figure year
  	if ((thisyea<=100)&&(isNaN(parseInt(thisyea))==false))
		{if(thisyea>=31)
			{thisyea=(1900 + parseInt(thisyea));}
		else
			{thisyea=(2000 + parseInt(thisyea));}
		 eval(thisobj + "." + datefld + "3.value="+thisyea);
		}

	if (isNaN(parseInt(thisday))||thismon==0||isNaN(parseInt(thisyea)))
		{ eval(thisobj+"."+datefld+".value=''");}
	else
		{ 
		  if (thisday.length==1) thisday=("0" + thisday);
		  if (isDate(""+thisyea+thismon+thisday+"")==false) {
			alert(" "+thisday+"/"+thismon+"/"+thisyea+" is not a valid date");
			eval(thisobj+"."+datefld+".value=''");
			}
		  else  {var thisDate = new Date();
			if((datefld=="empDob")&&((thisDate.getFullYear()-thisyea)<15))
				{alert("Sorry, but that would make the age less than 16 - please try again");}
			else {thisfld = eval(thisobj+"."+datefld);thisfld.value=(""+thisyea+thismon+thisday+"");}
			}
		}
}

function isDate(dateStr) {
    month = dateStr.substring(4,6);
    day = dateStr.substring(6,8);
    year = dateStr.substring(0,4);
    if (day < 1 || day > 31) { return false;}
    if ((month==4 || month==6 || month==9 || month==11) && day>=31) {return false;}
    if (month == 2) { // check for february 29th
        var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
        if (day > 29 || (day==29 && !isleap)) {return false;}
    }
    return true; // date is valid
}

// setzero is to turn a text string (which is a number) into a number with two padded decimal places
function setzero(sz_num) {
	sz_num = "" + sz_num;
	sz_num = sz_num.replace(",","");
	if(isNaN(sz_num)) sz_num = "0" 
	sz_num = parseFloat(sz_num);
	sz_num = Math.round(sz_num*100)/100;
	sz_num = "" + sz_num;
	var sz_dotpos = sz_num.indexOf('.');
	if (sz_dotpos < 0) sz_num+=".00";
	if (sz_dotpos==(sz_num.length-1)) sz_num+="00";
	if (sz_dotpos==(sz_num.length-2)) sz_num+="0";
	return sz_num ;
}

function getSelectedRadio(buttonGroup) { // returns the array number of the selected radio button or -1 if no button is selected
	if (buttonGroup[0]) { for (var i=0; i<buttonGroup.length; i++) if (buttonGroup[i].checked) return i } 
	else {if (buttonGroup.checked) return 0;} return -1; }

function getSelectedRadioValue(buttonGroup) { // returns the value of the selected radio button or "" if no button is selected
	var i = getSelectedRadio(buttonGroup);
	if (i == -1) return ""; else {if (buttonGroup[i]) return buttonGroup[i].value; else return buttonGroup.value; }}

function showhide(id) { 
	obj = document.getElementById(id); 
	if (obj.style.display == "none") obj.style.display = ""; else obj.style.display = "none"; 
} 

function showhidediv(id, istate) { 
	obj = document.getElementById(id); 
	if (istate=="show" || (obj.style.display == "none" && istate=="swap")) obj.style.display = "block"; else obj.style.display = "none"; 
} 

function toggleBox(szDivID, iState) // 1 visible, 0 hidden
{
    if(document.layers)	   //NN4+
       if(document.layers[szDivID].visibility=="show"||iState==0) document.layers[szDivID].visibility = "hide"; else document.layers[szDivID].visibility = "show";
    else if(document.getElementById)	  //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(szDivID);
        if(obj.style.visibility == "visible"||iState==0) obj.style.visibility = "hidden"; else obj.style.visibility = "visible";
    }
    else if(document.all)	// IE 4
        if(document.all[szDivID].style.visibility=="visible"||iState==0) document.all[szDivID].style.visibility = "hidden"; else document.all[szDivID].style.visibility = "visible";
		 showhide(szDivID)
}

// Ajax functions
function GetXmlHttpObject() {
	var xmlHttp=null;
	try { xmlHttp=new XMLHttpRequest(); } // Firefox, Opera 8.0+, Safari
	catch (e) { // Internet Explorer
		try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
	catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
	}
	return xmlHttp;
}

function getajax(div, ajaxpage, ajtype, var1, var2, var3, var4) {
	xmlHttp=GetXmlHttpObject();
	//document.getElementById(div).innerHTML = "Loading ...";
	if (xmlHttp==null) { alert ("Your browser does not support AJAX!"); return; } 
	xmlHttp.onreadystatechange=function() { if (xmlHttp.readyState==4) { document.getElementById(div).innerHTML=xmlHttp.responseText } }
	xmlHttp.open("GET",ajaxpage + "?ajax="+div+"|"+ajtype+"|"+var1+"~"+var2+"~"+var3+"~"+var4+"|"+new Date().getTime(),true);
	xmlHttp.send(null);
} 

function logincheck(thisform) {
	var msg = "";
	if((thisform.Password.value == "")&&(thisform.reminder.value=="")) { msg += "  - you have not entered a password\n" }
	// email validation
	var thise = thisform.Username ; var emsg = "  - Please ensure a valid email address is entered for your username\n"
	s = thise.value; s = s.replace(",","."); s = s.replace(" ",""); thise.value = s;
	if((s=="")||(s.indexOf('@')<=1)||(s.indexOf('.')<=0)) msg += emsg ;	
	else { if((s=="")||(s.length<6)) msg+=emsg ; else { var theStr=s; var index=theStr.indexOf("@");
	if (index>0) {var pindex=theStr.indexOf(".",index);	if (!((pindex>index+1) && (theStr.length > pindex+1))) msg += emsg ; }	else msg += emsg ; } }
	var success=(msg=="");
	if(success==false) alert("Sorry, but you have not yet filled in all of the required fields:\n\n"+msg);
	return success; 
}
function swapdivs(divstem, divno, total) { showhidediv(divstem+divno, "show"); for(i=1;i<=total;i++) { if(i!=divno) showhidediv(divstem+i, ""); } }

function switchdiv(block, imgstem, fp) {
	if(fp==undefined) fp="";
	thisimg = document.getElementById(block + 'img'); if(imgstem == undefined) imgstem = "";
	if(layervisibility(block)) { showhidediv(block, 'hide'); thisimg.src=fp + 'images/icons/plus'+imgstem+'.gif'; } 
	else { showhidediv(block, 'show'); thisimg.src=fp + 'images/icons/minus'+imgstem+'.gif'; }
}
function layervisibility(layerid) {
	 if(document.layers)	return (document.layers[layerid].visibility == "show")
    else if(document.getElementById)	  //gecko(NN6) + IE 5+
    { return (document.getElementById(layerid).style.visibility == "visible" || document.getElementById(layerid).style.display != "none") }
    else if(document.all)	// IE 4
        return (document.all[layerid].style.visibility=="visible")
}

function getotherevents(urn,cnt,gig,div,fullp,showhide) {
	document.getElementById(div).innerHTML='<h2 align="center">Loading ...</h2>';
	if(showhide==undefined) showhide=1;
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) { alert ("Your browser does not support AJAX!"); return; } 
	xmlHttp.onreadystatechange=function() { if (xmlHttp.readyState==4) { document.getElementById(div).innerHTML=xmlHttp.responseText } }
	if(div=="othergigs") ajaxpage = "more-gigs"; else ajaxpage = "more-events"
	xmlHttp.open("GET",fullp+"inc/" + ajaxpage + ".asp?x="+gig+"|"+urn+"|"+cnt+"|"+showhide+"|"+new Date().getTime(),true);
	xmlHttp.send(null);
} 
function getotherreviews(urn, cnt, rurn, div, fullp, showhide) {
	document.getElementById(div).innerHTML='<h2 align="center">Loading ...</h2>';
	if(showhide==undefined) showhide=1;
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) { alert ("Your browser does not support AJAX!"); return; } 
	xmlHttp.onreadystatechange=function() { if (xmlHttp.readyState==4) { document.getElementById(div).innerHTML=xmlHttp.responseText } }
	ajaxpage = "more-venue-reviews"
	xmlHttp.open("GET",fullp+"inc/" + ajaxpage + ".asp?x="+rurn+"|"+urn+"|"+cnt+"|"+showhide+"|"+new Date().getTime(),true);
	xmlHttp.send(null);
} 

//** Chrome Drop Down Menu- Author: Dynamic Drive (http://www.dynamicdrive.com)
var cssdropdown={ disappeardelay: 150, dropdownindicator: '',//<img src="images/icons/down.gif" alt="" />',
enablereveal: [true, 3], enableiframeshim: 1, 
dropmenuobj: null, asscmenuitem: null, domsupport: document.all || document.getElementById, standardbody: null, iframeshimadded: false, revealtimers: {},

getposOffset:function(what, offsettype){
	var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop-2;
	var parentEl=what.offsetParent;
	while (parentEl!=null){
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
},

css:function(el, targetclass, action){
	var needle=new RegExp("(^|\\s+)"+targetclass+"($|\\s+)", "ig")
	if (action=="check")
		return needle.test(el.className)
	else if (action=="remove")
		el.className=el.className.replace(needle, "")
	else if (action=="add" && !needle.test(el.className))
		el.className+=" "+targetclass
},

showmenu:function(dropmenu, e){
	if (this.enablereveal[0]){
		if (!dropmenu._trueheight || dropmenu._trueheight<10)
			dropmenu._trueheight=dropmenu.offsetHeight
		clearTimeout(this.revealtimers[dropmenu.id])
		dropmenu.style.height=dropmenu._curheight=0
		dropmenu.style.overflow="hidden"
		dropmenu.style.visibility="visible"
		this.revealtimers[dropmenu.id]=setInterval(function(){cssdropdown.revealmenu(dropmenu)}, 10)
	}
	else{
		dropmenu.style.visibility="visible"
	}
	this.css(this.asscmenuitem, "selected", "add")
},

revealmenu:function(dropmenu, dir){
	var curH=dropmenu._curheight, maxH=dropmenu._trueheight, steps=this.enablereveal[1]
	if (curH<maxH){
		var newH=Math.min(curH, maxH)
		dropmenu.style.height=newH+"px"
		dropmenu._curheight= newH + Math.round((maxH-newH)/steps) + 1
	}
	else{ //if done revealing menu
		dropmenu.style.height="auto"
		dropmenu.style.overflow="hidden"
		clearInterval(this.revealtimers[dropmenu.id])
	}
},

clearbrowseredge:function(obj, whichedge){
	var edgeoffset=0
	if (whichedge=="rightedge"){
		var windowedge=document.all && !window.opera? this.standardbody.scrollLeft+this.standardbody.clientWidth-15 : window.pageXOffset+window.innerWidth-15
		var dropmenuW=this.dropmenuobj.offsetWidth
		if (windowedge-this.dropmenuobj.x < dropmenuW)  //move menu to the left?
			edgeoffset=dropmenuW-obj.offsetWidth
	}
	else{
		var topedge=document.all && !window.opera? this.standardbody.scrollTop : window.pageYOffset
		var windowedge=document.all && !window.opera? this.standardbody.scrollTop+this.standardbody.clientHeight-15 : window.pageYOffset+window.innerHeight-18
		var dropmenuH=this.dropmenuobj._trueheight
		if (windowedge-this.dropmenuobj.y < dropmenuH){ //move up?
			edgeoffset=dropmenuH+obj.offsetHeight
			if ((this.dropmenuobj.y-topedge)<dropmenuH) //up no good either?
				edgeoffset=this.dropmenuobj.y+obj.offsetHeight-topedge
		}
	}
	return edgeoffset
},

dropit:function(obj, e, dropmenuID){
	if (this.dropmenuobj!=null) //hide previous menu
		this.hidemenu() //hide menu
	this.clearhidemenu()
	this.dropmenuobj=document.getElementById(dropmenuID) //reference drop down menu
	this.asscmenuitem=obj //reference associated menu item
	this.showmenu(this.dropmenuobj, e)
	this.dropmenuobj.x=this.getposOffset(obj, "left")
	this.dropmenuobj.y=this.getposOffset(obj, "top")
	this.dropmenuobj.style.left=this.dropmenuobj.x-this.clearbrowseredge(obj, "rightedge")+"px"
	this.dropmenuobj.style.top=this.dropmenuobj.y-this.clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+1+"px"
	this.positionshim() //call iframe shim function
},

positionshim:function(){ //display iframe shim function
	if (this.iframeshimadded){
		if (this.dropmenuobj.style.visibility=="visible"){
			this.shimobject.style.width=this.dropmenuobj.offsetWidth+"px"
			this.shimobject.style.height=this.dropmenuobj._trueheight+"px"
			this.shimobject.style.left=parseInt(this.dropmenuobj.style.left)+"px"
			this.shimobject.style.top=parseInt(this.dropmenuobj.style.top)+"px"
			this.shimobject.style.display="block"
		}
	}
},

hideshim:function(){
	if (this.iframeshimadded)
		this.shimobject.style.display='none'
},

isContained:function(m, e){
	var e=window.event || e
	var c=e.relatedTarget || ((e.type=="mouseover")? e.fromElement : e.toElement)
	while (c && c!=m)try {c=c.parentNode} catch(e){c=m}
	if (c==m)
		return true
	else
		return false
},

dynamichide:function(m, e){
	if (!this.isContained(m, e)){
		this.delayhidemenu()
	}
},

delayhidemenu:function(){
	this.delayhide=setTimeout("cssdropdown.hidemenu()", this.disappeardelay) //hide menu
},

hidemenu:function(){
	this.css(this.asscmenuitem, "selected", "remove")
	this.dropmenuobj.style.visibility='hidden'
	this.dropmenuobj.style.left=this.dropmenuobj.style.top="-1000px"
	this.hideshim()
},

clearhidemenu:function(){
	if (this.delayhide!="undefined")
		clearTimeout(this.delayhide)
},

addEvent:function(target, functionref, tasktype){
	if (target.addEventListener)
		target.addEventListener(tasktype, functionref, false);
	else if (target.attachEvent)
		target.attachEvent('on'+tasktype, function(){return functionref.call(target, window.event)});
},

startchrome:function(){
	if (!this.domsupport)
		return
	this.standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body
	for (var ids=0; ids<arguments.length; ids++){
		var menuitems=document.getElementById(arguments[ids]).getElementsByTagName("a")
		for (var i=0; i<menuitems.length; i++){
			if (menuitems[i].getAttribute("rel")){
				var relvalue=menuitems[i].getAttribute("rel")
				var asscdropdownmenu=document.getElementById(relvalue)
				this.addEvent(asscdropdownmenu, function(){cssdropdown.clearhidemenu()}, "mouseover")
				this.addEvent(asscdropdownmenu, function(e){cssdropdown.dynamichide(this, e)}, "mouseout")
				this.addEvent(asscdropdownmenu, function(){cssdropdown.delayhidemenu()}, "click")
				try{
					menuitems[i].innerHTML=menuitems[i].innerHTML+" "+this.dropdownindicator
				}catch(e){}
				this.addEvent(menuitems[i], function(e){ //show drop down menu when main menu items are mouse over-ed
					if (!cssdropdown.isContained(this, e)){
						var evtobj=window.event || e
						cssdropdown.dropit(this, evtobj, this.getAttribute("rel"))
					}
				}, "mouseover")
				this.addEvent(menuitems[i], function(e){cssdropdown.dynamichide(this, e)}, "mouseout") //hide drop down menu when main menu items are mouse out
				this.addEvent(menuitems[i], function(){cssdropdown.delayhidemenu()}, "click") //hide drop down menu when main menu items are clicked on
			}
		} //end inner for
	} //end outer for
	if (this.enableiframeshim && document.all && !window.XDomainRequest && !this.iframeshimadded){ //enable iframe shim in IE5.5 thru IE7?
		document.write('<IFRAME id="iframeshim" src="about:blank" frameBorder="0" scrolling="no" style="left:0; top:0; position:absolute; display:none;z-index:90; background: transparent;"></IFRAME>')
		this.shimobject=document.getElementById("iframeshim") //reference iframe object
		this.shimobject.style.filter='progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)'
		this.iframeshimadded=true
	}
} //end startchrome

}