﻿// 隐藏flash菜单 
function nb_flash(flashsrc,flashwidth,flashheight,flashlink,br){
	//document.write("<table width="+flashwidth+" height="+flashheight+" border=0 cellpadding=0 cellspacing=0><tr><td>");
	document.write("<div align=\"left\" style=\"width:"+flashwidth+"px;height:"+flashheight+"px;\">");
	document.write("<embed src="+flashsrc+" quality=\"high\" width="+flashwidth+" height="+flashheight+" TYPE=\"application/x-shockwave-flash\" PLUGINSPAGE=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" wmode=\"opaque\"></embed>");
//	document.write("<div style=\"background:white;filter:alpha(opacity=0);opacity:0;position: relative;z-index:10;left:0pt;top:0pt;width:"+flashwidth+";height:"+flashheight+"px;\">");
//	document.write("<a href="+flashlink+" target=\"_blank\" style=\"cursor:pointer;display:block;width:"+flashwidth+";height:"+flashheight+"px;\"></a>");
//	document.write("</div>");
	document.write("</div>");
	//document.write("</td></tr></table>");
	if (br=="1") {
	document.write("<br>");
	}
}
function nb_flash(flashsrc,flashwidth,flashheight,flashlink,adid,br){
    //flashlink = "/Transfer/ts.shtml?url="+flashlink.replace("?","$").replace("&","^").replace("=","#");
	//document.write("<table width="+flashwidth+" height="+flashheight+" border=0 cellpadding=0 cellspacing=0><tr><td>");
	document.write("<div align=\"left\" style=\"width:"+flashwidth+"px;height:"+flashheight+"px;\">");
	document.write("<embed src="+flashsrc+" quality=\"high\" width="+flashwidth+" height="+flashheight+" TYPE=\"application/x-shockwave-flash\" PLUGINSPAGE=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" wmode=\"opaque\"></embed>");
//	document.write("<div style=\"background:white;filter:alpha(opacity=0);opacity:0;position: relative;z-index:10;left:0pt;top:0pt;width:"+flashwidth+";height:"+flashheight+"px;\">");
//	document.write("<a href="+flashlink+" onclick=\"tongbu('"+adid+"')\" target=\"_blank\" style=\"cursor:pointer;display:block;width:"+flashwidth+";height:"+flashheight+"px;\"></a>");
//	document.write("</div>");
	document.write("</div>");
	//document.write("</td></tr></table>");
	if (br=="1") {
	document.write("<br>");
	}
}
// 创建并返回Ajax对象
function createNewXMLHttpRequest(){
    var xht = null; 
    if(window.ActiveXObject)
        xht = new ActiveXObject("Microsoft.xmlHttp");
    else if(window.XMLHttpRequest)
        xht = new XMLHttpRequest();
    return xht;
}
//创建并返回div
function createDiv(dvid,bgcolor,lft,tp,pos,wdth,hgt,zindex){
	var newdv = document.createElement("div");
	if(dvid!=""){
		newdv.id = dvid;
	}
	if(bgcolor!=""){
		newdv.style.backgroundColor=bgcolor;
	}
	if(lft!=""){
		newdv.style.left = lft;
	}
	if(tp!=""){
		newdv.style.top = tp;
	}
	if(pos!=""){
		newdv.style.position = pos;
	}
	if(wdth!=""){
		newdv.style.width = wdth;
	}
	if(hgt!=""){
		newdv.style.height = hgt;
	}
	if(zindex!=""){
		newdv.style.zIndex = zindex;
	}
	return newdv;
}
//Ajax调用get方式
function Ajax(method, url, params, loadingCallback, loadedCallback) {
    this.createHttpRequest = function() {
        if (window.XMLHttpRequest) {
            return (new XMLHttpRequest());
        }
        var arr_t = [
                'MSXML2.XMLHTTP.3.0',
                'MSXML2.XMLHTTP',
                'Microsoft.XMLHTTP'
            ];
        for (var i = 0; i < arr_t.length; i++) {
            try {
                xmlhttp_ver = arr_t[i];
                return new ActiveXObject(arr_t[i]);
            } catch (e) { }
        }
        return null;
    }
    this.url = url;
    this.params = params;
    this.loadingCallback = loadingCallback;
    this.loadedCallback = loadedCallback;
    this.method = (method == null ? "get" : method);
    this.xmlHttp = this.createHttpRequest();

    window.myAjax = this;
    this.doRequest = function() {
        var query = "";
        for (var param in this.params) {
            if (query != "") {
                query += "&";
            }
            query += param + "=" + this.params[param];
        }
        if (query != "") query += ("&N=" + Math.random());
        if (this.method == "post") {
            this.xmlHttp.open(this.method, this.url, true);
            this.xmlHttp.onreadystatechange = this.stateChanged;
            this.xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset=UTF-8');
            query = encodeURI(query);
            this.xmlHttp.send(query);
        }
        else {
            this.url += "?" + query;
            try {
                this.xmlHttp.open(this.method, this.url, true);
                this.xmlHttp.onreadystatechange = this.stateChanged;
            }
            catch (err) {}
            this.xmlHttp.send(null);
        }
    };
    this.stateChanged = function() {
        if (myAjax.xmlHttp.readyState == 4 && myAjax.xmlHttp.status == 200) {
            try{
                var data = myAjax.xmlHttp.responseText;
                myAjax.loadedCallback(data);
            }
            catch(ee) {}
        }
        else {
            try{
                myAjax.loadingCallback(myAjax.xmlHttp.readyState);
            }
            catch(ee) {}
        }
    };
}
//loading加载效果
function ajaxLoading(){
    if ($("imgAjaxLoading") != null || $("divAjaxLoading") != null )
        return;
    var imgUrl = "/VipProject/images/ajax-loader1.gif";
    var text = "Loading...";
    if (arguments.length > 0){
        imgUrl = arguments[0];
        text = arguments[1];
    }
    if (imgUrl != ""){
        var img = document.createElement("IMG");
        img.id="imgAjaxLoading";
        img.src=imgUrl;
        img.setAttribute("style","vertical-align:middle;");
        img.alt=img.title="Loading...";
    }
    var iWidth = 100;
    var iHeight = 30;
    var iTop = (document.documentElement.clientHeight-iHeight)/2 + "px";
    var iLeft = (document.documentElement.clientWidth-iWidth)/2 + "px";
    var div = document.createElement("DIV");
    div.id = "divAjaxLoading";
    div.style.cssText = "background: #FFF;border: 3px solid #4077ba;left:"+iLeft+";top:"+iTop+";width:"+iWidth+";height:"+iHeight+";position:fixed;z-index:9999;cursor:pointer;vertical-align:middle;";
    if (imgUrl != "")
        div.appendChild(img);
    var txt = document.createTextNode(text);
    div.appendChild(txt);
    document.body.appendChild(div);
}
function removeLoading(){
    if ($("divAjaxLoading") != null){
        if ($("imgAjaxLoading") != null)
            $("divAjaxLoading").removeChild($("imgAjaxLoading"));
        document.body.removeChild($("divAjaxLoading"));
    }
}
//快捷获取对象
//var obj=new Object();
//obj.g=function(){}; 
//等价于 
//obj={
// g:function(){}
//} 
function $(id){
    return document.getElementById(id);
}
function N$(name){
    return document.getElementsByName(name);
}
function tagN$(tagName){
    return document.getElementsByTagName(tagName);
}
//字符串去前后空格
String.prototype.Trim=function(){ 
    return this.replace(/(^\s*)|(\s*$)/g, '');
}
String.prototype.Url=function(){
    var url = this;
    if (this.indexOf("?") != -1)
        url = this.split("?")[0];
    return url;
}
String.prototype.Param=function(){
    var url = "";
    if (this.indexOf("?") != -1)
        url = this.split("?")[1];
    return url;
}
//字符出现次数
String.prototype.havN=function (){
    var c = "";
    if (arguments.length > 0)
        c = arguments[0];
    return this.split(c).length-1;
}
function   formatNum(num){//将数字转换成三位逗号分隔的样式
    if(!/^(\+|-)?(\d+)(\.\d+)?$/.test(num)){return num;}
    var a = RegExp.$1, b = RegExp.$2, c = RegExp.$3;
    var re = new RegExp().compile("(\\d)(\\d{3})(,|$)");
    while(re.test(b)){
        b = b.replace(re, "$1,$2$3");
    }
    return a +""+ b +""+ c;
}
//兼容ie和ff的Event获取
function getEvent(){
     //同时兼容ie和ff的写法
     if(document.all)    return window.event;
     func=getEvent.caller;
     while(func!=null){
         var arg0=func.arguments[0];
         if(arg0){
             if((arg0.constructor==Event || arg0.constructor ==MouseEvent)
                || (typeof(arg0)=="object"  &&  arg0.preventDefault  &&  arg0.stopPropagation)){
                return arg0;
              }
         }
          func=func.caller;
        }
        return null;
}
//获取事件的源节点
function getElementByEvent(){
    e = getEvent();
    return e.srcElement || e.target;
}
//获取Request参数,值
function Request(strName){
    var strHref = window.document.location.href;
    var intPos = strHref.indexOf("?");
    var strRight = strHref.substr(intPos + 1);

    var arrTmp = strRight.split("&");
    for(var i = 0; i < arrTmp.length; i++){
        var arrTemp = arrTmp[i].split("=");

        if(arrTemp[0].toUpperCase() == strName.toUpperCase()) return arrTemp[1];
    }
    return "";
}
//居中open窗口
function openwindow(url,name,iWidth,iHeight){
    var url;
    var name;
    var iWidth;
    var iHeight;
    var iTop = (window.screen.availHeight-30-iHeight)/2;
    var iLeft = (window.screen.availWidth-10-iWidth)/2;
    window.open(url,name,'height='+iHeight+',innerHeight='+iHeight+',width='+iWidth+',innerWidth='+iWidth+',top='+iTop+',left='+iLeft+',toolbar=no,menubar=no,scrollbars=auto,resizeable=no,location=no,status=no');
}
//
Array.prototype.have = function (){
    var isExist = false;
    if (arguments.length > 0)    {
        if (("#$@" + this.join("#$@").toLowerCase() + "#$@").indexOf("#$@"+arguments[0].toLowerCase()+"#$@") != -1)
            isExist = true;
        else
            isExist = false;
    }
    return isExist;
}
//脚本块注册方法参数是url,参数是脚本加载后要执行的方法.
function addScript(url, func){
    var _doc = document.getElementsByTagName('head')[0];
    var js = document.createElement('script');
    js.setAttribute('type', 'text/javascript');
    js.setAttribute('src', url); 
    _doc.appendChild(js);
    if (!/*@cc_on!@*/0){  //if not IE //Firefox2、Firefox3、Safari3.1+、Opera9.6+ support js.onload    
        js.onload = function(){
            if (func) 
                func();
        }
    }
    else //IE6、IE7 support js.onreadystatechange
    {
        js.onreadystatechange = function(){
            if (js.readyState == 'loaded' || js.readyState == 'complete') 
                if (func) 
                    func();
        }
    }
    return false;
}
//简单判断当前浏览器是否为IE
function isIE(){
    if (/*@cc_on!@*/0)
        return true;
    else
        return false;
}
//获取浏览器类型
function getOs() 
{
	var obj = "";
    if(navigator.userAgent.indexOf("MSIE 6.0")!=-1) { 
         return "IE6"; 
    } 
    if(navigator.userAgent.indexOf("MSIE 7.0")!=-1) { 
         return "IE7"; 
    } 
    if(navigator.userAgent.indexOf("MSIE 8.0")!=-1) { 
         return "IE8"; 
    } 
    if(navigator.userAgent.indexOf("Firefox")!=-1){ 
         return "Firefox"; 
    } 
    if(navigator.userAgent.indexOf("Safari")!=-1) { 
         return "Safari"; 
    } 
    if(navigator.userAgent.indexOf("Camino")!= -1){ 
         return "Camino"; 
    } 
    if(navigator.userAgent.indexOf("Gecko/")!=-1){ 
         return "Gecko"; 
    }
    if(navigator.userAgent.indexOf("Opera")!=-1){ 
         return "Opera"; 
    }   
} 
//DOM没有提供insertAfter()方法，所以我们只能自己写一个。
function insertAfter(newElement,targetElement){
  var parent = targetElement.parentNode;
  if (parent.lastChild == targetElement) 
//如果最后的节点是目标元素，则直接添加。因为默认是最后
    parent.appendChild(newElement);
  else
    parent.insertBefore(newElement,targetElement.nextSibling);
//如果不是，则插入在目标元素的下一个兄弟节点 的前面。也就是目标元素的后面。
}
function removeElement(_element){
         var _parentElement = _element.parentNode;
         if(_parentElement){
                _parentElement.removeChild(_element);
         }
}
String.prototype.isMobile = function() {  //是否是手机号码
   return (/^(?:13\d|15\d|18\d)-?\d{5}(\d{3}|\*{3})$/.test(this.Trim()));  
}
String.prototype.isTel = function(){//是否是电话号码
     //"兼容格式: 国家代码(2到3位)-区号(2到3位)-电话号码(7到8位)-分机号(3位)"
     //return (/^(([0\+]\d{2,3}-)?(0\d{2,3})-)?(\d{7,8})(-(\d{3,}))?$/.test(this.Trim()));
     return (/^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/.test(this.Trim()));
}
String.prototype.isEmail = function(){//是否是有效邮箱
     return (/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(this.Trim()));
}
function Exec(f){
    if (typeof f=="string")
        eval(f);
    else if (typeof f=="function")
        f();
}
function onLoadComplete(func){
    if (isIE()){
        try{
        document.onreadystatechange = function (){
            if (document.readyState=="complete")
                Exec(func);
        }}
        catch(e){}
    }
    else{
        window.onload = function (){
		    Exec(func);
        }
    }
}
function getElementPos(element) {  
    var ua = navigator.userAgent.toLowerCase(); 
    var isOpera = (ua.indexOf('opera') != -1); 
    var isIE = (ua.indexOf('msie') != -1 && !isOpera); // not opera spoof 
 
    var el = element; 
 
    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]}; 
}
String.prototype.getBytes = function() {
    var cArr = this.match(/[^\x00-\xff]/ig);
    return this.length + (cArr == null ? 0 : cArr.length);
}