<!--
//always have a sequential number after the name of each checkbox
//ie: prod1, prod2, prod2, etc....
//adjust this number to the number of checkboxes that your form contains

var checkboxnum = 8;

//this is for the number of radio buttons
var radionum = 4;

// global variable to check for validity
var retcode;

//list of fields in the form
var fieldList = new Array();

function validate_form()
{
	retcode = true;
	for (var v_field in fieldList)
		if (retcode) 
		{
			if (v_field != "state") eval(fieldList[v_field]);
		}
	if (retcode) eval(fieldList['stateregion']); 
	return retcode;
}

function jsval_custom(fieldname, alertmsg )
{
	if (document.form1.state.selectedIndex == 0 && document.form1.region.value == "") 
	{
        	alert(alertmsg);
        	document.forms[0][fieldname].focus();
        	retcode = false;
    }
    return retcode;
}


function jsval_text( fieldname, alertmsg )
{
	if (document.forms[0][fieldname].value=='')
	{
        	alert(alertmsg);
        	document.forms[0][fieldname].focus();
        	retcode = false;
    }
    return retcode;
}

function jsval_checkbox(fieldname, alertmsg)
{
	var noneselected = true;
	for (i=1; i<=checkboxnum ;i++)
	{
		//alert(fieldname+i);
		if (document.forms[0][fieldname+i].checked == true)
		{
			noneselected = false;
			retcode = true;
			i = checkboxnum + 1;
		}
	}

	if (noneselected)
	{
		i = 1;
		alert(alertmsg);
		document.forms[0][fieldname+i].focus();
		retcode = false;
	}
	return retcode;
}

function jsval_radio(fieldname, alertmsg)

{

	var noneselected = true;

	for (i=0; i<radionum; i++)

	{

	

		if (document.forms[0][fieldname][i].checked == true)

		{

			noneselected = false;

			retcode = true;

			i = radionum + 1;

		}

	}

	if (noneselected)

	{

			i = 1;

			alert(alertmsg);

			document.forms[0][fieldname][i].focus();

			retcode = false;

	}

	return retcode;

}

function jsval_select(fieldname, alertmsg)
{
	if(document.forms[0][fieldname].selectedIndex == 0)
	{
			alert(alertmsg);
			document.forms[0][fieldname].focus();
			retcode = false;
	}
	return retcode;
}


function jsval_number(fieldname, alertmsg)
{
	var fnumvalue = "document.form." + fieldname + ".value";
	retcode  = true;
	if(fnumvalue.length==0) { return false; alert(alertmsg);}
	var RefString="1234567890";
	for (Count=0; Count < fnumvalue.length; Count++)
	{
		TempChar= fnumvalue.substring (Count, Count+1);
		if (RefString.indexOf (TempChar, 0)==-1)
		{
			alert(alertmsg)
			retcode = false
			return retcode;
		}
	}
	return retcode;
}

// Use jsval_text_email to "ensure correct format" of email. Use
// jsval_text to "require" email. Note, alertmsg is optional.

function jsval_text_email(fieldname, alertmsg) 
{
	var checkTLD = 1;
	var knownDomsPat = /^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var emailPat = /^(.+)@(.+)$/;
	var specialChars= "\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars  = "\[^\\s" + specialChars + "\]";
	var quotedUser = "(\"[^\"]*\")";
	var ipDomainPat = /^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom = validChars + '+';
	var word = "(" + atom + "|" + quotedUser + ")";
	var userPat = new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat = new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray = document.forms[0][fieldname].value.match(emailPat);

	if (matchArray == null) 
	{
		/* Too many/few @'s or something; basically, this address doesn't
		even fit the general mould of a valid e-mail address. */

		document.forms[0][fieldname].focus();
		alert(alertmsg);
		retcode = false;
		return retcode;
	}
	
	var user = matchArray[1];
	var domain = matchArray[2];

	// Start by checking that only basic ASCII characters are in the strings (0-127).
	for (i=0; i<user.length; i++) 
	{
		if (user.charCodeAt(i)>127) 
		{
			document.forms[0][fieldname].focus();
			alert(alertmsg);
			retcode = false;
			return retcode;
		}
	}

	for (i=0; i<domain.length; i++) 

	{
		if (domain.charCodeAt(i)>127) 
		{
			document.forms[0][fieldname].focus();
			alert(alertmsg);
			retcode = false;
			return retcode;
		}

	}

	// See if "user" is valid 
	if (user.match(userPat) == null) 
	{
		// user is not valid
		document.forms[0][fieldname].focus();
		alert(alertmsg);
		retcode = false;
		return retcode;
	}

	/* if the e-mail address is at an IP address (as opposed to a symbolic
	host name) make sure the IP address is valid. */

	var IPArray = domain.match(ipDomainPat);
	if (IPArray != null) 
	{
		// this is an IP address
		for (var i=1;i<=4;i++) 
		{
			if (IPArray[i]>255) 
			{
				document.forms[0][fieldname].focus();
				alert(alertmsg);
				retcode = false;
				return retcode;
			}
		}
		retcode = true;
		return retcode
	}

	// Domain is symbolic name.  Check if it's valid.
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	
	for (i=0;i<len;i++) 
	{
		if (domArr[i].search(atomPat)==-1) 
		{
			alert(alertmsg);
			retcode = false;
			return retcode;
		}
	}

	/* domain name seems valid, but now make sure that it ends in a
	known top-level domain (like com, edu, gov) or a two-letter word,
	representing country (uk, nl), and that there's a hostname preceding 
	the domain or country. */

	if (checkTLD && domArr[domArr.length-1].length!=2 && 
	domArr[domArr.length-1].search(knownDomsPat)==-1) 
	{
		document.forms[0][fieldname].focus();
		alert(alertmsg);
		retcode = false;
		return retcode;
	}

	// Make sure there's a host name preceding the domain.
	if (len<2) 
	{
		document.forms[0][fieldname].focus();
		alert(alertmsg);
		retcode = false;
		return retcode;
	}

	// If we've gotten this far, everything's valid!
	retcode = true;
	return retcode;
}

//always use sequential numbering after the main name starting with "1"
// for checkboxes
fieldList['leadtype_c'] = 'jsval_radio("leadtype_c", "Please choose the type of the request.")';
fieldList['first_name'] = 'jsval_text("first_name", "Please enter your First Name.")';
fieldList['last_name'] = 'jsval_text("last_name", "Please enter your Last Name.")';
fieldList['email1'] = 'jsval_text_email("email1", "Please enter a valid email.")';
fieldList['phone_work'] = 'jsval_text("phone_work", "Please enter your phone number.")';
fieldList['refered_by'] = 'jsval_text("refered_by", "Please enter how you found 3 Media Web Solutions.")';

// -->



function MM_findObj(n, d) { //v4.01

  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {

    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}

  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];

  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);

  if(!x && d.getElementById) x=d.getElementById(n); return x;

}

//-->
