//LesediFmAllFunctionsJavascript JavaScript Document

// Perform Client Side Form Validation for RegistrationForm
//------------Begin:Registration Form Script------------------//
var messageSent = "no";
function frmValidate()
{
	if(document.frmRegister.username.value == "")
	{
		alert("Please enter your Username");
		document.frmRegister.username.focus();
		return false;
	}
	if(document.frmRegister.propID_pass1.value == "")
	{
		alert("Please enter New Password");
		document.frmRegister.propID_pass1.focus();
		return false;
	}
	if(document.frmRegister.propID_pass2.value == "")
	{
		alert("Please confirm your password");
		document.frmRegister.propID_pass2.focus();
		return false;
	}
	if(document.frmRegister.propID_email.value == "")
	{
		alert("Please enter your email address");
		document.frmRegister.propID_email.focus();
		return false;
	}
	if(document.frmRegister.propID_firstname.value == "")
	{
		alert("Please enter your first name");
		document.frmRegister.propID_firstname.focus();
		return false;
	}
	if(document.frmRegister.propID_lastname.value == "")
	{
		alert("Please enter your last name");
		document.frmRegister.propID_lastname.focus();
		return false;
	}

	var gender = "false";
	for (i=0; i<document.frmRegister.propID_gender.length; i++) {
		if (document.frmRegister.propID_gender[i].checked) gender = "true";
	}
	if (gender == "false")
	{
		alert("Please select your gender");
		return false;
	}

	if(document.frmRegister.propID_age_group.value == "Please select...")
	{
		alert("Please select your age group");
		document.frmRegister.propID_age_group.focus();
		return false;
	}

	if(document.frmRegister.propID_province.value == "Please select...")
	{
		alert("Please select your province");
		document.frmRegister.propID_province.focus();
		return false;
	}

	/*
	propID_city
	propID_suburb	
	propID_mobile_phone
	*/
    if (!isEmailAddr(document.frmRegister.propID_email.value))
    {
		alert("Please enter a valid email address");
		document.frmRegister.propID_email.focus();
		return false;
	}
	if (document.frmRegister.propID_pass1.value != document.frmRegister.propID_pass2.value) 
	{
		alert("Please ensure that your confirm password field matches your new password field");
		document.frmRegister.propID_pass1.value = '';
		document.frmRegister.propID_pass2.value = '';
		document.frmRegister.propID_pass1.focus();
		return false;
	}
	if (messageSent == "no")
	{
		messageSent = "yes";
	    document.frmRegister.submitprofile.value='Register';
		document.frmRegister.cancel.value='';
		document.frmRegister.submit();
		return true;
	} 
}
function isEmailAddr(email)
{
	var result = false
	var theStr = new String(email)
	var index = theStr.indexOf("@");
	
	if (index > 0)
	{
		var pindex = theStr.indexOf(".",index);
		if ((pindex > index+1) && (theStr.length > pindex+1))
		result = true;
	}
	return result;
}


//------------------ End: Registration Form --------------------//

//------------------Begin: LesediFMNavigation script -------------//

function frmValidateSearch() {
		if(document.searchForm.SearchText.value == "") {

			alert("Please enter the text you want to search.");
			document.searchForm.SearchText.focus();
			return false;
		} else if (document.searchForm.SearchText.value == " ") {
			alert("Please enter the text you want to search.");
			document.searchForm.SearchText.focus();
			return false;			
		} else if (document.searchForm.SearchText.value == "  ") {
			alert("Please enter the text you want to search.");
			document.searchForm.SearchText.focus();
			return false;			
		} else {
			document.searchForm.submit();
		}
	}

//------------------ End: LesediFMNavigation Form --------------------//




