// JavaScript Document

function invia() {
document.form.submit();
}
// prima attiva o meno la scelta della sub.sub.categoria
function attiva_subcategoria(azione) {
	if(azione == 'not')
	{
		document.getElementById('go_on').value = 'not';
	}
	if(azione == 'ok')
	{
		document.getElementById('go_on').value = 'ok';
	}
	
	document.form.submit();
}
function TrimString(sInString) 
{
   sInString = sInString.replace( /^\s+/g, "" );// strip leading
   return sInString.replace( /\s+$/g, "" );// strip trailing
}
function f_controllo(lingua) 
{
	if(lingua == 'it') {
			text_ls_mail = 'il campo MAIL è obbligatorio';
			text_ls_mail_correct = 'inserire un indirizzo MAIL valido';
			text_ls_name = 'il campo NOME è obbligatorio';
			text_ls_surname = 'il campo COGNOME è obbligatorio';
			text_ls_cell = 'il campo CELL è obbligatorio';
			text_ls_full_name = 'il campo RAGIONE SOCIALE è obbligatorio';
			text_ls_address = 'il campo INDIRIZZO è obbligatorio';
			text_ls_country = 'il campo PAESE è obbligatorio';
			text_ls_city = "il campo CITTA' è obbligatorio";
			text_ls_cap = 'il campo CAP è obbligatorio';
			text_ls_tel = 'il campo TEL è obbligatorio';
			text_ls_howknown = 'Per favore popola il campo "come ci hai conosciuto"';
			text_ls_privacy = 'il campo PRIVACY è obbligatorio';
			text_ls_core = 'il campo CORE è obbligatorio';
			text_ls_captcha = 'il codice di verifica inserito è errato';
			text_ls_note = 'essendo un PRIVATO gentilmente completa anche il campo NOTE';
		}
		else {
			text_ls_mail = 'the EMAIL field is mandatory';
			text_ls_mail_correct = 'enter valid EMAIL';
			text_ls_name = 'the NAME field is mandatory';
			text_ls_surname = 'the SURNAME field is mandatory';
			text_ls_cell = 'the MOBILE field is mandatory';
			text_ls_full_name = 'the COMPANY NAME field is mandatory';
			text_ls_address = 'the ADDRESS field is mandatory';
			text_ls_cap = 'the CAP field is mandatory';
			text_ls_country = 'the COUNTRY field is mandatory';
			text_ls_city = 'the CITY field is mandatory';
			text_ls_tel = 'the TEL field is mandatory';
			text_ls_howknown = 'Please populate the field "How did you meet us"';
			text_ls_privacy = 'the PRIVACY field is mandatory';
			text_ls_captcha = 'the verification code you entered is incorrect';
			text_ls_core = 'the CORE field is mandatory';
			text_ls_note = 'the NOTE field is mandatory for private persons';
			}
	ls_mail = document.getElementById('usr_email').value;
	ls_name = document.getElementById('name').value;
	ls_surname = document.getElementById('surname').value;
	ls_cell = document.getElementById('cell').value;
	ls_full_name = document.getElementById('full_name').value;
	ls_address = document.getElementById('address').value;
	ls_cap = document.getElementById('cap').value;
	ls_tel = document.getElementById('tel').value;
	ls_howknown = document.getElementById('howknown').value;
	posizione = ls_mail.indexOf('@');
	ls_core = document.getElementById('core').value;
	ls_city = document.getElementById('city').value;
	ls_country = document.getElementById('country').value;
	ls_note = document.getElementById('note').value;
	ls_privacy = document.getElementById('privacy-id').checked;
	ls_captcha = document.getElementById('captcha').value;
	ls_invariante = document.getElementById('invariante').value;
	
	//Obbligatorietà
	
	if (TrimString(ls_mail)=='') {alert (text_ls_mail); return -1;}
	if (posizione<=0) {alert (text_ls_mail_correct); return -1;}
	if (TrimString(ls_name)=='') {alert (text_ls_name); return -1;}
	if (TrimString(ls_surname)=='') {alert (text_ls_surname); return -1;}
/*	if (TrimString(ls_cell)=='') {alert (text_ls_cell); return -1;} */ // non è più obbligatorio
	if (TrimString(ls_full_name)=='') {alert (text_ls_full_name); return -1;}
	if (TrimString(ls_country)=='not') {alert (text_ls_country); return -1;}
	if (TrimString(ls_address)=='') {alert (text_ls_address); return -1;}
	if (TrimString(ls_city)=='') {alert (text_ls_city); return -1;}
	if (TrimString(ls_cap)=='') {alert (text_ls_cap); return -1;}
	if (TrimString(ls_tel)=='') {alert (text_ls_tel); return -1;}
	if (TrimString(ls_core)=='not') {alert (text_ls_core); return -1;}
	if (TrimString(ls_howknown)=='not') {alert (text_ls_howknown); return -1;}
	if(ls_core=='Private') {
		if(TrimString(ls_note)=='')
		{
		alert (text_ls_note); return -1;  
		}
		}
	
	if (!ls_privacy) {alert (text_ls_privacy); return -1;}
	if (ls_captcha != ls_invariante) {alert (text_ls_captcha); return -1;}

	return 1;
}


function f_operazione(lingua) 
{
	lamia = lingua;
	controllo = f_controllo(lamia);
	if (controllo==1) {
		document.getElementById('regForm').submit();
	}
	return;
}
function TrimString(sInString) 
{
   sInString = sInString.replace( /^\s+/g, "" );// strip leading
   return sInString.replace( /\s+$/g, "" );// strip trailing
}
function f_controllo_2(lingua) 
{
	if(lingua == 'it') {
			text_ls_name = 'il campo NOME è obbligatorio';
			text_ls_mail = 'il campo MAIL è obbligatorio';
			text_ls_mail_correct = 'inserire un indirizzo MAIL valido';
			text_ls_mess = 'il campo MESSAGGIO è obbligatorio';
			text_ls_privacy = 'il campo PRIVACY è obbligatorio';
		}
		else {
			text_ls_name = 'the NAME field is mandatory';
			text_ls_mail = 'the EMAIL field is mandatory';
			text_ls_mail_correct = 'enter valid EMAIL';
			text_ls_mess = 'the MESSAGE field is mandatory';
			text_ls_privacy = 'the PRIVACY field is mandatory';
			}
	ls_mail = document.getElementById('mail-id').value;
	ls_name = document.getElementById('nome-id').value;
	ls_message = document.getElementById('messaggio-id').value;
	posizione = ls_mail.indexOf('@');	
	ls_privacy = document.getElementById('privacy-id').checked;
	
	//Obbligatorietà
	if (TrimString(ls_name)=='') {alert (text_ls_name); return -1;}	
	if (TrimString(ls_mail)=='') {alert (text_ls_mail); return -1;}
	if (posizione<=0) {alert (text_ls_mail_correct); return -1;}
	if (TrimString(ls_message)=='') {alert (text_ls_mess); return -1;}
	if (!ls_privacy) {alert (text_ls_privacy); return -1;}

	return 1;
}


function f_domande(lingua) 
{
	lamia = lingua;
	controllo = f_controllo_2(lamia);
	if (controllo==1) {
		document.getElementById('form1-id').submit();
	}
	return;
}
// marketing

function f_choose (indicatore) {
	img1 = 'images/back-marketing-left';
	img2 = 'images/back-marketing-right';
	
	if (indicatore=='left') {img1 = img1 + '-on';} else {img1 = img1 + '-off';}
	if (indicatore=='right') {img2 = img2 + '-on';} else {img2 = img2 + '-off';}

	
	img1 = img1 + '.png';
	img2 = img2 + '.png';
	
	document.getElementById('left-marketing').src = img1;
	document.getElementById('right-marketing').src = img2;

}
// upload file
function startUpload(riferimento){
	document.getElementById('loader-'+riferimento).style.visibility = 'visible';
	document.getElementById('form-upload-'+riferimento).style.visibility = 'hidden';
	return true;
}
function stopUpload(success, riferimento){
      var result = '';
      if (success == 1){
         result = '<span class="ok-msg">The file was uploaded successfully!<\/span>';
      }
      else {
         result = '<span class="emsg">There was an error during file upload!<\/span>';
      }
      document.getElementById('loader-'+riferimento).style.visibility = 'hidden';
	  document.getElementById('result-'+riferimento).innerHTML = result;
      document.getElementById('form-upload-'+riferimento).style.visibility = 'visible';      
      return true;   
}
function changerif() {
	rif = document.getElementById('serie_rif').value;
	document.getElementById('frameManualiUpdate').src ='upload/index.php?realnome=manuale-'+rif+'.zip&realpercorso=manuali';
	document.getElementById('frameEsplosiUpdate').src ='upload/index.php?realnome=esplosi-'+rif+'.zip&realpercorso=esplosi';
	document.getElementById('agente').innerHTML = 'Stai agento sulla serie ' +rif;
}
function set_visibility(parameter) {
	if(parameter == 1)
	{
		document.getElementById('example_video_1').style.visibility = 'hidden';
	}
	if(parameter == 2)
	{
		document.getElementById('example_video_1').style.visibility = 'visible';
	}
}
function cambiaiFrame(look){
	document.getElementById("iframe-dettagli").src = look;
}
function cambiaObjet(look) {
	document.getElementById('iframe-dettagli').src = look;
}
function cambiaiFrameSelect(who){
	set_type = document.getElementById(who).value;
	if(set_type != 'not')
	{
		if(who == 'look_esplosi')
		{
			deselect_1 = 'look_manuali';	
			deselect_2 = 'catalogo_pagina';	
		}
		if(who == 'catalogo_pagina')
		{
			deselect_1 = 'look_manuali';	
			deselect_2 = 'look_esplosi';	
		}
		if(who == 'look_manuali')
		{
			deselect_1 = 'look_esplosi';	
			deselect_2 = 'catalogo_pagina';	
		}
		id_1 = document.getElementById(deselect_1)
		id_2 = document.getElementById(deselect_2)
		id_1.selectedIndex=0;
		id_2.selectedIndex=0;
		
		document.getElementById("iframe-dettagli").src = set_type+'&embedded=true';
		// document.getElementById('contenutoiframe').innerHTML = '<iframe src="http://docs.google.com/viewer?url=www.gianneschi.net/catalogoPDF/4.pdf&embedded=true" class="iframe-dettagli" style="border: none;" id="iframe-dettagli"></iframe>';
	}

}
function cambiaObjectSelect(look) {
	set_type = document.getElementById(look).value;

	if(set_type != 'not')
	{
		document.getElementById('iframe-dettagli').src = set_type;
	}

}
function eseguiDownload(rif_id,lingua){
	// setto i messaggi in base alla lingua di navigazione
	if(lingua == 'it')
	{
		txt_msg = 'Selezionare prima un file da scaricare';
	}
	else
	{
		txt_msg = 'First select a file to download';
	}
	// percorso file da scaricare
	set_percorso = document.getElementById(rif_id).value;
	if(set_percorso != 'not')
	{
		window.open(set_percorso);
	}
	else
	{
		alert (txt_msg);
	}
}

function f_check_feedback(lang) {
	if(lang == 'it')
	{
		text_ls_oggetto = 'Il campo OGGETTO è obbligatorio';
		text_ls_messaggio = 'Il campo MESSAGGIO è obbligatorio';
		text_ls_privacy = 'il campo PRIVACY è obbligatorio';
	}
	else
	{
		text_ls_oggetto = 'The OBJECT field is mandatory';
		text_ls_messaggio = 'The MESSAGE field is mandatory';
		text_ls_privacy = 'the PRIVACY field is mandatory';
	}

	ls_oggetto = document.getElementById('oggetto-id').value;
	ls_messaggio = document.getElementById('messaggio-id').value;
	ls_privacy = document.getElementById('privacy-id').checked;
	
	if (TrimString(ls_oggetto)=='') {alert (text_ls_oggetto); return -1;}
	if (TrimString(ls_messaggio)=='') {alert (text_ls_messaggio); return -1;}
	if (!ls_privacy) {alert (text_ls_privacy); return -1;}
	
	return 1;
	
}
function f_feedback(lingua) 
{
	lamia = lingua;
	controllo = f_check_feedback(lamia);
	if (controllo==1) {
		document.getElementById('form1-id').submit();
	}
	return;
}
function f_check_appuntamento(lang) {
	if(lang == 'it')
	{
		text_ls_nome = 'Il campo NOME è obbligatorio';
		text_ls_tel = 'Il campo TELEFONO è obbligatorio';
		text_ls_messaggio = 'Il campo MESSAGGIO è obbligatorio';
		text_ls_privacy = 'il campo PRIVACY è obbligatorio';
	}
	else
	{
		text_ls_nome = 'the NAME field is mandatory';
		text_ls_tel = 'the PHONE field is mandatory';
		text_ls_messaggio = 'The MESSAGE field is mandatory';
		text_ls_privacy = 'the PRIVACY field is mandatory';
	}

	ls_nome = document.getElementById('nome-id').value;
	ls_tel = document.getElementById('telefono-id').value;
	ls_messaggio = document.getElementById('messaggio-id').value;
	ls_privacy = document.getElementById('privacy-id').checked;
	
	if (TrimString(ls_nome)=='') {alert (text_ls_nome); return -1;}
	if (TrimString(ls_tel)=='') {alert (text_ls_tel); return -1;}
	if (TrimString(ls_messaggio)=='') {alert (text_ls_messaggio); return -1;}
	if (!ls_privacy) {alert (text_ls_privacy); return -1;}
	
	return 1;
}
function f_appuntamento(lingua) 
{
	lamia = lingua;
	controllo = f_check_appuntamento(lamia);
	if (controllo==1) {
		document.getElementById('form1-id').submit();
	}
	return;
}
function verificaupload(page) {
	news = document.getElementById('rif_news_upload').value;
	file = document.getElementById('file-'+page).value;
	if(news == 'not') { alert ('Selezionare una news di riferimento'); return -1;}
	if(file == 0) { alert ('Selezionare un file per upload'); return -1;}
	
	document.getElementById('uploadFoto').submit();
}
function msi_visibility(mouse) {
	verifica = document.getElementById('iframe-dettagli').style.visibility;
	if(mouse == 'over')
	{
		if(verifica == 'visible')
		{
			document.getElementById('iframe-dettagli').style.visibility = 'hidden';
		}
	}
	if(mouse == 'away')
	{
		if(verifica == 'hidden')
		{
			document.getElementById('iframe-dettagli').style.visibility = 'visible';
		}
	}
}
