﻿// JScript File

var txt_cap_correo_es = 'escriba aqui su e-mail';
var txt_cap_correo_en = 'enter your e-mail here';

function ReceiveServerData(arg, context) {
    var R = arg.split('^|^');
    var control;
    
    switch (R[0]) {           
        case "Envia-Suscripcion-email":
            control = ObjetoporId('BtnSub');
            control.innerHTML = R[2];
            alert(R[1]);
            break;
            
        case "Contactus-Envia-Msg":
            control = ObjetoporId('BtnSub');
            control.innerHTML = R[2];
            alert(R[1]);
            break;
            
        case "Testimonio-Envia-Msg":
            control = ObjetoporId('BtnSub');
            control.innerHTML = R[2];
            alert(R[1]);
            break;
            
        case "Testimonio-lst-Envia-Msg":
            control = ObjetoporId('BtnSub');
            control.innerHTML = R[2];
            break;
    }
    
}
            
function ReceiveServerDataError(msg_error, context) {
    alert('Error. ' + msg_error);
    //$find('pup_espera').hide();
}

function dcontenido(obj,idioma) {
    if (idioma == 'esp') {
        if (obj.value == txt_cap_correo_es)      obj.value = '';
    } else {
        if (obj.value == txt_cap_correo_en)      obj.value = '';
    }   
}

function rcontenido(obj,idioma) {
    if (idioma == 'esp') {
        if (obj.value == '')      obj.value = txt_cap_correo_es;
    } else {
        if (obj.value == '')      obj.value = txt_cap_correo_en;
    }   
}

function suscribe_qcorreo(ctrl,idioma) {
    var ref = '';
    var obj = ObjetoporId(ctrl);
    
    if (obj.value == '' || obj.value == '.' || obj.value == txt_cap_correo_es || obj.value == txt_cap_correo_en) {
        if (idioma == 'esp')    alert('Por favor introduzca su correo electr\ónico.');
        else                    alert('Please enter your e-mail addess.');
    } else {
        if (idioma == 'esp')    ref = 'e-Boletin.html';
        else                    ref = 'e-Newsletter.html';
        window.location = './' + ref + '?ref=' + obj.value;
    }
}

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 suscribe_email(idioma) {
    var nombre_val = ObjetoporId('frm_nombre');
    var apellido_val = ObjetoporId('frm_apellido');
    var correo_val = ObjetoporId('frm_correo');
    var correo2_val = ObjetoporId('frm_correo2');
    var inst = '';
    var sep = '^|^';    
    var stop = false;
    
    if (nombre_val.value == '' && !stop){
        stop = true; 
        if (idioma == "esp")    alert('Por favor especifique su nombre. Gracias!');
        else                    alert('Please enter your first name. Thank you!');
        nombre_val.focus();
    }
    if (apellido_val.value == '' && !stop){
        stop = true; 
        if (idioma == "esp")    alert('Por favor especifique su apellido. Gracias!');
        else                    alert('Please enter your last name. Thank you!');
        apellido_val.focus();
    }
    if (correo_val.value == '' && !stop){
        stop = true; 
        if (idioma == "esp")    alert('Por favor especifique su correo electr\ónico. Gracias!');
        else                    alert('Please enter your e-mail address. Thank you!');
        correo_val.focus();
    }
    if (correo2_val.value == '' && !stop){
        stop = true; 
        if (idioma == "esp")    alert('Por favor confirme su correo electr\ónico. Gracias!');
        else                    alert('Please confirm your e-mail address. Thank you!');
        correo2_val.focus();
    }
    if (correo_val.value != '' && correo2_val.value != '' && correo_val.value != correo2_val.value && !stop){
        stop = true; 
        if (idioma == "esp")    alert('Por favor verifique su correo electr\ónico, \ndebe escribirlo igual en el campo de correo y \nen la confirmaci\ón. Gracias!');
        else                    alert('The confirmation e-mail must match your e-mail address. \nPlease verify your e-mails. Thank you!');
        correo2_val.focus();
    }
    
    if (!stop) {
        muestra_en_espera('BtnSub');
        
        inst += 'Envia-Suscripcion-email' + sep + idioma + sep + nombre_val.value + sep + apellido_val.value + sep + correo_val.value;
        CallServerEmailSuscribe(inst, '');
    }
}

function contactus_envia_mensaje(idioma) {
		var fnombre = ObjetoporId('frm_nombre');
		var fapellido = ObjetoporId('frm_apellidos');
		var fmail = ObjetoporId('frm_mail');
		var ftipo = ObjetoporId('frm_asunto');
		var ftipo_valor = ftipo[ftipo.selectedIndex].value;
		var fmsg = ObjetoporId('frm_review');
		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 + ftipo_valor + sep + tinyMCE.get('frm_review').getContent();
			CallServerContactus(inst, '');
		}
	}
	
function reviews_envia_mensaje(idioma) {
    var fnombre = ObjetoporId('frm_nombre');
    var fapellido = ObjetoporId('frm_apellidos');
    var fcorreo = ObjetoporId('frm_mail');
    var festancia_mes = ObjetoporId('frm_fecha_estancia_mes');      var festancia_mes_valor = festancia_mes[festancia_mes.selectedIndex].value;
    var festancia_anio = ObjetoporId('frm_fecha_estancia_anio');    var festancia_anio_valor = festancia_anio[festancia_anio.selectedIndex].value;
    var ftitulo = ObjetoporId('frm_titulo');
    //var fmsg = ObjetoporId('frm_review');
    var fmsg = tinyMCE.get('frm_review').getContent();
    var famigo = document.laforma.frm_recomendar_amigo;
    var famigo_checked;
    var fcalif;
    var lstars = new param('');
    
    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){
        stop = true; 
        if (idioma == "esp")    alert('Por favor especifique su apellido. Gracias!');
        else                    alert('Please enter your last name. Thank you!');
        fapellido.focus();
    }
    if (fcorreo.value == '' && !stop){
        stop = true; 
        if (idioma == "esp")    alert('Por favor especifique su correo electr\ónico. Gracias!');
        else                    alert('Please enter your e-mail address. Thank you!');
        fcorreo.focus();
    }
    if (ftitulo.value == '' && !stop){
        stop = true; 
        if (idioma == "esp")    alert('Por favor especifique el t\ítulo de su testimonio. Gracias!');
        else                    alert('Please enter the testimonial title. Thank you!');
        ftitulo.focus();
    }
    if (fmsg == '' && !stop){
        stop = true; 
        if (idioma == "esp")    alert('Por favor introduzca el contenido de su testimonio. Gracias!');
        else                    alert('Please enter your testimonial text. Thank you!');
        //fmsg.focus();
    }
    
    famigo_checked = valorGrupo(famigo);
    
    if (famigo_checked == null && !stop){
        stop = true; 
        if (idioma == "esp")    alert('Por favor especifique si nos recomendar\ía con un amigo. Gracias!');
        else                    alert('Please specify if you\'d recommend us to a friend. Thank you!');
    }
    
    //Las calificaciones
    fcalif = valorGrupo(famigo);
    
    if (!stop) {
        stop = dame_valores_stars(lstars);
        if (lstars.value == '') {
            if (idioma == "esp")    alert('Por favor eval\úe nuestro hotel utilizando todos los criterios. Presione cada grupo de estrellas por criterio para evaluarlos. \¡Gracias!');
            else                    alert('Please rate our hotel by clicking on each group of stars for each of the parameters. Thank you!');
        }
    }
    
	if (!stop) {
		muestra_en_espera('BtnSub');   
		inst += 'Testimonio-Envia-Msg' + sep + idioma + sep; 
		inst += fnombre.value + sep + fapellido.value + sep + fcorreo.value + sep + festancia_mes_valor + '-' + festancia_anio_valor + sep;
		inst += ftitulo.value + sep + fmsg + sep + famigo_checked + sep + lstars.value;
		
		//alert(inst);
		CallServerReviews(inst, '');
	}
}

function reviews_show_lst(idioma,bloque) {
    var sep = '^|^';
	var inst = '';
	
	muestra_en_espera('BtnSub');   
    inst += 'Testimonio-lst-Envia-Msg' + sep + idioma + sep + bloque; 
	CallServerReviewsLst(inst, '');
}

function valorGrupo(elem) {
    var cnt = -1;
    for (var i=elem.length-1; i > -1; i--) {
        if (elem[i].checked) {cnt = i; i = -1;}
    }
    if (cnt > -1) return elem[cnt].value;
    else return null;
}       

function param(initValue)
{   this.value = initValue}

function valor_star(campo,str1) {
    var ui1;
    
    ui1 = jQuery(campo).data("stars");   
    if (ui1.options.value != 999) {
        str1.value = ui1.options.name + ':' + ui1.options.value + ';';
        return true
    } else  {str1.value = ''; return false}
}
