var style_cookie = 'phpBBstyle';
	var onload_functions = new Array();
	var onunload_functions = new Array();



	/**
	* New function for handling multiple calls to window.onload and window.unload by pentapenguin
	*/
	window.onload = function()
	{
		for (i = 0; i <= onload_functions.length; i++)
		{
			eval(onload_functions[i]);
		}
	}

	window.onunload = function()
	{
		for (i = 0; i <= onunload_functions.length; i++)
		{
			eval(onunload_functions[i]);
		}
	}


function validatePhone(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');

   if (fld.value == "") {
        error = "You didn't enter a phone number.\n";
        fld.style.background = 'Yellow';
    } else if (isNaN(parseInt(stripped))) {
        error = "The phone number contains illegal characters.\n";
        fld.style.background = 'Yellow';
    } else if (!(stripped.length == 10)) {
        error = "The phone number is the wrong length. Make sure you included an area code.\n";
        fld.style.background = 'Yellow';
    }
    return error;
}

function trim(s)
{
  return s.replace(/^\s+|\s+$/g,"");

}

function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;

    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "Please enter a valid email address.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = 'Yellow';
        error = "Please enter a valid email address.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = 'Yellow';
        error = "Please enter a valid email address.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}


function validateEmpty(fld) {
    var error = "";

    if (fld.value.length == 0) {
        fld.style.background = 'Yellow';
        error = "The required field has not been filled in.\n"
    } else {
        fld.style.background = 'White';
    }
    return error;
}
function validateUsername(fld) {
    var error = "";

    if (fld.value.length < 3 || fld.value.length > 20) {
        fld.style.background = 'Yellow';
        error = "The username field needs to be between 6 and 20 chars.\n"
    } else {
        fld.style.background = 'White';
    }
    return error;
}
function validatePassword(fld) {
    var error = "";

    if (fld.value.length < 6 || fld.value.length > 30) {
        fld.style.background = 'Yellow';
        error = "The username field needs to be between 6 and 30 chars.\n"
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function cardval(s) {
// remove non-numerics
var v = "0123456789";
var w = "";
for (i=0; i < s.length; i++) {
x = s.charAt(i);
if (v.indexOf(x,0) != -1)
w += x;
}
// validate number
j = w.length / 2;
if (j < 6.5 || j > 8 || j == 7) return false;
k = Math.floor(j);
m = Math.ceil(j) - k;
c = 0;
for (i=0; i<k; i++) {
a = w.charAt(i*2+m) * 2;
c += a > 9 ? Math.floor(a/10 + a%10) : a;
}
for (i=0; i<k+m; i++) c += w.charAt(i*2+1-m) * 1;
return (c%10 == 0);
}

function isZip(s)
{

     // Check for correct zip code
     reZip = new RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/);

     if (!reZip.test(s)) {
          return false;
     }

return true;
}


function isChecked(chk){
  if (chk.checked == 1)
    return (true);
  else
    return (false);
}

function popFLV(directory,fileName,fileTitle,width,height) {
window.open('/flash.php?fileID='+fileName+ '&directory=' + directory + '&extension=' + 'flv' + '&video_width=' + width + '&video_height=' + height + '&title=' + fileTitle,fileName,'height=' + (height + 20) + ',width=' + width + ',status=yes,toolbar=no,menubar=no,location=no,resizable=yes');
}


function popJPG(fileName,title,width,height) {
window.open('/image_viewer.php?filename='+fileName + '&title=' + title,"_blank",'height=' + (height + 20) + ',width=' + (width + 20) + ',status=no,toolbar=no,menubar=no,location=no,resizable=yes');
}
function popWMA(fileName) {
newwindow = window.open('/play_audio.php?filename='+fileName + '&id=' + hapi_session ,'audio','width=360,height=60,status=no,toolbar=no,menubar=no,location=no,resizable=true');
newwindow.focus();
}
function popWMV(fileName,fileTitle,width,height,video_width,video_height) {
window.open('/windows_media_video.php?fileID='+fileName+ '&video_width=' + video_width + '&video_height=' + video_height + '&title=' + fileTitle,fileName,'height=' + (height + 40) + ',width=' + (width + 20) + ',status=yes,toolbar=no,menubar=no,location=no,resizable=yes');
}
// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

// set the radio button with the given value as being checked
// do nothing if there are no radio buttons
// if the given value does not exist, all the radio buttons
// are reset to unchecked
function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}

function getXMLHTTP() { //fuction to return the xml http object
	var xmlhttp=false;
	try{
		xmlhttp=new XMLHttpRequest();
	}
	catch(e)	{
		try{
			xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e){
			try{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch(e1){
				xmlhttp=false;
			}
		}
	}

	return xmlhttp;
}


	function getCity(stateId) {
		var strURL="find_city.php?state_id="+stateId;
		var req = getXMLHTTP();

		if (req) {

			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {
						document.getElementById('citydiv').innerHTML=req.responseText;
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}
			}
			req.open("GET", strURL, true);
			req.send(null);
		}

	}




function timedRefresh(timeoutPeriod) {
	setTimeout("location.reload(true);",timeoutPeriod);
}


// cookie stuff
function getCookie (name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
			return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
}

function setCookie(cookieName, cookieValue, nDays) {
	var today = new Date();
	var expire = new Date();
	if (nDays==null || nDays==0) nDays=365;
	expire.setTime(today.getTime() + 3600000*24*nDays);
	document.cookie = cookieName+"=" + escape(cookieValue) + ";expires="+expire.toGMTString();
}

function getCookieVal(offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

var expdate = new Date();
expdate.setTime(expdate.getTime() +  (24 * 60 * 60 * 1000 * 15));

function setCookie(name, value) {
	document.cookie = name + "=" + escape (value) + "; expires=" + expdate.toGMTString() +  "; path=/";
}
function unhide(divID) {
 	var item = document.getElementById(divID);
 	if (item) {
 		item.className=(item.className=='hidden')?'unhidden':'hidden';
 	}
}
function popJPG(fileName,title,width,height) {
window.open('/image_viewer.php?filename='+fileName + '&title=' + title,"_blank",'height=' + (height + 20) + ',width=' + (width + 20) + ',status=no,toolbar=no,menubar=no,location=no,resizable=yes');
}
function openWindow(url,width,height,options,name) {
  width = width ? width : 800;
  height = height ? height : 600;
  options = options ? options : 'resizable=yes';
  name = name ? name : 'openWindow';
  window.open(
    url,
    name,
    'screenX='+(screen.width-width)/2+',screenY='+(screen.height-height)/2+',width='+width+',height='+height+','+options
  )
}

function show_scoreboard_updater (event_id)
{
  openWindow('/scoreboard_updater.php?event_id=' + event_id,750,450,'resizable=yes','scoreboard_updater');
}

