

//Phone validate start
var n;
var p;
var p1;
function ValidatePhone(){
p=p1.value
if(p.length==3){
	//d10=p.indexOf('(')
	pp=p;
	d4=p.indexOf('(')
	d5=p.indexOf(')')
	if(d4==-1){
		pp="("+pp;
	}
	if(d5==-1){
		pp=pp+")";
	}
	//pp="("+pp+")";
	document.Form1.txtPhone.value="";
	document.Form1.txtPhone.value=pp;
}
if(p.length>3){
	d1=p.indexOf('(')
	d2=p.indexOf(')')
	if (d2==-1){
		l30=p.length;
		p30=p.substring(0,4);
		//alert(p30);
		p30=p30+")"
		p31=p.substring(4,l30);
		pp=p30+p31;
		//alert(p31);
		document.Form1.txtPhone.value="";
		document.Form1.txtPhone.value=pp;
	}
	}
if(p.length>5){
	p11=p.substring(d1+1,d2);
	if(p11.length>3){
	p12=p11;
	l12=p12.length;
	l15=p.length;
	//l12=l12-3
	p13=p11.substring(0,3);
	p14=p11.substring(3,l12);
	p15=p.substring(d2+1,l15);
	document.Form1.txtPhone.value="";
	pp="("+p13+")"+p14+p15;
	document.Form1.txtPhone.value=pp;
	//obj1.value="";
	//obj1.value=pp;
	}
	l16=p.length;
	p16=p.substring(d2+1,l16);
	l17=p16.length;
	if(l17>3&&p16.indexOf('-')==-1){
		p17=p.substring(d2+1,d2+4);
		p18=p.substring(d2+4,l16);
		p19=p.substring(0,d2+1);
		//alert(p19);
	pp=p19+p17+"-"+p18;
	document.Form1.txtPhone.value="";
	document.Form1.txtPhone.value=pp;
	//obj1.value="";
	//obj1.value=pp;
	}
}
//}
setTimeout(ValidatePhone,100);
}
function getIt(m){
n=m.name;
//p1=document.forms[0].elements[n]
p1=m
ValidatePhone()
}
function testphone(obj1){
p=obj1.value
//alert(p)
p=p.replace("(","")
p=p.replace(")","")
p=p.replace("-","")
p=p.replace("-","")
//alert(isNaN(p))
if (isNaN(p)==true){
alert("Check phone");
return false;
}
}
//Phone validate end

function isValidPhone2(field) {
	var valid = "()-1234567890";
	var ok = "yes";
	var temp;
	
	for (var i=0; i<field.value.length; i++) {
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") ok = "no";
	}

	if (ok == "no") {
		//alert(field.value + " is an invalid phone entry!");
		alert("Please enter a valid phone number.");
		field.focus();
		field.select();
   	}
}

function isValidPhone(field) {
	var valid = "1234567890";
	var ok = "yes";
	var temp;
	
	for (var i=0; i<field.value.length; i++) {
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") ok = "no";
	}

	if (ok == "no" || field.value.length < 10){
		//alert(field.value + " is an invalid phone entry!");
		alert("Please enter a valid 10 digit phone number.");
		field.focus();
		field.select();
   	}
}

//remove spaces
function stripSpaces(field) {
var x = field.value;
	while (x.substring(0,1) == ' ') x = x.substring(1);
	while (x.substring(x.length-1,x.length) == ' ') x = x.substring(0,x.length-1);
	field.value = x;
}

function checkRequired(Action)
{

	if (document.Form1.txtName.value == "")
	{
	 alert("Please enter a contact name.");
	 
	 //document.write("<font size=3 color=red>Please enter your name.</font>");
	//setTimeout('window.location="http://www.LodoInfo.com/contact.aspx";',2000);
	
	 return false;
	}
	
	if (document.Form1.txtEmail.value == "")
	{
	 alert("Please enter your E-mail address.");
	 return false;
	}
	
	if (document.Form1.txtImageText.value == "")
	{
	 alert("Please enter the red text below.");
	 return false;
	}
	
	return true;
}



function checkRequiredForAnAddition(Action)
{		

	if (document.Form1.txtCompany.value == "")
	{
	 alert("Please enter your company name.");
	 
	 return false;
	}
	
	if (document.Form1.txtCategory.value == "")
	{
	 alert("Please select a category.");
	 
	 return false;
	}
	
	
	if (document.Form1.txtName.value == "")
	{
	 alert("Please enter a contact name.");
	 
	 return false;
	}

	if (document.Form1.txtAddress.value == "")
	{
	 alert("Please enter your street address.");
	 return false;
	}
	
	//if no city selected
	//if (document.Form1.ddlCity.options[document.Form1.ddlCity.selectedIndex].value < 1) 
	if (document.Form1.txtCity.value == "")
	{
		alert("Please enter your city.");
		return false;
	}
		
	if (document.Form1.txtZip.value == "")
	{
	 alert("Please enter your zip.");
	 return false;
	}
	
	if (document.Form1.txtPhone.value == "")
	{
	 alert("Please enter your phone number.");
	 return false;
	}
	
	if (document.Form1.txtEmail.value == "")
	{
	 alert("Please enter your E-mail address.");
	 return false;
	}
	
	if (document.Form1.txtImageText.value == "")
	{
	 alert("Please enter the red text below.");
	 return false;
	}
	
	/*
	if (document.Form1.txtMessage.value == "")
	{
	 alert("Please enter your spotlight blurb.");
	 return false;
	}
	*/
	
	return true;
}

function checkRequiredForAnInsertion(Action)
{		

	if (document.Form1.txtCompany.value == "")
	{
	 alert("Please enter your company name.");
	 
	 return false;
	}
	
	if (document.Form1.txtCategory.value == "")
	{
	 alert("Please select a category.");
	 
	 return false;
	}

	if (document.Form1.txtAddress.value == "")
	{
	 alert("Please enter your street address.");
	 return false;
	}
	
	//if no city selected
	if (document.Form1.txtCity.value == "") 
	
	{
		alert("Please select your city.");
		return false;
	}
		
	if (document.Form1.txtZip.value == "") 
	{
	 alert("Please select your zip.");
	 return false;
	}
	
	if (document.Form1.txtPhone.value == "")
	{
	 alert("Please enter your phone number.");
	 return false;
	}
	
	if (document.Form1.txtImageText.value == "")
	{
	 alert("Please enter the red text below.");
	 return false;
	}
	
	return true;
}


function isValidEmail(field)
{
	var valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@-_.";
	var temp;
	var ok = "yes";

	if (field.value == "") {
	 alert("Please enter your E-mail address.");
	field.focus();
	return false; 
	}

	for (var i=0; i<field.value.length; i++) {
	temp = "" + field.value.substring(i, i+1);
	if (valid.indexOf(temp) == "-1") ok = "no";
	}
	
	if (ok == "no") {
		alert("Please enter a valid E-mail address.");
		field.focus();
		field.select();
		return false;
   	}

	if (field.value.indexOf ('@',0) == -1 || 
	field.value.indexOf ('.',0) == -1)
	{
		alert("Please enter a valid E-mail.");
		field.select();
		field.focus();
		return false;
	}
	else
	{
		return true;
	}
}


function isValidTextField(field)
{
	var valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_ /:,.!?$";
	var temp;
	var ok = "yes";

	
	for (var i=0; i<field.value.length; i++) {
	temp = "" + field.value.substring(i, i+1);
	if (valid.indexOf(temp) == "-1") ok = "no";
	}
	
	if (ok == "no") {
		alert("Please only use the following characters " + valid);
		field.focus();
		field.select();
		//alert(field)
		return false;
   	}

	else
	{//alert(field)
		return true;
	}
}

function isValidNumericField(field)
{	
//alert('hey');
	var valid = "0123456789";
	var temp;
	var ok = "yes";
	
	
	for (var i=0; i<field.value.length; i++) {
	temp = "" + field.value.substring(i, i+1);
	if (valid.indexOf(temp) == "-1") ok = "no";
	}
	
	if (ok == "no") {
		alert("Please only use numeric characters.");
		field.focus();
		field.select();
		//alert(field)
		return false;
   	}

	else
	{//alert(field)
		return true;
	}
}
