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;
}

// AJAX Functionality
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");
}
function getFormValues(fobj,valFunc) {

	var str 		= "";
	var valueArr 	= null;
	var val 		= "";
	var cmd 		= "";

	for(var i = 0;i < fobj.elements.length;i++) {
		switch(fobj.elements[i].type) {
			case "text":
			case "textarea":
				if(valFunc) {
					//use single quotes for argument so that the value of
                        //fobj.elements[i].value is treated as a string not a literal
                        cmd = valFunc + "(" + 'fobj.elements[i].value' + ")";
                        val = eval(cmd)
				}
                str += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&";
			break;
			case "select-one":
				str += fobj.elements[i].name + "=" + fobj.elements[i].options[fobj.elements[i].selectedIndex].value + "&";
			break;
          }
	}
	str = str.substr(0,(str.length - 1));
	return str;
}

/*
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);

	}
*/