/**************************************************************************************************************/
// Create xmlhttp object based on browsertype
function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
	  xmlhttp.overrideMimeType("text/xml"); 
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}
/**************************************************************************************************************/
// Define global variables to be used throughout
var tableBusy = false;
var tableHttp = getHTTPObject();

var tableBusy2 = false;
var tableHttp2 = getHTTPObject();

var step1Over = false;
var row = "";

/**************************************************************************************************************/
function strim(s)
		{
			return s.replace(/\s+/g, '');
		}

var dtCh= "/";
var minYear=1901;
var maxYear=2100;

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++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
    // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
    for (var i = 1; i <= n; i++) {
        this[i] = 31
        if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
        if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
    var daysInMonth = DaysArray(12)
    var pos1=dtStr.indexOf(dtCh)
    var pos2=dtStr.indexOf(dtCh,pos1+1)
    var strMonth=dtStr.substring(0,pos1)
    var strDay=dtStr.substring(pos1+1,pos2)
    var strYear=dtStr.substring(pos2+1)
    strYr=strYear
//    if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
//    if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
    for (var i = 1; i <= 3; i++) {
        if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
    }
    month=strMonth;
    day=strDay;
    year=parseInt(strYr)
    if (pos1==-1 || pos2==-1){
        alert("The date format should be : mm/dd/yyyy")
        return false;
    }

    if (strMonth.length<2 || month<1 || month>12){
        alert("Please enter a valid month i.e. 01/01/1980")
        return false;
    }
    if (strDay.length<2 || day<1 || day>31 || ((month==2 || month=='02') && day>daysInFebruary(year)) || day > daysInMonth[month]){
        alert("Please enter a valid day i.e. 01/01/1980")
        return false;
    }
    if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
        alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
        return false;
    }
    if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
        alert("Please enter a valid date")
        return false;
    }
    return true;

}
        
function validateform()
{
    var group = document.frmReservation.GroupName.value;
    var name =  document.frmReservation.Name.value;
    var add  = document.frmReservation.Address.value;
    var city  = document.frmReservation.City.value;
    var state  = document.frmReservation.State.value;
    var zip  = document.frmReservation.Zip.value;
    var country  = document.frmReservation.Country.value;
    var phone  = document.frmReservation.Phone.value;
    var email  = document.frmReservation.Email.value;
    
    
/*   if(strim(document.frmReservation.GroupName.value) == "")
   {
      alert("Please enter the Group Name");
      document.frmReservation.GroupName.focus();
      return;
   }
   */
   if(strim(document.frmReservation.Name.value) == "")
   {
      alert("Please enter Your Name");
      document.frmReservation.Name.focus();
      return;
   }
   if(strim(document.frmReservation.Address.value) == "")
   {
      alert("Please enter Your Address");
      document.frmReservation.Address.focus();
      return;
   }
   if(strim(document.frmReservation.City.value) == "")
   {
      alert("Please enter the City");
      document.frmReservation.City.focus();
      return;
   }
   
   if(strim(document.frmReservation.Zip.value) == "")
   {
      alert("Please enter the Zip Code");
      document.frmReservation.Zip.focus();
      return;
   }
   
   if(strim(document.frmReservation.Phone.value) == "")
   {
      alert("Please enter Your Phone Number");
      document.frmReservation.Phone.focus();
      return;
   }
   
   if(strim(document.frmReservation.Email.value) == "")
   {
      alert("Please enter Your Email Address");
      document.frmReservation.Email.focus();
      return;
   }
   else
   {
       var email=document.frmReservation.Email.value;
       var x="/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/";
        
       if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)))
       {
            alert("Invalid E-mail");
            document.frmReservation.Email.focus();
            document.frmReservation.Email.select();
            return;
       }
   }
   if(document.frmReservation.srcmode.value=='newlogin')
   {
       if(strim(document.frmReservation.Password.value) == "")
       {
          alert("Please enter Your Password");
          document.frmReservation.Password.focus();
          return;
       }
       if(strim(document.frmReservation.Password.value) != strim(document.frmReservation.Confirm_Password.value))
       {
          alert("Password and confirm password should be same");
          document.frmReservation.Confirm_Password.focus();
          return;
       }
   }
    
   //hdd = document.getElementById('hdndates').value;
   
   var group = document.frmReservation.GroupName.value;
   
   var name =  document.frmReservation.Name.value;
   var add  = document.frmReservation.Address.value;
   var city  = document.frmReservation.City.value;
   var state  = document.frmReservation.State.value;
   var zip  = document.frmReservation.Zip.value;
   var country  = document.frmReservation.Country.value;
   var phone  = document.frmReservation.Phone.value;
   var email  = document.frmReservation.Email.value;
   var password  = document.frmReservation.Password.value;
   var params = "group="+group+"&name="+name+"&address="+add+"&city="+city+"&state="+state+"&zip="+zip+"&country="+country+"&phone="+phone+"&email="+email+"&password="+password;
   //+"&hdndates="+hdd
    
   hdp = document.getElementById('hdnpeople').value;
   onameObj = document.frmReservation.elements["OutfittingName[]"];
   ageObj = document.frmReservation.elements["OutfittingAge[]"];
   feetObj = document.frmReservation.elements["Feet[]"];
   inchObj = document.frmReservation.elements["Inch[]"];
   weightObj = document.frmReservation.elements["Weight[]"];
   bootObj = document.frmReservation.elements["Boots[]"];
   sizeObj = document.frmReservation.elements["Size[]"];
   unitObj = document.frmReservation.elements["Unit[]"];
   packageObj = document.frmReservation.elements["Package[]"];
   stypeObj = document.frmReservation.elements["SkierType[]"];
   plengthObj = document.frmReservation.elements["PreferredLength[]"];

   
   
   var oname;
   var age;
   var feet;
   var inch;
   var weight;
   var boot;
   var size;
   var unit;
   var package;
   var stype;
   var plengh;
   for(i=0;i<hdp;i++)
   {
       if(i==0)
       {
           oname=onameObj[i].value;
           age = ageObj[i].value;
           feet=feetObj[i].value;
           inch = inchObj[i].value;
           weight=weightObj[i].value;
           if(bootObj[i].checked == true)
              bootvalue = 1;
           else
              bootvalue = 0;
           boot = bootvalue;   
           size=sizeObj[i].value;
           unit = unitObj[i].value;
           package=packageObj[i].value;
           stype = stypeObj[i].value;
           plength = plengthObj[i].value;
           
/*         if(oname=="")
           {
               alert("Please enter the outfitting name");
               document.getElementById('oname1').focus();
               return;
           }*/
           
           if(age=="")
           {
               alert("Please enter the outfitting age");
               document.getElementById('age1').focus();
               return;
           }
           if(age!="")
           {
               var dt=age;
               if (isDate(age)==false)
               {
                    ageObj[i].focus();
                    return;
               }
           }
          /* 
           if(feet=="")
           {
               alert("Please enter the height");
               document.getElementById('feet1').focus();
               return;
           }
           
           if(inch=="")
           {
               alert("Please enter the height");
               document.getElementById('inch1').focus();
               return;
           }
           
           if(weight=="")
           {
               alert("Please enter the weight");
               document.getElementById('weight1').focus();
               return;
           }
           
           if(size=="")
           {
               alert("Please enter the size");
               document.getElementById('size1').focus();
               return;
           }
           
           if(plength=="")
           {
               alert("Please enter the preferred length");
               document.getElementById('plength1').focus();
               return;
           }*/
       }
       else
       {
           var valAge = ageObj[i].value;
           if(valAge=="")
           {
               alert("Please enter the outfitting age");
               ageObj[i].focus();
               return;
           }
           if(valAge!="")
           {
               var dt=valAge;
               if (isDate(valAge)==false)
               {
                    ageObj[i].focus();
                    return;
               }
           }
           oname=oname + "*^" + onameObj[i].value;
           age=age + "*^" + ageObj[i].value;
           feet=feet + "*^" + feetObj[i].value;
           inch=inch + "*^" + inchObj[i].value;
           weight=weight + "*^" + weightObj[i].value;
           if(bootObj[i].checked == true)
              bootvalue = 1;
           else
              bootvalue = 0;
           boot=boot + "*^" + bootvalue;
           size=size + "*^" + sizeObj[i].value;
           unit=unit + "*^" + unitObj[i].value;
           package=package + "*^" + packageObj[i].value;
           stype=stype + "*^" + stypeObj[i].value;
           plength=plength + "*^" + plengthObj[i].value;
       }
   }
   params = params + "&outfitName="+oname+"&outfitAge="+age+"&outfitFeet="+feet+"&outfitInch="+inch+"&outfitWeight="+weight+"&outfitBoot="+boot+"&outfitSize="+size+"&outfitUnit="+unit+"&outfitPackage="+package+"&outfitStype="+stype+"&outfitPlength="+plength+"&mode=save";
   
   var pickup_date;
   var ski_date;
   var dropoff_date;
   var err = "";
   
/*   for(p=1;p<=hdp;p++)
   {
       divhdn = 'hdndates_' + p;
       hdd = document.getElementById(divhdn).value;
       for(i=1;i<=hdd;i++)
       {
            pickup_date = 'pickup_date' + p + '_' + i;
            pickup_time = 'pickup_time' + p + '_' + i;
            ski_date = 'ski_date' + p + '_' + i;
            dropoff_date = 'dropoff_date' + p + '_' + i;
            dropoff_time = 'ski_time' + p + '_' + i;
            rental_days = 'totalRentalDays' + p + '_' + i;
            
            switch(i)
            {
                case 1:
                    n = 'first';
                    break;
                case 2:
                    n= 'second';
                    break;
                case 3:
                    n= 'third';
                    break;
                case 4:
                    n='fourth';
                    break;
                case 5:
                    n='fifth';
                    break;
            }
            
            if(document.getElementById(pickup_date).value=="")
            {
                err = "Please select the "+n+ " pickup date for person " + p + "\n";
                alert(err);
                document.getElementById(pickup_date).focus();
                return;
            }
            
            if(document.getElementById(pickup_time).value=="")
            {
                err = "Please select the "+n+ " pickup time for person " + p + "\n";
                alert(err);
                document.getElementById(pickup_time).focus();
                return;
            }
            
            if(strim(document.getElementById(ski_date).value)=="")
            {
                err = "Please select the "+n+ " ski date for person " + p + "\n";
                alert(err);
                document.getElementById(ski_date).focus();
                return;
            }
            if(strim(document.getElementById(dropoff_date).value)=="")
            {
                err = "Please select the "+n+ " dropoff date for person " + p + "\n";
                alert(err);
                document.getElementById(dropoff_date).focus();
                return;
            }
            
            if(strim(document.getElementById(dropoff_time).value)=="")
            {
                err = "Please select the "+n+ " dropoff time for person " + p + "\n";
                alert(err);
                document.getElementById(dropoff_time).focus();
                return;
            }
            
            if(strim(document.getElementById(rental_days).value)=="")
            {
                err = "Please enter the value for "+n+ " Total Rental days for person " + p + "\n";
                alert(err);
                document.frmReservation.totalRentalDays1.focus();
                return;
            }
       }
   }    
   */
   
   for(p=1;p<=hdp;p++)
   {
       divhdn = 'hdndates_' + p;
       hdd = document.getElementById(divhdn).value;
       for(i=1;i<=hdd;i++)
       {
            pickup_date = 'pickup_date' + p + '_' + i;
            ski_date = 'ski_date' + p + '_' + i;
            dropoff_date = 'dropoff_date' + p + '_' + i;
            totrentdays = 'totalRentalDays' + p + '_' + i;
            pickup_time = 'pickup_time' + p + '_' + i;
            ski_time = 'ski_time' + p + '_' + i;
            
            
            pd_val = document.getElementById(pickup_date).value;
            skd_val = document.getElementById(ski_date).value;
            drp_val = document.getElementById(dropoff_date).value;
            rentdays_val = document.getElementById(totrentdays).value;
            ptime_val = document.getElementById(pickup_time).value;
            stime_val = document.getElementById(ski_time).value;
            params = params + "&"+pickup_date+"="+pd_val+"&"+ski_date+"="+skd_val+"&"+dropoff_date+"="+drp_val+"&"+totrentdays+"="+rentdays_val+"&"+pickup_time+"="+ptime_val+"&"+ski_time+"="+stime_val+"&"+divhdn+"="+hdd;
       }
   }
   if (!tableBusy)
   {
       var url = "process.php?randoms="+Math.random();
        tableHttp.open("post", url, true);
        tableHttp.onreadystatechange = SaveChanges;
        tableHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        tableHttp.setRequestHeader("Content-length", params.length);
        tableHttp.setRequestHeader("Connection", "close");
        tableBusy = true;
        tableHttp.send(params);
   }
}

function SaveChanges()
{
    if (tableHttp.readyState == 4)
    {
        try
        {
            var output = tableHttp.responseText;
            tableBusy = false;
            calculateSummary();
        }
        catch(e)
        {
            alert("Error: " + e) ;
        }
    }
}

function calculateSummary()
{
    var params = "mode=summary";
    if (!tableBusy)
    {
        var url = "process.php?randoms="+Math.random();
        tableHttp.open("POST", url, true);
        tableHttp.onreadystatechange = GetSummary;
        tableHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        tableHttp.setRequestHeader("Content-length", params.length);
        tableHttp.setRequestHeader("Connection", "close");
        tableBusy = true;
        tableHttp.send(params);
    }
}

function GetSummary()
{
    if (tableHttp.readyState == 4)
    {
        try
        {
            var output = tableHttp.responseText;
            tableBusy = false;
            document.getElementById('idsummary').innerHTML = output;
            calculateCart();
        }
        catch(e)
        {
            alert("Error: " + e) ;
        }
    }
}

function calculateCart()
{
    var email = document.frmReservation.Email.value;
    var params = "mode=cart&email="+email;
    if (!tableBusy2)
    {
        var url = "process.php?randoms="+Math.random();
        tableHttp2.open("POST", url, true);
        tableHttp2.onreadystatechange = GetCart;
        tableHttp2.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        tableHttp2.setRequestHeader("Content-length", params.length);
        tableHttp2.setRequestHeader("Connection", "close");
        tableBusy2 = true;
        tableHttp2.send(params);
    }
}

function GetCart()
{
    if (tableHttp2.readyState == 4)
    {
        try
        {
            var output = tableHttp2.responseText;
            tableBusy2 = false;
            document.getElementById('idcart').innerHTML = output;
        }
        catch(e)
        {
            alert("Error: " + e) ;
        }
    }
}

function copyrentinfo()
{
    if(document.frmReservation.chk_bill.checked == true)
    {
        document.frmReservation.BillAddress.value = document.frmReservation.Address.value;
        document.frmReservation.BillCity.value = document.frmReservation.City.value;
        document.frmReservation.BillState.value = document.frmReservation.State.value;
        document.frmReservation.BillZip.value = document.frmReservation.Zip.value;
        document.frmReservation.BillCountry.value = document.frmReservation.Country.value;
    }
    else
    {
        document.frmReservation.BillAddress.value = "";
        document.frmReservation.BillCity.value = "";
        document.frmReservation.BillState.value = "CO";
        document.frmReservation.BillZip.value = "";
        document.frmReservation.BillCountry.value = "US";
    }
}

function validateCCInfo()
{
   validateform();
    /*if(strim(document.frmReservation.GroupName.value) == "")
   {
      alert("Please enter the Group Name");
      document.frmReservation.GroupName.focus();
      return;
   }*/
   if(strim(document.frmReservation.Name.value) == "")
   {
      alert("Please enter Your Name");
      document.frmReservation.Name.focus();
      return;
   }
   if(strim(document.frmReservation.Address.value) == "")
   {
      alert("Please enter Your Address");
      document.frmReservation.Address.focus();
      return;
   }
   if(strim(document.frmReservation.City.value) == "")
   {
      alert("Please enter the City");
      document.frmReservation.City.focus();
      return;
   }
   
   if(strim(document.frmReservation.Zip.value) == "")
   {
      alert("Please enter the Zip Code");
      document.frmReservation.Zip.focus();
      return;
   }
   
   if(strim(document.frmReservation.Phone.value) == "")
   {
      alert("Please enter Your Phone Number");
      document.frmReservation.Phone.focus();
      return;
   }
   
   if(strim(document.frmReservation.Email.value) == "")
   {
      alert("Please enter Your Email Address");
      document.frmReservation.Email.focus();
      return;
   }
   else
   {
       var email=document.frmReservation.Email.value;
       var x="/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/";
        
       if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)))
       {
            alert("Invalid E-mail");
            document.frmReservation.Email.focus();
            document.frmReservation.Email.select();
            return;
       }
   }
   
   if(document.frmReservation.srcmode.value=='newlogin')
   {
       if(strim(document.frmReservation.Password.value) == "")
       {
          alert("Please enter Your Password");
          document.frmReservation.Password.focus();
          return;
       }
       if(strim(document.frmReservation.Password.value) != strim(document.frmReservation.Confirm_Password.value))
       {
          alert("Password and confirm password should be same");
          document.frmReservation.Confirm_Password.focus();
          return;
       }
   }
   /*
   if (document.frmReservation.BillAddress.value == "")
    {
        alert("Please Enter Your Billing Address.");
        document.frmReservation.BillAddress.focus();
        return;
    }
    
    if (document.frmReservation.BillCity.value == "")
    {
        alert("Please Enter Your Billing City.");
        document.frmReservation.BillCity.focus();
        return;
    }
    
    if (document.frmReservation.BillState.value == "")
    {
        alert("Please Enter Your Billing State.");
        document.frmReservation.BillState.focus();
        return;
    }
    
    if (document.frmReservation.BillZip.value == "")
    {
        alert("Please Enter Your Billing Zip Code.");
        document.frmReservation.BillZip.focus();
        return;
    }
    
    if (document.frmReservation.BillCountry.value == "")
    {
        alert("Please Enter Your Billing Country.");
        document.frmReservation.BillCountry.focus();
        return;
    }
    
    if (document.frmReservation.Name_On_Card.value == "")
    {
        alert("Please Enter Your Name On Card.");
        document.frmReservation.Name_On_Card.focus();
        return;
    }
    
    if (document.frmReservation.Credit_Card_Type.value == "")
    {
        alert("Please Select the Credit Card Type.");
        document.frmReservation.Credit_Card_Type.focus();
        return;
    } 
    
    if (document.frmReservation.CustBillCCNum.value == "" || isNaN(document.frmReservation.CustBillCCNum.value))
    {
        alert("Please Enter Your Numeric Credit Card Number.");
        document.frmReservation.CustBillCCNum.value = '';
        document.frmReservation.CustBillCCNum.focus();
        return;
    }

    if (document.frmReservation.CustBillCCExpiresMonth.selectedIndex == 0)
    {
        alert("Please Select Expiration Month");
        document.frmReservation.CustBillCCExpiresMonth.focus();
        return;
    }

    if (document.frmReservation.CustBillCCExpiresYear.selectedIndex == 0)
    {
        alert("Please Select Expiration Year");
        document.frmReservation.CustBillCCExpiresYear.focus();
        return;
    }

    if (document.frmReservation.Card_Code.value == "" || isNaN(document.frmReservation.Card_Code.value))
    {
        alert("Please Enter Numeric CVV2 Code Located On Back Of Card.");
        document.frmReservation.Card_Code.value = "";
        document.frmReservation.Card_Code.focus();
        return;
    }
    */
    document.frmReservation.submit();
}


function cvv2_help()
{
    var newurl = "secure/cvv2_help.html";
    apopup = window.open(newurl,'note','toolbar=no,location=no,directories=no,status=no,scrollbars=No,menubar=no,hscroll=No,resizable=No,copyhistory=no,height=400,width=500,left=50,top=50');
}

function manageDates(mod,i)
    {
        var divpeople = 'hdndates_'+i;
        id = document.getElementById(divpeople).value;
        if(mod==0)
        {
            if(id > 1)
            {
                id = Number(id) - 1;
                divid = 'divdates' + i + "_" + id;
                document.getElementById(divpeople).value = id;
                for(x=1;x<=5;x++)
                {
                    divid = 'divdates' + i + '_'+ x;
                    document.getElementById(divid).style.display = 'none';
                }
                for(x=1;x<=id;x++)
                {
                    divid = 'divdates' + i + '_'+ x;
                    document.getElementById(divid).style.display = 'inline';
                }
                //document.getElementById(divid).style.display = 'none';
            }
        }
        else
        {
            if(id < 5 )
            {
                id = Number(id) + 1;
                divid = 'divdates' + i + "_" + id;
                document.getElementById(divpeople).value = id;
                
                for(x=1;x<=5;x++)
                {
                    divid = 'divdates' + i + '_'+ x;
                    document.getElementById(divid).style.display = 'none';
                }
                for(x=1;x<=id;x++)
                {
                    divid = 'divdates' + i + '_'+ x;
                    document.getElementById(divid).style.display = 'inline';
                }
                //document.getElementById(divid).style.display = 'inline';
            }
        }
    }
    
    function managePeople(mod)
    {
        id = document.getElementById('hdnpeople').value;
        if(mod==0)
        {
            if(id > 1)
            {
                id = Number(id) - 1;
                divid = 'divpeople' + id;
                document.getElementById('hdnpeople').value = id;
                for(x=1;x<=10;x++)
                {
                    divid = 'divpeople' + x;
                    document.getElementById(divid).style.display = 'none';
                    if(x==(id+1))
                    {
                        for(y=1;y<=5;y++)
                        {
                             divid = 'divdates' + x + '_'+y;
                             if(y>1)
                                 document.getElementById(divid).style.display = 'none';
                        }
                        divid = 'hdndates_' + x;
                        document.getElementById(divid).value = 1;
                    }
                }
                for(x=1;x<=id;x++)
                {
                    divid = 'divpeople' + x;
                    document.getElementById(divid).style.display = 'inline';
                }
                //document.getElementById(divid).style.display = 'none';
            }
        }
        else
        {
            if(id < 10 )
            {
                id = Number(id) + 1;
                divid = 'divpeople' + id;
                document.getElementById('hdnpeople').value = id;
                for(x=1;x<=10;x++)
                {
                    divid = 'divpeople' + x;
                    document.getElementById(divid).style.display = 'none';
                }
                for(x=1;x<=id;x++)
                {
                    divid = 'divpeople' + x;
                    document.getElementById(divid).style.display = 'inline';
                }
                divid = 'hdndates_1';
                firstval = document.getElementById(divid).value;
                divid = 'hdndates_'+ id;
                document.getElementById(divid).value=firstval;
                for(y=1;y<=5;y++)
                {
                     divid = 'divdates' + id + '_'+y;
                     document.getElementById(divid).style.display = 'none';
                }
                for(y=1;y<=firstval;y++)
                {
                     divid = 'divdates' + id + '_'+y;
                     first_pdate = 'pickup_date1' + '_' + y;
                     first_sdate = 'ski_date1' + '_' + y;
                     first_ddate = 'dropoff_date1' + '_' + y;
                     first_ptime = 'pickup_time1' + '_' + y;
                     first_stime = 'ski_time1' + '_' + y;
                     first_day = 'totalRentalDays1' + '_' + y;
                     pdate = 'pickup_date' + id + '_' + y;
                     sdate = 'ski_date' + id + '_' + y;
                     ddate = 'dropoff_date' + id + '_' + y;
                     ptime = 'pickup_time' + id + '_' + y;
                     stime = 'ski_time' + id + '_' + y;
                     sday = 'totalRentalDays' + id + '_' + y;
                     
                     document.getElementById(pdate).value = document.getElementById(first_pdate).value;
                     document.getElementById(sdate).value = document.getElementById(first_sdate).value;
                     document.getElementById(ddate).value = document.getElementById(first_ddate).value;
                     document.getElementById(ptime).value = document.getElementById(first_ptime).value;
                     document.getElementById(stime).value = document.getElementById(first_stime).value;
                     document.getElementById(sday).value = document.getElementById(first_day).value;
                     document.getElementById(divid).style.display = 'inline';
                     
                }
                //document.getElementById(divid).style.display = 'inline';
            }
        }
    }
    
    function fnPopUpCalendar(field)
    {
        fieldname = 'frmReservation.'+field;
        show_calendar(fieldname);
    }
    
    function calculatDays(p, d, s, r)
    {
        if(document.getElementById(p).value=="")
        {
            alert("Please select the pickup date");
            document.getElementById(p).focus();
            document.getElementById(s).value="";
            return;
        }
        if(document.getElementById(d).value=="")
        {
            alert("Please select the dropoff date");
            document.getElementById(d).focus();
            return;
        }
        
        value1 = document.getElementById(p).value;
        value2 = document.getElementById(d).value;;

        month1 = value1.substring (0, value1.indexOf ("/"));
        day1 = value1.substring (value1.indexOf ("/")+1, value1.lastIndexOf ("/"));
        year1 = value1.substring (value1.lastIndexOf ("/")+1, value1.length);

        month2 = value2.substring (0, value2.indexOf ("/"));
        day2 = value2.substring (value2.indexOf ("/")+1, value2.lastIndexOf ("/"));
        year2 = value2.substring (value2.lastIndexOf ("/")+1, value2.length); 

        date1 = year1+"/"+month1+"/"+day1;
        date2 = year2+"/"+month2+"/"+day2;

        if(date2 < date1)
        {
            alert("Dropoff date should be greater than pickup date");
            document.getElementById(d).value="";
            document.getElementById(s).value="";
            return;
        }
        firstDate = Date.parse(date1)
        secondDate= Date.parse(date2)
        
        msPerDay = 24 * 60 * 60 * 1000
        dbd = Math.round((secondDate.valueOf()-firstDate.valueOf())/ msPerDay) + 1;
        
        document.getElementById(r).value = dbd;
    }
    
    function updateDays(p)
    {
        for(i=1;i<=5;i++)
        {
            //pickup_date = 'pickup_date'+i;
            pickup_date = 'ski_date' + p + '_' + i;
            dropoff_date = 'dropoff_date' + p + '_' + i;
            ski_time = 'ski_time' + p + '_'+i;
            rentaldays = 'totalRentalDays' + p + '_' + i;
            divdates = 'divdates' + p + '_' + i;
            if(document.getElementById(divdates).style.display!='none')
            {
                if((document.getElementById(pickup_date).value!="") && (document.getElementById(dropoff_date).value!=""))
                {
                    calculatDays(pickup_date,dropoff_date,ski_time,rentaldays);
                }
            }
        }    
    }
