<!--
function setNotice(state) {
	notice = document.getElementById('div_notice');
	notice.style.display = (state=='show') ? 'block' : 'none';
}

function BRB_PHP_DelWithCon(deletepage_url,field_name,field_value,messagetext) { //v1.0 - Deletes a record with confirmation
  if (confirm(messagetext)==1){
  	location.href = eval('\"'+deletepage_url+'?'+field_name+'='+field_value+'\"');
  }
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function doSubmit(thisForm) {
	var theForm = document.getElementById(thisForm);
	if(theForm.onsubmit()) {
		theForm.submit();
	}
}

function restrictTo(inp,chars) {
	reg = '([^'+chars+'])';
	inp.value=inp.value.replace(RegExp(reg,'g'),"");
}

function toTitleCase(str) {
    return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
}
function validEmail(e) {
	retVal = true;
	suffix = e.substr((e.lastIndexOf('.',e.length-1)+1),e.length);
	switch(true) {
		case (typeof(e) == "object"): 								retVal = false; break;	// check it is not an object
		case (e.length<1):											retVal = false; break;	// check it is not empty
		case (e.indexOf('@',0)==-1):								retVal = false; break;	// check it contains an @ sign
		case (e.indexOf('@',0)<1):									retVal = false; break;	// Nothing before the @
		case (e.indexOf('@',0)==e.length-1):						retVal = false; break;	// Nothing after the @
		case (e.indexOf('[',0)==-1&&e.charAt(e.length-1)==']'):		retVal = false; break;	// No Left Bracket
		case (e.indexOf('[',0)>-1&&e.charAt(e.length-1)!=']'):		retVal = false; break;	// No Right Bracket
		case ((e.indexOf('@',0)>1&&e.charAt(e.length-1)!=']')&&(e.indexOf('.',0)==-1)): err="8";	retVal = false; break;	// No valid full-stop
		case ((e.indexOf('@',0)>1&&e.charAt(e.length-1)!=']')&&(((suffix.length<1)||(suffix.length>4))&&((suffix.toLowerCase()!='travel')&&(suffix.toLowerCase()!='museum')))): retVal = false; break; // validate the suffix
	}
	return retVal;
}

/* Author: John Gardner (checkPostCode & checkUKtel)
Copyright Info http://www.braemoor.co.uk/software/postcodes.shtml */
function checkPostCode(toCheck) {
	var alpha1 = "[abcdefghijklmnoprstuwyz]";
	var alpha2 = "[abcdefghklmnopqrstuvwxy]";
	var alpha3 = "[abcdefghjkpmnrstuvwxy]";
	var alpha4 = "[abehmnprvwxy]";
	var alpha5 = "[abdefghjlnpqrstuwxyz]";
	var pcexp = new Array ();
	pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1,2})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
	pcexp.push (new RegExp ("^(" + alpha1 + "{1}[0-9]{1}" + alpha3 + "{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
	pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "{1}" + "?[0-9]{1}" + alpha4 +"{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
	pcexp.push (/^(GIR)(\s*)(0AA)$/i);
	pcexp.push (/^(bfpo)(\s*)([0-9]{1,4})$/i);
	pcexp.push (/^(bfpo)(\s*)(c\/o\s*[0-9]{1,3})$/i);
	pcexp.push (/^([A-Z]{4})(\s*)(1ZZ)$/i);
	var postCode = toCheck;
	var valid = false;
	for ( var i=0; i<pcexp.length; i++) {
	if (pcexp[i].test(postCode)) {
	pcexp[i].exec(postCode);
	postCode = RegExp.$1.toUpperCase() + " " + RegExp.$3.toUpperCase();
	postCode = postCode.replace (/C\/O\s*/,"c/o ");
	valid = true;
	break;}}
	if (valid) {return postCode;} else return false;
}
function checkUKtel(telephoneNumber) {
	var telNumberErrors = new Array ();
	telNumberErrors[0] = "Valid UK telephone number";
	telNumberErrors[1] = "Telephone number not provided";
	telNumberErrors[2] = "UK telephone number without the country code, please";
	telNumberErrors[3] = "UK telephone numbers should contain 10 or 11 digits";
	telNumberErrors[4] = "The telephone number should start with a 0";
	telNumberErrors[5] = "The telephone number is either invalid or inappropriate";
	
	var telnum = telephoneNumber + " ";
	if (telnum.length == 1)  {
		telNumberErrorNo = 1;
		return false
	}
	telnum.length = telnum.length - 1;

	var exp = /^(\+)[\s]*(.*)$/;
	if (exp.test(telnum) == true) {
		telNumberErrorNo = 2;
		return false;
	}

	while (telnum.indexOf(" ")!= -1)  {
	telnum = telnum.slice (0,telnum.indexOf(" ")) + telnum.slice (telnum.indexOf(" ")+1)
	}

	while (telnum.indexOf("-")!= -1)  {
	telnum = telnum.slice (0,telnum.indexOf("-")) + telnum.slice (telnum.indexOf("-")+1)
	}  

	exp = /^[0-9]{10,11}$/;
	if (exp.test(telnum) != true) {
	telNumberErrorNo = 3;
	return false;
	}

	exp = /^0[0-9]{9,10}$/;
	if (exp.test(telnum) != true) {
	telNumberErrorNo = 4;
	return false;
	}

	var tnexp = new Array ();
	tnexp.push (/^(0113|0114|0115|0116|0117|0118|0121|0131|0141|0151|0161)(4960)[0-9]{3}$/);
	tnexp.push (/^02079460[0-9]{3}$/);
	tnexp.push (/^01914980[0-9]{3}$/);
	tnexp.push (/^02890180[0-9]{3}$/);
	tnexp.push (/^02920180[0-9]{3}$/);
	tnexp.push (/^01632960[0-9]{3}$/);
	tnexp.push (/^07700900[0-9]{3}$/);
	tnexp.push (/^08081570[0-9]{3}$/);
	tnexp.push (/^09098790[0-9]{3}$/);
	tnexp.push (/^03069990[0-9]{3}$/);
	
	for (var i=0; i<tnexp.length; i++) {
		if ( tnexp[i].test(telnum) ) {
			telNumberErrorNo = 5;
			return false;
		}
	}
	exp = (/^(01|02|03|05|070|071|072|073|074|075|07624|077|078|079|0800|0808|0844|0845|0870|0871)[0-9]+$/);
	if (exp.test(telnum) != true) {
		telNumberErrorNo = 5;
		return false;
	} 
	return telnum;
}
function liveCheck(e,obj,typ,override) {
	doCheck = true;
	if((override)&&($(override).checked!=1)) { doCheck = false; }
	if(doCheck) {
		var KeyID = (window.event) ? event.keyCode : e.keyCode;
		if(KeyID) {
		//if( ((KeyID>45)&&(KeyID<112)) || ((KeyID>185)&&(KeyID<223)) || (KeyID==32)) {
			switch(typ) {
				case 'title':
					obj.value = toTitleCase(obj.value); break;
				case 'postcode':
					if(checkPostCode(obj.value)) {
						obj.removeClass('invalid'); obj.addClass('valid');  
						obj.value = checkPostCode(obj.value);
					} else {
						obj.removeClass('valid'); obj.addClass('invalid'); 
					}
					break;
				case 'telephone':
					if(checkUKtel(obj.value)) {
						obj.removeClass('invalid'); obj.addClass('valid'); 
						obj.value = checkUKtel(obj.value);
					} else {
						obj.removeClass('valid'); obj.addClass('invalid');
					}
					break;
				case 'email':
				default: 
					// ! # $ % & ' * + - / = ? ^ _ ` { | } ~
					restrictTo(obj,'A-Za-z0-9\-_\+\.\!#%\*\?\`\$\&{}~\|\^=\'@');
					if(validEmail(obj.value)) {
						obj.removeClass('invalid'); obj.addClass('valid'); 
					} else {
						obj.removeClass('valid'); obj.addClass('invalid');
					}
					break;
			}
		} //}
	}
}

function submitCheck(f) {
	
}

function checkVote(form) {
	answer_yes = document.getElementById('vote_yes').checked;
	answer_no = document.getElementById('vote_no').checked;
	if((answer_yes==false)&&(answer_no==false)) {
		alert('Please vote either yes or no.');
		document.voteResponse = false;
	} else {
		document.voteResponse = true;
	}
}

function checkKey(thisForm) {
	var key = document.layers ? evt.which 
            : document.all ? event.keyCode
            : evt.keyCode;
	var keyName = String.fromCharCode(key);
	if (key==13) {
		doSubmit(thisForm);
		return false;
	}
}

function addCommas(nStr) {
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

function toMoney(str) {
	str = Math.round(parseFloat(str)*100)/100;
	return str.toFixed(2);
}

function authEmail(typ,id) {
	var myRequest = new Request({
		url: 'http://www.bestpartiesever.com/Scripts/authEmail.php?userType='+typ+'&userID='+id,
		onRequest: function(){
			$('ajaxLoader').setStyle('display', 'block');
		},
		onSuccess: function(responseText){
			$('ajaxLoader').setStyle('display', 'none');
			if(responseText=='OK') {
				alert('Email Sent:\nPlease check your email for the authorisation code');
			} else {
				alert('There was an error sending the authorisation email:\n'+responseText);
			}
		},
		onFailure: function(){
			alert('There was an error sending the email - details unknown');
			$('ajaxLoader').setStyle('display', 'none');
		}
	});
	myRequest.send(null);
}

function minVal(field,minV) {
	if(parseInt(field.value)<parseInt(minV)) {
		field.value = parseInt(minV);
		alert('Please enter a minimum amount of '+minV+' or remove all numbers to remove this item');
		return false;
	} else {
		return true;
	}
}

function includeInvoice() {
	// get pay invoice checkbox value
	payInv = document.getElementById('pay_invoice');
	invtot = document.getElementById('invBalance');
	grandtot = document.getElementById('grandtotal');
	invTotal = ((invtot)&&(invtot.lang!=null)) ? parseFloat(invtot.lang) : 0;
	grandTotal = (grandtot.lang) ? parseFloat(grandtot.lang) : 0;
	balance = document.getElementById('balance');
	if(payInv.checked==1) {
		gt = grandTotal+invTotal;
		grandtot.value = '£'+addCommas(toMoney(gt));
		grandtot.lang = gt;
		balance.value = gt;
	} else {
		gt = grandTotal-invTotal;
		grandtot.value = '£'+addCommas(toMoney(gt));
		grandtot.lang = gt;
		balance.value = gt;
	}
	addCardCharge();
}

function calcTotals(inp) {
	if(typeof(inp)!='object') {
		inp = document.getElementById(inp);
	}
	if(typeof(inp)=='object') {
		id = inp.id;
		val = inp.value;
		// make sure the input is numerical
		val=val.replace(/([^0-9])/g,"");
		val = (val=='') ? 0 : val;
		if(val != inp.value) {
			inp.value = val;
		}
		
		// get row total field
		tot = document.getElementById('total_'+id);
		// get subtotal field
		subtot = document.getElementById('subtotal');
		// get grand field
		grandtot = document.getElementById('grandtotal');
		// get inv total field
		invtot = document.getElementById('invBalance');
		// get balance field
		balance = document.getElementById('balance');
		
		// get stored totals
		rowTotal = (tot.lang) ? parseFloat(tot.lang) : 0;
		subTotal = (subtot.lang) ? parseFloat(subtot.lang) : 0;
		grandTotal = (grandtot.lang) ? parseFloat(grandtot.lang) : 0;
		invTotal = ((invtot)&&(invtot.lang!=null)) ? parseFloat(invtot.lang) : 0;
		
		// get new totals
		cost = parseFloat(inp.lang);
		total = parseInt(val)*cost;
		st = (subTotal-rowTotal)+total;
		gt = st+invTotal;
		
		tot.value = '£'+addCommas(toMoney(total));
		subtot.value = '£'+addCommas(toMoney(st));
		grandtot.value = '£'+addCommas(toMoney(gt));
		balance.value = gt;
		
		// store data
		tot.lang = total;
		subtot.lang = st;
		grandtot.lang = gt;
		
		addCardCharge();
	}
}

function checkCart() {
	grandtot = document.getElementById('grandtotal');
	grandTotal = (grandtot.lang) ? parseFloat(grandtot.lang) : 0;
	if(grandTotal>0) {
		card = selectedCard();
		if(!card) { alert('Please select your card type'); document.getElementById('submit').value='Pay Now'; }
		if(card){ 
		document.getElementById('submit').disabled=true;
		return true; } else { return false;}
	} else {
		alert('You must select something to pay for before you can continue');
		return false;
	}
}


function addCardCharge() {
	card = selectedCard();
	// get balance field
	balance = document.getElementById('balance');
	// get surcharge field
	surch = document.getElementById('surcharge');
	// get grand field
	grandtot = document.getElementById('grandtotal');
	total = (parseFloat(balance.value)) ? parseFloat(balance.value) : 0;
	vat = 20;
	sur = 1.5;
	totSur = sur*(vat/(100)+1);
	// calculate surcharge
	if(card=='credit') {
		surcharge = (total/100)*totSur;
		newTotal = (total+surcharge);
		surch.value = toMoney(surcharge);
		grandtot.value = '£'+addCommas(toMoney(newTotal));
	} else {
		surch.value = toMoney(0);
		grandtot.value = '£'+addCommas(toMoney(total));
	}
}

// get the value of the card_type box
function selectedCard() {
	retVal = false;
	// get card type info
	var card_type = document.getElementById('card_type');
	var selIndex = card_type.selectedIndex;
	card = card_type.options[selIndex].value;
	// check card type entered
	if(card!='') {
		retVal = card;
	}
	return retVal;
}

function toggle(me) {
	me = document.getElementById(me);
	if(me.style.display) {
		if(me.style.display != "block") {
			me.style.display = "block";
		} else {
			me.style.display = "none";
		}
	} else {
		me.style.display = "none";
	}
}

function setNotice(state) {
	notice = document.getElementById('notice_holder');
	notice.style.display = (state=='show') ? 'block' : 'none';
	if(state!='show') {
		nc = document.getElementById('div_notice_text');
		nc.innerHTML = " ";
	} // remove content
	if(state=='show') { window.scrollTo(0,0); } // scroll to the top of the page 
}

function noticeContent(cont,noesc,count) { 
	if(noesc) {
		cont = unescape(cont)
		replaceThis = "+";
		cont = cont.replace(/\+/g," ");
	}
	setNotice("show");
	document.getElementById('div_notice_text').innerHTML = cont;
	if(count!=null) { document.getElementById('div_notice_text').title = count; }
}

function showImage(img,alt,count) {
	alt = (alt) ? alt : '';
	imageTag = '<img src="'+img+'" alt="'+alt+'" />';
	noticeContent(imageTag,true,count);
}

function stristr( haystack, needle, bool ) {
    var pos = 0;
    haystack += '';
    pos = haystack.toLowerCase().indexOf( (needle+'').toLowerCase() );
    if( pos == -1 ){
        return false;
    } else{
        if( bool ){
            return haystack.substr( 0, pos );
        } else{
            return haystack.slice( pos );
        }
    }
}

function querySt(ji) {
	hu = window.location.search.substring(1);
	gy = hu.split("&");
	for (i=0;i<gy.length;i++) {
		ft = gy[i].split("=");
		if (ft[0] == ji) {
			return ft[1];
		}
	}
}

function setup() {
	if(querySt("dev")!="true") {
		var menu = document.getElementById('div_menu');
		var links = menu.getElementsByTagName('a');
		for(var i=0;i<links.length;i++) {
			links[i]._title = links[i].title;
			links[i].onmouseover = function() {
				 this.title = '';
			}
			links[i].onmouseout = function() {
				 this.title = this._title;
			}
		}
	}
}


function ajax(param) {
	//__show('AJAX: '+param);
	// set default values
	var url 	= (param.url) ? param.url : false;
	var async 	= (param.async) ? param.async : false; // default to synchronous updates
	var data 	= (param.data) ? param.data : '';
	var method	= (param.method) ? param.method : 'get';
	var onReq	= (param.onReq) ? param.onReq : null;
	var onComp	= (param.onComp) ? param.onComp : null;
	var onFail	= (param.onFail) ? param.onFail : function(){ _alert('The request failed'); };
	var onTO	= (param.onTO) ? param.onTO : function(){ _alert('The request timed out'); };
	var link	= (param.link) ? param.link : 'ignore';
	if(url) {
	var req = new Request({ 
		method: method,
		link: link,
		async: async,
		url: url, 
		data: data, 
		onRequest: onReq,
		onFailure: onFail,
    	onTimeout:onTO,
		onSuccess: function(res,xml) { onComp(res); } 
	}).send();
	} else { return false; }
}

function validateProduct(b,p,q,o) {
	$('ajaxLoader').setStyle('display', 'block');
	b = (b) ? b : 0;
	p = (p) ? p : 0;
	q = (q) ? q : 0;
	o = (o) ? o : 0;
	//__show('AJAX CALL');
	// add ajax submit parameter
	param = '&auth=ajax&b='+b+'&p='+p+'&q='+q;
	url = '/crmbo/validateProducts';
	ajax({url:url,data:param,onComp:function(result){
		if(result=='1') { 
			if($(o)) { 
				$(o).removeClass('cross');
				if(q>0) {
					$(o).addClass('tick');
				} else {
					$(o).removeClass('tick');
				}
			}
		} else {
			if($(o)) {
				$(o).removeClass('tick');
				$(o).addClass('cross');
			}
		}
		$('ajaxLoader').setStyle('display', 'none');
		return false;
	}});
}






function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function YY_checkform() { //v4.71
//copyright (c)1998,2002 Yaromat.com
  var a=YY_checkform.arguments,oo=true,v='',s='',err=false,r,o,at,o1,t,i,j,ma,rx,cd,cm,cy,dte,at;
  for (i=1; i<a.length;i=i+4){
    if (a[i+1].charAt(0)=='#'){r=true; a[i+1]=a[i+1].substring(1);}else{r=false}
    o=MM_findObj(a[i].replace(/\[\d+\]/ig,""));
    o1=MM_findObj(a[i+1].replace(/\[\d+\]/ig,""));
    v=o.value;t=a[i+2];
    if (o.type=='text'||o.type=='password'||o.type=='hidden'){
      if (r&&v.length==0){err=true}
      if (v.length>0)
      if (t==1){ //fromto
        ma=a[i+1].split('_');if(isNaN(v)||v<ma[0]/1||v > ma[1]/1){err=true}
      } else if (t==2){
        rx=new RegExp("^[\\w\.=-]+@[\\w\\.-]+\\.[a-zA-Z]{2,4}$");if(!rx.test(v))err=true;
      } else if (t==3){ // date
        ma=a[i+1].split("#");at=v.match(ma[0]);
        if(at){
          cd=(at[ma[1]])?at[ma[1]]:1;cm=at[ma[2]]-1;cy=at[ma[3]];
          dte=new Date(cy,cm,cd);
          if(dte.getFullYear()!=cy||dte.getDate()!=cd||dte.getMonth()!=cm){err=true};
        }else{err=true}
      } else if (t==4){ // time
        ma=a[i+1].split("#");at=v.match(ma[0]);if(!at){err=true}
      } else if (t==5){ // check this 2
            if(o1.length)o1=o1[a[i+1].replace(/(.*\[)|(\].*)/ig,"")];
            if(!o1.checked){err=true}
      } else if (t==6){ // the same
            if(v!=MM_findObj(a[i+1]).value){err=true}
      }
    } else
    if (!o.type&&o.length>0&&o[0].type=='radio'){
          at = a[i].match(/(.*)\[(\d+)\].*/i);
          o2=(o.length>1)?o[at[2]]:o;
      if (t==1&&o2&&o2.checked&&o1&&o1.value.length/1==0){err=true}
      if (t==2){
        oo=false;
        for(j=0;j<o.length;j++){oo=oo||o[j].checked}
        if(!oo){s+='* '+a[i+3]+'\n'}
      }
    } else if (o.type=='checkbox'){
      if((t==1&&o.checked==false)||(t==2&&o.checked&&o1&&o1.value.length/1==0)){err=true}
    } else if (o.type=='select-one'||o.type=='select-multiple'){
      if(t==1&&o.selectedIndex/1==0){err=true}
    }else if (o.type=='textarea'){
      if(v.length<a[i+1]){err=true}
    }
    if (err){s+='* '+a[i+3]+'\n'; err=false}
  }
  if (s!=''){alert('The required information is incomplete or contains errors:\t\t\t\t\t\n\n'+s)}
  document.MM_returnValue = (s=='');
}


if(window.addEventListener) window.addEventListener("load", setup, false); // for non IE browsers
else if(window.attachEvent) window.attachEvent("onload", setup);			 // for IE

// replace window.open for reservation pages
function openwindow(url,name,params,rep) {
	// process URL
	newURL = 'http://www.bestpartiesever.com/goto?l='+escape(url);
	return window.open(newURL,name,params,rep);
}
