function confirm_graph(message, callback) {
	$('#confirm').modal({
		closeHTML:"<a href='#' title='Close' class='modal-close'>x</a>",
		position: ["20%",],
		overlayId:'confirm-overlay',
		containerId:'confirm-container',
		opacity:70,
		onShow: function (dialog) {
			$('.message', dialog.data[0]).append(message);

			// if the user clicks "yes"
			$('a#modal_yes', dialog.data[0]).click(function () {
				// call the callback
				if ($.isFunction(callback)) {
					callback.apply();
				}
				// close the dialog
				$.modal.close();
			});
		}
	});
}

function confirm2(callback) {
	$('#gestione_elementi').modal({
		closeHTML:"<a href='#' title='Close' class='modal-close'>x</a>",
		position: ["20%",],
		overlayId:'confirm-overlay',
		containerId:'gestione_elementi-container',
		opacity:70,
		onShow: function (dialog) {
			// if the user clicks "yes"
			$('a#bn_gest_elem_salva', dialog.data[0]).click(function () {
				// call the callback
				if ($.isFunction(callback)) {
					callback.apply();
				}
				// close the dialog
				$.modal.close();
			});
		}
	});
}

function getInternetExplorerVersion() {

    var rv = -1; // Return value assumes failure.

    if (navigator.appName == 'Microsoft Internet Explorer') {

        var ua = navigator.userAgent;

        var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");

        if (re.exec(ua) != null)

            rv = parseFloat(RegExp.$1);

    }

    return rv;

}

function checkVersion() {

    var msg = "You're not using Windows Internet Explorer.";

    var ver = getInternetExplorerVersion();

    if (ver > -1) {

        if (ver >= 8.0)

            msg = "You're using a recent copy of Windows Internet Explorer."

        else

            msg = "You should upgrade your copy of Windows Internet Explorer.";

    }

    alert(msg);

}

version = getInternetExplorerVersion();
var ie7 = (version==7) ? true : false;
//var ie7 = (navigator.appVersion.indexOf("MSIE 7.")==-1) ? false : true;
if (true/*!ie7*/){
fun = ""+
"function alert(msg, callback) {"+
"	$('#alert').modal({                                              "+
"		closeHTML:\"<a href='#' title='Close' class='modal-close'>x</a>\","+
"		position: [\"20%\"],       "+
"		overlayId:'alert-overlay',    "+
"		containerId:'alert-container',"+
"		opacity:70,                "+
"		onShow: function (dialog) {                "+
"			$('.message', dialog.data[0]).append(msg);         "+
"			$('a#modal_ok', dialog.data[0]).click(function () {"+
"				/*									                         "+                       
"				var message_box = document.getElementById('alert_message');"+
"				if (message_box) {           "+
"					message_box.innerHTML = msg;"+
"				} "+
"				*/                                                             "+
"				if (typeof callback != \"undefined\" && $.isFunction(callback)) {"+
"					callback.apply();"+
"				}               "+
"				$.modal.close();"+
"			});                                         "+
"			/*$('.message', dialog.data[0]).append(msg);*/"+
"		}"+ 
"	});"+ 
"}";
eval(fun);
}


function trim(sString) {
	/*
	while (sString.substring(0,1) == ' ') {
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ') {
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
	*/
	return sString.replace(/\s+$|^\s+/g,"");
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function hide_element(element_id) {
	var div_element = document.getElementById(element_id);
	if (div_element) {
		div_element.style.display = 'none';
	}
}
function show_block_element(element_id) {
	var div_element = document.getElementById(element_id);
	if (div_element) {
		div_element.style.display = 'block';
	}
}
function show_element(element_id) {
	var div_element = document.getElementById(element_id);
	if (div_element) {
		div_element.style.display = '';
	}
}
function show_inline_element(element_id) {
	var div_element = document.getElementById(element_id);
	if (div_element) {
		div_element.style.display = 'inline';
	}
}
function hide_show_element(element_id)  {
	var div_element = document.getElementById(element_id);
	if (div_element) {
		if (div_element.style.display == 'none' || div_element.style.display == '') {
			div_element.style.display = 'block';
		}
		else {
			div_element.style.display = 'none';
		}
	}
}
function hide_show_element_if(sel_field, sel_value, target_id)  {
	var div_element = document.getElementById(target_id);
	if (div_element) {
		//if (div_element.style.display == 'none' && sel_field.selectedIndex == sel_value) {
		if (div_element.style.display == 'none' && sel_field.value == sel_value) {
			div_element.style.display = 'block';
		}
		else {
			div_element.style.display = 'none';
		}
	}
}
function goto_url(url) {
	window.location.assign(url);
}
function popup(nomefile, larghezza, altezza, x, y)
{
    win_popup = window.open(nomefile, "", "toolbar= 0,location= 0,directories= 0,status= 0,menubar= 0,scrollbars= 0,resizable= 0,marginheight= 0,marginwidth= 1,copyhistory= 0,width=" + (larghezza+30) + ",height=" + (altezza+60));
    x = parseInt(x);
    y = parseInt(y);
    win_popup.moveTo(x, y);
}
function resize_popup(new_width, new_height, doscroll) { //v2.0
	window.resizeTo(new_width,new_height);
}

function select_menu(menu_handle, menu_id, normal_css_class, select_css_class) {
	for (i=0;i<menu_handle.length; i++) {
		
		var div_output = document.getElementById(menu_handle[i]); 
		if (div_output) { 
			if (menu_handle[i] == menu_id) {
				div_output.className = normal_css_class + ' ' + select_css_class; 
			}
			else {
				div_output.className = normal_css_class; 
			}
		}
	}
}

function select_submenu(element_id, max_element) {
	for (i=1;i<=max_element;i++) {		
		var div_element = document.getElementById('submenu'+i);
		if (div_element) {
			if (i == element_id) {
				div_element.className = 'menu_selected';
			}
			else {
				div_element.className = '';
			}
		}
	}
}

function update_menu_basket_items(num_items) {
	var a_element = document.getElementById('bag_items');
	if (a_element) {
		if (num_items > 0)	
			a_element.innerHTML = num_items
		else 
			a_element.innerHTML = '';
	}
}


function JQuery_initialization() {
	function buttonEnter () {
		$("div#service_bar2").css("display", "none");
		$("div#service_bar").css("display", "block");
		$("div#overlay_wrapper").unbind("mouseleave");
		$("div#overlay_wrapper").unbind("mouseenter");
		$("div#overlay_button a, div#head_overlay").unbind("mouseenter");
		$("div#overlay_wrapper").animate({ 
			top: "-102px",
			opacity: 1
		  }, 500, "swing", animStep1Complete);

	}
	
	function animStep1Complete () {
		$("div#overlay_wrapper").bind("mouseleave", overlayLeave);
		/*
		$("div#overlay_wrapper").unbind("mouseenter");
		$("div#overlay_button a").unbind("mouseenter");
		*/
	}
	
	function overlayLeave () {
		$("div#overlay_wrapper").unbind("mouseleave");
		$("div#overlay_wrapper").animate({ 
			top: "-188px",
			opacity: 1
		}, 500, "swing", animComplete);
	}
	
	function animComplete () {
		$("div#service_bar2").css("display", "block");
		$("div#service_bar").css("display", "none");
		$("div#overlay_button a, div#head_overlay").bind("mouseenter", buttonEnter)
		//$("div#service_bar").css("z-index", "1");
	}
	
	
	function setExpanderTimeout() {
		expander_timeout = setTimeout(expanderEnter, 500);
	}

	function clearExpanderTimeout() {
		clearTimeout(expander_timeout);
	}

	function expanderEnter () {
		$("div#expander_obj").unbind("mouseenter");
		//$("div#expander_obj").unbind("mouseleave");
		$("div#expander_obj div.normal").hide();
		//$("div#expander_obj div.expanded").show();
		$("div#expander_obj").animate({ 
			"height": "140px",
			opacity: 1
		  }, 500, "", expanderStep1Complete);
		$("div#gestione_elementi").animate({ 
			"top": "320px",
			opacity: 1
		  }, 500);
	}
	
	function expanderLeave () {
		clearExpanderTimeout();
		//$("div#expander_obj").unbind("mouseleave");
		$("div#expander_obj").animate({ 
			height: "30px",
			opacity: 1
		}, 500, "", expanderComplete);
		$("div#gestione_elementi").animate({ 
			"top": "210px",
			opacity: 1
		  }, 500);
	}
	
	function expanderStep1Complete () {
		$("div#expander_obj").bind("mouseleave", expanderLeave);
	}

	function expanderComplete () {
		$("div#expander_obj div.normal").show();
		//$("div#expander_obj div.expanded").hide();
		$("div#expander_obj").bind("mouseenter", setExpanderTimeout);
	}
    
	var expander_timeout;
	$(document).ready(function() { 
		$("div#overlay_button a, div#head_overlay").bind("mouseenter", buttonEnter)
		$("div#overlay_wrapper").bind("mouseleave", overlayLeave);
		
		//$("a#typing_prefs").fancybox({ 'overlayShow': true, 'overlayOpacity':0.3, 'frameWidth':760, 'frameHeight':600 } ); 

		$("div#expander_obj").bind("mouseenter", setExpanderTimeout);
		$("div#expander_obj").bind("mouseleave", expanderLeave);

		$('a[rel="external"]')
		.attr("target", "_blank");

		$('a[rel="internal"]')
		.attr("target", "_parent");

		$("#slider_vetrina, #slider_trovalavoro, #slider_serviziaziende, #slider_aziende, #slider_socricerca, #slider_companyfocus, #slider_scuole, #slider_offerte_evidenza").fadeIn();

		$("#slider_vetrina").easySlider({
			auto: true, 
			continuous: true,
			numeric: true,
			speed:700,
			pause:3000,
			numericId: "slider_vetrina_controls",
			nextId: "slider_vetrina_next",
			prevId: "slider_vetrina_prev"
		},1);
		
        $("#slider_scuole").easySlider({
			auto: true, 
			continuous: true,
			numeric: true,
			speed:700,
			pause:3000,
			numericId: "slider_scuole_controls",
			nextId: "slider_scuole_next",
			prevId: "slider_scuole_prev"
		},2);
        
        $("#slider_offerte_evidenza").easySlider({
			auto: true, 
			continuous: true,
			numeric: true,
			speed:1000,
			pause:13000,
			numericId: "slider_offerte_evidenza_controls",
			nextId: "slider_offerte_evidenza_next",
			prevId: "slider_offerte_evidenza_prev"
		},2);
        
		$("#slider_trovalavoro").easySlider({
			auto: true, 
			continuous: true,
			numeric: true,
			speed:1000,
			pause:5000,
			numericId: "slider_trovalavoro_controls",
			nextId: "slider_trovalavoro_next",
			prevId: "slider_trovalavoro_prev"
		});
		
		$("#slider_serviziaziende").easySlider({
			auto: true, 
			continuous: true,
			numeric: true,
			speed:1000,
			pause:5000,
			numericId: "slider_serviziaziende_controls",
			nextId: "slider_serviziaziende_next",
			prevId: "slider_serviziaziende_prev"
		});
	
		$("#slider_aziende").easySlider({
			auto: true, 
			continuous: true,
			numeric: true,
			speed:1000,
			pause:5000,
			numericId: "slider_aziende_controls",
			nextId: "slider_aziende_next",
			prevId: "slider_aziende_prev"
		});

		$("#slider_socricerca").easySlider({
			auto: false, 
			continuous: true,
			numeric: true,
			speed:1000,
			pause:5000,
			numericId: "slider_socricerca_controls",
			nextId: "slider_socricerca_next",
			prevId: "slider_socricerca_prev"
		});

		$("#slider_companyfocus").easySlider({
			auto: false, 
			continuous: true,
			numeric: true,
			speed:1000,
			pause:5000,
			numericId: "slider_companyfocus_controls",
			nextId: "slider_companyfocus_next",
			prevId: "slider_companyfocus_prev"
		});
	
		$("#slider_vetrina ul li a").each(function(i) {

			$(this).bind("mouseenter", {index:i}, function(event) {
				//alert(i);
				offset = $("#slider_vetrina ul li a img").position();	
				//$("div#anteprima_azienda").css("top", (offset.top + $("#slider_vetrina ul li a img").height() / 2) + "px");
				//$("div#anteprima_azienda").css("top", "auto");
				//$("div#anteprima_azienda").fadeIn();
                $("#slider_vetrina").easySlider.do_pause(1);
			})
			$("#slider_vetrina").bind("mouseleave", function() {
                //$(this).easySlider.resume_slider();
				//$("div#anteprima_azienda").fadeOut();
                $("#slider_vetrina").easySlider.do_resume(1);	
			})
												   
		});
        
        $("#slider_scuole ul li a").each(function(i) {

			$(this).bind("mouseenter", {index:i}, function(event) {
				//offset = $("#slider_scuole ul li a img").position();
				//$("div#anteprima_scuole").fadeIn();
                $("#slider_scuole").easySlider.do_pause(2);
			})
			$("#slider_scuole").bind("mouseleave", function() {
                $("#slider_scuole").easySlider.do_resume(2);	
			})
												   
		});

			  

		$("input#cosa").focus(function () { 
			if ($(this).val() == "Che lavoro cerchi?") {
				$(this).val(""); 
				$(this).focus() 
				$("div#suggerimento_iniziale").fadeOut();
				setCookie("suggerimento_iniziale", "visto","30","/");
			}
		})
		$("input#cosa").blur( function () { 
			if ($(this).val() == "") {
				$(this).val("Che lavoro cerchi?") 
			}
		})

		$("input#dove").focus(function () { 
			if ($(this).val() == "Dove?") {
				$(this).val(""); 
				$(this).focus() 
			}
		})
		$("input#dove").blur( function () { 
			if ($(this).val() == "") {
				$(this).val("Dove?") 
			}
		})
		
		//$("div#box").css("display", "none");
		$("div#box").css("visibility", "hidden");
		//$("div#box2").css("display", "none");
		$("div#box2").css("visibility", "hidden");
		//$("div#box3").css("display", "none");
		$("div#box3").css("visibility", "hidden");
		//$("div#box4").css("display", "none");
		$("div#box4").css("visibility", "hidden");

		$("input#i193, input#i203").attr("autocomplete", "off");

		$("input#i193").keyup(function(){ 
			showHint('ric_av_azienda');
		});

		$("input#i203").keyup(function(){ 
			showHint('ric_av_jobtitle');
		});

		$("input#email, input#email_aziende").focus(function () { 
			if ($(this).val() == "Email") {
				$(this).val(""); 
				$(this).focus() 
			}
		})
		$("input#email, input.email_aziende").blur( function () { 
			if ($(this).val() == "") {
				$(this).val("Email") 
			}
		})

		$("input#password, input#password_aziende").focus(function () { 
			if ($(this).val() == "Password") {
				$(this).val(""); 
				$(this).focus() 
			}
		})
		$("input#password, input#password_aziende").blur( function () { 
			if ($(this).val() == "") {
				$(this).val("Password") 
			}
		})
		

		$('a#reset_home').click(function (e) {
			//resetGestioneBox('colsx','/index.php');
			//e.preventDefault();
			// example of calling the confirm function
			// you must use a callback function to perform the "yes" action
			confirm_graph("Attenzione!<br/>Ripristinando le impostazioni iniziali della home page cancellerai tutte le modifiche precedentemente impostate", function () {
				resetGestioneBox('colsx','/index.php');
			});
		});		

		$("a#add_elems").click(function(){ 
			confirm2(function () {
				salvaGestioneBox('/index.php');
			});

			/*
			if ($("div#gestione_elementi").css("display") == "none")  {
					$("div#gestione_elementi").fadeIn("fast");
				}										
				else {
					$("div#gestione_elementi").fadeOut();
				}
				*/
		})
        
        $('a#reset_home_formazione').click(function (e) {
			//resetGestioneBox('colsx','/index.php');
			//e.preventDefault();
			// example of calling the confirm function
			// you must use a callback function to perform the "yes" action
			confirm_graph("Attenzione!<br/>Ripristinando le impostazioni iniziali della home page cancellerai tutte le modifiche precedentemente impostate", function () {
				resetGestioneBox('colsx','/home_formazione.php');
			});
		});
        
        $("a#add_elems_formazione").click(function(){ 
			confirm2(function () {
				salvaGestioneBox('/home_formazione.php');
			});

			/*
			if ($("div#gestione_elementi").css("display") == "none")  {
					$("div#gestione_elementi").fadeIn("fast");
				}										
				else {
					$("div#gestione_elementi").fadeOut();
				}
				*/
		})

		//$("a#add_elems").fancybox({ 'overlayShow': true, 'overlayOpacity':0.8, 'frameWidth':380, 'frameHeight':300 } );		

		$("div.qw_annuncio_wrapper").bind("mouseleave", function () { 
			//$(this).fadeOut();
		})

		$("a#ticker_config").click(function(){ 
			if ($("div#criteri").css("display") == "none")  {
					$("div#criteri").fadeIn();
				}										
				else {
					$("div#criteri").fadeOut();
				}
		})
		

		

	
		
		
		$("#home_sx, #colsx, #home_middle").sortable({cancel: 'div#box_mini2000', cursor: 'crosshair',  helper: 'original', revert: true, revertDuration: 200, axis: 'y', zIndex: 700, opacity: 0.8, update:function(event, ui) { salvaPosizioni($(this).sortable('toArray')) } });
		//$(".boxmini").draggable({containment: "home_sx", cursor: 'crosshair',  helper: 'original', revert: true, revertDuration: 400, axis: 'y', zIndex: 700, stack: { group: 'boxmini', min: 50 } });
		$("#home_sx .boxmini .head, #colsx .boxmini .head, #home_middle .boxmedium .head").bind("mouseenter", function () { $(this).css({"cursor": "move"}) });
		$("#home_sx .boxmini .head, #colsx .boxmini .head, #home_middle .boxmedium .head").qtip(
		   { content: 'SPOSTA questo box', 
		     style: { name: 'cream' }, position: { target: "mouse", x:'20', y:'10' }  });
        $(".box_close").qtip(
		   { content: 'CHIUDI questo box  ', 
		     style: { name: 'cream' }, position: { target: "mouse", x:'20', y:'10' }  });
		$("#tip_gestione_elem").qtip(
		   { content: 'Personalizza la home page selezionando gli elementi che vuoi visualizzare.',
		     style: { name: 'blue' }, position: { target: "mouse", x:'20', y:'10' } });
		$("#tip_reset_elem").qtip(
		   { content: 'Porta lo stato della pagina alla versione originale',
		     style: { name: 'blue' }, position: { target: "mouse", x:'20', y:'10' } });
        $(".redirect").qtip(
		   { content: 'La funzionalit� \'redirect\' aprir� un nuovo sito diverso da talentmanager nel quale potrai procedere con l\'operazione di candidatura.',
		     style: { name: 'cream' }, position: { 
		      corner: {
                 target: 'topLeft',
                 tooltip: 'bottomRight'
              } } });

		$("a.tab_aziende").bind("click", function() {
				loginAziende();
			}
		);
        
        $(".cv_pubblico").qtip(
		   { content: 'Questo tuo curriculum sar� visibile anche alle aziende che ogni giorno cercano candidati nel nostro database di curricula.', 
		     style: { name: 'cream' }, 
             position: { 
		      corner: {
                 target: 'topLeft',
                 tooltip: 'bottomRight'
              }
            }  });
             
        $(".cv_riservato").qtip(
		   { content: 'Il tuo curriculum � registrato nel nostro database ma NON sar� ricercabile e visibile dalle aziende che ricercano direttamente candidati. Potrai comunque utilizzarlo per candidarti agli annunci di lavoro. ', 
		     style: { name: 'cream' }, 
             position: { 
                corner: {
                    target: 'topLeft',
                    tooltip: 'bottomRight'
                } 
             }  });
             
        $(".draggable_tag").qtip(
		   { content: 'Sposta il TAG in una cella a fianco. ', 
		     style: { name: 'cream' }, 
             position: { target: "mouse", x:'20', y:'10' }});
             
        $(".espandi_qtip").qtip(
		   { content: 'Clicca per espandere. ', 
		     style: { name: 'cream' }, 
             position: { target: "mouse", x:'20', y:'10' }});
       
        $(".riduci_qtip").qtip(
		   { content: 'Clicca per ridurre. ', 
		     style: { name: 'cream' }, 
             position: { target: "mouse", x:'220', y:'10' }});

         $(".tc").qtip(
		   { content: '<b>Talent Campus</b><br/><br/>\n\
                               <small>In Talent Campus trovi offerte di lavoro dedicate a LAUREANDI, NEOLAUREATI, candidati alla ricerca del PRIMO IMPIEGO e figure JUNIOR con solo 1 anno d\'esperienza.</small>',
		     style: { name: 'cream' },
                     position: {
                         corner: {
                         target: 'topRight',
                         tooltip: 'bottomLeft'
                         }
                   }
                   }
         );

         $(".tp25").qtip(
		   { content: '<b>Talent Professional 2-5</b><br/><br/>\n\
                               <small>Talent Professional &egrave; il luogo dove trovare offerte di lavoro dedicate a PROFESSIONISTI con almeno 2 anni d\'esperienza e MANAGER qualificati.</small>',
		     style: { name: 'cream' },
                     position: {
                         corner: {
                         target: 'topRight',
                         tooltip: 'bottomLeft'
                         }
                   }
                   }
         );

         $(".tp5").qtip(
		   { content: '<b>Talent Professional 5</b><br/><br/>\n\
                               <small>Talent Professional &egrave; il luogo dove trovare offerte di lavoro dedicate a PROFESSIONISTI con almeno 2 anni d\'esperienza e MANAGER qualificati.</small>',
		     style: { name: 'cream' },
                     position: {
                         corner: {
                         target: 'topRight',
                         tooltip: 'bottomLeft'
                         }
                   }
                   }
         );

		$("a.tab_candidati").bind("click", function() {
				$("div#tab_aziende").hide();
				$("div#tab_candidati").show();

				$("div#login_aziende").hide();
				$("div#login_candidati").show();
                settaSessione("aziende",0);
			}
		);

		/*
		$("a.tab_formazione").bind("click", function() {
				$("div#tab_lavoro").hide();
				$("div#tab_formazione").show();

				$("div#area_lavoro").hide();
				$("div#area_lavoro_classica").hide();
				$("div#area_formazione").show();

				setCookie("tipo_ricerca", "formazione","30","/");
			}
		);
		$("a.tab_lavoro, a.ricerca_innovativa").bind("click", function() {
				//alert($("div#tab_formazione").css('display'));
				$("div#tab_formazione").hide();
				$("div#tab_lavoro").show();

				$("div#area_formazione").hide();
				$("div#area_lavoro_classica").hide();
				$("div#area_lavoro").show();

			 	setCookie("tipo_ricerca", "innovativa","30","/");
			}
		);
		*/
		$("a.ricerca_innovativa").bind("click", function() {
				//alert($("div#tab_formazione").css('display'));
				$("div#tab_formazione").hide();
				$("div#tab_lavoro").show();

				$("div#area_formazione").hide();
				$("div#area_lavoro_classica").hide();
				$("div#area_lavoro").show();

			 	setCookie("tipo_ricerca", "innovativa","30","/");
			}
		);

		$("a.ricerca_classica").bind("click", function() {
				$("div#area_lavoro").hide();
				$("div#area_formazione").hide();
				$("div#area_lavoro_classica").show();
				$("div#suggerimento_iniziale").hide();
			 	setCookie("tipo_ricerca", "classica","30","/");
			}
		);
		
		$("a#close_suggerimento_iniziale").bind("click", function() {
				$("div#suggerimento_iniziale").fadeOut();
				setCookie("suggerimento_iniziale", "visto","30","/");
			}
		);

		$("a#tab_config_criteri_lavoro").bind("click", function() {
				hide_element('criteri_formazione');
				show_block_element('criteri_lavoro');
				$(this).addClass("tab_mini_selected");
				$("a#tab_config_criteri_formazione").removeClass("tab_mini_selected");
			}
		);
		
		$("a#tab_config_criteri_formazione").bind("click", function() {
				hide_element('criteri_lavoro');
				show_block_element('criteri_formazione');
				$(this).addClass("tab_mini_selected");
				$("a#tab_config_criteri_lavoro").removeClass("tab_mini_selected");
			}
		);

	
     //select all the a tag with name equal to modal
	$('a[name=modal]').click(function(e) {
		//Cancel the link behavior
		e.preventDefault();
		
		//Get the A tag
		var id = $(this).attr('href');
	
		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
	
		//Set heigth and width to mask to fill up the whole screen
		$('#mask').css({'width':maskWidth,'height':maskHeight});
		
        var scrolly = getScrollXY();  
        
		//transition effect		
		$('#mask').fadeIn(1000);	
		$('#mask').fadeTo("slow",0.8);	
	
		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();
              
		//Set the popup window to center
		$(id).css('top',  (winH/2-$(id).height()/2)+scrolly);
		$(id).css('left', winW/2-$(id).width()/2);
	
		//transition effect
		$(id).fadeIn(2000); 
	
	});
	
	//if close button is clicked
	$('.window .close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();
		
		$('#mask').hide();
		$('.window').hide();
	});		
	
	//if mask is clicked
	$('#mask').click(function () {
		$(this).hide();
		$('.window').hide();
	});			
		

	}); 

	/*
	// attivare jquery-ui-personalized-1.5.1.min.js e ui.datepicker-it.js in header.php
	var accordions = jQuery('#list1a, #list1b');

	jQuery().ready(function(){
		// simple accordion
		jQuery('#list1a').accordion();
		jQuery('#list1b').accordion({
			autoHeight: false
		});
		$.datepicker.setDefaults({rangeSelect: false});
		$.datepicker.setDefaults($.datepicker.regional['it']);
		$('input#fm_search_date').datepicker(); 

	});
	*/
}

function start_search() {
	document.forms['searchform'].submit();
	/*
	var suggest_select = document.getElementById('suggest_select');
	if (suggest_select) {
		if (suggest_select.selectedIndex < 0) {
			alert('Selezionare un suggerimento e riprovare');
			return;
		}
		hide_element('box');
		var fm_ricerca = document.getElementById('fm_ricerca');
		fm_ricerca.submit();
	}
	else {
		alert('Nessun risultato disponibile');
		return;
	}
	*/
}

function salva_suggeritore_cosa() {
	cosa = document.getElementById('cosa').value;
	funzione = document.getElementById('funzione').selectedIndex;
	settore = document.getElementById('settore').selectedIndex;
	var cat_index = 0;
	do {
		cat = document.getElementById('cat_' + cat_index);
		if (cat) {
			cat_checked = document.getElementById('cat_' + cat_index).checked ? 1 : 0;
			setCookie("suggeritore_cat_" + cat_index, cat_checked ,"30","/");
			cat_index++;
		}
	}
	while (cat);
	hide_element('box');
	setCookie("stato_box", "salvato","30","/");
	setCookie("suggeritore_cosa", cosa,"30","/");
	setCookie("suggeritore_funzione", funzione,"30","/");
	setCookie("suggeritore_settore", settore,"30","/");
	show_inline_element('apri_suggeritore_cosa');
}

function apri_suggeritore_cosa() {
	//document.getElementById('cosa').value = getFirst(getCookie('suggeritore_cosa').replace('[company]', ''));
	cosa = getCookie('suggeritore_cosa');
	// tolgo l'ultimo ; per far aprire il suggeritore
	last_comma = cosa.lastIndexOf(';');
	if (last_comma > 0) {
		cosa = cosa.substr(0,last_comma);
	}
	// tolgo se esiste l'ultimo tag [company] per far aprire il suggeritore
	last_company_tag = cosa.lastIndexOf('[company]');
	if (last_company_tag > 0 && last_company_tag + 9 == cosa.length) {
		cosa = cosa.substr(0,last_company_tag);
	}
	document.getElementById('cosa').value = cosa;
	document.getElementById('funzione').selectedIndex = getCookie('suggeritore_funzione');
	document.getElementById('settore').selectedIndex = getCookie('suggeritore_settore');
	var cat_index = 0;
	do {
		cat = document.getElementById('cat_' + cat_index);
		if (cat) {
			cat.checked = getCookie("suggeritore_cat_" + cat_index) == 1 ? true : false;
			cat_index++;
		}
	}
	while (cat);
	show_block_element("box");
	showHint('cosa');
	document.getElementById('cosa').focus();
}

function salva_suggeritore_dove() {
	dove = document.getElementById('dove').value;
	hide_element('box2');
	setCookie("stato_box2", "salvato","30","/");
	setCookie("suggeritore_dove", dove,"30","/");
	show_inline_element('apri_suggeritore_dove');
}

function apri_suggeritore_dove() {
	dove = getCookie('suggeritore_dove');
	// tolgo l'ultimo ; per far aprire il suggeritore
	last_comma = dove.lastIndexOf(';');
	if (last_comma > 0) {
		dove = dove.substr(0,last_comma);
	}
	document.getElementById('dove').value = dove;
	show_block_element("box2");
	showHint('dove');
	document.getElementById('dove').focus();
}

function loginSubmit() {
	var email_field = document.getElementById('email');
	var pass_field = document.getElementById('password');
	login_ok = email_field.value != "Email" && pass_field.value != "Password";
	if (!login_ok) {
		alert("Specificare email e password e riprovare");
	}
	return login_ok;
}

function loginAziendeSubmit() {
	var email_field = document.getElementById('email_aziende');
	var pass_field = document.getElementById('password_aziende');
	login_ok = email_field.value != "Email" && pass_field.value != "Password";
	if (!login_ok) {
		alert("Specificare email e password e riprovare");
	}
	return login_ok;
}

function link_on_div(div_handle) {
	$(document).ready(function() { 
		$('div#' + div_handle).css({'cursor':'pointer'}); 
		$('div#' + div_handle).bind("click", $('div#' + div_handle + ' a').attr('onclick'));
		$('div#' + div_handle + ' a').click(function(event) { event.stopPropagation(); });
	}); 
}


function expand_collapse_noanim(boxid) {

	var div_box = document.getElementById('boxcontainer_' + boxid);
	if (div_box) {
		if (div_box.style.display == 'none' || div_box.style.display == '') {
			$("div#box_" + boxid).removeClass("collapsed");
		}
		else {
			$("div#box_" + boxid).addClass("collapsed");
		}
	}
}

function expand_collapse_box_annunci(boxid) {



 
Cookie.setData('nrRicerche', ( Cookie.getData('nrRicerche') + 1 ));
Cookie.setData('nrRicerche', ( Cookie.getData('nrRicerche') + 1 ));


  	new Ajax.Updater('preferiti_annunci', 'include_hrweb/ajax_preferiti.php'  ,  {
		method: 'get',
		parameters: {
					id_ut : '<?=$_SESSION["utente_sessione_id"]?>' ,
					id_azione : "anteprimaAnnunci" 	,
                    numero : Cookie.getData('nrPreferitiAnnuncio')  
					},
				    onSuccess: function(transport){

},
										
		evalScripts: true
	});  

expand_collapse_box(boxid) ;



}

function expand_collapse_box(boxid) {




	function oncollapse() {
		//$("a#bn_options_" + boxid).hide();
		$("div#box_" + boxid).addClass("collapsed");
		$("div#box_" + boxid + " .head").removeClass("head_open")
	}
	function onexpand() {
		//$("a#bn_options_" + boxid).show();
		$("div#box_" + boxid).removeClass("collapsed");
	}
		
 	var div_box = document.getElementById('boxcontainer_' + boxid);
 	var main_box = document.getElementById('box_' + boxid);
	if (main_box) {
		var collapsed = main_box.className.indexOf('collapsed') >= 0;
		if (div_box) {
			//alert(document.getElementById("box_" + boxid).className);
			if (collapsed) {
				$("div#box_" + boxid + " .head").addClass("head_open");
				$(div_box).slideDown(200, onexpand);
				var icon_box_open = document.getElementById("box_arrow_open_" + boxid);
				if (icon_box_open) {
					icon_box_open.style.display = 'block';
				}
				var icon_box_close = document.getElementById("box_arrow_close_" + boxid);
				if (icon_box_close) {
					icon_box_close.style.display = 'none';
				}
			}
			else {
				$(div_box).slideUp(200, oncollapse);
				var icon_box_open = document.getElementById("box_arrow_open_" + boxid);
				if (icon_box_open) {
					icon_box_open.style.display = 'none';
				}
				var icon_box_close = document.getElementById("box_arrow_close_" + boxid);
				if (icon_box_close) {
					icon_box_close.style.display = 'block';
				}
			}
		}
	}
}

function expand_collapse_boxmsg(boxid) {
	var div_box = document.getElementById("boxoptions_" + boxid);
	if (div_box) {
		if (div_box.style.display == "block") {
			$("a#bn_options_" + boxid).removeClass("bn_options_pressed")
		}
		else {
			$("a#bn_options_" + boxid).addClass("bn_options_pressed")
		}
	}
	$("div#boxoptions_" + boxid).slideToggle(200);
	
}

function close_box(boxid,check) {
	$("div#box_" + boxid).fadeOut(200);
    $("#setting"+check).attr('checked','');
    new Ajax.Request('/include/azioni_ajax.php' , {
            method: 'get', parameters: {
			close_box  : "s",
            box        : boxid            
		} , asynchronous: false,onSuccess: function(transport) {
		}
	});	
}

function colora(oggetto,overORout,alternato,td){
	var bordo_evidenziato    = "#a7d3fa";
	var bordo_normale        = "#fff";
	var bg_evidenziato       = "#e5effe";
	var bg_normale           = "#fff";
	var bg_normale_alternato = "#eff5fe";
	if (overORout){
		bordo  = bordo_normale;
		sfondo = bg_normale;
		if (alternato)
			sfondo =  bg_normale_alternato;
	}else{
		bordo  = bordo_evidenziato;
		sfondo = bg_evidenziato;
	}
	position   = (oggetto.id).indexOf("|","0"); 
	table_name = (oggetto.id).substring("0",position+1);
	id = (oggetto.id).substring(position+1);
	document.getElementById(table_name+"first"+id).style.borderTop    = "1px solid "+bordo;
	document.getElementById(table_name+"first"+id).style.borderLeft   = "1px solid "+bordo;
	document.getElementById(table_name+"first"+id).style.borderBottom = "1px solid "+bordo;
	document.getElementById(table_name+"first"+id).style.backgroundColor = sfondo;
	
	//lista_middletd = document.getElementsBy(table_name+"middle"+id);
    lista_middletd = new Array();
    for(i=0;i<td; i++){
        lista_middletd[i] = document.getElementById(table_name+"middle"+id+"_"+i);
    }
    
	for(i=0;i<lista_middletd.length; i++)
    {
		oggetto = lista_middletd[i];
		oggetto.style.borderTop    = "1px solid "+bordo;
		oggetto.style.borderBottom = "1px solid "+bordo;
		oggetto.style.backgroundColor = sfondo;
	}
	
	document.getElementById(table_name+"last"+id).style.borderTop    = "1px solid "+bordo;
	document.getElementById(table_name+"last"+id).style.borderRight  = "1px solid "+bordo;
	document.getElementById(table_name+"last"+id).style.borderBottom = "1px solid "+bordo;
	document.getElementById(table_name+"last"+id).style.backgroundColor = sfondo;
}

function colora2(oggetto,overORout,alternato,td){
	var bordo_evidenziato    = "#ffe099";
	var bordo_normale        = "#fff";
	var bg_evidenziato       = "#fbeecf";
	var bg_normale           = "#fff";
	var bg_normale_alternato = "#fdf7e9";
	if (overORout){
		bordo  = bordo_normale;
		sfondo = bg_normale;
		if (alternato)
			sfondo =  bg_normale_alternato;
	}else{
		bordo  = bordo_evidenziato;
		sfondo = bg_evidenziato;
	}
	position   = (oggetto.id).indexOf("|","0"); 
	table_name = (oggetto.id).substring("0",position+1);
	id = (oggetto.id).substring(position+1);
	document.getElementById(table_name+"first"+id).style.borderTop    = "1px solid "+bordo;
	document.getElementById(table_name+"first"+id).style.borderLeft   = "1px solid "+bordo;
	document.getElementById(table_name+"first"+id).style.borderBottom = "1px solid "+bordo;
	document.getElementById(table_name+"first"+id).style.backgroundColor = sfondo;
	
	//lista_middletd = document.getElementsByName(table_name+"middle"+id);
    lista_middletd = new Array();
    for(i=0;i<td; i++){
        lista_middletd[i] = document.getElementById(table_name+"middle"+id+"_"+i);
    }
	for(i=0;i<lista_middletd.length; i++)
    {
		oggetto = lista_middletd[i];
		oggetto.style.borderTop    = "1px solid "+bordo;
		oggetto.style.borderBottom = "1px solid "+bordo;
		oggetto.style.backgroundColor = sfondo;
	}
	
	document.getElementById(table_name+"last"+id).style.borderTop    = "1px solid "+bordo;
	document.getElementById(table_name+"last"+id).style.borderRight  = "1px solid "+bordo;
	document.getElementById(table_name+"last"+id).style.borderBottom = "1px solid "+bordo;
	document.getElementById(table_name+"last"+id).style.backgroundColor = sfondo;
}


function check_form_segnala() {
	var emailamico = document.segnalaForm.email_amico;
	var emailtua   = document.segnalaForm.email_personale;
	var espressione = new RegExp("^([a-zA-Z0-9]+[\.]?[a-zA-Z0-9]+[@]{1}[a-zA-Z0-9]+[\.]{1}[a-zA-Z]{2,4}){1}$");
	
	if (emailamico.value=="" || emailamico.value == "undefined"){
		alert("L'E-Mail del tuo amico � obbligatoria");
		emailamico.focus();
		return false;
	}
	
	if (!espressione.test(emailamico.value)){
	    alert("L'E-Mail del tuo amico non � in un formato valido");
	    emailamico.focus();
        return false;
	}
	
	if (emailtua.value=="" || emailtua.value == "undefined"){
		alert("La tua E-Mail � obbligatoria");
		emailtua.focus();
		return false;
	}
	
	if (!espressione.test(emailamico.value)){
	    alert("La tua E-Mail non � in un formato valido");
	    emailtua.focus();
        return false;
	}
	
	document.segnalaForm.submit();
}

function aggiungiPreferitiAnnuncio(id_an, id_ut,tipo){
    if (typeof tipo == "undefined") tipo = 0;
    new Ajax.Request('/include_hrweb/ajax_preferiti.php' , {
            method: 'get', parameters: {
			id_an : id_an ,
			id_ut : id_ut ,
			id_azione : "aggiungiPreferitiAnnuncio",
            tipo  : tipo            
		} , asynchronous: false,onSuccess: function(transport) {
		        alert("Annuncio aggiunto ai preferiti") ; 
                document.getElementById("preferiti").style.display    = 'none' ;
                document.getElementById("preferiti_sub").style.display = 'block' ;
                showPreferitiAnnunci(true);
                document.getElementById("box_mini1").style.display = "block";
                document.getElementById("box_mini1").className = "boxmini";
		}
	});	
    /*
	new Ajax.Updater('prefAjax', '/include_hrweb/ajax_preferiti.php'  ,  {
		method: 'get',
		parameters: {
					id_an : id_an ,
					id_ut : id_ut ,
					id_azione : "aggiungiPreferitiAnnuncio",
                    tipo  : tipo 	
					},
				    onSuccess: function(transport){
                                //expand_collapse_box_annunci('mini91') ;
								alert("Annuncio aggiunto ai preferiti") ; 
                                document.getElementById("preferiti").style.display    = 'none' ;
                                document.getElementById("preferiti_sub").style.display = 'block' ;
                                showPreferitiAnnunci(true);
                                document.getElementById("box_mini1").style.display = "block";
                                document.getElementById("box_mini1").className = "boxmini";
					    },
										
		evalScripts: true
	});
    */    
}

function rimuoviPreferitiAnnuncio(id_an, id_ut, tipo){
    if (typeof tipo == "undefined") tipo = 0;
	new Ajax.Updater('prefAjax', '/include_hrweb/ajax_preferiti.php'  ,  {
		method: 'get',
		parameters: {
					id_an : id_an ,
					id_ut : id_ut ,
					id_azione : "eliminaPreferitiAnnuncio",
                    tipo  : tipo 	
					},
				    onSuccess: function(transport){
                                //expand_collapse_box_annunci('mini91') ;
								alert("Annuncio rimosso dai preferiti") ; 
                                document.getElementById("preferiti").style.display    = 'block' ;
                                document.getElementById("preferiti_sub").style.display = 'none' ;
                                showPreferitiAnnunci(true);
                                document.getElementById("box_mini1").className = "boxmini";
					    },
										
		evalScripts: true
	});
}

function aggiungiPreferitiAzienda(id_az, id_ut){
	new Ajax.Updater('prefAjax', '/include_hrweb/ajax_preferiti.php'  ,  {
		method: 'get',
		parameters: {
					id_az : id_az ,
					id_ut : id_ut ,
					id_azione : "aggiungiPreferitiAzienda" 	
					},
				    onSuccess: function(transport){
								alert("Azienda aggiunta ai preferiti") ; 
						        document.getElementById("preferiti").style.display    = 'none' ;
                                document.getElementById("preferiti_sub").style.display = 'block' ;
                                showPreferitiAziende(true);
                                document.getElementById("box_mini6").style.display = "block";
                                document.getElementById("box_mini6").className = "boxmini";
					    },
										
		evalScripts: true
	});
}

function rimuoviPreferitiAzienda(id_az, id_ut){
	new Ajax.Updater('prefAjax', '/include_hrweb/ajax_preferiti.php'  ,  {
		method: 'get',
		parameters: {
					id_az : id_az ,
					id_ut : id_ut ,
					id_azione : "eliminaPreferitiAzienda" 	
					},
				    onSuccess: function(transport){
								alert("Azienda rimossa dai preferiti") ; 
						        document.getElementById("preferiti").style.display    = 'block' ;
                                document.getElementById("preferiti_sub").style.display = 'none' ;
                                showPreferitiAziende(true);
                                document.getElementById("box_mini6").className = "boxmini";
					    },
										
		evalScripts: true
	});
}



var show_data      = false;
var show_provincia = false;
var show_settori   = false;
var show_funzioni  = false;
var show = false;
function showhide(id,pos){
	lista_div = document.getElementsByClassName("div");
	for(i=0;i<lista_div.length; i++)
    {
		oggetto = lista_div[i];
        oggetto.setAttribute("style","display:none");
    }
	document.getElementById("div_"+id).style.display="block";
}

function showbox(id){
	show = !show;
	if (show)
		document.getElementById(id).style.display="block";
	else
		document.getElementById(id).style.display="none";
}

function chiudiErefresh(id){
    document.getElementById(id).style.display = "none";
    location.href = location.href;
}

var criteri = new Array();
var criteri_salvati = new Array();
var elenco          = new Array();
var elenco_criteri  = new Array();
criteri[0]  = "province";
criteri[1]  = "funzioni";
criteri[2]  = "settori";

var criteri_f = new Array();
var criteri_salvati_f = new Array();
var elenco_f          = new Array();
var elenco_criteri_f  = new Array();
criteri_f[0]  = "province_f";
criteri_f[1]  = "funzionif";

function salvaCriteri(url){
    new Ajax.Request('/include_hrweb/ajax_ricerca.php' , {
            method: 'get', parameters: {
			elimina_criteri  : 1
		} , asynchronous: false,onSuccess: function(transport) {
			
		}
	});		
    var data = document.getElementsByName("data");
    var valore_data = "";
	for (a=0;a<data.length;a++){
		if(data[a].checked){
		  valore_data = data[a].value;
        }
	}
	new Ajax.Request('/include_hrweb/ajax_ricerca.php' , {
		method: 'get', parameters: {
			salva_criteri  : 1,
			criteri        : 'data',
			valori_criteri : valore_data
		} , asynchronous: false,onSuccess: function(transport) {
			
		}
	});
    
    criteri_salvati[0] = valore_data;
	for	(a=0;a<criteri.length;a++){
		var valori = "";
		var criterio = criteri[a];
		var valore_criterio = document.getElementById(criterio).options;
		var first = true;
		criteri_salvati[a+1] = "";
		for (b=0;b<valore_criterio.length;b++){
			if (valore_criterio[b].selected  ){
				if (first){
					valori = valore_criterio[b].value;
					first = false;
				}
				else
					valori = valore_criterio[b].value+","+valori;
			}
		}
		criteri_salvati[a+1] += valori;
		new Ajax.Request('/include_hrweb/ajax_ricerca.php' , {
			method: 'get', parameters: {
				salva_criteri  : 1,
				criteri        : criterio,
				valori_criteri : valori
			} , asynchronous: false,onSuccess: function(transport) {
				
			}
		});
	}
    
       
    var data = document.getElementsByName("data_f");
    var valore_data = "";
	for (a=0;a<data.length;a++){
		if(data[a].checked){
		  valore_data = data[a].value;
        }
	}
	new Ajax.Request('/include_hrweb/ajax_ricerca.php' , {
		method: 'get', parameters: {
			salva_criteri  : 1,
			criteri        : 'data_f',
			valori_criteri : valore_data
		} , asynchronous: false,onSuccess: function(transport) {
			
		}
	});
    
    var tipologia = document.getElementsByName("tipologia");
    var valore_tipo = "";
	for (a=0;a<tipologia.length;a++){
		if(tipologia[a].checked){
		  valore_tipo = tipologia[a].value;
        }
	}
	new Ajax.Request('/include_hrweb/ajax_ricerca.php' , {
		method: 'get', parameters: {
			salva_criteri  : 1,
			criteri        : 'tipologia',
			valori_criteri : valore_tipo
		} , asynchronous: false,onSuccess: function(transport) {
			
		}
	});
    
    criteri_salvati_f[0] = valore_data;
	for	(a=0;a<criteri_f.length;a++){
		var valori = "";
		var criterio = criteri_f[a];
		var valore_criterio = document.getElementById(criterio).options;
		var first = true;
		criteri_salvati_f[a+1] = "";
		for (b=0;b<valore_criterio.length;b++){
			if (valore_criterio[b].selected  ){
				if (first){
					valori = valore_criterio[b].value;
					first = false;
				}
				else
					valori = valore_criterio[b].value+","+valori;
			}
		}
		criteri_salvati_f[a+1] += valori;
		new Ajax.Request('/include_hrweb/ajax_ricerca.php' , {
			method: 'get', parameters: {
				salva_criteri  : 1,
				criteri        : criterio,
				valori_criteri : valori
			} , asynchronous: false,onSuccess: function(transport) {
				
			}
		});
	}
    
	alert("Salvataggio avvenuto con successo");
	/*
	new Ajax.Updater('','/include_hrweb/ajax_annunci_homepage.php' , {
		method: 'get', parameters: {
			data     : criteri_salvati[0],
			province : criteri_salvati[1],
			settori  : criteri_salvati[2],
			funzioni : criteri_salvati[3],
			op       : 'dati'
		} , asynchronous: false,onSuccess: function(transport) {
			elenco = transport.responseText.split(",");
			for (a=0;a<elenco.length;a++)
				elenco[a] = elenco[a].split("|");

			ul = document.getElementById("ticker_area");
            ul.innerHTML = "";
            codice       = "";
           
			for (a=0;a<elenco.length;a++){
				li = document.createElement("LI");
				ah  = document.createElement("A");
				ah.setAttribute("href","/page.php?include_page=dettaglio_annuncio&titolo="+elenco[a][1]+"&id_annuncio="+elenco[a][0]);
				text = document.createTextNode(elenco[a][2]+" "+elenco[a][1]);
				ah.appendChild(text);
				li.appendChild(ah);
				ul.appendChild(li); 
               // codice += '<li><a href="/page.php?include_page=dettaglio_annuncio&titolo='+elenco[a][1]+'&id_annuncio='+elenco[a][0]+'>'+elenco[a][2]+' '+elenco[a][1]+'</a></li>';
			}
            //ul.innerHTML = "";
            //ul.innerHTML = codice;
		}
	});
    */
}

var testo_ticker = 'Personalizza secondo le tue preferenze cliccando sull�icona ad ingranaggio';

function caricaCriteri(){
	//return;
    elenco = "";
    vuoto = false;        
    new Ajax.Request('/include_hrweb/ajax_ricerca.php' , {
		method: 'get', parameters: {
			recupera_criteri : 1
		} , asynchronous: true,onSuccess: function(transport) {
		    elenco = transport.responseText.split(";");
            count = 0;                   
            for (a=0;a<elenco.length;a++){
                elenco_criteri[a] = elenco[a].split(",");
                
                if (elenco_criteri[a].length==1 && elenco_criteri[a][0]!=""){
                    count++;   
                }                
            } 
            if (elenco.length==count){
                vuoto=true;
            }  
            
            elenco_lavori     = new Array();
            elenco_formazione = new Array();
                         
            //new Ajax.Request('/include_hrweb/ajax_annunci_homepage.php' , {
            new Ajax.Request('/include/azioni_ajax.php' , {
    		method: 'get', parameters: {
    			data     : elenco[0],
    			province : elenco[1],
    			settori  : elenco[3],
    			funzioni : elenco[2],
    			op       : 'dati',
                limit    : 15
    		} , asynchronous: true,onSuccess: function(transport) {
    			elenco_lavori = transport.responseText.split(",");
                new Ajax.Request('/include_hrweb/ajax_ricerca.php' , {
        		method: 'get', parameters: {
        			data     : elenco[4],
        			province : elenco[5],
        			tipologia : elenco[7],
        			funzioni : elenco[6],
                    recupera : 1
        		} , asynchronous: true,onSuccess: function(transport) {
        			elenco_formazione = transport.responseText.split("&&");
                    elenco = elenco_lavori.concat(elenco_formazione);
        			for (a=0;a<elenco_lavori.length;a++){  
                         elenco_lavori[a] = elenco_lavori[a].split("|");
                    }
        
        			ul = document.getElementById("ticker_area");
                    ul.innerHTML = "";
                    
                    testo = "";
                     
        			for (a=0;a<15;a++){ 
        			    if (a>=elenco_lavori.length){
                            break;
                        } 
        			    if((a%5)==0 && a!=0 && vuoto){
                            testo += '<li><a href="javascript: showbox(\'criteri\')">clicca qui per personalizzare questi contenuti</a></li>';
                        } 
                        testo +=  '<li><a href="'+elenco_lavori[a][5]+'" >'+elenco_lavori[a][4] + ' cerca ' + elenco_lavori[a][1]+'</a></li>';
                    }
                        
                    
                        
                    for (a=0;a<elenco_formazione.length;a++){  
                         elenco_formazione[a] = elenco_formazione[a].split("|");
                    }
                    
                    for (a=0;a<15;a++){ 
                        if (a>=elenco_formazione.length){
                            break;
                        }
        			    if (elenco_formazione[a]=="undefined")
                            break;
        			    if((a%5)==0 && a!=0 && vuoto){
                            testo += '<li><a href="javascript: showbox(\'criteri\')">clicca qui per personalizzare questi contenuti</a></li>';
                        } 
                        testo +=  '<li><a href="/dettaglio_annuncio_formazione.php?titolo='+elenco_formazione[a][1]+'&id_anf='+elenco_formazione[a][0]+'" >'+elenco_formazione[a][4] + ' organizza ' + elenco_formazione[a][1]+'</a></li>';
                    }
                    
                    
                    ul.innerHTML = testo;
                    var options = {
            		newsList: "#ticker_area",
            		startDelay: 30,
            		tickerRate: 80,
            		placeHolder1: "_"
            		}
            		$().newsTicker(options);
                    completaFormCriteri();
                    
            		$("#ticker_toolip").qtip(
            		   { content: testo_ticker,
            		     style: { name: 'blue' }, position: { target: "mouse", x:'20', y:'10' } });
                    }
                });
                
            }
            });                    
		}
	});
    
}

function resetCriteri(id,tipo){
    if(tipo==0){
        radio = document.getElementsByName(id);
        for(a=0;a<document.getElementsByName(id).length;a++){
            radio[a].checked = false;
        }
    }else
    if (tipo==1){
        select =  document.getElementById(id).options;
        for(a=0;a<select.length;a++){
            select[a].selected = false;
        }
    }
}

function completaFormCriteri(){
    var criterio = "";
    var testo_criterio = "";
    var radio = document.getElementsByName("data");
    
    var criterio_f = "";
    var testo_criterio_f = "";
    var radio_f = document.getElementsByName("data_f");
    
    if (elenco_criteri[0] == "G"){
        radio[0].checked = true;
        document.getElementById("div_data").style.display = "block";
        testo_ticker = "Data: 'Di oggi'";
    }
    else 
    if (elenco_criteri[0] == "S"){
        radio[1].checked = true;
        document.getElementById("div_data").style.display = "block";
        testo_ticker = "Data: 'Della settimana'";
    }
    else
    if (elenco_criteri[0] == "M"){
        radio[2].checked = true; 
        document.getElementById("div_data").style.display = "block";
        testo_ticker = "Data: 'Di questo mese'";
    }
    for (a=0;a<criteri.length;a++){
        options =  document.getElementById(criteri[a]).options;
        for(i=0;i<options.length;i++){
            if (elenco_criteri[a+1]!=undefined){
            //for(b=0;b<(elenco_criteri[a].length);b++){
                            
                //if (options[i].value==3717) alert(options[i].value+" "+elenco_criteri[a+1]+" "+options[i].selected);
                if (in_array(options[i].value,elenco_criteri[a+1])){
                     switch(a){
                        case 0: 
                        criterio = "<b>Province: </b>"; 
                        document.getElementById("div_province").style.display = "block";
                        testo_criterio += options[i].firstChild.nodeValue+", ";
                        break;
                        case 1:
                        criterio = "<b>Funzione: </b>"; 
                        document.getElementById("div_funzioni").style.display = "block";
                        testo_criterio += options[i].firstChild.nodeValue;
                        break;
                        case 2:
                        criterio = "<b>Settore: </b>"; 
                        document.getElementById("div_settori").style.display = "block";
                        testo_criterio += options[i].firstChild.nodeValue;
                        break;
                     }
                     options[i].setAttribute("selected","selected");
                }
            //}
            }
        }
    }
    
    if(criterio!=""){
        testo_ticker = "<b>Lavoro</b><ul><li>"+criterio+testo_criterio.substring(0,testo_criterio.length-2)+"</li></ul>";    
    }
    
    testo_criterio = "";
    for (a=0;a<criteri_f.length;a++){
        options =  document.getElementById(criteri_f[a]).options;
        for(i=0;i<options.length;i++){
            if (elenco_criteri[a+5]!=undefined){
            //for(b=0;b<(elenco_criteri[a].length);b++){
                            
                //if (options[i].value==3717) alert(options[i].value+" "+elenco_criteri[a+1]+" "+options[i].selected);
                if (in_array(options[i].value,elenco_criteri[a+5])){
                     switch(a){
                        case 0: 
                        criterio = "<b>Province: </b>"; 
                        document.getElementById("div_province_f").style.display = "block";
                        testo_criterio += options[i].firstChild.nodeValue+", ";
                        break;
                        case 1:
                        criterio = "<b>Funzione: </b>";
                        document.getElementById("div_funzioni_f").style.display = "block";
                        testo_criterio += options[i].firstChild.nodeValue;
                        break;
                        case 2:
                        criterio = "<b>Settore: </b>";
                        document.getElementById("div_settori_f").style.display = "block";
                        testo_criterio += options[i].firstChild.nodeValue;
                        break;
                     }
                     options[i].setAttribute("selected","selected");
                }
            //}
            }
        }
    }    
    
    if (criterio!=""){
        testo_ticker += "<b>Formazione</b><ul><li>"+criterio+testo_criterio.substring(0,testo_criterio.length-2)+"</li></ul>";    
    }    
} 


function in_array(thaArray, element){
 var res=false;
  for(var e=0;e<thaArray.length;e++){
     if(thaArray == element[e]){
       res=true;
       break;
     }
   }
 return res;
}










// Gestione Cookie
var Cookie = {
		  data: {},
		  options: {expires: 1, domain: "", path: "", secure: false},

		init: function(options, data) {
		  Cookie.options = Object.extend(Cookie.options, options || {});

		  var payload = Cookie.retrieve();
		        if(payload) {
		            Cookie.data = payload.evalJSON();
		        }
		        else {
		            Cookie.data = data || {};
		        }
		        Cookie.store();
		    },
		    getData: function(key) {
		        return Cookie.data[key];
		    },
		    setData: function(key, value) {
		        Cookie.data[key] = value;
		        Cookie.store();
		    },
		    removeData: function(key) {
		        delete Cookie.data[key];
		        Cookie.store();
		    },
		    retrieve: function() {
		        var start = document.cookie.indexOf(Cookie.options.name + "=");

		        if(start == -1) {
		            return null;
		        }
		        if(Cookie.options.name != document.cookie.substr(start, Cookie.options.name.length)) {
		            return null;
		        }

		        var len = start + Cookie.options.name.length + 1;   
		        var end = document.cookie.indexOf(';', len);

		        if(end == -1) {
		            end = document.cookie.length;
		        } 
		        return unescape(document.cookie.substring(len, end));
		    },
		    store: function() {
		        var expires = '';

		        if (Cookie.options.expires) {
		            var today = new Date();
		            expires = Cookie.options.expires * 86400000;
		            expires = ';expires=' + new Date(today.getTime() + expires);
		        }

		        document.cookie = Cookie.options.name + '=' + escape(Object.toJSON(Cookie.data)) + Cookie.getOptions() + expires;
		    },
		    erase: function() {
		        document.cookie = Cookie.options.name + '=' + Cookie.getOptions() + ';expires=Thu, 01-Jan-1970 00:00:01 GMT';
		    },
		    getOptions: function() {
		        return (Cookie.options.path ? ';path=' + Cookie.options.path : '') + (Cookie.options.domain ? ';domain=' + Cookie.options.domain : '') + (Cookie.options.secure ? ';secure' : '');      
		    }
		};


        function cambiaTab(obj,iddiv,tab,id_po,idlang){
            new Ajax.Request('/include/azioni_ajax.php' , {
			method: 'get', parameters: {
				stampa_contenuto_tab  : 's',
                tab                   : tab,
                id_po                 : id_po,
                idlang                : idlang  
			} , asynchronous: false,onSuccess: function(transport) {
                 for (a=0;a<3;a++){
                    if (a!=1){
                        if (tab == a){
                            document.getElementById('piuc'+a).className="tab_mini tab_mini_selected";   
                        }else{
                            document.getElementById('piuc'+a).className="tab_mini";
                        }
                    }
			     }
			     document.getElementById(iddiv).innerHTML = transport.responseText; 	
			}
            });    
        }
        
        function getScrollXY() {
		  var scrOfX = 0, scrOfY = 0;
		  if( typeof( window.pageYOffset ) == 'number' ) {
		    //Netscape compliant
		    scrOfY = window.pageYOffset;
		    scrOfX = window.pageXOffset;
		  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		    //DOM compliant
		    scrOfY = document.body.scrollTop;
		    scrOfX = document.body.scrollLeft;
		  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		    //IE6 standards compliant mode
		    scrOfY = document.documentElement.scrollTop;
		    scrOfX = document.documentElement.scrollLeft;
		  }
		  return scrOfY ;
	   }  
       

    	function ObjectPosition(obj) {
    	    var curleft = 0;
    	      var curtop = 0;
    	      var top = 0;
    	      if (obj.offsetParent) {				
    	            do {
    	                  curleft += obj.offsetLeft;
    	                  curtop  += obj.offsetTop;
    	                  
    	            } while (obj = obj.offsetParent);
    	      }
    	      return [curleft,curtop];
    	}
        
        function setCookie(name, value, expiredays, path, domain, secure) {
        	var expires = new Date();
        	expires.setDate( expires.getDate() + expiredays );
        	var cookieString = name + "=" +escape(value) +
        	   ( (expires) ? ";expires=" + expires.toGMTString() : "") +
        	   ( (path) ? ";path=" + path : "") +
        	   ( (domain) ? ";domain=" + domain : "") +
        	   ( (secure) ? ";secure" : "");
        	document.cookie = cookieString;
        }
        
        /**
         * Elimina un cookie
         *
         * @example
         *  deleteCookie( 'variabile' );
         *
         */
        function deleteCookie(name, path, domain) {
           if (getCookie(name)) document.cookie = name + "=" +
        	  ( (path) ? ";path=" + path : "") +
        	  ( (domain) ? ";domain=" + domain : "") +
        	  ";expires=Thu, 01-Jan-70 00:00:01 GMT";
        }
        
        /**
         * Restituisce il valore di un cookie
         *
         * @example
         *  var res = getCookie( 'variabile' );
         *
         */
        function getCookie( 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)) );
        }



        function salvaPosizioni(posizioni){
            a=-1;
            found = false;
            prova = "ok";
            for (b=0;b<posizioni.length;b++){
                a++;
                if (posizioni[b]!=""){
                switch(posizioni[b]){
                    // Box mini 
                    case "box_mini50" :
                    prova += "50-"+a+" ";
                    setCookie("colsxpos["+a+"]",0,"30","/");
                    break;
                    case "box_mini60" :
                    prova += "60-"+a+" ";
                    setCookie("colsxpos["+a+"]",1,"30","/");
                    break;
                    case "box_mini01" :
                    prova += "01-"+a+" ";
                    setCookie("colsxpos["+a+"]",2,"30","/");
                    break;
                    case "box_mini1" :
                    prova += "1-"+a+" ";
                    setCookie("colsxpos["+a+"]",3,"30","/");
                    break;
                    case "box_mini6" :
                    prova += "6-"+a+" ";
                    setCookie("colsxpos["+a+"]",4,"30","/");
                    break;
                    case "box_mini300" :
                    prova += "300-"+a+" ";
                    setCookie("colsxpos["+a+"]",5,"30","/");
                    break;
                    case "box_mini22" :
                    prova += "22-"+a+" ";
                    setCookie("colsxpos["+a+"]",6,"30","/");
                    break;
                    // Box mini loggato
                    case "box_mini0" :
                    prova += "0-"+a+" ";
                    setCookie("colsxlpos["+a+"]",0,"30","/");
                    break;
                    case "box_mini9" :
                    prova += "9-"+a+" ";
                    setCookie("colsxlpos["+a+"]",1,"30","/");
                    break;
                    case "box_mini91" :
                    prova += "91-"+a+" ";
                    setCookie("colsxlpos["+a+"]",2,"30","/");
                    break;
                    case "box_mini92" :
                    prova += "92-"+a+" ";
                    setCookie("colsxlpos["+a+"]",3,"30","/");
                    break;
                    case "box_mini5" :
                    prova += "5-"+a+" ";
                    setCookie("colsxlpos["+a+"]",4,"30","/");
                    break;
                    case "box_mini2" :
                    prova += "2-"+a+" ";
                    setCookie("colsxlpos["+a+"]",5,"30","/");
                    break;
                    case "box_mini7" :
                    prova += "7-"+a+" ";
                    setCookie("colsxlpos["+a+"]",6,"30","/");
                    break;
                    case "box_mini8" :
                    prova += "8-"+a+" ";
                    setCookie("colsxlpos["+a+"]",7,"30","/");
                    break;
                    case "box_mini10" :
                    prova += "10-"+a+" ";
                    setCookie("colsxlpos["+a+"]",8,"30","/");
                    break;
                    case "box_mini4" :
                    prova += "4-"+a+" ";
                    setCookie("colsxlpos["+a+"]",9,"30","/");
                    break;
                    case "box_mini010" :
                    prova += "010-"+a+" ";
                    setCookie("colsxlpos["+a+"]",10,"30","/");
                    break;
                    case "box_mini11" :
                    prova += "11-"+a+" ";
                    setCookie("colsxlpos["+a+"]",11,"30","/");
                    break;
                    case "box_mini300l" :
                    prova += "300-"+a+" ";
                    setCookie("colsxlpos["+a+"]",12,"30","/");
                    break;
                    // Box medi
                    case "box_medium2" :
                    if (!found) cancellaCookie();
                    found = true;
                    setCookie("colmiddlepos["+a+"]",0,"30","/");
                    prova += posizioni[b]+" ";
                    break;
                    case "box_medium120" :
                    if (!found) cancellaCookie();
                    found = true;
                    setCookie("colmiddlepos["+a+"]",1,"30","/");
                    prova += posizioni[b]+" ";
                    break;
                    case "box_medium1" :
                    if (!found) cancellaCookie();
                    found = true;
                    setCookie("colmiddlepos["+a+"]",2,"30","/");
                    prova += posizioni[b]+" ";
                    break;
                    case "box_medium100" :
                    if (!found) cancellaCookie();
                    found = true;
                    setCookie("colmiddlepos["+a+"]",3,"30","/");
                    prova += posizioni[b]+" ";
                    break;
                    case "box_medium_p0" :
                    if (!found) cancellaCookie();
                    found = true;
                    setCookie("colmiddlepos["+a+"]",4,"30","/");
                    prova += posizioni[b]+" ";
                    break;
                    // Box medi loggato
                    case "box_medium120l" :
                    if (!found) cancellaCookieL();
                    found = true;
                    setCookie("colmiddlelpos["+a+"]",0,"30","/");
                    prova += posizioni[b]+":"+a+"";
                    break;
                    case "box_medium1001" :
                    if (!found) cancellaCookieL();
                    found = true;
                    setCookie("colmiddlelpos["+a+"]",1,"30","/");
                    prova += posizioni[b]+":"+a+"";
                    break;
                    case "box_medium_pl0" :
                    if (!found) cancellaCookieL();
                    found = true;
                    setCookie("colmiddlelpos["+a+"]",2,"30","/");
                    prova += posizioni[b]+":"+a+"";
                    break;
                    // Box medi formazione
                    case "box_medium_f0" :
                    setCookie("colmiddleformazionepos["+a+"]",1,"30","/");
                    break;
                    case "box_medium_f1" :
                    setCookie("colmiddleformazionepos["+a+"]",2,"30","/");
                    break;
                    case "box_medium_f2" :
                    setCookie("colmiddleformazionepos["+a+"]",3,"30","/");
                    break;
                    case "box_medium_f3" :
                    setCookie("colmiddleformazionepos["+a+"]",4,"30","/");
                    break;
                }
                }else{
                    a--;    
                }
            }
            //alert(prova);
        }

        function cancellaCookie(){
                for (i=0;i<5;i++)
                setCookie("colmiddlepos["+i+"]","","-30","/");
        }

        function cancellaCookieL(){
                for (i=0;i<3;i++)
                setCookie("colmiddlelpos["+i+"]","","-30","/");
        }

        function riempiAnteprimaVetrinaAziende(idaz,toplogo){
            /*
            offset = $("#slider_vetrina ul li a img").position();	
			$("div#anteprima_azienda").css("top", (offset.top + $("#slider_vetrina ul li a img").height() / 2) + "px");
			//$("div#anteprima_azienda").css("top", "auto");
			$("div#anteprima_azienda").fadeIn();
            */
			offset = $("#slider_vetrina").position();
            new Ajax.Request('/include/azioni_ajax.php' , {
                    method: 'get', parameters: {
        			riempi_anteprima  : "s",
                    idaz        : idaz            
        		} , asynchronous: false,onSuccess: function(transport) {
        		  if (transport.responseText=="null"){
        		      //document.getElementById("anteprima_azienda").style.display = "none";
                      $("div#anteprima_azienda").fadeOut();
                      return;
        		  }
        		  topbox = offset.top;
                  topnew = parseInt(topbox)+parseInt(toplogo);
        		  document.getElementById("anteprima_azienda").style.top = topnew+"px";
        		  document.getElementById("anteprima_azienda").innerHTML = transport.responseText;
                  $("div#anteprima_azienda").fadeIn();  
        		}
        	});
            
            chiudiBox("div#anteprima_azienda",10000);
        }
        
        function riempiAnteprimaVetrinaScuole(idaz,toplogo){
			offset = $("#slider_scuole").position();
            new Ajax.Request('/include/azioni_ajax.php' , {
                    method: 'get', parameters: {
        			riempi_anteprima_scuole  : "s",
                    idaz        : idaz            
        		} , asynchronous: false,onSuccess: function(transport) {
        		  topbox = offset.top;
        		  topnew = topbox+parseInt(toplogo);
        		  document.getElementById("anteprima_scuole").style.top = topnew+"px";
        		  document.getElementById("anteprima_scuole").innerHTML = transport.responseText;  
        		}
        	});
            
            chiudiBoxScuole("div#anteprima_scuole",10000);
        }
        
        function chiudiBox(id,secondi){
            if (typeof timbox!="undefined")
                clearTimeout(timbox);
            timbox = setTimeout('$("'+id+'").fadeOut()', secondi);
        }
        
        function chiudiBoxScuole(id,secondi){
            if (typeof timboxscuole!="undefined")
                clearTimeout(timboxscuole);
            timboxscuole = setTimeout('$("'+id+'").fadeOut()', secondi);
        }
        
        function openBox(id,id_icon_close,id_icon_open){
            if(document.getElementById(id).style.display=="none"){
                document.getElementById(id).style.display = "block";
                document.getElementById(id).focus();    
            }else{
                document.getElementById(id).style.display = "none";
            }
            /*
             if (id_icon_close!="" && id_icon_open!=""){
                document.getElementById(id_icon_close).style.display = "none";
                document.getElementById(id_icon_open).style.display  = "block";
             }
             */
        }
        
        function cancellaVoce(elemento){
        	var user = document.getElementById('emaillogin').value ;
        	var pass = document.getElementById('passwordlogin').value ; 
        	if(elemento.value  == "username"){
        		document.getElementById('emaillogin').value  = "" ;
        		//   document.getElementById('username').style.backgroundColor = "white"; 
        		if(document.getElementById('passwordlogin').value  == "")
        		{   document.getElementById('passwordlogin').value  = "password" ;  
        			//  document.getElementById('password').style.backgroundColor = "cccccc"; 
        		}     
        	}
        	if(elemento.value  == "password") {
        		document.getElementById('passwordlogin').value  = "" ;  
        		//  document.getElementById('password').style.backgroundColor = "white"; 
        		if(document.getElementById('emaillogin').value  == "") {   
        			document.getElementById('emaillogin').value  = "username" ;  
        		 // document.getElementById('username').style.backgroundColor = "cccccc"; 
        		}           
        	} 
        }
        
        function settaSessione(id,val){
            new Ajax.Request('/include/azioni_ajax.php' , {
                    method: 'get', parameters: {
        			setta_sessione  : 1,
                    id              : id,
                    val             : val            
        		} , asynchronous: false,onSuccess: function(transport) {
        		}
        	});    
        }
        
        function reset_criteri(){
            document.searchform.cosa.value = "";
            document.searchform.dove.value = "";
            document.searchform.funzione.selectedIndex = 0;
            document.searchform.settore.selectedIndex  = 0;
            document.getElementById("cat_0").checked = false;
            document.getElementById("cat_1").checked = false;
            document.getElementById("cat_2").checked = false;

            hide_element("box");
        }
        
        function nascondiVisualizza(idv,idn){
            obj_v = document.getElementById(idv);
            obj_n = document.getElementById(idn);
            
            obj_v.style.display = "block";
            obj_n.style.display = "none";
        }
        
        function apriQtip(id,testo){
            $("#"+id).qtip({ 
                 content: testo, 
    		     style: { name: 'cream' },
                 position: { target: "mouse", x:'20', y:'10' }  
             });    
        }                        
        
        
        // SCRIPT Ricerca per TAG
        
        var numeroTAG = 0;
        
        function setNumeroTAG(n){
            numeroTAG = n;                    
        }        
                                        
        function controllaDuplicati(tag){
            for (a=0;a<10;a++){
                if (document.getElementById("d"+a).value.toLowerCase() == tag.toLowerCase()){
                    document.getElementById("d"+a).value = "";
                    riempiCloud(a);
                    return;
                }
            }
        }
        
        function pulisciCampo(id){
            text = document.getElementById(id).value;
            document.getElementById(id).value = "";
            id = id.substr(1);
            riempiCloud(id);
            eliminaSelezione(text);
        }
        
        function eliminaSelezione(text3){
            for(a=0;a<numeroTAG;a++){
                if (document.getElementById('p'+a).innerHTML == text3){
                    document.getElementById('p'+a).style.color = "#000";
                }
            }
        } 
        
        function sposta(dir,div){
            if (dir == 1){
                testo = document.getElementById("d"+(div-1)).value;
                document.getElementById("d"+(div-1)).value = document.getElementById("d"+div).value;
                document.getElementById("d"+div).value = testo;
                riempiCloud(div-1);
                riempiCloud(div);
            }else{
                testo = document.getElementById("d"+(div+1)).value;
                document.getElementById("d"+(div+1)).value = document.getElementById("d"+div).value;
                document.getElementById("d"+div).value = testo;
                riempiCloud(div+1);
                riempiCloud(div);
            } 
        }
        
        function riempiCloud(id){
            text2  = document.getElementById('d'+id).value;
            a = document.getElementById('tag'+id);
            value = document.getElementById('d'+id).value;
            a.innerHTML = value;
        }   
        
               
        
        //-- END Ricerca per TAG
        
        window.onload=function(){caricaCriteri()};