﻿// JavaScript Document
/**
[www.dianyisheji.com] (C)2008-2009 Dianyi Design Ltd.
This is NOT a freeware, use is subject to license terms

Id: main.js 2009-07-23 16:12:20 wowotou
*/

/*
obj: selected projects
showStyle: The style of the selected projects
hiddenStyle: The project is not selected style
LObj: All items
MObj: More link's button id
MUrl: More link's href
*/
function showitem(obj, showStyle, hiddenStyle, LObj, MObj, MUrl) {

    if (obj) {
        if (document.getElementById('cityid'))
            document.getElementById('cityid').disabled = false;
        searchbustypedistext(0, 'keywords');
        if (document.getElementById('selectsub'))
            if (obj.id == "bus") {
            document.getElementById('selectsub').style.display = "";
        }
        else {
            document.getElementById('selectsub').style.display = "none";
        }
    }
    var TObj = obj.parentNode;
    if (LObj != "") var LObj = document.getElementById(LObj);
    if (MObj != "") {
        var MObj = document.getElementById(MObj);
        if (MObj.href) MObj.href = MUrl;
        if (MObj.action) {
            MObj.action = MUrl;
            //alert(MObj.action);
        }
    }

    for (var i = 0; i < TObj.childNodes.length; i++) {
        if (TObj.childNodes[i].nodeName !== "#text") {
            if (TObj.childNodes[i] == obj) {
                TObj.childNodes[i].className = showStyle;
                if (LObj != "") LObj.childNodes[i].style.display = "";
            } else {
                TObj.childNodes[i].className = hiddenStyle;
                if (LObj != "") LObj.childNodes[i].style.display = "none";
            }
        }
    }
}


function cleartext(obj) {
        obj.value = "";
}
function headkeywords(obj) {
    if (obj.value == '关键词') {
        obj.value = "";
    }
}

function searchbustypedistext(selectvalue, objid) {
    var obj = document.getElementById(objid);
    if (obj) {
        if (selectvalue == "3") {
            obj.disabled = true;
            window.location = 'bustwopoint.aspx';
        }
        else {
            obj.disabled = false;
        }
    }
}

/*

格式化金额
price:金额
zoom :金额的缩小倍数
*/
function price_format(price, zoom) {
    if (typeof (PRICE_FORMAT) == 'undefined') {
        //PRICE_FORMAT = '&yen;%s';
        PRICE_FORMAT = '￥%s';
    }
    if (zoom)
        price = price / zoom;
    price = number_format(price, 2);

    return PRICE_FORMAT.replace('%s', price);
}

function number_format(num, ext) {
    if (ext < 0) {
        return num;
    }
    num = Number(num);
    if (isNaN(num)) {
        num = 0;
    }
    var _str = num.toString();
    var _arr = _str.split('.');
    var _int = _arr[0];
    var _flt = _arr[1];
    if (_str.indexOf('.') == -1) {
        /* 找不到小数点，则添加 */
        if (ext == 0) {
            return _str;
        }
        var _tmp = '';
        for (var i = 0; i < ext; i++) {
            _tmp += '0';
        }
        _str = _str + '.' + _tmp;
    } else {
        if (_flt.length == ext) {
            return _str;
        }
        /* 找得到小数点，则截取 */
        if (_flt.length > ext) {
            _str = _str.substr(0, _str.length - (_flt.length - ext));
            if (ext == 0) {
                _str = _int;
            }
        } else {
            for (var i = 0; i < ext - _flt.length; i++) {
                _str += '0';
            }
        }
    }
    return _str;
}
function redkey(str, key) {
    if (str != null && str != '') {
        var reg = new RegExp('(' + key + ')', 'ig');
        str = str.replace(reg, '<font style="color:red;">$1</font>');
    } else {
        str = '';
    }
    return str;
}
