/*
	File: 			lostcode.js
	Description:	Lost code scripts
	Author:			Slava Karpenko @ FLOW~13 <info@flow13.com>

	Lost code routines (validation, submit, display)
*/


function doUpdateLostCode()
{
	var email = $F('lostcode_email');

	if (/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i.test(email))
		$('lostcode_submit').disabled = false;
	else
		$('lostcode_submit').disabled = true;
}

function doLostCode()
{
	var email = $F('lostcode_email');

	if (/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i.test(email))
	{
		new Ajax.Request("/store/lostcode.php", { method: "post", parameters: "email="+encodeURIComponent(email), evalScripts: true });
	}
}


//function to check empty fields

// function isEmpty(strfield1) {
// //change "field1" to your field name
// strfield1 = document.forms[0].email.value
//
//   //name field
//     if (strfield1 == "" || strfield1 == null || !isNaN(strfield1) || strfield1.charAt(0) == ' ')
//     {
//     alert("\"Email\" is a mandatory field.\nPlease amend and retry.")
//     return false;
//     }
//
//     return true;
// }


//function to check valid email address
function isValidEmail(strEmail){
  validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
  strEmail = document.forms[0].email.value;

   // search email text for regular exp matches
    if (strEmail.search(validRegExp) == -1)
   {
      alert('A valid e-mail address is required.\nPlease amend and retry');
      return false;
    }
    return true;
}


//function that performs all functions, defined in the onsubmit event handler

function check(form)){
  		if (isValidEmail(document.myLookup.email.value)){
		  return true;
		}

return false;
}