﻿/*function killErrors(){
return true;
}
window.onerror = killErrors;
*/
function $Obj(v) { return document.getElementById(v); }

function Trim(s) {
    var m = s.match(/^\s*(\S+(\s+\S+)*)\s*$/);
    return (m == null) ? "" : m[1];
}

function encode(str) {
    if (str == null) return '';

    //先做一次编码
    var retStr = escape(str);

    //处理url中所有的+号，该字符escape中不处理
    if (str.indexOf('+') != -1) {
        retStr = retStr.replace(/\+/g, '%2B');
    }

    //
    return retStr;
}

function GetObjects() {
    var ajax = false;
    /*@cc_on@*/
    /*@if (@_jscript_version >= 5)
    try {
        ajax = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e) {
        try {
            ajax = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (E) {
            try {
                ajax = new XMLHttpRequest();
            }
            catch (e) {
                ajax = false;
            }
        }
    }
    @end@*/

    if (!ajax && typeof XMLHttpRequest != 'undefined') {
        ajax = new XMLHttpRequest();
    }
    return ajax;
}
function numkeypress() {
    var key = event.keyCode;
    if (key < 48 || key > 57) {
        event.keyCode = 0;
    }
}
function resizeimg(ImgD, iwidth, iheight) {
    var image = new Image();
    image.src = ImgD.src;
    if (image.width > 0 && image.height > 0) {
        if (image.width / image.height >= iwidth / iheight) {
            if (image.width > iwidth) {
                ImgD.width = iwidth;
                ImgD.height = (image.height * iwidth) / image.width;
            }
            else {
                ImgD.width = image.width;
                ImgD.height = image.height;
            }
        }
        else {
            if (image.height > iheight) {
                ImgD.height = iheight;
                ImgD.width = (image.width * iheight) / image.height;
            }
            else {
                ImgD.width = image.width;
                ImgD.height = image.height;
            }
        }
    }
}

function ListByClick() {
    var parm = $Obj("ctl00_CPH_hidCatID").value;
    if (parm != "")
        parm = "?cat=" + parm;
    else
        parm = "?";
    var sort = $Obj("ctl00_CPH_ddlSort").value;
    var type = $Obj("ctl00_CPH_ddlType").value;
    if (type == "All") {
        parm = "?cat=1";
    }
    var lsort = "&sort=";
    if (parm == "?")
        lsort = "sort=";

    if (type == "1") {
        var SearchText = $Obj("ctl00_CPH_Navigator1_txtSearch").value;
        window.location.href = parm + lsort + sort + "&SearchText=" + SearchText;

    }
    else {
        if (type == "Home")
            window.location.href = "/" + parm + lsort + sort + "&type=" + type;
        else
            window.location.href = "/Category/" + parm.replace("?cat=", "") + "/ListBy_" + sort + ".html";
    }
}

function WishListAdd() {
    var v = $Obj('ctl00_CPH_Additional1_hidList').value;
    var ajax = GetObjects();
    var url = "/Common/XmlHttpRequest.aspx?type=WishListAdd&checkvalue=" + v;
    ajax.open("POST", url, false);
    ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
    ajax.send(v);

    var result = ajax.responseText;
    if (result == "go") {
        window.location.href = "/WishList/";
    }
    else {
        var str = result.split('|');
        $Obj("ctl00_CPH_hidListID").value = str[1];
        if (str[0] == "taken") {
            $Obj("spanmsg").innerHTML = "This item already exists in this list";
        }
        else if (str[0] == "failed") {
            window.location.href = "/Common/Message.aspx";
            return;
        }
        ShowWindow(350, 130, 'msgadded');
    }
}

function selectList(v, flag) {
    if (flag == "true") {
        $Obj("ctl00_CPH_Additional1_hidList").value = $Obj(v).value;
    }
    else {
        $Obj("ctl00_CPH_Additional1_hidList").value = $Obj("ctl00_CPH_Additional1_hidParam").value + $Obj(v).value;
    }
}
function plover(obj) {
    obj.style.backgroundImage = "url(/images/picbg_over.png)";
}
function plout(obj) {
    obj.style.backgroundImage = "url(/images/picbg.png)";
}