//<script>

//==========================================================
//
//==========================================================
function validate()
{
	if(!checkEmail())
		return(false);
	else if(!checkName())
		return(false);
	else if(!checkPhone())
		return(false)
	else
		return(true);
}

//==========================================================
//
//==========================================================
function checkForImage()
{
	this.form	  = document.forms["f1"];
	this.image	  = form.file.value;
	
	if(this.image.length < 4)
	{
		alert("Please select an image to upload, Thank You.");
		return(false);
	}
	else
	{
		var index	  = String(this.image).split(".");
		var lastThree = index[1];
	}
	
	switch(String(lastThree))
	{
		case "gif" : return(true);
		case "jpg" : return(true);
		case "bmp" : return(true);
		case "peg" : return(true);
	}
	
	alert("This file that you selected cannot be accepted at this time. Please select .gif, .jpg, .jpeg, or .bmp format.");
	return(false);
}

//==========================================================
//
//==========================================================
function checkEmail()
{
	this.form		= document.forms["f1"];
	var INVALID		= "Please make sure that you give us a valid email address.";
	var email		= String(this.form.email.value);
	var haveDomain	= false;
	var haveAmp		= (email.indexOf("@") > -1)
	
	if(!haveAmp)
	{	
		alert(INVALID);
		this.form.email.focus();
		return(false);
	}
	
	if(email.length < 6)
	{
		alert(INVALID);
		this.form.email.focus();
		return(false);
	}
	
	var s = email.split(".");
	s[0] = null;
	switch(s[1])
	{
		case "com" : haveDomain = true; break;
		case "net" : haveDomain = true; break;
		case "gov" : haveDomain = true; break;
		case "edu" : haveDomain = true; break;
		case "ws"  : haveDomain = true; break;
		case "tv"  : haveDomain = true; break;
		case "uk"  : haveDomain = true; break;
	}
	
	if(!haveDomain)
	{
		alert(INVALID);
		this.form.email.focus();
		return(false);
	}
	
	return(true);
}

//==========================================================
//
//==========================================================
function checkPhone()
{
	this.form  = document.forms["f1"];
	var phone = String(this.form.phone.value);
	
	if(phone.length < 10)
	{
		alert("Please enter you phone number and area code.");
		return(false);
	}
	
	for(var i=0;i<phone.length;i++)
	{
		if(isNaN(phone.charAt(i)))
		{
			alert("Please do not enter any spaces or dashed in your phone number. ex: 7777777777");
			this.form.phone.value = "";
			this.form.phone.focus();
			return(false);
		}
	}
	
	var areaCode	= phone.substr(0, 3);
	var firstThree	= phone.substr(3, 3);
	var lastFour    = phone.substr(6, 4);
	var formatPhone = "(" + areaCode + ") " + firstThree + "-" + lastFour;
	this.form.phone.value = formatPhone;
	
	return(true);
}

//==========================================================
//
//==========================================================
function checkName()
{
	this.form  = document.forms["f1"];
	var name  = String(this.form.name.value);
	
	if(name.length < 1)
		alert("Please make sure you give me your name.")
	
	return(true);
}

