
function keywordpresent() {

if (document.getElementById('keywordin').value==null||document.getElementById('keywordin').value=="")
    {
    alert("Enter Keyword for Search");
    }
  else
    {
   document.forms["gsearch"].submit();

	}}




function switchlogin() {
 
 var element=document.getElementById('loginframe');
 if(element.className.indexOf("showx")!= -1){
 
 newClass = element.className.replace("showx","hidex");}
                                       else{
									   
									   newClass = element.className.replace("hidex","showx");}
		element.className = newClass;
var element=document.getElementById('loginframe2');
 if(element.className.indexOf("showx")!= -1){
 
 newClass = element.className.replace("showx","hidex");}
                                       else{
									   
									   newClass = element.className.replace("hidex","showx");}
		element.className = newClass;		

	
		}



function switchsearch() {
createCookie('menu','cats',30);
 var element=document.getElementById('selectionframe');
 if(element.className.indexOf("show")!= -1){newClass = element.className.replace("show","hide");}
                                       else{newClass = element.className.replace("hide","show");}
		element.className = newClass;

var element3=document.getElementById('frame');
if(element3.className.indexOf("show")!= -1)	{newClass3 = element3.className.replace("show","hide");	
		                                     element3.className = newClass3;}		

										 
		}
		
function switchsearchback() {
createCookie('menu','pop',30);
 var element=document.getElementById('frame');
 if(element.className.indexOf("show")!= -1){newClass = element.className.replace("show","hide");}
                                       else{newClass = element.className.replace("hide","show");}
		element.className = newClass;

var element3=document.getElementById('selectionframe');
if(element3.className.indexOf("show")!= -1)	{newClass3 = element3.className.replace("show","hide");	
		                                     element3.className = newClass3;}		

										 
		}




function PostCodeEntry(e)
{
if(window.event) // IE
	{
	var myTextField = document.getElementById('myPostcode');
	keynum = e.keyCode
	}
	
else if(e.which) // Netscape/Firefox/Opera
	{
	var myTextField = document.getElementById('myPostcode');
	keynum = e.which
	}
	keychar = String.fromCharCode(keynum)
	var name =  "postcode=";
	var date = new Date();
	date.setTime(date.getTime()+(30*24*60*60*1000));
	var expires = "; expires="+date.toGMTString();
	var value = myTextField.value + keychar
	
	if(checkPostCode(value)!= false){	
	document.cookie = name+value+expires+"; path=/";
	document.cookie = "valpostcode=valid"+expires+"; path=/";
	}
	else {	document.cookie = "valpostcode=invalid"+expires+"; path=/";	}
	var nameEQ = "postcode=";
	var ca = document.cookie.split(';');
	}
	
function PostCodeEntry2(e) {
var myTextField = document.getElementById('myPostcode');
var name =  "postcode=";
	var date = new Date();
	date.setTime(date.getTime()+(30*24*60*60*1000));
	var expires = "; expires="+date.toGMTString();
	var value = myTextField.value 
	if(myTextField.value != "") {
	if(checkPostCode(value)!= false){	
	document.cookie = name+value+expires+"; path=/";
	document.cookie = "valpostcode=valid"+expires+"; path=/";
	}
	else {	document.cookie = "valpostcode=invalid"+expires+"; path=/";	}

} else {
eraseCookie("postcode");
eraseCookie("valpostcode");
}
	}
	
	

function CreateBookmarkLink() {
title = "AllAboutGoingOut.com"; 
url = "http://www.allaboutgoingout.com";
	if (window.sidebar) { // Mozilla Firefox Bookmark
		alert("To Bookmark this page , OK this message, then press Control + D");
	}else if( window.external ) { // IE Favorite
		window.external.AddFavorite(location.href, title);
	}else if(window.opera && window.print) { // Opera Hotlist
		return true;
	}
 }
function fixWidth(){
alert("fixwidth");
	if(!document.getElementById('header'))return false;
	if(!document.getElementById('entries'))return false;
	
	var widthY = document.getElementById('header').clientWidth;
	alert (widthY);
	widthY=widthY-333;
	if(widthY < 1) {widthY=600;}
	
	document.getElementById('entries').style.width=widthY+'px';
	alert(document.getElementById('header').clientWidth);
}
function showLocalImage(imgname,id) {
	imgname = imgname.replace(/\\/g,"/");
	imgname = imgname.replace(/\'/g,"\\'");
	var element = document.getElementById(id);
	element.src = imgname;
}
function prepareResults(){
//alert(document.body.offsetParent.clientWidth);
	if(document.getElementById("entries")){
		var entries = document.getElementById("entries");
		var myDivs = entries.getElementsByTagName("DIV");
		for (i = 0; i < myDivs.length; i++) {
			var thisDiv = myDivs[i];
			if(thisDiv.className.indexOf("subFirst")!=-1){
				var myLists = thisDiv.getElementsByTagName("UL");
				var myList = myLists[0];
				var firstLI = myLists[0].getElementsByTagName("LI")[0];
				//alert(firstLI.nodeName);
				txt = document.createTextNode("Multiple Dates for this Event");
				var listItem = document.createElement("LI");
				var myAnchor = document.createElement("A");
				myAnchor.appendChild(txt);
				myAnchor.setAttribute("HREF","#");
				myAnchor.className="moreEntries";
				myAnchor.onclick=function(){showResults(this)};
				listItem.appendChild(myAnchor);
				myList.appendChild(listItem);if(document.URL.indexOf("Advertiser") != -1 ) {showResults(myAnchor);}
				//myList.insertBefore(listItem,firstLI);
			}
		}
		//alert(document.body.clientWidth);
		//entries.style.width='400px';
	}
}
function showResults(element){
	var myDiv=element;
	var myAnchorText=element.childNodes[0];
	if(element.innerHTML.indexOf("show")!=-1){
		myAnchorText.nodeValue="Multiple Dates for this Event - click to remove";
	}else{
		myAnchorText.nodeValue="Multiple Dates for this Event";
	}
	while(myDiv.className.indexOf("subFirst")==-1){
		myDiv=myDiv.parentNode;
	}
	var start = myDiv.id.indexOf("set");
	var end = myDiv.id.indexOf("_");
	var divId = myDiv.id.substring(start,end+1);
	var entries = document.getElementById("entries");
	var myDivs = entries.getElementsByTagName("DIV");
	for (i = 0; i < myDivs.length; i++) {
		var thisDiv = myDivs[i];
		if(thisDiv.id.indexOf(divId)!=-1){
			if(thisDiv.className.indexOf("subDupOn")!=-1){
				var newClass = thisDiv.className.replace("subDupOn","subDupOff");
				thisDiv.className = newClass;
			}else if(thisDiv.className.indexOf("subDupOff")!=-1){
				var newClass = thisDiv.className.replace("subDupOff","subDupOn");
				thisDiv.className = newClass;		
			}
		}
	}
	//entries.style.marginLeft='176px';
	//alert(document.getElementById("entries").style.marginRight);
}
function buttons(id){
	var mydiv = document.getElementById(id);
	var imgs = document.getElementsByTagName("img");
	for(var i=0;i<imgs.length;i++){
		img = imgs[i];
		if(img.className.indexOf("btn")!= -1){
		var dummyImg = new Image();
		dummyImg.src = img.src.replace("_f1","_f2");
			img.onmouseover = function(){
				 var newSrc = this.src.replace("_f1","_f2");
				 this.src = newSrc;
			}
			img.onmouseout = function(){
				 var newSrc = this.src.replace("_f2","_f1");
				 this.src = newSrc;
			}

		}
	}
	var imgs = document.getElementsByTagName("input");
	for(var i=0;i<imgs.length;i++){
		img = imgs[i];
		if(img.className.indexOf("btn")!= -1){
			var dummyImg = new Image();
			dummyImg.src = img.src.replace("_f1","_f2");
			img.onmouseover = function(){
				 var newSrc = this.src.replace("_f1","_f2");
				 this.src = newSrc;
			}
			img.onmouseout = function(){
				 var newSrc = this.src.replace("_f2","_f1");
				 this.src = newSrc;
			}
		var dummyImg = new Image();
		dummyImg.src = img.src;
		}
	}
}
function initButtons(){
	buttons("mainNav");
	buttons("search");
	buttons("signon");
	buttons("itineraryBtns");
	if(document.getElementById("nlSubmit"))buttons("nlSubmit");
}
function maxlen(element){
	var end = element.className.length;
	var start = element.className.indexOf("maxlen");
	var maxlen = element.className.substring(start+6,end);
	if(element.value.length>maxlen){
		alert("Exceeded maximum length for this field");
		var newVal = element.value.substring(0,maxlen);
		element.value = newVal;
	}
}

function clear(thisid){
	var element = document.getElementById(thisid);
	var inputs = element.getElementsByTagName("INPUT");
	for(var i=0;i<inputs.length;i++){
		if(inputs[i].type=="text")
			inputs[i].value="";
		if(inputs[i].type=="radio")
			inputs[i].checked=false;	
	}
	var selects = element.getElementsByTagName("SELECT");
	for(var i=0;i<selects.length;i++){
			selects[i].selectedIndex=0;
	}	
}
function blankout(thisid,element){
	if(element.toString()=="")return false;
	var element = document.getElementById(thisid);
	if(element.nodeName=="INPUT")element.value="";
	else if(element.nodeName=="SELECT"){
		element.options[0].selected=true;
	}
}
function directions(link,saddr,daddr){
	if (saddr==""){
		 var saddr = prompt("What location (town / postcode) will you be leaving from?");
	}
	if (saddr!==null && saddr!=""){
		address="http://maps.google.co.uk/maps?daddr="+daddr+"&saddr="+saddr;
		//link.setAttribute("target","_blank");
		//link.setAttribute("href",address);
		//
		//
		document.open(address,'_blank','fullscreen=no,scrollbars = yes,titlebar =no,resizable =yes,menubar =no,width=750px,height=600px,toolbar=no');
	}else{
		return false;
	}
}function weblink(address){				document.open(address,'_blank','fullscreen=no,scrollbars = yes,titlebar =no,resizable =yes,menubar =no,width=750px,height=600px,toolbar=no');	}
function refreshPostcode(){
	if(document.getElementById("myPostcode")){
		var thisPostcode = document.getElementById("myPostcode");
		var cookieVal = readCookie('postcode');
		if(cookieVal==null){
			//alert("null cookie");
		}else{
			//alert(readCookie('postcode'));
			thisPostcode.value=cookieVal.replace("+"," ");
		}
	}
}
function setFormAction(id,value){
if(!document.getElementById("search")) return false;

	var search = document.getElementById("search");
	var destination = search.getAttribute('action');
	if(value!=""){
		var newItem = id+"="+value;
	}else{
		var newItem = "";	
	}
	if(destination.indexOf(id)!=-1){
		var items = destination.split(new RegExp( "[?&]{1}", "g" ));
		for(var i=0;i<items.length;i++){
			if(items[i].indexOf(id)!=-1){
				var newDest = destination.replace(items[i],newItem);
			}
		}
	}else{
		if(destination.indexOf("?")==-1){
			destination = destination+"?";
		}
		if(destination.length-destination.indexOf("?")>1){
			destination = destination+"&";
		}
		var newDest = destination + newItem;
	}
	if(newDest.lastIndexOf("&")==(newDest.length-1)){
		newDest = newDest.slice(0,-1);
	}
	search.setAttribute("action",newDest);
}
function createCookie(name,value,days) {
	var name = name + "=";
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+value+expires+"; path=/";
}
function appendCookie(name,value,element) {
	if(readCookie(name)!= null){
		var currentValue = unescape(readCookie(name));
		var newValue = "";
		var values = currentValue.split(',');
		var found = false;
		for(var i=0;i<values.length;i++){
			if(values[i]==value){
				found=true;
			}else{
				if(newValue==""){
					newValue=newValue+values[i];
				}else{
					newValue=newValue+","+values[i];
				}
			}
		}
		if(found==false){
			newValue=newValue+','+value;
			createCookie(name,newValue,30);
			element.src="assets/itineryMinus.gif";
			element.setAttribute("title","Remove this entry from your Itinerary");
		}else{
			createCookie(name,newValue,30);
			element.src="assets/itinery.gif";
			element.setAttribute("title","Add this entry to your Itinerary");		
		}
	}else{
		createCookie(name,value,30);
		element.src="assets/itineryMinus.gif";
		element.setAttribute("title","Remove this entry from your Itinerary");
	}
}
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name){
	createCookie(name,"",-1);
}

function screenWidth(){
	if(window.innerWidth){
		myWidth=window.innerWidth;
	}else if(document.documentElement.clientWidth){
		var myWidth=document.documentElement.clientWidth;
	}else if(document.body.clientWidth){
		var myWidth=document.body.clientWidth;
	}else{
		myWidth=800;
	}
	return myWidth;
}
function moveResultsCount(){
	if(document.getElementById("nbrResults")&&document.getElementById("newResults")){;
		if(screenWidth()>1000){
			var results = document.getElementById("nbrResults");
			var newResults = document.getElementById("newResults");
			newResults.childNodes[0].nodeValue = results.childNodes[0].nodeValue;
			newResults.className = "show";
			results.className = "shrink";
		}
	}
}
function beforeToday(dateStr) {
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
	
	var matchArray = dateStr.match(datePat); // is the format ok?
	if (matchArray == null) {
		alert("Date is not in a valid format.")
		return false;
	}
	month = matchArray[3]; // parse date into variables
	month=month-1;
	day = matchArray[1];
	year = matchArray[4];
	var myDate=new Date();
	myDate.setFullYear(year,month,day);
	
	var today = new Date();
	
	if (myDate<today){
		return true;
	}else{
		return false;  // date is valid
	}
}
function exceedsYear(dateStr) {
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
	
	var matchArray = dateStr.match(datePat); // is the format ok?
	if (matchArray == null) {
		alert("Date is not in a valid format.")
		return false;
	}
	month = matchArray[3]; // parse date into variables
	month=month-1;
	day = matchArray[1];
	year = matchArray[4];
	var myDate=new Date();
	myDate.setFullYear(year,month,day);
	
	var nextYear = new Date();
	nextYear.setDate(nextYear.getDate()+365);
	
	if (myDate>nextYear){
		return true;
	}else{
		return false;  // date is valid
	}
}
function fromBeforeTo(dateStr1,dateStr2) {
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
	
	var matchArray1 = dateStr1.match(datePat); // is the format ok?
	var matchArray2 = dateStr2.match(datePat); // is the format ok?
	
	if (matchArray1 == null||matchArray2 == null) {
		alert("Date is not in a valid format.")
		return false;
	}
	month1 = matchArray1[3]; // parse date into variables
	month1=month1-1;
	day1 = matchArray1[1];
	year1 = matchArray1[4];
	var myDate1=new Date();
	myDate1.setFullYear(year1,month1,day1);

	month2 = matchArray2[3]; // parse date into variables
	month2=month2-1;
	day2 = matchArray2[1];
	year2 = matchArray2[4];
	var myDate2=new Date();
	myDate2.setFullYear(year2,month2,day2);	
	
	if (myDate1>myDate2){
		return true; // fromdate is before todate
	}else{
		return false;  
	}
}
function isValidDate(dateStr) {
	// Checks for the following valid date formats:
	// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
	// Also separates date into month, day, and year variables
	
	//var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;
	
	// To require a 4 digit year entry, use this line instead:
	 var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
	
	var matchArray = dateStr.match(datePat); // is the format ok?
	if (matchArray == null) {
		alert("Date is not in a valid format."+dateStr)
		return false;
	}
	month = matchArray[3]; // parse date into variables
	day = matchArray[1];
	year = matchArray[4];
	if (month < 1 || month > 12) { // check month range
		alert("Month must be between 1 and 12.");
		return false;
	}
	if (day < 1 || day > 31) {
		alert("Day must be between 1 and 31.");
		return false;
	}
		if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		alert("Month "+month+" doesn't have 31 days!")
		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)) {
			alert("February " + year + " doesn't have " + day + " days!");
			return false;
	   }
	}
	return true;  // date is valid
}
function submitForm(){
	if(!document.getElementById("search"))return false;
	document.getElementById("search").submit();
}
function uncheckRadios(object){
	var myForm = document.getElementById(object);
	var elements = myForm.getElementsByTagName("INPUT");
	for(var i=0;i<elements.length;i++){
		var element = elements[i];
		if(element.className.indexOf("radio") != -1){
			element.checked = false;
		}
	}
}
function contactAd(advertiserId,org,subid,defaultMessage){
	var myForms = document.getElementsByTagName("FORM");
	for(var i=0;i<myForms.length;i++){
		var thisForm = myForms[i];
		if(thisForm.id.indexOf("contactAdv")!=-1||thisForm.id.indexOf("contactUs")!=-1){
			if(thisForm.adId)thisForm.adId.value = advertiserId;
			if(thisForm.subId)thisForm.subId.value = subid;
			if(thisForm.orgName)thisForm.orgName.value = org;
			if(document.getElementById("orgNm")){
			//var orgNm = document.getElementById("orgNm");
			//orgNm.childNodes[0].nodeValue = org;
			}
			if(defaultMessage){
				thisForm.userMessage.value = defaultMessage;
			}
		}
	}
}
function sendEntries(title,entries,eventTitle){
	if(document.getElementById("sendTitle")){
		var sendTitle = document.getElementById("sendTitle");
		sendTitle.firstChild.nodeValue = title;
		var thisForm = document.getElementById("sendToFriend");
		thisForm.entries.value = entries;
		thisForm.sendTitle.value = title;
		
	}
	if(document.getElementById("evtTitle")){
		var evtTitle = document.getElementById("evtTitle");
		if(eventTitle.length>1){
			evtTitle.nodeValue = eventTitle;
			thisForm.evtTitle.value = eventTitle;
		}
	}
} 
function toggle(elem,classFrom,classTo,evt){
	if(document.getElementById("admin")){
	var mySelects = document.getElementsByTagName("SELECT");
	for(var i=0;i<mySelects.length;i++){
		var element=mySelects[i];
		if(element.className.indexOf("hide")!= -1){
			newClass = element.className.replace("hide","");
			element.className = newClass;
		}else{
			newClass = element.className+" hide";
			element.className = newClass;
		}		
	}
	}
	if(document.getElementById(elem)){
		var element=document.getElementById(elem);
		if(evt){
			var posX = evt.clientX+30+"px";
			var posY = evt.clientY+"px";
			element.style.left = posX;
			element.style.top = posY;
		}
		if(element.className.indexOf(classFrom)!= -1){
			newClass = element.className.replace(classFrom,classTo);
			element.className = newClass;
		}else{
			newClass = element.className.replace(classTo,classFrom);
			element.className = newClass;
		}
	}
}
function hide(elem){
	document.getElementById(elem).className="hide";
}

function addLoadEvent(func) {

  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function setDates(period){
	if(period=="today"){
		var fromDt = new Date();
		var day = fromDt.getDate();
		var month = fromDt.getMonth()+1;
		var year = fromDt.getFullYear();
		fromDt = day+"/"+month+"/"+year;
		toDt = "";
	}
	if(period=="tomorrow"){
		var fromDt = new Date();
		fromDt.setDate(fromDt.getDate()+1);
		var day = fromDt.getDate();
		var month = fromDt.getMonth()+1;
		var year = fromDt.getFullYear();
		fromDt = day+"/"+month+"/"+year;
		toDt = "";
	}
	if(period=="week"){
		var fromDt = new Date();
		var toDt = new Date();
		toDt.setDate(toDt.getDate()+6);
		var day = fromDt.getDate();
		var month = fromDt.getMonth()+1;
		var year = fromDt.getFullYear();
		fromDt = day+"/"+month+"/"+year;
		day = toDt.getDate();
		month = toDt.getMonth()+1;
		year = toDt.getFullYear();	
		toDt = day+"/"+month+"/"+year;			
	}
	if(period=="month"){
		var fromDt = new Date();
		var toDt = new Date();
		toDt.setDate(toDt.getDate()+28);
		var day = fromDt.getDate();
		var month = fromDt.getMonth()+1;
		var year = fromDt.getFullYear();
		fromDt = day+"/"+month+"/"+year;
		day = toDt.getDate();
		month = toDt.getMonth()+1;
		year = toDt.getFullYear();	
		toDt = day+"/"+month+"/"+year;			
	}
	//alert(document.getElementById("fromdate").value);
	document.getElementById("fromdate1").value = fromDt;
	document.getElementById("todate1").value = toDt;
}
function confirmExit(){
    if (needToConfirm.flag){
		needToConfirm.flag=false;
		for (var i=0;i<document.forms.length;i++){
			var thisform=document.forms[i];
			if(thisform.className.indexOf("savedata")!=-1){
				for(var l=0;l<thisform.elements.length;l++){
					var element = thisform.elements[l];
					if(element.type=="checkbox"){
						if(needToConfirm[element.name]!=element.checked)
							needToConfirm.flag=true;
					}else{
						if(needToConfirm[element.name]!=element.value)
							needToConfirm.flag=true;					
					}
					//alert(needToConfirm[element.name]+":"+element.value);
				}
			}
		}
		if(needToConfirm.flag){
			return "You have made changes that have yet to be saved";
		}else{
			return;
		}
    }
}
function prepareForms(){
	for (var i=0;i<document.forms.length;i++){
		var thisform=document.forms[i];
		if(thisform.className.indexOf("savedata")!=-1){
			needToConfirm = new Object();
			needToConfirm.flag = true;
			window.onbeforeunload = confirmExit;
		}
		thisform.onsubmit = function(){
			return validateForm(this);
		}
		for(var l=0;l<thisform.elements.length;l++){
			var element = thisform.elements[l];
			if(thisform.className.indexOf("savedata")!=-1){
				if(element.type=="checkbox"){
					needToConfirm[element.name]=element.checked;
				}else{
					needToConfirm[element.name]=element.value;
				}
			}
			if(element.className.indexOf("delete") != -1){
				element.onclick = function(){
					return checkDelete();
				}			
			}
			if(element.className.indexOf("defaultText") != -1){
				if(element.value != ""){
					var curClass = element.className;
					curClass=curClass.replace(/defaultText/,"");
					element.className = curClass;		
				}
				element.onfocus = function(){
						var curClass = this.className;
						curClass=curClass.replace(/defaultText/,"");
						this.className = curClass;
				}
				element.onblur = function(){
					if(this.value == ""){
						var curClass = this.className;
						curClass=curClass+" "+"defaultText";
						this.className = curClass;
					}
				}			
			}
			if(element.className.indexOf("maxlen") != -1){
				if(element.tagName=="INPUT"){
					element.onkeyup = function(){
						 maxlen(this);
					}	
				}
				if(element.tagName=="TEXTAREA"){
					element.onkeydown = function(){
						 maxlen(this);
					}	
				}				
			}			
		}
	}
	/*if(document.getElementById("catz")){
		var categories=document.getElementById("catz");
		if(document.getElementsByTagName){
			var divs = categories.getElementsByTagName("DIV");
			for(var j=0;j<divs.length;j++){
				var element = divs[j];
				if(element.className.indexOf("cat") != -1){
					if(element.getAttribute("class")){
						element.setAttribute("class","cat hide");
					}else{
						element.className="cat hide";
					}
				}
			}
			var newDiv = document.createElement("DIV");
			var newAnchor=document.createElement("A");
			if(newAnchor.className="moreCatz"){
			
			}else{
				newAnchor.setAttribute("class","moreCatz");
			}
			var txt=document.createTextNode("Show more categories");
			newAnchor.appendChild(txt);
			newAnchor.onclick = function(){
				for(var k=0;k<divs.length;k++){
					var element = divs[k];
					if(element.className.indexOf("cat hide") != -1){
						if(element.getAttribute("class")){
							element.setAttribute("class","cat");
						}else{
							element.className="cat";
						}
					}
				}
				categories.removeChild(newDiv);
			}
			newDiv.appendChild(newAnchor);
			categories.appendChild(newDiv);
		}
	}*/
}
function resetFields(whichform){
	for(var i=0;i<whichform.elements.length;i++){
		var element = whichform.elements[i];
		if(element.type== "submit") continue;
		if(element.tagName== "SELECT") continue;
		if(element.value != ""){
			var curClass = element.className;
			curClass=curClass.replace(/defaultText/,"");
			element.className = curClass;		
		}
		element.onfocus = function(){
				var curClass = this.className;
				curClass=curClass.replace(/defaultText/,"");
				this.className = curClass;
		}
		element.onblur = function(){
			if(this.value == ""){
				var curClass = this.className;
				curClass=curClass+" "+"defaultText";
				this.className = curClass;
			}
		}
	}
}
function prepareTextareas(){
	var textareas = document.getElementsByTagName("textarea");
	for(var j=0;j<textareas.length;j++){
		var textarea = textareas[j];
		var maxSize = textarea.getAttribute("maxsize")?textarea.getAttribute("maxsize"):500;
		textarea.onkeyup = function(){
			return counterUpdate(textarea.id, 'countBody', maxSize)
		}
	}
}
function counterUpdate(opt_countedTextBox, opt_countBody, opt_maxSize) {
        var countedTextBox = opt_countedTextBox ? opt_countedTextBox : "counttxt";
        var countBody = opt_countBody ? opt_countBody : "countBody";
        var maxSize = opt_maxSize ? opt_maxSize : 500;

        var field = document.getElementById(countedTextBox);

        if (field && field.value.length >= maxSize) {
                field.value = field.value.substring(0, maxSize);
        }
        var txtField = document.getElementById(countBody);
                if (txtField) { 
                txtField.innerHTML = maxSize - field.value.length;
        }
}
function reveal(elem){
	while (elem.nodeName != 'BODY'){
		if(elem.className.indexOf("hide")!= -1){
			elem.className="show";
		}
		elem=elem.parentNode;
	}
}
function checkDelete(){
	var where=confirm("Are you sure you want to delete?");
	if (!where){
		return false;
	}
	if (where){
		return true;
	}
}

function validateForm(myForm){
	if(myForm.className.indexOf("savedata")!=-1){
		needToConfirm.flag = false;
	}
	for(var i=0;i<myForm.elements.length;i++){
		var element = myForm.elements[i];
		if(element.className.indexOf("dataCapture") != -1&&element.className.indexOf("email") == -1&&element.className.indexOf("web") == -1&&element.className.indexOf("image") == -1){
			if(isFilled(element)){
				var myWords = new Array();
				myWords = element.value.split(" ");
				for(j=0;j<myWords.length;j++){
					if(myWords[j].length>50){
						alert(element.title+" - contains a word longer than 50 characters - please amend");
						return false;
					}
				}
			}
		}
	}
	for(var i=0;i<myForm.elements.length;i++){
		var element = myForm.elements[i];
		if(element.className.indexOf("required") != -1){
			if(!isFilled(element)){
				myElementName = element.name.replace("fm_","");
				myElementName = myElementName.replace("_"," ");
				alert("Please enter a  "+myElementName+" for your Activity/Event");
				var myDiv = element.parentNode;
				var myLabels = myDiv.getElementsByTagName("LABEL");
				if(myLabels.length==1) myLabels[0].className+=" error";
				return false;
			}
		}
		if(element.className.indexOf("ostcode") != -1){
			if(isFilled(element)){
				if(!checkPostCode(element.value)){
					myElementName = element.name.replace("fm_","");
					myElementName = myElementName.replace("_"," ");
					alert("Please enter a valid post code");
					var myDiv = element.parentNode;
					var myLabels = myDiv.getElementsByTagName("LABEL");
					if(myLabels.length==1) myLabels[0].className+=" error";
					return false;
				}
			}
		}
		if(element.className.indexOf("email") != -1){
			if(isFilled(element)){
				if(!IsEmail(element)){
					myElementName = element.name.replace("fm_","");
					myElementName = myElementName.replace("_"," ");
					alert("The email address you have entered is incorrectly formatted");
					var myDiv = element.parentNode;
					var myLabels = myDiv.getElementsByTagName("LABEL");
					if(myLabels.length==1) myLabels[0].className+=" error";
					return false;
				}
			}
		}
		if(element.className.indexOf("numeric") != -1){
			if(!IsNumeric(element)){
				myElementName = element.name.replace("fm_","");
				myElementName = myElementName.replace("_"," ");
				alert("Please input only numbers in the  "+myElementName+" field");
				var myDiv = element.parentNode;
				var myLabels = myDiv.getElementsByTagName("LABEL");
				if(myLabels.length==1) myLabels[0].className+=" error";
				return false;
			}
		}
		if(element.className.indexOf("web") != -1){
			if(isFilled(element)){
				if(!IsURL(element)){
					myElementName = element.name.replace("fm_","");
					myElementName = myElementName.replace("_"," ");
					alert("The web site adderess you have entered is incorrectly formatted");
					var myDiv = element.parentNode;
					var myLabels = myDiv.getElementsByTagName("LABEL");
					if(myLabels.length==1) myLabels[0].className+=" error";
					return false;
				}
			}
		}
		if(element.className.indexOf("fromdate") != -1){
			if(isFilled(element)){
				if(!isValidDate(element.value)){
					reveal(element);
					element.focus();
					return false;
				}else{
					var fromdate = element;
				}
			}
		}
		if(element.className.indexOf("todate") != -1){
			if(isFilled(element)){
				if(!isValidDate(element.value)){
					reveal(element);
					element.focus();
					return false;
				}else{
					var todate = element;
				}
			}
		}
		if(element.form.name.indexOf("searchPrefs") != -1){
			if(document.getElementById("formCatId")&&document.getElementById("formSubCatId")){
				var formCatId = document.getElementById("formCatId");
				var formSubCatId = document.getElementById("formSubCatId");
				if((formCatId.value==""||formCatId.value=="%")&&(formSubCatId.value==""||formSubCatId.value=="%")){
					alert("Please select a category first");
					return false;
				}
			}
		}
		if(element.className.indexOf("setPostcode") != -1){
			if(isFilled(element)){
				createCookie("postcode",element.value,30);
			}else{
				eraseCookie("postcode");
			}
		}		
		if(element.className.indexOf("postcode") != -1){
			if(isFilled(element)){
				//createCookie("postcode",element.value,30);
				var postcodeSet = element;
			}
		}
		if(element.className.indexOf("contactEmail") != -1){
			if(isFilled(element)){
				createCookie("contactEmail",element.value,30);
			}
		}
		if(element.className.indexOf("radius") != -1){
			if(isFilled(element)){
				var radiusSet = element;
			}
		}
		if(element.className.indexOf("town") != -1){
			if(isFilled(element)){
				var townSet = element;
			}
		}
	}
	if(postcodeSet&&townSet){
		reveal(postcodeSet);
		var where=confirm("You have selected both postcode and town, click 'OK' to use postcode or click 'Cancel' to use town");
		if (!where){
			postcodeSet.value="";
		}
		if (where){
			townSet.value="";
		}
	}else if(townSet){
		setFormAction("townId",townSet.value);
	}else if(postcodeSet){
		setFormAction("townId",pc2town(postcodeSet.value));
	}else{
		setFormAction("townId","");
	}
	if((fromdate&&fromdate.id=="fromdate1")||(todate&&todate.id=="todate1")){
		if(fromdate.value&&exceedsYear(fromdate.value)){
			alert("You have entered a date of "+fromdate.value+". Events and Activities are  contained within AllAboutGoingOut.com for up to 12 months ahead");
		}else{
			if(todate&&exceedsYear(todate.value))alert("You have entered a date of "+todate.value+". Events and Activities are contained within AllAboutGoingOut.com for up to 12 months ahead");
		}
	}
	if(fromdate&&todate){
		if(beforeToday(fromdate.value)&&beforeToday(todate.value)){
			alert("Invalid date range: both before today");
			reveal(fromdate);
			return false;
		}
		if (fromBeforeTo(fromdate.value,todate.value)) {
			alert("Invalid Date Range!\nStart Date cannot be after End Date!")
			return false;
		}
	}else if(fromdate){
		if(beforeToday(fromdate.value)){
			alert("You have entered a past date, please re-enter");
			reveal(fromdate);
			return false;
		}
	}

}
function isFilled(field){
	if(field.type=="textarea"){
		if(field.value.length <1 ){
			return false;
		}
	}
	if(field.type=="text"){
		if(field.value.length <1 ){
			return false;
		}
	}
	if(field.type=="checkbox"){
		if(field.checked== false){
			return false;
		}
	}
	if(field.type=="select-one"){
		if(field.selectedIndex== false){
			return false;
		}
	}
	if(field.type=="file"){
		if(field.value.length <1 ){
			return false;
		}
	}
	return true;
}
function IsNumeric(sText){
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
 
   for (i = 0; i < sText.value.length && IsNumber == true; i++) 
      { 
      Char = sText.value.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
}
function IsEmail(field){
	if(field.value.indexOf("@")==-1||field.value.indexOf(".")==-1){
		return false;
	}else{
		return true;
	}
}
function IsURL(field){
	var myRegxp = /^http|https|www/;
	return myRegxp.test(field.value);

}
function pc2town(pcode){
	var thisPC = pcode.substr(0,pcode.length-3);
	thisPC = thisPC.replace(" ","");
	var lookupTable = "#BA20%110#BA21%110#BA22%110#BH1%8#BH10%8#BH11%8#BH12%54#BH13%54#BH14%54#BH15%54#BH16%54#BH17%54#BH18%112#BH19%78#BH2%8#BH20%84#BH21%88#BH22%31#BH23%11#BH24%58#BH25%48#BH3%8#BH31%82#BH4%8#BH5%8#BH6%8#BH7%8#BH8%8#BH9%8#DT1%13#DT10%76#DT11%7#DT2%13#DT3%86#DT4%86#DT5%114#DT6%9#DT7%42#DT8%6#DT9%70#GU11%1#GU14%3#GU30%40#GU32%52#PO1%56#PO10%116#PO11%118#PO12%36#PO13%36#PO14%30#PO15%120#PO16%30#PO17%122#PO18%124#PO19%126#PO2%56#PO20%128#PO21%130#PO22%130#PO3%56#PO30%50#PO31%12#PO32%12#PO33%62#PO34%62#PO35%132#PO36%64#PO37%68#PO38%80#PO39%80#PO4%134#PO40%34#PO5%134#PO6%134#PO7%136#PO8%136#PO9%138#RG21%5#SO14%72#SO15%72#SO16%72#SO17%72#SO18%72#SO19%72#SO20%74#SO21%140#SO22%90#SO23%90#SO24%2#SO30%142#SO31%144#SO32%146#SO41%44#SO42%10#SO43%46#SO45%38#SO50%14#SO51%60#SO52%148#SO53%150#SP1%152#SP10%4#SP11%154#SP2%152#SP3%156#SP4%158#SP5%160#SP6%32#SP7%66#SP8%162#SP9%164";
	var myVal = "#"+thisPC.toUpperCase()+"%";
	var start = "";
	if(lookupTable.indexOf(myVal)!=-1){
		start = lookupTable.indexOf(myVal)+myVal.length;
		var end = lookupTable.indexOf("#",start);
		if(end==-1)end=lookupTable.length;
		var len = end-start;
		return lookupTable.substr(start,len);
	}else{
		return "";
	}
}
function checkPostCode (toCheck) {

  // Permitted letters depend upon their position in the postcode.
  var alpha1 = "[abcdefghijklmnoprstuwyz]";                       // Character 1
  var alpha2 = "[abcdefghklmnopqrstuvwxy]";                       // Character 2
  var alpha3 = "[abcdefghjkstuw]";                                // Character 3
  var alpha4 = "[abehmnprvwxy]";                                  // Character 4
  var alpha5 = "[abdefghjlnpqrstuwxyz]";                          // Character 5
  

  // Array holds the regular expressions for the valid postcodes
  var pcexp = new Array ();

  // Expression for postcodes: AN NAA, ANN NAA, AAN NAA, and AANN NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1,2})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
  
  // Expression for postcodes: ANA NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}[0-9]{1}" + alpha3 + "{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));

  // Expression for postcodes: AANA  NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1}" + alpha4 +"{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
  
  // Exception for the special postcode GIR 0AA
  pcexp.push (/^(GIR)(\s*)(0AA)$/i);
  
  // Standard BFPO numbers
  pcexp.push (/^(bfpo)(\s*)([0-9]{1,4})$/i);
  
  // c/o BFPO numbers
  pcexp.push (/^(bfpo)(\s*)(c\/o\s*[0-9]{1,3})$/i);

  // Load up the string to check
  var postCode = toCheck;

  // Assume we're not going to find a valid postcode
  var valid = false;
  
  // Check the string against the types of post codes
  for ( var i=0; i<pcexp.length; i++) {
    if (pcexp[i].test(postCode)) {
    
      // The post code is valid - split the post code into component parts
      pcexp[i].exec(postCode);
      
      // Copy it back into the original string, converting it to uppercase and
      // inserting a space between the inward and outward codes
      postCode = RegExp.$1.toUpperCase() + " " + RegExp.$3.toUpperCase();
      
      // If it is a BFPO c/o type postcode, tidy up the "c/o" part
      postCode = postCode.replace (/C\/O\s*/,"c/o ");
      
      // Load new postcode back into the form element
      valid = true;
      
      // Remember that we have found that the code is valid and break from loop
      break;
    }
  }
  
  // Return with either the reformatted valid postcode or the original invalid 
  // postcode
  if (valid) {return postCode;} else return false;
}

// xSelect r4, Copyright 2004-2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
function xSelectInit(){
if(!document.getElementById("catz"))return false;
xSelect('category1','','catid1','subcatid1','','','required');
xSelect('category2','','catid2','subcatid2');
xSelect('category3','','catid3','subcatid3');
/*
xSelect('category4','','catid4','subcatid4');
xSelect('category5','','catid5','subcatid5');
xSelect('category6','','catid6','subcatid6');
xSelect('category7','','catid7','subcatid7');
xSelect('category8','','catid8','subcatid8');
xSelect('category9','','catid9','subcatid9');
xSelect('category10','','catid10','subcatid10');
xSelect('category11','','catid11','subcatid11');
xSelect('category12','','catid12','subcatid12'); 
*/
 
 // var oldCat = document.getElementById('category2');
 // var newCat = document.getElementById('catid2');
 // var container = document.getElementById('admin');
 // oldCat.parentNode.insertBefore(newCat,oldCat);
}
function xSelect(sId, fnSubOnChange, sMainName, sSubName, bUnder, iMargin, className) // Object Prototype
{
  // Private Event Listener
  function s1OnChange()
  {

    var io, s2 = this.xSelSub; // 'this' points to s1
    // clear existing
	//alert("b:"+s2.options.length);
    for (io=0; io<s2.options.length; +io) {
      s2.options[io] = null;
    }
    var a = this.xSelData, ig = this.selectedIndex;
	//alert("a:"+s2.options.length);
	for (io=0; io<a[ig].length; ++io) {
      var op = new Option(a[ig][io][1].replace("&amp;","&"));
      s2.options[io] = op;
	  var thisSubCatid = a[ig][io][2].split(",");
	  s2.options[io].setAttribute("value",thisSubCatid[1]);
		if(a[ig][io][3]=="selected"||a[ig][io][3]==true){
			s2.options[io].setAttribute("selected",a[ig][io][3]);
			s2.options[io].selected= true;
		}else{
		}
    }
  }
  // Constructor Code
  // Check for required browser objects
  var s0 = document.getElementById(sId);
  if (!s0 || !s0.firstChild || !s0.nodeName || !document.createElement || !s0.form || !s0.form.appendChild) {
    return null;
	
  }
  // Create main category SELECT element
  var s1 = document.createElement('SELECT');
  s1.className = className;
  s1.id = s1.name = sMainName ? sMainName : sId + '_main';
  s1.display = 'block'; // for opera bug?
  //s1.style.position = 'absolute';
  s1.xSelObj = this;
  s1.xSelData = new Array();
  // append s1 to s0's form
  //s0.form.appendChild(s1);
  s0.parentNode.insertBefore(s1,s0);
  // Iterate thru s0 and fill array.
  // For each OPTGROUP, a[og][0] == OPTGROUP label, and...
  // a[og][n] = innerHTML of OPTION n.
  var ig=0, io,ab, op, og, a = s1.xSelData;
  og = s0.firstChild;
  while (og) {
    if (og.nodeName.toLowerCase() == 'optgroup') {
      io = 0;
      a[ig] = new Array();
      //a[ig] = og.label;
      op = og.firstChild;
      while (op) {
        if (op.nodeName.toLowerCase() == 'option') {
		  a[ig][io] = new Array();
		  a[ig][io][0] = og.label;
          a[ig][io][1] = op.innerHTML;
		  a[ig][io][2] = op.value;
		  if(op.getAttribute("selected")){
			a[ig][io][3] = op.getAttribute("selected");
		  }else{
			a[ig][io][3] = null;
		  }
		  io++;
        }
        op = op.nextSibling;
      }
      ig++;
    }
    og = og.nextSibling;
  }
  // In s1 insert a new OPTION for each OPTGROUP in s0
  for (ig=0; ig<a.length; ++ig) {
    //op = new Option(a[ig][0]);
	op = new Option(a[ig][0][0]);
    s1.options[ig] = op;
	var thisCatid = a[ig][0][2].split(",");
	s1.options[ig].setAttribute("value",thisCatid[0]);
	for (io=0; io<a[ig].length; ++io) {
		if(a[ig][io][3]){
			s1.options[ig].setAttribute("selected","selected");
			s1.options[ig].selected = true;
		}
	}
  }
  // Create sub-category SELECT element
  var s2 = document.createElement('SELECT');
  s2.id = s2.name = sSubName ? sSubName : sId + '_sub';
  s2.className = "sub";
  s2.display = 'block'; // for opera bug?
  s2.style.position = 'absolute';
  s2.xSelMain = s1;
  s1.xSelSub = s2;
  // Append s2 to s0's form
  //s0.form.appendChild(s2);
  s0.parentNode.insertBefore(s2,s0);
  // Add event listeners
  s1.onchange = s1OnChange;
  s2.onchange = fnSubOnChange || null;
  // Hide s0. Position and show s1 where s0 was.
  s0.style.visibility = 'hidden';
  s1.style.visibility = 'visible';
  iMargin = iMargin || 0;
  s2.style.visibility = 'visible';
  // Initialize s2
  s1.onchange();
}
function fbs_click() {u=location.href;t=document.title;window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');return false;}
