/**
 * 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 $
 */

/**
 * 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;
}

/**
 * Open window displaying help.
 */
function openHelp(url) {
	window.open(url, 'Help', 'width=770,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;	
}

function idioma(){
	i=0;
	x="";
	while(i<document.getElementById("idioma").options.length){
		if(document.getElementById("idioma").options[i].selected){
			document.write(document.getElementById("idioma").options[i].label+" ");
		}
		i++;
	}				
}
function toggle(){
	
	if(document.getElementById("idiomas").style.display=="none"){
		document.getElementById("idiomas").style.display="block";
		//alert(document.getElementById("idiomas").style);	
	}
	else{
		//alert(document.getElementById("idiomas").style.display);
		document.getElementById('idiomas').style.display="none";
	}
}
function idiomas(){
	i=0;	
	var ur=location.href;	
	final=ur.length-1;
	ur3=ur.substr(0,ur.indexOf("/",ur.search("index.php/"))+1);
	ur=ur.substr(ur.indexOf("/",ur.search("index.php/"))+1);	
	if(ur.indexOf("/")>0){
		final=ur.indexOf("/");
	}
	ur4=ur3.concat(ur.substr(0,final));
	//alert(ur4);
	/*if(location.href.match(/\?/)){
		ur+="&";		
	}
	else{
		ur+="?";
	}*/
	//ur+="source=";
	//alert(ur);s
	while(i<document.getElementById("idioma").options.length){
		if(!document.getElementById("idioma").options[i].selected){
			//document.write("<span>"+document.getElementById("idioma").options[i].label+"</span><br />");						
			//document.write("<span onclick='location.href=&quot;"+str+"en_US?source="+ur+"&quot;'>go</span>");
			//url="{url page='user' op='setLocale' path='en_US' source=$smarty.server.REQUEST_URI escape=false}";
			document.write('<a href="'+ur4+'/user/setLocale/'+document.getElementById("idioma").options[i].value+'?source=%2F'+ur4+'">'+document.getElementById("idioma").options[i].label+' </a>');
		}
		i++;
	}			
}