var xmlHttp;
var myWidth=0;
var myHeight=0;

function dumy( result ) {
}

function getWindowSize() {  
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
//  alert(myWidth);
}

function GetResponse( e ,y, m ,command)
{ 
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	 {
	 alert ("Browser does not support HTTP Request")
	 return
	 }
	el=e;		
	var url="agent.php"
	url=url+"?yr="+y
	url=url+"&mo="+m	
	url=url+"&calname="+el.id
	url=url+"&command="+command
	url=url+"&sid="+Math.random()
	//alert(url);

	xmlHttp.onreadystatechange=function ( ) 
	{ 
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	 	{ 
			 //document.getElementById("txtHint").innerHTML=xmlHttp.responseText 
			 e.innerHTML = xmlHttp.responseText;
		 } 
	}

	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function SendFile( el , f , command) {
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	 {
	 alert ("Browser does not support HTTP Request")
	 return
	 }
//  alert(f);
	var url="agent.php"	
	url=url+"&file="+f	
	url=url+"&command="+command
	url=url+"&sid="+Math.random()
	//alert(url);

	xmlHttp.onreadystatechange= function() {
	  if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
	     el.value=xmlHttp.responseText;
	  }
	}
	 
	xmlHttp.open("POST",url,true)
	xmlHttp.send(null)
}

function SendCommand( cmd , param , func , dest) {      
			xmlHttp=GetXmlHttpObject()
			if (xmlHttp==null)
			 {
			 alert ('Browser does not support HTTP Request')
			 return
			 }
		  //alert(a);
		    getWindowSize();
			var url='agent.php'			
			url=url+'?command='+ cmd;
			url=url+'&param='+ param
			url=url+'&mywidth='+myWidth
			url=url+'&myheight='+myHeight
			url=url+'&sid='+Math.random();
		//	alert(url);
			xmlHttp.onreadystatechange= function() {
			  if (xmlHttp.readyState==4 || xmlHttp.readyState=='complete') {
			     return func( xmlHttp.responseText ,dest);  
			  }
			}			 
			xmlHttp.open('GET',url,true)
			xmlHttp.send(null)
}

function AfterLoadPage( result , dest) {				
// alert(result);
 
 switch(dest) {
 	
	  case 0: divActivePage.innerHTML=result;	 
		        break; 	   			 
		case 1: //alert(divPages.innerHTML);
		        divPages.innerHTML=result;
					break;
 }
}

function LoadPage(p, dest) {
    //alert(p);	
		if (dest==null)	dest=0;
		
    dest.innerHTML='Please Wait...';
    SendCommand( 'GETPAGE' , p , AfterLoadPage  ,dest );
}

function AfterLoadForm( result) {				
 //alert(result);
	divForm.innerHTML=result;
  divForm.style.left= 250;//window.screenX+(myWidth-divForm.style.width) / 2;
  divForm.style.top = 100;//window.screenY+(myHeight-divForm.style.Height) / 2;
  
  divForm.style.visibility='visible';	
}

function LoadForm(p,cmd) { 

    getWindowSize();
    divglass.style.width= myWidth;
    divglass.style.height= myHeight;

    divglass.style.visibility='visible';
    divForm.style.visibility='hidden';   
				  
    SendCommand( cmd , p , AfterLoadForm  );
}

function closeForm() {
	divglass.style.visibility='hidden';  
	divForm.style.visibility='hidden';
}
function FormClose() {
	closeForm();
}

function AfterLoadNews(result) {
		 //alert(result);
	var title;
    window.execScript(result);
	//frmedit.news_title.value=title;
}

function LoadNews( nid, lang ) {
//	frmedit.disabled = true;
    var param='1&nid='+nid +'&lang='+lang;
    frmedit.lang.value=lang;
	SendCommand( 'GETNEWS' , param , AfterLoadNews  );		 
}

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;
}