function VerifyForm(theform)
   {
   var x = 0 
   var msg
   var current = "";
   var obj 
   var errMsg = "The following required fields are incomplete:\n";
   var currentValue
   var isError = false;
   var options = false;
   var checked = new Array(theform.elements.length)
	  while(obj=theform.elements[x])
      {
	   //alert(obj.name) //debugging - alerts name of each field in form
		currentValue = ""
		msg = new String(obj.name)
		//alert(theform.elements[x].name + ' disabled? ' + theform.elements[x].disabled)
	 	if(theform.elements[x].disabled != true){ //allows for skipping validation on disabled fields
				var names = msg.split("-") //split to get name of form element
				
				if (names.length > 1)
				{
				   msg = new String(names[0]) 
				   var values=msg.split("_") 
				  
				  
					   if (values.length > 1)
					   {
						 if (values[0] == "t")
							currentValue = obj.value;
						 if (values[0] == "r"){
						 var j = 0;
						 var radErr = true;
							while (radObj = theform[names[1]][j])
							{
								if (radObj.checked)
								{
									currentValue = radObj.value
								}
							j++;
							}
						 } 
						 if (values[0] == "p")
							currentValue = obj.options[obj.options.selectedIndex].value;
						 if (values[1]=="blank")
						 {
							if(currentValue=="")
							{

							   errMsg += values[2] + "\n"; 
							   isError = true  

							}
						 }
						 if (values[1]=="index")
						 {
							if(obj.options.selectedIndex == 0)
							{

							   errMsg += values[2] + "\n"; 
							   isError = true  

							}
						 }
						 if (values[1] == "date")
						 {
							 if (!(Date.parse(currentValue)))
							 {

							   errMsg += values[2] + "\n"; 
							   isError = true  
                                                  
							 }
							 else
							 {
								var newDate = new Date(Date.parse(currentValue))
		//                        obj.value = newDate.getMonth() + "/" + newDate.getDate() + "/" + newDate.getYear();
							 }
						 }  
		
						 if (values[1] == "email")
						 {
							var re = /[\S]+@[\S]+\.[\S]+/
							var str = new String(currentValue)
							if(!str.match(re)){

							   errMsg += values[2] + "\n"; 
							   isError = true  

							}
						 }
						 if (values[1] == "int")
						 {
							 if (!parseInt(currentValue))
							 {

							   errMsg += values[2] + "\n"; 
							   isError = true  

							 }
						 }
						 
					  }
			 }
			 else
			 {
				if (theform.elements[x].name=="totalMonths")
				{
				   if(obj.options[obj.selectedIndex].value=="nopull")
				   { 
					 errMsg += obj.name + "\n" + "R"
					 isError = true;                                                        
				   }
				}
			 
			 }  

    	}//end if (disabled)
				
		   obj = null  
		   x++

	}//end while
   if (isError)
   {
       alert(errMsg)
       return false;
   }
   else
   { 
     x=0
     while(obj=theform.elements[x])
     {
         msg = new String(theform.elements[x].name)
         var names = msg.split("-")
         if (names.length > 1)
         {
			 if (names.length == 2){

   			     obj.name = names[1];
             
			 }
		 }
         x++;
     } 
     return true
   }
}

function checkURL(url){
	if (url.value == "")
	{
		return false;
	}
	var newUrl = new String(url.value)
	/*  strip http://www.  */
	var re = /^http:\/\//i;
	newUrl = newUrl.replace(re,"");
	re = /^www\./i;
	newUrl = new String(newUrl.replace(re,""));
    
    /*  full url regular expression */
	re = /\.\S+/;
	if (newUrl.match(re))
    {
		newUrl = new String("http://www." + newUrl);
		url.value = newUrl
    }else{
		alert("Please make sure your website is in \'http://www.yourpage.com\' format.");
		url.focus();
	}
}

function VerifyThenSubmit(theform)
{
   if (VerifyForm(theform))
   {
	   theform.submit()
   }
}

function doStartDate(theform)
{
          var beginDate = new Date(Date.parse(theform["t_date_ad start date-ad_start_date"].value));
          var newMonth = beginDate.getMonth() + 1 + parseInt(theform.totalMonths.options[theform.totalMonths.selectedIndex].value);
          var endDate = new Date(Date.parse(newMonth + "/" + beginDate.getDate() + "/" + beginDate.getYear()));          
          theform["ad_finish_date"].value=(endDate.getMonth() + 1) + "/" + endDate.getDate() + "/" + endDate.getYear();
}
   function checkNum(textbox)
   {
     if (!parseInt(textbox.value))
     {
     return 0
     }
     if (parseInt(textbox.value) < 1)
     { 
        return 0
     }
	 return true;
   }
function checkDate(form)//form object and and element//checks XX/XX/XXXX format, replaces if necessary
{
	var date_array //array holding split date
	if (form.value.length < 5){return 0;}
	date_array = form.value.split("/")
	for(var i=0;i<3;i++){//getting rid of unwanted chars, digits
		if(date_array[i]){
			var dateString = new String(date_array[i])
			var re = /\D/gi
			dateString = dateString.replace(re,"")
			date_array[i] = dateString
		}
	}
	
	if (!checkNum(form)){alert("Please Enter a Valid Year in XX/XX/XXXX Format");return 0;}
	
	if(date_array[0]){
		if(date_array[0] < 10 && date_array[0].length == 1) {date_array[0] = "0" + date_array[0]}
		if(date_array[0] > 12){alert("Invalid Month. Please Try Again.");form.focus();return 0;}
	}else{return 0};//nothing entered
	if(date_array[1]){
		if(date_array[1] < 10 && date_array[1].length == 1) {date_array[1] = "0" + date_array[1]}//adding 0 to 03/01/ format
		if(date_array[1] > 31){alert("Invalid Day. Please Try Again.");form.focus();return 0;}
	}else{return 0;}//no / to be parsed, invalid date
	
	if(date_array[2]){
		//if(date_array[2].length < 4 || date_array[2].length > 4) 
		/*removed so users can enter an XX format date when adding exhibitions*/
		/*if (date_array[2].length == 2){
  		   todaysYear = new Date();
  		   year = todaysYear.getYear();
		   strYear = new String(year)
		   "20"		   
		}//removed because if users setting is off, replace won't work properly (changing 02 to 1902 instead of 2002*/
		
		if(date_array[2].length < 2 || date_array[2].length == 3 || date_array[2].length > 4)
		{
		alert("Please use a valid year format. (XX or XXXX)");
		form.focus();
		return 0;
		}
	}else{//year is defaulting to this year if no year is entered
		todaysYear = new Date();
		year = todaysYear.getYear();
	}
	
	var day = date_array[0]
	var month = date_array[1]
	if(!year){//today's year was not substituted for blank year
		var year = date_array[2]
	}
	return day + "/" + month + "/" + year;
}



function changeField(field,value)//field is full form object location eg document.formname.elements[elementname]
{
field.value=value;
}	



function compareDate(date1,operand,date2,part)
{
//this function parses a date (string) in XX/XX/XXXX format
//checkDate() should be run before this function to insure all dates are in this format
//-------------
//PARAMETERS:
//date1: date string in format XX/XX/XXXX (original date you wish to perform operation on
//operand: logical operation you wish to use (<,>,=,!=,<=,>=)
//date2: date string or integer you wish compare or evaluate with date1 (you could add two dates or add 10 whatevers, specified below)
//part: date portion you wish to operate or compare (day,month,year) OPTIONAL
//you are able to compare two dates, and tell if date1 is 'operand' date2
// this is basically constructing a logical expression with a standard operand, two date strings, and the portion
// of the date strings you wish to compare.

//this function can be used to evaluate expressions, using dates 

//eg- ('10/10/2001','day','+',10,'day') will add 10 days to 10/10/2001, returning 10/20/2001
//standard Date() object is used, so all rules for that apply to this function (leap years, etc)
//---------------------------------split dates being passed

date1_array = date1.split("/")
date2_array = date2.split("/")
//---------------------------------establish date objects or integer values
if(!part){part = date2;var integer=true}
	if(!date1_array[0]){//nothing passed, doesn't exist, return false
		return 0;
	}
	else{//value does exist
		if(!date1_array[1]){//integer or date in non-standard format passed
			//var int1 = parseInt(date1_array[0])//creates integer value, date is not present (or not in xx/xx/xxxx format)
			//reason commented:eliminating the ability to handle integers as first parameter
			return 0;

		}
		else{//date contains at least 1 '/'
			if(date1_array[2]){//date contains xx/xx/xxxx, valid
				var day1 = parseInt(date1_array[0])
				var month1 = parseInt(date1_array[1])-1//date object month is 1 less (0 is jan)
				var year1 = parseInt(date1_array[2])
				objDate1 = new Date(year1,day1,month1)
			}
		}	
	}
	if(!date2_array[0]){//nothing passed, doesn't exist, return false
		if(!operand=="++" || operand == "--"){//increment or decrement requires no date2 integer
			return 0;
			
		}
	}
	else{//value does exist
		if(!date2_array[1]){//integer or date in non-standard format passed
			var integer = parseInt(date2_array[0])//creates integer value
		}
		else{//date contains at least 1 '/'
			if(date2_array[2]){//date contains xx/xx/xxxx, valid
				var day2 = parseInt(date2_array[0])
				var month2 = parseInt(date2_array[1])-1//date object month is 1 less (0 is jan)
				var year2 = parseInt(date2_array[2])
				objDate2 = new Date(year2,day2,month2)
			}
		}	
	}
//---------------------------------start operating
//---------------------------------find out if comparing dates or evaluating math expressions

	if(operand){//not required, avoiding errors
		if(objDate1){
			if(operand == "=" || operand == "==")
				if(objDate1 - objDate2 == 0){
					return true;//they're the same!
				}else{return false;}//not the same
			}if(operand == "<=" || operand == "=<" ){
				if(objDate1 <= objDate2){
					return true;
				}else return false;//date1 is not less than or equal to date2
			}if(operand == ">=" || operand == "=>" ){
				if(objDate1 >= objDate2){
					return true;
				}else return false;//date1 is not greater than or equal to date2
			}if(operand == "<"){
				if(objDate1 < objDate2){
					return true;
				}else return false;//date1 is not less than to date2
			}if(operand == ">"){
				if(objDate1 > objDate2){
					return true;
				}else return false;//date1 is not greater than to date2
			}if(operand == "!="){
				if(objDate1 != objDate2){
					return true;
				}else return false;//date1 is not = to date2
			}
		}else return false;
		if(integer){//operand == "+" || operand == "-" || operand =="++" || operand == "--"){//using math, either using date,date or date,integer
			var resultDate = new Date() // result date object after math
				//-----------------------using math, start with date object 1
				if(part){//error checking if part is present (day or month or year)
					resultDate = objDate1;
					if(integer){
						if(part == "day" || part == "Day" || part == "DAY"){//operation to be performed on day
							if(operand == "++"){resultDate.setDate(resultDate.getDate() + 1)}
							if(operand == "--"){resultDate.setDate(resultDate.getDate() - 1)}
							if(operand=="+"){resultDate.setDate(objDate1.getDay() + parseInt(integer))}
							if(operand=="+"){resultDate.setDate( objDate1.getDay() + parseInt(integer))}
						}else if (part == "month" || part == "Month" || part == "MONTH"){//operation to be performed on month
							if(operand == "++"){resultDate.setMonth(resultDate.getMonth() + 1)}
							if(operand == "--"){resultDate.setMonth(resultDate.getMonth() - 1)}
							if(operand == "+"){resultDate.setMonth(objDate1.getMonth() + parseInt(integer))}
							if(operand == "-"){resultDate.setMonth(objDate1.getMonth() - parseInt(integer))}
						}else if (part == "year" || part == "Year" || part == "YEAR"){//operation to be performed on month
							if(operand == "++"){resultDate.setYear(resultDate.getYear() + 1)}
							if(operand == "--"){resultDate.setYear(resultDate.getYear() - 1)}
							if(operand == "+"){resultDate.setYear(objDate1.getYear() + parseInt(integer))}
							if(operand == "-"){resultDate.setYear(objDate1.getYear() - parseInt(integer))}
						}
					}
				return resultDate;//date Object being returned as math result
				}
	}//end if(operand)		
}//end function



///***  Like showhidemulti except it actually hides layers which showhidedoesnt.  Its broken use this one.
function DoLayer(thelayer)
{

   var nsLayers = (document.layers) ? true : false;
   var ieLayers = (document.all) ? true : false;
   if(thelayer=="")
      return;
   thelayer = new String(thelayer)
//   alert(thelayer)
   var layers = thelayer.split(",")
   if (nsLayers)
   {
     
	      for(x=0;x<layers.length;x++){ 
				 
				 if(document.layers[layers[x]].visibility == "show"){
      			        document.layers[layers[x]].visibility="hide"
   				 }
				 else
				 {
				   document.layers[layers[x]].visibility = "show"
				   currentLayer=document.layers[layers[x]].name
                                                   SetCookie("ensLayer",currentLayer,1) 
				 }
		  } 
   }
   if (ieLayers)
   {
	  for(x=0;x<layers.length;x++){
	  if(document.all[layers[x]]){
		 if (document.all[layers[x]].style.visibility == "visible"){
			document.all[layers[x]].style.visibility = "hidden"; 
		 }
         else
         {
     	    document.all[layers[x]].style.visibility = "visible";
                currentLayer=document.all[layers[x]].id
                SetCookie("ensLayer",currentLayer,1) 

      	 }  
      }
   }
  }
}

//Reads a cookie with a specified name
function ReadCookie(cookieName) { var theCookie=""+document.cookie; var ind=theCookie.indexOf(cookieName); if (ind==-1 || cookieName=="") return ""; var ind1=theCookie.indexOf(';',ind); if (ind1==-1) ind1=theCookie.length; return unescape(theCookie.substring(ind+cookieName.length+1,ind1)); } 
//Writes a cookie with a specified name
function SetCookie(cookieName,cookieValue,nDays) {
 var today = new Date();
 var expire = new Date();
 if (nDays==null || nDays==0) nDays=1;
 expire.setTime(today.getTime() + 3600000*24*nDays);
 document.cookie = cookieName+"="+escape(cookieValue)
                 + ";expires="+expire.toGMTString();
}


function mailto(user) {
alert("\n          ---------------------------------------------- NOTICE ----------------------------------------------\n\n          Because there is a risk that information transmitted via Internet email could\n          fall into the wrong hands, we suggest that confidential information such as\n          account numbers or social security numbers not be transmitted via email.\n\n         --------------------------------------------------------------------------------------------------------          \n\nClick OK to proceed with email.")
locationstring = "mailto:" + user;
locationstring = locationstring + "@";
locationstring = locationstring  + "sunwestbank.com";
window.location = locationstring;
}

function confirmLeave(link) {
	var submitOK = confirm("You are leaving the Sunwest Bank Web site\n\nThe web site you selected is an external one located on another server.\nSunwest Bank has no responsibility for any external Web site.\nOur privacy policies do not apply to the linked Web site.\nPlease consult the privacy policy on that site for further information.\n\nThank you for visiting the Sunwest Bank Web site.");
	if ( submitOK ){ window.open(link,"body","");}
}
