function checkForFlash() {
	//alert("this one...");
	var flashinstalled = 0;
	var flashversion = 0;
	MSDetect = "false";
	if (navigator.plugins && navigator.plugins.length)
	{
		//alert("navigator");
		x = navigator.plugins["Shockwave Flash"];
		if (x)
		{
			flashinstalled = 2;
			if (x.description)
			{
				y = x.description;
				flashversion = y.charAt(y.indexOf('.')-1);
				//alert("flash installed...");
			}
		}
		else
			flashinstalled = 1;
		if (navigator.plugins["Shockwave Flash 2.0"])
		{
			flashinstalled = 2;
			flashversion = 2;
			//alert("netscape true");
		}
	}
	else if (navigator.mimeTypes && navigator.mimeTypes.length)
	{
		//alert("navigator mime types");
		x = navigator.mimeTypes['application/x-shockwave-flash'];
		if (x && x.enabledPlugin)
			flashinstalled = 2;
		else
			flashinstalled = 1;
	}
	else {
		MSDetect = "true";
		//alert("ms true");
		}
		
	// IE flash detection.
		for(var i=7; i>0; i--){
			flashVersion = 0;
			try{
				var flash = new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + i);
				flashVersion = i;
				flashinstalled = 2;
				//alert("activexobject true...");
				
			}
			catch(e){
			}
		}
	return flashinstalled;
}


function checkRequired() {
	var alertString;
	
	if (!document.permitForm.reviewed.checked ||
		!document.permitForm.sprinkler.checked ||
		!document.permitForm.flammable.checked ||
		!document.permitForm.floorWallCoverings.checked ||
		!document.permitForm.equipmentCondition.checked ||
		!document.permitForm.fireExtinguisher.checked ||
		!document.permitForm.fireWatchRequired.checked ||
		!document.permitForm.fireWatchTrained.checked ||
		!document.permitForm.fireWatchExtMonitor.checked) {
		
		alertString = "\r\rIf you cannot answer yes to all of these questions, please call Risk Management at 422-4468 before beginning work.";
		alert(alertString);
	}
}

function checkReferenceForm() {
	confirmString = "Please properly fill out all required fields.";
	badform = false;
	
	
	if (document.form1.hiringMan.value == "") { 
		
		badform = true; 
		document.getElementById('hiringManDiv').style.color = '#ff0000';
	} else document.getElementById('hiringManDiv').style.color = '#000000';
	if (document.form1.postingNum.value == "" || document.form1.postingNum.value.length != 6) { 
		badform = true; 
		document.getElementById('postingNumDiv').style.color = '#ff0000'; 
	} else document.getElementById('postingNumDiv').style.color = '#000000'; 
	if (document.form1.deptID.value == "") { 
		badform = true; 
		document.getElementById('deptIDDiv').style.color = '#ff0000'; 
	} else document.getElementById('deptIDDiv').style.color = '#000000'; 
	if (document.form1.applicant.value == "") { 
		badform = true; 
		document.getElementById('applicantDiv').style.color = '#ff0000'; 
	} else document.getElementById('applicantDiv').style.color = '#000000'; 
	if (document.form1.personContacted.value == "") { 
		badform = true; 
		document.getElementById('personContactedDiv').style.color = '#ff0000'; 
	} else document.getElementById('personContactedDiv').style.color = '#000000'; 
	if (document.form1.organization.value == "") { 
		badform = true; 
		document.getElementById('organizationDiv').style.color = '#ff0000'; 
	} else document.getElementById('organizationDiv').style.color = '#000000'; 
	if (!document.form1.relationshipToApplicant[0].checked && !document.form1.relationshipToApplicant[1].checked && !document.form1.relationshipToApplicant[2].checked) { 
		badform = true; 
		document.getElementById('relationshipToApplicantDiv').style.color = '#ff0000'; 
	} else document.getElementById('relationshipToApplicantDiv').style.color = '#000000';
	if (document.form1.relationshipToApplicant[2].checked && document.form1.otherRelationship.value == "") {
		badform = true; 
		document.getElementById('relationshipToApplicantDiv').style.color = '#ff0000'; 
	} 
	if (document.form1.empStartDate.value == "") { 
		badform = true; 
		document.getElementById('empStartDateDiv').style.color = '#ff0000'; 
	} else document.getElementById('empStartDateDiv').style.color = '#000000'; 
	if (document.form1.empEndDate.value == "") { 
		badform = true; 
		document.getElementById('empEndDateDiv').style.color = '#ff0000'; 
	} else document.getElementById('empEndDateDiv').style.color = '#000000'; 
	if (document.form1.refChecker.value == "") { 
		badform = true; 
		document.getElementById('refCheckerDiv').style.color = '#ff0000'; 
	} else document.getElementById('refCheckerDiv').style.color = '#000000'; 
	
	
	if (badform) {
		alert(confirmString);
		return false;
	}
	
	return true;

}


function validateUSDate( strValue ) {
/************************************************
DESCRIPTION: Validates that a string contains only
    valid dates with 2 digit month, 2 digit day,
    4 digit year. Date separator can be ., -, or /.
    Uses combination of regular expressions and
    string parsing to validate date.
    Ex. mm/dd/yyyy or mm-dd-yyyy or mm.dd.yyyy

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.

REMARKS:
   Avoids some of the limitations of the Date.parse()
   method such as the date separator character.
*************************************************/
  var objRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/

  //check to see if in correct format
  if(!objRegExp.test(strValue)) {
   	//alert("bad string");
   	return false; //doesn't match pattern, bad date
  }
  else{
	if (strValue.substring(1,2) == "/" || strValue.substring(1,2) == "-" || strValue.substring(1,2) == ".")
		strValue = "0" + strValue;
	var strSeparator = strValue.substring(2,3) //find date separator
	//alert(strSeparator);
    var arrayDate = strValue.split(strSeparator); //split date into month, day, year
    //create a lookup for months not equal to Feb.
    var arrayLookup = { '01' : 31,'03' : 31, '04' : 30,'05' : 31,'06' : 30,'07' : 31,
                        '08' : 31,'09' : 30,'10' : 31,'11' : 30,'12' : 31}
	//var arrayLookup2 = { '1' : 31,'3' : 31, '4' : 30,'5' : 31,'6' : 30,'7' : 31,
    //                    '8' : 31,'9' : 30,'10' : 31,'11' : 30,'12' : 31}
    var intDay = parseInt(arrayDate[1]);

    //check if month value and day value agree
    if(arrayLookup[arrayDate[0]] != null) {
      if(intDay <= arrayLookup[arrayDate[0]] && intDay != 0)
        return true; //found in lookup table, good date
    }

    //check for February (bugfix 20050322)
    var intMonth = parseInt(arrayDate[0]);
    if (intMonth == 2) { 
       var intYear = parseInt(arrayDate[2]);
       if( ((intYear % 4 == 0 && intDay <= 29) || (intYear % 4 != 0 && intDay <=28)) && intDay !=0)
          return true; //Feb. had valid number of days
       }
  }
   //alert("bad string1");
  return false; //any other values, bad date
}

function showDiv(divID) {
	document.getElementById(divID).style.display = "block";
}
		
function hideDiv(divID) {
	document.getElementById(divID).style.display = "none";
}

/*
 * NAME:		switchDiv
 * SUMMARY:		Changes the display status of a DOM element
 * PARAMETERS:	id - the DOM element to be updated
 * RETURNS:		false - to keep browser from reloading the page
 * REMARKS:		
 */
function switchDiv(id) {
	var element = document.getElementById(id);
	//var override = document.getOverrideStyle(element, null);
	if(element.style.display == "none") {
		element.style.display = "block";
	}
	else {
		element.style.display = "none"; 
	}
	return false;
}

function showEquipment(element, id) {
	if(element.checked) {
		//document.write("display on");
		document.getElementById(id).style.display = "block"; }
	else {
		//document.write("display off");
		document.getElementById(id).style.display = "none"; }
}


function showDatesBetween(element, id) {
	if(element.checked) {
		//document.write("display on");
		document.form1.dateBetween.value = "true";
		document.getElementById(id).style.display = "block"; }
	else {
		//document.write("display off");
		document.form1.dateBetween.value = "false";
		document.getElementById(id).style.display = "none"; }
}

function getVar(name)
{
	get_string = document.location.search;         
	return_value = '';
         
    do { //This loop is made to catch all instances of any get variable.
        name_index = get_string.indexOf(name + '=');
            
        if(name_index != -1) {
           get_string = get_string.substr(name_index + name.length + 1, get_string.length - name_index);
              
           end_of_value = get_string.indexOf('&');
           if(end_of_value != -1)                
              value = get_string.substr(0, end_of_value);                
           else                
              value = get_string;                
                
           if(return_value == '' || value == '')
              return_value += value;
           else
              return_value += ', ' + value;
           }
	} while(name_index != -1)
            
         //Restores all the blank spaces.
    space = return_value.indexOf('+');
    while(space != -1) { 
    	return_value = return_value.substr(0, space) + ' ' + 
		return_value.substr(space + 1, return_value.length);
							 
        space = return_value.indexOf('+');
    }
          
    return(return_value);        
}



function popUp(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=449, height=380');");
}	
function popUpMain(URL, width, height) {
	day = new Date();
	id = day.getTime();
	window.open(URL);
}	