/*
* 2011 POOEL PROJECTS - Pooel-WA 
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to info@pooel.it so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Pooel-WA to newer
* versions in the future. If you wish to customize Pooel-WA for your
* needs please refer to http://www.pooel.it for more information.
*
*  @author Pooel <info@pooel.it>
*  @copyright  2007-2011 Pooel
*  @version  Release: 1.0
*  @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
*/
// TEXT REQUEST GET & POST

function textRequestGet(nameUrl,nameDiv,callback) { 
      if(POO){clearTimeout(POO.loop);POO=null;}

      var div = document.getElementById(nameDiv);
      div.style.background='url(images/ajax-loader.gif) no-repeat center center #eee';
      var ajax = assegnaXMLHttpRequest(), elemento = prendiElementoDaId(nameDiv),usaLink = true;
      elemento.innerHTML ="";
    
      if(ajax) {
    
	usaLink = false;
	nameUrl = varJS['server_url']+nameUrl;
    
	ajax.open("get", nameUrl, true);
    
	ajax.onreadystatechange = function() {
    
	  if(ajax.readyState === readyState.COMPLETATO) {
    
	    if(statusText[ajax.status] === "OK")
		    {
	      // success!
		      div.style.opacity=0;
		      elemento.innerHTML = ajax.responseText;
		      if(!elemento.innerHTML=="")
		      {
			div.style.background='none';
			Alpha =new OpacityTween(div,Tween.regularEaseOut, 0, 100, 1,'px');
			Alpha.start();
			if(document.getElementsByTagName('var')[0]!=null)
			{
			  for(i=0;i<document.getElementsByTagName('var').length;i++){
			  var src = document.getElementsByTagName('var')[i].innerHTML; 
			  eval(src);
			  }
			}
			if(callback!=null)eval(callback);
		      }
		      else{
			div.style.background='none';
			div.innerHTML = 'no result';
		      }
		      
		    }
	    else {
    
	      elemento.innerHTML = "Waiting ...";
	      //elemento.innerHTML += "Error: " + statusText[ajax.status];
	    }
	  } 
	}
    
    
	ajax.send(null);
      }
       
      return usaLink;
}

function textRequestPost(url,params,div,callback){
      var content = document.getElementById(div);
      content.style.background='url(images/ajax-loader.gif) no-repeat center center #eee';
      
      var http = new XMLHttpRequest();
      http.open("POST", url, true);
      
      //Send the proper header information along with the request
      http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      //http.setRequestHeader("Content-length", params.length);
      //http.setRequestHeader("Connection", "close");
      
      http.onreadystatechange = function() {//Call a function when the state changes.
	      if(http.readyState == 4 && http.status == 200) {
		      content.style.background='none';
		      content.innerHTML = http.responseText;
	      }
	      else{
		  content.style.background='none';
		  content.innerHTML ='<br>Waiting ...'
	      }
      }
      http.send(params);

}

