// JavaScript Document
function $(id){
  var obj = typeof(id)=="object" ? id : document.getElementById(id);
  return obj
}

function $$(className,oBox) { 
//适用于获取某个HTML区块内部含有某一特定className的所有HTML元素 
 oBox = $(oBox)
 this.d= oBox || document; 
 var children = this.d.getElementsByTagName('*') || document.all; 
 var elements = new Array(); 
 for (var ii = 0; ii < children.length; ii++) { 
  var child = children[ii]; 
  var classNames = child.className.split(' '); 
  for (var j = 0; j < classNames.length; j++) { 
   if (classNames[j] == className) { 
    elements.push(child); 
    break; 
   } 
  } 
 } 
 return elements; 
} 

//根据ID返回指定表单项名
function $F(id){
       var obj = typeof(id)=="object" ? id : $(id);
	   var fvalue = obj.value;
	   return fvalue;
	}
/*
Hide show
id:对象ID或对象本身
返回:没
作用:隐藏显示指定对象
*/
function HS(id){
  var obj = typeof(id)=="object" ? id : $(id);
  if(obj.style.display==""){
    obj.style.display="none"
  }else{
    obj.style.display=""
  }
}

/*
get Parameter
name:参数名
返回:参数值
作用:取得地址栏指定参数值(未完成)
*/
function GP(name){
//C:\Documents and Settings\lwf\桌面\Untitled-2.htm?na=45&na=45
  var s,e,soKey
  var href = window.location.href
  href = String(href)
  alert(href)
  //href = "C:\Documents and Settings\lwf\桌面\Untitled-2.htm?aa=yy&na=lwf0757&yy=aa"
  //alert('?na="')
  if(href.indexOf('?na=')==-1&&href.indexOf('&na=')==-1){
    return null
  }else{
    if(href.indexOf('?na=') != -1){
	  if(href.indexOf('?na=\'') != -1){
	    soKey = "?na=\'"
	    s = href.indexOf(soKey)
		s = s + soKey.length
		e = href.indexOf('\'',s)
		return href.substring(s,e)
	  }else{
	    soKey = "?na="
	    s = href.indexOf(soKey)
		s = s + soKey.length
		e = href.indexOf('&',s)
		if(e==-1){
		  e = href.length
		  return href.substring(s,e)
		}else{
		  return href.substring(s,e)
		}
	  }
	}
	if(href.indexOf('&na=') != -1){
	  if(href.indexOf('&na=\'') != -1){
	    soKey = "&na=\'"
		s = href.indexOf(soKey)
		s= s + soKey.length
		e = href.indexOf("\'",s)
		return href.substring(s,e)
	  }else{
	    soKey = "na="
		s = href.indexOf(soKey)
		s= s + soKey.length
		e = href.indexOf("&",s)
		if(e==-1){
		  e = href.length
		  return href.substring(s,e)
		}else{
		  return href.substring(s,e)
		}
	  }
	}
  }
  /*
  is = href.indexOf('?na="')
  if(is == -1){
    is = href.indexOf('?na=')
	if(is == -1){
	  is = href.indexOf('&na="')
	  if(is == -1){
	    is = href.indexOf('&na=')
		if(is == -1){
		 return null
		}else{
		  //找到'&na='
		}
	  }else{
	    //找到'&na="'
	  }
	}else{
	  //找到'?na='
	}
  }else{
    //找到'?na="'
  }
  */
}
//向指定对象追加对象返回该对象的语句柄
/*
get Element
type:建立对象类型
id:追加对象ID或追加对象本身
返回:新建对象语句柄
作用:新建对象并追加到指定对象返回新建对象语句柄
*/
function CE(type,id){
  if(!type) return;
  if(!id) id = document;
  var obj = typeof(id)=="object"?id:$(id);
  var c_obj = document.createElement(type);
  return obj.appendChild(c_obj);
}

function SA(id,array){

}
//取对象的属性值get attribute
function GA(id,attr){
 obj = $(id)
 if ( obj == null ) { return ""; }
 return obj.getAttribute( attr );
}
// append row to table
function append_row( table, row ) {
	if ( table==null || row=="" ) {
		return;
	}
	table.insertRow( table.rows.length ).insertCell(0).innerHTML = row;
}
// append option to select
function append_select( selection, text, value ) {
	var new_opt = new Option( text, value, false, false );
	selection.options.add( new_opt );
}
// read radio selected value
function read_radio( radio ){
	for( var i=0; i<radio.length; i++ ) {
		if ( radio[i].checked ) {
			return radio[i].value;
		}
	}
	return "";
}
// set radio selected value
function set_radio( radio, value ){
	for( var i=0; i<radio.length; i++ ) {
		if ( radio[i].value == value ) {
			radio[i].checked = true;
		}
	}
}
// append random param suffix在地址后面增加一个随机数
function random_tag( url ) {
	var now = new Date();
	var seconds = Math.floor( now.getTime()/1000 );
	if ( url.indexOf("?") == -1 ) {
		return url + "?random_tag_param=" + seconds;
	} else {         
		return url + "&random_tag_param=" + seconds;
	}
}
// trim string
function trim( s ) {
	if ( s==null || s=="" ) {
		return "";
	}
	var Str = new String( s );
	var newstr = Str.replace( /^\s*/, "" );
	return ( newstr.replace(/\s*$/,"") );
}
// uri encode
function uri_encode( str ) {
	if ( str==null || str=="" ) {
		return "";
	}
	var toescape = ";/?:@&=+ \"#%<>'`[],~!$^(){}|\\";
	var newstr="", chr="";
	for ( var i=0; i<str.length; i++ ) {
		chr = str.charAt(i);
		if ( toescape.indexOf(chr) == -1 ) {
			newstr += chr;
		} else {
			newstr += escape( chr );
		}
	}
	return newstr;
}
// push elements to array, replace Array.push() in IE5
function push_array( array, item ) {
	array[array.length] = item;
}
// remove beginning element from array, replace Array.shift() in IE5
function shift_array( array ) {
	if ( array.length < 2 ) {
		array.length = 0;
		return;
	}
	for ( var i=0; i<array.length-1; ++i ) {
		array[i] = array[i+1];
	}
	--array.length;
}
// strip repeated <br>
function strip_enter( str ) {
	var strip_str = "";
	while( strip_str != str ) {
		strip_str = str;
		str = strip_str.replace( /<br><br>/ig, "<br>" );
	}
	return str;
}
// get objects list by tage name取指定标签的所有name值返回数组
function tag_objs( tag, name ) {
	if ( tag=="" || name=="" ) {
		return null;
	}
	var elem = document.getElementsByTagName( tag );
	var list = new Array();
	for( i=0,iarr=0; i<elem.length; ++i ) {
		var att = elem[i].getAttribute( "name" );
		if( att == name ) {
			list[iarr] = elem[i];
			++iarr;
		}
	}
	return list;
}

