//  browser sniffer
var IE4 = (document.all && !document.getElementById) ? true : false;
var NS4 = (document.layers) ? true : false;
var IE5 = (document.all && document.getElementById) ? true : false;
var N6 = (document.getElementById && !document.all) ? true : false;
var isMac = ((navigator.appVersion.indexOf("Mac")!=-1)) ? true : false;

document.onmouseover = capEvent;
var evX, evY
function capEvent(e) {
	if (N6) {
		evX = e.pageX;
		evY = e.pageY;
	}
	else {
		evX = event.x;
		evY = event.y;
	}

}

function KeyPress() 
{
//alert(window.event.keyCode)
if (window.event.keyCode == 13)
window.event.keyCode =0;
} 

var isOk = false;  
var checkArray = new Array();
	
function validate(elem){
	var stopSubmit = false; 
	var alertStr = 'You must read and check all the boxes related to chemical use for each pest type. ';
	
	if (checkArray.length > 0) {
		for (var i=0; i<checkArray.length; i++) {
			if (document.getElementById(checkArray[i]).checked == false) {
				stopSubmit = true;
			}
		}
	}
	
	// Commented to prevent checking if attestation is checked.
	//if (document.getElementById("6")) {
	//	if (document.getElementById("6").checked == false) {
	//		stopSubmit = true;
	//	}
	//}
	//if (document.getElementById("17")) {
	//	if (document.getElementById("17").checked == false) {
	//		stopSubmit = true;
	//	}
	//}
	//if (document.getElementById("28")) {
	//	if (document.getElementById("28").checked == false) {
	//		stopSubmit = true;
	//	}
	//}
	
	if (stopSubmit == true) {
		alert(alertStr);
	} else {
		document.factsheet.submit();
	}
}


function clearDefault(el) {
  if (el.defaultValue==el.value) el.value = ""
}

function popWin(ur,w,h) {
	if (!w) w = 600;
	if (!h) h = 350;
	pWin = window.open(ur,'detailWin','scrollbars=yes,toolbar=no,menubar=yes,resizable=yes,status=yes,height='+h+',width='+w);
	pWin.focus();
}

function markAsDone(whch) {
	var obj = document.getElementById(whch);
	obj.style.backgroundColor='#cccccc';
}

function checkOther(inp,ste,clr) {
	var obj = document.getElementById(inp);
	if (!obj) return;
	obj.checked = ste;
	if (ste==false) {
		// Clear the OTHER textarea, too
		obj = eval('document.forms.form1.elements.'+clr)
		obj.value = "";
	}
}

function makeSameForm(form,arr,num) {
	if (num>0) {
		// There is a variable number of elements to fill 
		// (or the element names are dynamic), so we
		// need to go by the element number
		for (var i=0; i<arr.length; i+=2) {
			for (var j=1; j<num; j++) {
				var takeFromField = arr[i] + j + '';
				var putIntoField = arr[(i+1)] + j + '';
				takeObj = eval('document.forms.' + form + '.elements.' + takeFromField);
				putObj = eval('document.forms.' + form + '.elements.' + putIntoField);
				putObj.value = takeObj.value;
			}
		}
	} else {
		// We have a complete array of the element names
		// to copy, so we can just go through that array
		for (var i=0; i<arr.length; i+=2) {
			var takeFromField = arr[i];
			var putIntoField = arr[(i+1)];
			takeObj = eval('document.forms.' + form + '.elements.' + takeFromField);
			putObj = eval('document.forms.' + form + '.elements.' + putIntoField);
			putObj.value = takeObj.value;
		}
	}
}

function showPop(id,ste,w,h) {
	if (!ste) ste = 'visible';
	if (!w) w = 450;
	if (!h) h = 350;
	var obj=document.getElementById(id);
	
	var scrollAdder = document.body.scrollTop
	if (N6) scrollAdder = 0;
	obj.style.visibility = ste;
	obj.style.width = w;
	obj.style.top = evY - 40 + scrollAdder;
	obj.style.left = evX - (w + 10);
	if (ste == 'visible') checkBounds(obj);
}

function checkBounds(obj) {
	var screenHeight = document.body.clientHeight;
	var bottomOfScreen = document.body.scrollTop + screenHeight;
	
	var divHeight = (N6) ? obj.offsetHeight : obj.clientHeight;
	var divTop = (N6) ? obj.offsetTop: obj.style.pixelTop;
	
	if (divTop + divHeight > bottomOfScreen) {
		var newTop = bottomOfScreen - (divHeight);
		obj.style.top = newTop;
	}
}

function popPlan(ur) {
	planWin = window.open(ur,'planWin','scrollbars=yes,toolbar=no,menubar=yes,resizable=yes,status=yes,height=500,width=700');
	planWin.focus();
}

function popSubmittedAlert() {
	alert('This IPM plan has already been submitted to MDAR. If you make any changes, you must re-submit. \n\nSave your changes by clicking the SAVE button and then return to the IPM workbook to resubmit.');
}

function popHelp(ur) {
	if (!ur) ur = 'help/help00.asp';
	hWin = window.open(ur,'helpWin','scrollbars=yes,toolbar=no,menubar=yes,resizable=yes,status=no,height=350,width=350');
	hWin.focus();
}

var intervalID;
function setTimeOutReload(frm,ur) {
	intervalID = setTimeout('timoutReload("'+frm+'","'+ur+'")',55*60*1000);
}

function timoutReload(frm,ur) {
	//var alertStr = 'IPM Plan Maker Warning:\n\nFor security reasons, your connection to the server is about to expire. \n\nTo prevent this, click OK and we\'ll save your work.';
	//if (confirm(alertStr)) {
		var obj = eval('document.forms.'+frm)
		//obj.elements.timoutredirect.value = ur;
		obj.elements.timoutredirect.value = "1";
		obj.submit();
		//document.location = "../make-your-ipm-online.asp?L=y&T=y"
	//};
	
}
function popConfirmDelUser(id,txt) {
	URLstr = 'deleteschool.asp?id=' + id;
	if (confirm(txt + '\n\n' + "Are you sure you want to delete this school?")) {
		document.location = URLstr;
	}
}
function doNothing() {
}