﻿function search2() {
    var loc = ' ';

    _province = document.getElementById('Province');
    if (_province == null)
        s = document.getElementById('ctl00_content_Agn1_EstateID').value;

    _city = document.getElementById('City');
    if (_city == null)
        _city = document.getElementById('ctl00_content_Agn1_City');

    if (document.getElementById('Province') != null)
        if (document.getElementById('Province').selectedIndex == -1)
        s = "";
    else
        s = document.getElementById('Province')[document.getElementById('Province').selectedIndex].text;

    if (document.getElementById('ctl00_content_Agn1_ag') != null) {
        ag = document.getElementById('ctl00_content_Agn1_ag').value;
        agnn = document.getElementById('ctl00_content_Agn1_agnn').value;
    }
    else {
        ag = -10;
        agnn = '';

    }
    if (document.getElementById('ctl00_content_Agn1_Province') != null)
        estt = document.getElementById('ctl00_content_Agn1_Province').value;
    else
        estt = '';

    //        if (sEstate == 'undefined')
    //                sEstate = 'تهران';
    if (estt != '')
        loc += 'استان ' + estt + ' ';
    c = _city.value.replace(/^\s+|\s+$/g, '');
    if (c == 'شهر')
        c = '';
    if (c != '')
        loc += 'شهر ' + c + ' ';
    var mtype = document.getElementById('MType')[document.getElementById('MType').selectedIndex].text;
    if (mtype == 'همه')
        mtype = '';
    el = document.getElementById("SearchType").value;
    sumprice1 = "";
    sumprice2 = "";
    rahnprice1 = "";
    rahnprice2 = "";
    leaseprice1 = "";
    leaseprice2 = "";
    if (document.getElementById('minprice').selectedIndex != -1)
        price1 = document.getElementById('minprice')[document.getElementById('minprice').selectedIndex].text;
    else
        price1 = "";
    if (document.getElementById('maxprice').selectedIndex != -1)
        price2 = document.getElementById('maxprice')[document.getElementById('maxprice').selectedIndex].text;
    else
        price2 = "";

    if (el.value == 2) {
        rahnprice1 = price1;
        rahnprice2 = price2;
    }
    else
        if (el.value == 3) {
        leaseprice1 = price1;
        leaseprice2 = price2;
    }
    else {
        sumprice1 = price1;
        sumprice2 = price2;
    }

    if (document.getElementById('Region').value.replace(/^\s+|\s+$/g, '') == 'محدوده')
        region = '';
    else
        region = document.getElementById('Region').value;
    searchtype = 0;
    if (document.getElementById('SearchType').value == 1)
        searchtype = 2;
    else
        if (document.getElementById('SearchType').value == 2 || document.getElementById('SearchType').value == 3)
        searchtype = 1;
    else
        if (document.getElementById('SearchType').value == 4)
        searchtype = 3;
    else
        if (document.getElementById('SearchType').value == 5)
        searchtype = 4;

    if (document.getElementById('Province') != null)
        estid = document.getElementById('Province').value;
    else
        estid = document.getElementById('ctl00_content_Agn1_EstateID').value;
    var s = 'SearchResult.aspx?ag=' + ag +
                '&agnn=' + agnn +
                '&est=' + estid +
                '&ct=' + c +
                '&loc=' + loc +
                '&rgn1=' + region +
                '&num=' +
                '&mtp=' + mtype +
                '&bld=' +
                '&slp=' + document.getElementById('sleepcnt')[document.getElementById('sleepcnt').selectedIndex].text +
                '&rhn1=' + rahnprice1 +
                '&rhn2=' + rahnprice2 +
                '&les1=' + leaseprice1 +
                '&les2=' + leaseprice2 +
                '&sprs1=' + sumprice1 +
                '&sprs2=' + sumprice2 +
                '&slvl=' + searchtype +
                '&mt=&nslc=0';
    window.open(encodeURI(s), '', '', '');

}

var m_strNewDefaultText = "";
function DeleteDefaultText(el, strDefaultText) {

    if (el.value == strDefaultText || el.value == m_strNewDefaultText) {
        el.value = '';
        el.onclick = '';
        el.onkeypress = '';
    }
}
function ChangeDefaultText(strText) {
    var txtSearch = document.getElementById("HomepageSearch_RMX1_txtSearch_txtCSZ");

    if (strText == "") {
        strText = "Search by City or County and State, or ZIP";
    }
    txtSearch.value = strText;
    m_strNewDefaultText = strText;
}


function searchchanged(el) {
    document.getElementById("minprice").disabled = "";
    document.getElementById("maxprice").disabled = "";
    premin = '<select name="minprice" id="minprice" class="garycolor">';
    premax = '<select name="maxprice" id="maxprice" class="garycolor">';
    post = '</select>';
    pricetext = "<option value=''></option><option value='1'>1ميليون</option><option value='3'>3ميليون</option><option value='5'>5ميليون</option><option value='7'>10ميليون</option><option value='8'>15ميليون</option><option value='9'>20ميليون</option><option value='11'>30ميليون</option><option value='13'>40ميليون</option><option value='15'>50ميليون</option><option value='17'>60ميليون</option><option value='18'>70ميليون</option><option value='19'>80ميليون</option><option value='20'>90ميليون</option><option value='21'>100ميليون</option><option value='22'>120ميليون</option><option value='23'>150ميليون</option><option value='24'>180ميليون</option><option value='25'>200ميليون</option><option value='26'>250ميليون</option><option value='27'>300ميليون</option><option value='28'>350ميليون</option><option value='29'>400ميليون</option><option value='30'>450ميليون</option><option value='31'>500ميليون</option><option value='32'>600ميليون</option><option value='33'>700ميليون</option><option value='34'>800ميليون</option><option value='35'>900ميليون</option><option value='36'>1ميليارد</option><option value='37'>2ميليارد</option><option value='38'>10ميليارد</option><option value='39'>50ميليارد</option><option value='40'>100ميليارد</option><option value='41'>1000ميليارد</option>";
    rahntext = "<option value=''></option><option value='0'>100تومان</option><option value='2'>1ميليون</option><option value='4'>3ميليون</option><option value='6'>5ميليون</option><option value='11'>10ميليون</option><option value='16'>15ميليون</option><option value='21'>20ميليون</option><option value='26'>25ميليون</option><option value='31'>30ميليون</option><option value='36'>35ميليون</option><option value='37'>40ميليون</option><option value='38'>45ميليون</option><option value='39'>50ميليون</option><option value='41'>60ميليون</option><option value='43'>70ميليون</option><option value='45'>80ميليون</option><option value='47'>90ميليون</option><option value='49'>100ميليون</option>"
    leasetext = "<option value=''></option>	<option value='1'>50تومان</option><option value='2'>100تومان</option><option value='3'>120تومان</option><option value='4'>140تومان</option><option value='5'>150تومان</option><option value='6'>170تومان</option><option value='7'>190تومان</option><option value='8'>200تومان</option><option value='9'>220تومان</option><option value='10'>240تومان</option><option value='11'>250تومان</option><option value='12'>300تومان</option><option value='13'>350تومان</option><option value='14'>400تومان</option><option value='15'>450تومان</option><option value='16'>500تومان</option><option value='17'>600تومان</option><option value='18'>700تومان</option><option value='19'>750تومان</option><option value='20'>800تومان</option><option value='21'>950تومان</option><option value='22'>900تومان</option><option value='23'>1ميليون</option><option value='24'>10ميليون</option><option value='25'>100ميليون</option>";
    minel = document.getElementById("mindiv");
    maxel = document.getElementById("maxdiv");
    if (el.value == 0) {
        document.getElementById("minprice").disabled = "disabled";
        document.getElementById("maxprice").disabled = "disabled";
    }
    else
        if (el.value == 2) {
        document.getElementById("mincap").innerHTML = "حداقل رهن";
        document.getElementById("maxcap").innerHTML = "حداکثر رهن";
        minel.innerHTML = premin + rahntext + post;
        maxel.innerHTML = premax + rahntext + post;
    }
    else
        if (el.value == 3) {
        document.getElementById("mincap").innerHTML = "حداقل اجاره";
        document.getElementById("maxcap").innerHTML = "حداکثر اجاره";
        minel.innerHTML = premin + leasetext + post;
        maxel.innerHTML = premax + leasetext + post;
    }
    else {
        document.getElementById("mincap").innerHTML = "حداقل قیمت";
        document.getElementById("maxcap").innerHTML = "حداکثر قیمت";
        minel.innerHTML = premin + pricetext + post;
        maxel.innerHTML = premax + pricetext + post;
    }


}
function WebForm_FireDefaultButton(event, target) {

    if (event.keyCode == 13) {
        search2()
    }

    return true;

}

function Removenums(s) {
    result = "";
    for (var i = 0; i < s.length - 8; i++)

        result += s.charAt(i);
    return result;
}
function getPriceStatment(p1, p2, pt) {
    if (p1 != "" && p2 == "")
        return " حداقل " + pt + p1;
    if (p1 == "" && p2 != "")
        return " حداکثر " + pt + p2;
    if (p1 != "" && p2 != "")
        return pt + p1 + " تا " + p2;
    return "";
}
function getMT(i) {
    if (i == "")
        return "";
    if (i == 0)
        return " متراژ  کمتر از 50 متر ";
    else
        if (i == 1)
        return " متراژ بين 50 تا 60 متر ";
    else
        if (i == 2)
        return " متراژ بين 60 تا 70 متر ";
    else
        if (i == 3)
        return " متراژ بين 70 تا 80 متر ";
    else
        if (i == 4)
        return " متراژ بين 80 تا 90 متر ";
    else
        if (i == 5)
        return " متراژ بين 90 تا 100 متر ";
    else
        if (i == 6)
        return " متراژ بين 100 تا 120 متر ";
    else
        if (i == 7)
        return " متراژ بين 120 تا 140 متر ";
    else
        if (i == 8)
        return " متراژ بين 140 تا 170 متر ";
    else
        if (i == 9)
        return " متراژ بين 170 تا 200 متر ";
    else
        if (i == 10)
        return " متراژ بيشتر از 200 متر ";
    return "";
}



function UpdateConditions() {
    if (document.forms[0].txtnum.value != "") {
        document.forms[0].txtConditions.value = "ملک با شماره: " + document.forms[0].txtnum.value;
        return;

    }
    arMstatus = ["", "رهن و اجاره", "خريد", "پيش خريد", "معاوضه"];
    Conditions = "";
    if (document.forms[0].ddest.value != "-1")
        Conditions += " " + "استان " + document.forms[0].ddest.options[document.forms[0].ddest.selectedIndex].text;
    if (document.forms[0].txtct.value != "")
        Conditions += " " + "شهر " + document.forms[0].txtct.value;
    sslvl = arMstatus[document.forms[0].ddslvl.value];
    smtp = document.forms[0].ddmtp[document.forms[0].ddmtp.selectedIndex].text;
    sSleep = "";
    if (document.forms[0].ddslp.value != "")
        sSleep = document.forms[0].ddslp.value + "خوابه ";
    if (document.forms[0].ddbld[document.forms[0].ddbld.selectedIndex].text != "")
        sSleep += document.forms[0].ddbld[document.forms[0].ddbld.selectedIndex].text;
    sSleep += getMT(document.forms[0].ddmt.value);
    if (smtp != "")
        ss = " نوع ملک " + smtp + sSleep;
    else
        ss = sSleep;
    if (document.forms[0].ddag.value == -10) {
        if (sslvl != "")
            Conditions += ss + " جهت " + sslvl;
        else
            Conditions += ss;
    }
    else
        if (document.forms[0].ddag.value == -20)
        Conditions += ss + " " + sslvl + " موردهاي بي واسطه ";
    else
        Conditions += ss + " " + " ملکهاي " + sslvl + document.forms[0].ddag.options[document.forms[0].ddag.selectedIndex].text;
    bNoRegionSelected = 1;
    if (document.forms[0].txtrgn.value != "") {
        Conditions += " محدوده " + document.forms[0].txtrgn.value;
        bNoRegionSelected = 0;
    }


    Conditions += getPriceStatment(document.forms[0].ddsprs1[document.forms[0].ddsprs1.selectedIndex].text, document.forms[0].ddsprs2[document.forms[0].ddsprs2.selectedIndex].text, " قيمت کل ");
    Conditions += getPriceStatment(document.forms[0].ddrn1[document.forms[0].ddrn1.selectedIndex].text, document.forms[0].ddrn2[document.forms[0].ddrn2.selectedIndex].text, " مبلغ رهن ");
    Conditions += getPriceStatment(document.forms[0].ddls1[document.forms[0].ddls1.selectedIndex].text, document.forms[0].ddls2[document.forms[0].ddls2.selectedIndex].text, " مبلغ اجاره ");

    document.forms[0].txtConditions.value = Conditions;

}


function SetComboEnabled() {

    el = document.forms[0].ddslvl;
    document.forms[0].ddrn1.disabled = "";
    document.forms[0].ddrn2.disabled = "";
    document.forms[0].ddls1.disabled = "";
    document.forms[0].ddls2.disabled = "";
    document.forms[0].ddsprs1.disabled = "";
    document.forms[0].ddsprs2.disabled = "";
    if (el.value == 1) {
        document.forms[0].ddsprs1.disabled = "disabled";
        document.forms[0].ddsprs2.disabled = "disabled";
    }
    else
        if (el.value == 2 || el.value == 3) {
        document.forms[0].ddrn1.disabled = "disabled";
        document.forms[0].ddrn2.disabled = "disabled";
        document.forms[0].ddls1.disabled = "disabled";
        document.forms[0].ddls2.disabled = "disabled";
    }
    UpdateConditions();
}
function EstateChange() {
    UpdateConditions();
    document.forms[0].txtct.value = "";
    document.forms[0].txtrgn.value = "";
}


function search() {
    var loc = ' ';
    var s = document.getElementById('ddest')[document.getElementById('ddest').selectedIndex].text;
    //        if (sEstate == 'undefined')
    //                sEstate = 'تهران';
    if (s != '')
        loc += 'استان ' + s + ' ';
    var c = document.getElementById('txtct').value;
    if (c != '')
        loc += 'شهر ' + c + ' ';
    var mtype = document.getElementById('ddmtp')[document.getElementById('ddmtp').selectedIndex].text;
    if (mtype == 'همه')
        mtype = '';
    var s = 'SearchResult.aspx?ag=' + document.getElementById('ddag').value +
                '&agnn=' + document.getElementById('ddag')[document.getElementById('ddag').selectedIndex].text +
                '&est=' + document.getElementById('ddest').value +
                '&ct=' + c +
                '&loc=' + loc +
                '&rgn1=' + document.getElementById('txtrgn').value +
                '&num=' + document.getElementById('txtnum').value +
                '&mtp=' + mtype +
                '&bld=' + document.getElementById('ddbld')[document.getElementById('ddbld').selectedIndex].text +
                '&slp=' + document.getElementById('ddslp')[document.getElementById('ddslp').selectedIndex].text +
                '&rhn1=' + document.getElementById('ddrn1')[document.getElementById('ddrn1').selectedIndex].text +
                '&rhn2=' + document.getElementById('ddrn2')[document.getElementById('ddrn2').selectedIndex].text +
                '&les1=' + document.getElementById('ddls1')[document.getElementById('ddls1').selectedIndex].text +
                '&les2=' + document.getElementById('ddls2')[document.getElementById('ddls2').selectedIndex].text +
                '&sprs1=' + document.getElementById('ddsprs1')[document.getElementById('ddsprs1').selectedIndex].text +
                '&sprs2=' + document.getElementById('ddsprs2')[document.getElementById('ddsprs2').selectedIndex].text +
                '&slvl=' + document.getElementById('ddslvl').value +
                '&mt=' + document.getElementById('ddmt').value +
                '&nslc=0';
    //s.replace('\n', ' ');  
    window.open(s, '', '', '');

}


function initjs() {
    document.forms[0].ddag.onchange = UpdateConditions;
    document.forms[0].ddslvl.onchange = SetComboEnabled;
    document.forms[0].ddest.onchange = EstateChange;
    document.forms[0].txtct.onchange = UpdateConditions;
    document.forms[0].ddmtp.onchange = UpdateConditions;
    document.forms[0].txtrgn.onchange = UpdateConditions;
    document.forms[0].ddbld.onchange = UpdateConditions;
    document.forms[0].ddslp.onchange = UpdateConditions;
    document.forms[0].ddrn1.onchange = UpdateConditions;
    document.forms[0].ddrn2.onchange = UpdateConditions;
    document.forms[0].ddls1.onchange = UpdateConditions;
    document.forms[0].ddls2.onchange = UpdateConditions;
    document.forms[0].ddsprs1.onchange = UpdateConditions;
    document.forms[0].ddsprs2.onchange = UpdateConditions;
    document.forms[0].txtnum.onchange = UpdateConditions;
    document.forms[0].ddmt.onchange = UpdateConditions;
}

//        function pageLoad() {
//                var autoComplete = $find('AutoCompleteEx');
//                if (!autoComplete) return;
//                var target = autoComplete.get_element();
//                if (!target) return;
//                var userContext = $get('ddest');
//                if (!userContext) return;
//                autoComplete.add_populating(function()
//                    {
//                        autoComplete.set_contextKey(userContext.value);
//                    });
//                    var autoComplete2 = $find('AutoCompleteExReg');
//                if (!autoComplete2) return;
//                var target2 = autoComplete.get_element();
//                if (!target2) return;
//                var userContext2 = $get('txtct');
//                if (!userContext2) return;
//                
//                autoComplete2.add_populating(function()
//                    {
//                        autoComplete2.set_contextKey(userContext2.value);
//                    });
//                }



//function checkMelliCode(varmellicode)
//{
//var meli_code;
//meli_code=varmellicode.value;
//if (meli_code.length == 10)
//{
//if(meli_code=='1111111111' || meli_code=='0000000000' || meli_code=='2222222222' || meli_code=='3333333333' || meli_code=='4444444444' ||
//meli_code=='5555555555' || meli_code=='6666666666' || meli_code=='7777777777' || meli_code=='8888888888' || meli_code=='9999999999' )
//{
//alert("کد ملی صحیح نمی باشد");
//objcode.focus();
//return false;
//}
//c = parseInt(meli_code.charAt(9));
//n = parseInt(meli_code.charAt(0))*10 +
//parseInt(meli_code.charAt(1))*9 +
//parseInt(meli_code.charAt(2))*8 +
//parseInt(meli_code.charAt(3))*7 +
//parseInt(meli_code.charAt(4))*6 +
//parseInt(meli_code.charAt(5))*5 +
//parseInt(meli_code.charAt(6))*4 +
//parseInt(meli_code.charAt(7))*3 +
//parseInt(meli_code.charAt(8))*2;
//r = n - parseInt(n/11)*11;
//if ((r == 0 && r == c) || (r == 1 && c == 1) || (r > 1 && c == 11 - r))
//{
//return true;
//}
//else
//{
//alert("کد ملی صحیح نمی باشد");
//objcode.focus();
//return true;
//}
//}
//else
//{
//return true;
//}
