// JavaScript Document
//验证验证码的JavaScript

var XMLHttp=false;
var url="/ticket/check.do?op=checkcode";
var oplx="";
String.prototype.trim = function()
{
	return this.replace(/^\s+|\s+$/g,"");
}
function createXMLHtpp()
{
	try
	{
		XMLHttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(failed)
	{
		try
		{
			XMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(failed)
		{
			XMLHttp = false;
		}
	}
	if (!XMLHttp&& typeof XMLHttpRequest != 'undefined')
	{
		XMLHttp = new XMLHttpRequest();
	}
	if (!XMLHttp)
	{
		alert("Error initializing XMLHttpRequest!");
	}
	XMLHttp.onreadystatechange =  processupdate;
	XMLHttp.open("GET", url, true);
	XMLHttp.send(null);
}
function processupdate()
{
	if (XMLHttp.readyState == 4)
	{
		if(XMLHttp.status == 200)
		{
			if ((XMLHttp.responseText).trim()!= 'ok')
			{
				alert("请输入正确的验证码！");
				document.getElementById("code").focus();
				//alert(XMLHttp.responseText);
			}
			else
			{
				if (oplx== "edituser")
				{
					document.edituser.submit();
				}
				if (oplx =="register")
				{
					document.registerForm.submit();
				}
				if(oplx=="loginform")
				{
					document.loginform.submit();
				}
			}
		}
		else
		{
			alert(XMLHttp.status+XMLHttp.statusText);
		}
	}
}
function checkcode(yzm,lx)
{
	url = "/ticket/check.do?op=checkcode&code="+yzm;
	//alert(url);
	oplx = lx;
	createXMLHtpp();
}
function checkcodereg(yzm,lx)
{
	url = "/ticket/check.do?op=checkcode&code="+yzm;
	//alert(url);
	oplx = lx;
	createXMLHtpp();
}