﻿// JScript File

function IsValidEmail(input){
      var mail=document.getElementById(input);
       var reg=new RegExp(/([a-zA-Z0-9_\-])+(\.([a-zA-Z0-9_\-])+)*@((\[(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5]))\]))|((([a-zA-Z0-9])+(([\-])+([a-zA-Z0-9])+)*\.)+([a-zA-Z])+(([\-])+([a-zA-Z0-9])+)*))/);
       if (reg.test(mail.value) == false) 
       {
          return false;
       }
       return true;
}

function IsEmail(){  
       if (!IsValidEmail(txtSubscriber)) 
       {
          ShowMessage("Please input a valid e-mail address");              
          return false;
       }
       return true;
}

function IsGoodInput(input){  
       var mail=document.getElementById(input);
       var reg=new RegExp(/<[a-zA-Z]+>/);
                 
       if (reg.test(mail.value) == false) 
       {
          return false;
       }
       return true;
}

function IsGoodName(input){  
       var mail=document.getElementById(input);
       var reg=new RegExp(/^([a-zA-Z ])+$/); 
       if (reg.test(mail.value) == true) 
       {
          return true;
       }
       return false;
}

function ValidateContact(){
        var mes = ''; 
        var tbName1=document.getElementById(tbName);
        if (tbName1.value=='') mes='fill the name, ';
        else if (!IsGoodName(tbName)) mes='fill a valid name, ';
        
        
        var tbEmail1=document.getElementById(tbEmail);
        if (tbEmail1.value=='') 
        {
            mes+='fill the e-mail, ';
        }
        else
        {
            if (!IsValidEmail(tbEmail)) 
            {
                mes+='fill a valid e-mail, ';
            }
        }
        
        var tbCountry1=document.getElementById(tbCountry);
        if (tbCountry1.value=='') mes+='fill the country, ';
        else if (IsGoodInput(tbCountry)) mes+='fill a valid country, ';        
             
        var tbComments1=document.getElementById(tbComments);
        if (tbComments1.value=='') mes+='fill the comments, ';
        else if (IsGoodInput(tbComments)) mes+='fill a valid comments, ';   
        
        if (mes!='') 
        {
            mes ='Please '+mes.substring(0,mes.length-2);
            ShowMessage(mes,'','Warning');
            return false;
        }
        else 
        { 
            return true;
        }         
}

function ValidateDetails(isUserLogged){
        var txtMemEmail1 = document.getElementById(txtMemEmail);
        var txtEmail1 = document.getElementById(txtUserEmail);
        var txtName1 = document.getElementById(txtUserName);
        var mes = ''; 
        var tbName1=document.getElementById(tbName);
        if (tbName1.value=='') mes='fill the name, ';
        else if (!IsGoodName(tbName)) mes='fill a valid name, ';        
        
        var tbEmail1=document.getElementById(tbEmail);
        if (tbEmail1.value==''){
            mes+='fill the e-mail, ';
        }
        else{
            if (!IsValidEmail(tbEmail)){
                mes+='fill a valid e-mail, ';
            }
        }        
        var tbAddress1=document.getElementById(tbAddress);
        if(tbAddress1.value != '')
            if (IsGoodInput(tbAddress)) 
                mes+='fill a valid address, ';
       
        var tbPost1=document.getElementById(tbPost);
        if (tbPost1.value!='') 
            if (IsGoodInput(tbPost)) mes+='fill a valid zip/post code, ';
        
        var ddlCountries1=document.getElementById(ddlCountries);
        if (ddlCountries1.selectedIndex==0) mes+='select the country, ';
         
        var tbTelephone1=document.getElementById(tbTelephone);
        if (tbTelephone1.value != '')
            if (IsGoodInput(tbTelephone)) mes+='fill a valid phone number, ';
        
        if (IsGoodInput(tbRemarks)) mes+='fill a valid remark, ';
        if (mes!=''){
            mes ='Please '+mes.substring(0,mes.length-2);
            ShowMessage(mes,'','Warning');
        }
        else {
            var cbAgree1=document.getElementById(cbAgree);
            if (!cbAgree1.checked){
                var mes2 ='You must be agree with the booking conditions and general terms in order to complete the reservation';
                ShowMessage(mes2,'','Warning');
            }else {    
                if(!isUserLogged){         
                    var divUser = document.getElementById('divUserData');
                    divUser.style.display = 'block';
                    x2ws(document.getElementById('divBookingComplete'));  
                    w2cs22(document.getElementById('divBookingCompleteContent'));
                    txtMemEmail1.value = tbEmail1.value;
                    txtEmail1.value = tbEmail1.value;
                    txtName1.value  = tbName1.value;
                    //txtCountry1.value = ddlCountries1.options[ddlCountries1.selectedIndex].text;
                 }
             }  
        }      
    if(isUserLogged)
        return true;
    else    
        return false;       
}


