// JavaScript Document
// IBEW Local 131 - Kalamazoo Michigan

// Salt Management

function updateTable(table)
{
//  Create an XMLHttpRequest object
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
// Create the function to be executed when the server response is ready
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
		
		document.getElementById("outputTable").innerHTML=xmlhttp.responseText;
	}
	}
  
// Send the request off to a file on the server
// Notice that a parameter (q) is added to the 
//  URL (with the content of the dropdown list)
//alert(xmlhttp.readyState);

var queryString = "?table=" + table;
xmlhttp.open("GET","ajaxCalls/updateTable.inc.php" +queryString,true);
xmlhttp.send();
}

function saltEdit(id) {
	//alert(CKEDITOR.currentInstance);
	
		if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
// Create the function to be executed when the server response is ready
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    
		document.getElementById("newSalt").innerHTML=xmlhttp.responseText;
			    }
  }
url = "includes/editSaltMember.inc.php";
url += "?id=" +id;
xmlhttp.open("GET",url,true);

xmlhttp.send();

}



function newSaltMember(){
	//alert(CKEDITOR.currentInstance);
	
		if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
// Create the function to be executed when the server response is ready
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    
		document.getElementById("newSalt").innerHTML=xmlhttp.responseText;
			    }
  }
url = "includes/newSaltMember.inc.php";
xmlhttp.open("GET",url,true);

xmlhttp.send();

}

function processNewSalt(disposition){  //  Get data from form and send to php script that will update the DB
															    			// This pulls the elements off the form
	name = document.getElementById('name').value;
	username = document.getElementById('username').value;
	password = document.getElementById('password').value;
	email = document.getElementById('email').value;
	unioncard = document.getElementById('unioncard').value;
	notes = document.getElementById('notes').value;
	id = "null";
	
	if(disposition == "UPDATE"){
	id = document.getElementById('SaltID').value; // This area needs some work.....
	}
		saltWriteRecord(disposition,id,name,username,password,email,unioncard,notes);
	
	return false;
	
	// if a new record --  pass month, day, visible, and html 
	}

// Ajax calls to insert or update the labor history DB
function saltWriteRecord(disposition,id,name,username,password,email,unioncard,notes) {
	//alert("writeRecordFunction");
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
	//alert("http");
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  } // closes if
// Create the function to be executed when the server response is ready
xmlhttp.onreadystatechange=function()
  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200)  {
							    document.getElementById("status").innerHTML=xmlhttp.responseText;
								document.getElementById('newSalt').innerHTML = "";
								updateTable("salts");
		    } 
	}
var disposition = encodeURIComponent(disposition);
var id = encodeURIComponent(id);
var name = encodeURIComponent(name);
var username = encodeURIComponent(username);
var password = encodeURIComponent(password);
var email = encodeURIComponent(email);
var unioncard = encodeURIComponent(unioncard);
var notes = encodeURIComponent(notes);

var url = "includes/saltWrite.inc.php";
var parameters = "disposition=" +disposition+ "&id=" +id+ "&name=" +name+ "&username=" +username+ "&password=" +password+ "&email=" +email+ "&unioncard=" +unioncard+ "&notes=" +notes;
//xmlhttp.open("GET",url,true);
//xmlhttp.send();
xmlhttp.open("POST", url, "true");
xmlhttp.setRequestHeader("Content-type" , "application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length" , parameters.length);
xmlhttp.setRequestHeader("Content-type" , "application/x-www-form-urlencoded");
xmlhttp.send(parameters);

}

// Exit Form

function exitSaltForm(){
	document.getElementById('newSalt').innerHTML = '';
//alert("exit edit mode");
navTo('saltmanagement');
}


// News Management Functions ================================================================

function getdata(){
//alert("here");
var html=CKEDITOR.instances.article.getData();
alert(html);
}

/* Ajax call will pass variables to php script that will query the database */
function dbNewsEdit(id){
	try {CKEDITOR.instances.article.destroy();}
		catch(e){}
			// animated GIF 'Status'
		document.getElementById('status').innerHTML = "";
		document.getElementById('newArticle').innerHTML = "";
	if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
// Create the function to be executed when the server response is ready
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    
		document.getElementById("eventForm").innerHTML=xmlhttp.responseText;
		
		    }
  }
url = "includes/newsArticleLookup.inc.php";
url += "?id=" +id;
xmlhttp.open("GET",url,true);

xmlhttp.send();

}

function processNewsUpdate(disposition){  //  Get data from form and send to php script that will update the DB
	//alert("processNewsUpdate()");
	// This pulls the elements off the form, checks if the record exists - then sends the results 
	// to the laborHistoryWriteRecord function with the appropriate arguments
	// retrieve contents of textarea element
	//alert("Instance: "+CKEDITOR.currentInstance);
	title = document.getElementById('NewsTitle').value;
	
try{
	var html=CKEDITOR.instances.article.getData();
} catch(e){}
	id = "null";
	date = "null";
	visible = 0;
	
	if(disposition == "UPDATE"){
		//alert("update");
	id = document.getElementById('NewsID').value;
	date = document.getElementById('NewsDate').value;
	visible = document.getElementById('NewsVisible').value;
	}
	//alert(disposition);
		newsWriteRecord(disposition,id,date,title,html,visible);
	
	return false;
	
	// if a new record --  pass month, day, visible, and html 
	}

// Ajax calls to insert or update the labor history DB
function newsWriteRecord(disposition,id,date,title,html,visible) {
	//alert(html);
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
	//alert("http");
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  } // closes if
// Create the function to be executed when the server response is ready
xmlhttp.onreadystatechange=function()
  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200)  {
							    document.getElementById("status").innerHTML=xmlhttp.responseText;
		    } 
	}
var disposition = encodeURIComponent(disposition);
var id = encodeURIComponent(id);
var date = encodeURIComponent(date);
var title = encodeURIComponent(title);
var html = encodeURIComponent(html);
var visible = encodeURIComponent(visible);
var url = "includes/newsWrite.inc.php";
var parameters = "disposition=" +disposition+ "&id=" +id+ "&date=" +date+ "&title=" +title+ "&html=" +html+ "&visible=" +visible;
//xmlhttp.open("GET",url,true);
//xmlhttp.send();
xmlhttp.open("POST", url, "true");
xmlhttp.setRequestHeader("Content-type" , "application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length" , parameters.length);
xmlhttp.setRequestHeader("Content-type" , "application/x-www-form-urlencoded");
xmlhttp.send(parameters);

}

function newNewsArticle(){
	//alert(CKEDITOR.currentInstance);
	try {CKEDITOR.instances.article.destroy();}
		catch(e){}
			document.getElementById('newArticle').innerHTML = "";
		if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
// Create the function to be executed when the server response is ready
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    
		document.getElementById("eventForm").innerHTML=xmlhttp.responseText;
		start();
	
		//start();
		    }
  }
url = "includes/newsArticleCreate.inc.php";
xmlhttp.open("GET",url,true);

xmlhttp.send();

}


function exitEditMode(){
	try {CKEDITOR.instances.article.destroy();}
		catch(e){alert(e);}
//alert("exit edit mode");
navTo('newsmanagement');
}

// End of News Management Functions =========================================================

// Functions for Labor History Management
function getLaborWeek(){
var x = document.getElementById('week').value;

document.getElementById('oldLaborHistory').innerHTML = "";
	if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }


// Create the function to be executed when the server response is ready
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
		document.getElementById("oldLaborHistory").innerHTML=xmlhttp.responseText;
		
		    }
  }
// Send the request off to a file on the server
// Notice that a parameter (q) is added to the 
//  URL (with the content of the dropdown list)

url = "includes/laborHistoryLookup2.inc.php";
url += "?x=" +x;
xmlhttp.open("GET",url,true);

xmlhttp.send();
//alert(x);
return;

}
function processLaborRecord(){ // This pulls the elements off the form, checks if the record exists - then sends the results 
																// to the laborHistoryWriteRecord function with the appropriate arguments
	// retrieve contents of textarea element
	var html=CKEDITOR.instances.article.getData();
	// Pull other fields from the form via hidden form fields
	id = document.getElementById('LHid').value;
	month = document.getElementById('LHmonth').value;
	day = document.getElementById('LHday').value;
	visible = document.getElementById('LHvisible').value;

	if (id == ""){
		var disposition = "INSERT";
		laborHistoryWriteRecord(disposition,id,month,day,html,visible);
	}
		else {
		var disposition = "UPDATE";
		laborHistoryWriteRecord(disposition,id,month,day,html,visible);
	}
	return false;
	
	// if a new record --  pass month, day, visible, and html 
	}
// ==============================================================================
// Ajax calls to insert or update the labor history DB
function laborHistoryWriteRecord(disposition,id,month,day,html,visible) {
	//alert(html);
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
	//alert("http");
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  } // closes if


// Create the function to be executed when the server response is ready
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)  {
							    document.getElementById("status").innerHTML=xmlhttp.responseText;
		    } 
	}
  
// Send the request off to a file on the server
// Notice that a parameter (q) is added to the 
//  URL (with the content of the dropdown list)
var disposition = encodeURIComponent(disposition);
var id = encodeURIComponent(id);
var month = encodeURIComponent(month);
var day = encodeURIComponent(day);
var html = encodeURIComponent(html);

var visible = encodeURIComponent(visible);
var url = "includes/laborHistoryWrite.inc.php";
var parameters = "disposition=" +disposition+ "&id=" +id+ "&month=" +month+ "&day=" +day+ "&html=" +html+ "&visible=" +visible;
//xmlhttp.open("GET",url,true);
//xmlhttp.send();
xmlhttp.open("POST", url, "true");
xmlhttp.setRequestHeader("Content-type" , "application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length" , parameters.length);
xmlhttp.setRequestHeader("Content-type" , "application/x-www-form-urlencoded");
xmlhttp.send(parameters);

}


// ==============================================================================
// End of labor history ajax functions

function highlightMonth(month) {
	for (i=1; i<=12; i++) {
	var bbb = "M" + i;
	document.getElementById(bbb).removeAttribute("class");
	}
	document.getElementById(month).setAttribute("class", "boxHighlight");
}

function highlightDay(day) {
	for(i=1; i<=31; i++) {
	var ccc = "D" + i;
	try {
	document.getElementById(ccc).removeAttribute("class");}
	catch (e) {}
	}
	document.getElementById(day).setAttribute("class", "boxHighlight");
}

function GetDays(month) {
	//alert("get days");
	document.getElementById("eventForm").innerHTML = "";
switch (month) {
    case "1":
        result = buildDays(month,'31','January');
				highlightMonth('M1');
        break;
    case "2":
        result =  buildDays(month,'28','February');
				highlightMonth('M2');
        break;
    case "3":
        result = buildDays(month,'31','March');
				highlightMonth('M3');
        break;
		case "4":
        result = buildDays(month,'30','April');
				highlightMonth('M4');
        break;
    case "5":
        result =  buildDays(month,'31','May');
				highlightMonth('M5');
        break;
    case "6":
        result = buildDays(month,'30','June');
				highlightMonth('M6');
        break;
		case "7":
        result = buildDays(month,'31','July');
				highlightMonth('M7');
        break;
    case "8":
        result =  buildDays(month,'31','August');
				highlightMonth('M8');
        break;
    case "9":
        result = buildDays(month,'30','September');
				highlightMonth('M9');
        break;
		case "10":
        result = buildDays(month,'31','October');
				highlightMonth('M10');
        break;
    case "11":
        result =  buildDays(month,'30','November');
				highlightMonth('M11');
        break;
    case "12":
        result = buildDays(month,'31','December');
				highlightMonth('M12');
        break;
	  default:
			 	result = "does not compute";
        break;
}
document.getElementById("days").innerHTML = "";
document.getElementById("days").innerHTML = result;
}

function buildDays(month,days,name) {
	//alert(month+ " here " + days);
 	result = "<ul>";
  for (i=1; i <= days; i++) {
		result += "<li id='D"+i+"'><a href='#' onclick=\"dbLaborLookup('"+month+"','"+i+"','"+name+"');highlightDay('D"+i+"');start();return false;\">"+ i +"</a></li>";
			if (i == 15) {
			result += "</ul><ul>";
			}
		}
	result += "</ul>";
	return result;
}


/* Ajax call will pass variables to php script that will query the database */
function dbLaborLookup(m,d,name){
		document.getElementById('status').innerHTML = "";
	if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }


// Create the function to be executed when the server response is ready
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    try {CKEDITOR.instances.article.destroy();}
		catch(e){}
		document.getElementById("eventForm").innerHTML=xmlhttp.responseText;
		
		    }
  }
// Send the request off to a file on the server
// Notice that a parameter (q) is added to the 
//  URL (with the content of the dropdown list)

url = "includes/laborHistoryLookup.inc.php";
url += "?m=" +m+ "&d=" +d+ "&name=" +name;
xmlhttp.open("GET",url,true);

xmlhttp.send();

}


// End of Functions for Labor History Management

// Function to start CKEditor 
function start() {
//	alert( CKEDITOR.instances.article );  //  E.g "object"
try {
CKEDITOR.instances.article.destroy();}
catch(e){}

//alert( CKEDITOR.instances.article );

	var t=setTimeout("startEditor()",1500);

}

function startEditor() {
	
	try {
CKEDITOR.replace( 'article',  { toolbar : 'MyToolbar',
												 filebrowserBrowseUrl : '/ckfinder/ckfinder.html',
        filebrowserImageBrowseUrl : '/ckfinder/ckfinder.html?Type=Images',
        filebrowserFlashBrowseUrl : '/ckfinder/ckfinder.html?Type=Flash',
        filebrowserUploadUrl : '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files',
        filebrowserImageUploadUrl : '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
        filebrowserFlashUploadUrl : '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash'});

				document.getElementById('ajaxStatus').innerHTML = "";
				
	} catch (e) {}
	return true;
}
//  End of Function to start CKEditor 




function checkform()
{
	//alert("checkform");
	if (document.comments.name.value == "")
	{
		// something is wrong
		alert('You must enter your name');
		return false;
	}
	else if (document.comments.email.value == "")
	{
		// something else is wrong
		alert('You must enter an email address');
		return false;
	}
	else if (document.comments.comments.value == "")
	{
		// comment field is empty
		alert('What is the sense of submitting commments, with no comments!?!?');
		return false;
	}
	// If the script gets this far through all of your fields
	// without problems, it's ok and you can submit the form

	return true;
}
var scrollPos;

function goHome() {
	scrollPos = "true";
	window.location = "http://www.ibew131.com";
	
}

function setScroll() {
	//alert(scrollPos);
	if (scrollPos == "true") {
		window.scroll(0,350); // horizontal and vertical scroll targets
		scrollPos = "";}
	}

function deleteConfirm(idHeading,id,table){  // Add the Data Table to this function so that it is universal
	//alert(val);
	//alert(id);
	var tableItem = idHeading+id;
	//alert(id);
	document.getElementById(tableItem).innerHTML = "<button class='yesbutton' onclick=\"deleteYes('"+ id + "','"+ table +"')\">Yes</button><button class='nobutton' onclick=\"deleteNo('"+ id + "')\">No</button>";
	
	
}
function deleteNo(id) { // delete reset
	var res = "confirm" + id;
	document.getElementById(res).innerHTML = "<button onclick=\"deleteConfirm('confirm', '" + id + "')\">Delete</button>";
}
function deleteYes(id,table) { // delete delete
deleteTableRow(id,table);
}
// added getMapUrl.js 1/23/2011


// ============================================================================
//  DELETE row from admin log 
//=============================================================================
function deleteTableRow(id,table)
{
//alert(id);
//alert(table);
//  Check if a person is selected
if (id=="")
  {
  //document.getElementById("main").innerHTML="";
  return;
  } 
//  Create an XMLHttpRequest object
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
// Create the function to be executed when the server response is ready
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
		
		document.getElementById("outputTable").innerHTML=xmlhttp.responseText;
	}
	}
  
// Send the request off to a file on the server
// Notice that a parameter (q) is added to the 
//  URL (with the content of the dropdown list)
//alert(xmlhttp.readyState);

var queryString = "?id=" + id + "&table=" + table;
xmlhttp.open("GET","ajaxCalls/deletetablerow.inc.php" +queryString,true);
xmlhttp.send();
}


function getMapUrl(dropdown)
{
    var myindex  = dropdown.selectedIndex
    var SelValue = dropdown.options[myindex].value
	document.getElementById("job_map_url").innerHTML="";
   // alert("myindex = " + myindex);
	//alert("SelValue = " + SelValue);
	
	//  Create an XMLHttpRequest object
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }


// Create the function to be executed when the server response is ready
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
  
	document.getElementById("job_map_url").innerHTML=xmlhttp.responseText;
	//alert(xmlhttp.responseText);
	}
  }
// Send the request off to a file on the server
// Notice that a parameter (q) is added to the 
//  URL (with the content of the dropdown list)


url = "ajaxCalls/getMapUrl.inc.php?id=" +  SelValue;
xmlhttp.open("GET",url,true);
xmlhttp.send();
    return true;
}

//added ajax.js 1/23/2011
// Main Navigation routine
function navigateTo(str)
{
//  Check if a person is selected
if (str=="")
  {
  document.getElementById("main").innerHTML="";
  return;
  } 
  

//  Create an XMLHttpRequest object
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }


// Create the function to be executed when the server response is ready
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    if (str=="home") {
	document.getElementById("wrap").innerHTML=xmlhttp.responseText;
	} else {
	document.getElementById("main").innerHTML=xmlhttp.responseText;
   	}
	}
  }
// Send the request off to a file on the server
// Notice that a parameter (q) is added to the 
//  URL (with the content of the dropdown list)

if (str=="home")
  {
	window.location = "http://www.ibew131.com";
	//xmlhttp.open("GET","http://www.ibew131.com/index.php",true);
	//xmlhttp.send(); 
  } else {
	 // alert(str);
xmlhttp.open("GET","navigate.inc.php?content="+str,true);
xmlhttp.send();
return;
}}

// Information Center Navigation
//====================================================================================
function infoNavTo(str)
{
//  Check if a person is selected
if (str=="")
  {
  document.getElementById("infoContainer").innerHTML="";
  return;
  } 
  

//  Create an XMLHttpRequest object
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }


// Create the function to be executed when the server response is ready
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("main").innerHTML=xmlhttp.responseText;
    }
  }
// Send the request off to a file on the server
// Notice that a parameter (q) is added to the 
//  URL (with the content of the dropdown list)
xmlhttp.open("GET","info.inc.php?info="+str,true);
xmlhttp.send();
}

// Information Center Navigation
//====================================================================================
function showIt(content,id,div)
{
//alert(id);
//alert(content);
//alert(content+'.inc.php');
//  Check if a person is selected
if (content=="")
  {
  document.getElementById(div).innerHTML="";
  return;
  } 
 

//alert(id);
//  Create an XMLHttpRequest object
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }


// Create the function to be executed when the server response is ready
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
		//alert("ready");
    document.getElementById(div).innerHTML=xmlhttp.responseText;
    } else {
		//alert("not ready");
		}
  }
// Send the request off to a file on the server
// Notice that a parameter (q) is added to the 
//  URL (with the content of the dropdown list)

	 url = content +'.inc.php?id='+id;

xmlhttp.open("GET",url,true);
xmlhttp.send();

}

// ============================================================================
//  UPDATE Visible Status labor history
//=============================================================================
/*

function visStatus(id,location,changeValue)
{

//  Check if a person is selected
if (id=="")
  {
  //document.getElementById("main").innerHTML="";
  return;
  } 
//  Create an XMLHttpRequest object
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
// Create the function to be executed when the server response is ready
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
		document.getElementById("main").innerHTML=xmlhttp.responseText;
	}
	}
  
// Send the request off to a file on the server
// Notice that a parameter (q) is added to the 
//  URL (with the content of the dropdown list)
//alert(xmlhttp.readyState);

var queryString = "?id=" + id + "&location=" + location + "&changeValue=" + changeValue;
xmlhttp.open("GET","ajaxCalls/changeVis.inc.php" +queryString,true);
xmlhttp.send();
}
*/
// ============================================================================
//  UPDATE Visible Status job action, labor history, 
//=============================================================================
function visChange(id,location,changeValue)
{
//alert(id);
//alert(location);
//alert(changeValue);
//  Check if a person is selected
if (id=="")
  {
  //document.getElementById("main").innerHTML="";
  return;
  } 
//  Create an XMLHttpRequest object
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
// Create the function to be executed when the server response is ready
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
		
		document.getElementById("vis").innerHTML=xmlhttp.responseText;
	}
	}
  
// Send the request off to a file on the server
// Notice that a parameter (q) is added to the 
//  URL (with the content of the dropdown list)
//alert(xmlhttp.readyState);

var queryString = "?id=" + id + "&location=" + location + "&changeValue=" + changeValue;
xmlhttp.open("GET","ajaxCalls/visChange.inc.php" +queryString,true);
xmlhttp.send();
}
// ============================================================================
//  EDIT routine for contractors or jobs
//=============================================================================
function editIt(type,id)
{
//  Check if a person is selected
//alert(id);
if (id=="")
  {
  //document.getElementById("main").innerHTML="";
  return;
  } 
//  Create an XMLHttpRequest object
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
// Create the function to be executed when the server response is ready
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	document.getElementById("main").innerHTML=xmlhttp.responseText;
	}
  }
// Send the request off to a file on the server
// Notice that a parameter (q) is added to the 
//  URL (with the content of the dropdown list)

var location = type + ".inc.php";
var queryString = "?id=" + id;
var combined = location + queryString;
//alert(combined);
xmlhttp.open("GET",combined,true);
xmlhttp.send();
}
//======================================================================================
//   Experimental Nav routine testing passing multiple variables
//======================================================================================
function navTo(content,info,id)
{

//  Create an XMLHttpRequest object
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }


// Create the function to be executed when the server response is ready
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    
	document.getElementById("main").innerHTML=xmlhttp.responseText;
	
	}
  }
// Send the request off to a file on the server
// Notice that a parameter (q) is added to the 
//  URL (with the content of the dropdown list)

if (content=="home")
  {
	window.location = "http://www.ibew131.com";
	//xmlhttp.open("GET","http://www.ibew131.com/index.php",true);
	//xmlhttp.send(); 
  } else {
url = "navigate.inc.php?content=" + content + "&info=" + info + "&id=" + id;
xmlhttp.open("GET",url,true);
xmlhttp.send();

}}



// addded calendar.js 1/23/2011
function toggleCalendar(objname){
	var div_obj = document.getElementById('div_'+objname);
	if (div_obj.style.visibility=="hidden") {
	  div_obj.style.visibility = 'visible';
	  document.getElementById(objname+'_frame').contentWindow.adjustContainer();
	}else{
	  div_obj.style.visibility = 'hidden';
	}
}

function setValue(objname, d){
	document.getElementById(objname).value = d;

	var dp = document.getElementById(objname+"_dp").value;
	if(dp == true){
		var date_array = d.split("-");
		
		var inp = document.getElementById(objname+"_inp").value;
		if(inp == true){
			
			document.getElementById(objname+"_day").value = padString(date_array[2].toString(), 2, "0");
			document.getElementById(objname+"_month").value = padString(date_array[1].toString(), 2, "0");
			document.getElementById(objname+"_year").value = padString(date_array[0].toString(), 4, "0");
			
			//check for valid day
			tc_updateDay(objname, date_array[0], date_array[1], date_array[2]);

		}else{
			if(date_array[0] > 0 && date_array[1] > 0 && date_array[2] > 0){			
				//update date pane
				
				var myDate = new Date();
				myDate.setFullYear(date_array[0],(date_array[1]-1),date_array[2]);
				var dateFormat = document.getElementById(objname+"_fmt").value
				
				var dateTxt = myDate.format(dateFormat);
			}else var dateTxt = "Select Date";
			
			document.getElementById("divCalendar_"+objname+"_lbl").innerHTML = dateTxt;
		}
		
		toggleCalendar(objname);
	}
}

function tc_setDay(objname, dvalue, path){
	var obj = document.getElementById(objname);
	var date_array = obj.value.split("-");
	
	//check if date is not allow to select
	if(!isDateAllow(objname, dvalue, date_array[1], date_array[0])){
		alert("This date is not allow to select");
		
		restoreDate(objname);
	}else{		
		if(isDate(dvalue, date_array[1], date_array[0])){			
			obj.value = date_array[0] + "-" + date_array[1] + "-" + dvalue;
			
			var obj = document.getElementById(objname+'_frame');
			
			var year_start = document.getElementById(objname+'_year_start').value;
			var year_end = document.getElementById(objname+'_year_end').value;
			var dp = document.getElementById(objname+'_dp').value;
			var smon = document.getElementById(objname+'_mon').value;
			var da1 = document.getElementById(objname+'_da1').value;
			var da2 = document.getElementById(objname+'_da2').value;
			var sna = document.getElementById(objname+'_sna').value;
			var aut = document.getElementById(objname+'_aut').value;
			var frm = document.getElementById(objname+'_frm').value;
			var tar = document.getElementById(objname+'_tar').value;
			var inp = document.getElementById(objname+'_inp').value;
			var fmt = document.getElementById(objname+'_fmt').value;
			
			obj.src = path+"calendar_form.php?objname="+objname.toString()+"&selected_day="+dvalue+"&selected_month="+date_array[1]+"&selected_year="+date_array[0]+"&year_start="+year_start+"&year_end="+year_end+"&dp="+dp+"&mon="+smon+"&da1="+da1+"&da2="+da2+"&sna="+sna+"&aut="+aut+"&frm="+frm+"&tar="+tar+"&inp="+inp+"&fmt="+fmt;
			
			obj.contentWindow.submitNow(dvalue, date_array[1], date_array[0]);
			
		}else document.getElementById(objname+"_day").selectedIndex = date_array[2];
	}
}

function tc_setMonth(objname, mvalue, path){
	var obj = document.getElementById(objname);
	var date_array = obj.value.split("-");
	
	//check if date is not allow to select
	if(!isDateAllow(objname, date_array[2], mvalue, date_array[0])){
		alert("This date is not allow to select");
		
		restoreDate(objname);
	}else{
		if(document.getElementById(objname+'_dp').value && document.getElementById(objname+'_inp').value){
			//update 'day' combo box
			date_array[2] = tc_updateDay(objname, date_array[0], mvalue, date_array[2]);
		}
		
		if(isDate(date_array[2], mvalue, date_array[0])){
			obj.value = date_array[0] + "-" + mvalue + "-" + date_array[2];
		
			var obj = document.getElementById(objname+'_frame');
			
			var year_start = document.getElementById(objname+'_year_start').value;
			var year_end = document.getElementById(objname+'_year_end').value;
			var dp = document.getElementById(objname+'_dp').value;
			var smon = document.getElementById(objname+'_mon').value;
			var da1 = document.getElementById(objname+'_da1').value;
			var da2 = document.getElementById(objname+'_da2').value;
			var sna = document.getElementById(objname+'_sna').value;
			var aut = document.getElementById(objname+'_aut').value;
			var frm = document.getElementById(objname+'_frm').value;
			var tar = document.getElementById(objname+'_tar').value;
			var inp = document.getElementById(objname+'_inp').value;
			var fmt = document.getElementById(objname+'_fmt').value;
			
			obj.src = path+"calendar_form.php?objname="+objname.toString()+"&selected_day="+date_array[2]+"&selected_month="+mvalue+"&selected_year="+date_array[0]+"&year_start="+year_start+"&year_end="+year_end+"&dp="+dp+"&mon="+smon+"&da1="+da1+"&da2="+da2+"&sna="+sna+"&aut="+aut+"&frm="+frm+"&tar="+tar+"&inp="+inp+"&fmt="+fmt;
			
			obj.contentWindow.submitNow(date_array[2], mvalue, date_array[0]);
			
		}else document.getElementById(objname+"_month").selectedIndex = date_array[1];
	}
}

function tc_setYear(objname, yvalue, path){
	var obj = document.getElementById(objname);
	var date_array = obj.value.split("-");
	
	//check if date is not allow to select
	if(!isDateAllow(objname, date_array[2], date_array[1], yvalue)){
		alert("This date is not allow to select");
		
		restoreDate(objname);
	}else{
		if(document.getElementById(objname+'_dp').value && document.getElementById(objname+'_inp').value){
			//update 'day' combo box
			date_array[2] = tc_updateDay(objname, yvalue, date_array[1], date_array[2]);
		}
		
		if(isDate(date_array[2], date_array[1], yvalue)){
			obj.value = yvalue + "-" + date_array[1] + "-" + date_array[2];
		
			var obj = document.getElementById(objname+'_frame');
			
			var year_start = document.getElementById(objname+'_year_start').value;
			var year_end = document.getElementById(objname+'_year_end').value;
			var dp = document.getElementById(objname+'_dp').value;
			var smon = document.getElementById(objname+'_mon').value;
			var da1 = document.getElementById(objname+'_da1').value;
			var da2 = document.getElementById(objname+'_da2').value;
			var sna = document.getElementById(objname+'_sna').value;
			var aut = document.getElementById(objname+'_aut').value;
			var frm = document.getElementById(objname+'_frm').value;
			var tar = document.getElementById(objname+'_tar').value;
			var inp = document.getElementById(objname+'_inp').value;
			var fmt = document.getElementById(objname+'_fmt').value;
			
			obj.src = path+"calendar_form.php?objname="+objname.toString()+"&selected_day="+date_array[2]+"&selected_month="+date_array[1]+"&selected_year="+yvalue+"&year_start="+year_start+"&year_end="+year_end+"&dp="+dp+"&mon="+smon+"&da1="+da1+"&da2="+da2+"&sna="+sna+"&aut="+aut+"&frm="+frm+"&tar="+tar+"&inp="+inp+"&fmt="+fmt;
			
			obj.contentWindow.submitNow(date_array[2], date_array[1], yvalue);
			
		}else document.getElementById(objname+"_year").value = date_array[0];
	}
}

function yearEnter(e){
	var characterCode;
	
	if(e && e.which){ //if which property of event object is supported (NN4)
		e = e;
		characterCode = e.which; //character code is contained in NN4's which property
	}else{
		e = event;
		characterCode = e.keyCode; //character code is contained in IE's keyCode property
	}
	
	if(characterCode == 13){ 
		//if Enter is pressed, do nothing		
		return true;
	}else return false;
}


// Declaring valid date character, minimum year and maximum year
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.

    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function is_leapYear(year){
	return (year % 4 == 0) ?
		!(year % 100 == 0 && year % 400 != 0)	: false;
}

function daysInMonth(month, year){
	var days = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	return (month == 2 && is_leapYear(year)) ? 29 : days[month-1];
}
	
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(strDay, strMonth, strYear){
/*
	//bypass check date	
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || day > daysInMonth(month, year)){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}*/
	return true
}

function isDateAllow(objname, strDay, strMonth, strYear){	
	var da1 = document.getElementById(objname+"_da1").value;
	var da2 = document.getElementById(objname+"_da2").value;
	
	strDay = parseInt(parseFloat(strDay));
	strMonth = parseInt(parseFloat(strMonth));
	strYear = parseInt(parseFloat(strYear));
	
	//alert(da1+"\n"+da2+"\n"+strDay+"\n"+strMonth+"\n"+strYear);
	
	if(strDay>0 && strMonth>0 && strYear>0){	
		if(da1 || da2){
			var date2Set = new Date();
			date2Set.setFullYear(strYear, strMonth-1, strDay);
			
			if(da1 && da2){
				
				var da1Arr = da1.split('-', 3);			
				var da2Arr = da2.split('-', 3);
				
				da1Arr[0] = parseInt(parseFloat(da1Arr[0]));
				da1Arr[1] = parseInt(parseFloat(da1Arr[1]));
				da1Arr[2] = parseInt(parseFloat(da1Arr[2]));
				
				da2Arr[0] = parseInt(parseFloat(da2Arr[0]));
				da2Arr[1] = parseInt(parseFloat(da2Arr[1]));
				da2Arr[2] = parseInt(parseFloat(da2Arr[2]));
				
				var da1Date=new Date();
				da1Date.setFullYear(da1Arr[0],da1Arr[1]-1,da1Arr[2]);
							
				var da2Date=new Date();
				da2Date.setFullYear(da2Arr[0],da2Arr[1]-1,da2Arr[2]);
				
				//alert(date2Set+"\n"+da1Date+"\n"+da2Date);
				
				return (date2Set>=da1Date && date2Set<=da2Date) ? true : false;
			}else if(da1){
				
				var da1Arr = da1.split('-', 3);			
				
				da1Arr[0] = parseInt(parseFloat(da1Arr[0]));
				da1Arr[1] = parseInt(parseFloat(da1Arr[1]));
				da1Arr[2] = parseInt(parseFloat(da1Arr[2]));
				
				var da1Date=new Date();
				da1Date.setFullYear(da1Arr[0],da1Arr[1]-1,da1Arr[2]);
							
				return (date2Set>=da1Date) ? true : false;
			}else{
				
				var da2Arr = da2.split('-', 3);			
				
				da2Arr[0] = parseInt(parseFloat(da2Arr[0]));
				da2Arr[1] = parseInt(parseFloat(da2Arr[1]));
				da2Arr[2] = parseInt(parseFloat(da2Arr[2]));
				
				var da2Date=new Date();
				da2Date.setFullYear(da2Arr[0],da2Arr[1]-1,da2Arr[2]);
				
				//alert(date2Set);
				//alert(da2Date);
				
				return (date2Set<=da2Date) ? true : false;
			}
		}else return true;
	}else return true; //always return true if date not completely set
}

function restoreDate(objname){
	//get the store value
	var storeValue = document.getElementById(objname).value;
	var storeArr = storeValue.split('-', 3);
	
	//set it
	document.getElementById(objname+'_day').value = storeArr[2];
	document.getElementById(objname+'_month').value = storeArr[1];
	document.getElementById(objname+'_year').value = storeArr[0];
}

//----------------------------------------------------------------
//javascript date format function thanks to
// http://jacwright.com/projects/javascript/date_format
//
// some modification to match the calendar script
//----------------------------------------------------------------

// Simulates PHP's date function
Date.prototype.format = function(format) {
	var returnStr = '';
	var replace = Date.replaceChars;
	for (var i = 0; i < format.length; i++) {
		var curChar = format.charAt(i);
		if (replace[curChar]) {
			returnStr += replace[curChar].call(this);
		} else {
			returnStr += curChar;
		}
	}
	return returnStr;
};
Date.replaceChars = {
	shortMonths: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
	longMonths: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
	shortDays: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
	longDays: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
	
	// Day
	d: function() { return (this.getDate() < 10 ? '0' : '') + this.getDate(); },
	D: function() { return Date.replaceChars.shortDays[this.getDay()]; },
	j: function() { return this.getDate(); },
	l: function() { return Date.replaceChars.longDays[this.getDay()]; },
	N: function() { return this.getDay() + 1; },
	S: function() { return (this.getDate() % 10 == 1 && this.getDate() != 11 ? 'st' : (this.getDate() % 10 == 2 && this.getDate() != 12 ? 'nd' : (this.getDate() % 10 == 3 && this.getDate() != 13 ? 'rd' : 'th'))); },
	w: function() { return this.getDay(); },
	z: function() { return "Not Yet Supported"; },
	// Week
	W: function() { return "Not Yet Supported"; },
	// Month
	F: function() { return Date.replaceChars.longMonths[this.getMonth()]; },
	m: function() { return (this.getMonth() < 9 ? '0' : '') + (this.getMonth() + 1); },
	M: function() { return Date.replaceChars.shortMonths[this.getMonth()]; },
	n: function() { return this.getMonth() + 1; },
	t: function() { return "Not Yet Supported"; },
	// Year
	L: function() { return "Not Yet Supported"; },
	o: function() { return "Not Supported"; },
	Y: function() { return this.getFullYear(); },
	y: function() { return ('' + this.getFullYear()).substr(2); },
	// Time
	a: function() { return this.getHours() < 12 ? 'am' : 'pm'; },
	A: function() { return this.getHours() < 12 ? 'AM' : 'PM'; },
	B: function() { return "Not Yet Supported"; },
	g: function() { return this.getHours() % 12 || 12; },
	G: function() { return this.getHours(); },
	h: function() { return ((this.getHours() % 12 || 12) < 10 ? '0' : '') + (this.getHours() % 12 || 12); },
	H: function() { return (this.getHours() < 10 ? '0' : '') + this.getHours(); },
	i: function() { return (this.getMinutes() < 10 ? '0' : '') + this.getMinutes(); },
	s: function() { return (this.getSeconds() < 10 ? '0' : '') + this.getSeconds(); },
	// Timezone
	e: function() { return "Not Yet Supported"; },
	I: function() { return "Not Supported"; },
	O: function() { return (-this.getTimezoneOffset() < 0 ? '-' : '+') + (Math.abs(this.getTimezoneOffset() / 60) < 10 ? '0' : '') + (Math.abs(this.getTimezoneOffset() / 60)) + '00'; },
	T: function() { var m = this.getMonth(); this.setMonth(0); var result = this.toTimeString().replace(/^.+ \(?([^\)]+)\)?$/, '$1'); this.setMonth(m); return result;},
	Z: function() { return -this.getTimezoneOffset() * 60; },
	// Full Date/Time
	c: function() { return "Not Yet Supported"; },
	r: function() { return this.toString(); },
	U: function() { return this.getTime() / 1000; }
};


function padString(stringToPad, padLength, padString) {
	if (stringToPad.length < padLength) {
		while (stringToPad.length < padLength) {
			stringToPad = padString + stringToPad;
		}
	}else {}
/*
	if (stringToPad.length > padLength) {
		stringToPad = stringToPad.substring((stringToPad.length - padLength), padLength);
	} else {}
*/	
	return stringToPad;
}

function tc_updateDay(objname, yearNum, monthNum, daySelected){
	var totalDays = daysInMonth(monthNum, yearNum);
	
	var dayObj = document.getElementById(objname+"_day");
	//var prevSelected = dayObj.value;
	
	if(dayObj.options[0].value == 0 || dayObj.options[0].value == "") 
		dayObj.length = 1;
	else dayObj.length = 0;
	
	for(d=1; d<=totalDays; d++){
		var newOption = document.createElement("OPTION");
		newOption.text = d;
		newOption.value = d;
		
		dayObj.options[d] = new Option(newOption.text, padString(newOption.value, 2, "0"));
	}
	
	if(daySelected > totalDays)
		dayObj.value = padString(totalDays, 2, "0");
	else dayObj.value = padString(daySelected, 2, "0");
	
	return dayObj.value;
}

