function ShowHotel(i, l) {
    for (kk = 0; kk < l; kk++) {
        if (kk == i) {
            document.getElementById("hoteltag_" + kk).className = "aa1";
            document.getElementById("hotellisttag_" + kk).style.display = "block";
        } else {
            document.getElementById("hoteltag_" + kk).className = "aa2";
            document.getElementById("hotellisttag_" + kk).style.display = "none";
        }
    }
}



function changeDate(type, obj) {
    var hindate = obj.parentElement.parentElement.parentElement.all("hindate").value;
    var houtdate = obj.parentElement.parentElement.parentElement.all("houtdate").value;
    var staydays = obj.parentElement.parentElement.parentElement.all("staydays").value;
    if (type == 1) {
        if (getDate(hindate) < new Date()) {
            obj.parentElement.parentElement.parentElement.all("hindate").value = formatDate(new Date(), "yyyy-mm-dd");
            obj.parentElement.parentElement.parentElement.all("indate_day").value = formatDate(getDate(hindate), "dd");
            hindate = obj.parentElement.parentElement.parentElement.all("hindate").value;
            obj.parentElement.parentElement.parentElement.all("houtdate").value = getAddDate(hindate, staydays);
        }
        obj.parentElement.parentElement.parentElement.all("indate_month").value = formatDate(getDate(hindate), "yyyy-m");
        obj.parentElement.parentElement.parentElement.all("indate_day").value = formatDate(getDate(hindate), "dd");
        obj.parentElement.parentElement.parentElement.all("houtdate").value = getAddDate(hindate, staydays);
    } else if (type == 3) {
        if (getDateDiff(hindate, houtdate) > 30) {
            //alert("only booking 30 nights");
            obj.parentElement.parentElement.parentElement.all("staydays").value = 30;
            obj.parentElement.parentElement.parentElement.all("houtdate").value = getAddDate(hindate, 30);
            houtdate = obj.parentElement.parentElement.parentElement.all("houtdate").value;
        }
        obj.parentNode.parentNode.parentNode.all("outdate_day").value = formatDate(getDate(houtdate), "dd");
        obj.parentElement.parentElement.parentElement.all("outdate_month").value = formatDate(getDate(houtdate), "yyyy-m");
        obj.parentElement.parentElement.parentElement.all("staydays").value = getDateDiff(hindate, houtdate);
    }
}

function selectInDate1(days) {
    var dates = new Date(new Date().getTime() + days * (1000 * 60 * 60 * 24))
    var hindate = document.getElementById("hindate").value;
    var houtdate = document.getElementById("houtdate").value;
    var staydays = document.getElementById("staydays").value;
    if (getDate(hindate) < dates) {
        hindate = formatDate(dates, "yyyy-mm-dd");
    }
    document.getElementById("indate_month").value = formatDate(getDate(hindate), "yyyy-m");
    document.getElementById("indate_day").value = formatDate(getDate(hindate), "d");
    document.getElementById("houtdate").value = getAddDate(hindate, staydays);
    houtdate = getAddDate(hindate, staydays);
    document.getElementById("outdate_month").value = formatDate(getDate(houtdate), "yyyy-m");
    document.getElementById("outdate_day").value = formatDate(getDate(houtdate), "d");
}


function selectInDate() {
    var dates = getAddDate(new Date(), 0);
    var hindate = document.getElementById("hindate").value;
    var houtdate = document.getElementById("houtdate").value;
    var staydays = document.getElementById("staydays").value;
    if (getDate(hindate) < dates) {
        hindate = formatDate(dates, "yyyy-mm-dd");
    }
    document.getElementById("indate_month").value = formatDate(getDate(hindate), "yyyy-m");
    document.getElementById("indate_day").value = formatDate(getDate(hindate), "d");
    document.getElementById("houtdate").value = getAddDate(hindate, staydays);
    houtdate = getAddDate(hindate, staydays);
    document.getElementById("outdate_month").value = formatDate(getDate(houtdate), "yyyy-m");
    document.getElementById("outdate_day").value = formatDate(getDate(houtdate), "d");
}

function selectOutDate() {
    var hindate = document.getElementById("hindate").value;
    var houtdate = document.getElementById("houtdate").value;
    var staydays = document.getElementById("staydays").value;
    if (getDateDiff(hindate, houtdate) > 30) {
        houtdate = getAddDate(hindate, 30);
    }
    if (getDateDiff(hindate, houtdate) < 1) {
        houtdate = getAddDate(hindate, 1);
    }
    document.getElementById("houtdate").value = formatDate(getDate(houtdate), "yyyy-mm-dd");
    document.getElementById("outdate_month").value = formatDate(getDate(houtdate), "yyyy-m");
    document.getElementById("outdate_day").value = formatDate(getDate(houtdate), "d");
    document.getElementById("staydays").value = getDateDiff(hindate, houtdate);
}


function changeDate1(type, obj) {
    var hindate = obj.parentElement.parentElement.parentElement.all("indate").value;
    var houtdate = obj.parentElement.parentElement.parentElement.all("outdate").value;
    var staydays = obj.parentElement.parentElement.parentElement.all("staydays1").value;
    if (type == 1) {
        if (getDate(hindate) < new Date()) {
            obj.parentElement.parentElement.parentElement.all("indate").value = formatDate(new Date(), "yyyy-mm-dd");
            obj.parentElement.parentElement.parentElement.all("indate_day").value = formatDate(new Date(), "dd");
            hindate = obj.parentElement.parentElement.parentElement.all("indate").value;
            obj.parentElement.parentElement.parentElement.all("outdate").value = getAddDate(hindate, staydays);
        }
        obj.parentElement.parentElement.parentElement.all("outdate").value = getAddDate(hindate, staydays);
    } else if (type == 3) {
        if (getDateDiff(hindate, houtdate) > 30) {
            alert("only booking 30 nights");
            obj.parentElement.parentElement.parentElement.all("staydays1").value = 30;
            obj.parentElement.parentElement.parentElement.all("outdate").value = getAddDate(hindate, 30);
            houtdate = obj.parentElement.parentElement.parentElement.all("outdate").value;
        }
        obj.parentElement.parentElement.parentElement.all("staydays1").value = getDateDiff(hindate, houtdate);
    }
}


function getDateDiff(date1, date2) {
    var re = /^(\d{4})\S(\d{1,2})\S(\d{1,2})$/;
    var dt1,dt2;
    if (re.test(date1)) {
        dt1 = new Date(RegExp.$1, RegExp.$2 - 1, RegExp.$3);
    }
    if (re.test(date2)) {
        dt2 = new Date(RegExp.$1, RegExp.$2 - 1, RegExp.$3);
    }
    return Math.floor((dt2 - dt1) / (1000 * 60 * 60 * 24))
}

function getDate(date1) {
    var re = /^(\d{4})\S(\d{1,2})\S(\d{1,2})$/;
    if (re.test(date1)) {
        return   new Date(RegExp.$1, RegExp.$2 - 1, RegExp.$3);
    }
}

function getAddDate(date1, days) {
    var re = /^(\d{4})\S(\d{1,2})\S(\d{1,2})$/;
    var dt1,dt2;
    if ((typeof date1 == 'string')) {
        if (re.test(date1)) {
            dt1 = new Date(RegExp.$1, RegExp.$2 - 1, RegExp.$3);
        }
    } else {
        dt1 = date1;
    }
    dt2 = new Date(dt1.getTime() + days * (1000 * 60 * 60 * 24))
    return formatDate(dt2, "yyyy-mm-dd");
}

function getAddDate1(date1, days) {
    var re = /^(\d{4})\S(\d{1,2})\S(\d{1,2})$/;
    var dt1,dt2;
    if (re.test(date1)) {
        dt1 = new Date(RegExp.$1, RegExp.$2 - 1, RegExp.$3);
    }
    dt2 = new Date(dt1.getTime() + days * (1000 * 60 * 60 * 24))
    return formatDate(dt2, "yyyy-mm-dd");
}

function formatDate(strFullDate, strFormatString) {

    var strMonths = new Array();
    var strDay = new Array();

    strMonths[0] = "January";
    strMonths[1] = "February";
    strMonths[2] = "March";
    strMonths[3] = "April";
    strMonths[4] = "May";
    strMonths[5] = "June";
    strMonths[6] = "July";
    strMonths[7] = "August";
    strMonths[8] = "September";
    strMonths[9] = "October";
    strMonths[10] = "November";
    strMonths[11] = "December";
    strDay[0] = "Sunday";
    strDay[1] = "Monday";
    strDay[2] = "Tuesday";
    strDay[3] = "Wednesday";
    strDay[4] = "Thursday";
    strDay[5] = "Friday";
    strDay[6] = "Saturday";
    var strValue_d = strFullDate.getDate();
    var strValue_dd = (strValue_d < 10) ? '0' + strValue_d : strValue_d;
    var strValue_m = strFullDate.getMonth() + 1;
    var strValue_mm = (strValue_m < 10) ? '0' + strValue_m : strValue_m;
    var strValue_mmmm = strMonths[strFullDate.getMonth()];
    var strValue_mmm = strValue_mmmm.substr(0, 3);
    var strValue_yyyy = "";
	if(strFullDate.getYear() < 1900){
		strValue_yyyy = (strFullDate.getYear() + 1900) + "";
	}else{
		strValue_yyyy = strFullDate.getYear() + "";
	}
    var strValue_yy = strFullDate.getYear();
	if(strValue_yy<1900){
		strValue_yy = strFullDate.getYear() + 1900 + "";
	}else{
		strValue_yy = strFullDate.getYear() + "";
	}

    var strValue_y = strValue_yy.substr(2, 2);
    var strValue_ww = strDay[strFullDate.getDay()];
    var strValue_w = strValue_ww.substr(0, 3);

    if (strFormatString.indexOf("dd") > -1) {
        strFormatString = strFormatString.replace("dd", "strValue_dd");
    }
    else {
        if (strFormatString.indexOf("d") > -1) {
            strFormatString = strFormatString.replace("d", "strValue_d");
        }
    }

    if (strFormatString.indexOf("mmmm") > -1) {
        strFormatString = strFormatString.replace("mmmm", "strValue_mmmm");
    } else {
        if (strFormatString.indexOf("mmm") > -1) {
            strFormatString = strFormatString.replace("mmm", "strValue_mmm");
        } else {
            if (strFormatString.indexOf("mm") > -1) {
                strFormatString = strFormatString.replace("mm", "strValue_mm");
            } else {
                if (strFormatString.indexOf("m") > -1) {
                    strFormatString = strFormatString.replace("m", "strValue_m");
                }
            }
        }
    }

    if (strFormatString.indexOf("yyyy") > -1) {
        strFormatString = strFormatString.replace("yyyy", "strValue_yyyy");
    } else
        if (strFormatString.indexOf("yy") > -1) {
            strFormatString = strFormatString.replace("yy", "strValue_yy");
        } else {
            if (strFormatString.indexOf("y") > -1) {
                strFormatString = strFormatString.replace("y", "strValue_y");
            }
        }

    if (strFormatString.indexOf("ww") > -1) {
        strFormatString = strFormatString.replace("ww", "strValue_ww");
    } else {
        if (strFormatString.indexOf("w") > -1) {
            strFormatString = strFormatString.replace("w", "strValue_w");
        }
    }

    strFormatString = strFormatString.replace("strValue_dd", strValue_dd);
    strFormatString = strFormatString.replace("strValue_d", strValue_d);
    strFormatString = strFormatString.replace("strValue_mmmm", strValue_mmmm);
    strFormatString = strFormatString.replace("strValue_mmm", strValue_mmm);
    strFormatString = strFormatString.replace("strValue_mm", strValue_mm);
    strFormatString = strFormatString.replace("strValue_m", strValue_m);
    strFormatString = strFormatString.replace("strValue_yyyy", strValue_yyyy);
    strFormatString = strFormatString.replace("strValue_yy", strValue_yy);
    strFormatString = strFormatString.replace("strValue_y", strValue_y);
    strFormatString = strFormatString.replace("strValue_ww", strValue_ww);
    strFormatString = strFormatString.replace("strValue_w", strValue_w);

    return strFormatString;
}
function changeInDate() {
    var indate_month = document.getElementById("indate_month").value;
    var indate_day = document.getElementById("indate_day").value;
    document.getElementById("hindate").value = indate_month + "-" + indate_day;
    selectInDate();
}

function changeOutDate() {
    var outdate_month = document.getElementById("outdate_month").value;
    var outdate_day = document.getElementById("outdate_day").value;
    document.getElementById("houtdate").value = outdate_month + "-" + outdate_day;
    selectOutDate();
}

function blockdisplay(tag) {
    if (tag == 1) {
        document.getElementById("b_blockdisplay1").style.display = "";
        document.getElementById("b_blockdisplay2").style.display = "none";
    } else {
        document.getElementById("b_blockdisplay1").style.display = "none";
        document.getElementById("b_blockdisplay2").style.display = "";
    }
}
