function printDoc() {
    if (window.print) window.print()
    else alert(tr.pressCltP);
}

function LoginFormSubmit() {
    return true;
}

function showFrameContainer(el, container, frame, url, width, height, xOffset, yOffset, busyUrl) {
    //    if (document.getElementById){
    //        var e = document.getElementById(el);
    //        var c = document.getElementById(container);
    //        var f = document.getElementById(frame);
    //        if (c.style.display == "block"){
    //            c.style.display="none";
    //			return false;
    //        }
    //        if (f.src != url) f.src=url;
    //        var l=0; var t=0;
    //        aTag = e;
    //        do {
    //            aTag = aTag.offsetParent;
    //            l += aTag.offsetLeft;
    //            t += aTag.offsetTop;
    //        } while (aTag.offsetParent && aTag.tagName != 'body');
    //        var left =  e.offsetLeft + l;
    //		if (xOffset) left += xOffset;
    //        var top = e.offsetTop + t
    //		if (yOffset) top += yOffset;
    //		if (!width) width = parseInt(c.style.width);
    //		if (width && ( (left + width) > getBrowserWidth() )) left = getBrowserWidth() - width - 40;
    //		if (left < 0) left = 0;
    //		c.style.position = "absolute";
    //        c.style.left = left+'px';
    //		alert(left);
    //        c.style.top = top+'px';
    //        c.style.display="block";
    //        return false;
    //    } else {
    window.open(url, "map", "top=200px,width=700px,height=400px");
    //    }
}

function hideFrameContainer(container, frame, busyUrl) {
    if (document.getElementById) {
        var c = document.getElementById(container);
        var f = document.getElementById(frame);
        c.style.display = "none";
    }
}
function popup(url, w, h, l, t)
{
    newwindow = window.open(url, 'popup1', 'width=' + w + ',height=' + h + ',left=' + l + ',top=' + t + ',menubar=no,resizable=yes,scrollbars=yes,status=yes,toolbar=no');
    if (window.focus) {
        newwindow.focus()
    }
}

function bookmark(url, description) {
    if (window.external) window.external.AddFavorite(url, description);
    else alert(tr.pressCtlD);
}

function checkSearchBox(obj) {
    var ss = obj.all("ss").value;
    if (ss == '' || ss.length < 2) {
        alert("please inter at least 3 chars");
        return        false;
    } else {
        return true;
    }
}

function ShowMore(obj) {
    var tags = "tag_" + obj;
    if (document.getElementById(tags).style.display == '') {
        document.getElementById(tags).style.display = 'none';
    } else {
        document.getElementById(tags).style.display = '';
    }
}

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 = "";
    }
}

function ChangeDiv() {
    document.getElementById("roomlistDiv").style.display = 'none';
    document.getElementById("selectDateDiv").style.display = '';
}

function ChangeDiv1() {
    document.getElementById("roomlistDiv").style.display = 'none';
    document.getElementById("mroomlistDiv").style.display = 'none';
    document.getElementById("selectDateDiv").style.display = '';
}

function showOrHiddenCityList() {
    var cityd = document.getElementById("citymoretable").style.display;
    if (cityd == '') {
        document.getElementById("citymoretable").style.display = "none";
    } else {
        document.getElementById("citymoretable").style.display = "";
    }
}

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.parentElement.parentElement.parentElement.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 = strFullDate.getYear() + "";
    var strValue_yy = strFullDate.getYear() + 1900 + "";
    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;
}

// CVC/Issue 
function onchange_cc(node) {
    if (node) {
        var issue_error = document.getElementById('dc_issue_error');
        var issue_label = document.getElementById('dc_issue_label');
        var issue_field = document.getElementById('dc_issue_number');
        var yyyymm_label = document.getElementById('dc_yyyymm_label');
        var yyyymm_field = document.getElementById('dc_yyyymm_field');
        var cvc_error = document.getElementById('cc_cvc_error');
        var cvc_label = document.getElementById('cc_cvc_label');
        var cvc_field = document.getElementById('cc_cvc_field');
        if (issue_error) {
            issue_error.style.display = 'none';
        }
        if (issue_label && issue_field) {
            issue_label.style.display = 'none';
            issue_field.style.display = 'none';
        }
        if (yyyymm_label && yyyymm_field) {
            yyyymm_label.style.display = 'none';
            yyyymm_field.style.display = 'none';
        }
        if (cvc_error) {
            cvc_error.style.display = 'none';
        }
        if (cvc_label && cvc_field) {
            cvc_label.style.display = 'none';
            cvc_field.style.display = 'none';
        }
        var cardName = ((node.options[node.selectedIndex].innerHTML).toLowerCase());
        switch (cardName) {
            case 'american express':
            case 'visa':
            case 'mastercard':
                if (cvc_error) {
                    cvc_error.style.display = '';
                }
                if (cvc_label) {
                    cvc_label.style.display = '';
                    cvc_field.style.display = '';
                }
                break;
            case 'diners club':
                break;
            case 'maestro (switch)':
                if (cvc_error) {
                    cvc_error.style.display = '';
                }
                if (cvc_label && cvc_field) {
                    cvc_label.style.display = '';
                    cvc_field.style.display = '';
                }
                if (issue_error) {
                    issue_error.style.display = '';
                }
                if (issue_label && issue_field) {
                    issue_label.style.display = '';
                    issue_field.style.display = '';
                }
                if (yyyymm_label && yyyymm_field) {
                    yyyymm_label.style.display = '';
                    yyyymm_field.style.display = '';
                }
                break;
        }
    }
}

function nochinese()
{
    value = value.replace(/[\W]/g, '');
}

function ChangeTab(tag) {
    if (tag == 1) {
        document.getElementById("tab1").style.backgroundColor = "#FFE9D2";
        document.getElementById("tab2").style.backgroundColor = "#FFFFFF";
        document.getElementById("tab3").style.backgroundColor = "#FFFFFF";
        document.getElementById("tab1").style.color = "FF6600";
        document.getElementById("tab2").style.color = "000000";
        document.getElementById("tab3").style.color = "000000";
        document.getElementById("hoteldesctab").style.display = "";
        document.getElementById("hotelpictab").style.display = "none";
        document.getElementById("hotelreviewtab").style.display = "none";
    } else if (tag == 2) {
        document.getElementById("tab1").style.backgroundColor = "#FFFFFF";
        document.getElementById("tab2").style.backgroundColor = "#FFE9D2";
        document.getElementById("tab3").style.backgroundColor = "#FFFFFF";
        document.getElementById("tab2").style.color = "FF6600";
        document.getElementById("tab1").style.color = "000000";
        document.getElementById("tab3").style.color = "000000";
        document.getElementById("hoteldesctab").style.display = "none";
        document.getElementById("hotelpictab").style.display = "";
        document.getElementById("hotelreviewtab").style.display = "none";
    } else if (tag == 3) {
        document.getElementById("tab1").style.backgroundColor = "#FFFFFF";
        document.getElementById("tab2").style.backgroundColor = "#FFFFFF";
        document.getElementById("tab3").style.backgroundColor = "#FFE9D2";
        document.getElementById("tab3").style.color = "FF6600";
        document.getElementById("tab2").style.color = "000000";
        document.getElementById("tab1").style.color = "000000";
        document.getElementById("hoteldesctab").style.display = "none";
        document.getElementById("hotelpictab").style.display = "none";
        document.getElementById("hotelreviewtab").style.display = "";
    }
}

function AddReview() {
    document.getElementById("hoteladdreviewtitle").style.display = "";
    document.getElementById("hoteladdreviewdetail").style.display = "";
}

function showPhoto(imgSrc, imgCont) {
    if (document.getElementById) {
        var c = document.getElementById(imgCont);
        if (c.style.display != "block") {
            c.innerHTML = '<img src="' + imgSrc + '">';
        }
        else {
            c.innerHTML = '<img src="' + tr.icons + '/transparent.gif">';
            c.style.display = "none";
        }
    }
}

function showHotPhoto(imgSrc, imgCont) {
    if (document.getElementById) {
        var c = document.getElementById(imgCont);
        if (c.style.display != "block") {
            c.innerHTML = '<img src="' + imgSrc + '">';
        }
        else {
            c.innerHTML = '<img src="' + tr.icons + '/transparent.gif">';
            c.style.display = "none";
        }
    }
}

function AddReviews() {
    var review_bookingid = document.getElementById("review_bookingid").value;
    var review_pincode = document.getElementById("review_pincode").value;
    var review_user = document.getElementById("review_user").value;
    var review_user = document.getElementById("review_user").value;
    var review_city = document.getElementById("review_city").value;
    var review_country = document.getElementById("review_country").value;
    var review_goodpl = document.getElementById("review_goodpl").value;
    var review_badpl = document.getElementById("review_badpl").value;
    if (review_bookingid.length != 9 || review_pincode.length != 4) {
        alert("Plese enter the right bookingid and pincode!");
        return false;
    }
    if (review_goodpl == "" && review_badpl == "") {
        alert("Plese remark at least setence on this hotel!");
        return false;
    }
    document.getElementById("plbtn").disabled = true;
    return true;
}

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 ChangeMemBtn(tag) {
    //alert(tag);
    if (tag == 1) {
        document.getElementById("memidtag").style.display = "";
    } else {
        document.getElementById("memidtag").style.display = "none";
    }
}

function bookingSubmit(obj) {
    var agree = document.getElementById("agree").checked;
    if (agree) {
        obj.disabled = true;
        document.getElementById("bookingForm").submit()
    } else {
        alert("Please check the policy and agree it");
        return false;
    }
}

function closeDiv() {
    document.all.AdLayer.style.visibility = 'hidden';
    document.getElementById('bg').style.display = 'none';
}
function ShowDiv() {
    document.all.AdLayer.style.visibility = 'visible';
    document.getElementById('bg').style.display = 'block';
}
