// JavaScript Document
/*variabili globali*/

var tmp = location.href;
tmp = tmp.substring(0,10);
if(tmp == 'http://www')
	var this_url = "http://www.cadica.com/";
else
	var this_url = "http://cadica.com/";


//var this_url = "http://localhost/cadica/";
var this_captcha = new Array("aq56", "5t8u", "mn7h", "9d53", "sd6b", "lujm", "ew37", "kk77", "scxz");
var clock_img = this_url+"images/clock/";
var vocabulary = new Array();
vocabulary['EN'] = new Array();
vocabulary['EN']['form_info_0'] = "Verifica di aver compilato correttamente i seguenti campi:\n";
vocabulary['EN']['form_info_1'] = "Nome\n";
vocabulary['EN']['form_info_2'] = "Cognome\n";
vocabulary['EN']['form_info_3'] = "Azienda\n";
vocabulary['EN']['form_info_4'] = "Inserisci un numero di telefono o un indirizzo eMail\n";
vocabulary['EN']['form_info_4a'] = "Inserisci un indirizzo eMail valido\n";
vocabulary['EN']['form_info_5'] = "Seleziona l'ambito di interesse\n";
vocabulary['EN']['form_info_6'] = "Inserisci correttamente il testo riportato nell'immagine";
vocabulary['EN']['form_info_7'] = "Allega un Curriculum Vitae";

vocabulary['IT'] = new Array();
vocabulary['IT']['form_info_0'] = "Verifica di aver compilato correttamente i seguenti campi:\n";
vocabulary['IT']['form_info_1'] = "Nome\n";
vocabulary['IT']['form_info_2'] = "Cognome\n";
vocabulary['IT']['form_info_3'] = "Azienda\n";
vocabulary['IT']['form_info_4'] = "Inserisci un numero di telefono o un indirizzo eMail\n";
vocabulary['EN']['form_info_4a'] = "Inserisci un indirizzo eMail valido\n";
vocabulary['IT']['form_info_5'] = "Seleziona l'ambito di interesse\n";
vocabulary['IT']['form_info_6'] = "Inserisci correttamente il testo riportato nell'immagine";
vocabulary['IT']['form_info_7'] = "Allega un Curriculum Vitae";

vocabulary['ES'] = new Array();
vocabulary['ES']['form_info_0'] = "Verifica di aver compilato correttamente i seguenti campi:\n";
vocabulary['ES']['form_info_1'] = "Nome\n";
vocabulary['ES']['form_info_2'] = "Cognome\n";
vocabulary['ES']['form_info_3'] = "Azienda\n";
vocabulary['ES']['form_info_4'] = "Inserisci un numero di telefono o un indirizzo eMail\n";
vocabulary['EN']['form_info_4a'] = "Inserisci un indirizzo eMail valido\n";
vocabulary['ES']['form_info_5'] = "Seleziona l'ambito di interesse\n";
vocabulary['ES']['form_info_6'] = "Inserisci correttamente il testo riportato nell'immagine";
vocabulary['ES']['form_info_7'] = "Allega un Curriculum Vitae";

vocabulary['DE'] = new Array();
vocabulary['DE']['form_info_0'] = "Verifica di aver compilato correttamente i seguenti campi:\n";
vocabulary['DE']['form_info_1'] = "Nome\n";
vocabulary['DE']['form_info_2'] = "Cognome\n";
vocabulary['DE']['form_info_3'] = "Azienda\n";
vocabulary['DE']['form_info_4'] = "Inserisci un numero di telefono o un indirizzo eMail\n";
vocabulary['EN']['form_info_4a'] = "Inserisci un indirizzo eMail valido\n";
vocabulary['DE']['form_info_5'] = "Seleziona l'ambito di interesse\n";
vocabulary['DE']['form_info_6'] = "Inserisci correttamente il testo riportato nell'immagine";
vocabulary['DE']['form_info_7'] = "Allega un Curriculum Vitae";

vocabulary['FR'] = new Array();
vocabulary['FR']['form_info_0'] = "Verifica di aver compilato correttamente i seguenti campi:\n";
vocabulary['FR']['form_info_1'] = "Nome\n";
vocabulary['FR']['form_info_2'] = "Cognome\n";
vocabulary['FR']['form_info_3'] = "Azienda\n";
vocabulary['FR']['form_info_4'] = "Inserisci un numero di telefono o un indirizzo eMail\n";
vocabulary['EN']['form_info_4a'] = "Inserisci un indirizzo eMail valido\n";
vocabulary['FR']['form_info_5'] = "Seleziona l'ambito di interesse\n";
vocabulary['FR']['form_info_6'] = "Inserisci correttamente il testo riportato nell'immagine";
vocabulary['FR']['form_info_7'] = "Allega un Curriculum Vitae";
/*gestione del menu principale*/
function setMenuSx(id, img)
{
	$('#'+id).attr("src", img);	
}


$(document).ready(function()
{
	updateClock();
});

/*funzione per la gestione dell'orologio*/
function updateClock()
{
	oggi = new Date()
    ore = oggi.getHours()
    if (ore < 10)
      ore = "0" + ore + "" // con l'aggiunta di "" converte il valore in stringa
    else
      ore += ""            // converte il valore in stringa; idem per min e sec
    min = oggi.getMinutes()
    if (min < 10)
      min = "0" + min + ""
    else
      min += ""
    sec = oggi.getSeconds()
    if (sec < 10)
      sec = "0" + sec + ""
    else
      sec += ""
    // per selezionare l'immagine del numero da visualizzare, 
    // rileva dalla stringa la cifra con substr(posizione,lunghezza)
	$('#ora1').attr("src", clock_img+(ore.substr(0,1))+".png");
	$('#ora2').attr("src", clock_img+(ore.substr(1,1))+".png");
	$('#min1').attr("src", clock_img+(min.substr(0,1))+".png");
	$('#min2').attr("src", clock_img+(min.substr(1,1))+".png");
	$('#sec1').attr("src", clock_img+(sec.substr(0,1))+".png");
	$('#sec2').attr("src", clock_img+(sec.substr(1,1))+".png");
	setTimeout('updateClock()',1000);
}
/*cambio della lingua*/
function changeLanguage(language, redirecturl)
{
	$.ajax({
		url : this_url+"library/phplib/ajax/ajaxResponse.php?op=changeLanguage&language="+language,
		complete : function (data){
				window.location = redirecturl;
		},
		async : false,
		type: "post"
	});
}

/*contenuto latest news*/
function getLatestNews(language)
{
	$.ajax({
		url : this_url+"xml/news_"+language+".xml",
		complete : function (data){var text = data.responseText;
					text=text.replace(/&lt;/g,"<");
					text=text.replace(/&gt;/g,">"); 
					$('#example2').html(text)},
		async : false,
		type: "post"
	});	
	
}

function getFiereContent()
{
	$.ajax({
		url : this_url+"xml/fiere.xml",
		complete : function (data){$('#fiere').prepend(data.responseText)},
		async : false,
		type: "post"
	});		
}

function getProductsXML(lang)
{
	$.ajax({
		url : this_url+"xml/products_"+lang+".xml",
		complete : function (data){$('#productsXML').html(data.responseText)},
		async : false,
		type: "post"
	});		
}

function getProductsGallery(id)
{
	$.ajax({
		url : this_url+"library/phplib/ajax/ajaxResponse.php?op=getProductsGallery&id="+id,
		complete : function (data){
			var path_xml = this_url+"xml/"+data.responseText;
			$.ajax({
				url : path_xml,
				complete : function (data){$('#productsGalleryXML').html(data.responseText)},
				async : false,
				type: "post"
			});	
		},
		async : false,
		type: "post"
	});
}

function checkFormInfo(language)
{
	if($("#txt_captcha").val() == "")
	{
		var check = true;
		var alertMsg = vocabulary[language]['form_info_0'];
		if($("#firstname").val() == '')
		{
			check = false;
			alertMsg += vocabulary[language]['form_info_1'];
		}
		if($("#lastname").val() == '')
		{
			check = false;
			alertMsg += vocabulary[language]['form_info_2'];
		}
		if($("#company").val() == '')
		{
			check = false;
			alertMsg += vocabulary[language]['form_info_3'];	
		}
		if($("#telephone").val() == '' && $("#mobilephone").val() == '' && $("#email").val() == '')
		{
			check = false;
			alertMsg += vocabulary[language]['form_info_4'];	
		}
		if($("#email").val() != '' && !validateEmail($("#email").val()))
		{
			check = false;
			alertMsg += vocabulary[language]['form_info_4a'];
		}
		if($("#relazione :selected").val() == '')
		{
			check = false;
			alertMsg += vocabulary[language]['form_info_5'];
		}
		if(!check)
			alert(alertMsg);
		else
			$("#info_form").submit();
	}
	else
		alert("It seems to me that you're a bot!");
}

function checkFormJob(language)
{
	if($("#txt_captcha").val() == "")
	{
		var check = true;
		var alertMsg = vocabulary[language]['form_info_0'];
		if($("#firstname").val() == '')
		{
			check = false;
			alertMsg += vocabulary[language]['form_info_1'];
		}
		if($("#lastname").val() == '')
		{
			check = false;
			alertMsg += vocabulary[language]['form_info_2'];
		}
		if($("#telephone").val() == '' && $("#mobilephone").val() == '' && $("#email").val() == '')
		{
			check = false;
			alertMsg += vocabulary[language]['form_info_4'];	
		}
		if($("#email").val() != '' && !validateEmail($("#email").val()))
		{
			check = false;
			alertMsg += vocabulary[language]['form_info_4a'];
		}
		if($("#relazione :selected").val() == '')
		{
			check = false;
			alertMsg += vocabulary[language]['form_info_5'];
		}
		if(!check)
			alert(alertMsg);
		else
			$("#job_form").submit();
	}
	else
		alert("It seems to me that you're a bot!");
}

function validateEmail(elementValue)
{  
	var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;  
	return emailPattern.test(elementValue); 
}

function swapPressImg(op, id)
{
	if(op == 'over')
		var src = "../images/press/icona_1.png";
	else
		var src = "../images/press/icona.png";
	$('#'+id).attr("src", src);
}

function getPressContent(lingua)
{
	$.ajax({
		url : this_url+"xml/press_"+lingua+".xml",
		complete : function (data){$('#pressContent').html(data.responseText)},
		async : false,
		type: "post"
	});		
}

function getSocialContent(lingua)
{
	$.ajax({
		url : this_url+"xml/com_soc_"+lingua+".xml",
		complete : function (data){$('#socialContent').html(data.responseText)},
		async : false,
		type: "post"
	});		
}


