﻿//ajax登陆
function ajaxLogin()
{
	var name = document.getElementById('name').value;
	var email = document.getElementById('email').value;
	if(name!=''&&email!='')
	{
		//创建XMLHttpRequest对象
		var xmlhttp;
		try{
			xmlhttp=new XMLHttpRequest();
		}catch(e){
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		//创建请求结果处理程序
		xmlhttp.onreadystatechange=function(){
			if (4==xmlhttp.readyState){
				if (200==xmlhttp.status){
					var content=xmlhttp.responseText;
					if(content=="1")
					{
						alert("用户已登陆");
						
						//建立iframe其他站点请求
						CreateIframe();
					}
					else
					{
						alert("登陆失败");
					}
				}
				else
				{
					alert("登陆失败");
				}
			}
		}
		//打开连接，true表示异步提交
		xmlhttp.open("post", "/chlogin.aspx", true);
		//当方法为post时需要如下设置http头
		xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
		//发送数据
		xmlhttp.send("name="+escape(name)+"&email="+escape(email));
	}
}

//ajax退出
function ajaxLogout()
{
	//创建XMLHttpRequest对象
	var xmlhttp;
	try{
		xmlhttp=new XMLHttpRequest();
	}catch(e){
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	//创建请求结果处理程序
	xmlhttp.onreadystatechange=function(){
		if (4==xmlhttp.readyState){
			if (200==xmlhttp.status){
				var content=xmlhttp.responseText;
				if(content=="1")
				{
					alert("用户已注销");
					
					//建立iframe其他站点请求
					CreateIframe();
				}
				else
				{
					alert("注销失败");
				}
			}
			else
			{
				alert("注销失败");
			}
		}
	}
	//打开连接，true表示异步提交
	xmlhttp.open("post", "/chlogout.aspx", true);
	//当方法为post时需要如下设置http头
	xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	//发送数据
	xmlhttp.send("");
}


//加载iframe
function CreateIframe()
{
   //删除原有节点
   var oldIframe=document.getElementById("ssoIframe");
   
   if(oldIframe!=null)
   {
      oldIframe.parentNode.removeChild(oldIframe);
   }
   
    //建立新节点
    var oBody = document.getElementsByTagName('body').item(0); 

    var oIframe= document.createElement("iframe"); 

    oIframe.id = "ssoIframe"; 
    
    oIframe.style.display = "none"; 

    oIframe.src="ssoAjax.aspx"; 

    oBody.appendChild(oIframe); 
}