﻿// JScript File
function ReceiveServerData(arg, context) {
    var R = arg.split('^|^');
    var control;
    
    switch (R[0]) {
        case "Envia-Suscripcion-email":
            control = ObjetoporId('wzd_btn_suscribe');
            control.innerHTML = R[2];
            alert(R[1]);
            break;
            
        case "Contactus-Envia-Msg":
            control = ObjetoporId('BtnSub');
            control.innerHTML = R[2];
            alert(R[1]);
            break;
   }
    
}

function ReceiveServerDataError(msg_error, context) {
    alert('Error. ' + msg_error);
    //$find('pup_espera').hide();
}

//Muy importante usar esta función crossbrowser.
function ObjetoporId( id ) 
{ 
    if (document.getElementById) 
        var returnVar = document.getElementById(id); 
    else if (document.all) 
        var returnVar = document.all[id]; 
    else if (document.layers) 
        var returnVar = document.layers[id]; 
    return returnVar; 
}

function toggle(showHideDiv, switchTextDiv, mostrar_txt, ocultar_txt) {
	var ele = document.getElementById(showHideDiv);
	var text = document.getElementById(switchTextDiv);
	if(ele.style.display == "block") {
    		ele.style.display = "none";
		text.innerHTML = mostrar_txt;
  	}
	else {
		ele.style.display = "block";
		text.innerHTML = ocultar_txt;
	}
}

function suscribir(idioma) {
    var ctrl1 = ObjetoporId('frm_nombre');
    var ctrl2 = ObjetoporId('frm_apellido');
    var ctrl3 = ObjetoporId('frm_correo');
    var inst = '';
    var sep = '^|^';
    var stop = false;
    var error1 = '';
    var error2 = '';
    var error3 = '';
    
    if (idioma == 'esp') {
        error1 = 'Por favor introduzca su Nombre para continuar.';
        error2 = 'Por favor introduzca su Apellido para continuar.';
        error3 = 'Por favor introduzca su e-mail para continuar.';
    } else {
        error1 = 'Please enter your First Name in order to continue.';
        error2 = 'Please enter your Last Name in order to continue.';
        error3 = 'Please enter your e-mail in order to continue.';
    }
    
    if (ctrl1.value == '' && !stop) {
        stop = true;         alert(error1);        ctrl1.focus();
    }
    if (ctrl2.value == '' && !stop) {
        stop = true;         alert(error2);        ctrl2.focus();
    }
    if (ctrl3.value == '' && !stop) {
        stop = true;         alert(error3);        ctrl3.focus();
    }
        
    if (!stop) {
        muestra_en_espera('wzd_btn_suscribe');
        inst = 'Envia-Suscripcion-email' + sep + idioma + sep + ctrl1.value + sep + ctrl2.value + sep + ctrl3.value;
        CallServerEmailSuscribe(inst, '');
    }
}

function contactus_envia_mensaje(idioma) {
		var fnombre = ObjetoporId('frm_contacto_nombre');
		var fapellido = ObjetoporId('frm_contacto_apellidos');
		var fmail = ObjetoporId('frm_contacto_mail');
		var ftel = ObjetoporId('frm_contacto_tel');
		var ftipo = ObjetoporId('frm_contacto_asunto');
		var ftipo_valor = ftipo[ftipo.selectedIndex].value;
		var fmsg = ObjetoporId('frm_contacto_message');
		var sep = '^|^';
		var inst = '';
		var stop = false;
	    
		if (fnombre.value == '' && !stop) {
			if (idioma == 'esp') alert('Por favor introduzca su Nombre.');
			else                 alert('Your First Name cannot be blank.');
			fnombre.focus();
			stop = true;
		}
		if (fapellido.value == '' && !stop) {
			if (idioma == 'esp') alert('Por favor introduzca sus Apellidos.');
			else                 alert('Your Last Name cannot be blank.');
			fapellido.focus();
			stop = true;
		}
		if (fmail.value == '' && !stop) {
			if (idioma == 'esp') alert('Por favor introduzca su e-mail.');
			else                 alert('Your e-mail cannot be blank.');
			fmail.focus();
			stop = true;
		}
		if (ftipo_valor == '' && !stop) {
			if (idioma == 'esp') alert('Por favor seleccione el tipo de solicitud.');
			else                 alert('The Inquiry Type cannot be blank.');
			ftipo.focus();
			stop = true;
		}
		if (fmsg.value == '' && !stop) {
			if (idioma == 'esp') alert('Por favor introduzca su mensaje.');
			else                 alert('The message content cannot be blank.');
			fmsg.focus();
			stop = true;
		}
	    
		if (!stop) {
			muestra_en_espera('BtnSub');   
			inst = 'Contactus-Envia-Msg' + sep + idioma + sep + fnombre.value + sep + fapellido.value + sep + fmail.value + sep + ftel.value + sep + ftipo_valor + sep + fmsg.value;
			CallServerContactus(inst, '');
		}
	}
