
function __appendStyleSheet(doc,cssFile)
{
	var cssId=cssFile.replace(/(\/)|(\.)/g,"_"); 
		if(doc.getElementById(cssId))return;
	
	var h=doc.getElementsByTagName("HEAD")[0];
	var link = doc.getElementsByTagName("HEAD")[0].appendChild(doc.createElement("LINK"));
		link.rel	= 'stylesheet' ;
		link.type	= 'text/css' ;
		link.href	= cssFile ;
		link.id		= cssId;
}
//延迟调用函数
function __deferRun(fn,paramArr,thisObject,milliseconds)
{
	if(typeof fn=="function")
	{
		if(typeof milliseconds=="undefined")milliseconds=0;
		var win=arguments[4] || window;
		win.setTimeout(function(){
				if(paramArr)
					fn.apply(thisObject || win,[].concat(paramArr));
				else
					fn.apply(thisObject || win);	
			},
			milliseconds
		);
	}
}

function __createGUID()
{
	var guid="";
	for(var i=1;i<=32;i++)
		guid+=Math.floor(Math.random()*16.0).toString(16);
	return guid;
}

function __blankFunc(){return false;}

function __appendStyleSheet(doc,cssFile)
{
	var cssId=cssFile.replace(/(\/)|(\.)/g,"_"); if($(cssId,doc))return;
	
	var h=doc.getElementsByTagName("HEAD")[0];
	var link = doc.getElementsByTagName("HEAD")[0].appendChild(doc.createElement("LINK"));
		link.rel	= 'stylesheet' ;
		link.type	= 'text/css' ;
		link.href	= cssFile ;
		link.id		= cssId;
}

function __preventDefault(e)
{
	if(!e)
	{
		window.event.returnValue = false;
	}
	else
	{
		if(e.preventDefault)e.preventDefault();
	}
}

function ___preventDefault(e,win)
{
	e=(win ? win.event : null) || window.event || this.event;
	e.cancelBubble	= true;
	e.returnValue	= false;
	return [e.x,e.y];
}

function __getTopLevelWindow(){return window.top;}
function __getElementPosition(el,relativeWindow)
{
	var c = { X:0, Y:0 } ;
	var oWindow = relativeWindow || window ;
	var oOwnerWindow = __getElementWindow( el ) ;
	
	while(el)
	{
		var borderWidth=parseInt(el.style.borderWidth); if(isNaN(borderWidth))borderWidth=0;
		c.X += el.offsetLeft - el.scrollLeft+borderWidth;
		c.Y += el.offsetTop - el.scrollTop+borderWidth;
		if ( el.offsetParent )
			el = el.offsetParent ;
		else
		{
			if ( oOwnerWindow != oWindow )
			{
				if (el=oOwnerWindow.frameElement)
					oOwnerWindow = __getElementWindow(el) ;
			}
			else
			{
				c.X += el.scrollLeft;
				c.Y += el.scrollTop;
				break ;
			}
		}
	}
	return c ;
}

// Get the window object where the element is placed in.
function __getElementWindow( element ){return __getDocumentWindow(__getElementDocument( element ) ) ;}
function __getDocumentWindow( doc ){return doc.parentWindow || doc.defaultView ;}
function __getParentWindow( document ){return document.contentWindow ? document.contentWindow : document.parentWindow ;}
function __getElementDocument( element ){return element.ownerDocument || element.document ;}
function __getScrollPosition(relativeWindow)
{
	if(__IsIE)
	{
		var oDoc = relativeWindow.document ;
		return { X : oDoc.body.scrollLeft, Y : oDoc.body.scrollTop } ;
	}
	return { X : relativeWindow.pageXOffset, Y : relativeWindow.pageYOffset } ;
}

function __disableSelection( element )
{
	element.unselectable = 'on' ;
	
	/*var e, i = 0 ;
	while ( e = element.all[ i++ ] )
	{
		switch ( e.tagName )
		{
			case 'IFRAME' :
			case 'TEXTAREA' :
			case 'INPUT' :
			case 'SELECT' :		break ;
			default : e.unselectable = 'on' ; break;
		}
	}*/
	if(element.all)
	{
		var e,i=0,l=element.all.length;
		for(i=0;i<l;i++)
		{
			e=element.all[i];
			if(e)
			{
				e.unselectable="on";
			}
		}
	}	
}

function __getElementAscensor(element,ascensorTagNames)
{
	var e = element ;
	var lstTags = "," + ascensorTagNames.toUpperCase() + "," ;
	
	while ( e )
	{
		//if ( lstTags.indexOf( "," + e.nodeName.toUpperCase() + "," ) != -1 )
		if ( lstTags.indexOf( "," + e.nodeName.toUpperCase() + "," ) != -1 )
			return e ;

		e = e.parentNode ;
	}
	return null ;
}

function __disableContextmenu(doc,disableSelect)
{
	if(!doc)doc=window.document;
	doc.oncontextmenu=__blankFunc;
	if(disableSelect)doc.onselectstart=__blankFunc;
}
function __getScriptPath(win)
{
	if(!win)win=window;
	var url=win.location.href;
	var i=url.lastIndexOf("/");
	if(i>0)url=url.substring(0,i+1);
	win=null;
	
	return url;
}
function __getScriptName(win)
{
	if(!win)win=window;
	var url=win.location.href;
	var i=url.lastIndexOf("/");
	if(i<0) return "";
	url=url.substring(i+1,url.length);
	win=null;
	return url;
}

function __getDomainUrl(win)
{
	if(!win)win=window;
	var url=win.location.href;
	var i=url.indexOf("/",7);
	if(i>0)url=url.substring(0,i);
	win=null;
	
	return url;
}
	
function __getHost(win)
{
	if(!win)win=window;
	var str=__getDomainUrl(win);
	str=str.substring(7);
	win=null;
	return str;
}

function __sendHttpRequest(url,method,data,xmlHttp,retType)
{
	if(method=="" || !method)method="get";
	
	if(!xmlHttp)xmlHttp=__IsIE ? new ActiveXObject("MSXML2.XmlHttp") : new XMLHttpRequest();
	xmlHttp.open(method,url,false);
	if(method.toLowerCase()=="post")
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
	xmlHttp.send(data);
	return retType=="1" ? xmlHttp.responseBody : xmlHttp.responseText;
};

function __sendHttpRequestAsync(url,onreadystatechangeFunc,method,data,xmlHttp)
{
	
	if(method=="" || !method)method="get";
	
	if(!xmlHttp)xmlHttp=__IsIE ? new ActiveXObject("MSXML2.XmlHttp") : new XMLHttpRequest();
	xmlHttp.open(method,url,true);
	if(method.toLowerCase()=="post")
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
	
	xmlHttp.onreadystatechange=onreadystatechangeFunc;
		
	xmlHttp.send(data);
	
	return xmlHttp;
};

function __formatDataSize(s)
{
	var r=s,u="B";
	if(s>1024*1024)
	{
		r=s/(1024*1024);
		u="M";
	}
	else if(s>1024)
	{
		r=s/1024;
		u="KB";
	}
	return String(r).round(2)+u;
}
function __removeClass(elt,className)
{
	var arr=elt.className.split(" ");
	var s="";
	for(var i=0,l=arr.length;i<l;i++)
	{
		if(arr[i]!=className)
			s+=arr[i]+" ";
	}
	elt.className=s;
}
function __addClass(elt,className)
{
	var arr=elt.className.split(" ");
	for(var i=0,l=arr.length;i<l;i++)
	{
		if(arr[i]==className)return;
	}
	elt.className+=" "+className;
}

function __scaleImage(origWidth,origHeight,maxWidth,maxHeight,imageElt)
{
	var w=origWidth,h=origHeight,maxW=maxWidth,maxH=maxHeight;
	var scale=w/h;
	if(w>maxW || h>maxH)
	{
		if(w>maxW)
		{
			w=maxW; h=Math.floor(w/scale);
		}
		
		if(h>maxH)
		{
			h=maxH; w=Math.floor(scale*h);
		}
	}
	if(imageElt)
	{
		imageElt.height=h;
		imageElt.width=w;
	}
	return {width : w, height : h};
}
/*function __loadLocalFileInBase64(path)
{
	//创建ADO-stream对象 
	var helper=new ActiveXObject("ADODB.Stream"); 

	//创建包含默认头信息和根节点的XML文档 
	var	xmlDoc=new ActiveXObject("MSXML2.DOMDocument"); 
		xmlDoc.loadXML('<root></root>'); 
		
		//指定数据类型 
		xmlDoc.documentElement.setAttribute("xmlns:dt","urn:schemas-microsoft-com:datatypes"); 
		//创建一个新节点，设置其为二进制数据节点 
	var xmlNode=xmlDoc.createElement("localFile"); 
		xmlNode.dataType="bin.base64"; 
		//打开Stream对象，读源文件 
		helper.Type=1;//1=adTypeBinary 
		helper.Open(); 
		helper.LoadFromFile(path); 
		
		//将文件内容存入XML节点 
		xmlNode.nodeTypedValue=helper.Read(-1);//-1=adReadAll 
	
		helper.Close(); 
	
		//xmlDoc.documentElement.appendChild(xmlNode); 
		
		return xmlNode.xml;
}
//---------------------------------------------------------------------------------------
*/

function __scrollItH(elt,speed,step)
{
	elt=(typeof elt=="string") ? document.getElementById(elt) : elt;
    if(!elt)return;
    elt.innerHTML="<table cellpadding=0 cellspacing=0><tr><td><nobr>"+elt.innerHTML+"</nobr></td><td><nobr>"+elt.innerHTML+"</nobr></td></tr></table>";
    
    if(elt.clientWidth*2>=elt.firstChild.offsetWidth)
    	elt.firstChild.style.width=elt.clientWidth*2;
    
    var td2=elt.firstChild.rows[0].cells[1];
    function __scroll()
    {
        if(td2.offsetWidth-elt.scrollLeft<=0)
        	 elt.scrollLeft-=elt.scrollWidth;
        else
        	elt.scrollLeft+=step; 
    }
   
    var intId=setInterval(__scroll,speed);
    elt.onmouseover=function(){clearInterval(intId);intId=null;};
    elt.onmouseout=function(){intId=setInterval(__scroll,speed);};
}

function __scrollItV(elt,speed,step)
{
    elt.innerHTML="<div>"+elt.innerHTML+"</div><div>"+elt.innerHTML+"</div>";
    function __scroll()
    {
        if(elt.lastChild.offsetTop-elt.scrollTop<=0)
            elt.scrollTop-=elt.firstChild.offsetHeight;
        else 
        elt.scrollTop+=step;
    }

    var tid=setInterval(__scroll,speed);
        elt.onmouseover=function() {clearInterval(tid);};
        elt.onmouseout=function(){tid=setInterval(__scroll,speed);};
}
function __loadFlash(url,wmode,w,h)
{ 
/*document.write(
  '<embed src="' + url + '" wmode=' + wmode +
  ' quality="high" pluginspage=http://www.macromedia.com/go/getflashplayer type="application/x-shockwave-flash" width="' + width + 
  '" height="' + Height + '"></embed>');*/
  
  	document.write
	(
		'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+w+'" height="'+h+'">'+
		'<param name="movie" value="'+url+'">'+
		'<param name="quality" value="high">'+
		'<param name="wmode" value="transparent">'+
		'<embed src="'+url+'" width="'+w+'" height="'+h+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent"></embed>'+
		'</object>'
	);
}

function __setLinkOpenInNewWindow(doc)
{
	if(typeof doc=="undefined")doc=document;
	var arr=document.getElementsByTagName("A");
	for(var i=0;i<arr.length;i++)
	{
		var a=arr[i];
		if(a.href!="" && a.href!=null && a.href!="#" && a.href.toLowerCase().indexOf("javascript")<0)
		{
			a.target="_blank";
		}
	}
}
