﻿// JavaScript Document
<!--
var __is_ie__ = (document.all ? true:false);
if (!__is_ie__){
    HTMLElement.prototype.insertAdjacentHTML=function(where, html)
    {
        var e = this.ownerDocument.createRange();
        e.setStartBefore(this);
        e = e.createContextualFragment(html);
        switch (where)
        {
            case 'beforeBegin':
                this.parentNode.insertBefore(e, this);
                break;
            case 'afterBegin':
                this.insertBefore(e, this.firstChild);
                break;
            case 'beforeEnd':
                this.appendChild(e);
                break;
            case 'afterEnd': 
                if(!this.nextSibling)
                    this.parentNode.appendChild(e);
                else
                    this.parentNode.insertBefore(e, this.nextSibling);
                break;
        }
    }
}
BrowserType =
{
    MSIE    : "Microsoft Internet Explorer",
    Gecko   : "Gecko",
    Opera   : "Opera",
    Safari  : "Safari",
    Unknown : "Unknown"
};

//-------------------------------------------------------------------------
// Function Name    :GetBrowserType
// Memo             :Get the visitor's browser type
//-------------------------------------------------------------------------
function GetBrowserType()
{
    if( navigator.userAgent.indexOf(BrowserType.Opera) >= 0 )
        return BrowserType.Opera;
        
    if( navigator.appName == BrowserType.MSIE )
        return BrowserType.MSIE;
        
    if( navigator.userAgent.indexOf(BrowserType.Gecko) >= 0 ||
        navigator.userAgent.indexOf("Netscape") >= 0 )
    {
        return BrowserType.Gecko;
    }
    
    if( navigator.userAgent.indexOf(BrowserType.Safari) >= 0 )
        return BrowserType.Safari;
        
    alert("Error: Unknown browser type.");
    return null;
}

function getWindowRect(win){
    var rect = {
            width:      0,
            height:     0,
            scrollTop:  0,
            scrollLeft: 0
            }
    var doc = win.document;
    if (win.innerHeight){ //firefox
        rect.width  = win.innerWidth;
        rect.height = win.innerHeight;
    }else if (doc.documentElement && doc.documentElement.clientHeight){ //other
        if (document.body){
            rect.width  = Math.min(doc.documentElement.clientWidth, doc.body.clientWidth);
            rect.height = Math.min(doc.documentElement.clientHeight,doc.body.clientHeight);
        }else{
            rect.width  = doc.documentElement.clientWidth;
            rect.height = doc.documentElement.clientHeight;
        }
    }else if (document.body){ //ie
        rect.width  = doc.body.clientWidth;
        rect.height = doc.body.clientHeight;
    }
    rect.scrollTop  = Math.max(doc.documentElement.scrollTop, doc.body.scrollTop);
    rect.scrollLeft = Math.max(doc.documentElement.scrollLeft,doc.body.scrollLeft);
    return rect;
}

var __popup__ = {
    handle      : null,
    background  : null,
    offsetX     : 0,
    offsetY     : 0,
    zIndex      : 100
}
function openWindow(url, modal, width, height){
    if (url == null || url == '') return;
    
    var modal   = modal  || false;
    var width   = width  || 640;
    var height  = height || 480;
    var doc     = top.document;
    var pop     = top.__popup__;
    var rect    = getWindowRect(top);

    var cw      = rect.width;
    var ch      = rect.height;
    var st      = rect.scrollTop;
    var sl      = rect.scrollLeft;

    //create background
    if (!pop.background){
        var div = doc.createElement('DIV');
        div.className     = 'Popup-Background'
        div.style.display = 'none';
        div.oncontextmenu = function(){return false;}
        div.onselectstart = function(){return false;}
        doc.body.appendChild(div);
        pop.background = div;
    }
    
    //initial popup
    if (modal){
        var div = pop.background;
        div.style.width    = (cw + sl) + 'px';
        div.style.height   = (ch + st) + 'px';
        div.style.zIndex   = ++pop.zIndex;
        div.style.display  = '';
    }
    
    //create popup
    var table = doc.createElement('TABLE');
    table.setAttribute('modal', modal.toString());
    table.style.width     = width+'px';
    table.style.height    = height+'px';
    table.style.top       = ((ch - height)/2 + st) + 'px';
    table.style.left      = ((cw - width)/2 + sl) + 'px';
    table.style.zIndex    = ++pop.zIndex;
    table.className       = 'Popup';
    table.oncontextmenu   = function(){return false;}
    table.onselectstart   = function(){return false;}
    
    //tbody
    var tbody = doc.createElement('TBODY');
    var row   = doc.createElement('TR');
    var cell  = doc.createElement('TD');
    cell.className   = 'Title';
    cell.setAttribute('identifier','movebar');
    cell.innerHTML  = '漫狐网络 - 页面读取中...';
    row.appendChild(cell);
    
    //close button
    var cell = doc.createElement('TD');
    cell.className  = 'Close'; 
    var link = doc.createElement('A');
    link.href       = 'javascript:void(0);';
    link.title      = '关闭窗口';
    link.innerHTML  = '<img src="../res/icon/16/074.gif" identifier="closebar" />';
    cell.appendChild(link);
    row.appendChild(cell);
    tbody.appendChild(row);

    //body content
    var row  = doc.createElement('TR');
    var cell = doc.createElement('TD');
    cell.className  = 'Body';
    cell.colSpan    = 2;
    cell.innerHTML  = '<iframe width="100%" height="100%" frameborder="no" scrolling="no" src="'+url+'"'+
                      ' onload="var e=this;while(e.tagName!=\'TABLE\')e=e.parentNode;e.rows[0].cells[0].innerHTML=\'漫狐网络 - \'+this.contentWindow.document.title;"></iframe>'+
                      '<img style="display:none;" src="../res/image/popup/body.loading.gif" />';
    row.appendChild(cell);
    tbody.appendChild(row);
    table.appendChild(tbody);
    doc.body.appendChild(table);
}

var __unique_id__ = null;
function closeWindow(){
    if (!__unique_id__)
        __unique_id__ = generateMixed(30);
    var doc  = top.document;
    var pop  = top.__popup__;
    var objs = doc.getElementsByTagName('IFRAME');
    for (var i = 0; i< objs.length; i++){
        var obj = objs[i].contentWindow;
        if (obj.__unique_id__ &&
            obj.__unique_id__ == __unique_id__){
            var e = objs[i].parentNode;
            while (e.tagName != 'TABLE') e = e.parentNode;
            doc.body.removeChild(e);
            if (pop.background)
                pop.background.style.display = 'none';
            break;
        }
    }
}

function popup_initialize(){
    if (self != top)
        return;
    //attach event mousemove to document
    document.onmousemove = function(evt){
        if (__popup__.handle){
            if (!evt) evt = event;
            var e = __popup__.handle;
            var x = evt.clientX - __popup__.offsetX;
            var y = evt.clientY - __popup__.offsetY;
            e.style.left = x + 'px';
            e.style.top  = y + 'px';
        }
    }
    //attach event mousedown to document
    document.onmousedown = function(evt){
        if (!evt) evt = event;
        var e = (__is_ie__ ? evt.srcElement : evt.target);
        switch (e.getAttribute('identifier')){
            case 'movebar':
                while (e.tagName != 'TABLE') e = e.parentNode;
                if (e.getAttribute('modal') == 'false'){
                    var _cw = parseInt(document.body.clientWidth, 10);
                    var _ch = parseInt(document.body.clientHeight, 10);
                    var _st = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
                    var _sl = Math.max(document.documentElement.scrollLeft,document.body.scrollLeft);
                    var div = __popup__.background;
                    div.style.width     = (_cw + _sl) + 'px';
                    div.style.height    = (_ch + _st) + 'px';
                    div.style.zIndex    = ++__popup__.zIndex;
                    div.style.display   = '';
                    e.style.zIndex      = ++__popup__.zIndex;
                }
                var p = e.rows[1].cells[0];
                p.childNodes[0].style.display = 'none';
                p.childNodes[1].style.display = '';
                var pos = getElementPos(e);
                __popup__.offsetX = parseInt(evt.clientX, 10) - pos.x;
                __popup__.offsetY = parseInt(evt.clientY, 10) - pos.y;
                __popup__.handle  = e;
                break;
           case 'closebar':
                while (e.tagName != 'TABLE') e = e.parentNode;
                __popup__.handle = null;
                document.body.removeChild(e);
                if (__popup__.background)
                    __popup__.background.style.display = 'none';
                break;
        }
    }
    //attach event mouseup to document
    document.onmouseup = function(){
        if (__popup__.handle){
            var e = __popup__.handle.rows[1].cells[0];
            e.childNodes[1].style.display = 'none';
            e.childNodes[0].style.display = '';
            if (__popup__.handle.getAttribute('modal') == 'false')
                __popup__.background.style.display = 'none';
            __popup__.handle = null;
        }
    }
}
popup_initialize();

function setFocusOn(){
    var objs = document.getElementsByTagName('INPUT');
    var patten = 'text|file|password'
    for (var i = 0; i < objs.length; i++){
        var type = objs[i].type.toLowerCase();
        if (patten.indexOf(type) != -1){
            objs[i].focus();
            return;
        }
    }
    var objs = document.getElementsByTagName('TEXTAREA');
    for (var i = 0; i < objs.length; i++){
        objs[i].focus();
        return;
    }
}


function __frame(targets){
    var frame = top;
    for (var i = 0; i < targets.length; i++){
        var obj = frame.document.getElementById(targets[i]);
        if (obj)
            frame = obj.contentWindow;
    }
    return frame;
}
function getFrameRight(){return __frame(new Array('CONTENT','RIGHT'));}
function getFrameLeft(){return __frame(new Array('CONTENT','LEFT'));}
function refreshRight(){getFrameRight().location.reload(true);}
function refreshLeft(){getFrameLeft().location.reload(true);}


function copyUrl(head, url){
	var content = head + '\r\n' + url;
	if (window.clipboardData){
	    // use thye clipboard in IE
	    window.clipboardData.setData("Text",content);
	    alert('按 CTRL+V，粘贴到 QQ 或 MSN 上发给好友吧 *^___^* ');
	}else{
	    alert('错误信息\n\n* 客户端非IE内核浏览器，不支持粘贴板功能\n* 请在本页内单击右键->本桢->查看桢信息->复制本页地址发送到 QQ 或 MSN 好友');
	}
}

function openFullWindow(url){
	var inf =   'left=0,'+
	            'top=0,'+
	            'resizable=yes,'+
                'height='+(screen.availHeight-20)+','+
	            'width='+screen.availWidth;
	//var inf =	'scrollbars=yes,'+
	//			'fullscreen=yes';
	var e = window.open(url,'_blank',inf);
	e.moveTo(-4,-4);
}

function dateSelection(textbox, displayTime, center){
    if (!__is_ie__)
        return;
	var fearures	= null;
	var height		= 250;
	var width		= 212;
	if (center == true){ 
		fearures =  'dialogHeight:'+height+'px;'+
					'dialogWidth:' +width+'px;'+
					'help: no;' +
					'status: no;'
	}else{
		var x = event.screenX;
		var y = event.screenY;
		if (x >= parseInt(screen.availWidth - width)) x -= width;
		if (y >= parseInt(screen.availHeight - height)) y -= height;
		fearures =  'dialogHeight:'+height+'px;'+
					'dialogWidth:'+width+'px;'+
					'dialogLeft:'+x+'px;'+
					'dialogTop:'+y+'px;'+
					'center: no;'+
					'help: no;'+
					'status: no;'
	}
	if (displayTime == true){
		window.showModalDialog('../Res/include/getdatetime.htm',textbox,fearures);
	}else{
		window.showModalDialog('../Res/include/getdate.htm',textbox,fearures);
	}
}

String.prototype.trim	= function(){return this.replace(/^\s+|\s+$/,'');}
String.prototype.ltrim	= function(){return this.replace(/^\s+/,'');}
String.prototype.rtrim	= function(){return this.replace(/\s+$/,'');}
String.prototype.merge  = function(){return this.replace(/[\n\f\t\r]+/gim,'\n').replace(/\s+/gim,' ');}
String.prototype.byteLength = function (){
	var result	= 0;
	var count	= this.length;
	for(var i = 0; i < count; i++){
		// Ascii码大于255是双字节的字符
		if  (this.charCodeAt(i) > 255)
		    result += 2;
		else
		    result += 1;
	}
	return result;
}

String.prototype.toHtml = function (){
	var result = this.toString();
	result = result.replace(/&/g,	'&amp;');
	result = result.replace(/</g,	'&lt;');
	result = result.replace(/>/g,	'&gt;');
	result = result.replace(/\"/g,	'&quot;');
	result = result.replace(/ /g,	'&nbsp;');
	result = result.replace(/\n/g,	'<br/>');
	return result;
}

String.prototype.toText = function (){
	var result = this.toString();
	result = result.replace(/&lt;/g,	'<');
	result = result.replace(/&gt;/g,	'>');
	result = result.replace(/&quot;/g,	'"');
	result = result.replace(/&nbsp;/g,	' ');
	result = result.replace(/&amp;/g,	'&');
	result = result.replace(/<br(?:\s*)\/?>/g,	'\n');
	return result;
}

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){         
        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){
        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{
        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'){
        pos[0] -= parent.scrollLeft;
        pos[1] -= parent.scrollTop;
        if (parent.parentNode) {
            parent = parent.parentNode;
        }else{
            parent = null;
        }
    }
    return {x:pos[0], y:pos[1]};
}

//对数据进行标准格式化(0.00格式)
function getNumberToCurrency(iv){
//对数据进行标准格式化(0.00格式)
	iv = iv.toString();
	if(iv=="" || iv==null) return "0.00";
	iv = iv.toString();
	var vPos=iv.indexOf(".");
	if((vPos>-1) && (iv.length -vPos -1)>2){
		iv=iv.substr(0,vPos+3);
	}else if((vPos>-1) && (iv.length -vPos -1)==1){
		iv=iv+"0";
	}else if((vPos>-1) && (iv.length -vPos -1)==0){
		iv=iv+"00";
	}else if(vPos==-1){
		iv=iv+".00"; 
	}
	return iv;
}
function getCurrencyToString(iv){
	//将钱数转化为大写
	var ls_bit = "万仟佰拾亿仟佰拾万仟佰拾元角分";
	var ls_num = "壹贰叁肆伍陆柒捌玖";
	var lmax = ls_bit.length;
	var ls_je, ls_dw, ls_result ="";
	var ll_len, i, k;
	//对数据进行标准格式化(0.00格式)
	iv = iv.toString();
	var vFirstChar=iv.substr(0,1);
	if(vFirstChar=="-"){
		vFirstChar="负";
		iv=iv.substr(1,iv.length -1);
	}else{
		vFirstChar="";
	}
	var vPos=iv.indexOf(".");
	if((vPos>-1) && (iv.length -vPos -1)>2){
		iv=iv.substr(0,vPos+3);
	}else if((vPos>-1) && (iv.length -vPos -1)==1){
		iv=iv+"0";
	}else if((vPos>-1) && (iv.length -vPos -1)==0){
		iv=iv+"00";
	}else if(vPos==-1){
		iv=iv+".00";	
	}
	
	ls_je=iv;
	ll_len = ls_je.length;	
	ls_je=ls_je.replace(".","")
	ll_len = ls_je.length;
	for(var i=ll_len;i>0;i--){	
		lmax =lmax-1;
		ls_dw =ls_bit.substr(lmax,1);
		k = parseInt(ls_je.substr(i-1,1));
		
		if(k == 0){
			switch(ls_dw){
				case '元':
					if(ls_result==""){
						ls_result = ls_dw + ls_result+"整";
					}else{
						ls_result = ls_dw + ls_result;
					}
					break;
				case '万':
					ls_result = ls_dw + ls_result;
					break;
				case '亿':
					ls_result = ls_dw + ls_result;
					break;	
				case '分':
					ls_result = ''; //整
					break;
				case '角':					
					if (ls_result != '') ls_result = '零' + ls_result;
					break;
				default:
					switch(ls_result.substr(0,1)){				
						case '万':
							break;
						case '亿':
							break;
						case '元':
							break;
						case '零':
							break;
						default:						
							ls_result = '零' + ls_result;
					}				
			}
		}else{
			if(ls_result=="" && ls_dw=="元" ){
				ls_result = ls_num.substr(k-1, 1 ) + ls_dw + ls_result+"整";
			}else{
				ls_result = ls_num.substr(k-1, 1 ) + ls_dw + ls_result;
			}					
		}
	}
	return vFirstChar+ls_result;
}

//-------------------------------------------------------------------------
// Function Name    :GetAbsoluteUrl
// Parameter(s)     :path       file name
// Memo             :To get the Absolute Url of the file 
//-------------------------------------------------------------------------
function GetAbsoluteUrl(path) 
{
	var img = new Image();
	img.src = path;
	return img.src;
}

function generateMixed(n) {
    var source = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    var result = '__';
    for(var i = 0; i < n ; i ++) {
        var id = Math.ceil(Math.random()*60);
        result += source.charAt(id);
    }
    return result;
}
//-->