﻿
if(window.navigator.userAgent.indexOf("MSIE")==-1){ //firefox innerText define
	 HTMLElement.prototype.__defineGetter__(    "innerText", 
        function(){ 
            return this.textContent; 
        } 
    ); 
    HTMLElement.prototype.__defineSetter__(    "innerText", 
        function(sText){ 
            this.textContent=sText; 
        } 
    ); 
		
}

function LTrim(str)
{
	var whitespace = new String(" \t\n\r");
	var s = new String(str);
	if (whitespace.indexOf(s.charAt(0)) != -1)
	{
		var j=0, i = s.length;
		while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
		{j++;}
		s = s.substring(j, i);
	}
	return s;
}

function RTrim(str)
{
	var whitespace = new String(" \t\n\r");
	var s = new String(str);
	if (whitespace.indexOf(s.charAt(s.length-1)) != -1)
	{
		var i = s.length - 1;
		while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
		{i--;}
		s = s.substring(0, i+1);
	}
	return s;
}

function Trim(str)
{
	return RTrim(LTrim(str));
}


String.prototype.Trim = function(){return   this.replace(/(^\s*)|(\s*$)/g,"");}   
String.prototype.Ltrim = function(){return   this.replace(/(^\s*)/g,   "");}   
String.prototype.Rtrim = function(){return   this.replace(/(\s*$)/g,   "");} 

function $$(objId)
{
	return document.getElementById(objId);	
}

function P$$(objId)
{
	var obj;
	if(parent)
	{
		obj=parent.document.getElementById(objId);
	}
	else
		obj=null;
	return obj;
}

function ZB() 
{
 this.left=0,
 this.top=0,
 this.width=0,
 this.height=0
 };
 
function getCurrentStyle(o,style)
{
   var number=parseInt(o.currentStyle[style]);
   return isNaN(number)?0:number;
}
function getComputedStyle(o,style)
{
   return parseInt(document.defaultView.getComputedStyle(o,null).getPropertyValue(style));
}
 
function GetZB(obj)
{
	var o=obj;
	var oLTWH=new ZB();
	oLTWH.width=o.offsetWidth;
	oLTWH.height=o.offsetHeight;
	oLTWH.left=o.offsetLeft;
	oLTWH.top=o.offsetTop;
	while(true)
    {
       o=o.offsetParent;
       if(o==(document.body&&null))break;
       oLTWH.left+=o.offsetLeft;
       oLTWH.top+=o.offsetTop;
    }
    return oLTWH;
}


function LoadJS(fileUrl,callback,code) 
{ 
    var oHead = document.getElementsByTagName('HEAD').item(0); 
    var oScript= document.createElement("script"); 
    oScript.type = "text/javascript";
	if(code)
	{
		oScript.charset="gb2312";
	}
	
    oScript.src=fileUrl ;  
	oHead.appendChild(oScript); 
	if(document.addEventListener)
	{
			
		oScript.onload = callback;
		oScript.onerror = callback;
		//oScript.addEventListener('onload',   LoadJsReady,   false);    
	}
	else
	{
		oScript.onreadystatechange =function(){ LoadJsReady(oScript,callback);}; 
	}

}


function LoadJsReady(obj,callBack)
{ 
	if(obj.readyState=="loaded")
	{  
		callBack();
	} 
}

function getCookie(cookieName)
{
    var cookieValue=  document.cookie.split("; "); 
	var startPos = -1;
	var str="";
	for (var i=0; i<cookieValue.length; i++)
	{
		startPos = cookieValue[i].indexOf(cookieName);
		if (startPos != 0)continue; 
		str = cookieValue[i].substring(cookieName.length+1, cookieValue[i].length);
		break;
	}
	return str;
}


function ImageResize(img,width,height)
{
	var tmpImg = new Image();
	tmpImg.src = img.src;
	var oW,oH;
	oW=tmpImg.width;
	oH=tmpImg.height;
	if(tmpImg.width>width)
	{
		img.width=width;
		img.height=oH*width/oW;
	}
	if(tmpImg.height>height)
	{
		img.height=height;
		img.width=oW*height/oH;
	}
	img.style.display= "";
}

// 注册事件
function AddEventHandler(oTarget,sEventType,fHandler)
{
	if(oTarget.addEventListener)
	{
		//alert('eDo1');
		oTarget.addEventListener(sEventType,fHandler,false);
	}
	else if(oTarget.attachEvent)
	{
		//alert('eDo2');
		oTarget.attachEvent('on'+sEventType,fHandler);
	}
	else
	{
		//alert('eDo3');
		oTarget['on'+sEventType]=fHandler;
	}
}

function SelectOption(objId,value)
{
	var obj=document.getElementById(objId);
	if(!obj)
    {
		return;
	}
	if(!value) return;
	for(var i=0;i<obj.options.length;i++)
	{
		if(obj.options[i].value==value)
		{
			obj.selectedIndex=i;
			return;
		}
	}
}
