function isValidForm( tp )
{
var blnValid = false;
if (tp==1){
	if (isFilled(document.custreg.firstname, "Please enter your first name."))
		if (isFilled(document.custreg.lastname, "Please enter your last name."))
			if (isFilled(document.custreg.email, "Please enter an email address."))
				if (isValidEmail(document.custreg.email, "Please enter an correct email address."))
						blnValid = true;
	}
else{
	if (tp==0) {
		if (isFilled(document.custreg.firstname, "Please enter your first name.") && isValidItem(document.custreg.firstname,"A"))
			if (isFilled(document.custreg.lastname, "Please enter your last name.") && isValidItem(document.custreg.lastname,"A"))
				if (isFilled(document.custreg.Address, "Please enter your Address."))
					if (isValidItem(document.custreg.PhoneExt1,"9"))
						if (isFilled(document.custreg.Phone1, "Please enter your Phone Number.") && isValidItem(document.custreg.Phone1,"9"))
							if (isValidItem(document.custreg.PhoneExt2,"9"))
							if (isValidItem(document.custreg.Phone2,"9"))
								if (isFilled(document.custreg.Card_No, "Please enter your ID Card NO."))
								blnValid = true;
	}
	else {
	if (isFilled(document.custreg.name, "Please enter your name."))
		if (isFilled(document.custreg.email, "Please enter an email address."))
			if (isValidEmail(document.custreg.email, "Please enter an correct email address."))
				blnValid = true;
		 }
	}
return blnValid;
}
function trim (obj)
{
	while(''+obj.value.charAt(0)==' ')
		obj.value= obj.value.substring(1,obj.value.length);
}
function isFilled(obj, msg)
{
 	trim(obj);
 	if ((obj.value == "")  || (obj.value == null))
	{
		if (msg != null)
		{
			alert(msg);
			obj.focus();
		}
		return false;
	} 
	else 
	{
		return true;
	}
}
function isValidEmail(obj, msg) 
{
	var locAt
	var locPeriod
	var strEmail = obj.value;
	var RegExp = /,| /gi;


	locAt = strEmail.indexOf("@");
	if ((locAt != -1) && (locAt != 0) && (locAt != (strEmail.length - 1)) && (strEmail.indexOf("@", locAt + 1) == -1))
	{
		locPeriod = strEmail.indexOf(".");
		if ((locPeriod != -1) && (locPeriod != (strEmail.length - 1)))
		{
			if (RegExp.test(strEmail))
			{
				if (msg != null)
				{
					alert(msg);
					obj.focus();
					obj.select();
					return false;
				}	
			}	
			else
				
				return true;

		}
		else
		{
			alert(msg);
			obj.focus();
			obj.select();
			return false;
		}
	}
	else
	{
		alert(msg);
		obj.focus();
		obj.select();
		return false;
	}
}

function isValidItem(ObjToGo,fpar)
{
	var str1;
	var chk_string=ObjToGo.value;
	var strlen=chk_string.length;
	var i;
	if (fpar=="A")
	{
		str1="ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz";
		err_message="Please use only alphabetic symbols [a-z]."
	}
	if (fpar=="9")
	{
		str1="0123456789 -";
		err_message="Please use only numeric symbols [0-9]."
	}
	for (i=0;i<strlen;i++)
	if ( str1.indexOf(chk_string.substr(i,1)) < 0 ) 
	{
		alert(err_message);
		ObjToGo.focus();
		return false;
	}
	return true;
}
