
var len = 100;
var p = document.getElementById('truncateMe');
if (p) {

  var trunc = p.innerHTML;
  if (trunc.length > len) {

    /* Truncate the content of the P, then go back to the end of the
       previous word to ensure that we don't truncate in the middle of
       a word */
    trunc = trunc.substring(0, len);
    trunc = trunc.replace(/\w+$/, '');

    /* Add an ellipses to the end and make it a link that expands
       the paragraph back to its original size */
    trunc += '<a href="#" ' +
      'onclick="this.parentNode.innerHTML=' +
      'unescape(\''+escape(p.innerHTML)+'\');return false;">' +
      '...<\/a>';
    p.innerHTML = trunc;
  }
}



var ricerca_pro;
var objXmlDOM;
function cerca(){
	var valorecampo = document.ricerca.regione.options[document.ricerca.regione.selectedIndex].value;
	if (valorecampo!="") {
	// branch for native XMLHttpRequest object
		if (window.XMLHttpRequest) {
		
			ricerca_pro = new XMLHttpRequest();
			//ricerca_pro.overrideMimeType('text/xml');
			ricerca_pro.onreadystatechange = ricevi;
			ricerca_pro.open("GET", "/inc/menu/cercaprovince.asp?reg="+valorecampo,true);
			ricerca_pro.send(null);
		
			
		// branch for IE/Windows ActiveX version
		} else if (window.ActiveXObject) {
			
		
			ricerca_pro = new ActiveXObject("Microsoft.XmlHttp");
			if (ricerca_pro) {
				ricerca_pro.onreadystatechange = ricevi;
				ricerca_pro.open("GET", "/inc/menu/cercaprovince.asp?reg="+valorecampo,true);
				ricerca_pro.send();
			}
		}
	
	}
	else
	{
	//clearing select
	document.ricerca.localita.options.length = 0;
	document.ricerca.localita.options[i] = new Option('Tutte le località','',true,true);

	}
	
	}
	

function ricevi() {
 var strRes;
 var arrValori;
 if (ricerca_pro.readyState == 4) {
	  strRes = decodeURIComponent(ricerca_pro.responseText);
	  arrValori=strRes.split("|");
	  document.ricerca.localita.options.length=0;
	  for(i=0;i<arrValori.length;i++) {
  	  document.ricerca.localita.options[document.ricerca.localita.options.length] = new Option(arrValori[i].split("|"),arrValori[i].split("|"));
  }
 }
}

function getInferiori(a)
{
	var parametri= "";
	//var a = "";
	var m3_r = Math.floor(Math.random()*99999999999);
	pagina="/inc/default/inferiori.asp";
	parametri="pag=" + a + "&randomid=" + m3_r ;
	// use the generic function to make the request
	doAJAXCall( pagina, 'GET', parametri, showInferioriResponse);
}

	

// The function for handling the response from the server
var showInferioriResponse = function (oXML) { 
    // get the response text, into a variable
    var response = oXML.responseText;
	document.getElementById("VisualizzaInferiori").innerHTML=response;

};


function inviologin(){
	var messaggio="";
	if (document.login.username.value=="" || document.login.username.value=="username") 
	{
	messaggio="Inserire l'username \n";
	}
	if (document.login.password.value=="" || document.login.password.value=="password") 
	{
	messaggio=messaggio + "Inserire la password \n";
	}
	
		
	if (messaggio!="")
	{
		alert(messaggio);
		return false
	}
	else
	{
		getMessage();
	}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


/** XHConn - Simple XMLHTTP Interface - bfults@gmail.com - 2005-04-08        **
 ** Code licensed under Creative Commons Attribution-ShareAlike License      **
 ** http://creativecommons.org/licenses/by-sa/2.0/                           **/
function XHConn()
{
  var xmlhttp, bComplete = false;
  try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
  catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
  catch (e) { try { xmlhttp = new XMLHttpRequest(); }
  catch (e) { xmlhttp = false; }}}
  if (!xmlhttp) return null;
  this.connect = function(sURL, sMethod, sVars, fnDone)
  {
    if (!xmlhttp) return false;
    bComplete = false;
    sMethod = sMethod.toUpperCase();
    try {
      if (sMethod == "GET")
      {
		xmlhttp.open(sMethod, sURL+"?"+sVars, true);
        sVars = "";
      }
      else
      {
        xmlhttp.open(sMethod, sURL, true);
        xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
        xmlhttp.setRequestHeader("Content-Type",
          "application/x-www-form-urlencoded");
      }
      xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4 && !bComplete)
        {
          bComplete = true;
          fnDone(xmlhttp);
        }};
      xmlhttp.send(sVars);
    }
    catch(z) { return false; }
    return true;
  };
  return this;
}

// doAJAXCall : Generic AJAX Handler, used with XHConn
// Author : Bryce Christensen (www.esonica.com)
// PageURL : the server side page we are calling
// ReqType : either POST or GET, typically POST
// PostStr : parameter passed in a query string format 'param1=foo&param2=bar'
// FunctionName : the JS function that will handle the response

var doAJAXCall = function (PageURL, ReqType, PostStr, FunctionName) {

	// create the new object for doing the XMLHTTP Request
	var myConn = new XHConn();

	// check if the browser supports it
	if (myConn)	{
	    
	    // XMLHTTPRequest is supported by the browser, continue with the request
	    myConn.connect('' + PageURL + '', '' + ReqType + '', '' + PostStr + '', FunctionName);    
	} 
	else {
	    // Not support by this browser, alert the user
	    alert("XMLHTTP not available. Try a newer/better browser, this application will not work!");   
	}
}

// launched from button click 
var getMessage = function () {
	// build up the post string when passing variables to the server side page
	var PostStr = "";
	var pagina = "";
	var parametri="";
	var m2_r = Math.floor(Math.random()*99999999999);
	if (document.login.box.checked==false)
	{
		pagina="/inc/login/loginUT.asp";
	}
	else
	{
		pagina="/inc/login/loginBigl.asp";
	}
	
	parametri="username=" + document.login.username.value + "&password=" + document.login.password.value +"&randomid=" + m2_r ;
	// use the generic function to make the request
	doAJAXCall( pagina, 'GET', parametri, showMessageResponse);
}

// The function for handling the response from the server
var showMessageResponse = function (oXML) { 
    
    // get the response text, into a variable
    var response = oXML.responseText;
    
    // update the Div to show the result from the server
	//document.getElementById("responseDiv").innerHTML = response;
	if (response=="AUTENTICATO_VENDITORE")
	{
		document.location.href='/news/avvisi.asp';
		//window.location.reload();
	}
	else if (response=="AUTENTICATO_UTENTE")
	{
		window.location.reload();
	}
	else if (response=="REPORT")
	{
		alert("Nella sua anagrafica mancano alcuni campi obbligatori!");
		document.location.href='/report/dati.asp';
	}
	else
	{
		alert(response);
	}
	
};

function showup(id_of_link,id_of_tab,id_of_link_timeout,id_of_tab_timeout)
{
	//alert(document.getElementById('secondlevel_one'));
	document.getElementById('secondlevel_one').style.display='none';
	document.getElementById('secondlevel_two').style.display='none';
	document.getElementById('secondlevel_three').style.display='none';
	document.getElementById('secondlevel_four').style.display='none';
	
	
	document.getElementById(id_of_link).style.display='block';	
	
	/*document.getElementById('mainlvl_home').className='empty';
	document.getElementById('mainlvl_services').className='empty';
	document.getElementById('mainlvl_attractions').className='empty';
	document.getElementById('mainlvl_contact').className='empty';*/
	
	document.getElementById(id_of_tab).className='selected';
	
	if(id_of_link!=id_of_link_timeout){
		setTimeout(function () 
		{
			showup(id_of_link_timeout, id_of_tab_timeout,id_of_link_timeout, id_of_tab_timeout);
		}, 105000);
	}

}

function inviaRicerca()
{
	document.ricerca.invio.value="ok"
	document.ricerca.action="/cerca/cerca.asp";
	document.ricerca.submit();	
}