// System        : MUS-IIT Reasearch DB System, Author Module
// Author        : Rex S. Sacayan
// Modified by   :
// Date created  : April 12, 2010
// Date modified : April 12, 2010

// defaults
var popup = null; 
var leftpos = 0;

// UTILITY FUNCTIONS

function xmlhttp_req() 
// Author : Rex S. Sacayan
// Date created  : November 16, 2007
// Date modified : November 16, 2007 
// Note : Create an instance of XMLHttpObject
{
	var Req = false;
	if (window.XMLHttpRequest) {
		Req = new XMLHttpRequest();
    }
	else if (window.ActiveXObject) {
		Req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	return Req;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
    window.open(theURL,winName,features);
}

function newWindow(url,prop)  
{
    var attr = "resizable=yes,width=615,height=630,top=80";
	 
	if(prop != ""){ attr = prop; }
	
	closeWindow();
    
	popup = window.open(url,"", attr);  
	popup.focus();
}
  
function closeWindow()
{
    if(popup && !popup.closed) {
      popup.close();
    }
}

function printForm(){
	setTimeout("window.print()",1000);
}

/* AJAX functions */ 
function drop_data(php_script,row, key,colid,value,table)   
{
    var debug   = 0; 
	var ID      = row; 
	  
	
    var req     = xmlhttp_req(); 
   	var answer  = confirm('Are you sure you want to delete this ' + key + ' ' + colid	 + '?');
	var colspan = document.getElementById(ID).getElementsByTagName('td').length;  
	var trElem  = document.getElementById(ID);
	
	if(answer) {
        if(req) {
			req.onreadystatechange = function () {
   			   if (req.readyState == 4) {
			      if(document.getElementById(ID)) {
					  // remove current td element
				  	  for(var i = colspan-1; i >= 0; i--){
		              	  trElem.deleteCell(i); 
					  }
				  	  // add new td element for the info message
				  	  newCell = trElem.insertCell(0);
		              newCell.setAttribute('colspan',colspan,0); 
		          	  newCell.innerHTML="<div class=\"info pcenter\">Record ID " + ID + " successfully deleted...</div>";  
			      }
			   }
			} 
		
		   	if(debug) alert("GET actions/" + php_script + "?table=" + table + "&" + key + "=" + value + "&action=delete");
			else req.open("GET","actions/" + php_script + "?table=" + table + "&" + key + "=" + value + "&action=delete");  
			req.send(null);   
	     }
    }	 
}
