/*
---------------------------------------------------------------------------------
OVERLAY 
---------------------------------------------------------------------------------
*/
	var close_mybox = function(){
//		$("#lightbox").remove();$("#overlay").remove(); 
		eval("$(\"#" + lightbox +"\").remove();$(\"#overlay\").remove()"); 
		return false;
	}
	
	function close_box(lightbox){
//		$("#lightbox").remove();$("#overlay").remove(); 

		eval("$(\"#" + lightbox +"\").remove();$(\"#overlay\").remove()"); 
		return false;
	}
	
	function mybox( sHtml , bAutoClose, lightbox ) 
	{
		$(document.body).append("<div id='overlay'> </div><div id='" + lightbox + "' class='" + lightbox + "'> </div>")			
			
		//$("#lightbox").html(sHtml).show().css("display","block");
		eval("$(\"#" + lightbox + "\").html(sHtml).show().css(\"display\",\"block\")");
	
	//Parametrizzando la funzione la chiusuta deve essere indicata specificatamente con un link che richiama removeMyBoxManual	
/*		if ( bAutoClose != false ) {
			//$("#overlay").show().click( close_mybox );
			//$("#lightbox a").click(close_mybox);
			//eval("$(\"#" + lightbox +" a\").click(close_box('" + lightbox + "'))");
		}
	*/	
	
	}
	
	function removeMyBoxManual(lightbox)
	{
		eval("$(\"#" + lightbox + "\").remove()");
		$("#overlay").remove(); 
		return false;
	
	}
	
/*
---------------------------------------------------------------------------------
FINE OVERLAY 
---------------------------------------------------------------------------------
*/

/*
---------------------------------------------------------------------------------
UTILITA'
---------------------------------------------------------------------------------
*/

function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
};

/*
---------------------------------------------------------------------------------
FINE UTILITA'
---------------------------------------------------------------------------------
*/

/*
---------------------------------------------------------------------------------
AJAX - Funzione generale 
---------------------------------------------------------------------------------
fun -> funzione da eseguire al ritorno dalla pagina asp
url -> pagina asp da eseguire completa di parametri
*/
function getAjaxObj(fun,url)
{
	http_request = false;
	if (window.XMLHttpRequest) 
	{ // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) 
			http_request.overrideMimeType('text/xml');
	} 
	else if (window.ActiveXObject) 
	{ // IE
		try 
		{
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e) 
		{
			try 
			{
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) 
			{}
		}
	}
	if (!http_request)
	{
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}

	http_request.onreadystatechange = eval(fun);
	http_request.open('GET',url, true);
	http_request.send(null);
}
/*
---------------------------------------------------------------------------------
FINE AJAX 
---------------------------------------------------------------------------------
*/

/*
---------------------------------------------------------------------------------
APERTURA/CHIUSURA DETTAGLIO ELEMENTO
---------------------------------------------------------------------------------
*/
var curr_ide="";
var curr_section="";

function viewDetailElement(ide,section)
{

	var tdclass=document.getElementById('td_desc_'+ide).className
	if(tdclass=='hide')
	{
		//Registra l'ide corrente e la section corrente
		curr_ide=ide;
		curr_section=section;		

		getAjaxObj('viewDetailInDiv','../site/ajax.asp?act=dett&ide='+ide+'&sec='+section);
		$('#tr_desc_'+ide).removeClass("hide")	
	}
	else
	{
		document.getElementById('desc_'+ide).innerHTML='';
		document.getElementById('td_desc_'+ide).className='hide';
		$('#tr_desc_'+ide).addClass("hide")	
	}
}


function viewDetailInDiv()
{
	if (http_request.readyState == 4) {
		if (http_request.status == 200)
		{
			if (http_request.responseText.length>0)
			{
				document.getElementById('desc_'+curr_ide).innerHTML=http_request.responseText;
				if ((curr_section=='lr')||(curr_section=='lj')||(curr_section=='fc')||(curr_section=='fm')||(curr_section=='uu'))
					//document.getElementById('td_desc_'+curr_ide).className='descrizio2';
					document.getElementById('td_desc_'+curr_ide).className='descrizio';
				else
					document.getElementById('td_desc_'+curr_ide).className='descrizio';
			}
		}
	}
}

/*
---------------------------------------------------------------------------------
FINE APERTURA/CHIUSURA DETTAGLIO ELEMENTO
---------------------------------------------------------------------------------
*/

function closeRicerca(pagina)
{
	var sLink='<a href="#" class="ricerca_avanzata" onClick="openRicerca(\'' + pagina + '\');return false;">Ricerca avanzata</a>';
	document.getElementById('ricerca_link').innerHTML=sLink;
	document.getElementById('div_ricerca').innerHTML='';
}

function getSubCategory(categoria)
{
	getAjaxObj('viewSubCategory','ajax.asp?act=subcat&cat='+categoria);
}

function viewSubCategory(){
	if (http_request.readyState == 4) {
		if (http_request.status == 200)
		{
			if (http_request.responseText.length>0)
			{
				document.getElementById('div_sottocategoria').innerHTML=http_request.responseText;				
			}
		}
	}
}

function getProvincia(regione)
{
	getAjaxObj('viewProvincia','ajax.asp?act=prov&reg='+regione);
}

function viewProvincia(){
	if (http_request.readyState == 4) {
		if (http_request.status == 200)
		{
			if (http_request.responseText.length>0)
			{
				document.getElementById('div_provincia').innerHTML=http_request.responseText;				
			}
		}
	}
}

function getProvinciaProfili(regione)
{
	getAjaxObj('viewProvinciaProfili','ajax.asp?act=provp&reg='+regione);
}

function viewProvinciaProfili(){
	if (http_request.readyState == 4) {
		if (http_request.status == 200)
		{
			if (http_request.responseText.length>0)
			{
				document.getElementById('div_provincia_profili').innerHTML=http_request.responseText;				
			}
		}
	}
}

function openRicerca(pagina)
{
	getAjaxObj('viewRicerca','../site/ajax_ricerca.asp?act='+pagina);
}

var cookie_name='carrierain%5Fsearch';
var selSede='selSede=';

function viewRicerca(){
	if (http_request.readyState == 4) {
		if (http_request.status == 200)
		{
			if (http_request.responseText.length>0)
			{
				document.getElementById('ricerca_link').innerHTML='';
				document.getElementById('div_ricerca').innerHTML=http_request.responseText;		
			
				cook=Get_Cookie(cookie_name);
				var start=cook.indexOf(selSede); 
				
				if((!start)||(start==-1))
					sede='zona';
				else
				{
					var len = start+selSede.length;
					var end = cook.indexOf("&",len); 
					var sede=unescape(cook.substring(len,end)); 
					if(!sede)
						sede='zona';
				}
				
				selezioneSede(sede);
			}
		}
	}
}

function Get_Cookie(name) { 
	   var start = document.cookie.indexOf(name+"="); 	   
	   var len = start+name.length+1; 	 
	   if ((!start) && (name != document.cookie.substring(0,name.length))) return null; 
	   if (start == -1) return null; 
	   var end = document.cookie.indexOf(";",len); 
	   if (end == -1) end = document.cookie.length; 
	   return unescape(document.cookie.substring(len,end)); 
} 
	
/*
--------------------------------------------------------------------
Creazione nuovo account
---------------------------------------------------------------------
*/
var curr_step_account=""

function createNewAccount(step)
{
	
	//Richiama la funzione ajax per la gestione della creazione login
	var urlAccount='../site/ajax_account.asp?act='+step;
	curr_step_account=step;
	getAjaxObj('viewFirstBoxAccount',urlAccount);
	
	
}

function viewFirstBoxAccount()
{
	if (http_request.readyState == 4) {
		if (http_request.status == 200)
		{
			if (http_request.responseText.length>0)
			{
				if (curr_step_account=="new")
					mybox(http_request.responseText,true,'lightbox_login');
				if (curr_step_account=="pnew")
					document.location='../my/my_account.asp';
				if (curr_step_account=="anew")
					document.location='../account/account_ins.asp';
			}
		}
	}
}

//Verifica il tipo di login scelto e manda alla pagina giusta
function checkTypeLogin()
{
	var loginpeople=document.frmTypeLogin.rdTipoLogin[0].checked;
	if (loginpeople) 
		createNewAccount("pnew");
	else
		createNewAccount("anew");
}

//Ricerca avanzata
function selezioneSede(selezione) {
	//Abilita i check della zona geografica
    if(selezione=='zona') {
    	document.frm_ricerca.chNord.disabled=false;               
       	document.frm_ricerca.chCentro.disabled=false;
       	document.frm_ricerca.chSud.disabled=false;    
       	document.frm_ricerca.slcRegione1.disabled=true;
       	document.frm_ricerca.slcRegione2.disabled=true;
        document.frm_ricerca.slcRegione3.disabled=true;  
        document.frm_ricerca.slcProvincia1.disabled=true;  
        document.frm_ricerca.slcProvincia2.disabled=true;
     	document.frm_ricerca.slcProvincia3.disabled=true;
     }
     //Abilita le combo delle regioni
     if(selezione=='reg') {   
        document.frm_ricerca.chNord.disabled=true;         
        document.frm_ricerca.chCentro.disabled=true;
        document.frm_ricerca.chSud.disabled=true;    
        document.frm_ricerca.slcRegione1.disabled=false;
        document.frm_ricerca.slcRegione2.disabled=false;
        document.frm_ricerca.slcRegione3.disabled=false;  
        document.frm_ricerca.slcProvincia1.disabled=true;  
        document.frm_ricerca.slcProvincia2.disabled=true;
        document.frm_ricerca.slcProvincia3.disabled=true;
	}
    //Abilita le combo delle provincie
    if(selezione=='prov') {
        document.frm_ricerca.chNord.disabled=true;          
        document.frm_ricerca.chCentro.disabled=true;
        document.frm_ricerca.chSud.disabled=true;    
        document.frm_ricerca.slcRegione1.disabled=true;
        document.frm_ricerca.slcRegione2.disabled=true;
        document.frm_ricerca.slcRegione3.disabled=true;  
        document.frm_ricerca.slcProvincia1.disabled=false;  
        document.frm_ricerca.slcProvincia2.disabled=false;
        document.frm_ricerca.slcProvincia3.disabled=false;
    }
}

			/***********************************************
			* Cool DHTML tooltip script II-  Dynamic Drive DHTML code library (www.dynamicdrive.com)
			* This notice MUST stay intact for legal use
			* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
			***********************************************/
			
			var offsetfromcursorX=12 //Customize x offset of tooltip
			var offsetfromcursorY=10 //Customize y offset of tooltip
			
			var offsetdivfrompointerX=10 //Customize x offset of tooltip DIV relative to pointer image
			var offsetdivfrompointerY=14 //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).
			
			document.write('<div id="dhtmltooltip"><'+'/div>') //write out tooltip DIV
			document.write('<img id="dhtmlpointer" src="../arrow2.gif">') //write out pointer image
			
			var ie=document.all
			var ns6=document.getElementById && !document.all
			var enabletip=false
			if (ie||ns6)
			
				var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""
				var pointerobj=document.all? document.all["dhtmlpointer"] : document.getElementById? document.getElementById("dhtmlpointer") : ""
			
			function ietruebody(){
			return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
			}
			
			function ddrivetip(thetext, thewidth, thecolor){
			if (ns6||ie){
			if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
			if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
			tipobj.innerHTML=thetext
			enabletip=true
			return false
			}
			}
			
			function positiontip(e){
			if (enabletip){
			var nondefaultpos=false
			var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
			var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
			//Find out how close the mouse is to the corner of the window
			var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20
			var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20
			
			var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-e.clientX-offsetfromcursorX
			var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY
			
			var leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-1) : -1000
			
			//if the horizontal distance isn't enough to accomodate the width of the context menu
			if (rightedge<tipobj.offsetWidth){
			//move the horizontal position of the menu to the left by it's width
			tipobj.style.left=curX-tipobj.offsetWidth+"px"
			nondefaultpos=true
			}
			else if (curX<leftedge)
			tipobj.style.left="5px"
			else{
			//position the horizontal position of the menu where the mouse is positioned
			tipobj.style.left=curX+offsetfromcursorX-offsetdivfrompointerX+"px"
			pointerobj.style.left=curX+offsetfromcursorX+"px"
			}
			
			//same concept with the vertical position
			if (bottomedge<tipobj.offsetHeight){
			tipobj.style.top=curY-tipobj.offsetHeight-offsetfromcursorY+"px"
			nondefaultpos=true
			}
			else{
			tipobj.style.top=curY+offsetfromcursorY+offsetdivfrompointerY+"px"
			pointerobj.style.top=curY+offsetfromcursorY+"px"
			}
			tipobj.style.visibility="visible"
			if (!nondefaultpos)
			pointerobj.style.visibility="visible"
			else
			pointerobj.style.visibility="hidden"
			}
			}
			
			function hideddrivetip(){
			if (ns6||ie){
			enabletip=false
			tipobj.style.visibility="hidden"
			pointerobj.style.visibility="hidden"
			tipobj.style.left="-1000px"
			tipobj.style.backgroundColor=''
			tipobj.style.width=''
			}
			}
			
			document.onmousemove=positiontip
