/////////////////////////////////////////////////////////////////////////////////////
/*
**	Filename:	name.php
**	Date:		9/1/2006
**	Author:		Troy Lutton 
**	Purpose:	To provide a purpose
**
**	Company:	Troy Lutton, ABN 42 118 890 064
**	Copyright:	Copyright (c) 2002-2006, Troy Lutton <troy.lutton@gmail.com>, All rights reserved.
**	License:	Software can not be distributed or modified without the explicit consent of the copyright holder.	
*/
/////////////////////////////////////////////////////////////////////////////////////



// a function to check the enewsletter signup form
function checkVideoUploadDetails(form)
{
	with (form)
	{
		// check the names
		if (first_name.value == "" || last_name.value == "")
		{
			window.alert("Please ensure that you have filled your first and last names");
			return false;
		}		
		// check the phone
		if (contact_number.value != "") 
		{
			// make sure that the phone and fax numbers are valid
			var stripped_phone = contact_number.value.replace(/[\(\)\.\-\ ]/g, '');
			
			// check it
			if (isNaN(parseInt(stripped_phone)))
			{
				window.alert("* The phone number appears to contain non numerical characters.\r\n* Please make sure that the home phone number is valid (numbers only).");
				return false;
			}
			else
			{
				contact_number.value = stripped_phone;	
			}
		}		
		// check the email
		if (email_address.value == "" || retyped_email_address.value == "")
		{
			window.alert("Please ensure that you have entered a valid email and a valid re-typed email address");
			return false;
		}		
		// check the email
		if (!check_valid_email(email_address.value))
		{
			window.alert("Your email appears to be invalid, please check the email you entered and try again");
			return false;
		}
		// check the email
		if (!check_valid_email(retyped_email_address.value))
		{
			window.alert("Your re-typed email appears to be invalid, please check the email you entered and try again");
			return false;
		}
		// check the email
		if (email_address.value != retyped_email_address.value)
		{
			window.alert("The email and re-typed email are not the same, please check the email you entered and try again");
			return false;
		}
		// age 
		if (age.value == "")
		{
			window.alert("Please ensure that you have selected your age");
			return false;
		}
		// check sex
		if (gender[0].checked == false && gender[1].checked == false)
		{
			window.alert("Please ensure that you have selected your gender");
			return false;
		}	
		// check the country
		if (country.value == "")
		{
			window.alert("Please ensure that you have entered your country");
			return false;
		}
		/*
		// check captcha
		if (captcha_text.value == "")
		{
			window.alert("Please ensure that you have entered the letters from the authentication image");
			return false;
		}
		*/
		if (video_comments.value == "")
		{
			window.alert("Please ensure that you have entered around 10 words about your video in the text box");
			return false;
		}

		return true;
	}
}

// a function to check the enewsletter signup form
function checkEnquiryDetails(form)
{
	with (form)
	{
		// check the names
		if (first_name.value == "" || last_name.value == "")
		{
			window.alert("Please ensure that you have filled your first and last names");
			return false;
		}		
		// check the phone
		if (contact_number.value != "") 
		{
			// make sure that the phone and fax numbers are valid
			var stripped_phone = contact_number.value.replace(/[\(\)\.\-\ ]/g, '');
			
			// check it
			if (isNaN(parseInt(stripped_phone)))
			{
				window.alert("* The phone number appears to contain non numerical characters.\r\n* Please make sure that the home phone number is valid (numbers only).");
				return false;
			}
			else
			{
				contact_number.value = stripped_phone;	
			}
		}		
		// check the email
		if (email_address.value == "" || retyped_email_address.value == "")
		{
			window.alert("Please ensure that you have entered a valid email and a valid re-typed email address");
			return false;
		}		
		// check the email
		if (!check_valid_email(email_address.value))
		{
			window.alert("Your email appears to be invalid, please check the email you entered and try again");
			return false;
		}
		// check the email
		if (!check_valid_email(retyped_email_address.value))
		{
			window.alert("Your re-typed email appears to be invalid, please check the email you entered and try again");
			return false;
		}
		// check the email
		if (email_address.value != retyped_email_address.value)
		{
			window.alert("The email and re-typed email are not the same, please check the email you entered and try again");
			return false;
		}
		// age 
		if (age.value == "")
		{
			window.alert("Please ensure that you have selected your age");
			return false;
		}
		// check sex
		if (gender[0].checked == false && gender[1].checked == false)
		{
			window.alert("Please ensure that you have selected your gender");
			return false;
		}	
		// check the country
		if (country.value == "")
		{
			window.alert("Please ensure that you have entered your country");
			return false;
		}
		/*
		// check captcha
		if (captcha_text.value == "")
		{
			window.alert("Please ensure that you have entered the letters from the authentication image");
			return false;
		}
		*/
		if (enquiry_comments.value == "")
		{
			window.alert("Please ensure that you have entered your enquiry comments or questions in the text box");
			return false;
		}

		return true;
	}
}


// function to check the signup
function checkNewsSignup(form)
{
	if (!check_valid_email(form.email_address.value))
	{
		window.alert("Please ensure that you have entered a vald email address");
		form.email_address.focus();
		return false;
	}
	return true;
}


// a function to check that an email is ok
function check_valid_email(email)
{
	// is there an email?
	if (email != "")
	{
		// build the regex filter
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		
		// test the email
		if (filter.test(email))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	else
	{
		return false;
	}
}


// show the count down
function login_counter(count)
{	
	// get the current count
	var currCount = parseInt(count); 
	
	// no negatives
	if (currCount >= 0)
	{		
		// update the screen
		document.getElementById('countdown').innerHTML = currCount;

		// decremement
		currCount -= 1;

		// wait and recall this function again
		window.setTimeout("login_counter('" + currCount + "')", 1000);
	}
}


// check the login form
function check_login(form)
{
	with (form)
	{	
		// check the names
		if (username.value == "" || password.value == "" || captcha_text.value == "")
		{
			window.alert("Please ensure that you have filled in your username, password and the authentication letters");
			return false;
		}
	}

	return true;
}

// check the login retieval
function check_login_retrieve(form)
{
	with (form)
	{
		// check that there is an email
		if (email.value == ""|| captcha_text.value == "")
		{
			window.alert("Please ensure that you have entered your email address and the authentication letters");
			return false;
		}
		// check the email
		if (!check_valid_email(email.value))
		{
			window.alert("Your email appears to be invalid, please check the email you entered and try again");
			return false;
		}
	}

	return true;
}

// function for login redirect to a url
function redirect(url)
{
	window.location.href = url;
}

function login_redirect(url)
{	
	var redir_func = "redirect('" + url + "')";

	window.setTimeout(redir_func, 5000);
}
