﻿// Seteo variables globales
var ecoQuantity = '';
var ecoQuantityHelp = '';
var timeCount;

window.onload = function(){
    //Cargo genero
    loadDropDownCombo("txtGender",[{id:'',detail:'Select'},{id:'Male',detail:'Male'},{id:'Female',detail:'Female'}]);
    
    //Completo el combo con los países y ciudades
    cargarPaises();
    cargarPaisesHotel();  
    
    cargarRelationships();
    cargarMonedas();  
    
    //validaciones on line
    $('txtUserName').onchange = checkearUserName; 
    $('txtPassword_1').onchange = checkearPassword;
    $('txtPassword_2').onchange = checkearPassword2;
    $('txtEmail').onchange = checkearEmail;
    $('txtWebsite').onchange = checkearWebsite;
    $('txtCity').onchange = checkearCiudad;
    $('txtHotelEmail').onchange = checkearHotelEmail;
    $('txtHotelWebsite').onchange = checkearWebsiteHotel;
    $('txtHotelCity').onchange = checkearCiudadHotel;
    
    $('txtHotelRateMin').onkeypress = checkForNumbersMin;
    $('txtHotelRateMin').onkeyup = checkForNumbersMin;
    $('txtHotelRateMin').onchange = checkForNumbersMin;
    
    $('txtHotelRateMax').onkeypress = checkForNumbersMax;
    $('txtHotelRateMax').onkeyup = checkForNumbersMax; 
    $('txtHotelRateMax').onchange = checkForNumbersMax;
  
    $("Bmonth").onchange = function(){setDayCombo(this.value);}  
    setYearCombo();
    setMonthCombo();
    setDayCombo(0);
    
    $("AceptoTerms").onclick = showRegister;

}

function showEcoExpert() {
    var win = null;
    var index = 1;
    var url = null;
    url = "EcoExperience_popup.aspx";
    Dialog.confirm({url:url}, 
               {windowParameters: {className: "alphacube", width:700, height:530, closable:false}, okLabel: "Ok", 
                ok:function(win) { searchEcovalues(); return true; },
                onCancel:function(win) {return true; }
                });
    index++;
    waiting();
}
 
function waiting()
{
    if($('totalItems') != null)
    {
        clearTimeout(timeCount);
        searchToCheck();
    }
    else
    {
        timeCount = setTimeout(waiting, 1000);
    }
}
 
function searchToCheck()
{
    var Arr = new Array(); 
    Arr.length = 0;   
    Arr = ecoQuantityHelp.split(',');
        var item;
        var seleccionado;
        var total = $('totalItems').value;
        if(ecoQuantityHelp.length != 0)
        {
            for(var i=1; i<=total; i++)
            {
                item = $('id_' + i);   
                if(Arr[i-1] != '0')
                {
                    item.checked = true;
                }
                else
                {
                    item.checked = false; 
                }       
            }
        }
}

function checkEcoQuantity()
{
    var respuesta = true;
    var EcoArr = ecoQuantity.split(',');
    if(EcoArr.length < 9)
    {
        $('lblEcoQuantity').innerHTML = 'You Need 9 Min';
        $('lblEcoQuantity').className="errores"; 
        
        respuesta = false;
    }
    else
    {
        $('lblEcoQuantity').innerHTML = '*';
        $('lblEcoQuantity').className="txt_form_resultado";
    }
    
    return respuesta;
}

function searchEcovalues()
{
    ecoQuantity = '';
    ecoQuantityHelp = '';
    var total = $('totalItems').value;
    var item;
    
    for(var i=1; i<=total; i++)
    {           
        item = $('id_' + i);        
        if(item.checked)
        {
            var numero = item.id.replace('id_','');
            ecoQuantity+= numero + ",";
            ecoQuantityHelp+= numero + ",";
        }
        else
        {
            ecoQuantityHelp+= 0 + ",";
        }
    }
    
    ecoQuantity = ecoQuantity.substring(0, ecoQuantity.length-1);
    ecoQuantityHelp = ecoQuantityHelp.substring(0, ecoQuantityHelp.length-1);
}

function cargarRelationships(){
    $Ajax(basepath + "controllers/AccountHotel/CreateHotelAccount.aspx?method=getRelationshipTypes", {
            cache: false,
            onfinish:function(relations){ 
                loadDropDownCombo("txtContactRelation",relations,"Select Your Relationship"); 
                $("txtContactRelation").onchange=function(){
                    if($F("txtContactRelation")=="Other"){
                        show("txtOtherRelation");
                    }
                    else{
                        hide("txtOtherRelation");
                    }
                
                }
            }, 
            tipoRespuesta:$tipo.JSON});
}

function cargarMonedas(){
    $Ajax(basepath + "controllers/AccountHotel/CreateHotelAccount.aspx?method=getCurrencyTypes", {
            cache: false,
            onfinish:function(monedas){ 
                loadDropDownCombo("txtHotelRateCurrency",monedas,"Currency"); 
                $("txtHotelRateCurrency").onchange=function(){
                    if($F("txtHotelRateCurrency")=="Other"){
                        show("txtOtherCurrency");
                    }
                    else{
                        hide("txtOtherCurrency");
                    }
                
                }
            }, 
            tipoRespuesta:$tipo.JSON});
}

function cargarPaises(){
    $("txtCountry").value = '';
    $("txtCountry").disabled = true;
    $("txtRegion").value = '';
    $("txtRegion").disabled = true;
    $("txtCity").value = '';
    $("txtCity").disabled = true; 
       
    $Ajax(basepath + "Controllers/Locations/locations.aspx?method=getCountries", {
            cache: false,
            onfinish:function(paises){ 
                loadDropDownCombo("txtCountry",paises,"Select Country");
                $("txtCountry").disabled = false; 
            }, 
            tipoRespuesta:$tipo.JSON});
            
    //agrega la funcion para q cargue las regiones al cambiar el pais
        $("txtCountry").onchange = function(){
            $("txtRegion").value = '';
            $("txtRegion").disabled = true;
            $("txtCity").value = '';
            $("txtCity").disabled = true;
            $Ajax(basepath+"Controllers/Locations/locations.aspx?method=getRegions&country_id="+this.value, {
                cache: false,
                onfinish:function(regions){ 
                    loadDropDownCombo("txtRegion",regions,"Select Region"); 
                    $("txtRegion").disabled = false;
                }, 
                tipoRespuesta:$tipo.JSON});
        }
        
        //agrega la funcion para q cargue las ciudades al cambiar la region
        $("txtRegion").onchange = function(){
            $("txtCity").value = '';
            $("txtCity").disabled = true;
            hide("loadingCity");
            $Ajax(basepath+"Controllers/Locations/locations.aspx?method=getCities&region_id="+this.value, {
                cache: false,
                avisoCargando:'loadingCity',
                onfinish:function(cities){ 
                    loadDropDownCombo("txtCity",cities,"Select City"); 
                    $("txtCity").disabled = false;
                }, 
                tipoRespuesta:$tipo.JSON});
        }         
}

function cargarPaisesHotel(){
    $("txtHotelCountry").value = '';
    $("txtHotelCountry").disabled = true;
    $("txtHotelRegion").value = '';
    $("txtHotelRegion").disabled = true;
    $("txtHotelCity").value = '';
    $("txtHotelCity").disabled = true; 
       
    $Ajax(basepath + "Controllers/Locations/locations.aspx?method=getCountries", {
            cache: false,
            onfinish:function(paises){ 
                loadDropDownCombo("txtHotelCountry",paises,"Select Country");
                $("txtHotelCountry").disabled = false; 
            }, 
            tipoRespuesta:$tipo.JSON});
            
    //agrega la funcion para q cargue las regiones al cambiar el pais
        $("txtHotelCountry").onchange = function(){
            $("txtHotelRegion").value = '';
            $("txtHotelRegion").disabled = true;
            $("txtHotelCity").value = '';
            $("txtHotelCity").disabled = true;
            $Ajax(basepath+"Controllers/Locations/locations.aspx?method=getRegions&country_id="+this.value, {
                cache: false,
                onfinish:function(regions){ 
                    loadDropDownCombo("txtHotelRegion",regions,"Select Region"); 
                    $("txtHotelRegion").disabled = false;
                }, 
                tipoRespuesta:$tipo.JSON});
        }
        
        //agrega la funcion para q cargue las ciudades al cambiar la region
        $("txtHotelRegion").onchange = function(){
            $("txtHotelCity").value = '';
            $("txtHotelCity").disabled = true;
            hide("loadingHotelCity");
            $Ajax(basepath+"Controllers/Locations/locations.aspx?method=getCities&region_id="+this.value, {
                cache: false,
                avisoCargando:'loadingHotelCity',
                onfinish:function(cities){ 
                    loadDropDownCombo("txtHotelCity",cities,"Select City"); 
                    $("txtHotelCity").disabled = false;
                }, 
                tipoRespuesta:$tipo.JSON});
        }         
}

//Creo los WaterMarks
function set_watermarks(){
        watermark('txtUserName', 'Enter Your UserName', 'input_marcagua');
        watermark('txtRealName', 'Enter Your Name', 'input_marcagua');
        watermark('txtSurname', 'Enter Your SurName', 'input_marcagua');
        watermark('txtEmail', 'Enter Your Email', 'input_marcagua');
        watermark('txtWebsite', 'http://www.yourwebsite.com', 'input_marcagua');
        watermark('txtAddress', 'Enter Your Address', 'input_marcagua');
        watermark('txtPostalCode', 'Enter Your Postal Code', 'input_marcagua');
        watermark('txtTelephone', 'Enter Your Phone', 'input_marcagua');
        watermark('txtHotelName', 'Enter Hotel Name', 'input_marcagua');
        watermark('txtHotelAddress', 'Enter Hotel Address', 'input_marcagua');
        watermark('txtHotelTelephone', 'Enter Hotel Phone', 'input_marcagua');
        watermark('txtHotelEmail', 'Enter Hotel Email', 'input_marcagua');
        watermark('txtHotelWebsite', 'http://www.hotelwebsite.com', 'input_marcagua');
        watermark('txtHotelFacilities', 'Enter Hotel Facilities', 'input_marcagua');
        watermark('txtOtherCurrency', 'Enter Currency', 'input_marcagua');
        watermark('txtOtherRelation', 'Enter Relationship', 'input_marcagua');
        watermark('txtHotelRateMin', 'Number', 'input_marcagua');
        watermark('txtHotelRateMax', 'Number', 'input_marcagua');
}

document.observe('dom:loaded', set_watermarks);


function showRegister()
{   
    if($("AceptoTerms").checked)
    {        
        $("imgSave").className = "input_botons";
        $("imgSave").disabled = "";
    }
    else{
        $("imgSave").className = "input_botons_off";
        $("imgSave").disabled = "disabled";
    }
    
}

function showTerms(type) { 
    var win = null;
    var index = 1;
    var url = null;
    url = basepath + "Terms_Privacy/HotelPolicy_popup.aspx";
    Dialog.alert({url:url}, 
               {windowParameters: {className: "alphacube", width:600, height:450, closable:false}, okLabel: "Close", 
                ok:function(win) {return true;}});
    index++;
} 

function showPrivacy(type) { 
    var win = null;
    var index = 1;
    var url = null;
    url = basepath + "Terms_Privacy/Privacy_popup.aspx";
    Dialog.alert({url:url}, 
               {windowParameters: {className: "alphacube", width:600, height:450, closable:false}, okLabel: "Close", 
                ok:function(win) {return true;}});
    index++;
} 

function checkUserData(){
    var result = validateFields();
    if(result){ saveAccount(); }
    return false;
}

function checkearUserName(){
    var retval = true;
    
    if($F('txtUserName') == '' || $F('txtUserName') == 'Enter Your UserName')
    {
        $('lblUserName').innerHTML = 'Field required !';
        $('txtUserName').style.backgroundColor = '#ecece0';
        $('lblUserName').className="errores"; 
        retval = false;
    }
    else if(!checkUserName())
    {
        $('lblUserName').innerHTML = 'Just [a-z] & [0-9] are Allowed ';
        $('txtUserName').style.backgroundColor = '#ecece0';
        $('lblUserName').className = "errores";
        retval = false;
        
    }
    else
    {    
        $Ajax(basepath + "controllers/AccountHotel/CreateHotelAccount.aspx?method=checkearUserName&userName=" + $F('txtUserName'), {
            cache: false, 
            onfinish: function(html) {
                                 
                if(html == '1'){
                    $('txtUserName').style.backgroundColor = '#98FB98';
                    $('lblUserName').innerHTML = 'User available';
                    $('lblUserName').style.color = '#999945';
                    //alert('llego a 1');
                    retval = true;
                }
                else{
                    $('txtUserName').style.backgroundColor = '#ecece0';
                    $('lblUserName').innerHTML = 'User Unavailable';
                    $('lblUserName').className="errores"; 
                    retval = false;
                }
                    
            }, 
            tipoRespuesta:$tipo.TEXTO});
    }
 
    return retval;
}

function checkearEmail(){
    var retval = true;
    
    //Verifico que el campo no esté vacío
    if($F("txtEmail") == '' || $F("txtEmail") == 'Enter Your Email'){    
        $('txtEmail').style.backgroundColor = '#ecece0';
        $('lblEmail').innerHTML = 'Field required !';
        $('lblEmail').className="errores"; 
        retval = false;
    }
    else{
        if(!checkEmail($F('txtEmail'))){
            $('txtEmail').style.backgroundColor = 'white';
            $('lblEmail').innerHTML = 'Not Valid!';
            $('lblEmail').className="errores";
            retval = false;
        }
        else{
            $Ajax(basepath + "controllers/AccountHotel/CreateHotelAccount.aspx?method=checkearUserMail&email=" + $F('txtEmail'), {
                cache: false, 
                onfinish: function(html) {
                    
                    if(html == '1'){
                        $('txtEmail').style.backgroundColor = '#98FB98';
                        $('lblEmail').innerHTML = 'Email available';
                        $('lblEmail').style.color = '#999945';
                        retval = true;
                    }
                    else{
                        $('txtEmail').style.backgroundColor = '#ecece0';
                        $('lblEmail').innerHTML = 'Email Unavailable';
                        $('lblEmail').className="errores"; 
                        retval = false;
                    }
                }, 
                tipoRespuesta:$tipo.TEXTO});
        }
    }
    return retval;
}

function checkearHotelEmail(){
    var retval = true;
    
    if($F("txtHotelEmail") == '' || $F("txtHotelEmail") == 'Enter Hotel Email'){    
        $('txtHotelEmail').style.backgroundColor = '#ecece0';
        $('lblHotelEmail').innerHTML = 'Field required !';
        $('lblHotelEmail').className="errores"; 
        retval = false;
    }
    else{
        if(!checkEmail($F('txtHotelEmail'))){
            $('txtHotelEmail').style.backgroundColor = '#ecece0';
            $('lblHotelEmail').innerHTML = 'Not Valid!';
            $('lblHotelEmail').className="errores"; 

            retval = false;
        }
        else{
            $('txtHotelEmail').style.backgroundColor = 'white';
            $('lblHotelEmail').innerHTML = '*';
            $('lblHotelEmail').className="txt_form_resultado";
        }
    }
    return retval;
}

function checkearPassword(){
    var retval = true;
    
    if($F('txtPassword_1').length < 5)
    {
       $('txtPassword_1').style.backgroundColor = '#ecece0';
       $('lblPassword_1').innerHTML = 'Min 5 - Max 20';
       $('lblPassword_1').className="errores"; 
       
       retval = false;
    }
    else{
        $('txtPassword_1').style.backgroundColor = '#FFFFFF';
        $('lblPassword_1').innerHTML = '*';
        $('lblPassword_1').className="txt_form_resultado";
        
    }  
    checkearPassword2();
    return retval;
}

function checkearPassword2(){
    var retval = true;
    
    if($F("txtPassword_2") == '')
    {
        $('txtPassword_2').style.backgroundColor = '#ecece0';
        $('lblPassword_2').innerHTML = 'Field required !';
        $('lblPassword_2').className="errores"; 
        
        retval = false;
    }
    else if($F("txtPassword_1") != $F("txtPassword_2") )
    {
        $('txtPassword_2').style.backgroundColor = '#ecece0';
        $('lblPassword_2').innerHTML = "Passwords don't match !";
        $('lblPassword_2').className="errores"; 
        
        retval = false;
    }
    else
    {
        $('txtPassword_2').style.backgroundColor = 'white';
        $('lblPassword_2').innerHTML = '*';
        $('lblPassword_2').className="txt_form_resultado";
    }
    
    
   return retval;
}

function checkearEdad(){
    var retval = true;
    
    var anionac = $('Byear').value;
    var dianac = $('Bday').value;
    var mnac = $('Bmonth').value;
    var ahora = new Date();
    var hoy = ahora.getFullYear();
    var diferencia = parseInt(hoy) - parseInt(anionac);
        

    if(anionac == '00' || dianac=='00' || mnac=='00')
    {
        $('Byear').style.backgroundColor = '#ecece0';
        $('Bmonth').style.backgroundColor = '#ecece0';
        $('Bday').style.backgroundColor = '#ecece0';
        $('lblBirthDay').innerHTML = 'Field required !';
        $('lblBirthDay').className="errores"; 
        retval = false;
    }
    else if(dianac == '29' && mnac == '02')
    {
        var birthday = "02/29/" +  anionac;
        if(checkLeapYear(birthday))
        {
            $('Byear').style.backgroundColor = 'white';
            $('Bmonth').style.backgroundColor = 'white';
            $('Bday').style.backgroundColor = 'white';
            $('lblBirthDay').innerHTML = '*';
            $('lblBirthDay').className="txt_form_resultado";
            retval = true;
        }
        else
        {
            $('Byear').style.backgroundColor = '#ecece0';
            $('Bmonth').style.backgroundColor = '#ecece0';
            $('Bday').style.backgroundColor = '#ecece0';
            $('lblBirthDay').innerHTML = 'Invalid Date';
            $('lblBirthDay').className = "errores";
            retval = false;
        }
    }
    else if(diferencia < 13) 
    {
        $('Byear').style.backgroundColor = '#ecece0';
        $('Bmonth').style.backgroundColor = '#ecece0';
        $('Bday').style.backgroundColor = '#ecece0';
        $('lblBirthDay').innerHTML = '13+ Only';
        $('lblBirthDay').className="errores"; 
        retval = false;
    }
    else
    {
        $('Byear').style.backgroundColor = 'white';
        $('Bmonth').style.backgroundColor = 'white';
        $('Bday').style.backgroundColor = 'white';
        $('lblBirthDay').innerHTML = '*';
        $('lblBirthDay').className="txt_form_resultado";
    }
    
    return retval;
}    

function checkearCiudad(){
    var retval = true;
    
    if($F("txtCity") == '')
    {
        $('txtCity').style.backgroundColor = '#ecece0';
        $('lblCity').innerHTML = 'Field required !';
        $('lblCity').className="errores"; 
        
        retval = false;
    }
    else{
        $('txtCity').style.backgroundColor = 'white';
        $('lblCity').innerHTML = '*';
        $('lblCity').className="txt_form_resultado";
        
    }
    
    return retval;
}    

function checkearCiudadHotel(){
    var retval = true;
    
    if($F("txtHotelCity") == '')
    {
        $('txtHotelCity').style.backgroundColor = '#ecece0';
        $('lblHotelCity').innerHTML = 'Field required !';
        $('lblHotelCity').className="errores"; 
        
        retval = false;
    }
    else{
        $('txtHotelCity').style.backgroundColor = 'white';
        $('lblHotelCity').innerHTML = '*';
        $('lblHotelCity').className="txt_form_resultado";
    }
   
    return retval;
}

function checkearWebsite(){
    var retval = true;
    
    if($F("txtWebsite").replace(/\s*/,'') != "" && !checkWebSite($F("txtWebsite")))
    {
        $('txtWebsite').style.backgroundColor = '#ecece0';
        $('lblWebsite').innerHTML = 'Not Valid!';
        $('lblWebsite').className="errores"; 
        
        retval = false;
    }
    else{
        $('txtWebsite').style.backgroundColor = 'white';
        $('lblWebsite').innerHTML = '';
        $('lblWebsite').className="txt_form_resultado";
    }
   
    return retval;
}

function checkearWebsiteHotel(){
    var retval = true;
    
    if($F("txtHotelWebsite").replace(/\s*/,'') != "" && !checkWebSite($F("txtHotelWebsite")))
    {
        $('txtHotelWebsite').style.backgroundColor = '#ecece0';
        $('lblHotelWebsite').innerHTML = 'Not Valid!';
        $('lblHotelWebsite').className="errores"; 
        
        retval = false;
    }
    else{
        $('txtHotelWebsite').style.backgroundColor = 'white';
        $('lblHotelWebsite').innerHTML = '';
        $('lblHotelWebsite').className="txt_form_resultado";
    }
   
    return retval;
}

function checkUserName()
{
    var regular = new RegExp("[a-z]|[0-9]", "i");
    var letters;    
    
    letters = $('txtUserName');
    
    letter = letters.value.split('');
    for(var i=0; i<=letter.length; i++)
    {
        if(!regular.test(letter[i]))
        {   
            return false;
        }
    }
    return true;
}

function checkForNumbersMin()
{
    var regNum = new RegExp("[0-9]", "i");
    var nums = $('txtHotelRateMin');
    
    num = nums.value.split('');
    for(var i=0; i<=num.length; i++)
    {
        if(!regNum.test(num[i]))
        {   
            nums.value = nums.value.replace(num[i], '');
        }
    }
}

function checkForNumbersMax()
{
    var regNum = new RegExp("[0-9]", "i");
    var nums = $('txtHotelRateMax');
    
    num = nums.value.split('');
    for(var i=0; i<=num.length; i++)
    {
        if(!regNum.test(num[i]))
        {   
            nums.value = nums.value.replace(num[i], '');
        }
    }
}

function CheckPalFacilities()
{    
    var arrContent;
    arrContent = $F("txtHotelFacilities").split(/[\s\n]/);
    
    var result = arrContent.all(
        function(pal){
            //alert(pal);    
            if(pal.length > 40)
            {
                $('txtHotelFacilities').style.backgroundColor = '#ecece0';
                $('lblHotelFacilities').innerHTML = pal + ' excedes allowed length, max is 40 characters';
                $('lblHotelFacilities').className="errores";
                return false;
            }
            else
	        {
                $('txtHotelFacilities').style.backgroundColor = 'white';
                $('lblHotelFacilities').innerHTML = '*';
                $('lblHotelFacilities').className="txt_form_resultado";
                return true;
            }
        }
    );
    return result;
}

//Valida la calidad de los datos
function validateFields(){
    var valid = true;
   
    //Valido Nombre de Usuario
    valid &= checkearUserName();
    //chequeo passwords
    valid &= checkearPassword();
    valid &= checkearPassword2();
    //Chequeo la Edad
    valid &= checkearEdad();
    //Valido E-Mail del Usuario
    valid &= checkearEmail(); 
    //valido direccion web
    valid &= checkearWebsite();
    
    
    if($F("txtRealName").replace(/\s*/,'') == '' || $F("txtRealName") == 'Enter Your Name')
    {
        $('txtRealName').style.backgroundColor = '#ecece0';
        $('lblRealName').innerHTML = 'Field required !';
        $('lblRealName').className="errores"; 
        
        valid &= false;
    }
    else
	{
        $('txtRealName').style.backgroundColor = 'white';
        $('lblRealName').innerHTML = '*';
        $('lblRealName').className="txt_form_resultado";
    }
        
    if($F("txtSurname").replace(/\s*/,'') == '' || $F("txtSurname") == 'Enter Your SurName')
    {
        $('txtSurname').style.backgroundColor = '#ecece0';
        $('lblSurname').innerHTML = 'Field required !';
        $('lblSurname').className="errores"; 
        
        valid &= false;
    }
    else
	{
        $('txtSurname').style.backgroundColor = 'white';
        $('lblSurname').innerHTML = '*';
        $('lblSurname').className="txt_form_resultado";
    }
       
    if($F("txtContactRelation").replace(/\s*/,'') == '' || ($F("txtContactRelation") == "Other" && $F("txtOtherRelation") == 'Enter Relationship'))
    {
        $('txtContactRelation').style.backgroundColor = '#ecece0';
        $('txtOtherRelation').style.backgroundColor = '#ecece0';
        $('lblContactRelation').innerHTML = 'Field required !';
        $('lblContactRelation').className="errores"; 
        
        valid &= false;
    }
    else
	{
        $('txtContactRelation').style.backgroundColor = 'white';
        $('txtOtherRelation').style.backgroundColor = 'white';
        $('lblContactRelation').innerHTML = '*';
        $('lblContactRelation').className="txt_form_resultado";
    }
    
    if($F("txtGender") == '')
    {
        $('txtGender').style.backgroundColor = '#ecece0';
        $('lblGender').innerHTML = 'Field required !';
        $('lblGender').className="errores"; 
        
        valid &= false;
    }
    else
	{
        $('txtGender').style.backgroundColor = 'white';
        $('lblGender').innerHTML = '*';
        $('lblGender').className="txt_form_resultado";
    }
    
    if($F("txtAddress").replace(/\s*/,'') == '' || $F("txtAddress") == 'Enter Your Address')
    {
        $('txtAddress').style.backgroundColor = '#ecece0';
        $('lblAddress').innerHTML = 'Field required !';
        $('lblAddress').className="errores"; 
        
        valid &= false;
    }
    else
	{
        $('txtAddress').style.backgroundColor = 'white';
        $('lblAddress').innerHTML = '*';
        $('lblAddress').className="txt_form_resultado";
    }
    
    if($F("txtPostalCode").replace(/\s*/,'') == '' || $F("txtPostalCode") == 'Enter Your Postal Code')
    {
        $('txtPostalCode').style.backgroundColor = '#ecece0';
        $('lblPostalCode').innerHTML = 'Field required !';
        $('lblPostalCode').className="errores"; 
        
        valid &= false;
    }
    else
	{
        $('txtPostalCode').style.backgroundColor = 'white';
        $('lblPostalCode').innerHTML = '*';
        $('lblPostalCode').className="txt_form_resultado";
    }
    
    if($F("txtTelephone").replace(/\s*/,'') == '' || $F("txtTelephone") == 'Enter Your Phone')
    {
        $('txtTelephone').style.backgroundColor = '#ecece0';
        $('lblTelephone').innerHTML = 'Field required !';
        $('lblTelephone').className="errores"; 
        
        valid &= false;
    }
    else
	{
        $('txtTelephone').style.backgroundColor = 'white';
        $('lblTelephone').innerHTML = '*';
        $('lblTelephone').className="txt_form_resultado";
    }
       
    if($F("txtCountry") == '')
    {
        $('txtCountry').style.backgroundColor = '#ecece0';
        $('lblCountry').innerHTML = 'Field required !';
        $('lblCountry').className="errores"; 
        
        valid &= false;
    }
    else
    {
        $('txtCountry').style.backgroundColor = 'white';
        $('lblCountry').innerHTML = '*';
        $('lblCountry').className="txt_form_resultado";
    } 
    
    if($F("txtRegion") == '')
    {
        $('txtRegion').style.backgroundColor = '#ecece0';
        $('lblRegion').innerHTML = 'Field required !';
        $('lblRegion').className="errores"; 
        
        valid &= false;
    }
    else
    {
        $('txtRegion').style.backgroundColor = 'white';
        $('lblRegion').innerHTML = '*';
        $('lblRegion').className="txt_form_resultado";
    }      
 
    valid &= checkearCiudad();
    
    if($F("txtHotelName").replace(/\s*/,'') == '' || $F("txtHotelName") == 'Enter Hotel Name')
    {
        $('txtHotelName').style.backgroundColor = '#ecece0';
        $('lblHotelName').innerHTML = 'Field required !';
        $('lblHotelName').className="errores"; 
        
        valid &= false;
    }
    else
	{
        $('txtHotelName').style.backgroundColor = 'white';
        $('lblHotelName').innerHTML = '*';
        $('lblHotelName').className="txt_form_resultado";
    }
    
    if($F("txtHotelAddress").replace(/\s*/,'') == '' || $F("txtHotelAddress") == 'Enter Hotel Address')
    {
        $('txtHotelAddress').style.backgroundColor = '#ecece0';
        $('lblHotelAddress').innerHTML = 'Field required !';
        $('lblHotelAddress').className="errores"; 
        
        valid &= false;
    }
    else
	{
        $('txtHotelAddress').style.backgroundColor = 'white';
        $('lblHotelAddress').innerHTML = '*';
        $('lblHotelAddress').className="txt_form_resultado";
    }
    
    if($F("txtHotelTelephone").replace(/\s*/,'') == '' || $F("txtHotelTelephone") == 'Enter Hotel Phone')
    {
        $('txtHotelTelephone').style.backgroundColor = '#ecece0';
        $('lblHotelTelephone').innerHTML = 'Field required !';
        $('lblHotelTelephone').className="errores"; 
        
        valid &= false;
    }
    else
	{
        $('txtHotelTelephone').style.backgroundColor = 'white';
        $('lblHotelTelephone').innerHTML = '*';
        $('lblHotelTelephone').className="txt_form_resultado";
    }
    
    //valid &= checkearEmailHotel();
    valid &= checkearWebsiteHotel();
    
    if($F("txtHotelFacilities").replace(/\s*/,'') == '' || $F("txtHotelFacilities") == 'Enter Hotel Facilities')
    {
        $('txtHotelFacilities').style.backgroundColor = '#ecece0';
        $('lblHotelFacilities').innerHTML = 'Field required !';
        $('lblHotelFacilities').className="errores"; 
        
        valid &= false;
    }
    else
	{
        $('txtHotelFacilities').style.backgroundColor = 'white';
        $('lblHotelFacilities').innerHTML = '*';
        $('lblHotelFacilities').className="txt_form_resultado";
    }
    
    if($F("txtHotelRateCurrency").replace(/\s*/,'') == '')
    {
        $('txtHotelRateCurrency').style.backgroundColor = '#ecece0';
        $('lblHotelRates').innerHTML = 'Field required !';
        $('lblHotelRates').className="errores"; 
        
        valid &= false;
    }
    else if($F("txtHotelRateCurrency") == 'Other' && $F("txtOtherCurrency") == 'Enter Currency')
    {
        $('txtHotelRateCurrency').style.backgroundColor = '#ecece0';
        $('txtOtherCurrency').style.backgroundColor = '#ecece0';
        $('lblHotelRates').innerHTML = 'Field required !';
        $('lblHotelRates').className="errores"; 
        
        valid &= false;
    }
    else
	{
        $('txtHotelRateCurrency').style.backgroundColor = 'white';
        $('txtOtherCurrency').style.backgroundColor = 'white';
        $('lblHotelRates').innerHTML = '*';
        $('lblHotelRates').className="txt_form_resultado";
    }
    
    if($F("txtHotelRateMin") == 'Number' || $F("txtHotelRateMin").replace(/\s*/,'') == '')
    {
        $('txtHotelRateMin').style.backgroundColor = '#ecece0';
        $('lblHotelRates').innerHTML = 'Field required !';
        $('lblHotelRates').className="errores"; 
        
        valid &= false;
    }
    else if($F("txtHotelRateMax") == 'Number' || $F("txtHotelRateMax").replace(/\s*/,'') == '')
    {
        $('txtHotelRateMax').style.backgroundColor = '#ecece0';
        $('lblHotelRates').innerHTML = 'Field required !';
        $('lblHotelRates').className="errores"; 
        
        valid &= false;
    }
    else if(parseInt($F("txtHotelRateMax")) < parseInt($F("txtHotelRateMin")))
    {
        $('txtHotelRateMax').style.backgroundColor = '#ecece0';
        $('lblHotelRates').innerHTML = 'Invalid Values';
        $('lblHotelRates').className="errores"; 
    
        valid &= false;
    }
    else
    {
        $('txtHotelRateMax').style.backgroundColor = 'white';
        $('txtHotelRateMin').style.backgroundColor = 'white';
        $('lblHotelRates').innerHTML = '*';
        $('lblHotelRates').className="txt_form_resultado";
    }
    
 
    if($F("txtHotelCountry") == '')
    {
        $('txtHotelCountry').style.backgroundColor = '#ecece0';
        $('lblHotelCountry').innerHTML = 'Field required !';
        $('lblHotelCountry').className="errores"; 
        
        valid &= false;
    }
    else
    {
        $('txtHotelCountry').style.backgroundColor = 'white';
        $('lblHotelCountry').innerHTML = '*';
        $('lblHotelCountry').className="txt_form_resultado";
    }    
    
    if($F("txtHotelRegion") == '')
    {
        $('txtHotelRegion').style.backgroundColor = '#ecece0';
        $('lblHotelRegion').innerHTML = 'Field required !';
        $('lblHotelRegion').className="errores"; 
        
        valid &= false;
    }
    else
    {
        $('txtHotelRegion').style.backgroundColor = 'white';
        $('lblHotelRegion').innerHTML = '*';
        $('lblHotelRegion').className="txt_form_resultado";
    }    
    
    valid &= checkearCiudadHotel();
    valid &= CheckPalFacilities();
    valid &= checkEcoQuantity();
  
    if(!$("AceptoTerms").checked)
    {
        $('lblTerms').innerHTML = 'Must Agree to Terms & Conditions';
        $('lblTerms').className="errores"; 
        
        valid &= false;
    }    
    else
    {
        $('lblTerms').innerHTML = '';
        $('lblTerms').className="txt_form_resultado";
    }
    
    return valid;
}

//guardado
function saveAccount(){
    
    if ($F("txtContactRelation")=="Other")
    {    var relationship = "Other#"+deleteInvalidTags($F("txtOtherRelation"));}
    else
    {    var relationship = $F("txtContactRelation");}        
        
    if ($F("txtHotelRateCurrency")=="Other")
    {    var currency = "Other#"+deleteInvalidTags($F("txtOtherCurrency"));}
    else
    {    var currency = $F("txtHotelRateCurrency");}
       
        
    //Borro contenido de error
    $('lblResult').innerHTML = '';
    $('imgSave').disabled = true;

    $Ajax(basepath + "controllers/AccountHotel/CreateHotelAccount.aspx?method=saveAccount", {
            cache: false,
            avisoCargando:"divCargando", 
            metodo: $metodo.POST,            
            parametros: {
                        "UserName":$F("txtUserName"),
                        "Password":$F("txtPassword_1"),
                        "Name":escape(deleteInvalidTags($F("txtRealName"))),
                        "Surname":escape(deleteInvalidTags($F("txtSurname"))),
                        "E-Mail":escape($F("txtEmail")),
                        "ContactRelationship":escape(relationship),
                        "Gender":$F("txtGender"),
                        "BirthDay":$F('Bday'),
                        "BirthMonth":$F('Bmonth'),
                        "BirthYear":$F('Byear'),
                        "City":escape($F("txtCity")),
                        "Address":escape(deleteInvalidTags($F("txtAddress"))),
                        "PostalCode":escape(deleteInvalidTags($F("txtPostalCode"))),
                        "Telephone":escape(deleteInvalidTags($F("txtTelephone"))),
                        "Website":($F("txtWebsite")=="http://www.yourwebsite.com")?"":escape($F("txtWebsite")),
                        "HotelName":escape(deleteInvalidTags($F("txtHotelName"))),
                        "HotelAddress":escape(deleteInvalidTags($F("txtHotelAddress"))),
                        "HotelTelephone":escape(deleteInvalidTags($F("txtHotelTelephone"))),
                        "HotelEmail":escape($F("txtHotelEmail")),
                        "HotelWebsite":($F("txtHotelWebsite")=="http://www.hotelwebsite.com")?"":escape($F("txtHotelWebsite")),
                        "HotelFacilities":escape(deleteInvalidTags($F("txtHotelFacilities"))),
                        "HotelEcoQuantity":ecoQuantity,
                        "HotelRateMin":escape($F("txtHotelRateMin")),
                        "HotelRateMax":escape($F("txtHotelRateMax")),
                        "HotelRateCurrency":escape(currency),
                        "HotelCity":escape($F("txtHotelCity"))},
            onfinish: function(result) {
                switch(result){
                    //Quiere decir que hubo: salida inexperada (estado del validate <> 1, UserName ocupado) o un error
                    //1 - Description (Lo sentimos, su petición no puede ser procesada.)
                    case '0': 
                        //Debería volver a chequear el UserName y E-mail.
                        $('imgSave').disabled = false;
                        $('lblResult').innerHTML = 'We are sorry, your request could not be completed.';                            
                        break;
                
                    //Ok. Obtengo el userName, y con los datos de pantalla envío mail a la persona. 
                    default:
                        sendMailValidation(result);
                        break;
                }   
            }, 
            tipoRespuesta:$tipo.TEXTO});

}

//Envío mail de validación de los datos ingresados
function sendMailValidation(new_hotel_id){   
    $Ajax(basepath + "controllers/AccountHotel/CreateHotelAccount.aspx?method=sendMailValidation", 
        {
            cache: false, 
            avisoCargando:"divCargando",
            metodo: $metodo.POST,            
            parametros: {"hotel_id":new_hotel_id},
            onfinish: function(result) {
                switch(result){
                    //Error
                    case '0':
                        $('lblResult').innerHTML = 'Your request will be processed as soon.';                            
                        break;
                    default:
                        window.location = "CreateHotelAccount_target.aspx";
                        break;
                }  
            }, 
            tipoRespuesta:$tipo.TEXTO});
}


//fechas
var arrMonth = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
var date = new Date();
var anio = date.getFullYear();
var initAnio = 1899;
var dif = anio - initAnio;

function setYearCombo(){
    $('Byear').options[0] = new Option('Year', '00');
    
    for(var un=1; un<=dif; un++)
    {
        $('Byear').options[un] = new Option(initAnio + un, initAnio + un);
    }

}    

function setMonthCombo(){

    $('Bmonth').options[0] = new Option('Month', '00');
    
    for(var un=1; un<=arrMonth.length; un++)
    {
        $('Bmonth').options[un] = new Option(arrMonth[un-1], (un<10?'0'+un:un));
    }
    
}

function setDayCombo(vmonth){   
    //alert(vmonth);
    //limpio el combo
    $('Bday').options.length = 0;
    $('Bday').options[0] = new Option('Day', '00');
    
    if(vmonth == '01' || vmonth == '03' || vmonth == '05' || vmonth == '07' || vmonth == '08' || vmonth == '10' || vmonth == '12')
    {
        for(var un=1; un<=31; un++)
        {
            $('Bday').options[un] = new Option((un<10?'0'+un:un), (un<10?'0'+un:un));
        }
    }
    else if(vmonth == '02')
    {
         for(var un=1; un<=29; un++)
        {
            $('Bday').options[un] = new Option((un<10?'0'+un:un), (un<10?'0'+un:un));
        }
    }
    else if(vmonth > 0)
    {
         for(var un=1; un<=30; un++)
        {
            $('Bday').options[un] = new Option((un<10?'0'+un:un), (un<10?'0'+un:un));
        }
    }
        
}