﻿//ทำการ แสดง Dialog ในการ Confirm จาก User ว่าต้องการให้ PostBack Event 
//ของ Control หรือไม่
function confirmationItem(ButtomID,strMessage) 
{
    var answer = confirm(strMessage)
    if (answer)
    {
        // ถ้ายืนยัน จะทำการเรียก Event Button Click ของ ปุ่ม Delete ที่เป็น Server Side
        __doPostBack(ButtomID,'');
    }
}

//ทำการ แสดง Dialog ในการ Confirm จาก User ว่าต้องการให้ PostBack Event 
//ของ Control หรือไม่ ( สำหรับ GridView มีการตรวจสอบ ว่าต้องถูก Select อย่างน้อย 1 ด้วย )
function confirmationItemGridView(GridViewClientName,ButtomID,strMessage) 
{
    var count = GridViewClientName.GetSelectedRowCount() > 0;
    if(!count) 
    {
        alert("กรุณาเลือกรายการที่ต้องการ");
        return;
    }

    var answer = confirm(strMessage)
    if (answer)
    {
        // ถ้ายืนยัน จะทำการเรียก Event Button Click ของ ปุ่ม Delete ที่เป็น Server Side
        __doPostBack(ButtomID,'');
    }
}

// Get QueryString
function GetQueryString(queryStringName) 
{
    strUrl = window.location.search.substring(1);
    arrayQueryString = strUrl.split("&");
    for (i=0;i<arrayQueryString.length;i++) 
    {
        valueQueryString = arrayQueryString[i].split("=");
        if (valueQueryString[0] == queryStringName) 
        {
            return valueQueryString[1];
        }
    }
}

// เปิด Select Image Dialog
function OpenSelectImageDialog(txtImgID,controlImg,hdfPath)
{        
    window.open('../Dialog/SelectImage.aspx?txtImgID='+txtImgID+'&controlImg='+controlImg+'&hdfPath='+hdfPath,'cal','width=600px,height=400px,scrollbars=yes,toolbar=no,resizable=no');
}

// เปิด Add Image Dialog
function OpenAddImageDialog(txtImgID,controlImg,hdfPath)
{                     
    window.open('../Dialog/AddImage.aspx?txtImgID='+txtImgID+'&controlImg='+controlImg+'&hdfPath='+hdfPath,'cal','width=600px,height=180px,scrollbars=yes,toolbar=no,resizable=no');
}
// ใช้ในการลบรูปที่ได้เลือกไว้
function OnDeleteImage(txtImgID,controlImg,hdfPath)
{
    var controlImage = document.getElementById(controlImg);
    if(typeof controlImage != "undefined")
        controlImage.src = "~/ImageObjectHandler.ashx?img=0&size=100";
        
    var controlTxtImg = document.getElementById(txtImgID);
    if(typeof controlTxtImg != "undefined")
        controlTxtImg.value = "";
    
    var controlHidPath = document.getElementById(hdfPath);
    if(typeof controlHidPath != "undefined")
        controlHidPath.value = "";
}


function GetImageID(strImgID,strVirtualPath)
{
    _dxeTbxInsertImageUrl.SetText("../"+strVirtualPath);
    dxPopupSelectImageUC.Hide();
}
function ChangeShowTerm(PropertyID) {
    if (PropertyID != "") {
        window.open('Dialog/ChangeShowTerm.aspx?PropertyID=' + PropertyID, 'cal', 'left=500,top=300,width=400,height=200,location=no, menubar=no, modal=yes, status=no, toolbar=no, scrollbars=no, resizable=no, tite=no, resizable=no, directories=no');
    }
}

function SetCheckBox(controlId,hdfID) {
    if (controlId.checked) {
        document.getElementById(hdfID).value = document.getElementById(hdfID).value + "|" + controlId.id;
    } else {
        document.getElementById(hdfID).value = document.getElementById(hdfID).value.replace("|" + controlId.id, "");
    }
    return;
}

function SetCheckBoxCompare(controlId, hdfID) {
    
    if (controlId.checked) {
        var len1 = document.getElementById(hdfID).value.split("|")
        //document.write(len1.length);
        if (len1.length > 4) {
            alert("สามารถเลือกเปรียบเทียบได้ครั้งละ 4 รายการ");
            controlId.checked = false;
            return;
        }
        document.getElementById(hdfID).value = document.getElementById(hdfID).value + "|" + controlId.id;
    } else {
        document.getElementById(hdfID).value = document.getElementById(hdfID).value.replace("|" + controlId.id, "");
    }
    return;
}


function OpenUpSendMail(hdfID,Page) {
    var PropID = document.getElementById(hdfID).value;
    window.open('Dialog/SendmailDialog.aspx?ID=' + PropID + '&Page='+ Page +'','SendEmail','width=500,height=350,toolbar=no,location=no,left=200,top=200,screenX=200,screenY=200');
    return;
}

function SetDisableAm(ddlprovice, ddlamphur) {
    if (ddlprovice != null) {
        // alert(province);
        var province = ddlprovice.value.replace(" ", "")
        var amp = document.getElementById(ddlamphur)
        if (province == 'กรุงเทพมหานคร') {//ถ้าเป็น ID ของ กรุงเทพ
            if (amp != null) {
                amp.disabled = false;
            }
        } else {

        if (amp != null) {
            amp.disabled = true;
        }
        }
    }
    return;
}

function openPopUp(linkURL) {
    window.open(linkURL);
}

function checkcompare(ButtomID, hdfID) {
    var compare = document.getElementById(hdfID).value
    if (compare == null || compare == "") {
        alert("กรุณาเลือกรายการที่ต้องการเปรียบเทียบ");
        return;
    }
    else {
        __doPostBack(ButtomID, '');
    }

}

function checkcompare1(hdfID, hdftype) {
    var compare = document.getElementById(hdfID).value
    var comparetype = document.getElementById(hdftype).value
    if (compare == null || compare == "") {
        alert("กรุณาเลือกรายการที่ต้องการเปรียบเทียบ");
        return;
    }
    else {
        var len1 = document.getElementById(hdfID).value.split("|")
        var data = "";
        for (i = 0; i < len1.length; i++) {
            var len2 = len1[i];
            var len3 = len2.split("_");
            if (len3.length == 5) {
                data = data + "_" + len3[4];
            }
        }
    }
    window.open('PropertiesCompare.aspx?T=' + comparetype + '&Id=' + data, '', 'menubar=1,status=1,scrollbars=1,resizable=1')
}

function checkcompareService(hdfID) {
    var compare = document.getElementById(hdfID).value    
    if (compare == null || compare == "") {
        alert("กรุณาเลือกรายการที่ต้องการเปรียบเทียบ");
        return;
    }
    else {
        var len1 = document.getElementById(hdfID).value.split("|")
        var data = "";
        for (i = 0; i < len1.length; i++) {
            var len2 = len1[i];
            var len3 = len2.split("_");
            if (len3.length == 5) {
                data = data + "_" + len3[4];
            }
        }
    }
    window.open('ServiceCompare.aspx?Id=' + data, '', 'menubar=1,status=1,scrollbars=1,resizable=1')
}



function SettypeSeach(hplseach, hdfseachMode, tableSeachfull) {

    var tb = document.getElementById(tableSeachfull);
    var hpl = document.getElementById(hplseach);
    var hdfseach = document.getElementById(hdfseachMode);
    if (tb != null) {
        if (hpl != null) {

            if (hpl.innerHTML == "ค้นหาแบบละเอียด") {
                tb.style.display = "";
                hpl.innerHTML = "ค้นหาแบบเร็ว";
                hdfseach.value = "f";
            }
            else {
                tb.style.display = "none";
                hpl.innerHTML = "ค้นหาแบบละเอียด";
                hdfseach.value = "q";
            }
        }
    }
    return;
}

function setValue(val, divE_rentprice, divE_saleprice) {
    if (val == "0") {
        document.getElementById(divE_rentprice).style.display = "none";
        document.getElementById(divE_saleprice).style.display = "";
    }
    else if (val == "1") {
    document.getElementById(divE_rentprice).style.display = "";
    document.getElementById(divE_saleprice).style.display = "none";
    }
    else if (val == "2") {
    document.getElementById(divE_rentprice).style.display = "";
    document.getElementById(divE_saleprice).style.display = "";
    }

    return;
}

function bgr_color(obj, color) {
    obj.style.color = color
}
