window.onload = function() 
{
	resizeIt();
	loadGoogle();
}

window.onunload = function() 
{
	GUnload();
}

window.onresize = function() 
{
	resizeIt();
}

function resizeIt() 
{
	var main = document.getElementById("main");
	main.style.height = 99 - (100 * 141 / document.body.clientHeight) + "%";

    document.cookie = "height=" + escape(screen.height) + "; expires=01/01/2020 00:00:00";
	
	var map = document.getElementById("map");
	map.style.width = 102.5 - (100 * 520 / document.body.clientWidth) + "%";

    document.cookie = "width=" + escape(screen.width) + "; expires=01/01/2020 00:00:00";
}


function overlayNewMarkers() 
				{
					resetMarkers();
					for(var i=0; i<arrLat.length; i++) 
					{
						if((arrLat[i]) && (arrLng[i])) 
						{ 
							var point = new GLatLng(arrLat[i],arrLng[i]); 
						} 
						
						if(arrLabel[i]) 
						{ 
							var marker = createTabbedMarker(point, arrHtml[i],arrLabel[i], arrIcons[i], arrTooltips[i]); 
						}
						else 
						{ 
							var marker = createMarker(point,arrName[i],arrHtml[i], arrIcons[i], arrTooltips[i]); 
						}
						
						if (marker) 
						{ 
							map.addOverlay(marker); 
							if (i == 0) { marker.openInfoWindowHtml(arrHtml[i]); }
						}
					}
				}

				//  ======== A function to create the marker and set up the event window ========
				function createMarker(point,name,html,thisimage,thistooltip) 
				{
					var marker;
	
					if((point) && (name) && (html) && (thisimage)) 
					{
						imgMarkers[intCount] = new GIcon(icon,thisimage);
						var marker = new GMarker(point,{icon:imgMarkers[intCount], title:thistooltip});
						gmarkers[intCount] = marker;
	
						GEvent.addListener(marker, "click", function(){marker.openInfoWindowHtml(html);});
	
						// save the info we need to use later
						htmls[intCount] = html;
				}
				
				intCount++;
				return marker;
			}

			
			// ==================================================
			// A function to create a tabbed marker and set up the event window
			// This version accepts a variable number of tabs, passed in the arrays htmlsTabs[] and labels[]
			function createTabbedMarker(point,htmlsTabs,labels,thisimage,thistooltip) 
			{
				var marker;

				if((point) && (htmlsTabs) && (labels) && (thisimage)) 
				{
					imgMarkers[intCount] = new GIcon(icon,thisimage);
					marker = new GMarker(point,{icon:imgMarkers[intCount], title:thistooltip});
					gmarkers[intCount] = marker;

					// adjust the width so that the info window is large enough for this many tabs
					if(htmlsTabs.length > 2) 
					{
						htmlsTabs[0] = '<div style="width:'+htmlsTabs.length*88+'px">' + htmlsTabs[0] + '<\/div>';
					}

					var thisTab = new Array();
					for (var i=0; i<htmlsTabs.length; i++) 
					{
						thisTab[i] = new GInfoWindowTab(labels[i],htmlsTabs[i]);
					}

					tabs[intCount] = thisTab;

					GEvent.addListener(marker, "click", function(){marker.openInfoWindowTabsHtml(thisTab);});
				}

				intCount++;
				return marker;
			}

			//  ======== This function picks up the click and opens the corresponding info window ========
			function myclick(i) 
			{
				if (arrName[i]) 
				{ 
					gmarkers[i].openInfoWindowHtml(htmls[i]); 
				}
				else 
				{
					gmarkers[i].openInfoWindowTabsHtml(tabs[i]);
				}
			}

			//  ======== A function to remove all overlays on the map ========
			function resetMarkers() 
			{
				// close any open info windows
				map.getInfoWindow().hide();
				// remove all overlay points
				map.clearOverlays();

				// reset all global vars
				gmarkers = new Array();
				htmls = new Array();
				tabs = new Array();
			}
			function getData(i) 
			{
				var strUrl = 'http://localhost/classes/updater.php';
				var strPars = 'page=' + i;
				var ar = new Ajax.Updater('clickarea', strUrl, { method: "get", parameters: strPars, evalScripts: true});
			}


function formValidator()
{
	// Make quick references to our fields
	var companyName	= document.getElementById('comame');
	var contactName	= document.getElementById('coname');
	var emailAdr	= document.getElementById('email');
	var phoneNum	= document.getElementById('phonemob');
	var numOfPeople	= document.getElementById('nopeople');

	// Check each input in the order that it appears in the form!
	if(setNotEmpty(contactName, "Please type in a contact name. Thank you."))
	{
        if(setEmail(emailAdr, "Please type in your email address. Thank you."))
		{
            if(setNumeric(phoneNum, "Please type in your phone or cell number. Thank you."))
			{
                return true;
			}
		}
	}
	return false;
}

function formContactValidator()
{
	// Make quick references to our fields
	var companyName_cot	= document.getElementById('comame_cot');
	var contactName_cot	= document.getElementById('coname_cot');
	var emailAdr_cot	= document.getElementById('email_cot');
	var phoneNum_cot	= document.getElementById('phonemob_cot');
	var numOfPeople_cot	= document.getElementById('nopeople_cot');

	// Check each input in the order that it appears in the form!
	if(setNotEmpty(contactName_cot, "Please type in a contact name. Thank you."))
	{
		if(setEmail(emailAdr_cot, "Please type in your email address. Thank you."))
		{
            if(setNumeric(phoneNum_cot, "Please type in your phone or cell number. Thank you."))
			{
            	return true;
			}
		}
	}
	return false;
}


// If the length of the element's string is 0 then display helper message
function setNotEmpty(elem, helperMsg){
	if(elem.value.length == 0){
		alert(helperMsg);
		setElemError(elem);
		elem.focus(); // set the focus to this input
		return false;
	}
	setElemCorrect(elem);
	return true;
}


// If the element's string matches the regular expression it is all letters
function setAlphabet(elem, helperMsg)
{
	var alphaExp = /^[a-zA-Z[:space:]]+$/;
	if(elem.value.match(alphaExp))
	{
		setElemCorrect(elem);
		return true;
	}
	else
	{
		alert(helperMsg);
		setElemError(elem);
		elem.focus();
		return false;
	}
}


// If the element's string matches the regular expression it is all numbers
function setNumeric(elem, helperMsg)
{
	var numericExpression = /^[0-9]+$/;
	if(elem.value.match(numericExpression))
	{
		setElemCorrect(elem);
		return true;
	}
	else
	{
		alert(helperMsg);
		setElemError(elem);
		elem.focus();
		return false;
	}
}


// If the element's string matches the regular expression it is numbers and letters
function setAlphanumeric(elem, helperMsg)
{
	var alphaExp = /^[0-9a-zA-Z]+$/;
	if(elem.value.match(alphaExp))
	{
		setElemCorrect(elem);
		return true;
	}
	else
	{
		alert(helperMsg);
		setElemError(elem);
		elem.focus();
		return false;
	}
}


function setEmail(elem, helperMsg)
{
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp))
	{
		setElemCorrect(elem);
		return true;
	}
	else
	{
		alert(helperMsg);
		setElemError(elem);
		elem.focus();
		return false;
	}
}


function setElemError(elem)
{
    elem.style.background = "#FFF7DF";
    elem.style.border = "1px solid #979797";
}
function setElemCorrect(elem)
{
    elem.style.background = "#FFF";
    elem.style.border = "1px solid #979797";
}







function setMinimum(min)
{
	var term = document.getElementById('search-input');
	
	if (term.value.length < min) 
	{
		alert('Please enter a City or Zip code');
		return false;
	}
	else
	{
		return true;
	}
}
