﻿String.prototype.lTrim=function(){return this.replace(/^\s*/,"");};
String.prototype.rTrim=function(){return this.replace(/\s*$/,"");};
String.prototype.trim=function(){return this.rTrim().lTrim();};

function enc(s){
	return s==null?null:s.toString ().replace(/\%/g,"%00").replace(/=/g,"%3D");
};
function req(operation,options){
    return new Ajax.Request('/req.ashx?act='+operation,options);
};
function requestQuery(key){
    var rutrunVal = null;
    var query = location.search;
    if(key==null || typeof key == 'undefined')
        return query;
    var pkey = key+'=';
    if(query.length > 0){
       query = query.substring(1,query.length);
       if(query.indexOf(pkey)!=-1){
            query = query.split('&');
            query.each(function(parm){
                if(parm.startsWith(pkey)){
                    rutrunVal = parm.replace(pkey,'');
                }
            });
       }
    }
    return unescape(rutrunVal);
};
Element.addMethods({
    isEmpty:function(element){
        element = $(element);
        if($F(element) == ''){
            $(element).setStyle({backgroundColor: '#ffeffd'});
            return true;
        }
        else{
            $(element).setStyle({backgroundColor: ''});
            return false;
        }
    }
});
var addToOnload = function(fn){
    Event.observe(window, 'load',fn);
};
function setCookie(name,value,day){
	var expdate=new Date();
	var argv=setCookie.arguments;
	var argc=setCookie.arguments.length;
	var expires=(argc>2)?argv[2]:null;
	var path=(argc>3)?argv[3]:null;
	var domain=(argc>4)?argv[4]:null;
	var secure=(argc>5)?argv[5]:false;
	if(expires!=null) expdate.setTime(expdate.getTime()+(expires*3600000*24));
	document.cookie=name+"="+escape(value)+((expires==null)?"":("; expires="+expdate.toGMTString()))+((path==null)?"":("; path="+path))+((domain==null)?"":("; domain="+domain))+((secure==true)?"; secure":"");
};
function deleteCookie(name){
	var exp=new Date();
	exp.setTime(exp.getTime()-1);
	var cval=getCookie(name);
	document.cookie=name+"="+cval+"; expires="+exp.toGMTString();
};
function getCookie(cn){
	var dc=document.cookie;
	var prefix=cn+"=";
	var begin=dc.indexOf("; "+prefix);
	if(begin==-1){
		begin=dc.indexOf(prefix);
		if(begin!=0)return null;
	}else {
		begin+=2;
	}var end=document.cookie.indexOf(";",begin);
	if(end==-1){
		end=dc.length;
	}
	return unescape(dc.substring(begin+prefix.length,end));
};
function getWindowSize(){
	var myWidth=0,myHeight=0;
	if(typeof(window.innerWidth)=='number'){
		myWidth=window.innerWidth;
		myHeight=window.innerHeight;
	}else if(document.documentElement&&(document.documentElement.clientWidth||document.documentElement.clientHeight)){
		myWidth=document.documentElement.clientWidth;
		myHeight=document.documentElement.clientHeight;
	}else if(document.body&&(document.body.clientWidth||document.body.clientHeight)){
		myWidth=document.body.clientWidth;
		myHeight=document.body.clientHeight;
	}
	return {width:myWidth,height:myHeight};
};
function getDocumentSize(){
    var winSize = getWindowSize();
    var docHeight=0,docWidth=0;
    if (window.innerWidth && window.scrollMaxX) {
        docWidth = window.innerWidth + window.scrollMaxX;
    } else if (document.body.scrollWidth > document.body.offsetWidth){
        docWidth = document.body.scrollWidth;
    } else {
        docWidth = document.body.offsetWidth;
    }
    if(docWidth < winSize.Width) docWidth = winSize.Width;
    if (window.innerHeight && window.scrollMaxY) {
        docHeight = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight){
        docHeight = document.body.scrollHeight;
    } else {
        docHeight = document.body.offsetHeight;
    }
    if(docHeight < winSize.Height) docHeight = winSize.Height;
    if(document.body.offsetWidth && docWidth > document.body.offsetWidth)
        docWidth = document.body.offsetWidth;
    return {width:docWidth,height:docHeight};
};
function getWindowScroll(w) {
    var T, L, W, H;
    with (w.document) {
      if (w.document.documentElement && documentElement.scrollTop) {
        T = documentElement.scrollTop;
        L = documentElement.scrollLeft;
      } else if (w.document.body) {
        T = body.scrollTop;
        L = body.scrollLeft;
      }
      if (w.innerWidth) {
        W = w.innerWidth;
        H = w.innerHeight;
      } else if (w.document.documentElement && documentElement.clientWidth) {
        W = documentElement.clientWidth;
        H = documentElement.clientHeight;
      } else {
        W = body.offsetWidth;
        H = body.offsetHeight
      }
    }
    return { top: T, left: L, width: W, height: H };
};
var randnum = function()
{
    now = new Date();
    return now.getTime();
};
function getContactTree(ReceiveObj){
    ReceiveObj = $(ReceiveObj);
    var ct = new contactFilter({customAttributes:['AccountId','RealName']});
    
    var popup = new popWin(360,150,150,'__newPopWin');
    
    ct.filterContainer = popup.bodyContainer;
    popup.fill();
    
    //popup.popWinContainer.setStyle({'right':'5px','left':''});
    ct.singleSelect = true;
    ct.leftMenu = ['用户组'];
    ct.showTab = false;
    ct.openAll = true;
    
    ct.leftMenuCallback = [
        function(deep,con,parentId,pCallback){
            getGroupByParentId(deep,con,parentId,['GroupId','GroupName','GroupId'],[],['ChildCount','MemberCount'],pCallback,['AccountId','Name','AccountId'],['AccountId','Name']);
        }
    ];
    ct.show();
    ct.leftMenuCon.hide();
    ct.cbClickCallback = function(cb){
        ReceiveObj.value = ct.getValuesByName('RealName');
        popup.close();
    };
};

function checkEmpty(a){
	a=$(a);
	a.style.backgroundColor='#ffffff';
	if($F(a).length<1){
		a.style.backgroundColor='#ffccff';
		return false
	}
	else return true
}
function sAlert(a,b,c,d,e,f){
	if(!$("__msgContainer")){
		this.winSize=getWindowSize();
		this.docSize=getDocumentSize();
		this.scrollHeight=document.documentElement.scrollTop;
		this.scrollWidth=document.documentElement.scrollLeft;
		var g=docSize.Width;
		var h=docSize.Height;
		if(!c)c=400;
		if(c>g)c=g-40;
		if(!d)d=120;
		if(d>h)d=h-40;
		if(!e)e=(winSize.Width-c)/2+this.scrollWidth;
		if(!f)f=(winSize.Height-d)/2+this.scrollHeight;
		if(!b)b="提 示";
		var i=document.createElement("div");
		i.setAttribute("id","__msgContainer");
		i.style.width=g+"px";
		i.style.height=h+"px";
		i.style.position="absolute";
		i.style.top="0";
		i.style.background="#777";
		i.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
		i.style.opacity="0.6";
		i.style.left="0";
		i.style.zIndex="10000";
		document.body.appendChild(i);
		var j=document.createElement("div");
		j.setAttribute("id","__msgMain");
		j.style.textAlign="center";
		j.style.backgroundColor="#fff";
		j.style.border="1px solid #0C4175";
		j.style.position="absolute";
		j.style.filter="progid:DXImageTransform.Microsoft.Alpha(startX=20, startY=20, finishX=100, finishY=100,style=1,opacity=95,finishOpacity=100);";
		j.style.opacity='0.95';
		j.style.width=c+"px";
		j.style.height=d+"px";
		j.style.left=e+"px";
		j.style.top=f+"px";
		j.style.zIndex="10001";
		j.innerHTML='<div id="__msgTitle" style="height:28px;line-height:28px;text-align:left;background-color:#336699;"><span id="__msgTitleText" style="float:left;height:28px;line-height:28px;margin-left:7px;color:#fff;">'+b+'</span><span id="__msgWinClose" title="关闭窗口" style="width:50px;height:28px;float:right;background-image:url(/Images/close.gif);background-repeat:no-repeat;background-position:right center;cursor:pointer;"></span></div><div id="__msgContent" style="margin:17px;font-family:宋体,"Comic Sans MS",Arial,Helvetica,sans-serif;"></div>';
		document.body.appendChild(j);
		$("__msgWinClose").onclick=function(){
			sAlertClose()
		};
		Element.update('__msgContent',a)
	}
	else{
		sAlertClose()
	}
}
function sAlertClose(){
	document.body.removeChild($("__msgMain"));
	document.body.removeChild($("__msgContainer"))
}
