

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~      Function OrderForm()     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


function ContForm()
{
	var oForm = "document.forms.ContactForm";		if(eval(oForm).Name.value.replace( / /g, "") == "")	{		alert("Please Enter Name!");		eval(oForm).Name.focus();		return false;	}		
	if(eval(oForm).Address.value.replace( / /g, "") == "")	{		alert("Please Enter Address!");		eval(oForm).Address.focus();		return false;	}
	
	if(eval(oForm).City.value.replace( / /g, "") == "")	{		alert("Please Enter City!");		eval(oForm).City.focus();		return false;	}
	
	if(eval(oForm).State.value.replace( / /g, "") == "")	{		alert("Please Enter State!");		eval(oForm).State.focus();		return false;	}
	
	if(eval(oForm).Zip.value.replace( / /g, "") == "")	{		alert("Please Enter Zip!");		eval(oForm).Zip.focus();		return false;	}
		if (!validZIP(eval(oForm).Zip.value))		{		eval(oForm).Zip.focus();		return false;		}
	
	if(eval(oForm).Phone.value.replace( / /g, "") == "")	{		alert("Please Enter Phone!");		eval(oForm).Phone.focus();		return false;	}
		if (!checkUSPhone(eval(oForm).Phone))		{			eval(oForm).Phone.focus();			return false;		}
		
	if (eval(oForm).Fax.value.replace( / /g, "") != "" && !checkUSPhone(eval(oForm).Fax))	{		eval(oForm).Fax.focus();		return false;	}
		
	if(eval(oForm).Email.value.replace( / /g, "") == "")	{		alert("Please Enter Email!");		eval(oForm).Email.focus();		return false;	}
				if (isEmail(eval(oForm).Email.value)==false)		{			alert("Please enter a valid Email address, like: name@companyname.com ");			eval(oForm).Email.focus();			return false;		}  
	
		
	return true;
}







//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~      Function OrdForm()     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


function OrdForm()
{
	var oForm = "document.forms.OrderForm";		if(eval(oForm).Name.value.replace( / /g, "") == "")	{		alert("Please Enter Name!");		eval(oForm).Name.focus();		return false;	}	
	if(eval(oForm).Address.value.replace( / /g, "") == "")	{		alert("Please Enter Address!");		eval(oForm).Address.focus();		return false;	}
	
	if(eval(oForm).City.value.replace( / /g, "") == "")	{		alert("Please Enter City!");		eval(oForm).City.focus();		return false;	}
	
	if(eval(oForm).State.value.replace( / /g, "") == "")	{		alert("Please Enter State!");		eval(oForm).State.focus();		return false;	}
	
	if(eval(oForm).Zip.value.replace( / /g, "") == "")	{		alert("Please Enter Zip!");		eval(oForm).Zip.focus();		return false;	}
		if (!validZIP(eval(oForm).Zip.value))		{		eval(oForm).Zip.focus();		return false;		}
	
	if(eval(oForm).DayTelephone.value.replace( / /g, "") == "")	{		alert("Please Enter Phone!");		eval(oForm).DayTelephone.focus();		return false;	}
		if (!checkUSPhone(eval(oForm).DayTelephone))		{			eval(oForm).DayTelephone.focus();			return false;		}
		
	if (eval(oForm).Fax.value.replace( / /g, "") != "" && !checkUSPhone(eval(oForm).Fax))	{		eval(oForm).Fax.focus();		return false;	}
		
	if(eval(oForm).Email.value.replace( / /g, "") == "")	{		alert("Please Enter Email!");		eval(oForm).Email.focus();		return false;	}
				if (isEmail(eval(oForm).Email.value)==false)		{			alert("Please enter a valid Email address, like: name@companyname.com ");			eval(oForm).Email.focus();			return false;		}  
	
	
	if(!eval(oForm).AnnualReport.checked &&
		!eval(oForm).ProDevSchool.checked &&
		!eval(oForm).Principals.checked &&
		!eval(oForm).Restructure.checked &&
		!eval(oForm).ExcTeachers.checked &&
		!eval(oForm).Superintendents.checked)
	{		alert("Please Select Publication!");		eval(oForm).AnnualReport.focus();		return false;	} 
	
	//1
	if(eval(oForm).AnnualReport.checked && eval(oForm).ARquant.value.replace( / /g, "") == "")
	{
		alert("Please Enter Quantity!");		eval(oForm).ARquant.focus();		return false;	
	}
	
	if(!eval(oForm).AnnualReport.checked && eval(oForm).ARquant.value.replace( / /g, "") != "")
	{
		alert("Please Select Publication!");		eval(oForm).AnnualReport.focus();		return false;	
	}
	
	if(eval(oForm).AnnualReport.checked && eval(oForm).ARquant.value.replace( / /g, "") != "")
	{
		if(!isNumber09(eval(oForm).ARquant.value.replace( / /g, "")))		{			eval(oForm).ARquant.focus();			return false;		}
		
		if(parseInt(eval(oForm).ARquant.value.replace( / /g, ""),10) <1)		{			alert("Please Enter Valid Quantity!");			eval(oForm).ARquant.focus();			return false;		}
		
		eval(oForm).ARquant.value = parseInt(eval(oForm).ARquant.value.replace( / /g, ""),10)
	}
	//1
	
	//2		
	if(eval(oForm).ProDevSchool.checked && eval(oForm).ProDevSchoolQuant.value.replace( / /g, "") == "")
	{
		alert("Please Enter Quantity!");		eval(oForm).ProDevSchoolQuant.focus();		return false;	
	}
	
	if(!eval(oForm).ProDevSchool.checked && eval(oForm).ProDevSchoolQuant.value.replace( / /g, "") != "")
	{
		alert("Please Select Publication!");		eval(oForm).ProDevSchool.focus();		return false;	
	}
	
	if(eval(oForm).ProDevSchool.checked && eval(oForm).ProDevSchoolQuant.value.replace( / /g, "") != "")
	{
		if(!isNumber09(eval(oForm).ProDevSchoolQuant.value.replace( / /g, "")))		{			eval(oForm).ProDevSchoolQuant.focus();			return false;		}
		
		if(parseInt(eval(oForm).ProDevSchoolQuant.value.replace( / /g, ""),10) <1)		{			alert("Please Enter Valid Quantity!");			eval(oForm).ProDevSchoolQuant.focus();			return false;		}
		
		eval(oForm).ProDevSchoolQuant.value = parseInt(eval(oForm).ProDevSchoolQuant.value.replace( / /g, ""),10)
	}
	//2
	
	//3
	if(eval(oForm).Principals.checked && eval(oForm).PrincipalsQuant.value.replace( / /g, "") == "")
	{
		alert("Please Enter Quantity!");		eval(oForm).PrincipalsQuant.focus();		return false;	
	}
	
	if(!eval(oForm).Principals.checked && eval(oForm).PrincipalsQuant.value.replace( / /g, "") != "")
	{
		alert("Please Select Publication!");		eval(oForm).Principals.focus();		return false;	
	}
	
	if(eval(oForm).Principals.checked && eval(oForm).PrincipalsQuant.value.replace( / /g, "") != "")
	{
		if(!isNumber09(eval(oForm).PrincipalsQuant.value.replace( / /g, "")))		{			eval(oForm).PrincipalsQuant.focus();			return false;		}
		
		if(parseInt(eval(oForm).PrincipalsQuant.value.replace( / /g, ""),10) <1)		{			alert("Please Enter Valid Quantity!");			eval(oForm).PrincipalsQuant.focus();			return false;		}
		
		eval(oForm).PrincipalsQuant.value = parseInt(eval(oForm).PrincipalsQuant.value.replace( / /g, ""),10)
	}
	//3
	
	//4
	if(eval(oForm).Restructure.checked && eval(oForm).RestructureQuant.value.replace( / /g, "") == "")
	{
		alert("Please Enter Quantity!");		eval(oForm).RestructureQuant.focus();		return false;	
	}
	
	if(!eval(oForm).Restructure.checked && eval(oForm).RestructureQuant.value.replace( / /g, "") != "")
	{
		alert("Please Select Publication!");		eval(oForm).Restructure.focus();		return false;	
	}
	
	if(eval(oForm).Restructure.checked && eval(oForm).RestructureQuant.value.replace( / /g, "") != "")
	{
		if(!isNumber09(eval(oForm).RestructureQuant.value.replace( / /g, "")))		{			eval(oForm).RestructureQuant.focus();			return false;		}
		
		if(parseInt(eval(oForm).RestructureQuant.value.replace( / /g, ""),10) <1)		{			alert("Please Enter Valid Quantity!");			eval(oForm).RestructureQuant.focus();			return false;		}
		
		eval(oForm).RestructureQuant.value = parseInt(eval(oForm).RestructureQuant.value.replace( / /g, ""),10)
	}
	//4
	
	//5
	if(eval(oForm).ExcTeachers.checked && eval(oForm).ExcTeachersQuant.value.replace( / /g, "") == "")
	{
		alert("Please Enter Quantity!");		eval(oForm).ExcTeachersQuant.focus();		return false;	
	}
	
	if(!eval(oForm).ExcTeachers.checked && eval(oForm).ExcTeachersQuant.value.replace( / /g, "") != "")
	{
		alert("Please Select Publication!");		eval(oForm).ExcTeachers.focus();		return false;	
	}
	
	if(eval(oForm).ExcTeachers.checked && eval(oForm).ExcTeachersQuant.value.replace( / /g, "") != "")
	{
		if(!isNumber09(eval(oForm).ExcTeachersQuant.value.replace( / /g, "")))		{			eval(oForm).ExcTeachersQuant.focus();			return false;		}
		
		if(parseInt(eval(oForm).ExcTeachersQuant.value.replace( / /g, ""),10) <1)		{			alert("Please Enter Valid Quantity!");			eval(oForm).ExcTeachersQuant.focus();			return false;		}
		
		eval(oForm).ExcTeachersQuant.value = parseInt(eval(oForm).ExcTeachersQuant.value.replace( / /g, ""),10)
	}
	//5
	
	//6
	if(eval(oForm).Superintendents.checked && eval(oForm).SuperintendentsQuant.value.replace( / /g, "") == "")
	{
		alert("Please Enter Quantity!");		eval(oForm).SuperintendentsQuant.focus();		return false;	
	}
	
	if(!eval(oForm).Superintendents.checked && eval(oForm).SuperintendentsQuant.value.replace( / /g, "") != "")
	{
		alert("Please Select Publication!");		eval(oForm).Superintendents.focus();		return false;	
	}
	
	if(eval(oForm).Superintendents.checked && eval(oForm).SuperintendentsQuant.value.replace( / /g, "") != "")
	{
		if(!isNumber09(eval(oForm).SuperintendentsQuant.value.replace( / /g, "")))		{			eval(oForm).SuperintendentsQuant.focus();			return false;		}
		
		if(parseInt(eval(oForm).SuperintendentsQuant.value.replace( / /g, ""),10) <1)		{			alert("Please Enter Valid Quantity!");			eval(oForm).SuperintendentsQuant.focus();			return false;		}
		
		eval(oForm).SuperintendentsQuant.value = parseInt(eval(oForm).SuperintendentsQuant.value.replace( / /g, ""),10)
	}
	//6
	
		
	return true;
}






//________________________________________________________________________________________________
//_____________________      isNumber09     _____________________________________________________________

function isNumber09(InString)  {
        RefString="0123456789";

        for (Count=0; Count < InString.length; Count++)  {
            TempChar= InString.substring (Count, Count+1);
            if (RefString.indexOf (TempChar, 0)==-1) { 
				alert("Please enter numbers only: 0 - 9 ");
				return false;
			}
		}
        return true;
}




//________________________________________________________________________________________________
//_____________________      checkUSPhone     _____________________________________________________________

function checkUSPhone (theField, emptyOK)
{   if (checkUSPhone.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else
    {  var normalizedPhone = stripCharsInBag(theField.value, phoneNumberDelimiters)
       if (!isUSPhoneNumber(normalizedPhone, false)) 
          return warnInvalid (theField, iUSPhone);
       else 
       {  // if you don't want to reformat as (123) 456-789, comment next line out
          theField.value = reformatUSPhone(normalizedPhone)
          return true;
       }
    }
}



//________________________________________________________________________________________________
//_____________________      isEmail     _____________________________________________________________

function isEmail(string) {
    if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
        return true;
    else
        return false;
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//~~~~~~~     isZip      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~function validZIP(field) {	var valid = "0123456789-";	var hyphencount = 0;	if (field.length!=5 && field.length!=10) {		alert("Please enter your 5 digit or 5 digit+4 zip code.");		return false;	}	for (var i=0; i < field.length; i++) {		temp = "" + field.substring(i, i+1);		if (temp == "-") hyphencount++;			if (valid.indexOf(temp) == "-1") {				alert("Invalid characters in your zip code.  Please try again.");		return false;	}	if ((hyphencount > 1) || ((field.length==10) && ""+field.charAt(5)!="-")) {		alert("The hyphen character should be used with a properly formatted 5 digit+four zip code, like '12345-6789'.   Please try again.");		return false;	}}return true;}  
//---------------- valid phone ----------------
// VARIABLE DECLARATIONS

var digits = "0123456789";

// whitespace characters
var whitespace = " \t\n\r";

// decimal point character differs by language and culture
var decimalPointDelimiter = "."

// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()-./ ";

// characters which are allowed in US phone numbers
var validUSPhoneChars = digits + phoneNumberDelimiters;

// U.S. phone numbers have 10 digits.
// They are formatted as 123-456-7890 or (123) 456-7890.
var digitsInUSPhoneNumber = 10;

// CONSTANT STRING DECLARATIONS

// m = "missing"

var mPrefix = "You did not enter a value into the "
var mSuffix = " field. This is a required field. Please enter it now."

// s --- "string"

var sPhone = "Phone Number"

// i is an abbreviation for "invalid"
var iUSPhone = "This field must be a 10 digit U.S. phone number (like 415-555-1212). Please reenter it now."
// p is an abbreviation for "prompt"
var pEntryPrompt = "Please enter a "
var pUSPhone = "10 digit U.S. phone number (like 415-555-1212)."
var defaultEmptyOK = false
// Check whether string s is empty.

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}function stripCharsInBag (s, bag)

{   var i;
    var returnString = "";

    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }

    return returnString;
}function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}
function isInteger (s)

{   var i;

    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}
function reformat (s)

{   var arg;
    var sPos = 0;
    var resultString = "";

    for (var i = 1; i < reformat.arguments.length; i++) {
       arg = reformat.arguments[i];
       if (i % 2 == 1) resultString += arg;
       else {
           resultString += s.substring(sPos, sPos + arg);
           sPos += arg;
       }
    }
    return resultString;
}


function isUSPhoneNumber (s)
{   if (isEmpty(s)) 
       if (isUSPhoneNumber.arguments.length == 1) return defaultEmptyOK;
       else return (isUSPhoneNumber.arguments[1] == true);
    return (isInteger(s) && s.length == digitsInUSPhoneNumber)
}

// Notify user that contents of field theField are invalid.
// String s describes expected contents of theField.value.
// Put select theField, pu focus in it, and return false.

function warnInvalid (theField, s)
{   theField.focus()
    theField.select()
    alert(s)
    return false
}

function reformatUSPhone (USPhone)
{   return (reformat (USPhone, "", 3, "-", 3, "-", 4))
}


function checkUSPhone (theField, emptyOK)
{   if (checkUSPhone.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else
    {  var normalizedPhone = stripCharsInBag(theField.value, phoneNumberDelimiters)
       if (!isUSPhoneNumber(normalizedPhone, false)) 
          return warnInvalid (theField, iUSPhone);
       else 
       {  // if you don't want to reformat as (123) 456-789, comment next line out
          theField.value = reformatUSPhone(normalizedPhone)
          return true;
       }
    }
}

