//Require LoadVars.js

function LinkToDIV(targetDIV, url, onloaded, loadingDIV) {
  var mioLV = new LoadVars();
  mioLV.onLoad = function(s)
  {
   if(s)
   {
	if (loadingDIV && (loadingDIV!=targetDIV)) document.getElementById(loadingDIV).innerHTML ='&nbsp;';
	if (targetDIV) document.getElementById(targetDIV).innerHTML =this.getText();
    if (onloaded) { 
      if(typeof(onloaded) === "function")
    	     onloaded();
      else eval(onloaded); 
    }
   }
   else
   {
	 if (targetDIV) document.getElementById(targetDIV).innerHTML ='Problemi durante il caricamento di '+url;
   }
  }
  if (loadingDIV) document.getElementById(loadingDIV).innerHTML ='<img src="img/loading.gif">';
  mioLV.decodeData =false;
  mioLV.load(url);   
}

function CallLink(url) {
  var mioLV = new LoadVars();
  mioLV.onLoad = function(s)
  {
   if(s)
   {
    dummyvar =this.getText();
   }
   else // problemi durante il caricamento dati
   {
   }
  }
  mioLV.decodeData =false;
  mioLV.load(url);   
}


function LinkToDIV_POST(targetDIV, url, parameters, onloaded, loadingDIV) {
  var mioLV = new LoadVars();
  mioLV.onLoad = function(s)
  {
   if(s)
   {
	if (loadingDIV && (loadingDIV!=targetDIV)) document.getElementById(loadingDIV).innerHTML ='&nbsp;';
    if (targetDIV) document.getElementById(targetDIV).innerHTML =this.getText();
    if (onloaded) { 
      if(typeof(onloaded) === "function")
    	     onloaded();
      else eval(onloaded); 
    }
   }
   else
   {
	   if (targetDIV) document.getElementById(targetDIV).innerHTML ='Problemi durante il caricamento di '+url;
   }
  }
  if (loadingDIV) document.getElementById(loadingDIV).innerHTML ='<img src="img/loading.gif">';
  mioLV.decodeData =false;
  mioLV.loadPOST(url, parameters);   
}

function POST_Form(targetDIV, theForm, onloaded, loadingDIV) {
 if (theForm) {
	var parameters='';
	for (var i=0;i<theForm.length;i++)
	{
		curElem =theForm.elements[i];
		curType  = curElem.type;
		switch (curType) {
		case "text": 
		case "textarea" : parameters = parameters+(curElem.name+"="+curElem.value+"&");
		case "button":break;
		}
	}
	LinkToDIV_POST(targetDIV, theForm.action, parameters, onloaded, loadingDIV);
 }
}