window.name='mainWindow';

function toggleCheckBackground(id){

	/*alert('div >' + id);*/
		
	div = "div_" + id;
	divElement = document.getElementById(div);

	if (divElement){
		if(divElement.className == 'checkbox-row'){
			divElement.className = "checked-checkbox-row";
		}else{
			divElement.className = "checkbox-row";
		}
	}
}

function toggleUnSelectedBoxState(id){


	span = "span_" + id;
	spanElement = document.getElementById(span);
	

	if (spanElement){
		if(spanElement.className == 'filter-breadcrumb-element-unselected'){
			spanElement.className = "filter-breadcrumb-element";
		}else{
			spanElement.className = "filter-breadcrumb-element-unselected";
		}
	}
}

function toggleCheckboxControls(select,unselect){
	
	selectElement = document.getElementById(select);
	
	unselectElement = document.getElementById(unselect);
	
	if (selectElement){
		if(selectElement.className == 'off-select-all-checkboxes'){
			selectElement.className = "on-select-all-checkboxes";
		}else{
			selectElement.className = "off-select-all-checkboxes";
		}
	}

	if (unselectElement){
		if(unselectElement.className == 'off-select-all-checkboxes'){
			unselectElement.className = "on-select-all-checkboxes";
		}else{
			unselectElement.className = "off-select-all-checkboxes";
		}
	}

}

function check_it(checkbox){
	checkboxElement = document.getElementById(checkbox);

	checkboxElement.checked = true;

	CheckBackground(checkboxElement.id);
}

function un_check_it(checkbox){
	checkboxElement = document.getElementById(checkbox);

	checkboxElement.checked = false;

	unCheckBackground(checkboxElement.id);
}

function CheckBackground(id){

	/*alert('div >' + id);*/
		
	div = "div_" + id;
	divElement = document.getElementById(div);

	if (divElement){
		divElement.className = "checked-checkbox-row";
	}
}

function unCheckBackground(id){

	/*alert('div >' + id);*/
		
	div = "div_" + id;
	divElement = document.getElementById(div);

	if (divElement){
		divElement.className = "checkbox-row";
	}
}

function CheckAll(form,group){
	
	formName = document.getElementById(form);
	
	for(var i=1; i<formName.elements.length; i++){
		if(formName.elements[i].type == 'checkbox'){
			
			
			/*if(formName.elements[i].name == "suggested_subjects[]"){
				alert(formName.elements[i].type + ' > ' + formName.elements[i].name+ ' > ' + formName.elements[i].id);
			}*/


			if(formName.elements[i].name == group){
				alternative_div = 'div_suggested_' + formName.elements[i].id;
				alternative_checkbox = 'suggested_' + formName.elements[i].id;

				
				if (document.getElementById(alternative_checkbox)){
					check_it(alternative_checkbox);
				}

				formName.elements[i].checked = true;

				div = "div_" + formName.elements[i].id;
				divElement = document.getElementById(div);

				if (divElement){
					divElement.className = "checked-checkbox-row";
				}
			}
		}
	}
}

function UnCheckAll(form,group){
	
	formName = document.getElementById(form);

	for(var i=1; i<formName.elements.length; i++){
		if(formName.elements[i].type == 'checkbox'){
			if(formName.elements[i].name == group){
				alternative_div = 'div_suggested_' + formName.elements[i].id;
				alternative_checkbox = 'suggested_' + formName.elements[i].id;

				
				if (document.getElementById(alternative_checkbox)){
					un_check_it(alternative_checkbox);
				}

				/*alert(formName.elements[i].type + ' > ' + formName.elements[i].name+ ' > ' + formName.elements[i].id);*/
				/*check_the_checkbox(formName.elements[i].id);*/

				formName.elements[i].checked = false;

				div = "div_" + formName.elements[i].id;
				divElement = document.getElementById(div);

				if (divElement){
					divElement.className = "checkbox-row";
				}
			}
		}
	}
}

function check_the_checkbox(checkbox){
	checkboxElement = document.getElementById(checkbox);

	if(checkboxElement.checked == true){
		checkboxElement.checked = false;
		
	}else{
		checkboxElement.checked = true;
		
	}

	toggleCheckBackground(checkboxElement.id);
}

function check_the_radiobutton(radiobutton){
	radiobuttonElement = document.getElementById(radiobutton);

	if(radiobuttonElement.checked == true){
		radiobuttonElement.checked = false;
		
	}else{
		radiobuttonElement.checked = true;
		
	}

	toggleCheckBackground(radiobuttonElement.id);
}



function UnCheckAllRadios(form,group,id){
	
	alert(test);

	formName = document.getElementById(form);

	for(var i=1; i<formName.elements.length; i++){
		if(formName.elements[i].type == 'radio'){
			if(formName.elements[i].name == group){
				alert(formName.elements[i].type + ' > ' + formName.elements[i].name+ ' > ' + formName.elements[i].id);
				check_the_checkbox(formName.elements[i].id);

				formName.elements[i].checked = false;

				div = "div_" + formName.elements[i].id;
				divElement = document.getElementById(div);

				if (divElement){
					divElement.className = "checkbox-row";
				}
			}
		}
	}
}

function clearDefault(el) {
  if (el.defaultValue==el.value) el.value = ""
}


function toggleAlphaLayer(id){
	divElement = document.getElementById(id);

	
	bodyElement = document.getElementById('body');
	
	if (divElement){
		if(divElement.className == 'alpha-layer-closed'){
			divElement.className = "alpha-layer-open";
		}else{
			divElement.className = "alpha-layer-closed";
		}
	}

	if (bodyElement){
		if(bodyElement.className == 'normal-scroll'){
			bodyElement.className = "hidden-scroll";
		}else{
			bodyElement.className = "normal-scroll";
		}
	}

}


function toggleConfirmation(id){
	divElement = document.getElementById(id);
	
	if (divElement){
		if(divElement.className == 'closed-confirmation'){
			divElement.className = "open-confirmation";
		}else{
			divElement.className = "closed-confirmation";
		}
	}

}

function togglePublishConfirmation(id){
	divElement = document.getElementById(id);
	
	if (divElement){
		if(divElement.className == 'closed-confirmation'){
			divElement.className = "open-confirmation";
		}else{
			divElement.className = "closed-confirmation";
		}
	}

}



function toggleNav(id){
	divElement = document.getElementById(id);
	
	if (divElement){
		if(divElement.className == 'itemOff'){
			divElement.className = "itemOver";
		}else{
			divElement.className = "itemOff";
		}
	}

}

function togglePhdBox(id){
	divElement = document.getElementById(id);
	
	if (divElement){
		if(divElement.className == 'phdBoxOff'){
			divElement.className = "phdBoxOver";
		}else{
			divElement.className = "phdBoxOff";
		}
	}

}

function resetNav(id){
	divElement = document.getElementById(id);
	
	if (divElement){
		divElement.className = "itemOff";
	}

}

function toggle(id){	
	div = "div_" + id;	
	divElement = document.getElementById(div);

	img = "img_" + id;	
	imgElement = document.getElementById(img);

	if (divElement){
		if(divElement.className == 'closed'){
			divElement.className = "open";
			imgElement.src = "/images/icon_collapse.gif";
		}else{
			divElement.className = "closed";
			imgElement.src = "/images/icon_expand.gif";
		}
	}
}


function changeTableBG(objRow, mouseState){
	if (mouseState == 'on'){
		sColor = '#eff3fa';
	}
	else if (mouseState == 'off'){
		sColor = '#ffffff';
	}
	objRow.bgColor = sColor;
}

function changeFacultyResourcesTableBG(objRow, mouseState){
	if (mouseState == 'on'){
		sColor = '#eef9db';
	}
	else if (mouseState == 'off'){
		sColor = '#ffffff';
	}
	objRow.bgColor = sColor;
}




	function call_printUpdateRelatedDocs() {
		agent.call('','printUpdateRelatedDocs','callback_printUpdateRelatedDocs');
		// Set a timeout to repeat this call every two seconds, controlled by the client.
		setTimeout('call_printUpdateRelatedDocs()',1000);
	}

	function callback_printUpdateRelatedDocs(str) {
		document.getElementById('divUpdateRelatedDocs').innerHTML = str;
	}

	function initRelatedDocs()  {
		call_printUpdateRelatedDocs();
	}



function popup (url, name, width, height){
	tearWin=window.open(url, name, 'personalbar=no,toolbar=no,status=no,scrollbars=no,location=no,resizable=no,menubar=no,width=' + width + ',height=' + height);
	if(window.focus) {
		tearWin.focus();
	}
}



function togglePublicationRow(id){
	divElement = document.getElementById(id);
	
	if (divElement){
		if(divElement.className == 'pub-info-row-off'){
			divElement.className = "pub-info-row-hover";
		}else{
			divElement.className = "pub-info-row-off";
		}
	}
}

function togglePublicationInfo(id){
	divElement = document.getElementById(id);
	
	if (divElement){
		if(divElement.className == 'hide'){
			divElement.className = "show";
		}else{
			divElement.className = "hide";
		}
	}
}

function disableForm(theform) {
if (document.all || document.getElementById) {
for (i = 0; i < theform.length; i++) {
var tempobj = theform.elements[i];
if (tempobj.type.toLowerCase() == "submit" || tempobj.type.toLowerCase() == "reset")
tempobj.disabled = true;
tempobj.value = "Indexing... Please wait!";
}
setTimeout('alert("The search index has now been updated! ;p")', 2000);
return true;
}
else {
alert("The form has been submitted.  But, since you're not using IE 4+ or NS 6, the submit button was not disabled on form submission.");
return false;
   }
}

function load_url(url){
	window.location = url;
}

function load_url_in_frame(url){
	parent.floating_frame.window.location = url;
}

function submit_form_in_frame(form){

	/*alert(form);
	
	formName = parent.floating_frame.document.getElementById(form).name;

	alert(formName);*/

	parent.floating_frame.document.getElementById(form).submit();

	//alert(parent.floating_frame.document.getElementById(form).submit);
}


function toggleButton(id,off,on){
	divElement = document.getElementById(id);

	if (divElement){
		if(divElement.className == off){
			divElement.className = on;
		}else{
			divElement.className = off;
		}
	}
}

function toggleStyle(id,off,on){
	divElement = document.getElementById(id);

	if (divElement){
		if(divElement.className == off){
			divElement.className = on;
		}else{
			divElement.className = off;
		}
	}
}

function hideBox(id){
	divElement = document.getElementById(id);
	divElement.className = 'no-show';
}


function toggleForumEdit(id){
	divElement = document.getElementById(id);
	
	if (divElement){
		if(divElement.className == 'hide'){
			divElement.className = "show";
		}else{
			divElement.className = "hide";
		}
	}
}

function toggleMenuItem(id){
	divElement = document.getElementById(id);
	
	if (divElement){
		if(divElement.className == 'hide'){
			divElement.className = "show";
		}else{
			divElement.className = "hide";
		}
	}
}

function toggleFloatingFrame(id){
	divElement = document.getElementById(id);
	
	if (divElement){
		if(divElement.className == 'hide'){
			divElement.className = "show";
		}else{
			divElement.className = "hide";
		}
	}
}


function basicAjaxLoader(url,id) {
  if (document.getElementById) {
    var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
  }
  if (x) {
    x.onreadystatechange = function() {
      if (x.readyState == 4 && x.status == 200) {
        el = document.getElementById(id);
        el.innerHTML = x.responseText;
      }
    }
    x.open("GET", url, true);
    x.send(null);
  }
}

function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 

	function pin_asset(){
		asset_to_pin = document.getElementById('pin_asset');

		document.pin_asset_form.asset.value = asset_to_pin.value;

		document.pin_asset_form.submit();
	}


function closeDrop(id){
	divElement = document.getElementById(id);
	if (divElement){
		alert(divElement.id);

		javascript:tabPopUp('in_my_selection_popup','span_in_my_drop_box');

	}else{
		alert("no element");
	}
}



function openTab(id){
	divElement = document.getElementById(id);

	if (divElement){
		if (divElement){
			divElement.className = "show";
		}
	}
}

function closeTab(id){
	divElement = document.getElementById(id);

	if (divElement){
		divElement.className = "no-show";
	}
}


function changeText(){
	document.getElementById('fluffy-view').innerHTML = document.upload_file.document.value;
}


function testImage(URL) {
    var tester=new Image();
    tester.onLoad=isGood;
    tester.onError=isBad;
    tester.src=URL;
}

function isGood() {
    alert('That image exists!');
}

function isBad() {
    alert('That image does no exist!');
}



function findExt(){
	var where_is_mytool=document.upload_file.document.value;

	var mytool_array=where_is_mytool.split(".");

	/*alert(mytool_array.length);*/

	/*alert(mytool_array[mytool_array.length-1]);*/

	/*mytool_array[mytool_array.length-1]*/

	/*testImage('../images/app_icons/'+ mytool_array[mytool_array.length-1] +'.gif');*/

	var ext = mytool_array[mytool_array.length-1];
	var exttolower = ext.toLowerCase();

	
	document.getElementById('app-icon').innerHTML = '<img src=\"/images/app_icons/'+ exttolower +'.gif\">';

}

function cancelFileUpload(){
	document.upload_file.reset();
}







// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove

// Temporary variables to hold mouse x-y pos.s
var tempX = 0
var tempY = 0

// Main function to retrieve mouse x-y pos.s




function thumbPreview(filter,drop_box)
{
    var div;
	var span;
	var box;
    
	span = document.getElementById(drop_box); 
	box = document.getElementById(filter); 

	/*alert(box.id);

	alert(document.getElementById('in_my_selection_popup').posTop);
	alert(document.getElementById('in_my_selection_popup').posLeft);*/
	/*alert(box.style.posLeft);*/


    if(document.getElementById)
    // Standard way to get element
    div = document.getElementById(filter); 
    else if(document.all) 
    // Get the element in old IE's 
    div = document.all[filter]; 
    
    // if the style.display value is blank we try to check it out here 
    if(div.style.display==''&&div.offsetWidth!=undefined&&div.offsetHeight!=undefined)
    {
        div.style.display = (div.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none'; 
    }
    
    // If the PopUp is hidden ('none') then it will display it ('block').
    // If the PopUp is displayed ('block') then it will hide it ('none').
    div.style.display = (div.style.display==''||div.style.display=='block')?'none':'block';
    


    // Off-sets the X position by 15px
	X = findPosX(span);
	Y = findPosY(span);

	//alert(X);
	//alert(Y);

	X = X;
	Y = Y - 130;
    
	//alert(span.offsetHeight);
	//alert(span.offsetWidth);

	//alert(getOffsetHeight(span));
	
    // Sets the position of the DIV


	div.style.left = X+'px';
    div.style.top = Y+'px';
	

	box.focus(); 
}


