// commonScript.js

function ExtSiteWindow(site){

	var w='800';
	var h='600';
   	var winl = (window.screen.width-h)/2;
  	var wint = (window.screen.height-w)/2;
 	var settings  ='height='+h+',';
      	settings +='width='+w+',';
      	settings +='top='+wint+',';
      	settings +='left='+winl+',';
      	settings +='menubar=yes,';
      	settings +='toolbar=yes,';
      	settings +='scrollbars=yes,';
      	settings +='location=yes,';
      	settings +='resizable=yes,';
   
 	win=window.open(site,'extsite',settings);
   	if(parseInt(navigator.appVersion) >= 4){win.focus();}
}

function NewMidSizeWindow(mypage){
	var w='325';
	var h='300';
  	var winl = (screen.width-w)/2;
  	var wint = (screen.height-h)/2;
 	var settings  ='height='+h+',';
      	settings +='width='+w+',';
    	settings +='top='+wint+',';
      	settings +='left='+winl+',';
      	settings +='scrollbars=no,';
      	settings +='resizable=yes,';
      	win=window.open(mypage,'PopUp',settings);
  	if(parseInt(navigator.appVersion) >= 4){win.focus();}
}
function verifyPersonalHistoryStatement(href, page){

var message = "If you want to proceed to the form you requested, Click OK";
if(page == "1"){
 message ="Current Applicants:\n"
 +"If you have been instructed to complete the Personal History Statement\n"
 +"by the Missouri State Highway Patrol, click OK to continue.";}
 else if(page == "2"){
  message ="Civilian Employment Application:\n"
 +"If you would like to apply for a civilian position,\n"
 +"that is currently posted in the Current Openings section of this website,\n"
 +"click OK to continue.";}
  else if(page == "3"){
  message ="Civilian Employment Application:\n"
 +"If you would like to apply for a civilian position that is listed below,\n"
 +"click OK to continue.";}
 var answer = confirm("This is NOT an application for Trooper. \n" + 
 "If you would like to apply for the Trooper position,\n" 
 + "please visit " + "www.motrooper.com.\n\n" + message); 

if (answer)
{window.location=href;}
}

function printpage() {
window.print();  
}

function popUpWindowForEmpApplication(href)
{

var answer = confirm("An application will only be accepted for the civilian positions listed below.\n\n");
if (answer)
{window.location=href;}


}









//The following script is used to load the fatal.xml file for the fatalitity totals

var xmlDoc;
var messageLocationType

function loadXML(locationType)
{

messageLocationType = locationType

//load xml file
// code for IE
if (window.ActiveXObject)
{
	xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
	xmlDoc.async=false;
	xmlDoc.load("/MSHPWeb/Fatal/fatal.xml");
	getmessage();
}
// code for Mozilla, Firefox, Opera, etc. Load and replace new line and carriage return
else if (document.implementation && document.implementation.createDocument)
{
	var datafile = "/MSHPWeb/Fatal/fatal.xml";
	var objXml = new XMLHttpRequest();
     objXml.open("GET",datafile,false);
     objXml.send(null);
     var xmlData = trim(objXml.responseText)
	//Take out the new line and carriage return in the xmldata file     
     xmlData = xmlData.replace(/\n\s*/g,"");
     xmlData = xmlData.replace(/\r\s*/g,"");
   
   //  var formattedXMLData = "<crashtotals><header1>Statewide Fatality Crash Totals</header1></crashtotals>"
  //var ascIIString = "ORIGINAL"
  // var newXML = trim(xmlData.replace(/\n\r\s*/g,""))
  // for(var i=0;i<formattedXMLData.length;i++){
  // ascIIString = ascIIString + ", " + formattedXMLData.charCodeAt(i);
  // }
    //alert(ascIIString)
    //var formattedXMLData = xmlData.replace(/\n\s*/g,"");
    
	xmlDoc=document.implementation.createDocument("","",null);
	var oParser = new DOMParser();
	xmlDoc = oParser.parseFromString(xmlData,"text/xml");
	xmlDoc.onload=getmessage();
	}
else
{
	alert('Your browser cannot handle this script');
}
document.getElementById("rightContent").style.display="block";

}

function trim(stringToTrim) {
	if (stringToTrim == null)
	 return null;
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

//
function getmessage()
{

var x=xmlDoc.documentElement.childNodes;
for (var i=0;i<x.length;i++)
  { 
  if ((x[i].nodeType!=3)&&(x[i].nodeType!=8))
    { 
	  	if(xmlDoc.getElementsByTagName("header1")[i] != null && trim(xmlDoc.getElementsByTagName("header1")[i].childNodes[0].nodeValue) == messageLocationType)
		
		{
	  document.getElementById("header1").innerHTML=xmlDoc.getElementsByTagName("header1")[i].childNodes[0].nodeValue;
      document.getElementById("header2").innerHTML=xmlDoc.getElementsByTagName("header2")[i].childNodes[0].nodeValue;
      document.getElementById("header3").innerHTML=xmlDoc.getElementsByTagName("header3")[i].childNodes[0].nodeValue;
      document.getElementById("currentyeardate").innerHTML=xmlDoc.getElementsByTagName("currentyeardate")[i].childNodes[0].nodeValue;
      document.getElementById("cyearnumbperday").innerHTML=xmlDoc.getElementsByTagName("cyearnumbperday")[i].childNodes[0].nodeValue;
	  document.getElementById("previousyeardate").innerHTML=xmlDoc.getElementsByTagName("previousyeardate")[i].childNodes[0].nodeValue;
	  document.getElementById("pyearnumbperday").innerHTML=xmlDoc.getElementsByTagName("pyearnumbperday")[i].childNodes[0].nodeValue;
 	  document.getElementById("cyearmonthtodate").innerHTML=xmlDoc.getElementsByTagName("cyearmonthtodate")[i].childNodes[0].nodeValue;
  	  document.getElementById("pyearmonthtodate").innerHTML=xmlDoc.getElementsByTagName("pyearmonthtodate")[i].childNodes[0].nodeValue;
      document.getElementById("cyeartodate").innerHTML=xmlDoc.getElementsByTagName("cyeartodate")[i].childNodes[0].nodeValue;
      document.getElementById("pyeartodate").innerHTML=xmlDoc.getElementsByTagName("pyeartodate")[i].childNodes[0].nodeValue;
	  document.getElementById("change").innerHTML=xmlDoc.getElementsByTagName("change")[i].childNodes[0].nodeValue;
   	  document.getElementById("yearendone").innerHTML=xmlDoc.getElementsByTagName("yearendone")[i].childNodes[0].nodeValue;
      document.getElementById("yearendtwo").innerHTML=xmlDoc.getElementsByTagName("yearendtwo")[i].childNodes[0].nodeValue;
	  document.getElementById("yearendthree").innerHTML=xmlDoc.getElementsByTagName("yearendthree")[i].childNodes[0].nodeValue; 
	  }
     
    }
}
}


