	<!-- File: willgo.js                                                               -->
	<!-- Created by:            Ervin-White Resources, Inc.                            -->
	<!-- Description:           These are a series of javascript programs which are    -->
	<!--                        designed for the Willgo Website Enhancement project.   -->
	<!-- GetCookie():           Reads cookie; if exists welcomes user back to website. -->
	<!-- getCookieVal():        Used by GetCookie() function to return the values in   -->
	<!--                        the cookie named in the GetCookie() function.          -->
	<!-- CookieValueProp():     This function defines a new object which are key/value -->
	<!--                        pairs of the named cookie.                             -->
	<!-- setCookie():           This function sets a cookie. The cookie name is passed -->
	<!--                        to the function. Also you set the expiration date      -->
	<!--                        through a value passed into the function               -->
	<!-- ExtractCookieValue():  This is the function that retrieves the cookie value   -->
	<!--                        information and returns it to the HTML page.           -->
	<!-- getIsCookieMsg():      This function is called if a cookie exists. The        -->
	<!--                        dynamic information is generated and then stored in a  -->
	<!--                        variable to be passed to the program and printed out   -->
	<!--                        when the page is loaded                                -->
	<!-- getNoCookieMsg():      This function is called if a cookie does not exist.    -->
	<!--                        The information is generated and then stored in a      -->
	<!--                        variable to be passed to the program and printed out   -->
	<!--                        when the page is loaded                                -->
	<!-- getAllCookies()        This function retrieves all cookies for a single       -->
	<!--                        domain.                                                -->
	<!-- IntroTitle()           allows the printing of consistent links for any html   -->
	<!--                        page that uses this program.                           -->
	<!-- AutoRecTest()          Lets user know that they have not selected the AutoRec -->
	<!--                        function and how to add it to their profile.           -->
	<!-- verifySelect()         verifies that the user has selected a search id.       -->
	<!-- PageLastModified()     prints date the page was last modified based on        -->
	<!--                        file date. Also makes adjustment for Netscape or IE    -->
	<!--                        browsers based on which browser the client is using.   -->
	<!-- openWin                this function opens a window based on specification    -->
	<!--                        made in the call. It is called as follows:             -->
	<!--                        javascript:openWin(URL,width,height)                   -->
	<!-- verify(f)              This is the function that performs form verification.  -->
	<!--                        It will be invoked from the onSubmit() event handler.  -->
	<!--                        The handler should return whatever value this function -->
	<!--                        returns.                                               -->
	<!-- isblank(s)             A utility function that returns true if a string       -->
	<!--                        contains only whitespace characters.                   -->
	<!-- getOther(selectObj)    This utility will add an item to a select list based   -->
	<!--                        whether the list has "Other" defined as the last       -->
	<!--                        defined in the list, if it does then the user input    -->
	<!--                        will be added to the list.                             -->
	<!--                        An example of how this function is invoked:            -->
	<!--                                onChange="getOther(this)"                      -->
	<!--                        The above uses "this" to indicate the current select   -->
	<!--                        object.                                                -->
	<!-- popupWin(URL)          This utility calls a pop-up window using the URL which -->
	<!--                        is passed to it as the page to display in a set window -->
	<!--                        for a 5 second time. The user can also select a link   -->
	<!--                        asking that the pop-up not be displayed.               -->
	<!--                                                                               -->
	<!-- Author:                Alice Ervin                                            -->
	<!-- Company:               Ervin-White Resources, Inc.                            -->
	<!-- Email:                 aervin@triad.rr.com                                    -->
	<!-- Version: 3.00                                                                 -->

	function GetCookie(name) {
		var arg = name + "=";
		var alen = arg.length;
		var clen = document.cookie.length;
          var i = 0;
		while (i < clen) {
			var j = i + alen;
			if (document.cookie.substring(i,j) == arg) return getCookieVal(j);
			i = document.cookie.indexOf(" ", i) + 1;
			if (i == 0) break;
		}
		return null;
	}

	function getCookieVal (offset) {
		var endstr = document.cookie.indexOf(";", offset);
		if (endstr == -1) endstr = document.cookie.length;
			return unescape(document.cookie.substring(offset, endstr));
	}

	function CookieValueProp(name, value) {
		this.name = name;
		this.value = value;
	}

	var iscookie = "false";

	function SetCookie (name) {
		var expdate = new Date ();
		var value = "Do not show pop-up ad"
  		expdate.setTime(expdate.getTime() + (365 * 24 * 60 * 60 * 1000));
		document.cookie = name + "=" + value + "; path=/" + "; expires=" + expdate.toGMTString();
		window.close()
	}

	function ExtractCookieValue(name) {
		var c = GetCookie(name);
		if ( c != null) {
			var a = new Array();
			a = c.split("&");
			var aLen = a.length;
			var cType = new Array();
			for (i = 0, j = 0; i < aLen; i++, j++) {
				var cName = a[i];
				i++
				var cValue = a[i];
				cType[j] = new CookieValueProp( cName, cValue);
			}
			var cLen = cType.length;
			var msg = getNoCookieMsg();
			for (i = 0; i < cLen; i++) {
				if (cType[i].name == "Contact") {
					iscookie = "true";
					msg = getIsCookieMsg(cType[i].value);
				}
			}
			var nextyear = new Date();
			nextyear.setFullYear(nextyear.getFullYear() + 1);
			document.cookie = "AutoRec=" + c + "; expires=" + nextyear.toGMTString() + "; path=/";
			return msg;
		} else {
			msg = getNoCookieMsg();
			return msg;
		}
	}

	function getIsCookieMsg(name) {
		var iscookiemsg = 'Welcome Back  ';
		iscookiemsg += '<font color="#0000FF">' + name + '</font>!';
		return iscookiemsg;
	}

	function getNoCookieMsg() {
		var nocookiemsg = '<td colspan="3" align="center"><font face="Arial"><strong>';
		nocookiemsg += '<a href="/cgi-bin/dbman5/db.pl?db=registration&signup_form=1">Register Now</a>';
		nocookiemsg += '<br><font color="#FF0000">Registration Is FREE!&nbsp; There Are No Obligations...';
		nocookiemsg += 'But Lots Of Advantages!</font></strong></font></td>';
		return nocookiemsg;
	}

	function getAllCookies() {
		var allcookies = document.cookie;
		alert("The variable allcookies is " + allcookies);
	}

	function IntroTitle() {
		var intro = '<CENTER><TABLE cellPadding=0 width="100%" border=0><TBODY><TR><TD width="50%"><A name=Top></A><IMG height=63 src="/images/willog4.gif" width=277></TD>';
		intro += '<TD vAlign=top align=middle width="50%"><B><FONT face=Arial color=#0000ff size=2><A href="/willgo3/ModernNEIHTMPageBigBlue.htm">Trailers for Sale Database</A></FONT>';
		intro += '<BR><FONT face=Arial color=#0000ff size=2><A href="/willgo3/ModernBuyersResources.htm">Buyer Resources</A></FONT><BR>';
		intro += '<FONT face=Arial color=#0000ff size=2><A href="/willgo3/ModernSellersResources.htm">Seller Resources</A></FONT><BR>';
		intro += '<FONT face=Arial color=#0000ff size=2><A href="/willgo3/ModernTrlrRelatedSvcs.htm">Trailer Related Services</A></FONT><BR>';
		intro += '<FONT face=Arial color=#0000ff size=2><A href="/willgo3/ModernIndexBigBlue.htm">Home</A></FONT></B></TD></TR></TBODY></TABLE></CENTER>';
		return intro;
	}

	function AutoRecTest(form) {
		var msg = "You have not selected the AutoRec Feature.\n";
		msg += "If you wish to select this feature, on the next screen click on the \n";
		msg += "modify link at the bottom of the page and change your registration\n";
		msg += "so that the Automatic Recognition Feature is set to YES.";
		for (var i = 0; i < form.AutoRecFeature.length; i++) {
			if (form.AutoRecFeature[i].checked) {
				if (form.AutoRecFeature[i].value == "N") {
					alert(msg);
				}
			}
		}
	}

	function verifySelect(a) {
		if ((a.name == "CurrentListing") || (a.name == "ViewExpiredListing")){
			var msg = "You must select a listing first.";
			var type = "list";
		} else if (a.name == "ViewSearches") {
			var msg = "You must select a search first.";
			var type = "search";
		} else {
			var msg = "You must make a selection first.";
		}
		var c = 0;
		var vlen = a.selectID.length;
		if (vlen) {
			for (var i = 0; i < vlen; i++) {
				if (a.selectID[i].checked) {
					c = 1;
				}
			}
		} else {
			if (a.selectID.checked) {
				c = 1;
			}
		}
		
		if (c == 1) {
			if (type == "list"){
				if (a.deleteButton.value == "true") {
					var response = confirm("Are you sure you want to delete this record?");
					if (response == false) {
						document.CurrentListing.deleteButton.value = "false";
						return false;
					} else {
						document.CurrentListing.deleteButton.value = "false";
					}
					return true;
				}
			}
			return true;	
		} else {
			if (type == "list"){
				if (a.sortButton.value == "true") {
					document.CurrentListing.deleteButton.value = "false";
					return true;
				} else {
					alert(msg);
					return false;
				}
			} else {
				alert(msg);
				return false;
			}
		}
	}

	function clickDelete() {
		document.CurrentListing.deleteButton.value = "true";
	}

	function clickSort() {
		if (document.forms[0].name == "CurrentListing") {
			document.CurrentListing.sortButton.value = "true";
		} else if (document.forms[0].name == "ViewExpiredListing") {
			document.ViewExpiredListing.sortButton.value = "true";
		}
	}
	
	function PageLastModified() {
		update = new Date(document.lastModified)
		theMonth = update.getMonth() + 1
		theDate = update.getDate()
		var browser = new Object();
		// Figure out the browser major version.
		browser.version = parseInt(navigator.appVersion);
		// Now figure out if the browser is from one of the two
		// major browser vendors. Start by assuming it is not.
		browser.isNavigator = false;
		browser.isIE = false;
		if (navigator.appName.indexOf("Netscape") != -1) {
			theYear = update.getYear() + 1900;
			document.writeln("Last modified: " + theMonth + "/" + theDate + "/" + theYear);
		}
		else if (navigator.appName.indexOf("Microsoft") != -1) {
			theYear = update.getYear();
			document.writeln("Last modified: " + theMonth + "/" + theDate + "/" + theYear);
		}
	}

     function openWin(url, width, height) {
          var win;
          var windowName;
          var params;
          windowName  = "buttons";
          params = "toolbar=0,";
          params += "location=0,";
          params += "directories=0,";
          params += "status=0,";
          params += "menubar=0,";
          params += "scrollbars=1,";
          params += "resizable=1,";
          params += "top=50,";
          params += "left=50,";
          params += "width="+width+",";
          params += "height="+height;
          win = window.open(url, windowName, params);
     }

	// A utility function that 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;
	}

	// A utility function that returns 1 or 0 to indicate whether a radio 
	// button in a radio group has been selected.
	function getSelectedButton(buttonGroup) {
		for (var i = 0; i < buttonGroup.length; i++) {
			if (buttonGroup[i].checked) {
				return 1;
			}
		}
		return 0;
	}

	// This is the function that performs form verification. It is invoked
	// from the onsubmit event handler. The handler should return whatever
	// value this function returns.
	function verify(f) {
		var msg;
		var empty_fields = "";
		var errors = "";
		var r = 0;
		var OT = "false"
		
		// Loop through the elements of the form, looking for all
		// text and textarea elements that don't have an "optional" property
		// defined. Then, check for fields that are empty and make a list of them.
		// Also, if any of these elements have a "min" or a "max" property defined,
		// verify that they are numbers and 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.required) {
				
				// first check if the field is empty
				if ((e.value == null) || (e.value == "") || isblank(e.value) || (e.value == "---")) {
					empty_fields += "\n          " + e.name;
					continue;
				}
				
				// Now check for fields that are supposed to be numeric.
				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";
					}
				}
			}
			// identify if there is a form element named "OrganizationType"
			if (e.type == "radio") {
				if (f.elements[i].name == "OrganizationType") {
					OT = "true"
				}
			}
			
			// identify if form element is a list, either single or multiple select and if
			// the element is required.
			var s = 0
			var n = 0
			if (((e.type == "select-one") || (e.type == "select-multiple")) && e.required) {
				for (var a = 0; a < e.length; a++) {
					if (e.options[a].selected) {
						if ((e.options[a].text == null) || (e.options[a].text == "") || isblank(e.options[a].text) || (e.options[a].text == "---") || (e.options[a].text == "Select State or Province")) {
							n++;
						} else {
							s++
						}
					} else {
						n++;
					}
				}
				
				if (s == 0) {
					if (e.name == "Web_Location") {
						e.name = "Inspection_State";
					}
					empty_fields += "\n          " + e.name;
				} else {
					if (e.name == "Inspection_State") {
						e.name = "Web_Location";
					}
				}
			}
		}
		
		//check to see if the organization type radio field has been checked.
		if (OT == "true") {
			for (var i = 0; i < f.OrganizationType.length; i++) {
				if (f.OrganizationType[i].checked) {
					r = 1;
					break;
				}
			}
		} else {
			r = 1;
		}
		
		if (r == 0) {
			empty_fields += "\n          OrganizationType";
		}
		
		// Now, if there were 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 form was not submitted because of the following error(s).\n";
		msg += "Please correct these error(s) and re-submit.\n";
		msg += "______________________________________________________\n\n"
	
		if (empty_fields) {
			msg += "- The following required field(s) are empty:"
			+ empty_fields + "\n";
			if (errors) msg += "\n";
		}
		msg += errors;
		alert(msg);
		return false;
	}

	function getOther(selectObj) {
		var listLength = selectObj.length;
		var itemIndex = selectObj.selectedIndex;
		var otherIndex = listLength - 1;
		var otherValue = selectObj.options[otherIndex].text;

		if (otherValue == "Other") {

			if (itemIndex == otherIndex) {

				var listItem = new Array(listLength);
				var listValue = new Array(listLength);

				for (var i = 0; i < listLength; i++) {
					listItem[i] = selectObj.options[i].text;
					listValue[i] = selectObj.options[i].value;
				}

				listItem[listLength] = listItem[otherIndex]
				listValue[listLength] = listValue[otherIndex]

				var other = prompt("Please enter your information:", "");
				listItem[otherIndex] = other;
				listValue[otherIndex] = other;

				selectObj.length = 0
				for (i = 0; i < listLength + 1; i++) {
					selectObj.options[i] = new Option(listItem[i]);
					selectObj.options[i].value = listValue[i];
				}

				selectObj.options[otherIndex].selected = true;
				selectObj.className='itemChanged';
			} else {
				selectObj.className='itemChanged';
			}
		} else {
			selectObj.className='itemChanged';
		}
	}

	function changeColor(selectObj) {
		selectObj.className='itemChanged';
	}
	
	function popupWin(URL) {
		var CookieName = "notShowAd";
		var stored_value = GetCookie(CookieName);

		if (stored_value == null) {		//if a cookie doesn't exist then show pop-up
			newWindow = window.open(URL,'newWin', 'width=600,height=265,left = 312,top = 184');
			setTimeout('newWindow.close()', 10000);	// delay 5 seconds before closing
		}
	}
