
//----------------------------------------------------------------- Browser detection ------------------------------------------------------


//Detects browser, version and OS.
//use by accessing the strings:
//BrowserDetect.browser displays the browser name
//BrowserDetect.version displays the version number
//BrowserDetect.os displays the computer platform


var BrowserDetect = {
	init: 
	function () 
		{
			this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
			this.version = this.searchVersion(navigator.userAgent) || this.searchVersion(navigator.appVersion) || "an unknown version";
			this.OS = this.searchString(this.dataOS) || "an unknown OS";
		},


	searchString: function (data) 
		{
			for (var i=0;i<data.length;i++)	
				{
					var dataString = data[i].string;
					var dataProp = data[i].prop;
					this.versionSearchString = data[i].versionSearch || data[i].identity;
					if (dataString) 
						{
							if (dataString.indexOf(data[i].subString) != -1) return data[i].identity;
						}
					else if (dataProp) return data[i].identity;
				}
		},


	searchVersion: function (dataString) 
			{
				var index = dataString.indexOf(this.versionSearchString);
				if (index == -1) return;
				return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
			},


	dataBrowser: 	[


			{ 	string: navigator.userAgent,
				subString: "OmniWeb",
				versionSearch: "OmniWeb/",
				identity: "OmniWeb"
			},


			{
				string: navigator.vendor,
				subString: "Apple",
				identity: "Safari"
			},


			{
				prop: window.opera,
				identity: "Opera"
			},


			{
				string: navigator.vendor,
				subString: "iCab",
				identity: "iCab"
			},


			{
				string: navigator.vendor,
				subString: "KDE",
				identity: "Konqueror"
			},


			{
				string: navigator.userAgent,
				subString: "Firefox",
				identity: "Firefox"
			},


			{
				string: navigator.vendor,
				subString: "Camino",
				identity: "Camino"
			},


			{		// for newer Netscapes (6+)
				string: navigator.userAgent,
				subString: "Netscape",
				identity: "Netscape"
			},


			{
				string: navigator.userAgent,
				subString: "MSIE",
				identity: "Explorer",
				versionSearch: "MSIE"
			},


			{
				string: navigator.userAgent,
				subString: "Gecko",
				identity: "Mozilla",
				versionSearch: "rv"
			},


			{ 		// for older Netscapes (4-)
				string: navigator.userAgent,
				subString: "Mozilla",
				identity: "Netscape",
				versionSearch: "Mozilla"
			}


		],


	dataOS : 	[
			{
				string: navigator.platform,
				subString: "Win",
				identity: "Windows"
			},


			{
				string: navigator.platform,
				subString: "Mac",
				identity: "Mac"
			},


			{
				string: navigator.platform,
				subString: "Linux",
				identity: "Linux"
			}


		]


};


BrowserDetect.init();

var widthofpage = 0;
var widthfactor = 0;

var heightofpage = 0;
var heightfactor = 0;

var span = new Array(0,345,465,610,745);


//--------------------------------------------------------------------- perform onPageLoad setup functions ---------------------------------------------------


function slidesIni() {

	currentslide = 1;
	currentad = 0;
	currentDiv = 1;
	intTiming = 0;
	showing = 0;
	fading = 100;
	phase = 0;

	slidetime = setInterval("slideShow()",10000);

	clearButtons();
	setButton(0);

	$("pix1").innerHTML = "<img border='0' src='images/slides/"+slidebank[0]+"' width='"+slidewidth[0]+"' height='"+slideheight[0]+"'>";
	$("pix2").innerHTML = "<img border='0' src='images/slides/"+slidebank[1]+"' width='"+slidewidth[1]+"' height='"+slideheight[1]+"'>";

	obj1 = $("pix2");

	if (obj1.style) {
		if (obj1.style.MozOpacity!=null) {  
			/* Mozilla's pre-CSS3 proprietary rule */
			obj1.style.MozOpacity = (0.0);
		} else if (obj1.style.opacity!=null) {
			/* CSS3 compatible */
			obj1.style.opacity = (0.0);
		} else if (obj1.style.filter!=null) {
			/* IE's proprietary filter */
			obj1.style.filter = "alpha(opacity=0)";
		}
	}
}

//------------------------------------------------------------------------------ Nav functions ----------------------------------------------------

function blankLinks() {
	$("home_link").style.color = "#6f9cad";
	$("home_link").style.fontWeight = "300";
	$("company_link").style.color = "#6f9cad";
	$("company_link").style.fontWeight = "300";
	$("news_link").style.color = "#6f9cad";
	$("news_link").style.fontWeight = "300";
	$("careers_link").style.color = "#6f9cad";
	$("careers_link").style.fontWeight = "300";
	$("find_link").style.color = "#6f9cad";
	$("find_link").style.fontWeight = "300";
	$("services_link").style.color = "#6f9cad";
	$("services_link").style.fontWeight = "300";
}

function navto(link,url,vars) {
	blankLinks();
	$(link+"_link").style.color = "#FFFFFF";
	$(link+"_link").style.fontWeight = "700";
	nextFrame("content",url,vars);
}

function nextFrame(div,url,vars) {

	if((url== "homecontent.php")||(url== "companycontent.php") ||(url== "careerscontent.php")) $("quotediv").style.visibility = "visible";
	else $("quotediv").style.visibility = "hidden";
	$("logonbox").style.visibility = "hidden";
	new Ajax.Updater(div,url,{method:'post',parameters:vars,asynchronous:false});
}

function openLogonBox() {

	if($("logonbox").style.visibility == "hidden") $("logonbox").style.visibility = "visible";
	else $("logonbox").style.visibility = "hidden";
}

//----------------------------------------------------------------------- accept email address submition ------------------------------------------

function validEmail(email) {
	invalidChars = " /:;,";

	if(email == "") return false;

	for(i=0;i<invalidChars.length;i++) {
		badChar = invalidChars.charAt(i);
		if(email.indexOf(badChar,0) > -1) return false;
	}
	atPos = email.indexOf("@",1);
	if(atPos == -1) return false;
	if(email.indexOf("@",atPos+1) > -1) return false;
	periodPos = email.indexOf(".",atPos);
	if(periodPos == -1) return false;
	if(periodPos+3 > email.length) return false;

	return true;
}

function saveEmailAddress() {
	var address = $("emailform").value;

	if((address == "")||(address == "Please enter your Email Address")) {
		$("emailform").value = "Please enter your Email Address";
		return;
	}

	if(!validEmail(address)) {
		$("emailform").value = "Invalid Address - Please try again";
		return;
	}

	new Ajax.Request("storeemailadd.php",{method:'post',parameters:"address="+address,asynchronous:true,onSuccess:function(transport){
		$("emailform").value = transport.responseText
	}
	});

}

//------------------------------------------------------------------- Slideshow load and crossfade code ---------------------------------------------

var currentslide = 1;
var currentad = 0;
var currentDiv = 1;
var intTiming = 0;
var showing = 0;
var fading = 100;
var phase = 0;

function slideShow() {
	fadeOut = currentDiv;
	if(currentDiv == 2) currentDiv = 0;
	currentDiv++;
	fadeIn = currentDiv;
	showing = 0;
	fading = 100;
	if(intTiming == 0) intTiming = setInterval("xfade(fadeIn,fadeOut);",70);
}


function xfade(fadeIn,fadeOut) {

	showing = showing + 5;
	fading = fading - 5;


	obj1 = $("pix"+fadeOut);
	obj2 = $("pix"+fadeIn);
	
	if (obj1.style) {
		if (obj1.style.MozOpacity!=null) {  
			/* Mozilla's pre-CSS3 proprietary rule */
			obj1.style.MozOpacity = (fading/100);
		} else if (obj1.style.opacity!=null) {
			/* CSS3 compatible */
			obj1.style.opacity = (fading/100);
		} else if (obj1.style.filter!=null) {
			/* IE's proprietary filter */
			obj1.style.filter = "alpha(opacity="+fading+")";
		}
	}
	
	if (obj2.style) {
		if (obj2.style.MozOpacity!=null) {  
			/* Mozilla's pre-CSS3 proprietary rule */
			obj2.style.MozOpacity = (showing/100);
		} else if (obj2.style.opacity!=null) {
			/* CSS3 compatible */
			obj2.style.opacity = (showing/100);
		} else if (obj2.style.filter!=null) {
			/* IE's proprietary filter */
			obj2.style.filter = "alpha(opacity="+showing+")";
		}
	}


	if(fading < 1) {
		clearInterval(intTiming);
		intTiming = 0;

		var oldslide = currentslide;
		currentslide++;
		if(currentslide == slidebank.length) currentslide = 0;
		$("pix"+fadeOut).innerHTML = "<img border='0' src='images/slides/"+slidebank[currentslide]+"' width='"+slidewidth[currentslide]+"' height='"+slideheight[currentslide]+"'>";
		clearButtons();
		setButton(oldslide);	
		phase++;
	}
	
}

function clearButtons() {
	for(var i=0;i < slidebank.length;i++) {
		$("ball"+i).style.width = 12+"px";
		$("ball"+i).style.height = 12+"px";
	}
}

function setButton(slide) {
	$("ball"+slide).style.width = 16+"px";
	$("ball"+slide).style.height = 16+"px";
}

var restartSlides = 0;

function showSlide(slide) {

	clearTimeout(restartSlides);
	restartSlides = setTimeout("slidesIni();",20000);
	
	clearButtons();
	setButton(slide);	

	clearInterval(intTiming);
	intTiming = 0;
	clearInterval(slidetime);
	slidetime = 0;

	$("pix1").innerHTML = "<img border='0' src='images/slides/"+slidebank[slide]+"' width='"+slidewidth[slide]+"' height='"+slideheight[slide]+"'>";

	obj1 = $("pix1");

	if (obj1.style) {
		if (obj1.style.MozOpacity!=null) {  
			/* Mozilla's pre-CSS3 proprietary rule */
			obj1.style.MozOpacity = (1.0);
		} else if (obj1.style.opacity!=null) {
			/* CSS3 compatible */
			obj1.style.opacity = (1.0);
		} else if (obj1.style.filter!=null) {
			/* IE's proprietary filter */
			obj1.style.filter = "alpha(opacity=100)";
		}
	}

	obj1 = $("pix2");

	if (obj1.style) {
		if (obj1.style.MozOpacity!=null) {  
			/* Mozilla's pre-CSS3 proprietary rule */
			obj1.style.MozOpacity = (0.0);
		} else if (obj1.style.opacity!=null) {
			/* CSS3 compatible */
			obj1.style.opacity = (0.0);
		} else if (obj1.style.filter!=null) {
			/* IE's proprietary filter */
			obj1.style.filter = "alpha(opacity=0)";
		}
	}
}

//------------------------------------------------------------------start date picker -----------------------------------------------------------------

//Date Picker Calendar - an interface for entering dates into a text field. Adapted from code by Julian Robichaux -- http://www.nsftools.com
//requires the companion stylesheet DatePickerCalendar.css

var dayArray = new Array('Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa');
var monthArray = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
var globalDate = "";
var otherDate = "";
var otherPlace = "";
var focusflag = "";
var calColor = "";

/*
                                                                             USING THE DATE PICKER CALENDAR INTERFACE
						   
PART 1 - CREATING THE HTML TEXT FORM FIELDS THAT WILL INVOKE THE INTERFACE

PLACING THE DIV AREA - Place it just above the </body> tag of the host page

Here are examples of the text input fields that would be used to invoke the calendar. 

 The first example is a "From Date - To Date" pair as might be used in setting boundry dates for a report or search:

                                                                                               arguement list:   dateField  setField    color   allow      flag  xoff yoff startingDate  todate
 <input readonly value="" type="text" size="10" name="fromDate" id="fromDate" onfocus="blur(); displayDatePicker('fromDate','from_Date','blue',''        ,''   ,-300,-150,''           ,'toDate');">
 <input readonly value="" type="text" size="10" name="toDate"   id="toDate"   onfocus="blur(); displayDatePicker('toDate'  ,'toDate'   ,'blue','fromDate',''   ,-300,-150,''           ,''      );">

 The code that calls the calendar has been streatched out to line the arguements up with the lables above them. Naturally, this would not be the case in a real page's markup.
 value can be set to today's date if you like. That can also be passed to the calendar as the startingDate arguement.
 color has been set to BLUE and so the date picker code will make sure the text is blue when it places it into the text field
 blur() prevents the cursor from appearing in the field so the users never get the impression that they are allowed to enter a date directly into the text field.
 allow is passed in to signal that entry of a date in this field is allowed only if the passed in field already has a date entered (see below).
 flag is blank in this example because there is no need to update a database with these entered dates as explained below.
 todate is the complement of allow. It forces a test of the date range for a valid to-from range (seel below).

 This next example is from a database form where the entered value will be passed to a database update routine the moment it is changed. In this case, the calendar is invoked by clicking an icon:

                                                    arguement list:   dateField  setField    color   allow      flag  xoff yoff startingDate                           todate
 <a name="jobdue" id="jobdue" href="#hold" onclick="displayDatePicker('Due_Date','jobdue'   ,''     ,''       ,'blur',200, 200 ,'<% =string([jobs_base]Due_Date;7) %>','');">
 <img src="Calander.jpg" width="13" height="11" border="0" alt="Select a Date"></a>&nbsp;
 <input class="customRowColor2" value="<% =string([jobs_base]Due_Date;7) %>" type="text" size="21" name="Due_Date" id="Due_Date" onfocus="blur();" onblur="updateDM('updateDM.a4d','<% =$tableJ %>',this.name,this.value,'<% =$keyfieldJ %>','','');">

 Again, the arguement list has been formatted to fall under the lables.
 we start by creating a hypertext link attached to an icon. The user clicks the icon instead of clicking in the text field to open the calendar interface.
 The setField has been set to the icon's ID. The calendar interface will open relative to its position rather than the input field's position. This is strictly a matter of persional choice.
 Color is blank and thus will default to any CSS settings or the default BLACK otherwise
 allow and todate are blank in that this is a stand-alone date field and isn't associated with any other fields
 startingDate has a value this time. It is given a string-converted version of the value as contained in the Due_Date field of the jobs_base table in the database as formatted and returned by the script method string()
 In this example, the text field has been assigned to the "customRowColor2" class to format it's background color. This is, of course, completely optional.
 The input field's VALUE has been filled with the same current contents of the database as startingDate above.
 This example of the input field has the onblur event handler. As soon as a value is selected from the calendar interface, it is placed into the input field (as always) but because of the inclusion of the flag
    arguement, the calendar code has been instructed to place this form element in focuse as soon as the date in inserted into the text field. This will cause the triggering of the onfocuse handler which will
    immediately blure the element. Now this triggers the onblur handler which contains a call to the database update function updateDM(). This function takes the new date as well as other necessary arguements and
    performs the database update through an AJAX call to the server-side script updateDM.a4d. 
 The use of an icon in this case is to prevent the user from having to click in the text field to launch the calendar interface and by so doing trigger an unnecessary database update.
 
PART 2 - HOW THE ARGUEMENTS ARE USED BY THE DATE PICKER CODE

The following arguements are accepted by the Date Picker Calendar:

 1) dateField is the text box ID where the date selected in the calendar will be displayed.
 2) setField is the ID of the object the picker will be positioned relitive to, likely the date text field itself or perhaps a page element that will be common to all instances of the calendar.
 3) coloring is the font color for the text box. It will be turned red as long as the calendar is open, then returned to this color when the calendar is closed and the selected date is placed into the field.
 4) allow is the ID of another date field that must contain a date before the user can select this date. if it's blank, an alert is issued to the user to set the "allow" date first. Also used for testing date range.
    As a rule, this is when there are a pair of calendar fields for "From" and "To" dates. This ID would be for the "From" field with the user currently entering the "To" date. The "From" date is tested to make sure
    it is less than or equal to the just selected "To" date. If not, an alert is issued and the "To" date is blanked out.
 5) flag, if set, causes the text field to gain focus once a new date has been placed there, thus forcing it to blur due to the blur() part of the onfocuse event handler. Requires an onblur handler in the text field also.
    The idea here is that the onblur handler triggers an AJAX call to a database update script and trigger a database update of the contents of this text field (ie, the newly selected date). This flag should always be empty
    except when entering dates into a database update form. 
 6) xoff and yoff are offsets to be added to the picker positioning
 7) startingDate is the date the picker will default to when it opens
 8) todate is used when there are "From" and "To" date pairs of calendar selectors much like the "allow" arguement above. This is the complement to "allow". If, for exapmle, the user is entering the "From" date,
    pass in the ID of the "To" date field and it will be used here. If the "To" date has already been set and the user is now entering the "From" date, a test is made to make sure that the "To" date is
    greater than or equal to the "From" date. If not, an alert is issued and the "To" date is set equal to the "From" date entered here.

*/

function displayDatePicker(dateField,setField,coloring,allow,flag,xoff,yoff,startingDate,todate)
	{

		if(startingDate == "00/00/00"){startingDate = '';}
		globalDate = "";
		otherDate = "";
		otherPlace = "";
		if(todate != "") 
			{
				//otherDate = $(todate).value;
				otherPlace = todate;
			}
		focusflag = flag;
		calColor = coloring;
		
		if(allow != "")
			{
				var theTest = testDate(allow);
				if(theTest == 1) {return;}
			}
		
  		var targetDateField = document.getElementById(dateField);
		var displayBelowThisObject = document.getElementById(setField);
		calColor = coloring;
		targetDateField.style.color = "red";
		var y = Position.cumulativeOffset($(setField)).top + yoff;
		var x = Position.cumulativeOffset($(setField)).left + xoff;
  		drawDatePicker(dateField, x, y, startingDate);
		
	}

function testDate(datefield)
	{
		var theField = document.getElementById(datefield).value;
		if(theField == "")
			{
				alert("You must select a 'FROM' date before you can select a 'TO' date.");
				return 1;
			}
		else
			{
				globalDate = theField;
				return 0;
			}
	}

function drawDatePicker(dateField, x, y, startingDate)
	{

  		var dt = new Date(startingDate);
  		var targetDateField = document.getElementById(dateField);

  		// move the datepicker div to the proper x,y coordinate and toggle the visiblity

  		var pickerDiv = document.getElementById('datePickerDivID');

  		pickerDiv.style.position = "absolute";
  		pickerDiv.style.left = x + "px";
  		pickerDiv.style.top = y + "px";

		if(pickerDiv.style.visibility == "visible")
			{
				pickerDiv.style.visibility = "hidden";
				targetDateField.style.color = calColor;
			}
		else
			{
				pickerDiv.style.visibility = "visible";
			}

  		//pickerDiv.style.visibility = (pickerDiv.style.visibility == "visible" ? "hidden" : "visible");
  		pickerDiv.style.display = (pickerDiv.style.display == "block" ? "none" : "block");
  		pickerDiv.style.zIndex = 10000;
 
  		//draw the datepicker table

  		refreshDatePicker(dateField, dt.getFullYear(), dt.getMonth(), dt.getDate());
	}

function refreshDatePicker(dateField, year, month, day)
	{
  		// if no arguments are passed, use today's date; otherwise, month and year
  		// are required (if a day is passed, it will be highlighted later)

  		var targetDateField = document.getElementById(dateField);
		var dateFieldName = targetDateField.name;
  		var thisDay = new Date();
 
  		if ((month >= 0) && (year > 0)) 
			{
    				thisDay = new Date(year, month, 1);
  			} 
		else 
			{
    				day = thisDay.getDate();
    				thisDay.setDate(1);
  			}

  		var crlf = "\r\n";
  		var TABLE = "<table cols=7 border='1' class='dpTable'>" + crlf;
  		var xTABLE = "</table>" + crlf;
  		var TR = "<tr class='dpTR'>";
  		var TR_title = "<tr class='dpTitleTR'>";
  		var TR_days = "<tr class='dpDayTR'>";
  		var TR_todaybutton = "<tr class='dpTodayButtonTR'>";
  		var xTR = "</tr>" + crlf;
  		var TD = "<td class='dpTD' onMouseOut='this.className=\"dpTD\";' onMouseOver=' this.className=\"dpTDHover\";' ";    // leave this tag open, because we'll be adding an onClick event
  		var TD_title = "<td colspan=5 align='center' class='dpTitleTD'>";
  		var TD_buttons = "<td class='dpButtonTD'>";
  		var TD_todaybutton = "<td colspan=7 align='center' class='dpTodayButtonTD'>";
  		var TD_days = "<td class='dpDayTD'>";
  		var TD_selected = "<td class='dpDayHighlightTD' onMouseOut='this.className=\"dpDayHighlightTD\";' onMouseOver='this.className=\"dpTDHover\";' ";    // leave this tag open, because we'll be adding an onClick event
  		var xTD = "</td>" + crlf;
  		var DIV_title = "<div class='dpTitleText'>";
  		var DIV_selected = "<div class='dpDayHighlight'>";
  		var xDIV = "</div>";

		var html = "<table border='1' class='dpTable'><tr><td colspan='2'><table width='40' class='dpTable'><tr><td align='left' width='25' style='border:1px solid black;'><a onclick=\"hideDatePicker('" + dateField + "');\" style='cursor:pointer;text-decoration:none;color:red;'><b>X</b></a></td><td align='left'>Close</td></tr></table></td><td align='center'><a style='cursor:pointer;text-decoration:none;' onclick=\"updateDateField('" + dateField + "', '00/00/0000');\">Clear Date Field</a></td></tr><tr><td>";
  		// start generating the code for the calendar table
		
		/////////////////// START OF YEAR MODULE ///////////////////////
		//creates a year scroll table to the left of the calendar allowing quick-pick of the year to display
		//to remove this feature, comment out everything from here to END OF YEAR MODULE.
		
		newDay = new Date();
		var startyear = newDay.getFullYear() + 10;
 		var startmonth = thisDay.getMonth();

		html += "<div style='height:170px; overflow:auto'><table border='1' class='dpTable'>";

		for(y=0;y<16;y++) 
			{
				html += "<tr><td width='45' class='dpTD' ";
				html += "onMouseOut='this.className=\"dpTD\";' onMouseOver=' this.className=\"dpTDHover\";' >";
				html += "<a href='#' style='text-decoration:none' ";
				html += "onclick='refreshDatePicker(\"" + dateField + "\",\"" + (startyear - y) + "\",\"" + startmonth + "\");return false;'>";
				html += (startyear - y) + "</a></td></tr>";
			}

		html += "</table></div></td><td>";
		/////////////////// END OF YEAR MODULE ///////////////////////
		
		/////////////////// START OF MONTH MODULE /////////////////////////
		//creatres a month scroll table between the calendar and the year table so the month can be selected quickly without having to page using the forward/back month arrows
		//to remove this feature, comment out everything from here to END OF MONTH MODULE.
		
		var currentyear = thisDay.getFullYear();

		html += "<div style='height:170px; overflow:auto'><table border='1' class='dpTable'>";

		for(y=0;y<12;y++) 
			{
				var rollingdate = new Date(currentyear,y)
				var amonth = rollingdate.getMonth()
				html += "<tr><td width='45' class='dpTD' ";
				html += "onMouseOut='this.className=\"dpTD\";' onMouseOver=' this.className=\"dpTDHover\";' >";
				html += "<a href='#' style='text-decoration:none' ";
				html += "onclick='refreshDatePicker(\"" + dateField + "\",\"" + currentyear + "\",\"" + y + "\");return false;'>";
				html += monthArray[amonth] + "</a></td></tr>";
			}

		html += "</table></div></td><td>";
		/////////////////// END OF MONTH MODULE ////////////////////
		
  		html += TABLE;
 
  		// this is the title bar, which displays the month and the buttons to
  		// go back to a previous month or forward to the next month

  		html += TR_title;
  		html += TD_buttons + getButtonCode(dateField, thisDay, -1, "&lt;") + xTD;
  		html += TD_title + DIV_title + monthArray[ thisDay.getMonth()] + " " + thisDay.getFullYear() + xDIV + xTD;
  		html += TD_buttons + getButtonCode(dateField, thisDay, 1, "&gt;") + xTD;
  		html += xTR;
 
  		// this is the row that indicates which day of the week we're on

  		html += TR_days;

  		for(i = 0; i < dayArray.length; i++) html += TD_days + dayArray[i] + xTD;

  		html += xTR;
 
  		// now we'll start populating the table with days of the month

  		html += TR;
 
  		// first, the leading blanks

  		for (i = 0; i < thisDay.getDay(); i++) html += TD + "&nbsp;" + xTD;
 
  		// now, the days of the month

  		do 
			{
    				dayNum = thisDay.getDate();
    				TD_onclick = " onclick=\"updateDateField('" + dateField + "', '" + getDateString(thisDay) + "');\">";
    
    				if (dayNum == day)
      					html += TD_selected + TD_onclick + DIV_selected + dayNum + xDIV + xTD;
    				else
      					html += TD + TD_onclick + dayNum + xTD;
    
    				// if this is a Saturday, start a new row

    				if (thisDay.getDay() == 6)
      				html += xTR + TR;
    
    				// increment the day

    				thisDay.setDate(thisDay.getDate() + 1);
  			}
 			while (thisDay.getDate() > 1)

 
  		// fill in any trailing blanks

  		if (thisDay.getDay() > 0) 
			{
    				for (i = 6; i > thisDay.getDay(); i--) html += TD + "&nbsp;" + xTD;
  			}
  		html += xTR;
 
  		// add a button to allow the user to easily return to today, or close the calendar

  		var today = new Date();
  		var todayString = "Today is " + dayArray[today.getDay()] + ", " + monthArray[ today.getMonth()] + " " + today.getDate();
  		html += TR_todaybutton + TD_todaybutton;
  		html += "<button name='now' class='dpTodayButton' onClick='refreshDatePicker(\"" + dateField + "\");return false;'>this month</button> ";

		//we don't want a close button so this line is commented out
  		//html += "<button class='dpTodayButton' onClick='updateDateField(\"" + dateField + "\");'>close</button>";

  		html += xTD + xTR;
 
  		// and finally, close the table

  		html += xTABLE + "</td></tr></table>";
 
  		document.getElementById('datePickerDivID').innerHTML = html;
	}


//Convenience function for writing the code for the buttons that bring us back or forward a month.

function getButtonCode(dateField, dateVal, adjust, label)
	{
  		var newMonth = (dateVal.getMonth () + adjust) % 12;
  		var newYear = dateVal.getFullYear() + parseInt((dateVal.getMonth() + adjust) / 12);
  		if (newMonth < 0) 
			{
    				newMonth += 12;
    				newYear += -1;
  			}
  		return "<button name='nav" + adjust + "' class='dpButton' onClick='refreshDatePicker(\"" + dateField + "\", " + newYear + ", " + newMonth + ");return false;'>" + label + "</button>";
	}

function getDateString(dateVal)
	{
  		var dayString = "00" + dateVal.getDate();
  		var monthString = "00" + (dateVal.getMonth()+1);
  		dayString = dayString.substring(dayString.length - 2);
  		monthString = monthString.substring(monthString.length - 2);
 
      	return monthString + '/' + dayString + '/' + dateVal.getFullYear();

	}

//Convert a string to a JavaScript Date object.

function getFieldDate(dateString)
	{
  		var dateVal;
  		var dArray;
  		var d, m, y;

     		dArray = splitDateString(dateString);

  	        d = parseInt(dArray[1], 10);
 	        m = parseInt(dArray[0], 10) - 1;
 	        y = parseInt(dArray[2], 10);

		dateVal = new Date(y, m, d);
 	 	return dateVal;
	}

//split a date string into an array of elements

function splitDateString(dateString)
	{
  		var dArray;

    		dArray = dateString.split("/");

  		return dArray;
	}

function datePickerClosed(dateString)
	{
		if(focusflag != "") {
			//a function to run upon close if flag is given;
			focusflag = "";
			otherPlace = ""; 
		}
	}

function updateDateField(dateField, dateString)
	{
  		var targetDateField = document.getElementById(dateField);
  		if (dateString)
			{
				targetDateField.value = dateString;
			}
 
		hideDatePicker(dateField);
 
 
  		// after the datepicker has closed, run a user-defined function called
  		// datePickerClosed, passing the field that was just updated as a parameter
  		// (note that this will only run if the user actually selected a date from the datepicker)

  		if ((dateString) && (typeof(datePickerClosed) == "function")) datePickerClosed(dateString);
	}

function hideDatePicker(dateField) 
	{
  		var targetDateField = document.getElementById(dateField);
		targetDateField.style.color = calColor;

  		var pickerDiv = document.getElementById("datePickerDivID");
  		pickerDiv.style.visibility = "hidden";
  		pickerDiv.style.display = "none";
}
	
//----------------------------------------------------------------- end date picker -------------------------------------------------------------------

function showJobDetails(id) {
	if($("details_"+id).innerHTML == "") {
		$("arrow_"+id).src = "images/arrowdown.png";
		$("details_"+id).innerHTML = "Searching...";
		$("learn_"+id).innerHTML = "Close";
		$("arrowdiv_"+id).style.left = "140px";
		new Ajax.Request('listjobdetails.php',{method:'post',parameters:'id='+id,asynchronous:false,onSuccess:function(transport){
			reply = transport.responseText;
			$("details_"+id).innerHTML = reply;
		}});
	}
	else {
		$("arrow_"+id).src = "images/arrowright.png";
		$("details_"+id).innerHTML = "";
		$("learn_"+id).innerHTML = "Learn More";
		$("arrowdiv_"+id).style.left = "160px";
	}
}

function showPixDetails(url,width,height,div) {
	$("innerbox").innerHTML = "<img src='"+url+"' width='"+width+"' height='"+height+"' />";
	$("innerbox").style.overflow = "hidden";
	$("infobox").style.height = "315px";
	$("infobox").style.width = "550px";
	$("innerbox").style.height = "285px";
	$("innerbox").style.width = "520px";

  	$("infobox").style.visibility = "visible";
  	$("infobox").style.display = "block";

  	$("infobox").style.position = "absolute";
  	$("infobox").style.zIndex = "1000000";
  	$("innerbox").style.zIndex = "1000001";
  	$("xbox").style.zIndex = "1000001";
	$("infobox").clonePosition($(div),{setLeft:true,setTop:true,setWidth:false,setHeight:false,offsetTop:0,offsetLeft:0});
	$("infobox").style.visibility = "visible";

}

function showPixFull(url,width,height,div) {
	var topside = parseInt(height)+30;

	$("innerbox").innerHTML = "<img src='"+url+"' width='"+width+"' height='"+height+"' />";
	$("innerbox").style.overflow = "hidden";
	$("infobox").style.height = topside+"px";
	$("infobox").style.width = "550px";
	$("innerbox").style.height = height+"px";
	$("innerbox").style.width = "520px";

  	$("infobox").style.visibility = "visible";
  	$("infobox").style.display = "block";

  	$("infobox").style.position = "absolute";
  	$("infobox").style.zIndex = "1000000";
  	$("innerbox").style.zIndex = "1000001";
  	$("xbox").style.zIndex = "1000001";
	$("infobox").clonePosition($(div),{setLeft:true,setTop:true,setWidth:false,setHeight:false,offsetTop:0,offsetLeft:0});
	$("infobox").style.visibility = "visible";

}

function updatePropLists(region,bbcombo) {
	new Ajax.Request('updateproplists.php',{method:'post',parameters:'region='+region+'&bbcombo='+bbcombo,asynchronous:false,onSuccess:function(transport){
			reply = transport.responseText.split("^");
			$("findpropselect").innerHTML = reply[0];
			//$("findpropregion").innerHTML = reply[1];
			//$("findpropbb").innerHTML = reply[2];
			$("detailsview").innerHTML = reply[3];
	}});
}

function chub(id) {
	if($("details_"+id).innerHTML == "") {
		$("arrow_"+id).src = "images/arrowdown.png";
		$("details_"+id).innerHTML = "Searching...";
		$("learn_"+id).innerHTML = "Close";
		$("arrowdiv_"+id).style.left = "340px";
		new Ajax.Request('chubprop.php',{method:'post',parameters:'id='+id,asynchronous:false,onSuccess:function(transport){
			reply = transport.responseText;
			$("details_"+id).innerHTML = reply;
		}});
	}
	else {
		$("arrow_"+id).src = "images/arrowright.png";
		$("details_"+id).innerHTML = "";
		$("learn_"+id).innerHTML = "Learn More";
		$("arrowdiv_"+id).style.left = "360px";
	}
}

function moreProps(nextlist,lastlist) {
	new Ajax.Request('updateproplists.php',{method:'post',parameters:'nextlist='+nextlist+'&lastlist='+lastlist,asynchronous:false,onSuccess:function(transport){
			reply = transport.responseText.split("^");
			$("findpropselect").innerHTML = reply[0];
			//$("findpropregion").innerHTML = reply[1];
			//$("findpropbb").innerHTML = reply[2];
			$("detailsview").innerHTML = reply[3];
	}});

}

function contactUAG() {
	if($("email").value != "") return;
	if(($("name").value == "")||($("address").value == "")||($("message").value == "")) {
		alert("Please complete the form before submitting your message");
		return;
	}
	var mailto = $("mailto").value;
	var name = $("name").value;
	var address = $("address").value;
	var phone = $("phone").value;
	var best = $("best").value;
	var message = $("message").value;

	new Ajax.Request('contactuag.php',{method:'post',parameters:'mailto='+mailto+'&name='+name+'&address='+address+'&phone='+phone+'&best='+best+'&message='+message,asynchronous:false,onSuccess:function(transport){
			$("content8").innerHTML = transport.responseText;
			$("themailform").innerHTML = "";
	}});
	
}

