﻿//Ajax类及其应用
function LogOut()
	{
	     executeJSFile("/memb/logout.aspx?action=none","DOM");
		 //document.location.reload();
	}
//Ajax类
function Ajax() {
	var xmlhttp;
	try
	{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.4.0");
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				xmlhttp = false;
			}
		}
	}
	//for firefox
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		xmlhttp = new XMLHttpRequest();
	}

	this.xmlhttp=xmlhttp;
	
	function responseIsSuccess() {
		return xmlhttp.status == undefined 
	    || xmlhttp.status == 0 
    	|| (xmlhttp.status >= 200 && xmlhttp.status < 300); 
	}
		
	this.getURL=function(url,asynchronous,callback) {
		xmlhttp.open('GET', url, asynchronous); 
		if (asynchronous) xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4){
				if(responseIsSuccess()) callback(xmlhttp.responseText);
			}
		}
		xmlhttp.send(null); 
		if (asynchronous==false) {
			if(responseIsSuccess()) callback(xmlhttp.responseText);
		}
	}
}

//执行JavaScript文件
function InsertScript(URL){
	var script;
	script=document.createElement("script");  
	script.type="text/javascript";
	script.src=URL;
	document.getElementsByTagName("head")[0].appendChild(script);
}

//创建iframe对象
function createIframe(){
	var newiframe = document.createElement("iframe");
	newiframe.src="frameSource.htm";
	newiframe.id="innerframe";
	newiframe.name="innername";
	newiframe.style.display="none";
	document.body.appendChild(newiframe);
	document.getElementById("innerframe").src="http://book.4yt.net";
}

//异步回调函数
function ProcessXML(XML){
	eval(XML);	
}

//读取JavaScript并执行
function executeJSFile(url){
	if(executeJSFile.arguments.length>1&&executeJSFile.arguments[1]=='DOM') InsertScript(url);
	else {
		var ajax=new Ajax();
		if(ajax.xmlhttp!=null) ajax.getURL(url,true,ProcessXML);	//使用Ajax执行
		else InsertScript(url);										//不支持Ajax使用script方法执行
	}
}

//检测首字母
function getFirstLetter(Name){
	var FL=document.getElementById("FL");
	var SL=document.getElementById("SL");
	if(Name.charCodeAt(0)>64&&Name.charCodeAt(0)<91) {
		FL.value=Name.charAt(0);
		SL.value=FL.value;
	}
	else if(Name.charCodeAt(0)>255) {
		executeJSFile("/getFirstLetter.aspx?" + Name);	
	}
}

function setFirstLetter(firstLetter){
	var FL=document.getElementById("FL");
	var SL=document.getElementById("SL");
	var LetterList="A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z";
	if(firstLetter.length==0) {
		FL.value="0";
		ArrayToSelect("SL",LetterList);
		SL.value=FL.value;
		SL.disabled="";
		alert("无法确定首字母，请自行选择！");
		SL.focus();
	}
	else if(firstLetter.length==1) {
		FL.value=firstLetter;
		ArrayToSelect("SL",firstLetter);
		SL.value=FL.value;
		SL.disabled="disabled";
	}
	else {
		FL.value=firstLetter.substr(0,1);
		ArrayToSelect("SL",firstLetter);
		SL.value=FL.value
		SL.disabled="";
		alert("首字为多音字，请自行选择！");
		SL.focus();
	}
}

function ArrayToSelect(Select,List){
	var ItemList = List.split(",");
	var objSelect=document.getElementById(Select);
	objSelect.length=ItemList.length;
	for(var i=0;i<ItemList.length;i++){
		var OptionItem=new Option(ItemList[i],ItemList[i]);
		objSelect.options[i+1]=OptionItem;
	}
}

function showFloatInfo(ObjID,Info){
	objDiv=createDiv(ObjID);
	if(document.all) objDiv.style.filter='alpha(opacity=80)';
	else objDiv.style.MozOpacity=0.9;
	objDiv.style.border="1px solid #000";
	objDiv.style.backgroundColor='#EEE';
	objDiv.style.padding='4px;';
	objDiv.style.textAlign='center';
	objDiv.style.width=300;
	objDiv.style.height=30;
	if(document.all){
		objDiv.style.left=document.body.scrollLeft + (document.body.clientWidth-300)/2 + "px";
		objDiv.style.top=document.body.scrollTop + (document.body.clientHeight-30)/2 + "px";
	}
	else{
		objDiv.style.left=window.pageXOffset + (document.body.clientWidth-300)/2 + "px";
		objDiv.style.top=window.pageYOffset + (document.body.clientHeight-30)/2 + "px";
	}
	
	objDiv.innerHTML=Info;
	objDiv.style.display='block';
}

function hideFloatInfo(ObjID){
	document.getElementById(ObjID).style.display='none';
}
//