﻿function RoomAdd() {
    var hiddenId = document.getElementById('ddlRoom').options[document.getElementById('ddlRoom').selectedIndex].text;
    var hiddenId = document.getElementById('ddlRoom').value;
    var childDivB = document.getElementById('div_room');

    var _ca = childDivB.getElementsByTagName("div");

    var _cc = _ca.length;

    if (_cc != 0) {
        for (var k = 2; k <= _cc + 1; k++) {
            if (k > hiddenId)
                childDivB.removeChild(document.getElementById('div_adults' + k));
        }
    }
    if (hiddenId != 1) {
        for (var i = 2; i < parseInt(hiddenId) + 1; i++) {
            if (document.getElementById('div_adults' + i) == null) {
                var divs = document.createElement('div');
                divs.setAttribute('id', 'div_adults' + i);
                divs.style.marginTop = "2px";
                divs.style.marginLeft = "0px";
                if (document.getElementById('ddlCountry').value == "IND" || document.getElementById('ddlCountry').value == "NEP" || document.getElementById('ddlCountry').value == "LKA") {
                    var txt1 = "<span><select name='ddlAdults" + i + "'  id='ddlAdults" + i + "' style='width:40px;margin-left:0px;' onchange='ChangeChild(" + i + ")'><option value='1' selected='selected'>1</option><option value='2'>2</option><option value='3'>3</option></select> </span> <span style='padding-left:2px;'> <select name='ddlChildren" + i + "' id='ddlChildren" + i + "' style='width:40px' onchange='AgeAdd(" + i + ")'> <option value='0' selected='selected'>0</option><option value='1'>1</option> <option value='2'>2</option>  </select> </span> <span style='padding-left:10px;' id='Children" + i + "age1'> </span> <span style='padding-left:5px;' id='Children" + i + "age2'> </span><span style='padding-left:5px;' id='Children" + i + "age3'></span>";
                }
                else {
                    var txt1 = "<span><select name='ddlAdults" + i + "'  id='ddlAdults" + i + "' style='width:40px;margin-left:0px;'  onchange='ChangeChild(" + i + ")'><option value='1' selected='selected'>1</option><option value='2'>2</option><option value='3'>3</option><option value='4'>4</option></select> </span> <span style='padding-left:2px;'> <select name='ddlChildren" + i + "' id='ddlChildren" + i + "' style='width:40px' onchange='AgeAdd(" + i + ")'> <option value='0' selected='selected'>0</option><option value='1'>1</option> <option value='2'>2</option> <option value='3'>3</option>  </select> </span> <span style='padding-left:10px;' id='Children" + i + "age1'> </span> <span style='padding-left:5px;' id='Children" + i + "age2'> </span><span style='padding-left:5px;' id='Children" + i + "age3'></span>";
                }
                divs.innerHTML = txt1; childDivB.appendChild(divs);
            }
        }
    }
}
function AgeAdd(a) {
    var hiddenId = document.getElementById('ddlChildren' + a).options[document.getElementById('ddlChildren' + a).selectedIndex].text;
    var childDivA = document.getElementById('div_adults' + a); var _ca = childDivA.getElementsByTagName("span");
    var _cc = _ca.length;
    if (_cc != 0) {
        for (var k = 1; k <= _cc - 2; k++) {
            if (document.getElementById('Children' + a + 'age' + k) != null)
                childDivA.removeChild(document.getElementById('Children' + a + 'age' + k));
        }
    }
    if (hiddenId != 0) {
        for (var i = 1; i < parseInt(hiddenId) + 1; i++) {
            var divs = document.createElement('span');
            divs.setAttribute('id', 'Children' + a + 'age' + i);
            if (i == 1) {
                divs.style.paddingLeft = "2px";
            }
            else {
                divs.style.paddingLeft = "2px";
            }
            var txt2 = "<select class=\"piinfosoftPersonsDdl\" name='ddlChildren" + a + "age" + i + "' id='ddlChildren" + a + "age" + i + "' ><option value='0'>0-1</option> <option value='1' selected='selected'>1</option>  <option value='2'>2</option> <option value='3'>3</option><option value='4'>4</option><option value='5'>5</option> <option value='6'>6</option> <option value='7'>7</option> <option value='8'>8</option> <option value='9'>9</option>  <option value='10'>10</option><option value='11'>11</option>  <option value='12'>12</option>  <option value='13'>13</option>  <option value='14'>14</option>   <option value='15'>15</option>  <option value='16'>16</option> <option value='17'>17</option> </select> ";
            divs.innerHTML = txt2;
            childDivA.appendChild(divs);
        }
    }
}

function ChangeChild(val) {
    var childDivB1 = document.getElementById('div_adults' + val);
    var _ca1 = childDivB1.getElementsByTagName("span");
    var _cc1 = _ca1.length;

    if (_cc1 != 0) {

        for (var k = 1; k <= _cc1 - 2; k++) {
            if (document.getElementById('Children' + val + 'age' + k) != null)
                childDivB1.removeChild(document.getElementById('Children' + val + 'age' + k));
        }
    }
    if (document.getElementById('ddlCountry').value == "IND" || document.getElementById('ddlCountry').value == "NEP" || document.getElementById('ddlCountry').value == "LKA") {
        var maxChild = 3;
    }
    else {
        var maxChild = 4;
    }

    var _cb = document.getElementById('ddlAdults' + val).options[document.getElementById('ddlAdults' + val).selectedIndex].text;

    var _c9 = document.getElementById('ddlChildren' + val);
    var _ca = _c9.getElementsByTagName("option");
    var _cc = _ca.length;
    var _ce;
    for (var q = 0; q < _cc; q++) {
        if (parseInt(_ca[q].text, 10) + _cb > maxChild) {
            _c9.options[q] = null;
            _cc = _cc - 1;
            q = q - 1;
        }
    }
    if ((q - 1) < (_ce = maxChild - _cb)) {
        for (q; q <= _ce; q++) {
            _c9.options[q] = new Option(q, q);
        }
    }
}

statesArray = [];
statesArrayId = [];
function StateName() {
    statesArray = [];
    statesArrayId = [];
    var country = document.getElementById('ddlCountry').value;
    var path = "?page=9&type=xml&country=" + country;
    try //Internet Explorer
           {
        var xmlDoc;
        xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
        xmlDoc.async = false;
        //xmlDoc.load(path +"XML/"+ country +".xml");
        xmlDoc.load(path);
        ClearDropDown(document.getElementById('txtCityId'));
        AddItem("Select City", "", document.getElementById('txtCityId'));
        for (var i = 0; i < xmlDoc.documentElement.childNodes.length; i = i + 1) {
            //                  statesArray[i] =   xmlDoc.documentElement.childNodes[i].attributes[1].nodeValue;
            //                  statesArrayId[i] = xmlDoc.documentElement.childNodes[i].attributes[0].nodeValue;
            AddItem(xmlDoc.documentElement.childNodes[i].attributes[1].nodeValue, xmlDoc.documentElement.childNodes[i].attributes[0].nodeValue, document.getElementById('txtCityId'));
        }
    }
    catch (e) {
        try //Firefox, Mozilla, Opera, etc.
              {
            var xmlDoc1;
            xmlDoc1 = document.implementation.createDocument("", "doc", null)
            xmlDoc1.async = false;
            xmlDoc1.load(path);
          // alert(xmlDoc1);
            var noOfCompanyTags = xmlDoc1.getElementsByTagName("vendors");
            var userdetails = noOfCompanyTags[0].getElementsByTagName("row");
            ClearDropDown(document.getElementById('txtCityId'));
            AddItem("Select City", "", document.getElementById('txtCityId'));
            for (var num1 = 0; num1 < userdetails.length; num1++) {
                //                      statesArray[num1]=userdetails[num1].getAttribute("AreaName");
                //                      statesArrayId[num1]= userdetails[num1].getAttribute("AreaId");         
                AddItem(userdetails[num1].getAttribute("AreaName"), userdetails[num1].getAttribute("AreaId"), document.getElementById('txtCityId'));
            }
        }
        catch (e) {
            try //Google Chrome
                {
                var xmlhttp = new window.XMLHttpRequest();
                xmlhttp.open("GET", path, false);
                xmlhttp.send(null);
                xmlDoc2 = xmlhttp.responseXML.documentElement;

                //var noOfCompanyTags = xmlDoc1.getElementsByTagName("vendors");
                var userdetails = xmlDoc2.getElementsByTagName("row");
                ClearDropDown(document.getElementById('txtCityId'));
                AddItem("Select City", "", document.getElementById('txtCityId'));
                for (var num1 = 0; num1 < userdetails.length; num1++) {
                    //                      statesArray[num1]=userdetails[num1].getAttribute("AreaName");
                    //                      statesArrayId[num1]= userdetails[num1].getAttribute("AreaId");      
                    AddItem(userdetails[num1].getAttribute("AreaName"), userdetails[num1].getAttribute("AreaId"), document.getElementById('txtCityId'));
                }
            }
            catch (e) {
                error = e.message;
            }
        }

    }
}


function ShowHideSearch() {
    var s2 = document.getElementById('SearchPanel');

    var _ca1 = s2.getElementsByTagName("div");
    var _cc1 = _ca1.length;

    if (_cc1 != 0) {

        for (var k = 1; k <= _cc1; k++) {
            s2.removeChild(document.getElementById('dv' + k));
        }
    }
    else {
        var txtBox = "<div id='dv1' style='margin-top:10px;margin-left:10px; '> <span style='width:42.5%; float:left;font-family:Verdana; font-size:11px'>Hotel</span> <span style='width:40.3%; float:left;font-family:Verdana; font-size:11px;padding-left:16px'>Select Star</span> </div> <div id='dv2' style='margin-top:10px;margin-left:10px;'> <span> <input id='txtHotel'  name='txtHotel'  style='width:42.3%'   type='text' />  </span>  <span style='padding-left:10px'>  <select id='ddlStar'  name='ddlStar'  style='width:39%' > <option value='Any'>Any</option> <option value='0'>0</option> <option value='1'>1</option> <option value='2'>2</option>  <option value='3'>3</option> <option value='4'>4</option> <option value='5'>5</option> <option value='6'>6</option> <option value='7'>7</option> </select> </span> </div>";
        s2.innerHTML = txtBox;

    }

}

function chkvalid() {
    document.getElementById("txtCity").value = document.getElementById('txtCityId').options[document.getElementById('txtCityId').selectedIndex].text;
    document.getElementById("ddlCountryName").value = document.getElementById('ddlCountry').options[document.getElementById('ddlCountry').selectedIndex].text;

    var chkmsg = "";
    if (document.getElementById("txtCityId").value == "") {
        chkmsg += "Select City ...\n";
        alert(chkmsg);
        return false;
    }
    else if (document.getElementById("txtCheckIn").value == "") {
        chkmsg += "Drop of CheckIn Date ...\n";
        alert(chkmsg);
        return false;
    }
    else {
        return true;
    }

}




function emptyCity() {
    document.getElementById('txtCityId').value = "";
    // document.getElementById('txtCityId').value="";

    if (document.getElementById('ddlCountry').value == "IND" || document.getElementById('ddlCountry').value == "NEP" || document.getElementById('ddlCountry').value == "LKA") {
        var snRoom = document.getElementById('spnRoom');
        var txtRoom = "<select name='ddlRoom' id='ddlRoom' class=\"piinfosoftSmallDdl\" onchange='RoomAdd()'>  <option value='1' selected='selected'>1</option><option value='2'>2</option><option value='3'>3</option> </select> ";
        snRoom.innerHTML = txtRoom;

        var dvAdult1 = document.getElementById('div_adults1');
        var txtAdult1 = "<span> <select name='ddlAdults1' id='ddlAdults1' class=\"piinfosoftPersonsDdl\"  onchange='ChangeChild(1);' >  <option value='1' selected='selected'>1</option>    <option value='2'>2</option> <option value='3'>3</option></select>  </span>  <span style='padding-left:2px;'> <select name='ddlChildren1' id='ddlChildren1' class=\"piinfosoftPersonsDdl\" onchange='AgeAdd(1)'> <option value='0' selected='selected'>0</option>  <option value='1'>1</option>  <option value='2'>2</option> </select> </span> ";
        dvAdult1.innerHTML = txtAdult1;

        if (document.getElementById('div_adults4') != null) {
            document.getElementById('div_room').removeChild(document.getElementById('div_adults4'));
        }
        if (document.getElementById('div_adults3') != null) {
            document.getElementById('div_room').removeChild(document.getElementById('div_adults3'));
        }
        if (document.getElementById('div_adults2') != null) {
            document.getElementById('div_room').removeChild(document.getElementById('div_adults2'));
        }
    }
    else {
        var snRoom = document.getElementById('spnRoom');
        var txtRoom = "<select name='ddlRoom' id='ddlRoom' class=\"piinfosoftSmallDdl\" onchange='RoomAdd()'>  <option value='1' selected='selected'>1</option><option value='2'>2</option><option value='3'>3</option> <option value='4'>4</option> </select> ";
        snRoom.innerHTML = txtRoom;

        var dvAdult1 = document.getElementById('div_adults1');
        var txtAdult1 = "<span> <select name='ddlAdults1' id='ddlAdults1' class=\"piinfosoftPersonsDdl\" onchange='ChangeChild(1);'  >  <option value='1' selected='selected'>1</option>    <option value='2'>2</option> <option value='3'>3</option>  <option value='4'>4</option> </select>  </span>  <span style='padding-left:2px;'> <select name='ddlChildren1' id='ddlChildren1' class=\"piinfosoftPersonsDdl\" onchange='AgeAdd(1)'> <option value='0' selected='selected'>0</option>  <option value='1'>1</option>  <option value='2'>2</option> <option value='3'>3</option> </select> </span> ";
        dvAdult1.innerHTML = txtAdult1;
    }
    StateName();
}







function Querystring(qs) { // optionally pass a querystring to parse

    this.params = {};

    if (qs == null) qs = location.search.substring(1, location.search.length);
    if (qs.length == 0) return;

    qs = qs.replace(/\+/g, ' ');
    var args = qs.split('&'); // parse out name/value pairs separated via &

    for (var i = 0; i < args.length; i++) {
        var pair = args[i].split('=');
        var name = decodeURIComponent(pair[0]);

        var value = (pair.length == 2)
			? decodeURIComponent(pair[1])
			: name;

        this.params[name] = value;
    }
}

Querystring.prototype.get = function (key, default_) {
    var value = this.params[key];
    return (value != null) ? value : default_;
}

Querystring.prototype.contains = function (key) {
    var value = this.params[key];
    return (value != null);
}

function getQuerystring(key, default_) {
    if (default_ == null) default_ = "";
    key = key.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regex = new RegExp("[\\?&]" + key + "=([^&#]*)");
    var qs = regex.exec(window.location.href);
    if (qs == null)
        return default_;
    else
        return qs[1];
}
//To Clear drop Down Before you fill new entries
function ClearDropDown(ddl) {
    var len = ddl.options.length;
    for (var i = 0; i < len; i++) {
        ddl.remove(0); //It is 0 (zero) intentionally 
    }
}
//Add New entries to the drop down
function AddItem(Text, Value, dropdownName) {
    var opt = document.createElement("option");
    opt.text = Text;
    opt.title = Text;
    opt.value = Value;
    dropdownName.options.add(opt);
}
function settxtCity() {
    var hiddenId = document.getElementById('txtCityId').options[document.getElementById('txtCityId').selectedIndex].text;
    if (document.getElementById("txtCity") != null)
        document.getElementById("txtCity").value = hiddenId;
}
