var ie=document.all

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 showSpan(divID){
	theDiv = document.getElementById(divID);
	theDiv.style.visibility = 'visible';	
	theDiv.style.display = 'inline';
}


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 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 matchHeights(div1, div2){
	div_1 = document.getElementById(div1);
	div_1_height = div_1.offsetHeight;
	div_2 = document.getElementById(div2);			
	div_2_height = div_2.offsetHeight;
	
	//div_1_height = div_2_height = "300px";
	
	//alert(div_1_height + " : " + div_2_height);
	//alert(div_1.offsetTop);
	if(div_1_height > div_2_height){
		div_2.style.height = (div_1_height + 20) + "px";
		div_1.style.height = div_1_height + "px";
		//div_2.style.height = "100%";
		//div_2.setAttribute('height', div_1_height);
		//div_2.setAttribute('height', "100%");
		//alert(div_2.style.height + " : " + div_2.height);
	}else if(div_2_height > div_1_height){
		div_1.style.height = (div_2_height - 20) + "px";
		div_2.style.height = div_2_height + "px";
		//div_1.style.height = "100%";
		//div_1.setAttribute('height', div_2_height);		
		//div_1.setAttribute('height', "100%");
		//alert(div_1.style.height + " : " + div_1.height);
	}
	
}




function checkLength(txtBox, maxLength, remainingDiv){
	if(txtBox.value.length > maxLength){
		alert('You have reached the '+maxLength+' character limit!');
		txtBox.value = txtBox.value.substr(0,maxLength-1);
		
	}
	
	if(remainingDiv != null){
		document.getElementById(remainingDiv).innerHTML = maxLength - txtBox.value.length;	
	}
	
}


function print_view(contentId){
	printDiv = document.getElementById(contentId);
	popup = window.open('', 'popup');
	popup.document.open();
	popup.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>');
	popup.document.write('<html xmlns="http://www.w3.org/1999/xhtml">');
	popup.document.write("<head><link href='includes/main.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();	
}


function admin_print_view(contentId){
	printDiv = document.getElementById(contentId);
	popup = window.open('', 'popup');
	popup.document.open();
	popup.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>');
	popup.document.write('<html xmlns="http://www.w3.org/1999/xhtml">');
	popup.document.write("<head><link href='../includes/main.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();	
}



function check_all_from_box(checked, theDiv){
	if(checked == true){
		check_all_boxes(theDiv, 1);
	}else{
		check_all_boxes(theDiv, 0);
	}
}
	
function check_all_boxes(table_name, on){
	
	var rows = document.getElementById(table_name).getElementsByTagName('tr');
    var unique_id;
    var checkbox;
	
	if(on == null){
		on = 1;	
	}
	
    for ( var i = 0; i < rows.length; i++ ) {
        checkbox = rows[i].getElementsByTagName( 'input' )[0];

        if ( checkbox && checkbox.type == 'checkbox' ) {
            unique_id = checkbox.name + checkbox.value;
            if ( on == 1 ) {
                checkbox.checked = true;
            }else{
				checkbox.checked = false;	
			}
        }
    }
	
}//end function


function checkBoxesInDiv(wrapperID, on){
	theElements = document.getElementById(wrapperID).getElementsByTagName('input');
	
	for(var i = 0; i < theElements.length; i++){
		//checkbox = theElements[i].getElementsByTagName( 'input' )[0];
		checkbox = theElements[i];

        if ( checkbox && checkbox.type == 'checkbox' ) {
            unique_id = checkbox.name + checkbox.value;
            if ( on == 1 ) {
                checkbox.checked = true;
            }else{
				checkbox.checked = false;	
			}
        }
	}
}


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';	
	}
}

// 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(); 
   } 
}


/***********************************************
* 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, dragable : 0,
	initialize:function(){
		document.onmousedown=this.drag;
		document.onmouseup=function(){
			
			/*
			if(this.dragapproved == 1){
				this.targetobj.className = "drag";				
			}
			
			if(this.dragable == 1){
				this.targetobj.className = "dragable";	
			}
			*/
			
			this.dragapproved=0;
			this.dragable = 0;
		}
	},
	
	
	drag:function(e){
		var evtobj=window.event? window.event : e;
		this.targetobj=window.event? event.srcElement : e.target;
		
		
		while(this.targetobj.className == ''){
			if(this.targetobj.offsetParent != null){
				this.targetobj = this.targetobj.offsetParent;
			}else{
				break;	
			}
		}
		
		tClass = this.targetobj.className;
		
		if(tClass.match("dragable")=="dragable"){
			this.targetobj.className = tClass = "drag";
			this.dragable = 1;
		}
		
		if (tClass.match("drag")=="drag" || tClass.match("dragIt")=="dragIt" || tClass == "overlayDiv"){
			this.dragapproved=1;
			//this.targetobj.className = "dragIt";
			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();