function elencomedici(vetrina){
	if (vetrina!="si"){
		if (document.registra1.sede.value!="" && document.registra1.trattamento.value!="" && document.registra1.email.value!=""){
			Richiesta("/ajax_elenco_medici.asp?prov=" + document.registra1.pp.value + "&sede=" + document.registra1.sede.value + "&tr=" + document.registra1.trattamento.value + "&email=" + document.registra1.email.value,"divelencomedici")
		}
	}
}

function validazione(idoggetto){
	var message = jQuery("#"+idoggetto).data('message');
	jQuery("#"+idoggetto).css({'border-bottom':'1px solid','border-color':'#e74e84'})
	jQuery(".messaggio_alert").html("");
	jQuery("#"+idoggetto).parent().append('<div class="text-lowercase messaggio_alert" style="margin-left:0px; margin-top: 2px; color:#e74e84; font-size:14px;">'+message+'</div>')
	$('html, body').animate({ scrollTop: $("#"+idoggetto).offset().top-80}, 600);
	//$('.modal').animate({ scrollTop: $("#"+idoggetto).offset().top-80}, 600);
	//document.getElementById(idoggetto).focus();
}
			
function xmlhttpPostRec(strURL,formname,responsediv,responsemsg) {
	
			$('#titoloalert').html('ATTENZIONE')
			responsemsg='<img src=/img/AjaxLoader.gif>';
			
			if (formname=="formrecensione"){
				
				
				if (document.getElementById('nomerec').value==""){
					alert("Compilare i campi obbligatori. Grazie")
					return false;
				}
				if (document.getElementById('testorec').value==""){
					alert("Compilare i campi obbligatori. Grazie")
					return false;
				}
				if (document.getElementById('telefonorec').value==""){
					alert("Compilare i campi obbligatori. Grazie")
					return false;
				}
				if (document.getElementById('emailrec').value.length < 3) {
					alert("Compilare i campi obbligatori. Grazie")
					return false;
				}
				
				var okay = true;
				var atsign = document.getElementById('emailrec').value;
				if (((atsign.indexOf('@') == -1) && (okay == true)) || ((okay == true) && (atsign == '')) || ((atsign.indexOf('.') == -1) && (okay == true)) ){
					alert("compilare i campi obbligatori. Grazie")
					return false;
				}
				
				if (document.getElementById('privacyrec1').checked!=true) {
					alert("Per proseguire devi accettare l'informativa sulla privacy")
					return false;
				}
				
				if (document.getElementById('privacyrec').checked!=true) {
					alert("Per proseguire devi accettare il regolamento per le recensioni")
					return false;
				}
				
				
				
				jQuery('#divloadingrec').css('display','block');
				
					
			} else if (formname=="richiamata"){
				
				
				if (document.getElementById("telefonoric").value=="") {
					return false;
					
				}
				
				
				if (document.getElementById("messaggioric").value=="") {
					return false;
				}
				
				if (document.getElementById('privacyric').checked!=true) {
					alert("Per proseguire devi accettare l'informativa sulla privacy");
					//$("#testoalert").html("Per proseguire devi accettare l'informativa sulla privacy")
					//$('#modalalert').modal('show')
					return false;
				}
				
				idstruttura=document.getElementById("idstric").value;
				ga_gtm('contatto email','invio richiamata','scheda');
				dataLayer.push({event:"contatto_fb"});
				//yaCounter30752958.reachGoal('richiamata');
				
				
			
			} else if (formname=="telefona3"){
				
				if (document.getElementById("telefono").value=="") {
					return false;
				}
				
				if (document.getElementById("messaggio").value=="") {
					return false;
				}
				
				if (document.getElementById("privacyric").checked!=true) {
					alert("Per proseguire devi accettare l'informativa sulla privacy")
					return false;
				}
				
				idstruttura=document.getElementById("idst").value;
				ga_gtm('contatto email','invio richiamata','scheda')
				dataLayer.push({event:"contatto_fb"});
				//yaCounter30478692.reachGoal('richiamata');
			}
			
			else if (formname=="telefona4"){
				
				//****pagina per la gestione da parte di operatrice della chiamata da numero verde
				if (document.getElementById("telefono").value=="") {
					return false;
				}
				
				if (document.getElementById("messaggio").value=="") {
					return false;
				}
				
			} else {
				
				idstruttura=document.registra1.idstruttura.value;
				

				if (document.registra1.nome.value=="") {
					validazione('nome');
					document.registra1.nome.focus();
					return false;
				}
				
				if (document.registra1.email.value.length < 3) {
					validazione('email');
					document.registra1.email.focus();
					return false;
				}
				
				if (document.registra1.telefono.value.length < 3) {
					validazione('telefono');
					document.registra1.telefono.focus();
					return false;
				}
		
		
				
				
				var okay = true;
				var atsign = document.registra1.email.value;
				if (((atsign.indexOf('@') == -1) && (okay == true)) || ((okay == true) && (atsign == '')) || ((atsign.indexOf('.') == -1) && (okay == true)) ){
					validazione('email');
					document.registra1.email.focus();
					return false;
				}
				
				if (document.registra1.trattamento.value=="") {
					validazione('trattamento');
					document.registra1.trattamento.focus();
					return false;
				}
				
				if (document.registra1.sede.value == "") {
					validazione('sede');
					document.registra1.sede.focus();
					return false;
				}

				
				if (document.registra1.messaggio.value=="") {
					validazione('messaggio');
					document.registra1.messaggio.focus();
					return false;
				}
				
				

				
				if (document.registra1.privacy.checked!=true) {
					alert("Per proseguire devi accettare l'informativa sulla privacy")
					document.registra1.privacy.focus();
					return false;
				}
				
				
				
				
				jQuery('#divloadingmsg').css('display','block');
				
				
			}

			
			
			
			/*
			if (document.registra1.nome.value.length < 2) {
				document.registra1.nome.focus();
				$('#testoalert').html('Indica il tuo nome')
				$('#modalalert').modal('show')
				return false;
			}
	
	
			if (document.registra1.email.value.length < 3) {
				$('#testoalert').html('Inserisci un email valida')
				$('#modalalert').modal('show')

				document.registra1.email.focus();
				return false;
			}
			
			var okay = true;
			var atsign = document.registra1.email.value;
			if (((atsign.indexOf('@') == -1) && (okay == true)) || ((okay == true) && (atsign == '')) || ((atsign.indexOf('.') == -1) && (okay == true)) ){
				$('#testoalert').html('Inserisci un email valida')
				$('#modalalert').modal('show')
				okay = false;
				document.registra1.email.focus();
				return false;
			}
			
			if (document.registra1.trattamento.value=="") {
				$('#testoalert').html('Seleziona un trattamento')
				$('#modalalert').modal('show')
				document.registra1.trattamento.focus();
				return false;
			}
			
			if (document.registra1.messaggio.value.length < 10) {
				$('#testoalert').html('Specifica nel messaggio le tue richieste')
				$('#modalalert').modal('show')
				document.registra1.messaggio.focus();
				return false;
			}
			
			if (document.registra1.sede.value == "") {
				$('#testoalert').html('Seleziona una sede di tuo interesse')
				$('#modalalert').modal('show')
				document.registra1.sede.focus();
				return false;
			}	
			*/	
	
			
			
			

			
		

	    var xmlHttpReq = false;
	    var self = this;
	    // Xhr per Mozilla/Safari/Ie7
	    if (window.XMLHttpRequest) {
	        self.xmlHttpReq = new XMLHttpRequest();
	    }
	    // per tutte le altre versioni di IE
	    else if (window.ActiveXObject) {
	        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	    }
	    self.xmlHttpReq.open('POST', strURL, true);
	    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	    self.xmlHttpReq.onreadystatechange = function() {
	        if (self.xmlHttpReq.readyState == 4) {
				// Quando pronta, visualizzo la risposta del form
	            updatepagerec(self.xmlHttpReq.responseText,responsediv);
	        }
			else{
				// In attesa della risposta del form visualizzo il msg di attesa
				updatepagerec(responsemsg,responsediv);
	
			}
	    }
	    
	    	self.xmlHttpReq.send(getquerystring(formname));
	    
	    

}


function getquerystring(formname) {
    var form = document.forms[formname];
	var qstr = "";

    function GetElemValue(name, value) {
        qstr += (qstr.length > 0 ? "&" : "")
            + escape(name).replace(/\+/g, "%2B") + "="
            + escape(value ? value : "").replace(/\+/g, "%2B");
			//+ escape(value ? value : "").replace(/\n/g, "%0D");
    }
	
	var elemArray = form.elements;
    for (var i = 0; i < elemArray.length; i++) {
        var element = elemArray[i];
        var elemType = element.type.toUpperCase();
        var elemName = element.name;
        if (elemName) {
            if (elemType == "TEXT"
                    || elemType == "TEXTAREA"
                    || elemType == "PASSWORD"
					|| elemType == "BUTTON"
					|| elemType == "RESET"
					|| elemType == "SUBMIT"
					|| elemType == "FILE"
					|| elemType == "EMAIL"
					|| elemType == "TEL"
					|| elemType == "IMAGE"
                    || elemType == "HIDDEN")
                GetElemValue(elemName, element.value);
            else if (elemType == "CHECKBOX" && element.checked)
                GetElemValue(elemName, 
                    element.value ? element.value : "On");
            else if (elemType == "RADIO" && element.checked)
                GetElemValue(elemName, element.value);
            else if (elemType.indexOf("SELECT") != -1)
                for (var j = 0; j < element.options.length; j++) {
                    var option = element.options[j];
                    if (option.selected)
                        GetElemValue(elemName,
                            option.value ? option.value : option.text);
                }
        }
    }
    return qstr;
}





function updatepagerec(str,responsediv){
    document.getElementById(responsediv).innerHTML = str;
}

function loadcontatto(idcontatto){
	window.setTimeout("doRedirect(idcontatto)", 500);
}

function doRedirect(idmessaggio,tipo){
	//$("#testoalert").html("Messaggio inviato con successo!")
	//$('#modalalert').modal('show')
	if (tipo=="base") {
		setTimeout(function(){ top.location.href="/elenco_medici.asp?bs=1&idc=fwqet7bzxchzux7z4czjq2eh8kset"+idmessaggio+"ca2sy6ds3jw1gq2eue6dg4vd6ejgd9r8jas"; }, 2000);
		
	} else {
		setTimeout(function(){ top.location.href="/elenco_medici.asp?pm=1&idc=fwqet7bzxchzux7z4czjq2eh8kset"+idmessaggio+"ca2sy6ds3jw1gq2eue6dg4vd6ejgd9r8jas"; }, 2000);
	}
};

function post_send(idmessaggio,visibilita,serviziolink,paginaaccesso,idstruttura,redirect,numeroinoltri,pulsante){

	if (visibilita=="base"){
		parametro="bs=1"
	} else {
		parametro="pm=1"
	}
	if (pulsante!=""){
		etichetta=paginaaccesso + ": " + pulsante
	} else {
		etichetta=paginaaccesso	
	}
	
	ga_gtm('contatto email', 'invio email diretta ' + visibilita, etichetta); 
	dataLayer.push({event:"contatto_fb"});
	
	for (i=0; i<Number(numeroinoltri); i++) {
		ga_gtm('contatto email', 'invio email inoltrata ' + visibilita, 'richiesta');
		dataLayer.push({event:"contatto_fb"});
	}
	//yaCounter30752958.reachGoal('inviocontatto');
    
	if (redirect=="si" && serviziolink!=""){
		//setTimeout(function(){ doRedirect(parametro,idmessaggio); }, 2000);
	}
}

