/* cl-hd ********************************************************************** 
 * rem: 基础
 * aut:时力科技：熊波
 * date:2007年12月06日 建立
 *    
 */ 
 
var userAgent = navigator.userAgent.toLowerCase();
var is_opera = userAgent.indexOf('opera') != -1 && opera.version();
var is_moz = (navigator.product == 'Gecko') && userAgent.substr(userAgent.indexOf('firefox') + 8, 3);
var is_ie = (userAgent.indexOf('msie') != -1 && !is_opera) && userAgent.substr(userAgent.indexOf('msie') + 5, 3);	
function $(id) {
		return document.getElementById(id);
}
String.prototype.trim = function ()
{
	return this.replace(/(^\s*)|(\s*$)/g,"");
}

String.prototype.size = function()
{
	return this.replace(/[^\x00-\xff]/g,"aa").length;
}

function $obj(id){
	
	return tryThese
	(
		function () { return  document.getElementById(name).style;  }
		,
		function () { return document.all[name].style;}
		,
		function () { return document.layers[name]; }
	);
}

var Ajax = new Object();
var tryThese = function() 
{
    var returnValue = null;
    for (var i = 0; i < arguments.length; i++)
	{
		var fun = arguments[i];
		try 
		{
			returnValue = fun();
			break;
		} catch (e) { }
    }
    return returnValue;
}
Ajax.sendRequest = function( handler , url,method,pars) 
{
	method = method||"get";
	pars = pars||null;
	var request = this.getXMLHttp();
	
	if( !request ) { window.status = "不能创建XMLHttpRequest对象实例!"; return false ;}
	request.onreadystatechange = function () 
	{
        if (request.readyState == 4) 
		{ 
            if (request.status == 200) 
			{ 
				handler( request );
            } 
        }
    };
	try
	{
		request.open(method, url , true);
		request.send(pars);
	}
	catch( e )
	{
		window.status = "发送请求异常 :  requestURL : " + url + "   exception : " + e ;
	}
}

/* 获取 XMLHttp对象 */
Ajax.getXMLHttp = function ()
{
	return tryThese
	(
		function () { return new ActiveXObject("Msxml2.XMLHTTP"); }
		,
		function () { return new ActiveXObject("Microsoft.XMLHTTP"); }
		,
		function () { return new XMLHttpRequest(); }
	);
}

var getResponseHTML = function( key , url,method,pars )
{
	Ajax.sendRequest
	(
	 	function ( response ) 
		{ 
			$(key).innerHTML = response.responseText;
		} 
		, 
		url 
		,
		method
		,
		pars		
	 );
}

/*取得带汉字的长度*/
function cnLength(str)
{
  return str.replace(/[^\x00-\xff]/g,"**").length;
}

var fixSelectBug = function ( viewSelect )
{try{
		var selects = document.getElementsByTagName("select");
		for( var i = 0 ; i < selects.length ; i++ )
		{
			selects[i].style.visibility = (viewSelect ? "visible" : "hidden");
		}
	}catch(exception){
	}
}

function divShow(id,flag) 
{     
		var x = $(id).style;  
		x.visibility = (flag) ? 'visible':'hidden';
} 


function getClientWidth(obj){
	var retValue = -1;	
	try{
		retValue = obj.getAttribute("cWidth");
	}catch(exception){	
		retValue = -1;	
	}
			
  try{
  	if(retValue == null || retValue == -1)
			retValue = obj.clientWidth+5;
			
	}catch(exception){	
			retValue = -1;	
	}	
	
	if(retValue == null || retValue == -1)
		retValue = 250;
		
		return  retValue;
	
}

function getClientHeight(obj){

	var retValue = -1;	
	try{
		retValue = obj.getAttribute("cHeight");
	}catch(exception){	
		retValue = -1;	
	}		
	
	if(retValue == null || retValue == -1)
		retValue = 150;	


	return  retValue;	
}

function mvDiv(obj){

	$("showAutoFill").style.width= getClientWidth(obj) + "px";	
	$("showAutoFill").style.height= getClientHeight(obj) + "px";
	$("closeAutoFill").style.width= 21 + "px";	
	$("closeAutoFill").style.height= 18 + "px";
	//$("AutoFill").style.height=(getClientHeight(obj) - 22)+"px"
	var x = 0;
	var y = 0;
	if(is_ie){
		x= document.body.scrollLeft + obj.getBoundingClientRect().left;
		y=document.body.scrollTop + obj.getBoundingClientRect().top + obj.clientHeight + 3;
		$("showAutoFill").style.filter = "alpha(opacity=100)";    	
	}else if(is_moz){
		x=document.body.scrollLeft + document.getBoxObjectFor(obj).x;
		y=document.body.scrollTop + document.getBoxObjectFor(obj).y + obj.clientHeight + 3;
		$("showAutoFill").style.opacity = "1.0";
	}
	


	try
	{
	$("showAutoFill").style.left = x+ "px"
	$("showAutoFill").style.top = y+"px";
	}
	catch(e)
	{
	}
	
	try
	{	
		$("closeAutoFill").style.left = (parseInt(x) + parseInt(getClientWidth(obj)) -22)+ "px"
		$("closeAutoFill").style.top = (parseInt(y)+2)+"px";
	}
	catch(e)
	{
	}
}

function openAutoFill(){
	divShow("showAutoFill",true);	
	divShow("closeAutoFill",true);	
	fixSelectBug(false);
}

function setAutoFill(context){
	$("showAutoFill").innerHTML =context;
}

function closeAutoFill(){
	divShow("showAutoFill",false);
	divShow("closeAutoFill",false);	
	fixSelectBug(true);	
}
var autoDiv =  "<div id=\"closeAutoFill\" style=\"position:absolute;width:21px;text-align:right;height:18px;z-index:101; visibility: hidden;background-color: #FFFFFF;border: 0px #000000 solid;\"><a href=javascript:closeAutoFill(); class='btnCls2' title='关闭' ></a></div>";
     autoDiv +="<DIV id=\"showAutoFill\"  style=\"height:130px; width:250px;left: 40%;background-color: #FFFFFF; border: 1px #000000 solid; font-size: 12px; padding: 0px;visibility: hidden; position: absolute;overflow: true; top: 40%;z-index:100;\"></div>";
 document.writeln(autoDiv);



function openWindow(url, name, style, width, height)
{
	t = (screen.height - height) / 2;
	l = (screen.width - width) / 2;
	return window.open(url, name, style + ",width=" + width + ",height=" + height + ",top=" + t + ",left=" + l);
}

