/* 
 * main.js 
 * JavaScript for Oklahoma Agritourism Growing Adventure.
 
 * Applies to all pages.
 */

window.addEvent('domready', function(){	
	window.addEvent('resize', function(){
		// resize the footer so green bleeds to bottom
		var winH = window.getSize().y;
		var footTop = $('footer').getPosition().y;
		var footH = winH - footTop - 25;
		if (footH < 95) footH = 95;
		$('footer').setStyle('height', footH);
	});
	window.fireEvent('resize');

	if (hdrSearchBtn = $('hdrSearchBtn')){
		hdrSearchBtn.addEvent('click', function(){
			document.forms.hdrSearchForm.submit();
		});
	}
	
	if (hdrSearchInput = $('hdrSearchInput')){
		hdrSearchInput.addEvent('click', function(){
			if (this.value == 'search agritourism'){
				this.value = '';
			} else {
				this.select();
			}
		});
	}
});


// Includes the Google Map API
function includeGoogleMapAPI(){
	// dev
	//key = 'ABQIAAAAlUR188h4rgkW3-IO0kz5iBTiiY--Xfpv7HDuBUs87krxGKLn2BT3_LVvLwNMyJlaM1vrSkzlN7gojg';
	
	// live
	key = 'ABQIAAAAlUR188h4rgkW3-IO0kz5iBQF3SgaifhIWW0I2267shwJGVjDhhRgVxfDj_SNzF_f4wATkDjecw25tw';
	
	document.writeln('<script type="text/javascript" src="http://maps.google.com/maps?file=api&amp;v=2.x&amp;sensor=false&amp;key=' + key + '"></script>');
}

function formCheck(formobj){
	// Enter name of mandatory fields
	var fieldRequired = Array("name", "email1", "email2", "password1", "password2", "zip");
	// Enter field description to appear in the dialog box
	var fieldDescription = Array("Name", "Email", "Verify Email", "Password", "Verify Password", "Zip Code");
	// dialog message
	var alertMsg = "Please complete the following fields:\n";
	
	var l_Msg = alertMsg.length;
	
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "text":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			default:
			}
			if (obj.type == undefined){
				var blnchecked = false;
				for (var j = 0; j < obj.length; j++){
					if (obj[j].checked){
						blnchecked = true;
					}
				}
				if (!blnchecked){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
			}
		}
	}

	if (alertMsg.length == l_Msg){
		return true;
	}else{
		alert(alertMsg);
		return false;
	}
}



function CountLeft(field, count, max) {
if (field.value.length > max)
field.value = field.value.substring(0, max);
else
count.value = max - field.value.length;
}



