// writen by Sadraddin Ahmed-Aziz
// validate required fields and email, and number or text
// April 2004
function validate(el,label,typ)
{
	var message ="";
	var rchk = 0;
	this.el=el;
	this.typ=typ;
	this.label=label;
	if(this.typ=="radyo")
	{
		for(var i=0;i < this.el.length;i++)
		{     
			if (this.el[i].checked)
			{
				rchk=1;
			}
		}
		if(rchk == 0)message+="- Please select of " + this.label + " options\n";
		return message;
	}
	
	if (!isBlank(this.el))// calling isBlank funtion
	{
		message+= "- " + this.label + " is required\n";
		return message;
	}
	else
	{
		switch(this.typ){
			case "email":
				message+=checkmail(this.el);
				break;
			case "numb":
				if(!isNum(this.el)) message+="- " + this.label + " should be numeric\n";
				break;
			default: message+="";
		}
		
		return message;
	}
	
	
	
}


function isNum(el)
{
	var l = el.value.length;
	var num = false;
	for(var i=0;i<l;i++)
	{
		if(el.value.charAt(i)<=49 || el.value.charAt(i)>57)
		{
		num=true;
		}
	}
		
	return num;
}

function checkmail(f) { 
		var em = f.value;
		var re =/^\w+@\w+(\.\w+)+$/;
		var mMessage ="";
		if (re.test(em))
			{
			return mMessage;
			}
			else
			{
			mMessage+= "Your e-mail could not be processed because " + f.value + " is not a valid e-mail address. Please enter a valid e-mail address and re-submit the form.\n";
			f.select();
			f.focus();
			}
			return mMessage;
}

function isBlank(s)
	{ 	
		if(s.value.length==0) return false;
		for (var i = 0; i < s.value.length; i++)
		{
			var c = s.value.charAt(i);
			if ((c != ' ') && (c != '\n') && (c != '\t'))
			{ 
				return true;
		    }
			else
			{
				return false;
			}

		}
	}
	

// JavaScript Document