
var len = 100;
var p = document.getElementById('truncateMe');
var pathWL;
var idPiantina;
var idEvento;
var idStruttura;
var idAbbonamento;
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=="") 
	{
	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);
}

// launched from button click 
var getMessageRegistrazione = function (p_User, p_Psw) {
	// 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);
	
	pagina="/inc/login/loginUT.asp";
	
	parametri="username=" + p_User + "&password=" + p_Psw +"&randomid=" + m2_r ;
	// use the generic function to make the request
	doAJAXCall( pagina, 'GET', parametri, showMessageResponse);
}

// launched from button click 
var getMessageRegistrazionePetruzzelli = function (p_User, p_Psw) {
	// 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);
	
	pagina="/inc/login/loginUT.asp";
	
	parametri="username=" + p_User + "&password=" + p_Psw +"&randomid=" + m2_r ;
	// use the generic function to make the request
	doAJAXCall( pagina, 'GET', parametri, showMessageResponsePetruzzelli);
}

// launched from button click 
var getMessageRegistrazioneWL = function (p_User, p_Psw, p_Path, p_IdEvento, p_IdPiantina, p_IdStruttura, p_IdAbbonamento) {
	// 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);
	pagina="/inc/login/loginUT.asp";
	pathWL=p_Path;
	if(p_IdEvento!=""&&p_IdPiantina!=""&&p_IdStruttura!="")
	{
		idPiantina=p_IdPiantina;
		idEvento=p_IdEvento;
		idStruttura=p_IdStruttura;
		idAbbonamento=p_IdAbbonamento;
	}
	parametri="username=" + p_User + "&password=" + p_Psw +"&randomid=" + m2_r ;
	// use the generic function to make the request
	doAJAXCall( pagina, 'GET', parametri, showMessageResponseWL);
}

// The function for handling the response from the server
var showMessageResponse = function (oXML) { 
    var response = oXML.responseText;
	
    var vector=response.split("-");
	var Risposta=vector[0];
	
	if (Risposta=="AUTENTICATO_VENDITORE")
	{
		parent.location.href='http://'+ window.location.host + '/asptoaspx.asp?Destpage=avvisi';
	}
	else if (Risposta=="AUTENTICATO_UTENTE")
	{
		parent.location.href='http://' + window.location.host+'/asptoaspx.asp?Destpage=default';
	}
	else if (Risposta=="REPORT")
	{
		alert("Nella sua anagrafica mancano alcuni campi obbligatori!");
		parent.location.href='http://'+ window.location.host +'/asptoaspx.asp?Destpage=dati';
	}
	else
	{
		alert(response);		
	}
	
};

// The function for handling the response from the server
var showMessageResponsePetruzzelli = function (oXML) { 
    var response = oXML.responseText;
	var vector=response.split("-");
	var Risposta=vector[0];
	var IdUtente=vector[1];
	var pathURL=vector[2];
	
	var path="";
	

	if (Risposta=="AUTENTICATO_VENDITORE")
	{
		path=pathURL+"/TeatroPetruzzelli/Default.aspx?TipoUtente=PV&IdUtente="+IdUtente
		document.location.href=path;
	}
	else if (Risposta=="AUTENTICATO_UTENTE")
	{
		path=pathURL+"/TeatroPetruzzelli/Default.aspx?TipoUtente=UT&IdUtente="+IdUtente;
		document.location.href=path;
	}
	else if (Risposta=="REPORT")
	{
		alert("Nella sua anagrafica mancano alcuni campi obbligatori!");
		document.location.href='/report/datiPetruzzelli.asp';
	}
	else
	{
		alert(Risposta);		
	}
	
};

// The function for handling the response from the server
var showMessageResponseWL = function (oXML) { 
    var response = oXML.responseText;
	var vector=response.split("-");
	var Risposta=vector[0];
	var IdUtente=vector[1];
	var pathURL=vector[2];
	
	var path="";
	if (Risposta=="AUTENTICATO_VENDITORE")
	{
		path=pathURL+pathWL+"?Tipo=PV&IdUtente="+IdUtente;
		document.location.href=path;
	}
	else if (Risposta=="AUTENTICATO_UTENTE")
	{
		if(idEvento!=""&&idPiantina!=""&&idStruttura!="")
		{
			if(idAbbonamento!="")
			{
				path=pathURL+pathWL+"?TipoUtente=UT&tipo=abbfisso&IdUtente="+IdUtente+"&abbonamento="+idAbbonamento+"&idpiantina="+idPiantina+"&idstruttura="+idStruttura+"&idevento="+idEvento;
			}
			else
			{
				path=pathURL+pathWL+"?TipoUtente=UT&tipo=big&IdUtente="+IdUtente+"&idpiantina="+idPiantina+"&idstruttura="+idStruttura+"&idevento="+idEvento;
			}
		}
		else
		{
			path=pathURL+pathWL+"?TipoUtente=UT&IdUtente="+IdUtente;
		}
		document.location.href=path;
	}
	else if (Risposta=="REPORT")
	{
		alert("Nella sua anagrafica mancano alcuni campi obbligatori!");
		document.location.href='/report/datiWL.asp';
	}
	else
	{
		alert(Risposta);		
	}
	
};

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(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();	
}
