﻿//HouseFun 新版首頁用 WebMax Code
//2011-11-14 By A+ Johnny Wu

var host = window.location.hostname.toLowerCase();
var pathname = window.location.pathname.toLowerCase();
var httpref = window.document.referrer;
var isShowInfo = false;
var reGuid = new RegExp('[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}');

if (getUrlVars()["webmax"] == "1") { isShowInfo = true; }

if (typeof (BuySearch) == 'undefined' || typeof (SellSearch) == 'undefined') {
    document.write("<scrip" + "t charset=\"big5\" src=\"" + (document.location.protocol == "https:" ? "https:" : "http:") + "//ecrmtr.housefun.com.tw/web_service/TrackingService/yc512_35eb327f2d.js\" type=\"text/javascript\"></" + "script>");
}

var chs = [{ 'chName': 'Unknown', 'WebID': 0, 'WebClassID': 0 }
         , { 'chName': 'YC_Buy', 'WebID': 1, 'WebClassID': 1 }
         , { 'chName': 'YC_Sell', 'WebID': 2, 'WebClassID': 1 }
         , { 'chName': 'HF_Buy', 'WebID': 3, 'WebClassID': 1 }
         , { 'chName': 'HF_Sell', 'WebID': 4, 'WebClassID': 1 }
         , { 'chName': 'Rent_Landlord', 'WebID': 5, 'WebClassID': 1 }
         , { 'chName': 'Rent_Tenant', 'WebID': 5, 'WebClassID': 2 }
         , { 'chName': 'Deco_Designer', 'WebID': 6, 'WebClassID': 1 }
         , { 'chName': 'Deco_Case', 'WebID': 6, 'WebClassID': 2 }
         , { 'chName': 'Deco_Reconstruct', 'WebID': 6, 'WebClassID': 3 }
         , { 'chName': 'Fix_MNFactory', 'WebID': 7, 'WebClassID': 1 }
         , { 'chName': 'Fix_Service', 'WebID': 7, 'WebClassID': 2 }
         , { 'chName': 'YC_Index', 'WebID': 8, 'WebClassID': 0 }
         , { 'chName': 'HF_Index', 'WebID': 9, 'WebClassID': 0 }
         , { 'chName': 'Mag', 'WebID': 21, 'WebClassID': 0 }
         , { 'chName': 'Other', 'WebID': 100, 'WebClassID': 0 }
        ];

var GetCh = function (chName) {
    for (var i = 1; i < chs.length; i++) {
        if (chs[i].chName.toLowerCase() == chName.toLowerCase()) { return (chs[i]); }
    }
    return (chs[0]);
}
//取得網址列所傳的參數
function getUrlVars() {
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for (var i = 0; i < hashes.length; i++) {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}
function GerRidOfString(s) {
    s = s.replace('縣　市', '').replace('行政區/捷運', '').replace('不限', '').replace('行政區', '').replace('類型', '').replace('街道、社區大樓、學校或關鍵字', '');
    return ($.trim(s));
}

/* Web Max Start */
$(function () {
    //買屋
    $('#SendSearchBuy').bind('click', function () {
        var ch = GetCh("HF_Buy");
        var city = GerRidOfString($('#hd_city').val());
        var area = GerRidOfString($('#hd_area').val());
        var pMin = '';
        var pMax = '';
        var purpose = '';
        if (isShowInfo) { alert('WebID:' + ch.WebID + '\nWebClassID:' + ch.WebClassID + '\n縣市：' + city + '\n區域：' + area + '\n預算Min：' + pMin + '\n預算Max：' + pMax + '\n用途：' + purpose); }
        if (ch.WebID == 0) { alert('Invalid WebID!'); return (false); }
        else { if (city != "" && area != "") { BuySearch2(ch.WebID, ch.WebClassID, city, area, '', '', pMin, pMax, purpose, 1); } }
        //return (true);
    });
    //租屋
    $('#SendSearchRent').bind('click', function () {
        var ch = GetCh("Rent_Tenant");
        var city = GerRidOfString($('#hd_city').val());
        var area = GerRidOfString($('#hd_area').val());
        var pMin = 0;
        var pMax = GerRidOfString($('select[id="ddlRentPrice"]').val());
        var MPurpose = GerRidOfString($('select[id="ddlRentType"]').val());
        if (isShowInfo) { alert('WebID:' + ch.WebID + '\nWebClassID:' + ch.WebClassID + '\n縣市：' + city + '\n區域：' + area + '\n預算Min：' + pMin + '\n預算Max：' + pMax + '\n用途：' + MPurpose); }
        if (ch.WebID == 0) { alert('Invalid WebID!'); return (false); }
        else { if (city != "" && area != "") { RentSearch2(ch.WebClassID, city, area, MPurpose, '', pMin, pMax, 1); } }
        //return (true);
    });
    //設計師
    $('#SendSearchDeco').bind('click', function () {
        var ch = GetCh("Deco_Case");
        var DecoStyle = GerRidOfString($('select[id="ddlDecoStyle"]').val());
        var DecoType = GerRidOfString($('select[id="ddlDecoType"]').val());
        var DecoPing = GerRidOfString($('select[id="ddlDecoPing"]').val());
        var DecoBudget = '';
        if (isShowInfo) { alert('WebID:' + ch.WebID + '\nWebClassID:' + ch.WebClassID + '\n裝潢風格：' + DecoStyle + '\n房屋型態：' + DecoType + '\n坪數：' + DecoPing + '\n預算：' + DecoBudget); }
        if (ch.WebID == 0) { alert('Invalid WebID!'); return (false); }
        else { DecoSearch2(ch.WebClassID, DecoStyle, DecoType, DecoPing, DecoBudget, 1); }
        //return (true);
    });
    //修繕廠商
    $('#SendSearchFix').bind('click', function () {
        var ch = GetCh("Fix_MNFactory");
        var city = GerRidOfString($('#hd_city').val());
        var area = GerRidOfString($('#hd_area').val());
        var SrvClass = GerRidOfString($('select[id="ddlFixType"]').val());
        if (isShowInfo) { alert('WebID:' + ch.WebID + '\nWebClassID:' + ch.WebClassID + '\n縣市：' + city + '\n區域：' + area + '\n類型：' + SrvClass); }
        if (ch.WebID == 0) { alert('Invalid WebID!'); return (false); }
        else { FixSearch2(ch.WebClassID, city, area, SrvClass, 1); }
        //return (true);
    });
});
/* Web Max End */
