﻿function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

   function validateForm()
{
    var chks = document.getElementsByName('bookingdates');
    var hasChecked = false;
    var noSequence = false;
    var startdate='';
    var enddate='';
    var nextdate=0;
    var nextcounter=0;
    for (var i = 0; i < chks.length; i++)
    {
        if (chks[i].checked)
        {
            var strvalue=trim(chks[i].value);
            //alert ( strvalue);
            //var arrvalue = strvalue.split("-");
            if (startdate=='')
            {
                startdate = strvalue;
            }
            
            hasChecked=true;
            if (nextcounter>0) {
                //if (parseInt(nextdate) != parseInt(trim(arrvalue[2]))) {
                  //  alert(nextdate);
                    //alert(arrvalue[2]);
                    //noSequence=true;
                    //break;
                    //}
                    //else 
                    if (nextcounter!=i){
                        noSequence=true;
                        break;
                    }
             }
            //nextdate=parseInt(arrvalue[2])+1;
            nextcounter=i+1;
        }
    }
    if (!hasChecked){
        alert("Please select at least one.");
        //chks[0].focus();
        return false;
    }
    if (noSequence) {
        alert("Please select sequencial dates !");
        //chks[0].focus();
        return false;
    }
    enddate=chks[nextcounter-1].value;
//    var startdate1 = document.getElementsByName('startdate');
//    startdate1.value=startdate;
//    var enddate1 = document.getElementsByName('enddate');
//    enddate1.value = enddate;
//    alert ("startdate " + startdate1.value);
//    alert ("enddate " + enddate1.value);
 //__doPostBack('btnAvailability1','');
 //theForm.action="Default.aspx";
    theForm.submit();
    return true;
}
