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;
		}
	}
}
