/* - - - - - - - - - - - - - - - - - - - - - - -
 JavaScript
 Friday, April 22, 2005 12:11:17 PM
 - - - - - - - - - - - - - - - - - - - - - - - */


     /*   VALIDATION  FOR  DESTINATION  FIELD  */

     function Srsubmit()
     {
     var ct=document.Srhform.City.value;
     if (ct == "")
     {
     alert ( "Please   enter  a  value  for   destination ");
     document.Srhform.City.focus();
     }
     else
     {
     document.Srhform.submit();
     }
     }
     /*   POPUP  WINDOW  FOR   PAYMENT  OPTIONS  */
     function  pay_win(opt)
     {

     window.open("../Search/bank_detail.php?opt="+opt, "Bank"+opt,"toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=430, height=270")

     }


     /*    POPUP  WINDOW  FOR  HOTEL PHOTOS    */

     function  photo_win(hid,pid)
     {
     window.open("photo_display.php?ht="+hid+"&pt="+pid, "photo"+hid,"toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=630, height=550")
     }

     /*   POPUP  WINDOW  FOR   HOTEL  DETAILS  */

     function  more_win(hid,chin,chout,person,sroom,droom)
     {
     window.open("search_more.php?ht="+hid+"&ckin="+chin+"&ckout="+chout+"&person="+person+"&sr="+sroom+"&dr="+droom, "","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=no, width=630, height=550")
     }
     /*   POPUP  WINDOW  FOR   ROOM CATEGORY   DETAILS  */

     function  category_win(hid,chin)
     {
      window.open("category_details.php?ht="+hid+"&ckin="+chin, "category","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=630, height=350")
     }
      /*   POPUP  WINDOW  FOR   TERMS  AND  CONDITIONS */

     function  terms_win()
     {
      window.open("http://localhost/public/ajith/terms.html", "terms","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=630, height=350")
     }

     /*   CATEGORY  DETAILS   VALIDATION  */

     function category_validate()
     {
        for(i=0;i<document.frmcat.category.length;i++)
        {
           if (document.frmcat.category[i].checked)
           {
              opener.document.frmbook3.category.value=document.frmcat.category[i].value
              opener.document.getElementById('spTable').rows[4].cells[1].innerHTML="<b>Room Category : </b>";
              opener.document.getElementById('spTable').rows[4].cells[2].innerHTML="<b>"+document.frmcat.category[i].value+"</b>"
              self.window.close();
           }
        }
     }

     /*         CHECKBOX   VALIDATION          */

     function checkPolicy()
     {
        if(document.frmbook3.Policy.checked == true)
        {
            document.frmbook3.B3.style.backgroundColor="#707056";
            document.frmbook3.B3.disabled=false;
        }
        else
        {
           document.frmbook3.B3.style.backgroundColor="#ECE9D8";
           document.frmbook3.B3.disabled=true;
        }
     }

     /*         EMAIL ID   VALIDATION         */

     function echeck(str)
        {
            var at="@";
            var dot=".";
            var lat=str.indexOf(at);
            var lstr=str.length;
            var ldot=str.indexOf(dot);
            if (str.indexOf(at)==-1)
            {
               alert("Invalid E-mail ID");
               return false;
            }

            if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
            {
               alert("Invalid E-mail ID");
               return false;
            }

            if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
            {
                alert("Invalid E-mail ID");
                return false;
            }

             if (str.indexOf(at,(lat+1))!=-1)
             {
                alert("Invalid E-mail ID");
                return false;
             }

             if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
             {
                alert("Invalid E-mail ID");
                return false;
             }

             if (str.indexOf(dot,(lat+2))==-1)
             {
                alert("Invalid E-mail ID");
                return false;
             }

             if (str.indexOf(" ")!=-1)
             {
                alert("Invalid E-mail ID");
                return false;
             }

            return true;
        }


      /*   VALIDATION  FOR  BOOKING  PAGE      */

      function   checkName()
       {

          var  fst_nm=document.frmbook3.Fname.value;
          var  lst_nm=document.frmbook3.Lname.value;
          var  zip=document.frmbook3.Zip.value;
          var  street=document.frmbook3.Street.value;
          var  city=document.frmbook3.City.value;
          var  phone=document.frmbook3.Phone.value;
          var  email=document.frmbook3.Email.value;
          var  ckin=document.frmbook3.Checkin.value;
          var  pers=document.frmbook3.Persons.value;
          var  sgl=document.frmbook3.Srooms.value;
          var  dbl=document.frmbook3.Drooms.value;
          var  prsroom=Number(sgl)+Number(dbl*2);
          // alert ( "pers "+pers+" Room"+prsroom);
          // var  ckout=document.frmbook3.Email.value;
          var  ctry=document.frmbook3.Country.value;
          var  sex=document.frmbook3.Gender.selectedValue;
          var i;
          var cnt=0;

         if( echeck(email)==false )
          {
              //emailID.value="";
              document.frmbook3.Email.focus();
              return false;

          }
          if (pers == "")
          {
           alert(" No  of Persons  Cannot  be  Empty ");
           document.frmbook3.Persons.focus();
           return false;
          }
          if (ckin == "")
          {
           alert(" Checkin  Date   Cannot  be  Empty ");
           document.frmbook3.Checkin.focus();
           return false;
          }
          if (sex == "")
          {
           alert(" Please   specify  your  Gender ");
           document.frmbook3.Gender.focus();
           return false;
          }
          if (ctry == "")
          {
           alert(" Country  field  Cannot  be  Empty ");
           document.frmbook3.Country.focus();
           return false;
          }

          if (fst_nm == "")
          {
           alert(" First  Name  Cannot  be  Empty ");
           document.frmbook3.Fname.focus();
           return false;
          }
          else if (lst_nm == "")
          {
           alert(" Last  Name  Cannot  be  Empty ");
           document.frmbook3.Lname.focus();
           return false;
          }
           else if (street == "")
          {
           alert(" Street  Field  Cannot  be  Empty ");
           document.frmbook3.Street.focus();
           return false;
          }
          else if (city == "")
          {
           alert(" City  Field  Cannot  be  Empty ");
           document.frmbook3.City.focus();
           return false;
          }
          else if (zip == "")
          {
           alert(" Zip  Field  Cannot  be  Empty ");
           document.frmbook3.Zip.focus();
           return false;
          }
          else if (phone == "")
          {
           alert(" Phone  Field  Cannot  be  Empty ");
           document.frmbook3.Phone.focus();
           return false;
          }
          else if ( pers != ""  )
          {
           if(  pers < prsroom )
           {
            alert("Total no. of  Rooms   greater  than  total  no. of  Persons  ... ");
            document.frmbook3.Srooms.focus();
            return false;
           }
           else if( pers > prsroom )
           {
            alert(" Total no. of  Persons   greater  than  total  no. of  Rooms ... ");
            document.frmbook3.Srooms.focus();
            return false;
           }
          }

          /*else if (document.frmbook3.category.value == "")
          {
           alert(" Please  select  a   Room  Category ");
           document.frmbook3.category.focus();
           return false;
          } */
          else if(zip != "")
          {
           if( zip.length < 5)
           {
                 alert(" Invalid  Zip Code ");
                 document.frmbook3.Zip.focus();
                return false;
           }

            for(i=0; i < zip.length; i++)
            {
              var  no=zip.chatAt(i);
              if (((no < "0") || (no > "9")))
              { alert(" Zip  Field  Cannot contain  characters ");
                document.frmbook3.Zip.focus();
                return false;
              }
            }

          }
          else if(phone != "")
          {
          if( phone.length < 5)
           {
                 alert(" Invalid  Phone Number ");
                 document.frmbook3.Phone.focus();
                 return false;
           }
            for(i=0; i < phone.length; i++)
            {
              var no1=phone.chatAt(i);
              if(((no1 < "0")  || (no1 > "9")))
              { alert(" Phone  Field  Cannot contain  characters ");
                document.frmbook3.Phone.focus();
                return false;
              }
            }

          }
          return true;

        }

     /*         IMAGE   RESIZING

     function im_rsz(im)
     {
       if (document.images[].im.height <= 250 && document.images[].im.width <= 250)
       {

       }

     }  */


        /***********************************SUNITA**************************************/

        //Index page
        function submitIndex()
        {
          if(document.frmIndex.txtUserName.value=="")
          {
              alert("Please enter your user name");
              return false;
          }
          var emailID=document.frmIndex.txtUserName;
          if (echeck(emailID.value)==false)
          {
              emailID.value="";
              emailID.focus();
              return false;
          }
          if(document.frmIndex.txtPassword.value=="")
          {
              alert("Please enter the password");
              return false;
          }
          document.frmIndex.submit();
        }

        function Formsubmit()
        {
            if(document.frmIndex.txtUserName.value=="")
            {
                alert("Please enter your user name");
                return false;
            }
            var emailID=document.frmIndex.txtUserName;
            if (echeck(emailID.value)==false)
            {
                emailID.value="";
                emailID.focus();
                return false;
            }
            if(document.frmIndex.txtPassword.value=="")
            {
                alert("Please enter the password");
                return false;
            }
            document.frmIndex.submit();
        }

        /***********************PHONE NUMBER VALIDATION************************/

        // Declaring required variables
        var digits = "0123456789";
        // non-digit characters which are allowed in phone numbers
        var phoneNumberDelimiters = "()- ";
        // characters which are allowed in international phone numbers
        // (a leading + is OK)
        var validWorldPhoneChars = phoneNumberDelimiters + "+";
        // Minimum no of digits in an international phone no.
        var minDigitsInIPhoneNumber = 5;

        function isInteger(s)
        {   var i;
            for (i = 0; i < s.length; i++)
            {
                // Check that current character is number.
                var c = s.charAt(i);
                if (((c < "0") || (c > "9"))) return false;
            }
            // All characters are numbers.
            return true;
        }

        function stripCharsInBag(s, bag)
        {   var i;
            var returnString = "";
            // Search through string's characters one by one.
            // If character is not in bag, append to returnString.
            for (i = 0; i < s.length; i++)
            {
                // Check that current character isnt whitespace.
                var c = s.charAt(i);
                if (bag.indexOf(c) == -1) returnString += c;
            }
            return returnString;
        }

        function checkInternationalPhone(strPhone){
        s=stripCharsInBag(strPhone,validWorldPhoneChars);
        return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
        }

        /***********************PHONE NUMBER VALIDATION************************/

        function submitForm1()
    {
        if(document.frmHotelEdit1.hotel_name.value=="")
        {
            alert("Please enter hotel name");
            return false;
        }
        if(document.frmHotelEdit1.hotel_tel.value=="")
        {
            alert("Please enter hotel telephone");
            return false;
        }

        var Phone=document.frmHotelEdit1.hotel_tel;
        if (checkInternationalPhone(Phone.value)==false)
        {
            alert("Please Enter a Valid Hotel Phone Number");
            Phone.value="";
            Phone.focus();
            return false;
        }

        var Fax=document.frmHotelEdit1.hotel_fax;
        if (Fax.value!="")
        {
            if (checkInternationalPhone(Fax.value)==false)
            {
                alert("Please Enter a Valid Hotel Fax Number");
                Fax.value="";
                Fax.focus();
                return false;
            }
        }

        if(document.frmHotelEdit1.hotel_email.value=="")
        {
            alert("Please enter hotel email");
            document.frmHotelEdit1.hotel_email.focus();
            return false;
        }

        var emailID=document.frmHotelEdit1.hotel_email;
        if (echeck(emailID.value)==false)
        {
            emailID.value="";
            emailID.focus();
            return false;
        }

        var chk;
        chk=false;
        for (i=0; i<document.frmHotelEdit1.elements.length; i++)
        {
            if(document.frmHotelEdit1.elements[i].name=="promoters[]")
            {
                if(document.frmHotelEdit1.elements[i].checked == true)
                {
                    chk=true;
                }
            }
        }
        if (chk==false)
        {
            alert("Please select promoter");
            return false;
        }

        if(document.frmHotelEdit1.contact_name.value=="")
        {
            alert("Please enter contact name");
            document.frmHotelEdit1.contact_name.focus();
            return false;
        }
        if(document.frmHotelEdit1.contact_email.value=="")
        {
            alert("Please enter contact email");
            document.frmHotelEdit1.contact_email.focus();
            return false;
        }

        var emailID1=document.frmHotelEdit1.contact_email;
        if (echeck(emailID1.value)==false)
        {
            emailID1.value="";
            emailID1.focus();
            return false;
        }

        if(document.frmHotelEdit1.contact_tel.value=="")
        {
            alert("Please enter contact telephone");
            document.frmHotelEdit1.contact_tel.focus();
            return false;
        }

        var Phone1=document.frmHotelEdit1.contact_tel;
        if (checkInternationalPhone(Phone1.value)==false)
        {
            alert("Please Enter a Valid Contact Phone Number");
            Phone1.value="";
            Phone1.focus();
            return false;
        }

        var Fax1=document.frmHotelEdit1.contact_fax;
        if (Fax1.value!="")
        {
            if (checkInternationalPhone(Fax1.value)==false)
            {
                alert("Please Enter a Valid Contact Fax Number");
                Fax1.value="";
                Fax1.focus();
                return false;
            }
        }
        document.frmHotelEdit1.submit();
        return false;
    }

    function submitLoginForm()
    {
        if(document.frmLogin.txtUserName.value=="")
        {
            alert("Please enter your Email");
            return false;
        }
        var emailID=document.frmLogin.txtUserName;
        if (echeck(emailID.value)==false)
        {
            emailID.value="";
            emailID.focus();
            return false;
        }
        if(document.frmLogin.txtPassword.value=="")
        {
            alert("Please enter the password");
            return false;
        }
        document.frmLogin.submit();
        return false;
    }

    function pay()
        {
            var chk;
            chk=false;
            for (i=0; i<document.frmbook4.elements.length; i++)
            {
                if(document.frmbook4.elements[i].name=="payoption")
                {
                    if(document.frmbook4.elements[i].checked == true)
                    {
                        chk=true;
                    }
                }
            }
            if (chk==false)
            {
               alert("Please select a payment option");
               return false;
            }
            if (chk==true)
            {
               document.frmbook4.submit();
            }
        }


/***********************************SUNITA*************************************/


