function choose_date(t,m,d,y){
	date = m+'/'+d+'/'+y;
	document.getElementById(t).value=date;
	document.getElementById(t).focus();
}
function PositionLayer(layer,position){
	var screenWidth;
	var screenHeight;
	var scrollTop;
	var scrollLeft;
	if(window.innerHeight){
		screentype = 'window';
		screenWidth = window.innerWidth;
		screenHeight = window.innerHeight;
	}else if(document.documentElement && document.documentElement.clientHeight > 0){
		screentype = 'document.documentElement';
		screenWidth = document.documentElement.clientWidth;
		screenHeight = document.documentElement.clientHeight;
	}else if(document.body.clientHeight){
		screentype = 'document.body';
		screenWidth = document.body.clientWidth;
		screenHeight = document.body.clientHeight;
	}
	if(window.pageYOffset){
		scrollType = 'window';
		scrollTop = window.pageYOffset;
		scrollLeft = window.pageXOffset;
	}else if(document.documentElement.scrollTop){
		scrollType = 'document.documentElement';
		scrollTop = document.documentElement.scrollTop;
		scrollLeft = document.documentElement.scrollLeft;
	}else if(document.body.scrollTop){
		scrollType = 'document.body';
		scrollTop = document.body.scrollTop;
		scrollLeft = document.body.scrollLeft;
	}else{
		scrollTop = 0;
		scrollLeft = 0;
	}
	if(position == 'center'){
		halfScreenWidth = screenWidth/2;
		halfScreenHeight = screenHeight/2;
		halfLayerWidth = document.getElementById(layer).offsetWidth/2;
		halfLayerWidth = Math.round(halfLayerWidth);
		halfLayerHeight = document.getElementById(layer).offsetHeight/2;
		halfLayerHeight = Math.round(halfLayerHeight);
		div_top = (scrollTop+(halfScreenHeight-halfLayerHeight));
		if(div_top < 0){
			div_top = 0;
		}
		document.getElementById(layer).style.left = (scrollLeft+(halfScreenWidth-halfLayerWidth)) + 'px';
		document.getElementById(layer).style.top = div_top + 'px';
	}else if(position == 'mouse'){
	}
}
function setOpacity(startvalue,	endvalue, curvalue){
	if(!curvalue){
		curvalue = startvalue;
	}
	curvalue = eval(curvalue);
	var IE = /*@cc_on!@*/false;
		if(startvalue < endvalue){
			if(IE){
				document.getElementById('BackgroundDiv').style.filter = "alpha(opacity='"+endvalue+"')";
			}else{
				diff = (endvalue - startvalue)/5;
				if(curvalue != endvalue){
					curvalue += diff;
					document.getElementById('BackgroundDiv').style.opacity = curvalue/100;
					setTimeout("setOpacity('"+startvalue+"', '"+endvalue+"', '"+curvalue+"');",5);
				}
			}
		}else{
			if(IE){
				document.getElementById('BackgroundDiv').style.filter = "alpha(opacity='"+endvalue+"')";
				document.getElementById('BackgroundDiv').style.display='none';
			}else{
				diff = (startvalue - endvalue)/5;
				if(curvalue != endvalue){
					curvalue -= diff;
					document.getElementById('BackgroundDiv').style.opacity = curvalue/100;
					setTimeout("setOpacity('"+startvalue+"', '"+endvalue+"', '"+curvalue+"');",5);
				}else{
					document.getElementById('BackgroundDiv').style.display='none';
				}
			}
		}
}
function BackgroundFilter(layer,action){
	//document.getElementById('BackgroundDiv').style.position = "absolute";
	var documentWidth;
	var documentHeight;
	var screenHeight;
	if(window.innerHeight){
		screentype = 'window';
		screenWidth = window.innerWidth;
		screenHeight = window.innerHeight;
	}else if(document.documentElement && document.documentElement.clientHeight > 0){
		screentype = 'document.documentElement';
		screenWidth = document.documentElement.clientWidth;
		screenHeight = document.documentElement.clientHeight;
	}else if(document.body){
		screentype = 'document.body';
		screenWidth = document.body.clientWidth;
		screenHeight = document.body.clientHeight;
	}
	documentWidth = document.body.scrollWidth;
	documentHeight = document.body.scrollHeight;
	if(documentHeight > screenHeight){
		document.getElementById('BackgroundDiv').style.height = documentHeight+"px";
	}else{
		document.getElementById('BackgroundDiv').style.height = screenHeight+"px";
	}
	document.getElementById('BackgroundDiv').style.width = documentWidth+"px";
	if(action == 'open'){
		if(layer == 'ErrorDiv'){
			document.getElementById('BackgroundDiv').style.zIndex = "9998";
			document.getElementById('BackgroundDiv').style.visibility = 'visible';
			document.getElementById('BackgroundDiv').style.display = 'block';
		}else if(layer == 'CalDiv1'){
			document.getElementById('BackgroundDiv').style.zIndex = "3000";
			document.getElementById('BackgroundDiv').style.visibility = 'visible';
			document.getElementById('BackgroundDiv').style.display = 'block';
			setOpacity(0,60);
		}else{
			layerCount = eval(document.getElementById('layerCounter').value) + 1;
			if(layerCount == 1){
				document.getElementById('BackgroundDiv').style.visibility = 'visible';
				document.getElementById('BackgroundDiv').style.display='block';
				setOpacity(0,60);
			}else{
				hello = document.getElementById(layer);
				prevname = hello.getAttribute('prevname');
				if(prevname != null){
					document.getElementById(prevname).style.zIndex = "999";
				}
			}
			document.getElementById('layerCounter').value = layerCount;
		}
	}else if(action == 'close'){
		if(layer == 'ErrorDiv' || layer == 'CalDiv1'){
			document.getElementById('BackgroundDiv').style.zIndex = "1000";
			layerCount = eval(document.getElementById('layerCounter').value);
			if(layerCount == 0){
				setOpacity(60,0);
			}
		}else{
			layerCount = eval(document.getElementById('layerCounter').value) - 1;
			if(layerCount == 0){
				setOpacity(60,0);
			}else{
				hello = document.getElementById(layer);
				prevname = hello.getAttribute('prevname');
				if(prevname != null){
					document.getElementById(prevname).style.zIndex = "1001";
				}
			}
			document.getElementById('layerCounter').value = layerCount;
		}
	}else{
		setOpacity(0,60);
		document.getElementById('BackgroundDiv').style.display='block';
	}
}
function PopLayer(layer,action,url,position,bgmove){

// layer 	= id of the layer
// action 	= 'open', 'close', 'error', or 'change' - action to be performed on the layer
// url 		= '' or 'url' - url of the page to fill the layer with FillLayer
// position = '', 'center', or 'mouse' - position the layer is to pop up at
// bgmove 	= 'true' or 'false' - whether or not the background filter is to affected

	if(bgmove == 'true'){
		BackgroundFilter(layer,action);
	}
	if(url != ''){
		var variableValid = url.indexOf("?");
		if(variableValid > -1){
			url = url+"&dummy=" + new Date().getTime();;
		}else{
			url = url+"?dummy=" + new Date().getTime();;
		}
		FillLayer(layer,action,url,bgmove);
	}
	if(action == 'open'){
		document.getElementById(layer).style.display='block';
	}else if(action == 'close'){
		document.getElementById(layer).style.display='none';
	}
	if(position != ''){
		if(url != ''){
			//alert('Move Me');
			setTimeout("PositionLayer('"+layer+"','"+position+"')",800);
		}else{
			PositionLayer(layer,position);
		}
	}
	if(action == 'open'){
		setTimeout("document.getElementById('"+layer+"').style.visibility='visible'",800);
	}else if(action == 'close'){
		document.getElementById(layer).style.visibility='hidden';
	}
}
function FillLayer(layer,action,url,bgmove) {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
		alert ("Your browser does not support AJAX!");
		return;
	} 
	xmlHttp.onreadystatechange= function() {stChanged(layer,action,bgmove);};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function stChanged(layer,action,bgmove) { 
	if (xmlHttp.readyState==4){
		setAndExecute(layer,xmlHttp.responseText);
		if(action == 'change' && bgmove == 'true'){
			setOpacity(60,0)
		}
	}
}
function setAndExecute(layer, innerHTML) {    
    var div = document.getElementById(layer);    
    div.innerHTML = innerHTML;    
    var x = div.getElementsByTagName("script");     
    for(var i=0;i<x.length;i++)    
    {    
		var code = x[i].text;
		var func = new Function(code);
		func();
    }    
}  

function GetXmlHttpObject() {
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}
