var t = 0;
function nukeCookies(num,x){
var kill_date = new Date("January 1, 1970");
var count = num - 10; 
if(x == 'p'){
	for (i = count; i > count; i--){ document.cookie = i + "=stub;expires=" + kill_date.toGMTString(); }	
}else if(x == 'f'){
	for (i = 0; i < count; i++) { document.cookie = i + "=stub;expires=" + kill_date.toGMTString(); }
}
 }
function GetXmlHttpObject(){
var xmlHttp=null;
		try{ xmlHttp=new XMLHttpRequest();}
		catch(e){ 
		try{ xmlHttp=new ActiveXObject('Msxml2.XMLHTTP');}
		catch(d){ xmlHttp=new ActiveXObject('Microsoft.XMLHTTP');} }
	return xmlHttp;
 }
function link(str,url2,dis,gop,form){
t++; 
var url = 'kitnes.php';
function getformvalues(){
var qstr = '';
if(document.getElementById(form)!==null){ var elem = document.getElementById(form).elements; }
	for(var i = 0; i < elem.length; i++){
	var specialcodeforand = "1234567890123456789012345678901234567890";
	var elemvalue_old = elem[i].value;
	var elemvalue_new = elemvalue_old.replace("&",specialcodeforand);
		if(elem[i].value == ''){
			document.getElementById(elem[i].name).style.backgroundColor='#ffeedd';
		}else if(elem[i].value != ''){
			document.getElementById(elem[i].name).style.backgroundColor='';
		}
		qstr += elem[i].name + '=' + elemvalue_new + '&';
	} 
qstr = qstr+url;
 if(document.getElementById(dis)!==null){ document.getElementById(dis).innerHTML = '<img src="loading.gif"> posting...'; }
return qstr;
 }
	var display=dis;
    var xmlHttp3= new GetXmlHttpObject();
	if(xmlHttp3===null){ alert('Browser does not support HTTP Request'); return; }
	if(str == 'reload'){nukeCookies(9999,'f'); window.location.reload(); return; } 
	  document.cookie = t+'='+str+','+url2+','+dis+','+gop+','+form; 
	  nukeCookies(t,'p');
	url=url+'?q='+str; 
	url=url+'&xcount='+t+'&div='+dis+'&sid='+Math.random();	
	url=url+'&'+url2;
	//alert(url);
		if(gop=='p'){
			xmlHttp3.open('POST',url,true);
		    xmlHttp3.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			//alert(getformvalues());
			xmlHttp3.send(getformvalues()); 
			//alert(url);
		}
		else if(gop=='g'){
		 	if(document.getElementById(dis)!==null){ document.getElementById(dis).innerHTML = '<img src="loading.gif"> requesting...'; }
				if(str.length===0){
			if(document.getElementById(display)!==null){ document.getElementById(display).innerHTML=''; } 
			return;
		 }
			xmlHttp3.open('GET',url,true);
			xmlHttp3.send(null);
		}
    xmlHttp3.onreadystatechange = function(){ 
	if(xmlHttp3.readyState==1){ if(document.getElementById(display)!==null){ document.getElementById(display).innerHTML='<img src="loading.gif"> connecting...'; } }
	if(xmlHttp3.readyState==2){ if(document.getElementById(display)!==null){ document.getElementById(display).innerHTML='<img src="loading.gif"> transferring...'; } }
	if(xmlHttp3.readyState==3){ if(document.getElementById(display)!==null){ document.getElementById(display).innerHTML='<img src="loading.gif"> loading...'; } }
	if(xmlHttp3.readyState==4 || xmlHttp3.readyState=='complete'){
	if(xmlHttp3.status==404){ 
	document.write('<p style="font-family:Georgia; color:#AAAADD">KITNES is undergoing an unscheduled maintenance. Please refresh this page in a few minutes.</p><p style="font-family:Georgia; color:#AAAADD">Any inconvenience caused is deeply regretted.</p>'); 
	setTimeout("link('reload','','main','g','')",10000);	return; }
		if(document.getElementById(display)!==null){
 			document.getElementById(display).innerHTML=xmlHttp3.responseText;
		}
 	} 
 };
 }
function inLink(location,display){
	if(document.getElementById(location) !== null){
    	document.getElementById(location).innerHTML=display;
	}
 }
function process_cookies(){ 
var whole_cookie = document.cookie;
var each_cookie = whole_cookie.split(";");
for (i = 0; i < each_cookie.length; i++){ 
var info = each_cookie[i].split("=");
var link_value = info[1];
var info3 = link_value.split(",");
	var a = info3[0];
	var b = info3[1];
	var c = info3[2];
	var d = info3[3];
	var e = info3[4];
if (a && a !=='' && c && c !==''){ 
	setTimeout("link('"+a+"','"+b+"','"+c+"','g','"+e+"')",0); 
	//setTimeout("inLink('"+a+"','"+c+"')",0);
	}
}
 }
function reLoad(){
	if(document.cookie && document.cookie !==""){ 
		process_cookies(); 
	} 
 }
window.onload = new reLoad();
var int = self.setInterval("link('notifications','','mm2','g','')",18000);
function fileupload(file,db){
document.fileuploadform.action='?q=upload_egn&type='+file+'&sql='+db;
document.getElementById('fileuploadform').target='ano';
document.fileuploadform.submit();
document.fileuploadform.thefile.value='';
 }
function openClose(divName,state){
	if((divName !== null || divName !== '') && (state !== null || state !== '')){
		if(state == 'open'){
			document.getElementById(divName).style.display = 'block';
		} else if(state == 'close'){
			document.getElementById(divName).style.display = 'none';
		}
		/*if((fade !== null || fade !== '')){
			if(fade == 'in'){
				var int3 = self.setTimeout("openClose(divName,fade)",5000);
			} else if(fade == 'out'){
				var int3 = self.setTimeout("openClose('"+divName+"','"+fade+"')",5000);
			} else {
				//do nothing
			}
		}*/
	}
 }
function toggleState(div){
//document.write('<div id="control"><a href="#" onClick="toggleState('+div+'); return false;">show[+]</a></div>');
if(c && c == 'block'){ c = 'none'; }else{ var c = 'none'; }
document.getElementById(div).style.display = c;
//if(c == 'none'){ document.getElementById(div).innerHTML=''; }else{ document.getElementById(div).innerHTML=''; }
 }
function dropDown(event,state){
	if(state!==null || state!==''){
		if(state=='off'){
			document.getElementById('xyPoint').innerHTML='';
		}else if(state=='on'){
			document.getElementById('xyPoint').innerHTML='<div style="z-index:10; background:#CCCCFF; border:1px solid #000000; position:absolute; padding:5px; left:'+event.clientX+'px; top:'+event.clientY+'px" id="dropDown">Menu</div>';
		}
	}
 }
function beforeAfter(x,y){
if(x !== null && y !== null){
	if(x == 'before'){
		document.getElementById(y).style.width='332px'; 
		document.getElementById(y).style.height='400px';
		document.getElementById(y).style.position='fixed';
		document.getElementById(y).style.top='130px';
	}else if(x == 'after'){
		document.getElementById(y).style.width=''; 
		document.getElementById(y).style.height='';
		document.getElementById(y).style.position='';
		document.getElementById(y).style.left='';
	}
 }
 }
function remove(id,div){
	if(confirm("Do you really want to delete this entry?")){
		link('doDelete','id='+id+'&delete','','g','');
		openClose(div,'close');
	}
 }
 
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
 }
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 eraseCookie(name) {
	createCookie(name,"",-1);
 }
