var pic1a = new Image();
var pic1b = new Image();
var pic1c = new Image();
var pic1d = new Image();
var pic2a = new Image();
var pic2b = new Image();
var pic2c = new Image();
var pic2d = new Image();
var pic3a = new Image();
var pic3b = new Image();
var pic3c = new Image();
var pic3d = new Image();
var pic4a = new Image();
var pic4b = new Image();
var pic4c = new Image();
var pic4d = new Image();
var pic5a = new Image();
var pic5b = new Image();
var pic5c = new Image();
var pic5d = new Image();

pic1a.src = "images/home1a.gif";
pic1b.src = "images/home1b.gif";
pic1c.src = "images/home1c.gif";

pic2a.src = "images/about1a.gif";
pic2b.src = "images/about1b.gif";
pic2c.src = "images/about1c.gif";

pic3a.src = "images/contact1a.gif";
pic3b.src = "images/contact1b.gif";
pic3c.src = "images/contact1c.gif";

pic4a.src = "images/link2us1a.gif";
pic4b.src = "images/link2us1b.gif";
pic4c.src = "images/link2us1c.gif";

pic5a.src = "images/link1a.gif";
pic5b.src = "images/link1b.gif";
pic5c.src = "images/link1c.gif";

var t_date = new Date();
t_date = t_date.getTime();
var c_date = new Date();
var acookie;
var	jar1;
var jar2;
var jar3;
var jar4 = new Array;
var x;
var jar5 ="";
var jar6;

var msg = "";                 // an output message
var missing = "";             // for missing required fields
var invNum = "";              // for invalid numeric fields
var invZIP = "";			// for invalid zip codes
var invPhone = "";			// for cridit card numbers
var invState = "";            // for invalid state fields


//opens zform1, an email form
//called from contact.html @ Message anchor link-onClick & testcookie()
function openwin(wind)
	{
		window.open(wind);
	}

//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
//used to Preload navbar images
//called from <body onLoad>

function NYB_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
//used to set cookie
//called from valFlds2()
function setCook2(frmName)
{ 
		var Fname = frmName.srfname.value;
		var Lname = frmName.srlname.value;
		var topics =  new Array;
		var i;
		var temp;
//alert( Fname);
//alert(Lname);
		c_date.setTime (t_date + 2*365*24*60*60 * 1000); //(365 * 24 * 60 * 60 * 1000)
		
		for (i=0; i< frmName.srvlist.length ;i++ )
	   		if (frmName.srvlist.options[i].selected)
			{	
//alert(frmName.srvlist.options[i].text);
			topics[i] = frmName.srvlist.options[i].text;
			}
			var SurCookie = "survey=fname:"+ Fname+"?lmane:"+Lname;

       for (i=0;i< topics.length ;i++ )
		{       
		   if (frmName.srvlist.options[i].selected)
		   {
			   SurCookie += "?topic"+i+":"+ (topics[i]);
		   }
		}
  document.cookie = escape(SurCookie)+";expires=" +  c_date.toGMTString();
  //alert(unescape(document.cookie));
}



//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
// View cookie string as a test funtion
//called from setcookie()
	function DemoCookieView () 
	{
  var cookieString = document.cookie;
	alert(unescape(cookieString));	
	}

//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
// Tests for cookie on users hard drive: 
//called from default.html at the Survey link onClick=
function cookietest()
	{

		var tstcookie = document.cookie;

		if (tstcookie.length > 0)			
		{
			showCookie();
//			post();
//			alert("Hello "+ jar4[0] + ". You have aready taken the Book Nook Survey. Your topics are " + jar5 + "." );
			//rdcookie(tstcookie);
			//alert ("a cookie already exists");
			return false;
		}
			openwin('survey.html');
	}

//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
// used to read and split cookie
// called from check()
function post()
{ var i;
	
		
		for (i=2;i<jar4.length;i++ )
		{
			jar5 += (jar4[i]+" ");
//alert("2 or more topics");
	
		}
	}
	

//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
// used to read and split cookie
// called from check()
function rdcookie(cookie) 
{

	var acookie = unescape(cookie);
	jar1 = acookie.split("=");	
	jar2 = jar1[1].split("?");
	for (var i=0; jar2[i] ; i++ )
	{
		 jar3=jar2[i].split(":");
				jar4[i]=jar3[1];
	}
}



//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
//
//
// 
function showCookie() 
{

var acookie;
var ajar1;
var ajar2;
var ajar3;
var ajar4 = new Array;
var ajar5 ="";
var acookie = unescape(document.cookie);

	ajar1 = acookie.split("=");	
	ajar2 = ajar1[1].split("?");
	for (var i=0; ajar2[i] ; i++ )
	{
		ajar3=ajar2[i].split(":");
		ajar4[i]=unescape(ajar3[1]);
	}
// load selection into variable called Jar5
	if (ajar4.length == 4)
   {
	  for (i=2;i<(ajar4.length - 1);i++ )
	      {
		    ajar5 += ajar4[i]+".";
          }

			alert( "Hi " + ajar4[0] + " " +  ajar4[1] + " You have done the Survey already. " + " " + "Your Topic is " + ajar5);
    }

	else
		{ 
			for (i=2;i<(ajar4.length - 1);i++ )
			{
				if (i==(ajar4.length - 2))
				{
					ajar5 += ("and " + ajar4[i]+".");
					}
					else
					{
					ajar5 += (ajar4[i]+", ");
				} 
			}

			alert( "Hi " + ajar4[0] + " " +  ajar4[1] + " You have done the Survey already. " + " " + "Your Topics are " + ajar5);
		}
}


//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
// Validates fields for the survey
// called from survey onSubmit
function valFlds2(frm)
	{
		for(i=0; i<3; i++)
			if(frm.elements[i].value=="")
				{alert("Please enter required information.");
//				{alert("Please enter Survey information");
				frm.elements[i].focus();
				return false;
				}
				setCook2(frm);
				rdcookie(document.cookie);
				window.close();
				return true;
	}




//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
// Validates fields for the email inquiry form: 
//will be called from zform1.html onSubmit=
function valFldsA(frm)
	{
		for(i=2; i<5; i++){
			if(frm.elements[i].value=="")
				{
					alert("Please enter required information");
					frm.elements[i].focus();
					return false;
				}
		}	
				if (!valemailA(frm))
				{			

				// window.close(frm);
		
							alert('Please enter a valid e-mail address!');
								frm.elements[3].focus();
							return false;
				}

				alert("Getting done!");
			
			window.close();
			return true;
	}


/*function checkCheckBox(f){
if (f.agree.checked == false )
{
alert('Please check the box to continue.');
return false;
}else
return true;
}
*/
//will be called from zform1.html onSubmit=
function valFldsB(frm)
	{
		for(i=0; i<5; i++)
		{
			if(frm.elements[i].value=="")
				{
					alert("Please enter required information");
					frm.elements[i].focus();
					return false;
				}
		}	
				if (!valemailA(frm))
				{			

				// window.close(frm);
		
							alert('Please enter a valid e-mail address!');
								frm.elements[5].focus();
							return false;
				}
				
				if (frm.elements[8].checked== false )
				{
					alert('Please check the box to continue.');
							return false;
					}
					//alert("Hello Joyce");
				
					
				
				
			
		
			return true;
			//alert("Getting done 2!");
				
			
			
			
	}


//will be called from zform1.html onSubmit=
function valFldsC(frm)
	{
		for(i=0; i<4; i++){
			if(frm.elements[i].value=="")
				{
					alert("Please enter required information");
					frm.elements[i].focus();
					return false;
				}
		}	
				if (!valemailC(frm))
				{			

				// window.close(frm);
		
							alert('Please enter a valid e-mail address!');
								frm.elements[2].focus();
								//alert("Your comments/inquiry will not be sent!");
							return false;
				}

				//alert("Your comments/inquiry will be sent!");
			
		//	window.close();
			return true;
	}


//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
// validates email field on the inquiry form
// should be called from valFlds(frm)
function valemailA(frm)
	{
	//var EmailOk  = true
	var Temp     = frm.elements[5]
	var AtSym    = Temp.value.indexOf('@')
	var Period   = Temp.value.lastIndexOf('.')
	var Space    = Temp.value.indexOf(' ')
	var Length   = Temp.value.length - 1   // Array is from 0 to length-1

		if ((AtSym < 1) ||			// '@' cannot be in first position
		(Period <= AtSym+1) ||	// Must be atleast one valid char btwn '@' and '.'
		(Period == Length ) ||		// Must be atleast one valid char after '.'
		(Space  != -1))				// No empty spaces permitted
		{  		
		
	//	EmailOk = false;
		return false;
		}
		else
		
	//	return EmailOk;	
	return true;
	}

//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
// validates email field on the inquiry form
// should be called from valFlds(frm)
function valemailC(frm)
	{
	//var EmailOk  = true
	var Temp     = frm.elements[2]
	var AtSym    = Temp.value.indexOf('@')
	var Period   = Temp.value.lastIndexOf('.')
	var Space    = Temp.value.indexOf(' ')
	var Length   = Temp.value.length - 1   // Array is from 0 to length-1

		if ((AtSym < 1) ||			// '@' cannot be in first position
		(Period <= AtSym+1) ||	// Must be atleast one valid char btwn '@' and '.'
		(Period == Length ) ||		// Must be atleast one valid char after '.'
		(Space  != -1))				// No empty spaces permitted
		{  		
		
	//	EmailOk = false;
		return false;
		}
		else
		
	//	return EmailOk;	
	return true;
	}



//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
// Test alert function to see how far 
//through a function i get and which way the function goes: 
//called as needed
function IsEmail(frm, ElemName)
	{ alert("Ok So far");	
	}


//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 
// tests browser type and alerts user to IE alternatives if needed: 
//called from a test script in default.html<body> tag
function brows()
{	
	if (document.cookie.length <= 0)
		{if (navigator.appName == "Netscape")
			{
			//alert("you are using " + navigator.appName + ". This browser might not render our web site very well. Please visit http://www.microsoft.com/windows/ie/default.asp to download the latest version of IE.-A")
			openwin('browser.html');
			}
		 else 
			 if(navigator.appName !== "Microsoft Internet Explorer")
			{
			//alert("you are using " + navigator.appName + ". tis browser might not render our web site very well. Please visit http://www.microsoft.com/windows/ie/default.asp to download the latest version of IE.-B")
			openwin('browser.html');
		}
		else
		alert("You are using MS IE.")
	}
	 
	  
}

//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
// used to check for cookie. If found, cookie is split and read into holders
// and if it's the first time back in a while, flashes a hello message or else 
//it checks your browser. 
//called from default.html's body onLoad
function check()
{
//alert(document.cookie);
	if (document.cookie.length > 0)
		{
//		alert(x);
		rdcookie(document.cookie);
		if (x != 1)
			{	
//alert(x);
		alert("Hello "+ jar4[0] + " " + jar4[1] + ", Welcome back to the Book Nook.");
			x = 1;
//alert(x);
			}
		}
		else
			brows();
}


//*********************************************

//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
// Checks for input in fields in the Order entry page
// called from order_entry.html onSubmit
function valFlds3(frm)
	{
		{
  for(i=0; i<frm.elements.length; i++)            // loop through form elements
    {
    var el = frm.elements[i];
	alert(frm.elements[i].name);
    if(el.required)                               // if element has required property
      {                                           // test to see if field is empty
	 if(isEmpty(el))
        {
        missing += "\n   - " + el.name + " is a required field";
        }
      }
    if(el.numeric)
      {
      if(notNumeric(el))
        {
        invNum += "\n   - " + el.name + " must be a number";
        }
      }
    
    if(el.zip && el.value.length !=0)
      {
      if(invalidZIP(el))
        {
        invZIP += "\n  - " + el.value + " is not a valid zip code";
        }
      }
    
    if(el.state && el.value.length != 0)
      {
      if(invalidState(el))
        {
        invState += "\n  - " + el.value + " is not a valid two-letter state abbreviation";
        }
      }
    }
  
  // build output message
  if(missing.length !=0 || invNum.length != 0 || invNum.length < 16 || invZIP.length != 0 || invState.length != 0)
    {
    if(missing.length !=0)
      {
      msg += "\n\nThe following required fields are missing:";
      msg += missing;
      }
    if(invNum.length !=0 )
      {
      msg += "\n\nYou have entered invalid info in the cc field:";
      msg += invNum;
      }

/*	  if(invNum.length < 16)
      {
      msg += "\n\nYou have entered an invalid credit card number:";
      msg += invNum;
      }
*/
	  
   
    if(invZIP.length !=0)
      {
      msg += "\n\nYou entered an incorrect zip code";
      msg += invZIP;
      }

if(el.phone) //&& el.value.length !=0)
      {
      if(invalidPhone(el)) //|| el.value.length < 16)
        {
        invPhone += "\n  - " + el.value + " is not a valid phone number";
        }
      }
   
    if(invState.length !=0)
      {
      msg += "\n\nYou entered an incorrect state abbreviation";
      msg += invState;
      }
    errMsg(msg);           // call the output function
    msg = ""; missing = ""; invNum = ""; invZIP = ""; invState = "" ; // reset all our variables
    return false;
    }
  else
    {
	//  alert ("All fields are correct");
    return true;
    }
  
}
/* *************************************************************
* Sub-functions follow from here to end of file                *
* All sub-functions return true if field is of invalid         *
* format and false if they are valid entries                   *
***************************************************************/

//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
//Checks for spaces in fields 
//will be called from valFlds3(frm)
function isEmpty(fld)
	{
	str= fld.value;
	if (str == "")
		{
		return true;
		}
		else
		{
		for (j=0; j < str.length; j++ )
			{
			if(str.charAt(j) != " ")
				{
				return false;
				}
			}
		}
		return true;
	}

//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
//tests for non numeric fields entry 
//will be called from valFlds3
	function notNumeric(field)
  {
  var errCount = 0;
  var numdecs = 0;                    // number of decimal points
  for(j=0;j<field.value.length;j++)
    {
    c = field.value.charAt(j);        // short hand notation for character at position j
    if((c >= 0 && c <= 9) || c=="." || (j==0 && c == "-"))
      {
      if(c==".") 
        {
        numdecs++;          // count the number of decimal points
        }
      }
    else
      {
      errCount++;                    // if it's none of those, increment error counter
      break;                         // no need to continue looping, it's not a number
      }
    }
  // error if count is non-zero or there are more than one decimal point
  if(errCount > 0 || numdecs > 1)
    {
    return true;
    }
  return false;
  }
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
//tests for valid Zip field entry 
//will be called from valFlds3
function invalidZIP(field)
  {
  var zipcode = field.value;
  if(zipcode.length == 5 || zipcode.length == 9)
    {
    var subZip = stripNonDigits(zipcode);
    if(subZip.length == zipcode.length)
      {
      return false;
      }
    else
      {
      return true;
      }
    }
  else if(zipcode.length == 10 && (zipcode.charAt(5) == "-" || zipcode.charAt(5) == " "))
    {
    subZip = zipcode.substring(0,5) + zipcode.substring(6,10);
    subZip = stripNonDigits(subZip);
    if(subZip.length == 9)
      {
      return false;
      }
    else
      {
      return true;
      }
    }
  return true;
  }
//********************************
//******************
function invalidPhone(field)
  {
  newStr = stripNonDigits(field.value);
  if(newStr.length == 16)
    {
    return false;
    }
  return true;
  }
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
//tests for valid State field entry 
//will be called from valFlds3
function invalidState(field)
  {
  var STATES = "AL/AK/AZ/AR/CA/CO/CT/DE/DC/FL/GA/HI/ID/IL/IN/IA/KS/LA/ME/MD/MA/MI/MN/MS/MO/MT/NV/NH/NJ/NM/NY/NC/ND/OH/OK/OR/PA/PR/RI/SC/TN/TX/UT/VT/VA/WA/WV/WI/WY";
  var newStr = field.value.toUpperCase();
  if(STATES.indexOf(newStr) == -1 || newStr.indexOf("/") != -1 || newStr.length != 2)
    {
    return true;
    }
  return false;
  }
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
//Generate the error message for problem fields 
//will be called from valFlds3
  function errMsg(msg)
  {
  var theMsg = "You entered 1 or more incorrect value(s) into the form. ";
  theMsg += "Please correct your entrie(s) then re-submit the form.\n";
  theMsg += "____________________________________________________________________";
  theMsg += msg;
  theMsg += "\n____________________________________________________________________\n";
  alert(theMsg);
  }




//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
// Validates fields for the email inquiry form: 
//will be called from zform1.html onSubmit=
function valFlds(frm)
	{
		for(i=2; i<5; i++){
			if(frm.elements[i].value=="")
				{
					alert("Please enter required information");
					frm.elements[i].focus();
					return false;
				}
		}	
				if (!valemail(frm))
				{			

				// window.close(frm);
		
							alert('Please enter a valid e-mail address!');
								frm.elements[3].focus();
							return false;
				}

				alert("Getting done!");
			
			window.close();
			return true;
	}


//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
// validates email field on the inquiry form
// should be called from valFlds(frm)
function valemail(frm)
	{
	//var EmailOk  = true
	var Temp     = frm.elements[3]
	var AtSym    = Temp.value.indexOf('@')
	var Period   = Temp.value.lastIndexOf('.')
	var Space    = Temp.value.indexOf(' ')
	var Length   = Temp.value.length - 1   // Array is from 0 to length-1

		if ((AtSym < 1) ||			// '@' cannot be in first position
		(Period <= AtSym+1) ||	// Must be atleast one valid char btwn '@' and '.'
		(Period == Length ) ||		// Must be atleast one valid char after '.'
		(Space  != -1))				// No empty spaces permitted
		{  		
		
	//	EmailOk = false;
		return false;
		}
		else
		
	//	return EmailOk;	
	return true;
	}

	}
//*********************************************


/* *********List of Methods********************
brows()
12
line-336

check()
14
line-362

cookietest()
4
line-142

DemoCookieView ()
3
line-133

errMsg(msg)
20
ln-580

invalidPhone(field)
18
ln-555

invalidState(field)
19
ln-567

invalidZIP(field)
17
ln-523

IsEmail(frm, ElemName)
11
line-328

isEmpty(fld)
15
line-470

notNumeric(field)
16
line-493

openwin(wind)
1
line-88

post()
5
line-162

rdcookie(cookie)
6
line-178

setCook2(frmName)
2
line-98

showCookie()
7
line-197

valemailA(frm)
10
line-299

valemail(frm)
22
ln-626

valFlds(frm)
21
ln-596

valFldsA(frm)
9
line-269

valFlds2(frm)
8
line-248

valFlds3(frm)
14
line-387


*/
