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/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();	
}


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/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();	
}



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';	
	}
}



function CreateBookmarkLink(title, url) {
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite(url, title); }
	else if(window.opera && window.print) { // Opera Hotlist
		return true; }
 }
 
 
 
 
// 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){
	fadeDiv('bodyOverlay', 'in');
	
	if (document.getElementById){
		var subobj=document.getElementById(divID);
		subobj.style.display=(subobj.style.display!="block")? "block" : "none";
		subobj.style.zIndex = 100;
		
		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){
	fadeDiv('bodyOverlay', 'out');
	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();















function fadeDiv(divID, direction){
	if(divID == null || !document.getElementById(divID)){
		return;	
	}
	
	var windowWidth=ie && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth : window.pageXOffset+window.innerWidth-18;
	var windowHeight=ie && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight : window.pageYOffset+window.innerHeight;
		
	div = document.getElementById(divID);
	div.style.left = '0px';
	div.style.top = '0px';
	div.style.width = windowWidth+'px';
	div.style.height = (windowHeight+100)+'px';
	
	if(direction == 'in'){
		if(getOpacity('', div) > 0.6){
			return;
		}
		opacity = 0;
	}else{
		if(getOpacity('', div) < 0.1){
			return;
		}
		opacity = 0.7;	
	}
	
	showDiv(divID);
	return fadeIt(divID, direction, opacity);
}





function fadeIt(divID, direction, opacity){
	var contentdiv = document.getElementById(divID);
	
	if (direction=="in"){
		opacity+=0.05;
	}else{
		opacity-=0.05;
	}
	
	if(contentdiv.style.filter != null){
		contentdiv.style.filter = "alpha(opacity=" + (opacity*100) + ")";
		contentdiv.style.opacity = opacity;
		
	}else if (contentdiv.filters && contentdiv.filters[0]){
		
		if (typeof contentdiv.filters[0].opacity=="number"){ //IE6+
			contentdiv.filters[0].opacity=opacity*100;
		}else{ //IE 5.5
			contentdiv.style.filter="alpha(opacity="+opacity*100+")";
		}
		
	}else if (typeof contentdiv.style.MozOpacity!="undefined" && opacity!=""){
		contentdiv.style.MozOpacity=opacity;
	}else{
		opacity=0;
		direction = "out";
	}

	
	if (direction=="in" && opacity>=0.7){
		return true;
	}else if(direction == "out" && opacity <= 0){
		hideDiv(divID);
		return true;
	}else{
		setTimeout(function(){fadeIt(divID, direction, opacity)}, 10);
	}

}



function getOpacity(divID, theDiv){
	if(divID != '' && theDiv == null){
		theDiv = document.getElementById(divID);	
	}
	
	var opacity = -1;
	
	opacity = theDiv.style.opacity;
	
	if(opacity < 0){
		if(theDiv.style.filter != null){
			var tmp = theDiv.style.filter.replace('alpha(opacity=','');
			opacity = parseInt(tmp.replace(')',''));
		}else{
			opacity = 0;	
		}
	}
	
	return opacity;
}




function startScrollToDiv(divID, doneFunction){
	theDiv = document.getElementById(divID);
	offset = getposOffset(theDiv);
	
	return pageScroll(offset, doneFunction);
}

function pageScroll(remaining, doneFunction) {
	if(remaining > 150){
		scrollInc = 50;
	}else{
		scrollInc = 10;	
	}
	
	if(remaining < scrollInc){
		if(doneFunction != null){
			setTimeout(doneFunction, 1000);
		}
		return;
	}
	window.scrollBy(0,scrollInc); // horizontal and vertical scroll increments
	return setTimeout(function(){pageScroll(remaining-scrollInc, doneFunction);},10); // scrolls every 100 milliseconds
}