//////////////////////////////////////////////////////////////////////////////////////////////
//account details
//////////////////////////////////////////////////////////////////////////////////////////////
function isblank(s) {
   for(var i = 0; i < s.value.length; i++) {
      var c = s.value.charAt(i);
      if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
   }
   return true;
}  
function checkemail(email_var){
	if (isblank(email_var))
	{
		alert("Please enter an email address.");
		email_var.focus();
		return false;
	}
	if (!isblank(email_var))
	{
		var valid = true;	// Initially set valid to true
		var atcount = 0;
		var email = email_var.value;
		var email_length = email_var.value.length;
		
		for (index=0; index<email_length; index++)
		{
			if ((email.substring(index,index+1) == ":") || (email.substring(index,index+1) == ",") || (email.substring(index,index+1) == "'") || (email.substring(index,index+1) == " ") )
			{
				valid = false;
			}
		}
		
		for (i=0; i<email_length; i++)
		{
			if (email.substring(i,i+1) == "@")
			{
				++atcount;
				if (email.substring(i-1,i) == ".")
					valid = false;
				if (email.substring(i+1,i+2) == ".")
					valid = false;
			}
		}
			if (email.substring(email_length-1,email_length) == "@")
			valid = false;
			if (email.substring(email_length-1,email_length) == ".")
			valid = false;
			if (email.substring(0,1) == "@")
			valid = false;
			if (email.substring(0,1) == ".")
			valid = false;
			if (email_var.value.indexOf(".") == -1)
			valid = false;
			if (atcount > 1 || atcount == 0)
			valid = false;
		
		if (!valid) 
		{
			alert("Please include a proper email address (Generally in the form 'username@hostname.domain').");
			email_var.focus();
			return false;
		}
	}
	return true;
}
//////////////////////////////////////////////////////////////////////////////////////////////
//LOGIN PAGE
//////////////////////////////////////////////////////////////////////////////////////////////
function validateLogin(obj) {
	if(!checkemail(obj.log_username)) return false;
	if (isblank(obj.log_password))
	{
		alert("Please enter password.");
		obj.log_password.focus();
		return false;
	}
return true;
}
function validateForgotPassword(obj) {
	if (isblank(obj.ret_email))
	{
		alert("Please enter email.");
		obj.ret_email.focus();
		return false;
	}
return true;
}
//////////////////////////////////////////////////////////////////////////////////////////////
//REGISTER PAGE
//////////////////////////////////////////////////////////////////////////////////////////////
function validateSubscription(obj){
    if (isblank(obj.name))
	{
		alert("Please enter your full name.");
		obj.name.focus();
		return false;
	}
	if(!checkemail(obj.email)) return false;
	if (isblank(obj.password))
	{
		alert("Please enter password.");
		obj.password.focus();
		return false;
	}
return true;
}
//////////////////////////////////////////////////////////////////////////////////////////////
//UPDATE SETTINGS
//////////////////////////////////////////////////////////////////////////////////////////////
function validateAccount(obj){
 if (isblank(obj.first_name))
	{
		alert("Please enter your first name.");
		obj.first_name.focus();
		return false;
	}
	 if (isblank(obj.last_name))
	{
		alert("Please enter your last name.");
		obj.last_name.focus();
		return false;
	}
	if(obj.gender.selectedIndex==0)
	{
		alert("Please select gender.");
		obj.gender.focus();
		return false;
	}
	if(obj.birthday_day.selectedIndex==0)
	{
		alert("Please select your birth day.");
		obj.birthday_day.focus();
		return false;
	}
	if(obj.birthday_month.selectedIndex==0)
	{
		alert("Please select your birth month.");
		obj.birthday_month.focus();
		return false;
	}
	if(obj.birthday_year.selectedIndex==0)
	{
		alert("Please select your birth year.");
		obj.birthday_year.focus();
		return false;
	}
	if(obj.location.selectedIndex==0)
	{
		alert("Please select your country of residence.");
		obj.location.focus();
		return false;
	}
	if(obj.occupation.selectedIndex==0)
	{
		alert("Please select your occupation.");
		obj.occupation.focus();
		return false;
	}
	if (isblank(obj.mobile))
	{
		alert("Please enter your mobile number.");
		obj.mobile.focus();
		return false;
	}
	if(!checkemail(obj.email)) return false;
	if (isblank(obj.password))
	{
		alert("Please enter password.");
		obj.password.focus();
		return false;
	}
return true;
}