﻿String.prototype.trim = function() 
{ 
    return this.replace(/(^\s*)|(\s*$)/g, ""); 
} 
function SelectAllCheckbox(){
	for( i = 0; i < document.forms[0].elements.length; i++ ){
		curObj = document.forms[0].elements(i);
		if( curObj.type == "checkbox"   )
 			  curObj.checked = true;
	}
 }
 function UnSelectAllCheckbox(){
	for( i = 0; i < document.forms[0].elements.length; i++ ){
		curObj = document.forms[0].elements(i);
		if( curObj.type == "checkbox"   )
 			  curObj.checked = false ;
	}
 }
  function SetAllCheckboxStatus(b){
	for( i = 0; i < document.forms[0].elements.length; i++ ){
		curObj = document.forms[0].elements(i);
		if( curObj.type == "checkbox"   )
 			  curObj.checked = b ;
	}
 }
 function GetQueryString(){
	var arr = window.location.href.split("?");
	if( arr.length == 1 ) return "";
	else return arr[1];
 }
  
 /***********
 *下拉列表操作
 *
 *
 *****************/
 
function CreateOption(text,value){
	var oOption = document.createElement("OPTION");
	oOption.text=text;
	oOption.value=value;
	return oOption;
}

/********
*移动下拉列表中所有项
*@fromObj 要移动的列表对象
*&toObj 移动到的列表对象
*************/
function MoveAllOption( fromObj , toObj ){
	var toOp ;
	var fromOp
	var i = 0 ;
	for( i = 0 ; i < fromObj.options.length ; i ++ ){
		fromOp = fromObj.options( i );
		toOp = createOption( fromOp.text , fromOp.value  ) 
		toObj.add( toOp ) ;
	}

	for( i =  fromObj.options.length - 1 ; i >= 0 ; i -- ){
		fromObj.remove(i);
	} 
}

function ClearAllOption( fromObj){
	 
	for( i =  fromObj.options.length - 1 ; i >= 0 ; i -- ){
		fromObj.remove(i);
	} 
}

/********
*移动下拉列表中所有选中项

*@fromObj 要移动的列表对象
*&toObj 移动到的列表对象
*************/
function MoveSelectedOption( fromObj , toObj ){

	///alert( fromObj.selectedIndex )   ;
	
	var toOp ;
	var fromOp
	var i = 0 ;
	for( i = 0 ; i < fromObj.options.length ; i ++ ){
		
		fromOp = fromObj.options( i );
		if( !fromOp.selected  ) continue ;
		toOp = createOption( fromOp.text , fromOp.value  ) 
		toObj.add( toOp ) ;
	}

	for( i =  fromObj.options.length - 1 ; i >= 0 ; i -- ){
		fromOp = fromObj.options( i );
		if( fromOp.selected  ) fromObj.remove(i);
	} 
}

//关闭窗口或后退
function CloseBack()
{
    if( top.location != self.location ){
	    history.back();
    }
    else{
	    window.close();
    }
}
function pageGoBack()
{
   window.history.go(-1);
}
//控件的绑定
function ControlBind( controlsString,propertyString)
{
    if ( controlsString == "" || propertyString == "" )return;
    if ( controlsString == null || propertyString == null )return;
    var controlArray = controlsString.split(",");
    var propertyArray = propertyString.split(",");
    var contorl;
    //var controlArray = new Array();
    for( var i = 0; i < controlArray.length; i++ )
    {
        //controlArray.push = GetElementByIdOnServerControl( controlArrayString[i] );
        contorl = GetElementByIdOnServerControl( controlArray[i] );
        contorl.value = getValueForArray( propertyArray,controlArray[i] )
    }
}
//根据属性名称返回属性集合中对应的值
function getValueForArray( propertyArray,propertyNameString )
{
    for( var j = 0; j < propertyArray.length; j++ )
    {
         var valueArray = propertyArray[j].split("=");
         if( propertyNameString.toLowerCase() == valueArray[0].toLowerCase() )
         {
			return valueArray[1];
		 }
    }
    return "";
}
//亲空所有text控件
function ClearTextBox()
{
    for( var i = 0; i < document.all.length; i++ )
    {
            
       if( document.all[i].type == "text" && document.all[i].readOnly == false)
       {
            document.all[i].value="";
       }
     }
}
//获得所有控件的ID和对应的值，控件之间“，”号相隔
function GetAllControlValue()
{
    var outStr=""
    for( var i = 0; i < document.all.length; i++ )
    {
         outStr += document.all[i].id + "=" + document.all[i].value +",";
     }
     return outStr;
}
//清空select
function ClearSelect(select)
{
    if( select.innerHTML != null )
       select.innerHTML="";
}
 //填充枝到select控件,格式为"textdengYuvaluefenGetextdengYuvalue"
function fillSelect( textAndName,select)
{
    if ( textAndName == null || textAndName == "")return;
    
    var propertyArray  = textAndName.split("fenGe");
    var array;
   for( var i = 0; i < propertyArray.length; i++ )
   {
        array = propertyArray[i].split("dengYu");
	    select.add(CreateOption(array[0],array[1]));
    }
 }
 //序列化选择框
    function SerializeSelect(select)
    {
        var s ="";
        var fromOp;
        for( i = 0 ; i < select.options.length ; i ++ )
        {
		    fromOp = select.options( i );
		    s+=fromOp.text + "dengYu" + fromOp.value;
            if( i != select.options.length-1)
            {
                s+="fenGe";
            }
	    }
	    return s;
    }
//根据列名和列的值在gridView上找到第1条匹配的row
 function findByIdOnGridView( GridViewName,ColmunName,value)
{
    var table = GetElementByIdOnServerControl( GridViewName );
    return FindOnTable(table,ColmunName,value);
}

 //返回整行
 function FindOnTable(table,ColmunName,value)
 {
    var rows = 	table.rows;
    var ColumnNumber = 0;
    if ( rows.length <1 ) return;
    var str="";
    //找到ColmunName 对应的列是第几排；
    for( var i = 0; i < rows[0].cells.length; i++ )
    {
        if(ColmunName.toLowerCase() ==  rows[0].cells[i].innerText.toLowerCase()  )
        {
            ColumnNumber = i;
            break;
         }
     } 
    for( var i = 1; i < rows.length; i++ )
    {
        if( value ==  rows[i].cells[ColumnNumber].innerText )
            return rows[i];
    }
}
 
function FindRowNumOnTable(table,ColmunName,value)
 {
    value = value.trim();
    ColmunName = ColmunName.trim();
    var rows = 	table.rows;
    var ColumnNumber = 0;
    if ( rows.length <1 ) return;
    var str="";
    //找到ColmunName 对应的列是第几排；
    for( var i = 0; i < rows[0].cells.length; i++ )
    {
        if(ColmunName.toLowerCase() ==  rows[0].cells[i].innerText.toLowerCase()  )
        {
            ColumnNumber = i;
            break;
         }
     } 
    for( var i = 1; i < rows.length; i++ )
    {
        if( value ==  rows[i].cells[ColumnNumber].innerText.trim() )
            return i;
    }
}
 //显示控件
function show(controlID)
{
    GetElementByIdOnServerControl( controlID ).style.display="";
}
//隐藏控件
function hidden(controlID)
{
    GetElementByIdOnServerControl( controlID ).style.display="none";
}
//是否是整数
function isInt ( value )
{
    return value == parseInt(value);
}
//替换最末尾匹配的字符，oldStr 要被替换的字符传，新的用来取代的字符传
function TrimEnd(str,oldStr,newStr) 
{
    if(str=="")return str;
    var index = str.indexOf(oldStr,str.length-oldStr.length);
    if(index>-1)
    {
        return str.substr(0,str.length-oldStr.length) + newStr;
    }
    return str;
}
//是否在字符串数组中存在，strList为字符串，比如 "abc,bca"
function IsExist(strList,value)
{
    if(strList== undefined)return false;
    var array = strList.split(",");
    for(var i=0;i<array.length;i++)
    {
        if(value.toLowerCase() == array[i].toLowerCase())
            return true;
     }
     return false;
} 	
function IsNumber(str)
{ 
    if(str == undefined)return false;
    str = str.trim();
    if(str=='')return false; 
    var re =/^(-?\d+)(\.\d+)?$/; 
    if(!re.test(str))
    { 
        return false;
    }
    return true;
}
//保留几位数
if(!Number.prototype.toFixed)   
{ Number.prototype.toFixed=   function(num)   
  {with(Math)return   round(this.valueOf()*pow(10,num))/pow(10,num);   
  }   
}
//找到父控件
function findParent(control,tagName)
{
    var myParent = control.parentNode;
    if(myParent.tagName.toUpperCase() == tagName.toUpperCase())
    {
        return myParent;
    }
    else
    {
        return findParent(myParent,tagName);
    }
}

//得到Radios的值
function getRadiosValue(radiosId)
{
    var radio = document.getElementById(radiosId);
    for(i=0;i<radio.all.length;i++)
    {
        if(radio.all[i].type ="radio")
        {
            if( radio.all[i].checked)
            {
                return radio.all[i].value;
            }
        }
    }
    return null;
}

