﻿// JScript File

function ReceiveServerData(arg, context) {
    var R = arg.split('^|^');
    var control;
    
    switch (R[0]) {
        case "lista_tipos":
            control = ObjetoporId('QF_drop_tipos');
            control.innerHTML = R[1];
            break;
        
        case "lista_stays":
            control = ObjetoporId('PS_drop_hoteles_tipo');
            control.innerHTML = R[1];
            break;
            
        case "Go-Places-to-Stay":
            window.location = R[1];
            break;
        
        case "Go-Places-to-Stay-filtrado":
            window.location = R[1];
            break;
            
        case "Solicitud-QF":
            window.location = R[1];
            break;
            
        case "Go-Events-filtrado":
            window.location = R[1];
            break;
            
        case "Envia-Solicitud-Ad":
            control = ObjetoporId('BtnSub');
            control.innerHTML = R[2];
            alert(R[1]);
            break;
            
        case "Envia-Suscripcion-email":
            control = ObjetoporId('BtnSub');
            control.innerHTML = R[2];
            alert(R[1]);
            break;
    }
    
}
            
function ReceiveServerDataError(msg_error, context) {
    alert('Error. ' + msg_error);
    //$find('pup_espera').hide();
}

function carga_inicial() {
    //$find('pup_espera').hide();
    
    CallServerTipos('lista_tipos^|^', '');
}

//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 desactiva_tipos(control, idioma, busco) {
    var ctrl = ObjetoporId(control);
    var valor = busco[busco.selectedIndex].value;
    var posis = ctrl.selectedIndex;
    
    if (posis != -1) {
        if (idioma == "eng") 
            ctrl.options[posis].text = "loading...";
        else
            ctrl.options[posis].text = "cargando...";  
    }
    ctrl.style.backgroundColor = "#74774a"; 
    ctrl.style.color = "#000000";
    ctrl.disabled = true;
    
    CallServerTipos('lista_tipos^|^' + valor, '');
}

function desactiva_lista_stay(control, idioma, busco) {
    var ctrl = ObjetoporId(control);
    var valor = busco[busco.selectedIndex].value;
    var posis = ctrl.selectedIndex;
    
    if (posis != -1) {
        if (idioma == "eng") 
            ctrl.options[posis].text = "loading...";
        else
            ctrl.options[posis].text = "cargando...";  
    }
    ctrl.style.backgroundColor = "#74774a"; 
    ctrl.style.color = "#000000";
    ctrl.disabled = true;
    
    CallServerPlaces('lista_stays^|^' + valor, '');
}

function solicita_places_to_stay(ref_buscar_por, ref_choose, idioma) {
    var ctrl1 = ObjetoporId(ref_buscar_por);
    var ctrl2 = ObjetoporId(ref_choose);
    var inst = '';
    
    valor1 = ctrl1[ctrl1.selectedIndex].value;
    valor2 = ctrl2[ctrl2.selectedIndex].value;
    inst = 'Go-Places-to-Stay^|^' + valor1 + '^|^' + valor2 + '^|^' + idioma;
    
    CallServerPlaces(inst, '');
}

function lista_hoteles_cambio_area(filtro, orden, idioma) {
    var inst = '';
    var valor1 = 'zona';
    var ctrl1 = ObjetoporId(filtro);
    var cual_zona = ctrl1[ctrl1.selectedIndex].value;
    var ctrl2 = ObjetoporId(orden);
    ordenado_por = ctrl2[ctrl2.selectedIndex].value;
    
    inst = 'Go-Places-to-Stay-filtrado^|^' + valor1 + '^|^' + cual_zona + '^|^' + ordenado_por + '^|^' + idioma;
    CallServerPlaces(inst, '');
}

function lista_hoteles_cambio_de_orden(filtro, orden, idioma) {
    lista_hoteles_cambio_area(filtro, orden, idioma);
}

function solicitud_QF(busco, tipos, idioma) {
    var ctrl1 = ObjetoporId(busco);
    var ctrl2 = ObjetoporId(tipos);
    var valor1 = ctrl1[ctrl1.selectedIndex].value;
    var valor2 = ctrl2[ctrl2.selectedIndex].value;
    var inst = '';
    
    inst = 'Solicitud-QF^|^' + valor1 + '^|^' + valor2 + '^|^' + idioma;
    CallServerTipos(inst, '');
}

function lista_eventos_cambio_categ(ctrl1, idioma) {
    var valor1 = ctrl1[ctrl1.selectedIndex].value;
    
    inst = 'Go-Events-filtrado^|^' + valor1 + '^|^' + idioma;
    CallServerEventosCategs(inst, '');
}

function suscribe_qemail(idioma) {
    var campo = ObjetoporId('frm_correo');
    var ref = '';
    
    if (campo.value == '' || campo.value == '.') {
        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=' + campo.value;
    }
}

function solicitud_AD(idioma) {
    var cidioma = ObjetoporId('frm_ads_idioma');
    var cidioma_val = cidioma[cidioma.selectedIndex].value;
    var nombre_val = ObjetoporId('frm_contact_nombre');
    var emp_val = ObjetoporId('frm_contact_empresa');
    var correo_val = ObjetoporId('frm_contact_correo');
    var tel_val = ObjetoporId('frm_contact_tel');
    var fax_val = ObjetoporId('frm_contact_fax');
    var fact_nombre_val = ObjetoporId('frm_razon_social');
    var fact_dir_val = ObjetoporId('frm_contact_billing_dir');
    var fact_rfc = ObjetoporId('frm_rfc');
    var url_val = ObjetoporId('frm_ad_url');
    var desc_ad_val = ObjetoporId('frm_ad_describe');
    var coments_val = ObjetoporId('frm_ad_comments');
    var inst = '';
    var sep = '^|^';    
    var stop = false;
    
    muestra_en_espera('BtnSub');
    
    if (nombre_val.value == '' && !stop){
        stop = true; 
        if (idioma == "esp")    alert('Por favor especifique su nombre. Gracias!');
        else                    alert('Please enter your name. Thank you!');
        nombre_val.focus();
    }
    if (emp_val.value == '' && !stop){
        stop = true; 
        if (idioma == "esp")    alert('Por favor especifique su empresa. Gracias!');
        else                    alert('Please enter your company name. Thank you!');
        emp_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 (fact_nombre_val.value == '' && !stop){
        stop = true; 
        if (idioma == "esp")    alert('Por favor especifique su Raz\ón Social. Gracias!');
        else                    alert('Please enter your Company Name or Your Full Name. Thank you!');
        fact_nombre_val.focus();
    }
    if (fact_rfc.value == '' && !stop && idioma == 'esp'){
        stop = true; 
        if (idioma == "esp")    alert('Por favor especifique su RFC. Gracias!');
        else                    alert('Please enter your Taxes Code. Thank you!');
        fact_rfc.focus();
    }
    if (fact_dir_val.value == '' && !stop){
        stop = true; 
        if (idioma == "esp")    alert('Por favor especifique su direcci\ón fiscal. Gracias!');
        else                    alert('Please enter your Billing Address. Thank you!');
        fact_dir_val.focus();
    }
    if ((url_val.value == '' || url_val.value == 'http://') && !stop){
        stop = true; 
        if (idioma == "esp")    alert('Por favor especifique la p\ágina donde se enviar\á al visitante. Gracias!');
        else                    alert('Please enter your link URL where the visitor will be redirected. Thank you!');
        url_val.focus();
    }
    if (desc_ad_val.value == '' && !stop){
        stop = true; 
        if (idioma == "esp")    alert('Por favor describa su producto o servicio. Gracias!');
        else                    alert('Please describe your product or service. Thank you!');
        desc_ad_val.focus();
    }
    
    
    if (!stop) {
        inst += 'Envia-Solicitud-Ad' + sep + idioma + sep + nombre_val.value + sep + emp_val.value + sep + correo_val.value + sep;
        inst += tel_val.value + sep + fax_val.value + sep + fact_nombre_val.value + sep + fact_rfc.value + sep + fact_dir_val.value + sep;
        inst += url_val.value + sep + desc_ad_val.value + sep + coments_val.value + sep + cidioma_val;
        CallServerEnviaAD(inst, '');
    }
}

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 mover_ver_video() {
    window.location.hash = 'inicia_video';
}

/*
Auto center window script- Eric King (http://redrival.com/eak/index.shtml)
Permission granted to Dynamic Drive to feature script in archive
For full source, usage terms, and 100's more DHTML scripts, visit http://dynamicdrive.com
*/

var win = null;
function NewWindow(mypage,myname,w,h,scroll,tamano){
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings =
'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable=' + tamano
win = window.open(mypage,myname,settings)
}


function track (link, ic, ip, tipo)
{
    new Image().src = 'tracking.html?href=' + link.href + '&ic=' + ic + '&ip=' + ip + '&tipo=' + tipo;
}

function trackFlash (href, ic, ip) {
    new Image().src = 'tracking.html?href=' + href + '&ic=' + ic + '&ip=' + ip + "&tipo=banner";
}
