// JavaScript Document
$(document).ready(onReady);

function onReady(){
	//$("#menu a img").mouseover(aMouseOver).mouseout(aMouseOut);
}

function aMouseOver(){
	var src = $(this).attr("src");
	if(src && src.indexOf("-over") < 0){
		var strArr = src.split(".");
		var newSrc = strArr[0]+"-over."+strArr[1];
		$(this).attr("src", newSrc);
	}
}

function aMouseOut(){
	var src = $(this).attr("src");
	if(src && src.indexOf("-over") > 0){
		var strArr = src.split("-over");
		var newSrc = strArr[0]+strArr[1];
		$(this).attr("src", newSrc);
	}
}

function openWindow(obj, w, h){
	var width = w != null ? w : 400;
	var height = h != null ? h : 520;
	var left = (window.screen.width-width) / 2;
	var top = (window.screen.height-height) / 2;
	var features = "top="+top+",left="+left+",width="+width+",height="+height+",resizable=no,location=no,scrollbars=yes,toolbar=no,menubar=no"
	disWindow = window.open(obj.href, "disclaimer", features);
	window.onfocus = function(){
		if(disWindow) disWindow.close();
		this.onfocus = null;
	}
}
function isValidEmail(email){
	var reg = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	return reg.exec(email);
}// isValidEmail

function restrictNumbers(e, obj){
	var keynum;
	var keychar;
	var numcheck;
	
	if(window.event) { // IE
	 	keynum = e.keyCode;
	} else if(e.which) {// Netscape/Firefox/Opera
	 	keynum = e.which;
	}
	
	 numcheck = /\d/;
	//if(!keynum) return keynum;
	
	if(keynum <=57 && !e.shiftKey){
		return keynum;
	} else {
		return false;
	}
	
	/*
	keychar = String.fromCharCode(keynum);
	numcheck = /\D/;
	return !numcheck.test(keychar);
	*/
}

function displayDIV(d, id){
	
	//setting them to default values if they are undefined
	if(document.getElementById(d).style.visibility == "") {
		document.getElementById(d).style.visibility = "hidden";
		document.getElementById(d).style.display = "none";
	}

	//make them visible if invisible and vice versa
	if(document.getElementById(d).style.visibility == "hidden"){
		document.getElementById(d).style.visibility = "visible";
		document.getElementById(d).style.display = "block";
	} else {
		document.getElementById(d).style.visibility = "hidden";
		document.getElementById(d).style.display = "none";
		clearPlayerData(id);
	}
}

//function to poppulate number of days in a date field depending upon month - Accounts first field for the day, month & year as description field
function populateDate(date, month, year){	
	date = document.getElementById(date);
	month = document.getElementById(month);
	year = document.getElementById(year);
	
	var days = new Array(-1, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);	
	leapDays = 28;
	
	if(month.selectedIndex != 0){
		//if date field requires addition of option elements
		if(date.length - 1 < days[month.selectedIndex]){
	
			val = (date.options[date.length-1].value); //last value in the date field
	 
			while(date.length - 1 < days[month.selectedIndex]){
				var option = document.createElement("option");	//create a new option element
				option.text = option.value = ++val;				//label and value of the new option
				try {
					date.add(option, null); // standards compliant; doesn't work in IE
				} catch(ex) {
					date.add(option); // IE only
				}
			}
		}
		
		//if date field requires removal of elements
		if(date.length - 1 > days[month.selectedIndex]){
			while(date.length - 1 > days[month.selectedIndex]){
				date.remove(date.length-1);		//remove last option element
			}
		}
		
		//leap year check
		if(year.options[year.selectedIndex].value % 4 == 0 && month.selectedIndex == 2){
			while(date.length - 1 > leapDays ){
				date.remove(date.length-1);
			}
		}
	}
}


////////////////////////// pull sonw menus /////////////////////////////////////
var hidInt = new Array();
var menuDist = new Array(null, 470, 390, 90, 245, 170);
function showMenu(menu, h, obj){
	
	window.clearTimeout(hidInt[h]);
	var objMenu = document.getElementById(menu);
	var tableLeft;
	if(window.innerWidth){
		//////////// ff
		tableLeft = Math.round( (window.innerWidth-845)/2);
	}
	else{
		///////////////// ie
		tableLeft = Math.round( (document.body.clientWidth-845)/2);
	} 
	if(tableLeft<0) tableLeft = 0;
	objMenu.style.left = tableLeft + menuDist[h] + "px";
	objMenu.style.top = "28px";
	objMenu.style.display = "block";
	
}

function beforeHide(menu, h){
	window.clearTimeout(hidInt[h]);
	hidInt[h] = window.setTimeout("hideMenu('"+menu+"')", 200);
}

function stopHide(h){
	window.clearTimeout(hidInt[h]);
}

function hideMenu(menu){
	var objMenu = document.getElementById(menu);
	objMenu.style.display = "none";
}
