
function showLostSerialMessage(message)
{
	try
	{
	disp=document.getElementById('lostkeydisp');
	var newNode = document.createTextNode(message);
	disp.removeChild(disp.childNodes[0]);
	disp.appendChild(newNode);
	}
	catch (exception)
	{
		alert('ex:'+exception);
	}
	
}

function create_xmlhttp()
{
	var xmlhttp = null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlhttp=new XMLHttpRequest();
	}
	catch (e)
 	{
		// Internet Explorer
		try
    	{
    		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
    	}
  		catch (e)
    	{
    		try
      		{
		      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      		}
    		catch (e)
      		{
      			alert("Your browser does not support AJAX! You can't retrival your serial from this form");
			}
		}
	}

	return xmlhttp;
}


function xmlhttpreadystatechange_handler()
{ 
//FONTOS: IE6-nal nem lehet a this-t hasznalni.
	try
	{
 	if ( xmlhttp.readyState == 4 && xmlhttp.status == 200 )
 	{
		showLostSerialMessage("Loaded");
  		if ( xmlhttp.responseText != null ) 
  		{
  			if ( xmlhttp.responseText == 'ok')
  			{
			showLostSerialMessage("Contacting the resender center...");
			}
			else
			{
  			showLostSerialMessage( xmlhttp.responseText);
  			}
  		}
  	}
 	else if (xmlhttp.readyState == 4 && xmlhttp.status != 200) 
 	{
		showLostSerialMessage("Failed to connect to resender center.");
	}
	else
	{
//		showLostSerialMessage("status:"+xmlhttp.status+"  readystate:"+xmlhttp.readyState);
		showLostSerialMessage("Contacting the resender center...");

	}
	}
	catch (exception)
	{
		showLostSerialMessage("Serial request error");
	
	}
}

function is_valid_email(email)
{
	return /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email);
	
}

function resend_serial()
{

	email=document.getElementById("emailforresend");
	if ( email == null || ! is_valid_email(email.value) )
	{
		showLostSerialMessage("Invalid email");
		return;
	}
	
	xmlhttp=create_xmlhttp();
	showLostSerialMessage("Loading...");
	if ( xmlhttp != null)
	{
		
		xmlhttp.onreadystatechange = xmlhttpreadystatechange_handler;
		xmlhttp.open("GET","/wp-content/plugins/binarynights/tools/resendlostserial.php?data="+email.value,true);
		xmlhttp.send(null);
	}
}


function foo()
{
	alert('foo');
}

function initLostSerial() {
	var lsbutton=document.getElementById('lostserial_button');
	if ( lsbutton!=null)
	{
		lsbutton.onclick=function(){resend_serial();}
	}
}



if (window.addEventListener) {
	window.addEventListener("load",initLostSerial,false);
} else if (window.attachEvent) {
	window.attachEvent("onload",initLostSerial);
} else {
	if (typeof window.onload != 'function') {
	window.onload = function() {initLostSerial();}
	} else
	{
		oldonload=window.onload;
		window.onload = function() {oldonload();initLostSerial();}
	}
}



