// JavaScript Document

// open browser window
function openPopUp(url, windowName, w, h, scrollbar) {

           var winl = (screen.width - w) / 2;
           var wint = (screen.height - h) / 2;
           winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scrollbar ;
		   win = window.open(url, windowName, winprops);
           if (parseInt(navigator.appVersion) >= 4) { 
              	win.window.focus(); 
           } 
}




function setValue(theID, theValue){
	document.getElementById(theID).value = theValue;	
}


function setHTML(theID, theHTML){
	document.getElementById(theID).innerHTML = theHTML;
}


function showDiv(divID){
	theDiv = document.getElementById(divID);
	theDiv.style.visibility = 'visible';	
	theDiv.style.display = 'block';
}


function hideTr(trID){
	document.getElementById(trID).style.display = 'none';
}

function showTr(trID){
	theTr = document.getElementById(trID);
	theTr.style.visibility = 'visible';	
	if (navigator.appName == "Microsoft Internet Explorer") {
		theTr.style.display = 'block';
	}else{
		theTr.style.display = 'table-row';	
	}
}




function showElementsByTag(wrapperID, tag){
	theElements = document.getElementById(wrapperID).getElementsByTagName(tag);
	
	for(var i = 0; i < theElements.length; i++){
		theElements[i].style.display = 'block';	
	}
}




function hideElementsByTag(wrapperID, tag){
	theElements = document.getElementById(wrapperID).getElementsByTagName(tag);
	
	for(var i = 0; i < theElements.length; i++){
		theElements[i].style.display = 'none';	
	}
}






function addRow(tableID, newRowID, oldRowID){
	
   	var tbody = document.getElementById(tableID).getElementsByTagName("TBODY")[0];
   	var newRow = document.createElement("TR");
   	newRow.setAttribute('id', newRowID);
	
	if(oldRowID != ''){
		oldRow = document.getElementById(oldRowID);
		
		for(i = 0; i < oldRow.cells.length; i++){
			//alert("NEW TD: " + i);
			var newTd = document.createElement("TD");
			oldTd = oldRow.cells[i];
			newTd.innerHTML = oldRow.cells[i].innerHTML;
			newRow.appendChild(newTd);
			//td1.appendChild(document.createTextNode("column 1"))
		}
	}
	
   	tbody.appendChild(newRow);
   	return newRow;
 }



function deleteAllRows(tableID){	
   	var tbody = document.getElementById(tableID).getElementsByTagName("TBODY")[0];
	numRows = tbody.rows.length;
	for(i = numRows - 1; i >= 0; i--){
		tbody.removeChild(tbody.rows[i]);	
	}
}


function hideDiv(divID){
	document.getElementById(divID).style.display = 'none';
}
function delayHideDiv(divID){
	setTimeout("hideDiv('"+divID+"')",250);	
}


function disableDiv(divID){
	document.getElementById(divID).disabled = 'disabled';
}

function enableDiv(divID){
	theDiv = document.getElementById(divID).disabled = '';
}


function noReadDiv(divID){
	document.getElementById(divID).readOnly = 'readonly';
}

function readDiv(divID){
	theDiv = document.getElementById(divID).readOnly = '';
}

function switchClass(ID, theClass){
	theDiv = document.getElementById(ID).className = theClass;	
}


function checkLength(txtBox, maxLength){
	if(txtBox.value.length > maxLength){
		alert('You have reached the '+maxLength+' character limit!');
		txtBox.value = txtBox.value.substr(0,maxLength-1);
	}
}



function print_view(contentId){
	printDiv = document.getElementById(contentId);
	popup = window.open('', 'popup');
	popup.document.open();
	popup.document.write("<html><head><link href='includes/style.css' rel='stylesheet' type='text/css' /></head><body><div style='padding:10px;'>");
	popup.document.write(printDiv.innerHTML);
	popup.document.write("</div></body></html>");
	popup.document.close();	
}







/***********************************************
* Drop Down/ Overlapping Content- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for legal use.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

function iecompattest(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function getposOffset(overlay, offsettype){
	var totaloffset=(offsettype=="left")? overlay.offsetLeft : overlay.offsetTop;
	var parentEl=overlay.offsetParent;
	while (parentEl!=null){
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}

function overlayDiv(curobj, divID, opt_position){
	if (document.getElementById){
		var subobj=document.getElementById(divID);
		subobj.style.display=(subobj.style.display!="block")? "block" : "none";
		subobj.style.zIndex = 0;
		
		
		var xpos = (document.body.clientWidth/2) - (subobj.offsetWidth/2);
		var ypos = ((iecompattest().clientHeight/2 + iecompattest().scrollTop)) - (subobj.offsetHeight/2);
		
		subobj.style.left=xpos+"px";
		subobj.style.top=ypos+"px";
		return false;
	}else{
		return true;
	}
}


function overlayclose(subobj){
	theDiv = document.getElementById(subobj)
	theDiv.style.display="none";
}







/***********************************************
* Drag and Drop Script: © Dynamic Drive (http://www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
* http://dynamicdrive.com/dynamicindex4/image3.htm
***********************************************/

var dragobject={
	z: 0, x: 0, y: 0, offsetx : null, offsety : null, targetobj : null, dragapproved : 0,
	initialize:function(){
		document.onmousedown=this.drag;
		document.onmouseup=function(){this.dragapproved=0;}
	},
	
	
	drag:function(e){
		var evtobj=window.event? window.event : e;
		this.targetobj=window.event? event.srcElement : e.target;
		tClass = this.targetobj.className;
		if (tClass=="drag" || tClass == "overlayDiv"){
			this.dragapproved=1;
			if (isNaN(parseInt(this.targetobj.style.left))){this.targetobj.style.left=0;}
			if (isNaN(parseInt(this.targetobj.style.top))){this.targetobj.style.top=0;}
			this.offsetx=parseInt(this.targetobj.style.left);
			this.offsety=parseInt(this.targetobj.style.top);
			this.x=evtobj.clientX;
			this.y=evtobj.clientY;
			if (evtobj.preventDefault)
				evtobj.preventDefault();
			document.onmousemove=dragobject.moveit;
		}
	},

	moveit:function(e){
		var evtobj=window.event? window.event : e;
		if (this.dragapproved==1){
			this.targetobj.style.left=this.offsetx+evtobj.clientX-this.x+"px";
			this.targetobj.style.top=this.offsety+evtobj.clientY-this.y+"px";
			return false;
		}
	}
}

dragobject.initialize();