function deleteBlanks_1(entry)
{
	var len = entry.length ;
	var foundBlank = 1;
	while(foundBlank == 1 && len > 0) 
	{
		var indx = entry.indexOf(" ");
		if(indx == -1) 
			foundBlank = 0 ;
		else
			entry = entry.substring(0,indx) + entry.substring(indx+1,len);
		len = entry.length;
	}
	return entry;
}

function checktel(tel,valname)
{
	val1=tel.value;
	if (val1!="")
	{
		for (var i=0;i<val1.length;i++)
		{
			var val = val1.charAt(i);
			if ((val1.length<12 ) || (i!=7 && i!=3 && (val<"0" || val>"9") ) || ( (i==3 || i==7) && val!="-" ))
			{
				alert("Please enter "+ valname + " in the format 999-999-9999");
				tel.focus();
				tel.select();
				return false;
			}
		}
	}

	return true;
}

function isTel(val1,val2,val3,valName)
{
	inv=0;
	v=val1.value+val2.value+val3.value;
	if (v!="")
	{
		if (v.length<10)
			inv=1;
		for (var i=0;i<v.length && inv==0;i++)
		{
			if ( v.charAt(i)<"0" || v.charAt(i)>"9")
				inv=1;
		}

		if (inv==1)
		{
			alert("Please enter "+ valName + " in the format 999-999-9999");
			val1.focus();
			val1.select();
			return false;
		}
	}
	return true;
}

function isEmpty_1(val,valName)

{
	if (!deleteBlanks_1(val.value))
	{
		alert(valName + " is required");
		val.focus();
		return false;	
	}

	return true;
}



function isEmail_1(val)

{
	tmp = val.value;
	if (isEmpty_1(val,"Email Address"))
	{
		if (tmp.indexOf("@")<1 || tmp.indexOf(".")<1 || tmp.indexOf(".")>eval(tmp.length)-3 || tmp.length<6)
		{
			alert("Email Address is invalid")
			val.focus();
			val.select();
			return false;	
		}
	}
	else
		return false;

	return true;
}



function redirect()
{
	if(!isEmpty_1(document.frmcontact.name1,"Name"))
		return false;

	if(document.frmcontact.name1.value == "Name")
	{
		alert("Please Enter Name");
		return false;
	}
	if(!isEmail_1(document.frmcontact.email))
		return false;
		
	if ( (!deleteBlanks_1(document.frmcontact.telephone1.value)) && (!deleteBlanks_1(document.frmcontact.telephone2.value)) && (!deleteBlanks_1(	document.frmcontact.telephone3.value)) )
	{
		alert("Phone Number is required");
		document.frmcontact.telephone1.focus();
		return false;	
	}
	if(!isTel(document.frmcontact.telephone1,document.frmcontact.telephone2,document.frmcontact.telephone3,"Phone")) 
		return false;	

	return true;

}

function checkLength(x,y)
{
	if (y.length==x.maxLength)
	{
		if(x.name=="telephone1")
			document.frmcontact.telephone2.focus();
		if(x.name=="telephone2")
			document.frmcontact.telephone3.focus();
	}
}