// JavaScript Document
function JQuery_initialization() {
	jQuery(document).ready(function() { 
									
		jQuery("a.tab_candidati").bind("click", function() {
				//jQuery("div#tab_aziende").hide();
				//jQuery("div#tab_candidati").show();

				jQuery("div#login_aziende").hide();
				jQuery("div#login_candidati").show();
			}
		);

		jQuery("a.tab_aziende").bind("click", function() {
				//jQuery("div#tab_aziende").hide();
				//jQuery("div#tab_candidati").show();

				jQuery("div#login_candidati").hide();
				jQuery("div#login_aziende").show();
				jQuery("div#separator_myarea_azienda").show();
			}
		);

	}); 
	
}

function addslashes(str) {
	str=str.replace(/\\/g,'\\\\');
	str=str.replace(/\'/g,'\\\'');
	str=str.replace(/\"/g,'\\"');
	str=str.replace(/\0/g,'\\0');
	return str;
}
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 doSubmit(form_name) {
	form = document.getElementById(form_name);
	if (form) {
		form.submit();
	}
}

function cancellaVoce(elemento){
	var user = document.getElementById('email').value ;
	var pass = document.getElementById('password').value ; 
	if(elemento.value  == "username"){
		document.getElementById('email').value  = "" ;
		//   document.getElementById('username').style.backgroundColor = "white"; 
		if(document.getElementById('password').value  == "")
		{   document.getElementById('password').value  = "password" ;  
			//  document.getElementById('password').style.backgroundColor = "cccccc"; 
		}     
	}
	if(elemento.value  == "password") {
		document.getElementById('password').value  = "" ;  
		//  document.getElementById('password').style.backgroundColor = "white"; 
		if(document.getElementById('email').value  == "") {   
			document.getElementById('email').value  = "username" ;  
		 // document.getElementById('username').style.backgroundColor = "cccccc"; 
		}           
	} 
}

function cambiaPagina(pag){
	document.ricercaForm.paginaScelta.value=pag;
	document.ricercaForm.submit();
}

function dettaglioAnnuncio(id_an){
	document.ricercaForm.action='dettaglio_annuncio.php';
	document.ricercaForm.id_an.value=id_an;
	document.ricercaForm.submit();
}

function clean(){
	if(document.getElementById('descrizioneJA').value == 'Avvisami quando viene inserito un annuncio'){
		document.getElementById('descrizioneJA').value = '';
	}
}

function check_form_segnala() {
	// prendo i riferimenti ai campi
	var id_an = document.getElementById("id_an");
	
	var field_required = new Array('email_amico', 'email_personale');
	
	for (i=0;i<field_required.length;i++) {
		var field_handle = document.getElementById(field_required[i]);
		var field_label_handle = document.getElementById(field_required[i] + "_lbl");

		if (field_handle.type != 'checkbox' && field_handle.type != 'radio')
			ok_required = field_handle && field_handle.value=='';
		else
			ok_required = field_handle && field_handle.checked == false;
			
		if (ok_required)	{
			if (field_label_handle) {
				// la label pu� contenere html
				var field_label_value = field_label_handle.innerHTML;
				tag_start = field_label_value.indexOf('<');
				if (tag_start >= 0) 
					field_label_value = field_label_value.substr(0, tag_start);
				
				alert(field_label_value + ' � un campo obbligatorio');
			}
			field_handle.focus();
			break;
		}
	}
	
	if (!ok_required) {
		url_params = "?id_an=" + escape(trim(id_an.value)) + "&segnalaForm_submit=true";
		for (i=0;i<field_required.length;i++) {
			var field_handle = document.getElementById(field_required[i]);
			url_params += "&" + field_required[i] + "=" + escape(trim(field_handle.value));
		}
		var textarea = document.getElementById("area_segnala");
		url_params += "&area_segnala=" + textarea.value;
		var url = "ajax_call/segnala.php" + url_params;
		http.open("POST", url, true); 
		http.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
		http.onreadystatechange = handleHttpResponse_form_segnala; 
		http.send(null);
	}
}

function handleHttpResponse_form_segnala() { 
	try {
		var div_output_id = "fm_segnala_form_messages";
		if (http.readyState == 4) { 
			if (http.status == 200) {
				results = http.responseText; 
				var div_output = document.getElementById(div_output_id); 
				if (div_output) { div_output.innerHTML = results; }
			}
		} 
		else {
			var div_output = document.getElementById(div_output_id); 
			if (div_output) { 
				div_output.style.display = "block";
				div_output.innerHTML = ajax_sending_text; 
			}
		}
	}
	catch(e) {
		var div_output = document.getElementById(div_output_id); 
		if (div_output) { div_output.innerHTML = ajax_error_text; }
		alert(generic_server_error);
    }	
}

function check_form_jobalert() {

	var field_required = new Array('descrizioneJA');
	var field_multi_required = new Array('regioni', 'province', 'funzioni', 'settori');

	// prendo i riferimenti ai campi
	for (i=0;i<field_required.length;i++) {
		var field_handle = document.getElementById(field_required[i]);
		var field_label_handle = document.getElementById(field_required[i] + "_lbl");

		if (field_handle.type != 'checkbox' && field_handle.type != 'radio')
			ok_required = field_handle && field_handle.value=='';
		else
			ok_required = field_handle && field_handle.checked == false;
			
		if (ok_required)	{
			if (field_label_handle) {
				// la label pu� contenere html
				var field_label_value = field_label_handle.innerHTML;
				tag_start = field_label_value.indexOf('<');
				if (tag_start >= 0) 
					field_label_value = field_label_value.substr(0, tag_start);
				
				alert(field_label_value + ' � un campo obbligatorio');
			}
			field_handle.focus();
			break;
		}
	}
	
	if (!ok_required) {

		// prendo i riferimenti ai campi
		for (i=0;i<field_multi_required.length;i++) {
			var field_handle = document.getElementsByName(field_multi_required[i] + '[]');
			var field_label_handle = document.getElementById(field_multi_required[i] + "_lbl");
			
			ok_required = true;
			for (j=0;j<field_handle.length;j++) {
				//alert(field_handle[j].id);
				if (field_handle[j].type != 'checkbox' && field_handle[j].type != 'radio')
					ok_required = ok_required && (field_handle[j] && field_handle[j].value=='');
				else
					ok_required = ok_required && (field_handle[j] && field_handle[j].checked == false);
					
				if (!ok_required) break;
					
			}
			if (ok_required) {
				if (field_label_handle) {
					// la label pu� contenere html
					var field_label_value = field_label_handle.innerHTML;
					tag_start = field_label_value.indexOf('<');
					if (tag_start >= 0) 
						field_label_value = field_label_value.substr(0, tag_start);
					
					alert(field_label_value + ' � un campo obbligatorio');
				}
				field_handle[0].focus();
				break;
			}
		}
	}

	return !ok_required;
}


function check_fm_invia_candidatura(alert_cv, alert_img, alert_lp) {
	var result = false;
        /*
	var selCV = document.forms["fm_invia_candidatura"].sel_cv;
	var selImg = document.forms["fm_invia_candidatura"].sel_img;
	var selLP = document.forms["fm_invia_candidatura"].sel_lp;
	*/
        var selCV  = document.getElementsByName("sel_cv");
	var selImg = document.getElementsByName("sel_img");
	var selLP  = document.getElementsByName("sel_lp");
	cv_checked = false;
	for (i=0;i<selCV.length;i++) {
		cv_checked = cv_checked || selCV[i].checked; 
	}

	img_checked = false;
	for (i=0;i<selImg.length;i++) {
		img_checked = img_checked || selImg[i].checked; 
	}

	lp_checked = false;
	for (i=0;i<selLP.length;i++) {
		lp_checked = lp_checked || selLP[i].checked; 
	}
	
	if (!cv_checked) alert(alert_cv);
	else if (!img_checked) alert(alert_img);
	else if (!lp_checked) alert(alert_lp);
	
	result = cv_checked && img_checked && lp_checked;
	
	return result;
}


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_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 getHTTPObject() {
	var xmlhttp;
	if (window.XMLHttpRequest && !(window.ActiveXObject)) {     // Object of the current windows
    	try {
			xmlhttp = new XMLHttpRequest();     // Firefox, Safari, ...
			//xmlhttp.overrideMimeType('text/xml');
        } catch(e) {
			xmlhttp = false;
        }
	} 
	else if (window.ActiveXObject) {
		try {
        	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
      	} 
		catch(e) {
        	try {
          		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		xmlhttp = false;
        	}
		}
	}
	return xmlhttp;
}

function aggiorna(id){
	new Ajax.Request('/include/azioni_ajax.php' , {
	   	method: 'get', parameters: {
	   	aggiornaClickDettaglio: "s",
	   	id_an : id
		} ,
		asynchronous: false,onSuccess: function(transport) {
		}
	});
}

var generic_server_error = "Richiesta dati dal server fallita, riprovare";


var ajax_loading_text = "<p>in caricamento...</p>";
var ajax_sending_text = "<p>sto inviando...</p>";
var ajax_error_text = "<p><span class=\"testo_errore\">[" + generic_server_error + "]</span></p>";
var http = getHTTPObject(); // HTTP Object


// parte per gestire il consizionamento
	var nome_pagina = location.href;
	nome_pagina     = nome_pagina.substr(nome_pagina.lastIndexOf("/")+1).split(/[?#]/)[0];
	
	switch (nome_pagina){
	    case "il_mio_cv.php":
		case "candidatura_spontanea.php":
	    case "candidatura.php": 
	    window.onload = function(){
	        var area1 = document.getElementById("campo_26_2843");
	        var role1 = document.getElementById("campo_26_2880");
	        var array_role1 = new Array();
	        var condizionamento1 = new Array(); 
	        condizionamento1[1473] = new Array(14836, 14837, 14838, 14839, 14840, 14841, 14842, 14843, 14844, 14845, 14846, 14847, 14848, 14849, 14850, 14851, 14852, 15251, 14853, 14854, 14855, 14856, 14857, 14858, 14859, 14860, 14861, 14862, 14863, 14864, 14865);
			condizionamento1[1466] = new Array(14884, 14883, 14882, 14881, 15252, 14880, 14879, 14878, 14877, 14876, 14875, 14874, 14873, 14872, 14871, 14870, 14869, 14868, 14867, 14866);
			condizionamento1[1467] = new Array(14912, 14911, 14910, 14909, 14908, 14907, 14906, 14905, 14904, 14903, 14902, 14901, 14900, 14899, 14898, 14897, 14896, 14895, 14894, 14893, 14892, 14891, 14890, 14889, 14888, 14887, 14886, 14885);
			condizionamento1[1468] = new Array(14977, 14976, 14975, 14974, 14973, 14972, 14971, 14970, 14969, 14968, 14967, 14966, 14965, 14964, 14963, 14962, 14961, 14960, 14959, 14958, 14957, 14956, 14955, 14954, 14953, 14952, 14951, 14950, 14949, 14948, 14947, 14946, 14945, 14944, 14943, 14942, 14941, 14940, 14939, 14938, 14937, 14936, 14935, 14934, 14933, 14932, 14931, 14930, 14929, 14928, 14927, 14926, 14925, 14924, 14923, 14922, 14921, 14920, 14919, 14918, 14917, 14916, 14915, 14914, 14913);
			condizionamento1[1469] = new Array(15018, 15017, 15016, 15015, 15014, 15013, 15012, 15011, 15010, 15009, 15008, 15007, 15006, 15005, 15004, 15003, 15002, 15001, 15000, 14999, 14998, 14997, 14996, 14995, 14994, 14993, 14992, 14991, 14990, 14989, 14988, 14987, 14986, 14985, 14984, 14983, 14982, 14981, 14980, 14979, 14978);
			condizionamento1[1470] = new Array(15047, 15046, 15271, 15045, 15044, 15043, 15042, 15041, 15040, 15039, 15038, 15037, 15036, 15035, 15034, 15033, 15032, 15031, 15030, 15029, 15028, 15027, 15026, 15025, 15024, 15023, 15022, 15021, 15020, 15019);
			condizionamento1[1471] = new Array(15074, 15073, 15072, 15071, 15070, 15069, 15068, 15067, 15066, 15065, 15064, 15063, 15062, 15061, 15060, 15059, 15058, 15057, 15056, 15055, 15054, 15053, 15052, 15051, 15050, 15049, 15048);
			condizionamento1[1472] = new Array(15075, 15076, 15077);
			condizionamento1[1474] = new Array(15078, 15079, 15080, 15081, 15082, 15083);
			condizionamento1[1475] = new Array(15121, 15120, 15119, 15118, 15117, 15116, 15115, 15114, 15113, 15112, 15111, 15110, 15109, 15108, 15107, 15106, 15105, 15104, 15103, 15102, 15101, 15100, 15099, 15098, 15097, 15096, 15095, 15094, 15093, 15092, 15091, 15090, 15089, 15088, 15087, 15086, 15085, 15084);
			condizionamento1[1476] = new Array(15153, 15152, 15151, 15150, 15149, 15148, 15147, 15146, 15145, 15144, 15143, 15142, 15141, 15140, 15139, 15138, 15137, 15136, 15135, 15134, 15133, 15132, 15131, 15130, 15129, 15128, 15127, 15126, 15125, 15124, 15123, 15122);
			condizionamento1[1477] = new Array(15168, 15167, 15166, 15165, 15164, 15163, 15162, 15161, 15160, 15159, 15158, 15157, 15156, 15155, 15154);
			condizionamento1[1478] = new Array(15184, 15183, 15182, 15181, 15180, 15179, 15178, 15253, 15177, 15176, 15175, 15174, 15173, 15172, 15171, 15170, 15169);
			condizionamento1[1479] = new Array(15254, 15255, 15256, 15257, 15258, 15259, 15260, 15261, 15262, 15263, 15264, 15265, 15266, 15267, 15268, 15269, 15270);
			condizionamento1[1480] = new Array(15196, 15195, 15194, 15193, 15192, 15191, 15190, 15189, 15188, 15187, 15186, 15185);
			condizionamento1[2956] = new Array(15211, 15210, 15209, 15208, 15207, 15206, 15205, 15204, 15203, 15202, 15201, 15200, 15199, 15198, 15197);
			condizionamento1[2957] = new Array(15215, 15214, 15213, 15212);
			condizionamento1[2958] = new Array(15238, 15237, 15236, 15235, 15234, 15233, 15232, 15231, 15230, 15229, 15228, 15227, 15226, 15225, 15224, 15223, 15222, 15221, 15220, 15219, 15218, 15217, 15216);
			condizionamento1[2959] = new Array(15250, 15249, 15248, 15247, 15246, 15245, 15244, 15243, 15242, 15241, 15240, 15239);
	        
	        for (a=0;a<role1.length;a++){
	            array_role1[role1[a].value] = role1[a].text;
	        }
	        
	        role1.length = 0;
	        area1.onchange = function(){
	             //checkLivello(this);
	             condizionaCampo(area1,role1,array_role1,condizionamento1); 
	        }; 
	        
	    }
	    break;
	}
	
	function condizionaCampo(area,obj,array_role1,condizionamento){
	    obj.length = 0;
	    for (a=0;a<condizionamento[area.value].length;a++){    
	        var optn = document.createElement("OPTION");
	        optn.text  = array_role1[condizionamento[area.value][a]];
	        optn.value = condizionamento[area.value][a];
	        obj.options.add(optn);
	    }    
	}
	
	
	
	var nome_pagina = location.href;
  	nome_pagina     = nome_pagina.substr(nome_pagina.lastIndexOf("/")+1).split(/[?#]/)[0];


	switch (nome_pagina){
	    case "il_mio_cv.php":
	    case "candidatura.php":
	    case "candidatura_spontanea.php":
	    case "registrati.php":
	    window.onload = function(){ 
	 
		    try
		    {
		    	document.getElementById('img_button').src = '/gfx/icon_calendar.gif' ; 
		        // document.getElementById('img_button_2830').src = '/gfx/ico-date.png' ;
		        // document.getElementById('img_button_2829').src = '/gfx/ico-date.png' ;
			}
		    catch(err)
		    {
		    	//Handle errors here
		    }  
	    
	    }
      
   	}
