﻿// JScript 文件

var root = window.location.hostname;
var globalHeight = window.screen.availHeight;
var globalWeight = window.screen.availWidth;

var aryRoot = new Array();
aryRoot[0] = "";
aryRoot[1] = "webHistory.aspx";
aryRoot[2] = "webProducts.aspx";
aryRoot[3] = "webHog.aspx";
aryRoot[4] = "webNews.aspx";
aryRoot[5] = "webMedias.aspx";
aryRoot[6] = "webContact.aspx";

var aryBannerImage = new Array();
aryBannerImage[0] = "Images/Banner/history1.gif";
aryBannerImage[1] = "Images/Banner/product1.gif";
aryBannerImage[2] = "Images/Banner/hog1.gif";
aryBannerImage[3] = "Images/Banner/news1.gif";
aryBannerImage[4] = "Images/Banner/medias1.gif";
aryBannerImage[5] = "Images/Banner/contactus1.gif";

var aryHistoryPage = new Array();
aryHistoryPage[0] = "webHistory_Page1.aspx";
aryHistoryPage[1] = "webHistory_Page2.aspx";
aryHistoryPage[2] = "webHistory_Page3.aspx";
aryHistoryPage[3] = "webHistory_Page4.aspx";
aryHistoryPage[4] = "webHistory_Page5.aspx";
//=========================================================================================================

function getObj(theObj, theDoc) {
    var p, i, foundObj;
    if (!theDoc) theDoc = document;
    if ((p = theObj.indexOf("?")) > 0 && parent.frames.length) {
        theDoc = parent.frames[theObj.substring(p + 1)].document;
        theObj = theObj.substring(0, p);
    }
    if (!(foundObj = theDoc[theObj]) && theDoc.all)
        foundObj = theDoc.all[theObj];
    for (i = 0; !foundObj && i < theDoc.forms.length; i++)
        foundObj = theDoc.forms[i][theObj];
    for (i = 0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++)
        foundObj = getObj(theObj, theDoc.layers[i].document);
    if (!foundObj && document.getElementById)
        foundObj = document.getElementById(theObj);
    return foundObj;
}

//=========================================================================================================
function divClear(obj, delSelf, parentObj) {
    if (obj.hasChildNodes) {
        while (obj.childNodes.length > 0) {
            obj.removeChild(obj.childNodes[0]);
        }
        if (delSelf) {
            parentObj.removeChild(obj);
        }
    }
}

//生成背景遮盖层，显示提示内容==========================================================================================
function CreateBackground(message) {
    var bgObj = document.createElement("div");
    bgObj.setAttribute('id', 'waitbgDiv');
    bgObj.style.position = "absolute";
    bgObj.style.top = "0";
    bgObj.style.left = "0";
    bgObj.style.background = "#666";
    bgObj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(Opacity=85, FinishOpacity=75, Style=0)";
    bgObj.style.opacity = "0.6";
    bgObj.style.width = "100%";
    bgObj.style.height = globalHeight - window.screenTop + "px";
    bgObj.style.zIndex = "1000";
    document.body.appendChild(bgObj);

    //	var waitObj = document.createElement("div");
    //	waitObj.setAttribute("id","waitmsgDiv");
    //	waitObj.setAttribute("align","center");
    //	waitObj.style.background = "white";
    //	waitObj.style.border="1px solid #ffcc33";
    //	waitObj.style.position = "absolute";
    //	waitObj.style.left = "50%";
    //	waitObj.style.top = "50%";
    //	waitObj.style.font="12px/1.6em Arial";
    //	waitObj.style.margin = "-150px 0px 0px -250px" ;
    //	waitObj.style.width = "500px";
    //	waitObj.style.height = "300px";
    //	waitObj.style.textAlign = "center";
    //	//waitObj.style.lineHeight = (g - titleheight) + "px";
    //	waitObj.style.zIndex = "10001";
    //			
    //	var span = document.createElement("span");
    //	span.style.position = "absolute";
    //	span.style.top =  "20px";
    //	span.style.left = "30px";
    //	span.style.scrolling = "yes";
    //	span.innerHTML = message;
    //	
    //	var img = document.createElement("img");
    //	img.style.position = "absolute";
    //	img.style.top =  "20px";
    //	img.style.left = "10px";
    //	img.src = "images/close.gif";
    //	img.align = "absMiddle";
    //	img.onclick = function()
    //	{
    //	    divClear(document.getElementById("waitbgDiv"),true,document.body);
    //	}
    //	
    //	waitObj.appendChild(img);		
    //	waitObj.appendChild(span);
    //	bgObj.appendChild(waitObj);
}
//==============================================================================================================================
function getURLParams(strname) {
    var hrefstr, pos, parastr, para, tempstr;
    hrefstr = window.location.href;
    pos = hrefstr.indexOf("?")
    parastr = hrefstr.substring(pos + 1);
    para = parastr.split("&");
    tempstr = "";

    for (i = 0; i < para.length; i++) {
        tempstr = para[i];
        pos = tempstr.indexOf("=");
        if (tempstr.substring(0, pos) == strname) {
            return tempstr.substring(pos + 1);
        }
    }
    return null;
}
//获取制定元素编号的x,y像素=====================================================================================================
function getElementPos(elementId) {
    var ua = navigator.userAgent.toLowerCase();
    var isOpera = (ua.indexOf('opera') != -1);
    var isIE = (ua.indexOf('msie') != -1 && !isOpera); // not opera spoof
    var el = document.getElementById(elementId);
    if (el.parentNode === null || el.style.display == 'none') {
        return false;
    }

    var parent = null;
    var pos = [];
    var box;
    if (el.getBoundingClientRect)    //IE
    {
        box = el.getBoundingClientRect();
        var scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
        var scrollLeft = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
        return { x: box.left + scrollLeft, y: box.top + scrollTop };
    }
    else if (document.getBoxObjectFor)    // gecko    
    {
        box = document.getBoxObjectFor(el);
        var borderLeft = (el.style.borderLeftWidth) ? parseInt(el.style.borderLeftWidth) : 0;
        var borderTop = (el.style.borderTopWidth) ? parseInt(el.style.borderTopWidth) : 0;
        pos = [box.x - borderLeft, box.y - borderTop];
    }
    else    // safari & opera    
    {
        pos = [el.offsetLeft, el.offsetTop];
        parent = el.offsetParent;
        if (parent != el) {
            while (parent) {
                pos[0] += parent.offsetLeft;
                pos[1] += parent.offsetTop;
                parent = parent.offsetParent;
            }
        }
        if (ua.indexOf('opera') != -1 || (ua.indexOf('safari') != -1 && el.style.position == 'absolute')) {
            pos[0] -= document.body.offsetLeft;
            pos[1] -= document.body.offsetTop;
        }
    }
    if (el.parentNode) {
        parent = el.parentNode;
    }
    else {
        parent = null;
    }
    while (parent && parent.tagName != 'BODY' && parent.tagName != 'HTML') { // account for any scrolled ancestors
        pos[0] -= parent.scrollLeft;
        pos[1] -= parent.scrollTop;
        if (parent.parentNode) {
            parent = parent.parentNode;
        }
        else {
            parent = null;
        }
    }
    return { x: pos[0], y: pos[1] };
}
//定义鼠标移进滑出事件=====================================================================================================
var cr = "";
function _Over(obj) {
    cr = obj.style.backgroundColor;
    obj.style.background = "#e0e0e0";
    obj.style.cursor = "hand";
}

function _Out(obj) {
    obj.style.background = cr;
    //obj.style.padding = "";
    //obj.style.margin = "";
}
//自定义window.alert事件=====================================================================================================
//window.alert = function(txt)
function CustomAlert(txt) {
    var shield = document.createElement("DIV");
    shield.id = "shield";
    shield.style.position = "absolute";
    shield.style.left = "0px";
    shield.style.top = "0px";
    shield.style.width = "100%";
    shield.style.height = "100%";
//    shield.style.height = document.body.scrollHeight+"px"; 
    shield.style.background = "#000";
    shield.style.textAlign = "center";
    shield.style.zIndex = "10000";
    shield.style.filter = "alpha(opacity=0)";
    var alertFram = document.createElement("DIV");
    alertFram.id = "alertFram";
    alertFram.style.position = "absolute";
    //负边界居中法,相对于shield层的顶部时 

    //alertFram.style.left = "50%"; 
    //alertFram.style.top = "50%"; 
    //alertFram.style.marginLeft = "-125px"; 
    //alertFram.style.marginTop = "-75px"; 

    //负边界居中法,相对于shield层的底部时 
    alertFram.style.right = "50%";
    alertFram.style.bottom = "50%";
    alertFram.style.marginRight = "-125px";
    alertFram.style.marginBottom = "-75px";

    alertFram.style.width = "250px";
    alertFram.style.height = "150px";
    alertFram.style.background = "#000";
    alertFram.style.textAlign = "center";
    alertFram.style.lineHeight = "150px";
    alertFram.style.zIndex = "10002";
    strHtml = "<ul style=\"list-style:none;margin:0px;padding:0px;width:100%\">\n";
    strHtml += "<li onmousedown=\"oMove(parentNode.parentNode);\" title=\"移動\" style=\"cursor:move;background:#002F9C;text-align:left;padding-left:5px;font-size:14px;font-weight:bold;color: #FFFFFF;height:25px;line-height:25px;border-left:1px solid #FFFFFF;border-top:1px solid #FFFFFF;border-right:1px solid #FFFFFF;\">[提示……]</li>\n";
    strHtml += "<li style=\"background:#5A7EDC;text-align:center;font-size:12px;color: #FFFFFF;height:120px;line-height:120px;border-left:1px solid #FFFFFF;border-right:1px solid #FFFFFF;\">" + txt + "</li>\n";
    strHtml += "<li style=\"background:#002F9C;text-align:center;font-weight:bold;height:25px;line-height:25px; border-left:1px solid #FFFFFF;border-bottom:1px solid #FFFFFF;border-right:1px solid #FFFFFF;\"><input type=button value=' 确定 ' onclick=\"remove()\"></li>\n";
    strHtml += "</ul>\n";
    alertFram.innerHTML = strHtml;
    document.body.appendChild(alertFram);
    document.body.appendChild(shield);

    var c = 0;
    this.doAlpha = function() {
        if (c++ > 50) { clearInterval(ad); return 0; }
        shield.style.filter = "alpha(opacity=" + c + ");";
    }
    this.remove = function() {
        alertFram.innerHTML = "";
        shield.style.filter = "";
        shield.id = "";
        shield.style.position = "";
        shield.style.left = "";
        shield.style.top = "";
        shield.style.width = "";
        shield.style.height = "";
        shield.style.background = "";
        shield.style.textAlign = "";
        shield.style.zIndex = "";
        shield.style.filter = "";
        alertFram.id = "";
        alertFram.style.position = "";
        alertFram.style.left = "";
        alertFram.style.top = "";
        alertFram.style.marginLeft = "";
        alertFram.style.marginTop = "";
        alertFram.style.width = "";
        alertFram.style.height = "";
        alertFram.style.background = "";
        alertFram.style.textAlign = "";
        alertFram.style.lineHeight = "";
        alertFram.style.zIndex = "";
    }
    var ad = setInterval("doAlpha()", 10);
    alertFram.focus();
    document.body.onselectstart = function() { return false; };
}

function oMove(obj) {
    var otop, oleft;
    otop = event.y - obj.offsetTop;
    oleft = event.x - obj.offsetLeft;
    obj.setCapture();
    obj.onmousemove = function() {
        obj.style.left = event.x - oleft;
        obj.style.top = event.y - otop;
    }
    obj.onmouseup = function() {
        obj.onmousemove = null;
        obj.style.filter = null;
        obj.releaseCapture();
    }
}

//Format String==============================================================================
String.prototype.replaceAll = function(s1, s2) {
    return this.replace(new RegExp(s1, "gm"), s2);
}

function EncodeString(tmpString) {
    //string tmpString = "";
    tmpString = tmpString.replaceAll("&", "&amp;");
    tmpString = tmpString.replaceAll("\"", "&quot;");
    tmpString = tmpString.replaceAll("<", "&lt;");
    tmpString = tmpString.replaceAll(">", "&gt;");
    tmpString = tmpString.replaceAll("   ", "&nbsp;");
    tmpString = tmpString.replaceAll("     ", "&nbsp;&nbsp;");
    tmpString = tmpString.replaceAll("\t", "&nbsp;&nbsp;");
    tmpString = tmpString.replaceAll("\r", "<br/>");
    tmpString = tmpString.replaceAll("'", "＇");
    return tmpString;
}

function DecodeString(tmpString) {
    tmpString = tmpString.replaceAll("&amp;", "&");
    tmpString = tmpString.replaceAll("&quot;", "\"");
    tmpString = tmpString.replaceAll("&lt;", "<");
    tmpString = tmpString.replaceAll("&gt;", ">");
    tmpString = tmpString.replaceAll("&nbsp;", "   ");
    tmpString = tmpString.replaceAll("&nbsp;&nbsp;", "     ");
    tmpString = tmpString.replaceAll("&nbsp;&nbsp;", "\t");
    tmpString = tmpString.replaceAll("<br/>", "\r");
    tmpString = tmpString.replaceAll("＇", "'");

    return tmpString
}
//设置select中text="paraText"的第一个Item为选中 ===============================================================
function jsSelectItemByValue(objSelect, objItemText) {
    for (var i = 0; i < objSelect.options.length; i++) {
        if (objSelect.options[i].text == objItemText) {
            objSelect.options[i].selected = true;
            isExit = true;
            break;
        }
    }
}
//popup iFrame include pages==========================================================================================================
function popupIFrame(url, w, h) {
    var b = navigator.appVersion.indexOf('MSIE 7.0') > 0;

    var bgDiv = document.createElement("div");
    bgDiv.id = "bgDiv";
    bgDiv.style.position = "absolute";
    bgDiv.style.left = "0px";
    bgDiv.style.top = "0px";
    bgDiv.style.width = "100%";
    bgDiv.style.height = (b) ? "100%" : document.body.scrollHeight;
    bgDiv.style.background = "#000";
    bgDiv.style.textAlign = "center";
    bgDiv.style.zIndex = "100000";
    bgDiv.style.filter = "alpha(opacity=90)";
    bgDiv.style.margin = "0px";

    document.body.appendChild(bgDiv);

    var iframe = document.createElement("IFRAME");
    iframe.style.position = "absolute";
    iframe.style.zIndex = "100012";
    iframe.id = "iframe";
    iframe.style.overflow = "hidden";
    iframe.style.width = w + "px";
    iframe.style.height = h + "px";


    iframe.setAttribute("frameBorder", 0);

    iframe.src = url;
    iframe.style.left = "50%";
    iframe.style.top = "50%";
    iframe.style.marginLeft = -w / 2 + "px";
    iframe.style.marginTop = -h / 2 + "px";

    //负边界居中法,相对于shield层的底部时
    iframe.style.right = "50%";
    iframe.style.bottom = "50%";
    iframe.style.marginRight = -w / 2 + "px";
    iframe.style.marginBottom = -h / 2 + "px";

    document.body.appendChild(iframe);

    var closeSpan = document.createElement("div");
    closeSpan.id = "closeSpan";
    closeSpan.style.cursor = "hand";
    closeSpan.style.position = "absolute";
    closeSpan.style.borderTop = "solid 1px #696969";
    closeSpan.style.width = (w - 15) + "px";
    closeSpan.style.height = "30px";
    closeSpan.style.textAlign = "right";
    closeSpan.style.lineHeight = "30px";
    closeSpan.style.paddingRight = "15px";
    closeSpan.style.backgroundColor = "#e0e0e0";

    closeSpan.style.left = "50%";
    closeSpan.style.top = iframe.offsetTop + h + "px";
    closeSpan.style.marginLeft = -w / 2 + "px";
    closeSpan.style.right = "50%";
    closeSpan.style.marginRight = -w / 2 + "px";


    closeSpan.innerText = "关闭窗口";
    closeSpan.style.zIndex = "100012";
    closeSpan.onclick = function() {
        var o4 = document.getElementById("closeSpan");
        var o3 = document.getElementById("iframe");
        var o1 = document.getElementById("bgDiv");
        document.body.removeChild(o4);
        document.body.removeChild(o3);
        document.body.removeChild(o1);
    }

    closeSpan.onmouseover = function() {
        this.style.color = "#ff6600";
        this.style.backgroundColor = "#f2f2f2";
    }

    closeSpan.onmouseout = function() {
        this.style.color = "#000";
        this.style.backgroundColor = "#e0e0e0";
    }

    document.body.appendChild(closeSpan);
}
