//Javascript Functions for OGT
//Developed by Sean McGill - April 2008 


var devMode = false;		//If development from other than development server  ; ADD ON NOTE by Daniel Hartanto: Since we are migrating this externally and there would be separate location for development server anymore, I am going to put same URL address

function openWindow(URL, x,y,w,h)
{
	alert("Opening new window.");
	//Opens a specifically sized windows at a particular location on the stage
	var winHeight;
	var winWidth;
	var winTop;
	var winLeft;
	winHeight = h;
	winWidth = w; 
	winTop = x;
	winLeft = y;
		
	buscard = window.open(URL, "OGT Business Card", "width="+winWidth+",height="+winHeight+",top="+winTop+",left="+winLeft+", resizable=no,toolbar=no,scrollbars=no,menubar=no,location=no"); 
}

function include(lyr,filename)
{
   //Update and pass the URL as needed, based on its location
   if(!devMode)
   {
	   url = "http://intranet.oakgrovetech.com/" + filename;
	   //url = "http://morx.pair.com/ogtweb/public_site/intranet/" + filename;
   }else{
	   url = "http://localhost/php/intranet/" + filename;
	   //url = "http://morx.pair.com/ogtweb/public_site/intranet/" + filename;
   }
   
   
   	  // Add on for cache issue resolution - Daniel Hartanto
	  if (url.indexOf("?") != -1) { 
		url = url + "&date=" + new Date(); } 

	  else { url = url + "?date=" + new Date(); } 
   
   
   if (document.all)
   {
      // IE version
      try {
      var xml = new ActiveXObject("Microsoft.XMLHTTP");
	 
	  xml.Open( "GET", url, false );
      xml.Send()
      document.getElementById(lyr).innerHTML=xml.responseText;
       }
      catch (e) {
      var xml = new ActiveXObject("MSXML2.XMLHTTP.4.0");
      xml.Open( "GET", url, false );
      xml.Send()
      document.getElementById(lyr).innerHTML=xml.responseText;
      }
   }
   else
   {
      // Mozilla/Netscrap 6+ version
      var xml=new XMLHttpRequest();
      xml.open("GET",url,false);
      xml.send(null);
      document.getElementById(lyr).innerHTML=xml.responseText;
   }
}

//AJAX Form elements
function makePOSTRequest(url, parameters) {
  http_request = false;
  if (window.XMLHttpRequest) { // Mozilla, Safari,...
	 http_request = new XMLHttpRequest();
	 if (http_request.overrideMimeType) {
		// set type accordingly to anticipated content type
		//http_request.overrideMimeType('text/xml');
		http_request.overrideMimeType('text/html');
		http_request.overrideMimeType('text/file');
	 }
  } else if (window.ActiveXObject) { // IE
	 try {
		http_request = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
		try {
		   http_request = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {}
	 }
  }
  if (!http_request) {
	 alert('Cannot create XMLHTTP instance');
	 return false;
  }
  
  http_request.onreadystatechange = alertContents;
  http_request.open('POST', url, true);
  http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http_request.setRequestHeader("Content-length", parameters.length);
  http_request.setRequestHeader("Connection", "close");
  http_request.send(parameters);
}

function alertContents() {
  if (http_request.readyState == 4) {
	 if (http_request.status == 200) {
		//alert(http_request.responseText);
		result = http_request.responseText;
		document.getElementById('ogtcontent').innerHTML = result;            
	 } else {
		alert('There was a problem with the request.');
	 }
  }
}

function get(obj) {
  var poststr = "search_fname=" + escape(encodeURI(document.getElementById("fname").value )) + "&search_lname=" + escape(encodeURI(document.getElementById("lname").value )) + "&search_local=" + escape(encodeURI( document.getElementById("location").value ));
  makePOSTRequest('dir_list.php', poststr);
}

function getDir(obj) {
  var poststr = "srch_fname=" + escape(encodeURI(document.getElementById("fname").value )) + "&srch_lname=" + escape(encodeURI(document.getElementById("lname").value )) + "&srch_local=" + escape(encodeURI( document.getElementById("local").value ))+"&srch_depart=" + escape(encodeURI( document.getElementById("depart").value ));
  makePOSTRequest('employee_search.php', poststr);
}

// Add On function to create Pop up - Daniel Hartanto
function popUp(URL,X,Y) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width="+ X + ",height= " + Y + ",left = 150,top = 100');");
}


// add on function for business card updater tool
function getAddy(obj) {
  var poststr = "bc_address=" + escape(encodeURI(document.getElementById("bc_address").value ));
  makePOSTRequest('bc_address.php', poststr);
}

function getOPhone(obj) {
  var poststr = "o_phone=" + escape(encodeURI(document.getElementById("o_phone").value ));
  makePOSTRequest('bc_ophone.php', poststr);
}

function getCPhone(obj) {
  var poststr = "c_phone=" + escape(encodeURI(document.getElementById("c_phone").value ));
  makePOSTRequest('bc_cphone.php', poststr);
}

function getExt(obj) {
  var poststr = "ext=" + escape(encodeURI(document.getElementById("ext").value ));
  makePOSTRequest('bc_ext.php', poststr);
}

function getFax(obj) {
  var poststr = "fax=" + escape(encodeURI(document.getElementById("fax").value ));
  makePOSTRequest('bc_fax.php', poststr);
}

function getExp(obj) {
  var poststr = "exp=" + escape(encodeURI(document.getElementById("exp").value ));
  makePOSTRequest('process_bc_exe_2.php', poststr);
}