/**
 * general.js
 *
 * Copyright (c) 2003-2006 John Willinsky
 * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
 *
 * Site-wide common JavaScript functions. 
 *
 * $Id: general.js,v 1.18 2006/06/12 23:26:06 alec Exp $
 */

//HACK: To hide/show reviewer interests
function showHideText(boxName,divName) {

	showhide(divName, "SUB");	
} 
function updateInterest(){

    var c_value = "";
    
    eureka_cat=false;
	for (var i=0; i < document.register.category.length; i++){
   		if (document.register.category[i].checked){
   			if(eureka_cat){
   				c_value=c_value+", ";
   			}
   			
   			eureka_cat=true;
   			c_value = c_value + document.register.category[i].value + " ";
   			eureka=false;
   			
   			for (var j=0; j < document.register.subcategory.length; j++){
   				
   				if((document.register.subcategory[j].id).substr(0,(document.register.subcategory[j].id).indexOf('_')) == document.register.category[i].id  ){
   				
	   				if (document.register.subcategory[j].checked){
	   					
		   				if(eureka){
		   					c_value=c_value+", ";
		   				}else{
		   					c_value=c_value+"(";	
		   				}
	   				
	   					eureka=true;
	      				c_value = c_value + document.register.subcategory[j].value;
	   				}
   				}
   				
   			}
   			if(eureka){
   				c_value=c_value + ")";
   			}
      	}
   	}
   	
   	//alert(">>"+c_value);

   	document.register.interests.value = c_value;

	//alert(select.register.interests.value);

    
}


function showhide(pass, hiders) {
	var divs = document.getElementsByTagName('div');

	for(i=0;i<divs.length;i++){
			if(divs[i].id.match(pass) ){ //if they are 'see' divs
			
				//OCULTAR SI ESTA VISIBLE
				
			
				if (document.getElementById)
					if(divs[i].style.display==""  && pass!="-1")
						divs[i].style.display='none';
					else
						divs[i].style.display='';
				else
					if (document.layers) // Netscape 4
						document.layers[divs[i]].style.display = '';
					else // IE 4
						document.all.hideShow.divs[i].style.display = '';				
			}else{				
				s1 = new String(divs[i].id);
				if(s1.search(hiders)>=0){
							divs[i].style.display='none';		
				}
			}
	}
}



/**
 * Prompt user for confirmation prior to loading a URL.
 */
function confirmAction(url, msg) {
	if (confirm(msg)) {
		if (url) {
			document.location.href=url;
		}
		return true;
	}
	return false;
}

/**
 * HACK: Fixed sidebar to avoid double scroll
 */
window.onscroll = function(){
	if( window.XMLHttpRequest ) { // IE 6 doesn't implement position fixed nicely...
		if (document.documentElement.scrollTop > 175) {
			document.getElementById('floatbar').style.position = 'fixed';
			document.getElementById('floatbar').style.top = '0';
		} else {
			document.getElementById('floatbar').style.position = 'relative';
			document.getElementById('floatbar').style.top = 'auto';
		}
	}
}

/**
 * Open window displaying help.
 */
function openHelp(url) {
	window.open(url, 'Help', 'width=700,height=600,screenX=100,screenY=100,toolbar=0,scrollbars=1');
}

/**
 * Open window displaying comments.
 */
function openComments(url) {
	window.open(url, 'Comments', 'width=700,height=600,screenX=100,screenY=100,toolbar=0,resizable=1,scrollbars=1');
}

/**
 * Open window for preview.
 */
function openWindow(url) {
	window.open(url, 'Window', 'width=600,height=550,screenX=100,screenY=100,toolbar=0,resizable=1,scrollbars=1');
}

/**
 * Open window for reading tools.
 */
function openRTWindow(url) {
	window.open(url, 'RT', 'width=700,height=500,screenX=100,screenY=100,toolbar=0,resizable=1,scrollbars=1');
}
function openRTWindowWithToolbar(url) {
	window.open(url, 'RT', 'width=700,height=500,screenX=100,screenY=100,toolbar=1,resizable=1,scrollbars=1');
}

/**
 * browser object availability detection
 * @param objectId string of object needed
 * @param style int (0 or 1) if style object is needed
 * @return javascript object specific to current browser
 */
function getBrowserObject(objectId, style) {
	var isNE4 = 0;
	var currObject;

	// browser object for ie5+ and ns6+
	if (document.getElementById) {
		currObject = document.getElementById(objectId);
	// browser object for ie4+
	} else if (document.all) {
		currObject = document.all[objectId];
	// browser object for ne4
	} else if (document.layers) {
		currObject = document.layers[objectId];
		isNE4 = 1;
	} else {
		// do nothing
	}
	
	// check if style is needed
	if (style && !isNE4) {
		currObject = currObject.style;
	}
	
	return currObject;
}

/**
 * Load a URL.
 */
function loadUrl(url) {
document.location.href=url;	
}

