﻿String.prototype.Trim  = function(){return this.replace(/^\s+|\s+$/g,"");}
String.prototype.Ltrim = function(){return this.replace(/^\s+/g, "");}
String.prototype.Rtrim = function(){return this.replace(/\s+$/g, "");}
String.prototype.ClearHTML = function(){return this.replace(/<[\s\S]*?>|&\S{4};?/g, "");}

function getElementLeft(obj){var x = 0;var elm = obj;while (elm != null){x+= elm.offsetLeft;elm = elm.offsetParent;}return parseInt(x);}
function getElementTop(obj){var y = 0;var elm = obj;while (elm != null){y+= elm.offsetTop;elm = elm.offsetParent;}return parseInt(y);}
function $(objName){return document.getElementById(objName);}

function GetXMLHttpReqObj()
{
    var xmlHttpReq;
    if (window.XMLHttpRequest)
    {// Mozilla, Safari, ...
        xmlHttpReq = new XMLHttpRequest();
    }
    else if (window.ActiveXObject)
    {// IE
        xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    return xmlHttpReq;
}

function search()
{
    var keywords = document.getElementById("txtKeywords").value;
    if(keywords.Trim()=="")
    {
        alert("关键字不可以为空！");
        return;
    }
    window.location.href = "Search.aspx?keywords="+escape(keywords);
    return false;
}
function keySearch(e)
{
    if(e.keyCode==13)
        return search();
}


function getTop(srcObj)
{
    var objDiv = document.createElement("DIV");
    var keyword = srcObj.innerHTML;
    var container = document.getElementById("popup");
    // Clear old
    while(container.childNodes.length>0)
        container.removeChild(container.childNodes[0]);
    // Add close button
    objDiv.className = "close";
    objDiv.onclick = function(){this.parentNode.style.display="none";};
    objDiv.innerHTML = "[关闭]";
    container.appendChild(objDiv);
    //Add Products
    objDiv = document.createElement("DIV");
    objDiv.className = "items";
    var items = srcObj.parentNode.parentNode.getElementsByTagName("DIV")[1].childNodes;
    for(var i=0;i<items.length;i++)
    {
        if(items[i].innerHTML.ClearHTML().indexOf(keyword)>-1)
            objDiv.innerHTML += "<div>"+items[i].innerHTML+"</div>";
    }
    container.appendChild(objDiv);
    // Set arrtibutes
    container.style.display = "block";
    container.style.top = getElementTop(srcObj) + 27 + "px";
    container.style.left = getElementLeft(srcObj.parentNode.parentNode) + "px";
}

function gotoPage(pgUrl)
{
    window.location.href = pgUrl;
}