window.onload = function() 
{
	if(document.getElementById("basicMain")){
		reszieItBasic();
	} else {
		resizeIt();
		loadGoogle();
	}
}

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

window.onresize = function() 
{
	if(document.getElementById("basicMain")){
		reszieItBasic();
	} else {
		resizeIt();
	}
}

function reszieItBasic()
{
	if(document.getElementById("basicMain").style.height.length >= 0){
	    var basicmain = document.getElementById("basicMain");
	    basicmain.style.height = 100 - (100 * 190 / document.body.clientHeight) + "%";
    }
}

function resizeIt() 
{	    
	var main = document.getElementById("main");
	main.style.height = 100 - (100 * 141 / document.body.clientHeight) + "%";
    
    document.cookie = "height=" + escape(screen.height) + "; expires=01/01/2020 00:00:00";
	
	var rightside = document.getElementById("right");
	rightside.style.width = 100 - (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(companyName, "Please include the Company Name. Thank you"))
	{
		if(setNotEmpty(contactName, "Please include the Contact Name. Thank you"))
		{
			if(setNumeric(numOfPeople, "Please enter the approximate number of workstations you need. Thank you"))
			{
				if(emailAdr.value.length > 0 || phoneNum.value.length > 0)
				{
					if(emailAdr.value.length !== 0)
					{	if(setEmail(emailAdr, "Please enter a valid email address please"))
						{
							return true;
						}
					}
					else if(phoneNum.value.length !== 0)
					{
						if(setNumeric(phoneNum, "Please enter a valid phone number (numbers and spaces only)"))
						{
							return true;
						}
					}
				}
				else
				{
					alert('Please include the email address OR phone number. Thank you.');
					return false;
				}
			}
		}
	}
	return false;
}

function formValidatorOffice()
{
	// Make quick references to our fields
	var companyName	= document.getElementById('comameoffice');
	var contactName	= document.getElementById('conameoffice');
	var emailAdr	= document.getElementById('emailoffice');
	var phoneNum	= document.getElementById('phonemoboffice');
	var numOfPeople	= document.getElementById('nopeopleoffice');

	// Check each input in the order that it appears in the form!
	if(setNotEmpty(companyName, "Please include the Company Name. Thank you"))
	{
		if(setNotEmpty(contactName, "Please include the Contact Name. Thank you"))
		{
			if(setNumeric(numOfPeople, "Please enter the approximate number of workstations you need. Thank you"))
			{
				if(emailAdr.value.length > 0 || phoneNum.value.length > 0)
				{
					if(emailAdr.value.length !== 0)
					{	if(setEmail(emailAdr, "Please enter a valid email address please"))
						{
							return true;
						}
					}
					else if(phoneNum.value.length !== 0)
					{
						if(setNumeric(phoneNum, "Please enter a valid phone number (numbers and spaces only)"))
						{
							return true;
						}
					}
				}
				else
				{
					alert('Please include the email address OR phone number. Thank you.');
					return false;
				}
			}
		}
	}
	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);
		elem.style.background = "#FFF7DF";
		elem.focus(); // set the focus to this input
		return false;
	}
	elem.style.background = "#FFF";
	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))
	{
		elem.style.background = "#FFF";
		return true;
	}
	else
	{
		alert(helperMsg);
		elem.style.background = "#FFF7DF";
		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))
	{
		elem.style.background = "#FFF";
		return true;
	}
	else
	{
		alert(helperMsg);
		elem.style.background = "#FFF7DF";
		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))
	{
		elem.style.background = "#FFF";
		return true;
	}
	else
	{
		alert(helperMsg);
		elem.style.background = "#FFF7DF";
		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))
	{
		elem.style.background = "#FFF";
		return true;
	}
	else
	{
		alert(helperMsg);
		elem.style.background = "#FFF7DF";
		elem.focus();
		return false;
	}
}










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