var ie=document.all

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


function getHTML(theID){
	document.getElementById(theID).innerHTML;
}


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


function copyHTML(sourceDiv, desDiv){
	document.getElementById(desDiv).innerHTML = document.getElementById(sourceDiv).innerHTML;	
}	


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){
	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('<!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(); 
   } 
}

