/*******************************************************************************
*
*
********************************************************************************/
// create a new Html tag object
function newHtmlObject(tagName, id, className) {
  var oElement = document.createElement(tagName)
  if (id) oElement.id = oElement.name = id;
  if (className) oElement.className = className;
  return oElement;
}

// create a new html input object
function newInput(id, title, type, className) {
	var oInput = newHtmlObject("INPUT", id, className);
	if (title != '') oInput.title = title;
	oInput.type = type;			
	if (className != '' && type != 'hidden') oInput.className = className;													
	return oInput;
}

// create a new Html input of type text/hidden
function newInputText(id, isVisible, value, size, title, className, onchange, showFocus) {
  var oInputText = newInput(id, title, (isVisible)?'Text':'hidden', className);
  oInputText.value = value;
  if (isVisible) {
    oInputText.size = size;
    oInputText.onchange = onchange;
  }
 // var isShowFocus = (typeOf(showFocus) != 'undefined')? showFocus : true;
  if(/*isShowFocus && */(document.layers ||(!document.all && document.getElementById))){
    oInputText.style.border = "1px #C6D2DD solid";
    oInputText.onfocus = function() { oInputText.style.border = "2px #DFC83F inset";}
    oInputText.onblur = function() {oInputText.style.border = "1px #C6D2DD solid";}
  }
  return oInputText;
}

// create a new Html input of image type
function newInputImage(id, src, title, onclick) {
	var inputImage = newInput(id, title, "image", '');			
	inputImage.src = src;		
	inputImage.style.backgroundColor = 'transparent';	
	inputImage.style.border = 0;
	inputImage.onclick = onclick;
	return inputImage		
}

// create a new html input of type button
function newInputButton(type, id, value, className, onclick) {
  var oInputButton = newInput(id, '', type, className);
  oInputButton.value = value;
  oInputButton.onclick = onclick;
  return oInputButton;
}

// create a new html img element
function newImage(id, src, alt, className, onclick){
  var oImg = newHtmlObject("img", id, className);
  oImg.src = src;
  oImg.alt = alt
  return oImg;  
}

// create a new Table with a title bar
function newTitledTable(id, bgColor, titleColor, className, title, actionImage, actionHint, onActionEvent) {
	var oTable = newHtmlObject("table", id, className );
	oTable.borderColor = bgColor;
	oTable.cellPadding=2;
	oTable.cellSpacing=0;
	var rowCount = 0;
	var oNewRow = oTable.insertRow(rowCount++);
	var oNewCell;
	if (title) {						
		oNewCell = oNewRow.insertCell(0);
		oNewCell.align='left';						
		oNewCell.style.backgroundColor = bgColor;	
    oNewCell.style.color = titleColor;	
		oNewCell.innerHTML = title;
		oTable.titleCell = oNewCell;
		
		oNewCell = oNewRow.insertCell(1);
		oNewCell.width='1';
		oNewCell.align='right';
		oNewCell.vAlign='top';
		oNewCell.style.backgroundColor = bgColor;	
    oNewCell.style.color = titleColor;
		oNewCell.appendChild(newInputImage('', actionImage, actionHint, onActionEvent));
		oTable.closeCell = oNewCell;	
		
		oNewRow = oTable.insertRow(rowCount++);												
	}						
	oNewRow = oTable.insertRow(rowCount++)
	oNewCell = oNewRow.insertCell(0);
	oNewCell.align="left";
	oNewCell.colSpan=2;
	//oNewCell.style.backgroundColor = titleColor; 	
  oNewCell.style.color = bgColor;
  //oNewCell.borderColor = bgColor;
	oTable.content = oNewCell
  	
	return oTable;
}

//class recSize
function recSize(){
  //this.top = 0;
  //this.left=0;
  this.height = 0;
  this.width = 0;
}

function getFrameSize() {
  var rec = new recSize;  
  
  if (self.innerWidth){
    //rec.top = self.top;
    //rec.left = self.left;
    rec.height = self.innerHeight;
    rec.width = self.innerWidth;
    }else if (document.documentElement && document.documentElement.clientWidth){
        //rec.top = document.documentElement.clientTop;
        //rec.left = document.documentElement.clientLeft;
        rec.height = document.documentElement.clientHeight;
        rec.width = document.documentElement.clientWidth;
        }	else if (document.body)	{
            //rec.top = document.body.clientTop;
           //rec.left = document.body.clientLeft;
            rec.height = document.body.clientHeight;
            rec.width = document.body.clientWidth;
          }
  return rec;
}

// return the height of the current frame
function getFrameHeight() {
  var rec = new recSize;  
  var frameHeight;
  if (self.innerWidth){
    frameHeight = self.innerHeight;
    }else if (document.documentElement && document.documentElement.clientWidth){
        frameHeight = document.documentElement.clientHeight;
        }	else if (document.body)	{
            frameHeight = document.body.clientHeight;
          }
  return frameHeight;
}

// open a fresh browser with a target name or give focus if already open
function linkBrowser(toHref, windowName) {
	windowprops = "height=540,width=740,location=1,resizable=1,scrollbars=1,status=0,titlebar=1,toolbar=0,z-lock=0";
	info = window.open(toHref, windowName, windowprops);					
	if (info.opener == null) 
		info.opener = window;
	else 
		info.focus();			
}	

function showInteractiveTable(tabid, rows) {
	var oForm = document.getElementById("frmShowTable");
	linkBrowser("", 'InteractiveTable');
	oForm.target = 'InteractiveTable';
	oForm["id"].value = tabid;
	oForm["rows"].value = rows;			
	oForm.submit();	
	return false;								
}


/******************************************************************************
 *  
******************************************************************************/  
function newHttpRequest() {  
  var xmlHttp = false;
  if(window.XMLHttpRequest) {
    try{
      xmlHttp = new XMLHttpRequest();            
    } catch(e) {
      xmlHttp = false;      
    } // catch(e) - xmlHttp = new XMLHttpRequest(); 
  } else if (window.ActiveXObject) {
    try {
      xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");      
    } catch(e) {
      try {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch(e) {
        xmlHttp = false;
      } //catch(e) - xmlHttp = false;
    } // catch(e) - xmlHttp = ActiveXObject("Msxml2.XMLHTTP");
  } //else if (window.ActiveXObject)
  return xmlHttp
 } 
 
/******************************************************************************
 *  CLASS: cHttpRequest
 *   
 *  DESCRIPTION: This class make it possible to possible to post back to the 
 *                web server using AJAX technology. 
******************************************************************************/
 function cHttpRequest(htmlReceiverObject) {  
  var xmlHttp = false;
  this.popup = null;
  this.anchor = htmlReceiverObject.id;
    
  if(window.XMLHttpRequest) {
    try{
      xmlHttp = new XMLHttpRequest();            
    } catch(e) {
      xmlHttp = false;      
    } // catch(e) - xmlHttp = new XMLHttpRequest(); 
  } else if (window.ActiveXObject) {
    try {
      xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");      
    } catch(e) {
      try {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch(e) {
        xmlHttp = false;
      } //catch(e) - xmlHttp = false;
    } // catch(e) - xmlHttp = ActiveXObject("Msxml2.XMLHTTP");
  } //else if (window.ActiveXObject)
           
  xmlHttp.onreadystatechange = 
      function () {                                                                                							
  			if (xmlHttp.readyState == 4) {
          document.body.style.cursor='default';
          if (this.popup) {
            this.popup.hidePopup();	
          }			
  				if (xmlHttp.status == 200) {
  					htmlReceiverObject.innerHTML = xmlHttp.responseText;	
            window.scrollTo(0, htmlReceiverObject.offsetTop);	                     
  				} else {
  				alert('The system has encountered the following error:\n' + 
                  xmlHttp.status + '\n' + xmlHttp.statusText);
  		      } // if (http_request.status == 200)
  		   } // if (http_request.readyState == 4)		  
  		} // function alertContents()  
  
  /*
  * this method is call to send a request using the post method
  */   
  this.post = 
    function(url, parameters, async) {                
      xmlHttp.open('POST', url, async);
      xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      xmlHttp.setRequestHeader("Content-length", parameters.length);
      xmlHttp.setRequestHeader("Connection", "close");      
      document.body.style.cursor='wait';      
      if (this.popup != null){
        xmlHttp.popup = this.popup;
        xmlHttp.popup.showPopup(this.anchor); 
      }      
      xmlHttp.send(parameters);
    } // function (url, parameters, async)
    
  /*
  * this method is call to send a request using the get method
  */  
  this.Get = 
    function(url,async){
      xmlHttp.open('GET',url, async);      
      if (this.popup != null){
        xmlHttp.popup = this.popup;
        xmlHttp.popup.showPopup(this.anchor); 
      } 
      xmlHttp.send(null);
    }
 } // function cHttpRequest(htmlReceiverObject)
 
