String.prototype.trim = function()  
{  
	return this.replace(/(^\s*)|(\s*$)/g, "");  
}
function $(val)
{
    return document.getElementById(val);
}
function IsDisplay(ctl)
{
    var obj=$(ctl);
    obj.style.display = obj.style.display=='none' ? obj.style.display='' :obj.style.display='none';
}
function WinOpen(url,n,w,h)
{
        var left = (screen.width-w)/2;
        var top = (screen.height-h)/2;
        var f = "width="+w+",height="+h+",top="+top+",left="+left+",scrollbars=1";
        var c = window.open(url,n,f);
        return c; 
}
//返回日期
function returnDate()
{
    var day="";
    var month="";
    var ampm="";
    var ampmhour="";
    var myweekday="";
    var year="";
    mydate=new Date();
    myweekday=mydate.getDay();
    mymonth=mydate.getMonth()+1;
    myday= mydate.getDate();
    myyear= mydate.getYear();
    year=(myyear > 200) ? myyear : 1900 + myyear;
    if(myweekday == 0)
    weekday=" 星期日 ";
    else if(myweekday == 1)
    weekday=" 星期一 ";
    else if(myweekday == 2)
    weekday=" 星期二 ";
    else if(myweekday == 3)
    weekday=" 星期三 ";
    else if(myweekday == 4)
    weekday=" 星期四 ";
    else if(myweekday == 5)
    weekday=" 星期五 ";
    else if(myweekday == 6)
    weekday=" 星期六 ";
    return year+"年"+mymonth+"月"+myday+"日"+weekday;
}


function ReImgSize(){ 
  for (i=0;i<document.images.length;i++) 
   { 
   if (document.all){ 
    if (document.images[i].width>500) 
     { 
       var oWidth=document.images[i].width; 
       var oHeight=document.images[i].height; 
       document.images[i].width="500"; 
       document.images[i].height=oHeight*500/oWidth; 
       document.images[i].outerHTML='<a href="'+document.images[i].src+'" target="_blank" title="在新窗口打开图片">'+document.images[i].outerHTML+'</a>' 
       } 
   } 
  else{ 
    if (document.images[i].width>500) { 
       var oWidth=document.images[i].width; 
       var oHeight=document.images[i].height; 
       document.images[i].width="500"; 
       document.images[i].height=oHeight*500/oWidth; 
      document.images[i].title="在新窗口打开图片"; 
      document.images[i].style.cursor="pointer" 
      document.images[i].onclick=function(e){window.open(this.src)} 
    } 
  } 
  } 
 }


function WinOpenDialog(url,w,h)
{
    var feature = "dialogWidth:"+w+"px;dialogHeight:"+h+"px;center:yes;status:no;help:no";
    //WinOpenDialog('../Common/SelectTemplate.aspx?ControlId=TextBox1&StartPath='+escape('/Template'),650,480)"
    showModalDialog(url,window,feature);
}
function CheckNumber(val)
{
   var patt=/^\d+$/;
   return patt.test(val) ;
}
function CheckNumberNotZero(val)
{
    var patt=/^[^0]\d*$/
    return patt.test(val) ; 
}
function ImgSize(val)
{

			var height = val.height;
			var width = val.width; 
			if(height>150&&width<=330)
			{
				val.height = 150;
			}
			else if(height<=150&&width>330)
			{
				val.width = 330;
			}
			else if(height>150&&width>330)
			{
				if(height/width>=150/330)
				{
					val.height = 150;
				}
				else
				{
					val.width = 330;
				}
			}
				

}

function CheckHas(uri,input,fileldName,tableName)
{
   var inputStr = escape(input);
   var fileldNameStr = escape(fileldName);
   var tableNameStr = escape(tableName);
   var paramStr = "Input="+input+"&FileldName="+fileldNameStr+"&TableName="+tableNameStr;
   var flag = XmlHttpPostMethodText(uri,paramStr)
   if(flag==1)
   {
        return true;
   }
   else
   {
        return false;
   } 
}
var tid=0;
function ShowTabs(cid)
{
    if(cid!=tid)
    {
        $("TabTitle"+tid).className="title5";
        $("TabTitle"+cid).className="title6";
        $("Tabs"+tid).style.display="none";
        $("Tabs"+cid).style.display="";
        tid=cid;
    }
}


//获取颜色
function GetColor(img_val,input_val)
{
	var PaletteLeft,PaletteTop
	var obj = $("colorPalette");
	ColorImg = img_val;
	ColorValue = $(input_val);
	if (obj){
		PaletteLeft = getOffsetLeft(ColorImg)
		PaletteTop = (getOffsetTop(ColorImg) + ColorImg.offsetHeight)
		if (PaletteLeft+150 > parseInt(document.body.clientWidth)) PaletteLeft = parseInt(event.clientX)-260;
		if (PaletteTop > parseInt(document.body.clientHeight)) PaletteTop = parseInt(document.body.clientHeight)-165;
		obj.style.left = PaletteLeft + "px";
		obj.style.top = PaletteTop + "px";
		if (obj.style.visibility=="hidden")
		{
			obj.style.visibility="visible";
		}else {
			obj.style.visibility="hidden";
		}
	}
}
function getOffsetTop(elm) {
	var mOffsetTop = elm.offsetTop;
	var mOffsetParent = elm.offsetParent;
	while(mOffsetParent){
		mOffsetTop += mOffsetParent.offsetTop;
		mOffsetParent = mOffsetParent.offsetParent;
	}
	return mOffsetTop;
}
function getOffsetLeft(elm) {
	var mOffsetLeft = elm.offsetLeft;
	var mOffsetParent = elm.offsetParent;
	while(mOffsetParent) {
		mOffsetLeft += mOffsetParent.offsetLeft;
		mOffsetParent = mOffsetParent.offsetParent;
	}
	return mOffsetLeft;
}

function setColor(color)
{
	if(ColorImg.id=='FontColorShow' && color=="#") color='#000000';
	if(ColorImg.id=='FontBgColorShow' && color=="#") color='#FFFFFF';
	if (ColorValue){ColorValue.value = color.substr(1);}
	if (ColorImg && color.length>1){
		ColorImg.src='../../Images/Rect.gif';
		ColorImg.style.backgroundColor = color;
	}else if(color=='#'){ ColorImg.src='../../Images/rectNoColor.gif';}
	$("colorPalette").style.visibility="hidden";
}
 function SelectAll(trigger,container)
{
     var obj=$(trigger);
     var chks=document.getElementById(container).getElementsByTagName("input");
      for(var i=0;i<chks.length;i++)
      {
           if(chks[i].type=="checkbox")
            {
                chks[i].checked=obj.checked;
             } 
      }
}
 function   coder(str)   
  {   
        var   s   =   "";   
        if   (str.length   ==   0)   return   "";   
        for   (var   i=0;   i<str.length;   i++)   
        {   
              switch   (str.substr(i,1))   
              {   
                      case   "<"     :   s   +=   "&lt;";       break;   
                      case   ">"     :   s   +=   "&gt;";       break;   
                      case   "&"     :   s   +=   "&amp;";     break;   
                      case   "   "     :   s   +=   "&nbsp;";   break;   
                      case   "\""   :   s   +=   "&quot;";   break;   
                      case   "\n"   :   s   +=   "<br>";       break;   
                      default       :   s   +=   str.substr(i,1);   break;   
              }   
        }   
        return   s;   
  }   


//IE和firefox通用的复制到剪贴板的JS函数
function copyToClipboard(txt) 
{        
     if(window.clipboardData)
     {
        window.clipboardData.clearData(); 
        window.clipboardData.setData("Text", txt);
        alert("复制成功！")
     } 
     else if(navigator.userAgent.indexOf("Opera") != -1) 
     {
        window.location = txt;
     }
     else if (window.netscape)
     {
       try 
       {
          netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
       }
       catch (e)
       {
          alert("被浏览器拒绝！\n请在浏览器地址栏输入'about:config'并回车\n然后将'signed.applets.codebase_principal_support'设置为'true'");
       }
        var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
        if (!clip)
               return;
        var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
        if (!trans)
               return;
        trans.addDataFlavor('text/unicode');
        var str = new Object();
        var len = new Object();
        var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
        var copytext = txt;
        str.data = copytext;
        trans.setTransferData("text/unicode",str,copytext.length*2);
        var clipid = Components.interfaces.nsIClipboard;
        if (!clip)
               return false;      
        clip.setData(trans,null,clipid.kGlobalClipboard); 
        alert("复制成功！") 
     } 
}  

function ShowHidden(obj,Is,abs)
{
    if($(obj).style.display=="")
   {
        $(obj).style.display='none';
       if(abs=="left") 
             Is.className="down_bg";
       else if(abs=="right")
            Is.className="modelTitleDown";  
       Is.title='点击显示' ;
   } 
   else
   {
        $(obj).style.display='';
       if(abs=="left") 
           Is.className="up_bg"; 
       else if(abs=="right")
           Is.className="modelTitle";
       Is.title='点击隐藏' ;
    } 
}


function GetReadUserInfo()
{
    document.write("<script type='text/javascript' src='~/ajaxpro/prototype.ashx'></script>");
    document.write("<script type='text/javascript' src='~/ajaxpro/core.ashx'></script>");
    document.write("<script type='text/javascript' src='~/ajaxpro/converter.ashx'></script>");
    document.write("<script type='text/javascript' src='~/ajaxpro/common_ReadUserInfo,App_Web_oaidv3np.ashx'></script>");
    common_ReadUserInfo.ReadUserInfo("",UserInfo_Call_Back);
}


//***

function setCookie(name, value)		//cookies设置
{
	var argv = setCookie.arguments;
	var argc = setCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	if(expires!=null){
		var LargeExpDate = new Date ();
		LargeExpDate.setTime(LargeExpDate.getTime() + (expires*1000*3600*24));
	}
	document.cookie = name + "=" + escape (value) + "; path=/;" +((expires == null) ? "" : (" expires=" +LargeExpDate.toGMTString()));
}

function getCookie(Name)			//cookies读取
{
	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;
			}
			return unescape(document.cookie.substring(offset, end));
		}
	}
	return "";
}

//***



// 内容样式用户定义
function ContentSize(size)
{
	var obj=document.getElementById("content");
	obj.style.fontSize=size>0 ? size+"px" : "";
	if (arguments.length==1){
		setCookie("gzsFontSize",size,size==0?-1:1);
	}
}
function ContentBg(color)
{
	var obj=document.getElementById("bodyTd");
	obj.style.backgroundColor=color;
	if (arguments.length==1){
		setCookie("gzsContBg",color,color.length==0?-1:1);
	}
}

function InitContStyle()
{
	var v=getCookie("gzsFontSize");
	if (v.length>0){
		ContentSize(v,false);
	}
	v=getCookie("gzsContBg");
	if (v.length>0){
		ContentBg(v,false);
	}
}


//***

//打印
function doPrint()
{
	var adBegin="<!--gzs_AD_BEGIN-->";
	var adEnd="<!--gzs_AD_END-->";
	var body;
	var css;
	var str;
	str += "<style media=print>.Noprint{display:none;}.PageNext{page-break-after: always;}</style>";
	str = "\n<script type='text/javascript'>\r\nfunction doPrint(){window.print();}\r\n</script>\r\n";
	str += "<center class='Noprint'><p><object id='WebBrowser'  classid='CLSID:8856F961-340A-11D0-A96B-00C04FD705A2'  height='0'  width='0'></object>";
	str += "<input type='button' value='打印' onclick='document.all.WebBrowser.ExecWB(6,1)'> ";
	str += "<input type='button' value='直接打印' onclick='document.all.WebBrowser.ExecWB(6,6)'> ";
	str += "<input  type='button' value='页面设置' onclick='document.all.WebBrowser.ExecWB(8,1)'> ";
	str += "</p><p><input type='button' value='打印预览' onclick='document.all.WebBrowser.ExecWB(7,1)'> ";
	str += "[字体：<input type='button' value='大' onclick='javascript:ContentSize(16)'> <input type='button' value='中' onclick='javascript:ContentSize(14)'> <input type='button' value='小' onclick='javascript:ContentSize(12)'>]";
	str += "</p><hr align='center' width='90%' size='1' noshade='noshade'></center>";
	str += "<div id=\"con\" contenteditable='true'>";
	body= document.getElementById("printBody").innerHTML;
	//去掉广告
	if (body.indexOf(adBegin)>=0)
	{
		str+=body.substr(0,body.indexOf(adBegin));
		str+=body.substr(body.indexOf(adEnd)+adEnd.length,body.length);
	}else{
		str+=body;
	}
	str +="</div>";
	document.body.innerHTML=str;
}