﻿//purchase hide



document.write("<style>.purchase #left table th p { display:none;} .defaultSalesman { display:none;}</style>");

//load func

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}
function addResizeEvent(func) {
    var oldonresize = window.onresize;
    if (typeof window.onresize != 'function') {
        window.onresize = func;
    } else {
        window.onresize = function() {
            if (oldonresize) {
                oldonresize();
            }
            func();
        }
    }
}

//control foot top
function getheight() {
    var foot = document.getElementById("foot");
    foot.style.display = 'block';
    //visibility = 'visible';
    var conheight = 0;
    var left = document.getElementById("left");
    var right = document.getElementById("right");
    if (!left || !right) {
        if (document.getElementById("offset")) {
            var offset = document.getElementById("offset");
            conheight = offset.scrollHeight;
        }
        else {
            foot.style.position = 'fixed';
            foot.style.bottom = '0';
            foot.style.marginBottom = '0';
            return true;
        }
    }

        if (conheight == 0) {
            var leftheight = left.clientHeight;
            var rightheight = right.clientHeight;
            conheight = left.clientHeight;
            if (leftheight < rightheight) {
                conheight = rightheight;
            }
            conheight += 157;
        }
        if (conheight + 65 < document.documentElement.clientHeight) {
            foot.style.marginTop = 'auto';
            foot.style.bottom = '0';
            //return true;
        }
        else {
            
            foot.style.marginTop = '';
            foot.style.bottom = '';
            foot.style.top = conheight + "px";
        }

        
        //	var left = document.getElementById("left");
        //	var right = document.getElementById("right");
        //	var foot = document.getElementById("foot");
        //	var leftheight = left.clientHeight;
        //	var rightheight = right.clientHeight;
        /*if (leftheight > rightheight) {
            foot.style.top = leftheight + 157 + "px";
        }
        else {
            foot.style.top = rightheight + 157 + "px";
        }*/
        if (parseInt(foot.style.top) + 65 < document.documentElement.offsetHeight) {
            foot.style.top = document.documentElement.offsetHeight - 65 + "px";
        }
        if (parseInt(foot.style.top) + 65 < window.innerHeight) {
            foot.style.top = window.innerHeight - 65 + "px";
        }

}

addLoadEvent(getheight);
addResizeEvent(getheight);

function gethost(url) {
    var urls = url.split("/");
    var hostname = urls[2];
    var host = "http://" + hostname + "/";
    return host;
}

function TrimEnd1(s, c) {
    if (s.length > 0 && s[s.length - 1] == c) {
        var tmp = s.substring(0, s.length - 1);
        return tmp;
    }
    return s;
}
///////////////////////////////////////////////////////
//扩展原型
String.prototype.trimStart=function(string)
{
    if (!string)
    {
        string="\\s+";
    }
    var trimStartPattern=new RegExp("^("+string+")+","g");
    return this.replace(trimStartPattern,"");
}
String.prototype.trimEnd=function(string)
{
    if (!string)
    {
        string="\\s+";
    }
    var trimEndPattern=new RegExp("("+string+")+$","g");
    return this.replace(trimEndPattern,"");
}
String.prototype.trim=function(string)
{
    return this.trimStart(string).trimEnd(string);
}
String.prototype.startsWith=function(string)
{
    if (!string)
    {
        string="\\s";
    }
    var startsWithPattern=new RegExp("^("+string+")","g");
    return startsWithPattern.test(this);
}
String.prototype.endsWith=function(string)
{
    if (!string)
    {
        string="\\s";
    }
    var endsWithPattern=new RegExp("("+string+")$","g");
    return endsWithPattern.test(this);
}
////////////////////////////////////////////////////////////

function newurl(url) {
    if (url.indexOf(".aspx") == -1)
        return url.trimEnd('/') + "/default.aspx";
    return url;
}

function newmenuurl(url) {
    var host = gethost(url);
    switch (url.toLowerCase()) {
        case host:
            return host + "default.aspx";
        default:
            return url;
    }
}

function newrighturl(url) {
    var host = gethost(url);
    switch (url.toLowerCase()) {
        case host:
            return host + "default.aspx";
        default:
            return newurl(url);
    }
}

//for common menu
function topmenuHover(menuobj) {
    var links = menuobj.getElementsByTagName("a");
    var url = newurl(window.location.href);
    for (i = 0; i < links.length; i++) {
        var link = newmenuurl(links[i].href);

        if (url.indexOf(link) != -1) {
            links[i].className = 'here';
        } else {
            links[i].className = '';
        }

        links[i].onmouseover = function () {
            for (j = 0; j < links.length; j++) {
                links[j].className = '';
            }
            this.className = 'here';
        }
        links[i].onmouseout = function () {
            for (j = 0; j < links.length; j++) {
                links[j].className = '';
                var linkj = newmenuurl(links[j].href);
                if (url.indexOf(linkj) != -1) {
                    links[j].className = 'here';
                }
            }
        }
    }
}
//this func only for some cate which have return menu
function rightmenuHover(menuobj) {
    var links = menuobj.getElementsByTagName("a");
    var url = newurl(window.location.href);
    for (i = 0; i < links.length; i++) {
        var link = newrighturl(links[i].href);
        if (url==link) {
            links[i].className = 'here';
        } else {
            links[i].className = '';
        }

        links[i].onmouseover = function () {
            for (j = 0; j < links.length; j++) {
                links[j].className = '';
            }
            this.className = 'here';
        }
        links[i].onmouseout = function () {
            for (j = 0; j < links.length; j++) {
                links[j].className = '';
                var linkj = newrighturl(links[j].href);
                if (url == linkj) {
                    links[j].className = 'here';
                }
            }
        }

    }
}

//top menu effect
function topmenu () {
	if(!document.getElementById("menu")) return false;
	var menuobj = document.getElementById("menu");
	topmenuHover(menuobj);
}

//right menu effect
function rightmenu () {
	if(!document.getElementById("right")) return false;
	var menuobj = document.getElementById("right");
	rightmenuHover(menuobj);
}

addLoadEvent(topmenu);
addLoadEvent(rightmenu);


//图片透明
function correctPNG(named) // correctly handle PNG transparency in Win IE 5.5 & 6.
{
    if (navigator.platform != "Win32" || navigator.appName != "Microsoft Internet Explorer")
        return;
    var arVersion = navigator.appVersion.split("MSIE")
    var version = parseFloat(arVersion[1])
    if ((version <= 6.0) && (document.body.filters)) {
        var img = document.images.namedItem(named)
        var imgName = img.src.toUpperCase()
        if (imgName.substring(imgName.length - 3, imgName.length) == "PNG") {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
             + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" + "margin:0;"
             + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
             + "(src=\'" + img.src + "\');\"></span>"
            img.outerHTML = strNewHTML
        }
    }
}


