// iPostMX 2005 - Coldfusion Community and Bulletin Board
// Copyright (C) 2004 - 2005  Cole Barksdale Applications 
// http://www.colebarksdale.com http://www.ipostmx.com
//
// This program is free software; you can redistribute it and/or modify 
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

// JavaScript Document

//VALIDATION IPOSTMX ACCOUNT
 function submitRegForm(form)
 {
 	if(form.firstName.value == null || form.firstName.value == '')
	{
		alert("First Name is Required. \n\n Ex. John");
		return false;
	}
	
	if(form.lastName.value == null || form.lastName.value == '')
	{
		alert("Last Name is Required. \n\nEx. Smith");
		return false;
	}

	if(form.address.value == null || form.address.value == '')
	{
		alert("Address is Required. \n\nEx. 123 Main Street");
		return false;
	}
	
	if(form.city.value == null || form.city.value == '')
	{
		alert("City is Required. \n\nEx. Smalltown");
		return false;
	}
	
	if(form.state.value == null || form.state.value == '')
	{
		alert("State is Required. \n\nEx. Texas OR TX");
		return false;
	}
	
	if(form.zip.value == null || form.zip.value == '')
	{
		alert("Postal Code is Required. \n\nEx. 785555");
		return false;
	}
	
	if(form.country.value == null || form.country.value == '')
	{
		alert("Country is Required. \n\nEx. USA");
		return false;
	}
	
	if(form.age.value == null || form.age.value == '' || isNaN(form.age.value))
	{
		alert("Age is Required. \n\nEx. 21");
		return false;
	}
	
	if(form.alias.value == null || form.alias.value == '')
	{
		alert("Alias is Required.");
		return false;
	}

	if(form.alias.value.indexOf( ' ' ) != -1)
	{
		alert("Alias cannot contain spaces.");
		return false;
	}

	if(special_char( form.alias.value ))
	{
		alert("Alias cannot contain special characters.");
		return false;
	}	
	
	goodEmail = validateEmail(form.email.value);
	if(!goodEmail) 
	{ 
		return false; 
	}
	
	if(form.password_a.value == null || form.password_a.value == '')
	{
		alert("Password is Required.");
		return false;
	}
	
	if(form.password_b.value == null || form.password_b.value == '')
	{
		alert("Please re-enter password.");
		return false;
	}
	
	if(form.password_a.value != form.password_b.value)
	{
		alert("Passwords must match!!");
		return false;
	}		
	
	return true;
}

//HELPER FUNCTION FOR VALIDATE EMAIL
function valid_ext ( ext ) 
	{
	var dom_ext = [".com",".net",".org",".aero",".biz",".coop",".info",".museum",".name",".pro",".edu",".gov",".int",".mil",".ac",".ad",".ae",".af",".ag",".ai",".al",".am",".an",".ao",".aq",".ar",".as",".at",".au",".aw",".az",".ba",".bb",".bd",".be",".bf",".bg",".bh",".bi",".bj",".bm",".bn",".bo",".br",".bs",".bt",".bv",".bw",".by",".bz",".ca",".cc",".cd",".cf",".cg",".ch",".ci",".ck",".cl",".cm",".cn",".co",".cr",".cu",".cv",".cx",".cy",".cz",".de",".dj",".dk",".dm",".do",".dz",".ec",".ee",".eg",".eh",".er",".es",".et",".fi",".fj",".fk",".fm",".fo",".fr",".ga",".gd",".ge",".gf",".gg",".gh",".gi",".gl",".gm",".gn",".gp",".gq",".gr",".gs",".gt",".gu",".gw",".gy",".hk",".hm",".hn",".hr",".ht",".hu",".id",".ie",".il",".im",".in",".io",".iq",".ir",".is",".it",".je",".jm",".jo",".jp",".ke",".kg",".kh",".ki",".km",".kn",".kp",".kr",".kw",".ky",".kz",".la",".lb",".lc",".li",".lk",".lr",".ls",".lt",".lu",".lv",".ly",".ma",".mc",".md",".mg",".mh",".mk",".ml",".mm",".mn",".mo",".mp",".mq",".mr",".ms",".mt",".mu",".mv",".mw",".mx",".my",".mz",".na",".nc",".ne",".nf",".ng",".ni",".nl",".no",".np",".nr",".nu",".nz",".om",".pa",".pe",".pf",".pg",".ph",".pk",".pl",".pm",".pn",".pr",".ps",".pt",".pw",".py",".qa",".re",".ro",".ru",".rw",".sa",".sb",".sc",".sd",".se",".sg",".sh",".si",".sj",".sk",".sl",".sm",".sn",".so",".sr",".st",".sv",".sy",".sz",".tc",".td",".tf",".tg",".th",".tj",".tk",".tm",".tn",".to",".tp",".tr",".tt",".tv",".tw",".tz",".ua",".ug",".uk",".um",".us",".uy",".uz",".va",".vc",".ve",".vg",".vi",".vn",".vu",".wf",".ws",".ye",".yt",".yu",".za",".zm",".zw"];
	
	for (var x = 0; x < dom_ext.length; x++) {
		if(ext == dom_ext[x]) return true;
	}
	return false;
}

//HELPER FUNCTION FOR VALIDATION
function special_char ( field ) 
	{
	for (var i = 1; i < field.length; i++) {
		var c = field.charCodeAt(i);
		if (!(c == 45 || c == 46 || (c >= 48 && c <= 57) || (c >= 64 && c <= 90) || c == 95 || (c >= 97 && c <= 122))) 
		{ 
			return true;
		}
	}
	return false;
}

//VALIDATE EMAIL FUNCTION
function validateEmail( email ) 
	{
		if(email == "" || email == null)
		{
			alert("Email address is required.");
			return false;
		}
	
		if(email.indexOf( ' ' ) != -1)
		{
			alert("Email address cannot contain spaces.");
			return false;
		}
		
		if(special_char( email ))
		{
			alert("Email address cannot contain special characters.");
			return false;
		}
	
		v_at = email.indexOf('@');
		if( v_at < 0 )
		{
			alert("Email address must contain an '@' symbol.");
			return false;
		}
	
		if(email.indexOf( '@', email.indexOf('@')+1 ) != -1)
		{
			alert("Email address cannot contain two '@' symbols.");
			return false;
		}
	
		i = email.lastIndexOf('.');
		if (i == -1)
		{
			alert("Email address must contain a '.'");
			return false;
		}
		
		if(Math.abs(v_at - i) == 1)
		{
			alert("Invalid email address, a '.' cannot follow an '@' symbol.");
			return false;
		}
	
		ext = email.slice(i, email.length);
		if(!valid_ext(ext))
		{
			alert("Domain extension on email address ( " + ext + " ) is not recognized.");
			return false;
		}
	
	return true;
}

//FORGOT PASSWORD FORM VALIDATION
function submitForgotPwd( form ) 
	{
		goodEmail = validateEmail(form.email.value);
		if(!goodEmail) 
		{ 
			return false; 
		} else {
			return true;
		}
}