/*
 * File:		ajax.js
 * Description:	AJAX communication object.
 *
 * Usage:		obj = Ajax();
 *				obj.send( <url>, <data string> );
 *				obj.recv();
 *
 *				Override obj.recv() with your own method for receiving data.
 */

/*
 *Talk from a URL to a specific DIV, with a cool loading screen.
 */


// Send Seperate request to reteive Check Value
function getFile(url) 
{
	if (window.XMLHttpRequest) 
	{   AJAX=new XMLHttpRequest();    }// alert('XML');
	else {  AJAX=new ActiveXObject( "Microsoft.XMLHTTP" );  } //alert('AXO');

	if (AJAX) 
	{
     	AJAX.open("GET", url, false);                             
     	AJAX.send(null);
	//	alert('URL : '+url+'\nCEC : '+AJAX.responseText);
    	 return AJAX.responseText;                                         
  	}
	else 
	{ return false;  }                                             
}


function isNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;
 	   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
	 
      if (strValidChars.indexOf(strChar) == -1)
         {
		    blnResult = false;
			//alert ("Reservation fields must contain only numbers!");
         }
      }
	  
   return blnResult;
}
//-------------------------------------------------------------------------------//


 
 function ajaxTalk( from, to )
 {
   
     net = new Ajax();
     
     if(document.getElementById(to))
	 {		var elem = document.getElementById(to)     }
	 else{ 	var elem = window.parent.document.getElementById(to)     }
	 
	 net.recv = function ( data ) { elem.innerHTML = '';  } 
	
     elem.innerHTML = '<table width=100% height=100% cellspacing=0 cellpadding=0 border=0><tr><td width=100% height=100% valign=middle align=center style="font-size:10px;" >Checking</td></tr></table>';
     //alert('FROM : '+from+'\nTO : '+to+'\n');
     net.recv = function ( data ) { elem.innerHTML = data;  } 
     net.send ( from );
  
 }


function tabSend(to, data, type){
	net = new Ajax() ;
	net.send(to, data) ;

	net.recv = function ( return_data ){
		if( return_data == "true"){
			parent.document.getElementById(type).src='index.php?switch=usertabs&action='+type;
		} 
	}
}

save_status = false ;
function set_save_status(value){
	save_status = value ;
}

function post(to, data, return_id){
	net = new Ajax() ;
	net.recv = function ( data ){
		if( data.replace(/^\s+/,"") == "true"){
			getElement(return_id).innerHTML = "Save Successful" ;
			getElement(return_id).bgColor = "#000000" ;
		}else{
			getElement(return_id).innerHTML = "Save Failed" ;
			getElement(return_id).bgColor = "#000000" ;
		}
	}
	net.send(to, data) ;
}
 
//
// Ajax object
//
function Ajax(){
	var xmlHttpReq	= false;
	//alert( "Ajax" );

	// Mozilla/Safari
	if ( window.XMLHttpRequest )
		this.xmlHttpReq = new XMLHttpRequest();

	// IE
	else if ( window.ActiveXObject )
		this.xmlHttpReq = new ActiveXObject( "Microsoft.XMLHTTP" );
	
	//if (window.ie) this.xmlHttpReq.setHeader('If-Modified-Since', 'Sat, 1 Jan 1900 00:00:00 GMT');

	this.send	= networkSend;
	//this.recv	= networkRecv;
}

//
// this.send( url, string );
// sends the string to the url
//
function networkSend( url, data )
{
	var	self = this;

	try {
		self.xmlHttpReq.open( "GET", url, true );
		self.xmlHttpReq.setRequestHeader(	"Content-Type",	"application/x-www-form-urlencoded" );
		self.xmlHttpReq.onreadystatechange = function()
		{
			if ( self.xmlHttpReq.readyState == 4 ) {
				self.recv( self.xmlHttpReq.responseText );
				//alert( self.xmlHttpReq.responseText );
			}
		}
		
		this.xmlHttpReq.send( data );
	} catch(e) {
		alert( "Ajax Error "+e );
	}
}

//
// this.recv( data );
// function stub called when data has been received from the server
// over-ride this method with your own method to handle incoming data
//
function networkRecv( data )
{
	//alert( data );
}

