var DHTML = (document.getElementById || document.all || document.layers);

function getObj(name) {
	if (document.getElementById) {
		this.obj = document.getElementById(name);
	} else if (document.all)  {
		this.obj = document.all[name];
	} else if (document.layers)  {
		this.obj = document.layers[name];
	}
	return this.obj;
}

function objExist(name) {
	if (document.getElementById) {
		this.obj = document.getElementById(name);
	} else if (document.all)  {
		this.obj = document.all[name];
	} else if (document.layers)  {
		this.obj = document.layers[name];
	}
	if(this.obj) 
		return true;
	else 
		return false;
}


function divDsp(hideThis,dspState)
{
	if (!DHTML) return;
	var x = new getObj(hideThis);
	x.style.display = (dspState)? (dspState=='inline'?'':dspState) : (x.style.display=='inline'||x.style.display=='') ? 'none' : '';
}


function popup(href,width,height,win_name) {
	    if (!win_name) win_name = 'none';
	    var window_features = "height="+height+",width="+width+",toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,copyhistory=0,dependent=1,top=100,left=100";
		win = window.open(href,win_name,window_features);
		if(win) {win.focus();}
		return false;
}

function selectAll(selectBox){
	for(var i=0;i<selectBox.options.length;i++){
		selectBox.options[i].selected = true;
	}
	return;
}

function unSelectAll(selectBox){
	for(var i=0;i<selectBox.options.length;i++){
		selectBox.options[i].selected = false;
	}
	return;
}

function selectAllChecked(selectBox){
	for(var i=0;i<selectBox.length;i++){
		selectBox[i].checked = true;
	}
	return;
}

function unSelectAllChecked(selectBox){
	for(var i=0;i<selectBox.length;i++){
		selectBox[i].checked = false;
	}
	return;
}

function numOnly(el) {
	return el.value=el.value.replace(/[^0-9.]/g,'');
}

function Highlight(j,color) {
	if(!color) color 	= "#FFF8CB";
	var n 				= null;
	if (j.parentNode && j.parentNode.parentNode) {
		n = j.parentNode.parentNode;
	}
	else if (j.parentElement && j.parentElement.parentElement) {
		n = j.parentElement.parentElement;
	}
	if (n) {
		n.style.backgroundColor = color; //if (n.className == "row-color") {  } //E3F1FF //C1DDF2 //F4F6D3
	}
}

function Unhighlight(j) {
    var n = null;
	if (j.parentNode && j.parentNode.parentNode) {
		n = j.parentNode.parentNode;
	}
	else if (j.parentElement && j.parentElement.parentElement) {
		n = j.parentElement.parentElement;
	}
	if (n) {
		n.style.backgroundColor=n.getAttribute('bgcolor'); //if (n.className == "row-color") {  }
	}
}

function CheckRow(j,color) {
	if (j.checked) {
	    Highlight(j,color);
	} else {
	    Highlight(j,"#ffffff");
	}
}

function DrawMenu(obj,event) {

	thisObj 	= 'toolbar-menu';

	if (!objExist(thisObj)) return;
	var x = new getObj(thisObj);
	
	if (!(x.style.display=='inline' || x.style.display=='')) {
		x.style.display = 'inline';
	}
	
	x.style.position	= "absolute";
	x.style.zIndex 		= obj.style.zIndex + 1;
	
	if (navigator.appName=="Netscape") {
		showX = (event.pageX);
		showY = (event.pageY);
	} else {
		showX = (event.clientX);
		showY = (event.clientY);
	}
	newX = document.body.clientWidth-showX;
	x.style.right = newX;
	x.style.top = showY;
	
	obj.className = 'toolbar-hover';
}

function closeMenu() {
	thisObj 	= 'k-link';
	
	if (!objExist(thisObj)) return;
	var x = new getObj(thisObj);
	x.className = '';
	
	divDsp('toolbar-menu','none');
}
var timer;
function timeoutMenu() {
	timer = setTimeout("closeMenu()",800);
}

function clearMenuTimeout(){
		clearTimeout(timer);
}

function hoverDiv(t,classN) {
	t.className = classN;
}

/*
function InstallTimeout() {
		var sessionTimeout =  (1000*60)*180; //1000*10;
		timer = setTimeout('TimeOut()',sessionTimeout);
	}
	function TimeOut() {
		popLayer('','visible',350,110,80,screen.width,screen.height,'#000000','hidden'); 
		var sessionTimeout =  (1000*60)*5;
		timer2 = setTimeout('location.href=\'?action=do_logout&msg=inactive\'',sessionTimeout);

	}
*/

// AJAX Functionality
//Last Update 7/17/06
function holler(method,url,parameters,callback) {
	method = method.toUpperCase();
	 try{
	    if (window.XMLHttpRequest) {
	        xmlhttp = new XMLHttpRequest();
	    } else if (window.ActiveXObject) {
	        //xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			try {
				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			}
	    }
		
		if(method=="POST"){
			xmlhttp.open(method, url, true);
			xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");//application/x-www-form-urlencoded
			xmlhttp.setRequestHeader("Content-length", parameters.length);//parameters.length
			xmlhttp.setRequestHeader("Connection", "close");
			xmlhttp.send(parameters);
		} else{
			xmlhttp.open(method, url+'&'+parameters, true);
			xmlhttp.send(null);
		}
		
     } catch(e){
	 	alert('Error occurred while trying to process your request');
	 	return;
	 }
	
    xmlhttp.onreadystatechange = function () {
	  		if (xmlhttp.readyState == 4 || xmlhttp.readyState == 'complete') {
				if (xmlhttp.status == 200) {
					eval(callback)
				} else{
					alert('An error occurred while trying to return your request. \nError '+xmlhttp.status+': '+xmlhttp.statusText);
					return;
				}
		    }
		};
	//xmlhttp.setRequestHeader("Content-Length", "66");
}

//Last Update 7/17/06
function hollerBack(method,url,parameters,thisObj,LoadingTxt) {
	 //alert(parameters);
	 method = method.toUpperCase();
	 try{
	    if (window.XMLHttpRequest) {
	        xmlhttp = new XMLHttpRequest();
	    } else if (window.ActiveXObject) {
	        //xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			try {
				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			}
	    }
		
		if(method=="POST"){
			xmlhttp.open(method, url, true);
			xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");//application/x-www-form-urlencoded
			xmlhttp.setRequestHeader("Content-length", parameters.length);//parameters.length
			xmlhttp.setRequestHeader("Connection", "close");
			xmlhttp.send(parameters);
		} else{
			xmlhttp.open(method, url+'&'+parameters, true);
			xmlhttp.send(null);
		}
		
     } catch(e){
	 	alert('Error occurred while trying to process your request');
	 	return;
	 }
	
    xmlhttp.onreadystatechange = function () {
			
		if (objExist(thisObj)) { 
			var x = new getObj(thisObj);
		}

		if (xmlhttp.readyState == 4 || xmlhttp.readyState == 'complete') {

			try {
				x.innerHTML = xmlhttp.responseText;
			} catch (e) {
				alert('An error occurred while trying to return your request. \nError '+e.description);
			}
			
			if (xmlhttp.status != 200) {
				alert('An error occurred while trying to return your request. \nError '+xmlhttp.status+': '+xmlhttp.statusText);
				return;
			}
	    } else{
			
			if(LoadingTxt){
				x.innerHTML = '<div>'+LoadingTxt+'</div>';
			} else {
				x.innerHTML = '<div><b>Loading...</b></div>';
			}
			return;
		}
	};
}

function print_r(obj) {
	big_list = "";
	for (property in obj) {
    	big_list +=property+"="+obj[property]+"\n";
	  }
	alert(big_list);
	return;
}