/*obj browser detection */
function Is ()
{   
				var agt=navigator.userAgent.toLowerCase();
    this.major = parseInt(navigator.appVersion);
    this.minor = parseFloat(navigator.appVersion);
    this.nav  = ((agt.indexOf('mozilla')!=-1) && ((agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1)));
    this.nav2 = (this.nav && (this.major == 2));
    this.nav3 = (this.nav && (this.major == 3));
				
    this.ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));

    this.ie6     = (this.ie && (this.major == 4) && (agt.indexOf ("msie 6.") != -1));
    this.vms   = (agt.indexOf("vax")!=-1) || (agt.indexOf("openvms")!=-1);
				this.chr = agt.indexOf('chrome') > -1;
}
var is = new Is(); 
//if (is.nav) {  ... navigator code here ... }
//else if (is.ie) {  ... explorer code here ... }


getViewportWidth = function() {
  var width=0;
  if( document.documentElement && document.documentElement.clientWidth ) {
    width = document.documentElement.clientWidth;
  }
  else if( document.body && document.body.clientWidth ) {
    width = document.body.clientWidth;
  }
  else if( window.innerWidth ) {
    width = window.innerWidth - 18;
  }
  return width;
}
getViewportHeight = function() {
  var height=0;
  if( document.documentElement && document.documentElement.clientWidth ) {
    height = document.documentElement.clientHeight;
  }
  else if( document.body && document.body.clientHeight ) {
    height = document.body.clientHeight;
  }
  else if( window.innerHeight ) {
    height = window.innerHeight;
  }
  return height;
}

//obj screen resolution 
function myscreen(){
var	width = getViewportWidth();
			if (width < 900){
				  width = "800";
			}else if (width < 1025){
			   width= "1024";
			}else if (width > 1025){
			   width= "1280";
			}else {width = "";	
			}
			return width ;
}


//win popup
function popWin( url, name, width, height, scroller ) {
	var outStr = 'height=' + height + ',width=' + width;
	if (scroller == true) {	outStr = outStr + ',menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes';} 
	else if (scroller == false) {	outStr = outStr + ',menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no';} 
	else {	outStr = outStr +',menubar=yes,toolbar=yes,location=yes,directories=yes,status=yes,scrollbars=yes,resizable=yes';
	}newWindow=window.open(url, name, outStr);
}

function showonlyone(thechosenone) {
      var newboxes = document.getElementsByTagName("div");
            for(var x=0; x<newboxes.length; x++) {
                  name = newboxes[x].getAttribute("name");
                  if (name == 'newboxes') {
                        if (newboxes[x].id == thechosenone) {
                        newboxes[x].style.display = 'block';
                  }
                  else {
                        newboxes[x].style.display = 'none';
                  }
            }
      }
}

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 trovAzione(rubriche_id, macro) {		
		
		var strURL="/azione_singola.php?rubriche_id="+rubriche_id+'&ms=' + new Date().getTime();
		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=\"/img/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 trovAzioneNew(rubriche_id_nuovo, macro) {		
		
		var strURL="/azione_nuovo.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=\"/img/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 trovAzioneAv(rubriche_id_nuovo, macro) {		
		
		var strURL="/azione_avanzata.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_tre').innerHTML="<div align=\"center\" style=\"padding:20px\"><img src=\"/img/ajax-loader.gif\"></div>";
				} 

				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {						
						document.getElementById('azione_tre').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;
    }
  }

