var positioncounter=1;
var fullpc="";

	
function pcbuild()//creates the postal code from the 6 pc fields
	{
	fullpc=document.PersonalInformation.PC1.value + document.PersonalInformation.PC2.value + document.PersonalInformation.PC3.value + " " + document.PersonalInformation.PC4.value + document.PersonalInformation.PC5.value + document.PersonalInformation.PC6.value;
	}
	
function test(fn,fv,cap)//makes sure previous field was filled in
	{

		if (fv.length==0)
			{
			cont = confirm("WARNING!\n\n" + cap + "\n\nYou must enter valid data here!\nDo you wish to continue or cancel this quote?");
			if (cont)
				{
				//document.all.item(fn).focus();
				}
			else
				{
				parent.window.location = "http://www.printintegrity.com";
				}
			}
		else
			{
			if (fv.indexOf(' ')==0)
				{
				cont= confirm("WARNING!\n\n" + cap + ".\n\nA SPACE is not allowed as the first character in this field!\nDo you wish to continue or cancel this quote?");
				document.all.item(fn).focus();
				}
			
			}
		
	}
	
	
//			function isnumber(n)//returns true if a number, false if not
//			{
//					var okays="0123456789";
//					if (okays.indexOf(n) != -1)
//						{
//						return true;
//						}
//					else
//						{
//						return false;
//						}
//				}

var pharea = 4

function phareaclick()
	{
		pharea = 3;
	}	

function isnumber(n)//returns true if a number, false if not
	{
		if (n <=57 && n >= 48 || n == 9)
			{
			return true;
			}
		else
			{
			return false;
			}
	}

	
function selectme(fn)//moves focus to the designated field and selects all in that field
	{
	document.all.item(fn).select();
	}
	
function initme()//initializes the position counter for the telephone fields
	{
	positioncounter=1;
	}

function autotab(l,nfn,e)//makes sure the entries to the telephone fields are all numbers and tabs to next field when the current one is full
	{
	//kc=String.fromCharCode(e.keyCode);//gets the string value of the key that was pressed
	kc=(e.keyCode);//gets the charcode value of the key that was pressed
	//alert(kc);
	if (isnumber(kc))
		{
		if (positioncounter < l)
			{
			positioncounter = positioncounter + 1;
			}
		else
			{
			positioncounter = 1;
			document.all.item(nfn).focus();
			}
		
		}
	//else
		//{
		//alert("You must enter all numbers here!");
		//}
	}

function checkinputnum(e) //makes sure pressed key is a number
	{
	n=(e.keyCode);//gets the string value of the key that was pressed
	if (n <=57 && n >= 48 || n == 9)
		{
		return true;
		}
	//else
		//{
		//alert("You must enter all numbers here!");
		
		//return false;
		//}
	}


// returns true if a string contains only whitespace characters
function isblank(s)
	{
		for(var i = 0; i < s.length; i++)
			{
				var c = s.charAt(i);
				if ((c != '') && (c != '\n') && (c != '\t')) return false;
			}
		return true;
	}

// performs verification, will be invoked from the onSubmit() event handler
// the handler should return whatever this function returns


function verify(f)
	{
		var msg;
		var empty_fields = "";
		var errors = "";

// loops through elements of the form looking for text and textarea elements that don't have "optional" property defined
// then checks for fields that are empty and makes a list of them
// if any of these elements have a "min" or "max" property defined, then verify that they are numbers and that they are in the right range
// if the element has a "numeric" property defined, verify that it is a number, but don't check its range
// put together error messages for fields that are wrong

		for (var i = 0; i < f.length; i++)
			{
				var e = f.elements[i];
				if (((e.type == "text") || (e.type == "textarea")) && !e.optional) 
					{
						if ((e.value == null) || (e.value == "") || isblank(e.value))
							{
								empty_fields += "\n          " + e.name;
								continue;
							}
			
						if (e.numeric || (e.min != null) || (e.max != null))
							{
								var v = parseFloat(e.value);
								if (isNaN(v) ||
									((e.min != null) && (v < e.min)) ||
									((e.max != null) && (v < e.max))) 
										{
											errors += "- The field " + e.name + " must be a number";
											if (e.min != null)
												errors += " that is greater than " + e.min;
											if (e.max != null && e.min != null)
												errors += " and less than " + e.max;
											else if (e.max != null)
												errors += " that is less than " + e.max;
											errors += ".\n";
										}
							}
					}				
			}

// if there are any errors, display the messages, and return false to prevent the form from being
// submitted, otherwise return true

if (!empty_fields && !errors) return true;
		msg  = "_______________________________________________________\n\n"
		msg += "The quote was not processed because of the following missing data.\n"
		msg += "Please complete the quotation form and re-send.\n"
		msg += "_______________________________________________________\n\n"
		
		if (empty_fields)
			{
				msg += "- The following information is missing:"
					+ empty_fields + "\n";
				if (errors) msg += "\n";
			}
		msg += errors;
		alert(msg);
		return false;
	}

