// JavaScript Document
function getXMLHTTP() { //fuction to return the xml http object
		var xmlhttp=false;	
		try{
			xmlhttp=new XMLHttpRequest();
		}
		catch(e)	{		
			try{			
				xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e){
				try{
				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch(e1){
					xmlhttp=false;
				}
			}
		}
		 	
		return xmlhttp;
    }
	
	function cambiAnnunci(macro) {		
		
		var strURL="/annunci_home.php?macro_id="+macro;
		var req = getXMLHTTP();
		document.getElementById('ajax').innerHTML = "<div aling=\"center\" style=\"width:100%\"><img src=\"/layout/ajax-loader.gif\" style=\"margin-top:15px\"></div>";
		
		if (req) {
					
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {					
					document.getElementById('ajax').innerHTML=req.responseText;						
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}		
	}
	
	function trovAzione(rubriche_id, macro) {		
		
		var strURL="/azione_singola.php?rubriche_id="+rubriche_id;
		var req = getXMLHTTP();
		
		if (req) {
			
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {						
						document.getElementById('azione_'+macro).innerHTML=req.responseText;						
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}		
	}
	
	
	function trovAzioneIn(rubriche_id_nuovo, macro) {		
		
		var strURL="/azione.php?rubriche_id="+rubriche_id_nuovo+'&ms=' + new Date().getTime();
		var req = getXMLHTTP();


		if (req) {
			
		req.onreadystatechange = function() {
				   
			   if (req.readyState==1) {//Loading 
				document.getElementById('azione_in').innerHTML="<div align=\"center\" style=\"padding:20px\"><img src=\"/layout/ajax-loader.gif\"></div>";
				} 

				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {						
						document.getElementById('azione_in').innerHTML=req.responseText;						
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}		
	}


function valida(form)
{
	
     if (document.form.rubriche_id.value.length == 0) {
		alert("Prego selezionare la RUBRICA");
		document.form.rubriche_id.focus();
		return false;
	}

return true;
}	


function selectURL(nexturl) {
 	if (nexturl != "") {
		  window.top.location.href = nexturl;
	 }
	}
	
	
var maxchars=300;

function CheckLength()
  {
  with (document.form)
    {
    chars=annuncio.value
    if (chars.length > maxchars)
      {
      annuncio.value=chars.substr(0,maxchars);
      annuncio.blur();     }
    chr.value=maxchars-annuncio.value.length;
    }
  }
