//---------------- MISC

var window_ref;
document.loaded = '';


function global(bln) {
	orollover();
	saved_comments(savedComments);
	if (!bln) flyouts();		//are flyouts being used on this site?

	document.loaded = true;
	if (objDetection.getGood) window_ref = top.window;
	else window_ref = window.opener;
}

//---------------- //


function logout() {
	if (confirm('Are you sure you want to logout?')) document.location.href = ROOT + "/_inc/logout.asp";
}

function admin_logout() {
	if (confirm('Are you sure you want to logout?'))document.location.href = ROOT + "/_admin/_inc/logout.asp";
}

function bookNow(f) {
	var myArray = new Array(
	"sessionid,req,Please select a session",
	"tickettype,req,A ticket type must be selected",
	"quantity,req,Please select a quantity"
	);
	if (myvalidate(f,myArray)) f.submit();
}

var booking_interval;
function showNewBooking(i,t) {
	var j = 0;
	if (!i && !t) window.setTimeout("showNewBooking(1)", 1000);
	else {
		for (i=0;(obj=myBooking[i]);i++) {
			if (obj.getAttribute) {
				if (obj.getAttribute("status") == "true") {
					document.myObj = obj;
					j++;
				}
			}
		}
		if (j==1) {
			obj = document.myObj;
			obj.style.display = 'block';
			obj.style.filter = 'alpha(opacity=0)';
			booking_interval = window.setInterval("animeMyBooking()",50);
		}else {
			for (i=0;(obj=myBooking[i]);i++) {
				if (obj.getAttribute) {
					if (obj.getAttribute("status") == "true") obj.style.display = 'block';
				}
			}
		}
	}
}

var intAlpha = 0;
function animeMyBooking() {
	obj = document.myObj;
	obj.style.filter = "alpha(opacity="+intAlpha+")";
	if (intAlpha >= 100) window.clearInterval(booking_interval);
	intAlpha += 20;
}

//---------------- //



//---------------- FORM VALIDATION
/*
[OVERVIEW]
Simple validation. After submitting, it alerts the user
with a list of missing elements, at the same time colours the
form fields needing attention.

[CALL]
This function takes two arguments. Firstly, the form object.
Secondly, an array of information needing validating. The format
for the array is simple.

var myArray = new Array ("myEmail,eml,Please enter your email address")
if (myvalidate(objForm,myArray)) objForm.submit();

1. Field Name
2. Validation Type*
3. Alert Message

*The validation type has a few pre set types to make life easy.

1. Required:	req		(Forces something to be entered)
2. Email:		eml		(Forces the '@' and '.' characters)
3. Number:		num		(Forces an integar type)

If some more custom needs validating, you can put that code in instead.
Example: "myPostcode,f.myPostcode.length!=4,You must have a 4 digit password"

[WRITTEN]
David Tsuji
*/
function myvalidate(f,vAr) {
	var errorColor = "#FF9900";
	var error='';
	for (i=0;(obj=vAr[i]);i++) {
		con='';arg='';objAr='';objAr=obj.split(",");
		if(objAr[0])obj=eval('document.'+f.name+'.'+objAr[0]);
		arg=objAr[1];alt=objAr[2];
		if(obj.style&&!obj.n) {
			objbc = obj.style.backgroundColor;
			if (objbc) obj.n=objbc;
			else obj.n="#FFFFFF";
			obj.e=errorColor; }else if(obj.style&&obj.n) obj.style.backgroundColor=obj.n;
		myerror=function(){error+='- '+alt+'\n';if(obj.style)obj.style.backgroundColor=obj.e;}
		if(arg.length>3) con=eval(objAr[1]);
		if(con) myerror();
		if(arg=='req') if(!obj.value) myerror();
		if(arg=='eml') if(!isMyEmail(obj.value)) myerror();
		if(arg=='num') if(isNaN(obj.value)||!obj.value) myerror();
	}if(error) {alert('Please correct the following fields:\n\n'+error);return false}
	else return true;
}

/*
[WRITTEN]
David Peterson
*/
function isMyEmail(eml) {
	var emailPat = /^(\".*\"|[A-Za-z0-9\_][A-Za-z0-9\.\-\_]*)@(\[\d{1,3}(\.\d{1,3}){3}]|([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,4})$/;
	var matchArray = eml.match(emailPat);
	if (matchArray == null) return false;
	var IPArray = matchArray[2].match(/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/);
	if (IPArray != null) for(i=1;i<=4;i++) if (IPArray[i]>255) return false;
	return true;
}
//---------------- //





//---------------- OTHER ROLLOVERS
function orollover() {
	if (getPlatform!="PC"||getBrowser!="IE") {
		for (i=0;(img=document.images[i]);i++) {
		if(img.getAttribute){
		if(img.stickonurl) if (location.href.match(img.stickonurl)) img.src=img.rollover;
		if(img.getAttribute("rollover")) {
		img.o=new Image();img.n=new Image();
		img.o.src=img.getAttribute("rollover");img.n.src=img.src;
		img.onmouseover=function(){this.src=this.o.src;}
		img.onmouseout=function(){this.src=this.n.src;}} }	}
	}
}
//---------------- //





//---------------- DETECTION

var agt=navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);
var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
                && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
var is_ie3    = (is_ie && (is_major < 4));
var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
var is_ie4up  = (is_ie && (is_major >= 4));
var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);
var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
var is_ie6up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);

var getBrowser = null;
if (is_ie) getBrowser = "IE";
else getBrowser = "NN";
var getPlatform = null;
var is_win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
var is_mac    = (agt.indexOf("mac")!=-1);
if (is_win) getPlatform = "PC";
else getPlatform = "MAC";

//---------------- //





//---------------- SAVED COMMENTS
function saved_comments(sc) {
	if (sc) {
		if (is_ie5_5up) {
			document.body.insertAdjacentHTML("beforeEnd", "<span id=my_sc style=\"display:none\">"+sc+"</span>");
		}else alert(sc);
	}
}
//---------------- //





//---------------- FLYOUTS
var current_flyout_o = null;
var flyout_over_bln = false;
var hide_flyout_interval = null;
function flyouts() {
	var menu_o = new get_o("menu");
	if (menu_o.length)
		for (var i=0;i<=(menu_o.length-1);i++) init_menu(menu_o[i]);
	else init_menu(menu_o);
}

var emulateonresizeendiid;
function emulateonresizeend() {
	if (parseInt(emulateonresizeendiid)) clearInterval(emulateonresizeendiid);
	emulateonresizeendiid = setInterval("flyouts();clearInterval(emulateonresizeendiid)" ,100);
}
window.attachEvent ? window.attachEvent("onresize", emulateonresizeend) : window.onresize = emulateonresizeend;

function init_menu(o) {
	var mpos, target_o, screencenter, sticky_bln = false;
	if (document.all)	screencenter = window.document.body.offsetWidth/2;
	else				screencenter = window.innerWidth/2;
	if (o.getAttribute("stickonurl")) if (location.href.match(o.getAttribute("stickonurl"))) sticky_bln = true;
	if (o.getAttribute("submenu") && sticky_bln == false) {
		p = new get_o(o.getAttribute("submenu"));
		//alert(o.getAttribute("submenu"));

		if (p.style) {
			mpos = o.getAttribute("submenuposition").split(",");
			if (!parseInt(mpos[0])) {
				if (mpos[0].indexOf("this") != -1) mpos[0] = mpos[0].replace("this", "getposition(o,\"x\")");
				mpos[0] = eval(mpos[0]);
			}
			if (!parseInt(mpos[1])) {
				if (mpos[1].indexOf("this") != -1) mpos[1] = mpos[1].replace("this", "getposition(o,\"y\")");
				mpos[1] = eval(mpos[1]);
			}
			p.style.left = mpos[0];
			p.style.top = mpos[1];
			//p.style.position = "absolute";
		}
		
		o.parentNode.mytc = o;
		
		o.parentNode.onmouseover = function() {
			var o = new get_o(this.mytc.getAttribute("submenu"));
			if (current_flyout_o) current_flyout_o.style.visibility = "hidden";
			if (o.style) o.style.visibility = "visible";
			current_flyout_o = o;
			flyout_over_bln = true;
			if (parseInt(hide_flyout_interval)) clearInterval(hide_flyout_interval);
			hide_flyout_interval = setInterval(hide_flyout, 2000);
		}

		o.parentNode.onmouseout = function() {
			getposition(this.mytc, "x");
			flyout_over_bln = false;
		}
		
		target_o = new get_o(o.getAttribute("submenu"));
		
		target_o.onmouseover = function() {
			flyout_over_bln = true;
		}
		
		target_o.onmouseout = function() {
			flyout_over_bln = false;
		}
	}
}

function hide_flyout() {
	var o = current_flyout_o;
	if (!flyout_over_bln) {
		if (hide_flyout_interval != null) clearInterval(hide_flyout_interval);
		hide_flyout_interval = null;
		if (o.style) {
			o.style.visibility = "hidden";
		}
	}
}

function get_o(v) {
	var p = null;
	if (document.getElementsByName) {
		if (document.getElementsByName(v).length==1) p = document.getElementsByName(v)[0];
		else if (document.getElementsByName(v).length==0) p = null;
		else p = document.getElementsByName(v);
		return p;
	} else return null;
}

function getposition(o, t) {
	var p=0;
	while (o.tagName != "BODY") {
		if (o.tagName != "TR" && o.tagName != "TBODY") t == "x" ? p += o.offsetLeft : p += o.offsetTop;
		o = o.parentNode;
	}
	return p;
}
//---------------- //



