var __l = window.location.href;
var domain = __l.substring(__l.indexOf(".")+1, __l.indexOf("com")+3);

function XMLRequst(purl,method,asy){
	if(typeof method =='undefined') method = 'get';	
	if(typeof asy =='undefined') asy = true;	
	
	this.http_request = false;
	this.url=purl;
	this.createXMLRequst = function(){
			//开始初始化XMLHttpRequest对象
		if(window.XMLHttpRequest) { //Mozilla 浏览器
			this.http_request = new XMLHttpRequest();
			if (this.http_request.overrideMimeType) {//设置MiME类别
				this.http_request.overrideMimeType("text/xml");
			}
		}
		else if (window.ActiveXObject) { // IE浏览器
			try {
				this.http_request = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {				
					this.http_request = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			}
		}
		if(!this.http_request) { // 异常，创建对象实例失败
			throw new Error("不能创建XMLHttpRequest对象实例.");
			return null;
		}
		this.http_request.open(method,this.url,asy);
		return this.http_request;
	}
}

String.prototype.len=function(){   
  var str=this;   
  return  this.replace(/[^\x00-\xff]/g,'**').length   
}

String.prototype.trim = function() {
    return this.replace(/(^\s+)|(\s+$)/g, "");
}

function isNoCheck(ev){
	var ev = ev || window.event;
	
	var lastEventKeyCode=-1;
	var result=true;
	
	var keyCode = ev.keyCode || ev.which;
	
	if(keyCode!=0)lastEventKeyCode=keyCode;
	switch(lastEventKeyCode){
		case 8://Back Space
		case 16://Shift
		case 17://Ctrl
		case 18://Alt
		case 20://Caps Lock
		case 27://Esc
		case 33://Page Up
		case 34://Page Down
		case 35://End
		case 36://Home
		case 37://left
		case 38://top
		case 39://right
		case 40://down
		case 45://Insert
		case 46://Delete
		
		result=false;
			break;
			
		case 88://x
		case 67://c
			result=!ev.ctrlKey;
		break;
		
		case 0://
			break;
	}
	return result;
}
function getDocName(doctype){
	var docName;
	if(doctype=="meeting"){
			docName="会议论文";
		}else if(doctype=="magazine"){
			docName="期刊";
		}else if(doctype=="standard"){
			docName="标准";
		}else if(doctype=="patent"){
			docName="专利";
		}else if(doctype=="degreeMag"){
			docName="学位论文";
		}else if(doctype=="pic"){
			docName="图片";
		}else if(doctype=="audio"){
			docName="音频";
		}else if(doctype=="video"){
			docName="视频";
		}else if(doctype=="unofficial"){
			docName="非正式出版物";
		}else if(doctype=="book"){
			docName="图书";
		}else if(doctype=="truedata"){
			docName="实物资料";
		}
		return docName;
}


function Wa_SetImgAutoSize(img1) 
{ 
 var img=document.getElementById(img1);//获取图片
 	img.style.display = 'inline';
 	//if(img.width>720)
		//img.width=720;
		//alert(img.style.display);
		var MaxWidth = 129;//设置图片宽度界限
		var MaxHeight = 188;//设置图片高度界限
		var HeightWidth = img.offsetHeight / img.offsetWidth;//设置高宽比
		var WidthHeight = img.offsetWidth / img.offsetHeight;//设置宽高比
		if (img.readyState != "complete") 
			return false;//确保图片完全加载 
		if (img.offsetWidth > MaxWidth) {
			img.width = MaxWidth;
			img.height = MaxWidth * HeightWidth;
		}
		if (img.offsetHeight > MaxHeight) {
			img.height = MaxHeight;
			img.width = MaxHeight * WidthHeight;
		}
} 

function getObject(id){
	var obj = document.getElementById(id);
	if(obj==null){
		throw new Error(id+" , this object is null.");	
	}
	else{
		return obj; 	
	}
}
function g(id){
	return document.getElementById(id);
}

function setHtmlTag(input){
	if(typeof input=='string'){		
		input=input.replace(/</g,"&lt;");
		input=input.replace(/>/g,"&gt;");
		input=input.replace(/\r/g,"");
		input=input.replace(/\n/g,"<br/>");		
	}
	return input;
}

function getHtmlTag(input){
	if(typeof input=='string'){
		input=input.replace(/<br>/g,"\r\n");
		input=input.replace(/&lt;/g,"<");
		input=input.replace(/&gt;/g,">");
		//input=input.replace(/'/g,"\'");
		//input=input.replace(/"/g,"\"");
	}
	return input;
}

function getSampleDate(){
	var date = new Date(); 
	return date.getYear()+"-"+(date.getMonth() + 1)+"-"+date.getDate()+" "+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds();
}

function getDate(){	
	var d = new Date();
	utc = d.getTime() + (d.getTimezoneOffset() * 60000);
	nd = new Date(utc + (3600000*8));
	return nd.getYear()+"-"+(nd.getMonth() + 1)+"-"+nd.getDate();
}

function writeCookie(name,para,expires){	
	if(! (expires||false) ){
		var date = new Date();	
		date.setYear(date.getYear()+1);
		expires = date.toGMTString();
	}	
	document.cookie = name+"="+escape(para) + "; expires=" + expires+";path=/";
}

function getCookie(sName){
// cookies are separated by semicolons
	var aCookie = document.cookie.split("; ");
	for (var i=0; i < aCookie.length; i++){
	// a name/value pair (a crumb) is separated by an equal sign
		var aCrumb = aCookie[i].split("=");
		if (sName == aCrumb[0])
		return unescape(aCrumb[1]);
	}
// a cookie with the requested name does not exist
	return null;
}

// Delete the cookie with the specified name.
function delCookie(sName){
	document.cookie = sName + "=-1" + "; expires=Fri, 31 Dec 1999 23:59:59 GMT;domain="+domain;
}


/**
*获得各种高度
*/
var getPageScrollHeigth = function(){
	var yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;	
	}
	else if (document.documentElement && document.documentElement.scrollTop){   // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;					
	}
	else if (document.body) {// all other Explorers		
		yScroll = document.body.scrollTop;			
	}
	return yScroll;
}

var getPageScrollWidth = function(){
	var xScroll;
	if (self.pageXOffset) {
		xScroll = self.pageXOffset;	
	} 
	else if (document.documentElement && document.documentElement.scrollLeft){   // Explorer 6 Strict
		xScroll = document.documentElement.scrollLeft;					
	}
	else if (document.body) {// all other Explorers		
		xScroll = document.body.scrollLeft;			
	}
	return xScroll;
}

var getWindowHeight = function(){
	var windowHeight;
	if (self.innerHeight) {  // all except Explorer
		windowHeight = self.innerHeight;
	} else if (document.documentElement &&  document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowHeight = document.body.clientHeight;
	}
	return windowHeight;
}

var getWindowWidth = function(){
	var windowWidth;
	if (self.innerWidth) {  // all except Explorer
		windowWidth = self.innerWidth;
	} else if (document.documentElement &&  document.documentElement.clientWidth) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
	}
	return windowWidth;
}
/**
*删除节点元素
*/
var removeElement = function(_domObj){	
	if(_domObj.parentNode){
		_domObj.parentNode.removeChild(_domObj);		
	}
}

/**
*格式化像素值
*/
var formatPX = function(_px){
	if(parseInt(_px)==Number.NaN){
		return _px+"px";
	}
	else{return _px;}
}

var notNull = function(str){
	if(str || false)
		return str;
	else return "";
}

var formatNumber = function(str , def_val){
	if(parseInt(str)==Number.NaN){
		return def_val;
	}
	else{
		return 	parseInt(str);
	}
}

/**
*判断是否为IE
*/
var isIE=function(){
	if(window.navigator.appName.indexOf("Microsoft")!=-1)
		return true;
	else
		return false;
}


function getObjectHTML( ur , id, w , h){
	return '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+w+'" height="'+h+'" id="'+id+'">'
	+'<param name="movie" value="' + ur + '"/>'
	+'<param name="quality" value="high"/>'
	+'<param name="wmode" value="opaque" />'
	+'<param name="allowScriptAccess" value="sameDomain" />'
	+'<embed name="'+id+'" src="'+ ur + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" allowScriptAccess="sameDomain" width="'+w+'" height="'+h+'"></embed>'
	+'</object>';	
}

function getWMPlay(ur , id , w , h ,autoplay,count){
	return '<OBJECT id='+id+' codeBase=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112 type=application/x-oleobject height='+h+' standby="Loading..." width='+w+' align=baseline border=0 classid=CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6><PARAM NAME="URL" VALUE="'+ur+'"><PARAM NAME="defaultFrame" VALUE="datawindow"><PARAM NAME="playCount" VALUE="'+count+'"><PARAM NAME="autoStart" VALUE="'+(0-autoplay)+'"><PARAM NAME="volume" VALUE="50"><PARAM NAME="uiMode" VALUE="full"><PARAM NAME="windowlessVideo" VALUE="0"><PARAM NAME="enabled" VALUE="-1"><PARAM NAME="enableContextMenu" VALUE="-1"><PARAM NAME="fullScreen" VALUE="0"><embed src="'+ur+'" align="baseline" border="0" width="'+w+'" height="'+h+'" type="application/x-mplayer2" name="'+id+'" showcontrols="1" showpositioncontrols="0" showaudiocontrols="1" showtracker="1" showdisplay="0"	showstatusbar="1" autosize="0" showgotobar="0" showcaptioning="0" autostart="'+autoplay+'" autorewind="0" animationatstart="0" transparentatstart="0" allowscan="1" enablecontextmenu="1" clicktoplay="0" defaultframe="datawindow"></embed></OBJECT>';
}



//在当前位置创建一个flash对象
function writeObject( ur , id, w , h){	
	document.write(getObjectHTML(ur , id, w , h));
}

//全选
function selectall(box,checkboxid){
	var che;
	if(box.checked == false)
		che = false;
	else
		che =true;
	var checkbox = document.getElementsByName(checkboxid);
	for(var i = 0 ; i < checkbox.length ; i ++)
		checkbox[i].checked = che;
}
