var XMLHttpReq;
function ifAccountExist(context,obj){
		var account = obj.value;
		var username = document.getElementById("username");
		if(account == "") {
			alert("请输入用户名!");
			username.focus();
			return;
		}	
		var url = context + "/checkAccount.do?account="+account;
		createXMLHttpRequest();	
		XMLHttpReq.open("get",url,true);
		XMLHttpReq.onreadystatechange = processResponse;
		//清除ajax缓存
		XMLHttpReq.setRequestHeader("If-Modified-Since","0"); 
		XMLHttpReq.send(null);
		}

function createXMLHttpRequest(){
	if(window.XMLHttpRequest){
		XMLHttpReq = new XMLHttpRequest();
	}
	else if(window.ActiveXObject){
		try{
			XMLHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				XMLHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(e){}
		}
	}
}

function processResponse(){
	if(XMLHttpReq.readyState == 4){
		//alert("ready == 4");
		if(XMLHttpReq.status == 200){
			startAction();
		}else{
			alert("The page can't return!");
		}
	}
}

function startAction(){
	var info = XMLHttpReq.responseText;
	if(info == 1){
		alert("用户名已经存在!");
		return;
	}else{
		alert("用户名可用!");
	}
}

function checkvote(context,type,webtype){
	var voteform = document.getElementById("voteform");
	var length = voteform.detailid.length;
	var flag = false;
	var detailid = -1;
	for(var i = 0; i < length; i++){
		if(voteform.detailid[i].checked == true){
			flag = true;
			detailid = voteform.detailid[i].value;
			break;
		}
	}
	if(!flag){
		alert("请投票!");
		return false;
	}
	var url = "";
	if(webtype == "1"){
	url = context + "/liaoli/pilotliaoli.do?method=voteActoin&type="+type+"&detailid="+detailid;
	window.open (url, "newwindow", "height=150, width=400, toolbar= no, menubar=no, scrollbars=no, resizable=no, location=no, status=no") 
	}
	if(webtype == "2"){
		url = context + "/ivv/pilotivv.do?method=voteActoin&type="+type+"&detailid="+detailid;
		//alert(url);
		window.open (url, "newwindow", "height=150, width=400, toolbar= no, menubar=no, scrollbars=no, resizable=no, location=no, status=no") 
	}
	if(webtype == "3"){
		url = context + "/coffee/pilotcoffee.do?method=voteActoin&type="+type+"&detailid="+detailid;
		window.open (url, "newwindow", "height=150, width=400, toolbar= no, menubar=no, scrollbars=no, resizable=no, location=no, status=no") 
	}
	return false;
}

function shortString(item){
	if(item.length > 17){
		document.write(item.substring(0,17) + "...");
	}else{
		document.write(item);
	}
}


//判断邮箱格式
function isEmail(strEmail) { 
if (strEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) 
return true; 
else {
	return false;
}
} 



function checkreg(){
				var username = document.getElementById("username");
				var password = document.getElementById("password");
				var repassword = document.getElementById("repassword");
				var truename = document.getElementById("truename");
				var email = document.getElementById("email");
				var phone = document.getElementById("phone");
				if(username.value == ""){
					alert("请输入用户名!");
					username.focus();
					return false;
				}
				if(username.value != ""){
					if(username.value.length < 4 || username.value.length > 15){
						alert("用户名长度在4~15位");
						username.focus();
						return false;
					}
				}
				if(password.value == ""){
					alert("请输入密码!");
					password.focus();
					return false;
				}
				if(password.value != ""){
					if(password.value.length < 4 || password.value.length > 12){
						alert("输入的密码长度在4~12位!");
						password.focus();
						return false;
					}
				}
				if(repassword.value == ""){
					alert("请输入确认密码!");
					repassword.focus();
					return false;
				}
				if(password.value != repassword.value){
					alert("两次密码不一致!");
					repassword.focus();
					return false;
				}
				if(truename.value == ""){
					alert("请输入您的真实姓名!");
					truename.focus();
					return false;
				}
				if(email.value == ""){
					alert("请输入电子邮件!");
					email.focus();
					return false;
				}
				if(email.value != ""){
					if(!isEmail(email.value)){
						alert("请输入合法的Email地址!");
						email.focus();
						return false;
					}
				}
				if(phone.value == ""){
					alert("请输入电话号码!");
					phone.focus();
					return false;
				}
			}
			
function openwin(context,type,themeid,webtype) { 
var url = "";
//alert(url);
if(webtype == "1"){
	url = context + "/liaoli/pilotliaoli.do?method=voteActoin&type="+type+"&themeid="+themeid;
	window.open (url, "newwindow", "height=150, width=400, top=0,left=0,toolbar= no, menubar=no, scrollbars=no, resizable=no, location=no, status=no") 
}
if(webtype == "2"){
	url = context + "/ivv/pilotivv.do?method=voteActoin&type="+type+"&themeid="+themeid;
	window.open (url, "newwindow", "height=150, width=400,top=500,left=600, toolbar= no, menubar=no, scrollbars=no, resizable=no, location=no, status=no") 
}
if(webtype == "3"){
	url = context + "/coffee/pilotcoffee.do?method=voteActoin&type="+type+"&themeid="+themeid;
	window.open (url, "newwindow", "height=150, width=400, top=0,left=0,toolbar= no, menubar=no, scrollbars=no, resizable=no, location=no, status=no") 
}
//写成一行 
} 
			
