/*
	Developer: Antwaan Harrison
	Language:  Javascript
*/
window.onload = function () {
	gallery();
	google_map();
	fade();
	remove_temp();
	no_resize();
}

function email() {
	if(document.forms[0].elements[1].value == "") {
		alert("You did not enter an email address.");
	} else if(document.forms[0].elements[2].value == ""){
		alert("You did not enter a subject.");
	} else if(document.forms[0].elements[3].value == ""){
		alert("You did not enter a message.");
	} else {
		document.forms['form_email'].submit();
	}
}

function suggestion() {
	document.forms['form_suggestion'].submit();
}

function goToURL(where) {
	if(where == 1){
		window.location = "page_edit.php?page=5";
	}
	if(where == 2){
		window.location = "plant_edit.php?subj=2";
	}
	if(where == 3){
		window.location = "plant_edit.php?subj=3";
	}
}

function xhRequest1(){
	var xhr;
	try {
		xhr = new XMLHttpRequest(); /* Mozilla / Safari / IE7 */
	} catch (e) {
		var ms_versions = new Array ('MSXML2.XMLHTTP.5.0',
									 'MSXML2.XMLHTTP.4.0',
									 'MSXML2.XMLHTTP.3.0',
									 'MSXML2.XMLHTTP',
									 'Microsoft.XMLHTTP');
		var success = false;
		for (var i = 0; i < ms_versions.length && !success; i++) {
			try {
				xhr = new ActiveXObject(ms_versions[i]); /* looping through IE versions */
				success = true;
			} catch (e) {}
		}
		if (!success) {
			throw new Error('Unable to create XMLHttpRequest.');
		}
	}
	return xhr;
}

function xhRequest2(){
	var xhr = false;
	try {
		xhr = new XMLHttpRequest(); /* e.g. Firefox */
	}
	catch(err1) {
		try {
			xhr = new ActiveXObject("Msxml2.XMLHTTP"); /* some versions IE */
		}
		catch(err2) {
			try{
				xhr = new ActiveXObject("Microsoft.XMLHTTP"); /* some versions IE */
			}
			catch(err3) {
				xhr = false;
			}
		}
	}
	return xhr;
}
function no_resize() {
	var txtarea = document.getElementsByTagName("textarea");
	if(txtarea) {
		txtarea.resize = "none";
	}else {
		return false;
	}
}
function stop_load() {
	if(navigator.appName === "Microsoft Internet Explorer") {
		document.execCommand("Stop");
	}else {
		window.stop();
	}
}
function remove_temp() {
	var tmp_overlay = document.getElementById("temp_overlay");
	var tmp_message = document.getElementById("temp_message");
	var b = document.body;
	if(tmp_overlay) {
		b.removeChild(tmp_message);
		b.removeChild(tmp_overlay);
	}else {
		return false;
	}
}
function highlight_row() {	
	var rows = document.getElementsByTagName('tr');
	for (i=0;i<rows.length;i++) {
		rows[i].onmouseover = highlight;
		rows[i].onmouseout = unhighlight;
	}
}
function fade() {
	if(document.getElementById("featured_plant")) {
		$(function() {
			$("#plant_gallery").innerfade({
				animationtype: 'fade',
				speed: 2000,
				timeout: 5000,
				type: "sequence"
			});
		});
	}
}
function gallery() {	
	if(document.getElementById("catalog_content")) {
		$(function() {
			$('#gallery a').lightBox();
		});
	}
}
function google_map() {
	if(document.getElementById("location")) {
		if (GBrowserIsCompatible()) {
			var map = new GMap2(document.getElementById("location"));
			//33.34071087191191, -84.29071426391602 Sunny Side, GA
			map.setCenter(new GLatLng(33.34071087191191, -84.29071426391602), 8);
			var marker = new GMarker(new GLatLng(33.038416, -84.334504));
			
			GEvent.addListener(marker, "click", function () {
			marker.openInfoWindowHtml("<img src='assets/images/logo_small.gif' alt='Mid Georgia Nursery' /><br/>727 Rose Hill Rd<br/>Meansville, GA 30256<br/>(770) 567-3874<br/><a href='directions.php'>Get Directions</a>");
			});
			map.addOverlay(marker);
			map.addControl(new GSmallZoomControl3D());
		}
	}
}
function clear_field(element_id, element_val) {
	if(document.forms[0].elements[element_id].value == element_val) {
		document.forms[0].elements[element_id].value = "";
	} else if(document.forms[1].elements[element_id].value == element_val) {
		document.forms[1].elements[element_id].value = "";
	}
}

function set_default(element_id, element_val) {
	if(document.forms[0].elements[element_id].value == "") {
		document.forms[0].elements[element_id].value = element_val;
	} else if(document.forms[1].elements[element_id].value == "") {
		document.forms[1].elements[element_id].value = element_val;		
	}
}

