
function G(id){
	return document.getElementById(id)
};
function dc(t) {return document.createElement(t)};
function pos(ele){var el = ele, left = 0, top = 0;do {left += el.offsetLeft || 0;top += el.offsetTop || 0;el = el.offsetParent;} while (el);return {x: left, y: top};}
/////////////////////////////////////////字符串操作///////////////////////////
String.prototype.trim= function()  
{  
    // 用正则表达式将前后空格  
    // 用空字符串替代。  
    return this.replace(/(^\s*)|(\s*$)/g, "");  
}

//定义一个字符stringbuilder类
function StringBuilder()
        {
            this.arrStr = new Array();
        }
        StringBuilder.prototype.Append = function(strVelue)
        {
            this.arrStr.push(strVelue);
        }
        
        StringBuilder.prototype.toString = function()
        {
               
             return this.arrStr.join("");

         }
         //html编码////////////
         function HtmlEncode(text) {
             return text.replace(/&/g, '&amp').replace(/\"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
         }
         //html解码
         function HtmlDecode(text) {
             
             return text.replace(/&amp;/g, '&').replace(/&quot;/g, '\"').replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/\n/g, '<br>').replace(/\t/g, '<br>').replace(/\r/g, '');
             
         }
         
         function GetJsPram(jsid, strArg) {
             var str = document.getElementById(jsid).src;
             var _url = str + "&";
             var regex = new RegExp("(\\?|\\&)" + strArg + "=([^\\&\\?]*)\\&", "gi");
             if (!regex.test(_url)) return "";
             var arr = regex.exec(_url);
             return (RegExp.$2);
         }
         //获取url?号后的参数
         function GetUrlParams(ParamName)
         {
            var URLParams = new Object() ;
            var aParams = document.location.search.substr(1).split('&') ;
            for (i=0 ; i < aParams.length ; i++)
            {
	            var aParam = aParams[i].split('=') ;
	            URLParams[aParam[0]] = aParam[1] ;
            }
            
            return URLParams[ParamName];
         }

         function cut_string(strString, nLength) {
             var nTheLength = 0;
             for (var nIndex = 0; nIndex < strString.length; nIndex++) {
                 if (strString.charCodeAt(nIndex) > 255)
                     nTheLength += 2;
                 else
                     nTheLength += 1;
                 if (nTheLength >= nLength)
                     break;
             }
             var strResult = strString.substr(0, nIndex);
             if (strResult.length < strString.length)
                 strResult = strResult + "...";
             return strResult;
         }
         function cut_str_mid(strString, iLength) {
             if (strString.length > iLength) {
                 var iLength2 = parseInt(iLength / 2);
                 var strtemp1 = strString.substr(0, iLength2);
                 var strtemp2 = strString.substr(strString.length - iLength2);
                 strString = "";
                 strString = strtemp1 + "  ...  " + strtemp2;
             }
             return strString;
         }
         //从url中获取文件类型
         function get_type_of_url(sUrl) {
             var strType = "";
             if (sUrl != "") {
                 var iLastIndex = sUrl.lastIndexOf(".") + 1;
                 strType = sUrl.substring(iLastIndex, sUrl.length);

             }
             if (strType.length > 5) return "";
             return strType;
         }
         //复制文本
         function CopyObText(thisobj) {
             var rng = document.body.createTextRange();
             rng.moveToElementText(thisobj);
             rng.scrollIntoView();
             rng.select();
             clipboardData.setData('text', thisobj.innerText);
             alert("复制成功!!");
         }
         function JsonToObj(sJson)
        { 
            
            return eval("({"+sJson+"})");  
        }
        
//////////////////////////////////数组操作///////////////////////
        
//为数组添加一个删除指定索引项  
    Array.prototype.removecount = 0;     
     Array.prototype.removedAt = function(index)
        {
            if(isNaN(index)||index<0)
            {
                return ;
            }
            if(index<this.length)
            {
                this.splice(index,1);
                this.removecount++;
            }            
            
        }
//为数组添加一个新办法:删除重复数组项。
Array.prototype.unique = function()
{
   var tempArray=this.slice(0);//复制数组到临时数组
     for(var i=0;i<tempArray.length;i++)
     {
          for(var j=i+1;j<tempArray.length;)
          {
           if(tempArray[j].toString()==tempArray[i].toString())
           //后面的元素若和待比较的相同，则删除并计数；
           //删除后，后面的元素会自动提前，所以指针j不移动
           {
            tempArray.splice(j,1);
           }
           else
           {
            j++;
           }
           //不同，则指针移动
      }
     }
 return tempArray;
}


//从指定值获取数组索引,如有重复值，只取第一个索引
Array.prototype.GetIndex = function(obj)
        {
           var tempArray=this.slice(0);//复制数组到临时数组
           var iIndex = 0;
             for(var i=0;i<tempArray.length;i++)
             {              
               if(tempArray[i].Equals(obj))
               {   
                   iIndex = i;
                   break;
               }
             }
            
           return iIndex;
        }
  //为数组添加一个新办法:转换成JSON代码,iarr为数组维数,只支持1,2维。
  Array.prototype.toJson = function(iarr)
        {
            var strJson = "";
            var sbJson = new StringBuilder();
            if(iarr==1)
            {
                strJson = this.join("\",\""); 
                 strJson = "[\""+strJson+"\"]";
            }
            else if(iarr==2)
            {
                for(var i=0;i<this.length;i++)
                {
                    
                    sbJson.append("\"],[\""+this[i].join("\",\""));
                }
                
                strJson = sbJson.toString();
                strJson = strJson.replace("\"],","["); 
                strJson = strJson+"\"]]";
            }
          
          return strJson;
          
        }


//table 常用操作,iTop为保留顶项

function clear_table_rows(obTable,iTop)
{
	  var delRows=obTable.rows.length;	  
	 for(i=iTop;i<delRows;i++)	obTable.deleteRow(1); 
  }

//////////////////////////////////////ajax操作////////////////
//GET办法运行异步http请求
function run_ajax_async(url,postdata,backfun)
{
				
				$.ajax({
				  type: "get",
				  url: url,
				  data: postdata,   
				  dataType: "html",
				  success: function(msg)
				  {		
				  	if(backfun!=null)backfun(msg);
					
				  },
				  async: true
				})	
}
//GET/post办法运行异步http请求
function run_ajax_async_type(url,postdata,backfun,type)
{
				$.ajax({
				  type: type,
				  url: url,
				  data: postdata,   
				  dataType: "html",
				  success: function(msg)
				  {		
				  	if(backfun!=null)backfun(msg);
					
				  },
				  async: true
				})	
}
//运行同步http请求
function run_ajax_unasync(url)
{
	var html = $.ajax({
				 url: url,
				 async: false
				}).responseText;
	
	return html;
}
//GET办法运行异步http请求 javascript
function run_ajax_async_js(url,postdata,backfun)
{
				
				$.ajax({
				  type: "get",
				  url: url,
				  data: postdata,   
				  dataType: "script",
				  success: function(msg)
				  {		
				  	if(backfun!=null)backfun(msg);
					
				  },
				  async: true
				})	
}
//获取json数据sPath为文件名称与路径
function get_json(sPath,fun)
{
     $.getJSON(sPath, 
                fun
        );
}
//批量操作----------------------------------------

//全选
function on_checkall(ob)
{    
   $(ob).find("input[@type='checkbox']").each(		
		function(i)
		{
			this.checked = true;
		}
		);
}
//反向选取
function on_checkback(ob)
{
  $(ob).find("input[@type='checkbox']").each(		
		function(i)
		{
			if(this.checked)
			{
				this.checked = false;
			}
			else
			{
				this.checked = true;
			}
		}
		);
}

//反向选取
function on_check(ob,obchk)
{
  $(ob).find("input[@type='checkbox']").each(		
		function(i)
		{
			this.checked = obchk.checked;
		}
		);
}

  //获取选择的radio值
 function get_checkedradio_value(radios)
 {
	 for(var i=0;i<=radios.length;i++)
	 {
		 if(radios[i].checked) return radios[i].value ;
	 }
	 return null;
 }

 //获取下拉列表项
 function get_selected_value(ob)
 {
	 
	return ob.options[ob.selectedIndex].value;
}
//设计一个通用的Tags类
function CustomTags()
{
    //tags列表的上一级元素名称
    this.ParentObjName = "";
    this.SubObj = "";
    this.CurrentClassName = "";
    this.ClassName = "";
    this.fun = null;
    if (typeof CustomTags._initialized == "undefined") 
    {
        CustomTags.prototype.InitOnclickInTags = function() 
        {
            var tags = this.GetTags();
            
            if(tags!=null&&tags.length>0)
            {   
                for(var i =0;i<tags.length;i++)
                {
                    tags[i].onclick = this.fun;//function(){ };
                }
            }
        }
        CustomTags.prototype.OnclickTags = function(obj) 
        {
            
            var tags = this.GetTags();
            
            if(tags!=null&&tags.length>0)
            {   
                for(var i =0;i<tags.length;i++)
                { 
                  if(tags[i]!=obj)
                  {
                    tags[i].className = this.ClassName;
                  }
                }
             }
             obj.className=this.CurrentClassName;
        }
        CustomTags.prototype.InitOnclick = function(index)
        {
            var tags = this.GetTags();
            var obj = tags[index];
            if(obj=="undefined"||obj==null)
            {
                alert("没有找到对应的Tag");
                return;
            }
            $(obj).click(); 
        }
        CustomTags.prototype.GetTags = function() 
        {
        
             var Tags = [];
                $("#"+this.ParentObjName).find(this.SubObj).each(
                
                    function(i)
		            {
		               Tags.push(this);
		            }
                );
               return Tags; 
        }
    }
    CustomTags._initialized = true;
    
}
 // 实现一个类似委托特性的类(js里面function可以相当于一个类)，add方法相当于运算符"+"重载,run相当执行委托链上所有的回调函数

function delegate(func){
    this.arr = new Array(); // 回调函数数组
    this.add = function(func){
        this.arr[this.arr.length] = func;
    };
    this.run = function(){
        for(var i=0;i<this.arr.length;i++){
            var func = this.arr[i];
            if(typeof func == "function"){
                func(); // 遍历所有方法以及调用
            }
        }
    }
    this.add(func);
}

  
//窗口操作----------------------------------------------
function OpenBrowse(obid,pram,listtype)
{
    var result = ShowDialog("/FileManager/filelist.aspx?t="+listtype+"&uppram="+pram, window,600,500);
	if ((result) && (result != ""))
	{
	    document.getElementById(obid).value = result;
		
	}
}
//打开上传对话框
function OpenUpload(obid,pram)
{
    var result = ShowDialog("/FileManager/UploadSingle.aspx?ut=1&pram="+pram.trim(), window,380,110);
	if ((result) && (result != ""))
	{
	    document.getElementById(obid).value = result;
		
	}
    //ShowLessDialog("/FileManager/UploadSingle.aspx?ucid="+obid+"&pram="+pram,380, 110);
}
// 显示无模式对话框
function ShowDialog(url, object, width, height) {	
	
	var cursor = document.body.style.cursor;
	document.body.style.cursor = "wait";
	var result = window.showModalDialog(url, object, "status:no; center:yes; help:no; minimize:no; maximize:no; scroll:no; border:thin; statusbar:no; dialogWidth:" + width + "px; dialogHeight:" + height + "px");
	document.body.style.cursor = cursor;
	return result;
	
}


// 显示模式对话框
function ShowLessDialog(url, width, height) {
	
	var result = showModelessDialog(url, window, "dialogWidth:" + width + "px;dialogHeight:" + height + "px;help:no;scroll:no;status:no");
	if ((result) && (result != ""))
	{
	    alert(result)
	}
}

function getposition(obj)
{
	var r = new Array();
	r['x'] = obj.offsetLeft;
	r['y'] = obj.offsetTop;
	while(obj = obj.offsetParent)
	{
		r['x'] += obj.offsetLeft;
		r['y'] += obj.offsetTop;
	}
	return r;
}

//显示提示层
function showhintinfo(obj, objleftoffset,objtopoffset, title, info , objheight, showtype ,objtopfirefoxoffset)
{
   
    var p = getposition(obj);
   
   if((showtype==null)||(showtype =="")) 
   {
       showtype =="up";
   }
   
   document.getElementById('hintiframe'+showtype).style.height= objheight + "px";
   document.getElementById('hintinfo'+showtype).innerHTML = info;
   document.getElementById('hintdiv'+showtype).style.display='block';
   
   
   
   if(objtopfirefoxoffset != null && objtopfirefoxoffset !=0 && !isie())
   {
        document.getElementById('hintdiv'+showtype).style.top=p['y']+parseInt(objtopfirefoxoffset)+"px";
   }
   else
   {
        if(objtopoffset == 0)
        { 
			if(showtype=="up")
			{
				 document.getElementById('hintdiv'+showtype).style.top=p['y']-document.getElementById('hintinfo'+showtype).offsetHeight-40+"px";
			}
			else
			{
				 document.getElementById('hintdiv'+showtype).style.top=p['y']+obj.offsetHeight+5+"px";
			}
        }
        else
        {
			document.getElementById('hintdiv'+showtype).style.top=p['y']+objtopoffset+"px";
        }
   }
   document.getElementById('hintdiv'+showtype).style.left=p['x']+objleftoffset+"px";
}



//隐藏提示层
function hidehintinfo()
{
    document.getElementById('hintdivup').style.display='none';
    document.getElementById('hintdivdown').style.display='none';
}
//打开播放页面
function win_open_play(id)
{
    window.open("/music/"+id,"c","");
}
//重定向到播放页面
function redirect_play(id)
{
    window.location.href = "../"+id;
}
function wo(url, w, h, m, s) {
    var left = (screen.width - w) / 2;
    var top = m ? (screen.height - h) / 2 : 0;
    return window.open(url, 'player', 'width=' + w + ',height=' + h + ',top=' + top + ',left=' + left + ',scrollbars=0,resizable=0,status=' + s);

}
function woshowbar(url, w, h, m, s) {
    var left = (screen.width - w) / 2;
    var top = m ? (screen.height - h) / 2 : 0;
    return window.open(url, '', 'width=' + w + ',height=' + h + ',top=' + top + ',left=' + left + ',scrollbars=1,resizable=0,status=' + s);

}
function OpenWinCenter(url,w,h) {
    woshowbar(url, w, h, 1, 1);
}
function wo_href(url, w, h, m, s, name) {
    var left = (screen.width - w) / 2;
    var top = m ? (screen.height - h) / 2 : 0;
    window.open(url, name, 'width=' + w + ',height=' + h + ',top=' + top + ',left=' + left + ',scrollbars=0,resizable=0,status=' + s);
    return false;
}
//以post方式打开窗口
function postwinopen(strUrl,postdata)
{  
    
    var contrlos = postdata.split("&");
    var form = document.createElement("form"); 
    for(var i=0;i<contrlos.length;i++)
    {
        
        var strPram = contrlos[i]; 
       
        var cotrlosname = strPram.substring(0,strPram.indexOf("="));
        var sValue = strPram.substring(strPram.indexOf("=")+1,strPram.length);
        
        var input = document.createElement("input");        
        input.setAttribute("type","text");
         input.setAttribute("style","display:none");
         input.name = cotrlosname;
         input.value = sValue; 
         
         form.appendChild(input);
    }
     
     document.body.appendChild(form);
        form.target="_blank"; 
        form.method="post";
        form.action = strUrl;        
        form.submit();
    document.body.removeChild(form);
}
//提示操作类--------

var cpopup = null; 		//气球提示窗口对象
var popuptt; 			//气球提示窗口定时器
var QI_ALERT_T = 1000;
var popupW = 180; 	//气球提示窗口宽度
var popupH = 30; 	//气球提示窗口高度
function newpopup() {
    cpopup = window.createPopup();
    var CCbody = cpopup.document.body;
    with (CCbody.style) {
        backgroundColor = "#E6F2FF";
        border = "#78B9FF 2px solid";
        color = "#FFFFFF";
        fontSize = "9pt";
        padding = 4;
    }
    CCbody.innerHTML = '<div id="txt" style="text-align:center;color:#FF0000"></div>';

}

function popuprun(s)		//气球提示窗口出现过程
{
    clearTimeout(popuptt);
    var ph = popupH * (ph = 1 - Math.abs(s) / 5);
    cpopup.show((screen.width - popupW) * 0.5, (screen.height - ph) * 0.5, popupW, ph);
    if (s > -4)
        popuptt = setTimeout("popuprun(" + (s - 1) + ")", (s == 0) ? QI_ALERT_T : 50);
    else
        cpopup.hide();
}

function popupopen() {
    if (QI_ALERT_T == 0)
        cpopup.show(screen.width - popupW, screen.height - popupH, popupW, popupH);
    else
        popuprun(4);
}
function showpop(strMSG) {
    newpopup();
    cpopup.document.all.txt.innerText = strMSG;
    popupopen();
}
function showpop_of_laod(strMSG) {
    newpopup();
    cpopup.document.all.txt.innerText = strMSG;
    cpopup.show((screen.width - popupW) * 0.5, (screen.height - popupH) * 0.5, popupW, popupH);
}
//窗口操作结束
function searchsubmit(ob)
{
	if(ob.q.value=="")return false;
}

