//  All document coding, except function MM's, copyrighted by Lisa West / Lisabee Web Design
//  All rights reserved
//  This document may not be used, modified, or sold without  written permission 
//  Lisabee Web Design - lisa@lisabee.com

// script for changing layer visibility

// Function for showing and hiding layers - used from a onClick command
// Accepts a variable number of arguments, in triplets as follows:
// arg 1: simple name of a layer object, such as "Layer1"
// arg 2: ignored (for backward compatibility)
// arg 3: 'hide' or 'show'
// repeat...
//
// Example: showHideLayers(Layer1,'','show',Layer2,'','hide');
function showHideLayers()
{ 
  var i, visStr, obj, args = showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3)
  {
	if ((obj = findObj(args[i])) != null)
	{
	  visStr = args[i+2];
	  if (obj.style)
	  {
		obj = obj.style;
		if(visStr == 'show') visStr = 'visible';
		else if(visStr == 'hide') visStr = 'hidden';
	  }
	  obj.visibility = visStr;
	}
  }
}
// Example: obj = findObj("image1");
function findObj(theObj, theDoc)
{
  var p, i, foundObj;
  
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
	theDoc = parent.frames[theObj.substring(p+1)].document;
	theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
	foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
	foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  
  return foundObj;
}

// script code for mouseover/mouseout
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_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];}}
}

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;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// function to prevent right-clicking

//if (document.all) {
//}
//else if (document.getElementById) { 
//   document.captureEvents(Event.MOUSEDOWN)
//}
//else if (document.layers) {
//    document.captureEvents(Event.MOUSEDOWN)
//}
//document.onmousedown = mousedown_handler

//function mousedown_handler(mouse_event) {

    // This is the message that will appear
//    var no_right_click = "All images on this site are copyrighted.\nThey are displayed for viewing purposes only.\nUnauthorized use is prohibited without written consent.\nPlease contact us if you would like to use one of our images."
    
//    if (document.all) {

        //Probably Internet Explorer 4 and later
//        if (event.button == 2 || event.button == 3) {
 //           alert(no_right_click)
 //           return false
//        }
//    }
//    else if (document.getElementById) { 

        // Probably Netscape 6 and later
//        if (mouse_event.which == 3) {
//            alert(no_right_click)
//            return false
//        }
//    }
//    else if (document.layers) {

        // Probably Netscape 4
//        if (mouse_event.which == 3) {
//            alert(no_right_click)
//            return false
//        }
//    }
//}


// function for subwindows
	
	var subWindow;

	function newWindow(targetFile,opts)
		{
		  if (subWindow && !subWindow.closed)
		     {
			subWindow.close();
		     }

		  subWindow=window.open(targetFile,"",opts);

		}  //  <a href="javascript:void(0)" onClick="newWindow('<filename>','height=400,width=640,menubar,scrollbars')">

// function for setting Button Values (Cancel,Delete,etc.)

	function setButton(field,frmName,strAction)
		{
			sField = eval("document.forms['" + frmName + "']." + field.name);
			sField.value = strAction;
			return true;
		}
		
// function for deleting confirmation

	function confDel(field,frmName,flseVal,strAction,msg) // field = field name for Delete Button; frmName = form name; flseVal = Delete Button's value to be reset to if confirmation is false; strAction = action for setButton . . if null then no setButton occurs; msg = alert message for confirmation
		{
			sField = eval("document.forms['" + frmName + "']." + field.name);
			
			if (confirm(msg))
				{ 
					if (strAction != "")
						{
							setButton(field,frmName,strAction);
						}
					
					return true;
				}else {
						sField.value = flseVal;
						sField.focus();
						return false;
					  }
			return true;
		}

// validation functions

//  function for validating Greeting Card Form not null
	  function valGreetings(frm)
	  	{
				if (frm.sendName.value == "")
					{alert("Please enter the Sender's Name");
					 frm.sendName.select();
					 frm.sendName.focus();
					 return false;
					}
				if (frm.sendEmail.value == "")
					{alert("Please enter the Sender's Email");
					 frm.sendEmail.select();
					 frm.sendEmail.focus();
					 return false;
					}
				if (frm.recpName.value == "")
					{alert("Please enter the Recipient's Name");
					 frm.recpName.select();
					 frm.recpName.focus();
					 return false;
					}
				if (frm.recpEmail.value == "")
					{alert("Please enter the Recipient's Email");
					 frm.recpEmail.select();
					 frm.recpEmail.focus();
					 return false;
					}
				
				return true;
		}

 // function for validating & parsing checkboxes
	 
	 	function valChkbox(chkBox,lmt,mn,strTyp)  // field = form field to be evaluated; frmName = Form Name; lmt = max number of checked boxes allowed; mn = minimum number of checked boxes required (0 if no requirement); strTyp = name of checkbox option for alert messages
						{
						 var cntr=0;
						 var strVal = "";
						 						 
						 if (!chkBox.length)
						 	{
								if (chkBox.checked)
									{
										strVal = strVal + chkBox.value;
										cntr = cntr + 1;
									}
							}else
								{
									for (var i=0; i<chkBox.length; i++)
										{
											if (chkBox[i].checked)
												{
													cntr=cntr+1;
													if (cntr == 1)
													  {
															strVal = strVal + chkBox[i].value;
													  } else
															{
																strVal = strVal + ", " + chkBox[i].value;
															}
												 }
										 }
								 }
							
						if (cntr > lmt)
							{
								alert("Please do not select more than " + lmt + " " + strTyp + ".");
								return false;
							}
						
						if (cntr < mn)
							{
								
								alert ("Please select at least " + mn + " " + strTyp + ".");
								return false;
							}
						
						return strVal;	
						} 
						
 // function for validating price
	
		function valPrice(field,frmName,strType,nOK) // field = form field to be evaluated; frmName = Form Name; strType = field name for alert message, nOK = is field value allowed to be null or empty
						{
						  
						  sField = eval("document.forms['" + frmName + "']." + field.name);
						  var strNum = new Number(sField.value);
						  
						  if (isNaN(strNum))
						  		{
									alert("Please be sure to enter only numeric digits for the " + strType + ".");
									sField.focus();
									return false;
								}
								
						  if (strNum.valueOf() == 0 && nOK != "y")
						  	{
								alert("Please enter an amount for the " + strType + ".");
								sField.focus();
								return false;
							}
						
						 sField.value = strNum.toFixed(2);
						 return true;
						}
						
	// function for validating text fields

       function valName(field,frmName,strTyp,nOK,sOK) // field = form field; frmName = form name; strType = title of option for alert statement; nOK = is a null value OK?; sOK = are spaces allowed in the value?
                       {
						
					   sField = eval("document.forms['" + frmName + "']." + field.name);
					   var strName = sField.value;	
						
                       if (strName=="" && nOK=="n")
                           {
           		    		  alert ("We need a " + strTyp + ". Please try again.");
							  sField.focus();
                              return false;
                           }
						   
						if (strName.indexOf(" ") != -1 && sOK == "n")
							 {
							 		alert("Please do not enter any spaces in the " + strTyp +".");
									sField.focus();
									return false;
								}
						if (strName.length>100)
                           {
                          	   alert ("The " + strTyp + " is a little too long.  Please try again.");
							   sField.focus();
                         	   return false;
                           }
			
		       			 if (strName.indexOf("<") != -1)
                           {
                            alert ("Use only letters, spaces, or hyphens in the " + strTyp + ". Please try again");
							sField.focus();
			   				return false;
						   }
			       
		       			 if (strName.indexOf("{") != -1)
                           {
                             alert ("Use only letters, spaces, or hyphens in the " + strTyp + ". Please try again");
							 sField.focus();
			   				 return false;
		          		   }
						
						return true; 
                        }
			
	
				  
 // function for validating description boxes
	  
	  	function valDesc(field,frmName,strName,nOK)  //   field = form field; frmName = form name; strName = name of field for alert message; nOK = is a blank value allowed?
			 			 {
						 	sField = eval("document.forms['" + frmName + "']." + field.name);
					 		  var strDesc = sField.value;
							  
						 	 if (strDesc == "" && nOK == "n")
							 	{
									alert("Please enter some " + strName + " information.");
									sField.focus();
									return false;
								}
                             if (strDesc.indexOf("<") == -1)
                                {
                                 if (strDesc.indexOf("{") == -1)
                                    {
                                     return true;
                                    }
                                 }
                               alert ("Your " + strName + " information appears to have special characters used in scripts.  Please be sure to remove any '<' or '{' characters.");
                              sField.focus();
							  return false;
                          }
						
	// function for validating numeric fields
	
		function valNum(field,frmName,prec,strType,nOK) // field = form field to be evaluated; frmName = Form Name; prec = Precision of the numeric value; strType = field name for alert message, nOK = is field value allowed to be null or empty
						{
						  
						  sField = eval("document.forms['" + frmName + "']." + field.name);
						  var strNum = new Number(sField.value);
						  
						  if (isNaN(strNum))
						  		{
									alert("Please be sure to enter only numeric digits for the " + strType + ".");
									sField.focus();
									return false;
								}
								
						  if (strNum.valueOf() == "0" && nOK != "y")
						  	{
								alert("Please enter the " + strType + ".");
								sField.focus();
								return false;
							}
						
						 sField.value = strNum.toFixed(prec);
						 return true;
						}
						
	// function for validating email address
						
		 function valEmail(field,frmName,strName,nOK) // field = form field to be evaluated; frmName - Form Name; strName = Name of Email Field Type; nOk = Null OK?
                       {
						   
						 sField = eval("document.forms['" + frmName + "']." + field.name);
						 var strEmail = sField.value;
						 var strOK = "yes";
						  
                        if (strEmail == "")
                           {
							 if (nOK != "y")
							 	{
									 alert ("Please enter a " + strName + " email address.");
									 sField.select();
									 sField.focus();
									 return false;
								}else{return true;}
					       }
						 
						 if (strEmail.length>100)
                           {
                              alert ("The " + strName + " email address is too long.  Please try again.");
							  sField.select();
							  sField.focus();
							  return false;
                           }
						
						if (strEmail.indexOf("@") == -1)
                           {
                             alert ("The " + strName + " email address is missing the '@' character. Please try again.");
							 sField.select();
							  sField.focus();
							  return false;
	                 	   }
			 
		       			if (strEmail.indexOf(".") == -1)
                           {
                             alert ("The "+ strName + " email address is missing a '.' character. Please try again.");
			   				 sField.select();
						     sField.focus();
							 return false;
			 			   }
						   
						if (strEmail.indexOf(" ") != -1)
							{
							  alert ("There appears to be spaces in the " + strName + " email address.  Please try again.");
							  sField.select();
							  sField.focus();
							  return false;
							}
						   
						return true;
                        }
						
				// function for validating the phone number field w/area code
		
		   function valPhone(field,frmName,strName,nOK) // field = form field to be evaluated; frmName = Form Name ; strName = name of field; nOK = Null OK?
			              {
							   sField = eval("document.forms['" + frmName + "']." + field.name);
							   var strPhone = sField.value;
							   var strPhoneLen="";
																
								for (var i=0; i<strPhone.length; i++)
								    {
									  var oneChar=strPhone.substring(i,i+1);
									  
									  if (oneChar>= "0")
									     {
										    if (oneChar<="9")
									         {
											    strPhoneLen=strPhoneLen + oneChar;
											   }
											}
									  }
								 
								 if (strPhoneLen == "")
									{
										if (nOK == "n")
											{
												alert ("You need to enter a " + strName + " phone.");
												sField.select();
												sField.focus();
												return false;
											}else {
													sField.value="";
													return true;
												  }
									}
										 								 
								if (strPhoneLen.length!=10)
									{
										alert ("There doesn't appear to be the correct amount of numbers for your " + strName + " phone number. Be sure to include your area code. Please try again");
										sField.select();
										sField.focus();
										return false;
									}
									
								strPhone = "("+strPhoneLen.substring(0,3)+") "+strPhoneLen.substring(3,6)+"-"+strPhoneLen.substring(6,10);
								sField.value = strPhone;
								return true;
								}
								
//  function for validating date field
	
		function valDate(field,frmName,strTyp,nOK) // field = form field to be evaluated; frmName = Form Name ; strName = name of field; nOK = Null OK?
				{
						sField = eval("document.forms['" + frmName + "']." + field.name);
						strDate = sField.value;
						
						if (strDate == "" && nOK == "n")
							{alert("Please enter a " + strTyp + ".");
							 sField.select();
							 sField.focus();
							 return false;
							} else if (strDate == ""){return true;}
							
							
						var strNewDate="";
						var strDte = "";
						var t = 0;
																
								for (var i=0; i<strDate.length; i++)
								    {
									  var oneChar=strDate.substring(i,i+1);
									  if (isNaN(oneChar)  || ((t%2)==0 && t != 0))
													{
														if (strDte.length <2)
															{
																strNewDate =  strNewDate + "0"+strDte;
															} else
																{
																	strNewDate = strNewDate + strDte;
																}
														strDte = "";
														t=0;
														
													}
									  if (oneChar>= "0")
									     {
										    if (oneChar<="9")
									         {
											    strDte = strDte + oneChar;
												t = t+1;
											 }
										 }
									  }
									  
								if (strDte != "")
										{
											if (strDte.length <2)
												{
													strNewDate =  strNewDate + "0"+strDte;
												} else
													{
														strNewDate = strNewDate + strDte;
													}
										}
										
									  
								if (strNewDate.length < 8)
									{
										alert("Please re-enter the " + strTyp + " using the mm/dd/yyyy format.");
										sField.select();
										sField.focus();
										return false;
									}
							    var strMonth = strNewDate.substring(0,2);	
								var strDay = strNewDate.substring(2,4);
								var strYear = strNewDate.substring(4,8);
								var entDate = strYear + strMonth + strDay;
								
								var curDate = new Date();
								
								var curYear = "" + curDate.getYear();
								if (curYear.length < 4)
									{
										cYr = 1900 + parseInt(curYear);
										curYear = "" + cYr;
									}
								var curMonth = "" + (curDate.getMonth()+1);
								if (curMonth.length < 2)
									{
										curMonth = "0" + curMonth;
									}
								var curDay = "" + curDate.getDate();
								if (curDay.length < 2)
									{
										curDay = "0" + curDay;
									}
								var curDate = curYear + curMonth + curDay;
								
								var mnthDays = new Array(0,31,28,31,30,31,30,31,31,30,31,30,31);
								if (parseInt(strYear,10)% 4 == 0)
									{
										mnthDays[2] = 29;
									}
								var mxDays = mnthDays[parseInt(strMonth,10)];
								
								
								if (parseInt(strMonth,10) > 12 || parseInt(strMonth,10) < 1)
									{
										alert("Please recheck the month you entered for the " +strTyp + ".  It doesn't appear to be a valid month (01 - 12)");
										sField.select();
										sField.focus();
										return false;
									}
									
								if (parseInt(strDay,10) > mxDays || parseInt(strDay,10) < 1)
									{
										alert("Please recheck the day value you entered for the " + strTyp + ". It does not fit within the number of days for the month you entered.");
										sField.select();
										sField.focus();
										return false;
									}
									
								if (parseInt(strYear) > curYear)
									{
										 alert("Please recheck the year you entered for the " + strTyp + ".  It appears to be a future year.");
										 sField.select();
										 sField.focus();
										 return false;
									}
								
								if (parseInt(entDate,10) > parseInt(curDate,10))
									{
										alert("The " + strTyp + " you entered appears to be a future date.  Please try again.");
										sField.select();
										sField.focus();
										return false;
									}
									
									
								sField.value = strMonth + "/" + strDay + "/" + strYear;
									
								return true;
							}
							
//  funtion for validating file upload type
	
		function valUpld(field,frmName,strTyp,nOK)
			 {
				   sField = eval("document.forms['" + frmName + "']." + field.name);
				 var strFName = sField.value;
				   
				 	if (strFName == "")
				  	{
					if (nOK == "n")
							{
								alert("You must upload an image.");
				 				sField.select();
								sField.focus();
								return false;
							} else{return true;}
					}
					
				  
				  if (strFName.indexOf(".jpg") == -1 && strFName.indexOf(".JPG") == -1 && strFName.indexOf(".GIF") == -1 && strFName.indexOf(".gif") == -1)
				  	{
						alert("The image you uploaded must be in jpg or gif format.");
						sField.select();
						sField.focus();
						return false;
					}
				  return true;
				  }

	