//window.onerror = HandleError
function HandleError(){
	return true;
}

//Menus and Navigation***************************************************************
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
function navigate(str){
	MM_goToURL('parent',str);return document.MM_returnValue
}
function navigate_external(str){
	MM_openBrWindow(str,'','top=0,left=0,width=1024,height=768,scrollbars=yes,resizable=yes,status=yes')
}
function BC_swapClass() {
   BC_swapClassRestore()
   var i,j=0,x,a=BC_swapClass.arguments; 
   document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oClassName) x.oClassName=x.className; x.className=a[i+2];}
}
function BC_swapClassRestore() { //v3.0
  var i,x,a=document.MM_sr; 
  for(i=0;a&&i<a.length&&(x=a[i])&&x.oClassName;i++) x.className=x.oClassName;
}
function calmenutop(imgid){
	var TT = findObj(imgid)
	var yPos = eval(TT).offsetTop;
	var tempEl = eval(TT).offsetParent;
  	while (tempEl != null) {
  		yPos += tempEl.offsetTop;
  		tempEl = tempEl.offsetParent;
  	}
	return yPos;
}
function calmenuleft(imgid){
	var LL = findObj(imgid)
	var xPos = eval(LL).offsetLeft;
	var tempEl = eval(LL).offsetParent;
  	while (tempEl != null) {
  		xPos += tempEl.offsetLeft;
  		tempEl = tempEl.offsetParent;
  	}
	return xPos;
}
//End of Menus and Navigation************************************************************

//Generic Functions**********************************************************************
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function tmt_formManager(f,c){
	if(MM_findObj(f)){eval("MM_findObj('"+f+"')."+c);}
}
function tmt_formAction(f,p){
	if(MM_findObj(f)){eval("MM_findObj('"+f+"').action='"+p+"'");}
}
function findObj(theObj, theDoc){
  var p, i, foundObj;
  
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length){
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  
  return foundObj;
}
function reposmenus(){
	newwidth=getWidth();
	if(newwidth!=currentwidth){
	var curloc = document.location.href
    MM_goToURL('parent',curloc); 
	return document.MM_returnValue;
	}
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function getHeight(){
	return window.innerHeight ? window.innerHeight :(document.getBoxObjectFor ? Math.min(document.documentElement.clientHeight, document.body.clientHeight) : ((document.documentElement.clientHeight != 0) ? document.documentElement.clientHeight : (document.body ? document.body.clientHeight : 0)));
}
function getWidth(){
	return (document.layers||(document.getElementById&&!document.all)) ? window.outerWidth : (document.all ? document.body.clientWidth : 0);
}
function close_window() {
    window.close();
}
function tmt_formManager(f,c){
	if(MM_findObj(f)){eval("MM_findObj('"+f+"')."+c);}
}
function tmt_formAction(f,p){
	if(MM_findObj(f)){eval("MM_findObj('"+f+"').action='"+p+"'");}
}

//End of Generic Functions***************************************************************
//Popup Boxes
function launchpopup(url,w,h){
	width=getWidth();
	height=getHeight();
    var left = Math.round(width/2-w/2);
    var top = Math.round(height/2-h/2);
    MM_openBrWindow(url,'','top='+top+',left='+left+',width='+w+',height='+h)
}
function launchScrollingPopup(url,w,h){
	width=getWidth();
	height=getHeight();
    var left = Math.round(width/2-w/2);
    var top = Math.round(height/2-h/2);
    MM_openBrWindow(url,'','scrollbars=yes,resizable=yes,top='+top+',left='+left+',width='+w+',height='+h)
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  popupwindow=window.open(theURL,winName,features);
}
function close_window() {
    window.close();
}
//End of Popup Boxes
//Link to Admin
function gotoadmin(){
	MM_goToURL('parent','Administration/Login.php');return document.MM_returnValue;
}
//End of Link to Admin
//Forms
//Catcha Check
var ONUM;
function CheckCatcha(PassedFinalCheck){
   var xmlHttp;
   try 
    {   
	xmlHttp=new XMLHttpRequest();    
	}
    catch (e) 
    {   
	try 
	{      
	xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");      
	}
    catch (e)
    {      
	try
    {        
	xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");        
	}
    catch (e)
    {        
	alert("Your browser does not support AJAX!");        
	return false;       
	}      
	}    
	}
    xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
    {
	ONUM=xmlHttp.responseText;
	if(ONUM=="Invalid"){
		document.getElementById('captcha-form').style.backgroundColor="#E66A37";
		document.getElementById('captcha-form').value="Type letters displayed in image above";
		alert('Please enter the correct letters into the Text Box that is currently displaying the text;\n"Type letters displayed in image above"');
		document.getElementById('captcha-form').value="";
		document.getElementById('captcha-form').focus();
		return false;
	}else{
		document.getElementById('captcha-form').style.backgroundColor="#92C94A";
		eval(ONUM)();
	}
    }
	}
	document.getElementById('captcha-form').focus();
	var CurrentCaptcha=document.getElementById('captcha-form').value;
	var url="CaptchCheck.php?captcha="+CurrentCaptcha+"&PassedFinalCheck="+PassedFinalCheck;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);  
}
function ChooseAnonymous(obj){
	var AnonymousCheck=document.getElementById('Anonymous');
	var requiredRows=new Array('FirstNameRow','LastNameRow','EmailAddressRow','ContactRow','CompanyRow');
	if(obj.checked==1){
		ClassSet="Hidden";
		document.getElementById('Require').value="FeedBackType,FeedBack";
		document.getElementById('AutoTemplate').value="FeedBack_Anonymous_Mail.htm";
		document.getElementById('EmailTemplate').value="FeedBack_Anonymous_Mail.htm";
	}else{
		ClassSet="Display";
		document.getElementById('Require').value="FeedBackType,FirstName,LastName,EmailAddress,FeedBack";
		document.getElementById('AutoTemplate').value="FeedBack_Mail.htm";
		document.getElementById('EmailTemplate').value="FeedBack_Mail.htm";
	}
	for (var i=0;i<requiredRows.length;i++) {
		document.getElementById(requiredRows[i]).className=ClassSet;
	}
}
function CheckFeedBackForm(){
	//alert('Feedback');
	var requiredCount=0;
	var Anonymous=document.getElementById('Anonymous');
	if(Anonymous.checked==1){
		var requiredRows=new Array('FeedBackTypeRow','FeedBackRow');
		var requiredFields=new Array('FeedBackType','FeedBack');
	}else{
		var requiredRows=new Array('FeedBackTypeRow','FirstNameRow','LastNameRow','EmailAddressRow','FeedBackRow');
		var requiredFields=new Array('FeedBackType','FirstName','LastName','EmailAddress','FeedBack');
	}
	for (var i=0;i<requiredFields.length;i++) {
		var fieldValue=document.getElementById(requiredFields[i]).value
		if(!fieldValue){
			document.getElementById(requiredRows[i]).style.backgroundColor="#E66A37";
			requiredCount++;
		}else{
			document.getElementById(requiredRows[i]).style.backgroundColor="#EBEDEE";
		}
	}
	if(requiredCount>0){
		alert('The Following Field(s) are Required');
		return false;
	}else{
	   tmt_formAction('former','Mail.php');
	   tmt_formManager('former','submit()')
	}
}
function CheckRequestQuoteForm(){
	//alert('Quote');
	var requiredCount=0;
	var requiredRows=new Array('FirstNameRow','LastNameRow','EmailAddressRow','WorkPhoneRow','JobDetailsRow');
	var requiredFields=new Array('FirstName','LastName','Email','WorkPhone','JobDetails');
	for (var i=0;i<requiredFields.length;i++) {
		var fieldValue=document.getElementById(requiredFields[i]).value
		if(!fieldValue){
			document.getElementById(requiredRows[i]).style.backgroundColor="#E66A37";
			requiredCount++;
		}else{
			document.getElementById(requiredRows[i]).style.backgroundColor="#EBEDEE";
		}
	}
	if(requiredCount>0){
		alert('The Following Field(s) are Required');
		return false;
	}else{
	   tmt_formAction('former','Mail.php');
	   tmt_formManager('former','submit()')
	}
}
function DictateReportType(str){
	if(str=="Safety Improvement"){
		document.getElementById('UnsafeRow').className="Display";
		document.getElementById('NearmissRow').className="Hidden";
		document.getElementById('Require').value="ReportType,UnsafeItemDescription";
		document.getElementById('AutoTemplate').value="Unsafe_Mail.htm";
		document.getElementById('EmailTemplate').value="Unsafe_Mail.htm";
		document.getElementById('Subject').value="Safety Report (Website)";
		document.getElementById('AutoSubject').value="Safety Report (Website)";
	}else{
		document.getElementById('UnsafeRow').className="Hidden";
		document.getElementById('NearmissRow').className="Display";
		document.getElementById('Require').value="ReportType,NearMissDescription";
		document.getElementById('AutoTemplate').value="NearMiss_Mail.htm";
		document.getElementById('EmailTemplate').value="NearMiss_Mail.htm";
		document.getElementById('Subject').value="Near Miss Report (Website)";
		document.getElementById('AutoSubject').value="Near Miss Report (Website)";
	}
}
function CheckSafetyForm(){
	//alert('Safety');
	var requiredCount=0;
	var ReportType=document.getElementById('ReportType');
	if(ReportType.value=="Safety Improvement"){
		var requiredRows=new Array('ReportTypeRow','UnsafeRow');
		var requiredFields=new Array('ReportType','UnsafeItemDescription');
	}else{
		var requiredRows=new Array('ReportTypeRow','NearmissRow');
		var requiredFields=new Array('ReportType','NearMissDescription');
	}
	for (var i=0;i<requiredFields.length;i++) {
		var fieldValue=document.getElementById(requiredFields[i]).value
		if(!fieldValue){
			document.getElementById(requiredRows[i]).style.backgroundColor="#E66A37";
			requiredCount++;
		}else{
			document.getElementById(requiredRows[i]).style.backgroundColor="#EBEDEE";
		}
	}
	if(requiredCount>0){
		alert('The Following Field(s) are Required');
		return false;
	}else{
	   tmt_formAction('former','Mail.php');
	   tmt_formManager('former','submit()')
	}
}


