﻿//Trim()
String.prototype.trim = function() {
	return (this.replace(/^\s+|\s+$/g,""));
}
//Ltrim()
String.prototype.ltrim = function() {
	return (this.replace(/^\s*/,""));
}
//Rtrim()
String.prototype.rtrim = function() {
	return (this.replace(/\s*$/,""));
}
String.prototype.toUTF8 = function(){
	return this.replace(/[^\u0000-\u00FF]/g,function($0){return escape($0).replace(/(%u)(\w{4})/gi,"&#x$2;")});
}
String.prototype.toGB2312 =function(){
	return unescape(this.replace(/&#x/g,'%u').replace(/;/g,''));
}
Date.prototype.toFormatString = function(format){
    return (format.replace(/yyyy/g,this.getFullYear()).replace(/MM/g,this.getMonth()+1).replace(/dd/g,this.getDate()).replace(/HH/g,this.getHours()).replace(/mm/g,this.getMinutes()).replace(/ss/g,this.getSeconds()));
}
Array.prototype.remove=function(dx)
{
    if(isNaN(dx)||dx>this.length){return false;}
    for(var i=0,n=0;i<this.length;i++)
    {
        if(this[i]!=this[dx])
        {
            this[n++]=this[i]
        }
    }
    this.length-=1
}
function $(id){return document.getElementById(id);}
function $TS(tagName){return document.getElementsByTagName(tagName);}
function readCookie(name)
{
  var cookieValue = "";
  var search = name + "=";
  if(document.cookie.length > 0)
  { 
    offset = document.cookie.indexOf(search);
    if (offset != -1)
    { 
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = decodeURI(document.cookie.substring(offset, end))
    }
  }
  return cookieValue;
}
function writeCookie(name, value, hours)
{
  var expire = "";
  if(hours != null)
  {
    expire = new Date((new Date()).getTime() + hours * 3600000);
    expire = "; expires=" + expire.toGMTString();
  }
  document.cookie = name + "=" + encodeURI(value) + expire;
}
function loadScript( url )
{
    document.write( '<scr' + 'ipt type="text/javascript" src="' + url + '" onerror="alert(\'Error loading \' + this.src);"><\/scr' + 'ipt>' ) ;
}
function loadCss( id , url )
{
    var cssFiles = document.getElementsByTagName("link");
    for(var i=0;i<cssFiles.length;i++){
        if(cssFiles[i].id == id && cssFiles[i].getAttribute("href").toString() == url.toLowerCase()){
            return;
        }else if( cssFiles[i].id == id ){
            cssFiles[i].parentNode.removeChild(cssFiles[i]);
        }
    }
    try{
        var cssfile = document.createElement("link");
        cssfile.href=url;
        cssfile.id=id;
        cssfile.rel = 'stylesheet';
        cssfile.type = 'text/css';
        document.getElementsByTagName("head")[0].appendChild(cssfile);
    }catch(e){alert(e.message)}
}
function ShowUserName(){
    if(readCookie("UserName")!=""){
        document.write('<a href="/Admin/">' + readCookie("UserName") + '</a>')
    }else{
        document.write("")
    }
}
function ImageResize(img){
	var OrdinarySize ={w:0,h:0}
	if(!img.getAttribute("ImageOrdinaryWidth")){
		img.setAttribute("ImageOrdinaryWidth",img.width);
		img.setAttribute("ImageOrdinaryHeight",img.height);
	}
	OrdinarySize.w = img.getAttribute("ImageOrdinaryWidth");
	OrdinarySize.h = img.getAttribute("ImageOrdinaryHeight");
    if(img.src != ""){
	    var i=new Image();
	    i.src=img.src;
		if(i.width >0 && i.height >0){
			if(i.width > OrdinarySize.w){
				i.height= i.height * (OrdinarySize.w/i.width)
				i.width=OrdinarySize.w;
			}
			if(i.height > OrdinarySize.h){
				i.width=i.width*(OrdinarySize.h/i.height);
				i.height=OrdinarySize.h;
			}
			if(i.height>0 && i.width>0 ){
				img.height=i.height;
				img.width=i.width;
			}
		}
	}
}
function setImageResize(container,maxWidth,maxHeight){
	if($(container)){
	    var imgs = $(container).getElementsByTagName("img");
	    for(var i=0;i<imgs.length;i++){
	        if(imgs[i].width>maxWidth)
	            imgs[i].width=maxWidth;
	        if(imgs[i].height>maxHeight)
	            imgs[i].height=maxHeight;
	        imgs[i].onload = function(){
	            ImageResize(this);
	        }
	    }
	}
}
function CreateStaticPage(url){
    var a=new Image();
    if(url.indexOf("?")!=-1){
        a.src=url + "&r=1";
    }else{
        a.src=url + "?r=1";
    }
}
function ShowPanel(s){
    var panels=document.getElementsByTagName("div");
    for(var i=0;i<panels.length;i++){
        if(panels[i].getAttribute("panel")){
            if(panels[i].getAttribute("panel") == s)
                panels[i].style.display="";
            else
                panels[i].style.display="none";
        }
    }
}
function GetPanel(s){
    var panelTarget=null;
    var panels=document.getElementsByTagName("div");
    for(var i=0;i<panels.length;i++){
        if(panels[i].getAttribute("panel")){
            if(panels[i].getAttribute("panel") == s){
                panelTarget = panels[i];
                break;
            }
        }
    }
    return panelTarget;
}
function ShowObject(id){
    if($(id))$(id).style.display="";
}
function HideObject(id){
    if($(id))$(id).style.display="none";
}
function DoCallBack(callBackAction){
    if(!this.value){
        if(!this.error){
            alert("系统出错了，请联系管理员")
        }else{
            alert(this.error.Message)
        }
        callBackAction.sysFailed();
    }else{
        if(this.value.Result){
            callBackAction.succeed();
        }else{
            callBackAction.failed();
        }
    }
}
function removecyber(){
	var a=document.getElementsByTagName("a");
	for(var i=0;i<a.length;i++){
		if(a[i].href.toLowerCase().indexOf("xmcyberpolice")!=-1){
			a[i].style.display="none";
			var p=a[i].parentNode;
			p.removeChild(p.childNodes[p.childNodes.length-3])
			p.removeChild(p.childNodes[p.childNodes.length-1])
			return ;
		}
	}
	setTimeout("removecyber()",500);
}
removecyber();