/*
* ebb.js
*
* Purpose   : Common Javascript functions to be included in web pages.	
*
* Author		: has
* Copyright : Grey Wolf Systems
* Disclaimer: Reasonable care has been taken to ensure this program produces
*   proper input and/or output.  No warranty or guarantees are promised, either
*	  explicitly or implicitly.
*		
* Modification History
*   Date   ID  Notes
*
*/

/******************************************************************/
//Switches between two checkboxes, so that only one can be checked
//at any one time.
function checkbox_checker() {
	if (document.cs.type[0].checked) {
		document.cs.type[1].checked = false;
	}
	if (document.cs.type[1].checked) {
		document.cs.type[0].checked = false;
	}
}

/*******************************************************************/
// Spawns new window
function popPDFwindow(URL) {
	day=new Date();
	id=day.getTime();
	eval("pdfwindow=window.open(URL,'pdf','toolbars=1,scrollbars=1,location=0,statusbars=0,menubars=0,resizable=1,innerwidth=400,innerheight=300,width=400,height=300,left=100,top=100');");
}

/*******************************************************************/
// Spawns new window
function popEMAILwindow(URL) {
	day=new Date();
	id=day.getTime();
	eval("emailwindow=window.open(URL,'email','toolbars=1,scrollbars=1,location=0,statusbars=0,menubars=0,resizable=0,innerwidth=500,innerheight=200,width=500,height=200,left=100,top=100');");
}

/*******************************************************************/
// Spawns new window
function popMAPwindow(URL) {
	day=new Date();
	id=day.getTime();
	eval("map=window.open(URL,'map','toolbars=1,scrollbars=1,location=0,statusbars=1,menubars=0,resizable=0,innerwidth=725,innerheight=565,width=725,height=565,left=20,top=20');");
}

/*******************************************************************/
// Spawns new window
function popPOSTwindow(URL) {
	day=new Date();
	id=day.getTime();
	eval("postwindow=window.open(URL,'post','toolbars=1,scrollbars=1,location=0,statusbars=0,menubars=0,resizable=1,innerwidth=500,innerheight=200,width=500,height=200,left=100,top=100');");
}

/*******************************************************************/
// Populates two frames with one click
function changeFrames(newleft,newMain) {
     parent.left.location.href=newleft 
     parent.main.location.href=newMain
    
// different calls shown below 
// javascript:changeFrames('left.htm','services.asp') --> js file
// onclick="changeFrames('left.htm','home.asp')"	--> page <a>
} 

/*******************************************************************/
// Swap images
function loadimages()
{
clickme1 = new Image(88,20);
clickme1.src = "images/home.jpg";

clickme2 = new Image(88,20);
clickme2.src = "images/home_lit.jpg";

clickme3 = new Image(88,20);
clickme3.src = "images/catalog.jpg";

clickme4 = new Image(88,20);
clickme4.src = "images/catalog_lit.jpg";

clickme5 = new Image(88,20);
clickme5.src = "images/sitemap.jpg";

clickme6 = new Image(88,20);
clickme6.src = "images/sitemap_lit.jpg";

clickme7 = new Image(88,20);
clickme7.src = "images/forms.jpg";

clickme8 = new Image(88,20);
clickme8.src = "images/forms_lit.jpg";
}

loadimages();

function hiLite(imgDocID,imgObjName) {
document.images[imgDocID].src = eval(imgObjName + ".src")
}

/*******************************************************************/
// Validates email addresses
function emailCheck (emailform) {
emailform.error.value = "";
/* The following pattern is used to check if the entered e-mail address
   fits the user@domain format.  It also is used to separate the username
   from the domain. */
var emailStr=emailform.email.value
var emailPat=/^(.+)@(.+)$/
/* The following string represents the pattern for matching all special
   characters.  We don't want to allow special characters in the address. 
   These characters include ( ) < > @ , ; : \ " . [ ]    */
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
/* The following string represents the range of characters allowed in a 
   username or domainname.  It really states which chars aren't allowed. */
var validChars="\[^\\s" + specialChars + "\]"
/* The following pattern applies if the "user" is a quoted string (in
   which case, there are no rules about which characters are allowed
   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")"
/* The following pattern applies for domains that are IP addresses,
   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
   e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
/* The following string represents an atom (basically a series of
   non-special characters.) */
var atom=validChars + '+'
/* The following string represents one word in the typical username.
   For example, in john.doe@somewhere.com, john and doe are words.
   Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")"
// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
/* The following pattern describes the structure of a normal symbolic
   domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


/* Finally, let's start trying to figure out if the supplied address is
   valid. */

/* Begin with the coarse pattern to simply break up user@domain into
   different pieces that are easy to analyze. */
var matchArray=emailStr.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. */
		/*alert("Email address seems incorrect (check @ and .'s)")*/
		emailform.email.value = ""
		emailform.error.value = "Email address seems incorrect (check @ and .'s)"
		emailwindow.focus()
		return true
}
var user=matchArray[1]
var domain=matchArray[2]

// See if "user" is valid 
if (user.match(userPat)==null) {
    // user is not valid
//	  alert("The username doesn't seem to be valid.")
		emailform.email.value = ""
		emailform.error.value = "The username doesn't seem to be valid."
		emailwindow.focus()
		return true
}

/* 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) {
//    alert("Destination IP address is invalid!")
		emailform.email.value = ""
		emailform.error.value = "Destination IP address is invalid!"
		emailwindow.focus()
		return true
	    }
    }
    return true
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
//		alert("The domain name doesn't seem to be valid.")
		emailform.email.value = ""
		emailform.error.value = "The domain name doesn't seem to be valid."
		emailwindow.focus()
		return true
}

/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding 
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>3) {
   // the address must end in a two letter or three letter word.
//    alert("The address must end in a three-letter domain, or two letter country.")
		emailform.email.value = ""
		emailform.error.value = "The address must end in a three-letter domain, or two letter country."
		emailwindow.focus()
		return true
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="This address is missing a hostname!"
//    alert(errStr)
		emailform.email.value = ""
		emailform.error.value = "This address is missing a hostname!"
		emailheath.focus()
		return true
}
// If we've gotten this far, everything's valid!
return true;
}

/*******************************************************************/
// Allows forms to fire without using a submit button
function go(s)
{
//	s.homepage.value = "true"
	
	if (s.options[s.selectedIndex].value != "none")
	{
		self.location = s.options[s.selectedIndex].value
	}
	return true
}

/*******************************************************************/
//For checking the suggestions and complaints form.
function check_sc(form) {
	var type0
	var type1

	if (eval(form.EBB_Customer[1].checked) == true) {
		if (form.Customer_ID.value.length == 0) {
			alert("Please enter your 6 Digit Customer ID Number.");
			form.Customer_ID.focus();
			return (false);
		}
		if (form.Customer_ID.value.length < 6) {
			alert("The Customer ID Number should contain 6 Digits.");
			form.Customer_ID.value = "";
			form.Customer_ID.focus();
			return (false);
		}
	}
	if (form.name.value == "") {
		alert("Please enter your Name.");
		form.name.focus();
		return (false);
	 }
	if (form.city.value == "") {
		alert("Please enter a City.");
		form.city.focus();
		return (false);
	 }
	if (form.state.value.length > 4) {
		alert("Please select a State.")
		form.state.focus();
		return (false);
	 }
	if (form.zip.value == "") {
		alert("Please enter your Zip Code.");
		form.zip.focus();
		return (false);
	 }
  if (form.email.value == "") {
		alert("Please enter your Email Address.");
		form.email.focus();
		return (false);
	}
	type0 = eval(form.type[0].checked);
	type1 = eval(form.type[1].checked);
	if ((type0 == false) && (type1 == false)) {	
		alert("Please select a Type, Suggestion or Complaint.");
		return (false);
	}
	if (form.text.value == "") {
		alert("Please enter some text regarding your suggestion or complaint.");
		form.text.focus();
		return (false);
	 }
	 
	popPOSTwindow('blank.htm') 
	return (true);
}

/*******************************************************************/
//For checking the application question form.
function check_aq(form) {
	if (eval(form.EBB_Customer[1].checked) == true) {
		if (form.Customer_ID.value.length == 0) {
			alert("Please enter your 6 Digit Customer ID Number.");
			form.Customer_ID.focus();
			return (false);
		}
		if (form.Customer_ID.value.length < 6) {
			alert("The Customer ID Number should contain 6 Digits.");
			form.Customer_ID.value = "";
			form.Customer_ID.focus();
			return (false);
		}
	}
	if (form.name.value == "") {
		alert("Please enter your Name.");
		form.name.focus();
		return (false);
	 }
	if (form.city.value == "") {
		alert("Please enter a City.");
		form.city.focus();
		return (false);
	 }
	if (form.state.value.length > 4) {
		alert("Please select a State.")
		form.state.focus();
		return (false);
	 }
	if (form.zip.value == "") {
		alert("Please enter your Zip Code.");
		form.zip.focus();
		return (false);
	 }
  if (form.email.value == "") {
		alert("Please enter your Email Address.");
		form.email.focus();
		return (false);
	}
	if (form.text.value == "") {
		alert("Please enter some text regarding your application question.");
		form.text.focus();
		return (false);
	 }

	popPOSTwindow('blank.htm')
	return (true);
}

/*******************************************************************/
//For checking the product information form.
function check_pi(form) {
	if (eval(form.EBB_Customer[1].checked) == true) {
		if (form.Customer_ID.value.length == 0) {
			alert("Please enter your 6 Digit Customer ID Number.");
			form.Customer_ID.focus();
			return (false);
		}
		if (form.Customer_ID.value.length < 6) {
			alert("The Customer ID Number should contain 6 Digits.");
			form.Customer_ID.value = "";
			form.Customer_ID.focus();
			return (false);
		}
	}
	if (form.name.value == "") {
		alert("Please enter your Name.");
		form.name.focus();
		return (false);
	 }
	if (form.city.value == "") {
		alert("Please enter a City.");
		form.city.focus();
		return (false);
	 }
	if (form.state.value.length > 4) {
		alert("Please select a State.")
		form.state.focus();
		return (false);
	 }
	if (form.zip.value == "") {
		alert("Please enter your Zip Code.");
		form.zip.focus();
		return (false);
	 }
  if (form.email.value == "") {
		alert("Please enter your Email Address.");
		form.email.focus();
		return (false);
	}
	if (form.text.value == "") {
		alert("Please enter some text regarding your product information request.");
		form.text.focus();
		return (false);
	 }
	 
    eval (popPOSTwindow('blank.htm'));
	return (true);
}

//	 Some old code for checking things. 
//	 if (form.company.value == "")
//	 {
//	 alert("Field Missing");
//	 form.company.focus();
//	 return (false);
//	 }
//	 if (form.address.value == "" || form.address.value.length < 3)
//	 {
//	 alert("Required Field Missing or Incomplete");
//	 form.address.focus();
//	 return (false);
//	 }
//	 if (form.city.value == "")
//	 {
//	 alert("Field Missing");
//	 form.city.focus();
//	 return (false);
//	 }
//	 if (form.zip.value == "")
//	 {
//	 alert("Required Field Missing or incomplete");
//	 form.zip.focus();
//	 return (false);
//	 }
//	 if (form.phone.value == "")
//	 {
//	 alert("Phone number not entered, please include area code");
//	 form.phone.focus();
//	 return (false);
//	 }
//	 if (form.phone.value.length < 10)
//	 {
//	 alert("Please enter phone number with Area code");
//	 form.phone.focus();
//	 return (false);
//	 }
//	 if (form.fax.value.length < 10)
//	 {
//	 alert("Please enter Fax number with area code");
//	 form.fax.focus();
//	 return (false);
//	 }
//	 if (form.fax.value == "")
//	 {
//	 alert("Please enter the Fax Number");
//	 form.fax.focus();
//	 return (false);
//	 }
//	 if (form.text.value == "")
//	 {
//	 alert("Please enter a description of the Product Information you are requesting");
//	 form.text.focus();
//	 return (false);
//	 }

/*******************************************************************/
// checks name/company/zip/phone/fax/text

function check2(form)
{
	 if (form.name.value == "")
	 {
	 alert("Field Missing");
	 form.name.focus();
	 return (false);
	 }
	 if (form.company.value == "")
	 {
	 alert("Field Missing");
	 form.company.focus();
	 return (false);
	 }
	 if (form.phone.value == "")
	 {
	 alert("Phone number not entered, please include area code");
	 form.phone.focus();
	 return (false);
	 }
	 if (form.phone.value.length < 10)
	 {
	 alert("Please enter phone number with Area code");
	 form.phone.focus();
	 return (false);
	 }
	 if (form.fax.value.length < 10)
	 {
	 alert("Please enter Fax number with area code");
	 form.fax.focus();
	 return (false);
	 }
	 if (form.fax.value == "")
	 {
	 alert("Please enter the Fax Number");
	 form.fax.focus();
	 return (false);
	 }
	 if (form.email.value == "")
	 {
	 alert("Field Missing");
	 form.email.focus();
	 return (false);
	 }
	 if (form.text.value == "")
	 {
	 alert("Please enter an Application Question");
	 form.text.focus();
	 return (false);
	 }
	 return (true);
}
/*******************************************************************/
// checks name/phone/email/text

function check3(form)
{
	 if (form.name.value == "")
	 {
	 alert("Field Missing");
	 form.name.focus();
	 return (false);
	 }
	 if (form.phone.value == "")
	 {
	 alert("Phone number not entered, please include area code");
	 form.phone.focus();
	 return (false);
	 }
	 if (form.phone.value.length < 10)
	 {
	 alert("Please enter phone number with Area code");
	 form.phone.focus();
	 return (false);
	 }
	 if (form.email.value == "")
	 {
	 alert("Field Missing");
	 form.email.focus();
	 return (false);
	 }
	 if (form.text.value == "")
	 {
	 alert("Please enter a description of the Complaint or Suggestion.");
	 form.text.focus();
	 return (false);
	 }
	 return (true);
}
/*******************************************************************/
