var request = null;
var request2 = null;
var payment_popup;

function gotoURL(url) {
	location.href=url;
}

function getRequest() {
	try {
		request = new ActiveXObject("Msxml2.XMLHTTP");
	} catch(e) {
		try {
			request = new ActiveXObject("Microsoft.XMLHTTP");
		} catch(e2) {
			request = null;
		}
	}
	
	if(!request&&typeof XMLHttpRequest!="undefined") request = new XMLHttpRequest();
	if (request == null) alert("Your browser is not compatible with this application");
}
getRequest();

function ajaxRequestOK() {
	if (arguments[0].readyState == 4) {
		try { if (arguments[0].status == 200) return true;
		} catch (ex) { if (arguments[0].responseText != '') return true; }
	}

	return false;
}


try {
	request2 = new XMLHttpRequest();
} catch (trymicrosoft) {
	try {
		request2 = new ActiveXObject("Msxm12.XMLHTTP");
	} catch (othermicrosoft) {
		try {
			request2 = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (failed) {
			request2 = null;
		}
	}
}

function setyear() {
	// send out a request to set the current year.
	var sid = Math.floor(Math.random()*10000000);
	var box = document.getElementById("year");
	var year = box.options[box.selectedIndex].value;
	var url = "setyear.php?year=" + escape(year) + "&sid=" + sid;
	request.open("GET",url,true);
	request.onreadystatechange = updateYear;
	request.send(null);	
}

function updateYear() {
	if (request.readyState == 4) {
		window.location.reload( true );
	}
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function getRadioValue(obj) {
	for (x=0;x<obj.length;x++) 
		if (obj[x].checked) return obj[x].value;
	return false;
}

function closepopup() {
	document.getElementById("popup_center").style.display = "none";
	document.getElementById("popup").style.display = "none";
}
function popup() {
	SetDivPosition();
	WindowMngr('popup_center');
	document.getElementById("blackout").style.height = document.getElementById('html').scrollHeight + 'px';
	document.getElementById("blackout").style.width = document.getElementById('html').scrollWidth + 'px';
	document.getElementById("popup").style.display = "block";
	document.getElementById("popup_center").style.display = "block";	
}

function setStyle(obj,style) {
	obj.className = style;
}


function showMultiple(id) {
	for (key in id) {
		show(id[key]);
	}
}
function showhide(id) {
	if (document.getElementById(id).style.display != "block") {
		show(id);
	} else {
		hide(id);
	}	
}
function show(id) {
	if (id=="working") {
		document.getElementById("working_center").className= "working_on";
	} else {
		document.getElementById(id).style.display = "block";
	}
}
function hide(id) {
	if (id=="working") {
		document.getElementById("working_center").className= "working_off";
	} else {
		document.getElementById(id).style.display = "none";
	}
}
function getHeight() {
	var myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) { 
		//Non-IE
		myHeight = window.innerHeight;
	} else {
		if ( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { //IE 6+ in 'standards compliant mode'
			myHeight = document.documentElement.clientHeight;
		} else {
			if ( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { //IE 4 compatible
				myHeight = document.body.clientHeight;
			}
		}
	}

	return myHeight;
}

function SetDivPosition(){
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
		scrOfY+= 100;
	}
	if (scrOfY==0) scrOfY = 100;
	//alert ("set to: " + scrOfY + " cur: " + document.getElementById("popup_center").style.marginTop);
	document.getElementById("popup_center").style.marginTop = (scrOfY-150) + 'px';
}


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 "";
}

function isEmail(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

function isNetID(str) {
   return (str.indexOf(".") == -1) && (str.indexOf("@") == -1);
}

function isIn(val, arr) {
	for(x=0;x<arr.length;x++)
		if((arr[x] == val)) return true;
	return false;
} 


function isNumeric(sText) {
	var ValidChars = "0123456789.";
	var IsNumber=true;
	var Char;

	for (i = 0; i < sText.length && IsNumber == true; i++) { 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) {
			IsNumber = false;
		}
	}
	return IsNumber;
}

function validateString(str,valid) {
	var strValidChars = "0123456789.-";
	var chr;
	
	if (str.length == 0) return false;

	for (i=0;i<str.length;i++) {
		chr = str.charAt(i);
		if (valid.indexOf(chr) == -1) {
			return false;
		}
	}
	return true;
}
