


/*
		Changes the visibility of a given DIV according of its
	current state
*/
function changeDivDisplay(divName)
{
   div = document.getElementById(divName);
   
   if (div.style.display == "block")
   		div.style.display = "none";
   else
        div.style.display = "block";

}


/*
	Changes the visibility of a DIV to hidden
*/
function hideDiv(divName) 
{
	document.getElementById(divName).style.display = "none";
}


/*
	Changes the visibility of a DIV to visible
*/
function showDiv(divName) 
{
	document.getElementById(divName).style.display = "block";
}





/*
	Opens a popup window, configurated through method's parameters
	
	Example call: 
	
	<input type="button" onclick="openWindow('page.htm',0,1,1,1,1,1,1,100,100,100,100,1);" 
		value="Open popup window">
*/
function openWindow(direction, fullScreen, toolBar, locations, status, menuBar, scrollBar, changeSize, 
	width, height, left, top, change)
{
     var options = "fullscreen=" + fullScreen +
                 ",toolbar=" + toolBar +
                 ",location=" + locations +
                 ",status=" + status +
                 ",menubar=" + menuBar +
                 ",scrollbars=" + scrollBar +
                 ",resizable=" + changeSize +
                 ",width=" + width +
                 ",height=" + height +
                 ",left=" + left +
                 ",top=" + top;
                 
     var v = window.open(direction,"window",options,change);
}                     





/* Returns the value of the given url param */
function getUrlParamValue( name )
{
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href );
	
	if( results == null )
		return "";
	else
		return results[1];
}
		
		
		


/*
	Switch stylesheet to the print-preview related
*/
function print_preview() 
{

	content = $("<html></html>");
	head = $("<head><link rel='StyleSheet' href='./css/print-publications.css' type='text/css' media='screen' title='Print Preview'><link rel='shortcut icon' href='./img/favicon.ico'/></head>");
	
	body = $("<body>"+$('.content').html()+"</body>");
	
	content.append(head);
	content.append(body);
	
	$('a', content).each(function() {
		 texto = $(this).text();
		 $(this).replaceWith(texto);
	});
	
	ventimp = window.open('');
	ventimp.document.open("text/html", "replace")
	ventimp.document.write(content.html());
	ventimp.document.close();
}

function print_preview_onlyBio() 
{
	
	content = $("<html></html>");
	head = $("<head><link rel='StyleSheet' href='./css/print-publications.css' type='text/css' media='screen' title='Print Preview'><link rel='shortcut icon' href='./img/favicon.ico'/></head>");
	$(".cvnlink").css("display","none");
	var temp = $("#researcherweb").html();
	$("#researcherweb").html($("#researcherweb").html()+" : "+$("#researcherweb").attr('href'));
	$(".print").css("display","none");
	$(".elementoFotoAncho").css("width","700px");
	$(".enlaceDer").css("display","none");
	
	body = $("<body>"+$('.elementoFotoAncho').html()+"</body>");
	
	content.append(head);
	content.append(body);
	
	$('a', content).each(function() {
		 texto = $(this).text();
		 $(this).replaceWith(texto);
	});
	
	ventimp = window.open('');
	ventimp.document.open("text/html", "replace")
	ventimp.document.write(content.html());
	ventimp.document.close();
	$("#researcherweb").html(temp);
	$(".cvnlink").css("display","inline");
	$(".elementoFotoAncho").css("width","100%");
	$(".print").css("display","inline");
	$(".enlaceDer").css("display","inline");
}


function print_preview() 
{

	content = $("<html></html>");
	head = $("<head><link rel='StyleSheet' href='./css/print-publications.css' type='text/css' media='screen' title='Print Preview'><link rel='shortcut icon' href='./img/favicon.ico'/></head>");
	$(".cvnlink").css("display","none");
	$(".print").css("display","none");
	$(".enlaceDer").css("display","none");
	$(".elementoFotoAncho").css("width","700px");
	var temp = $("#researcherweb").html();
	$("#researcherweb").html($("#researcherweb").html()+" : "+$("#researcherweb").attr('href'));
	body = $("<body>"+$('.content').html()+"</body>");
	
	content.append(head);
	content.append(body);
	
	$('a', content).each(function() {
		 texto = $(this).text();
		 $(this).replaceWith(texto);
	});
	
	ventimp = window.open('');
	ventimp.document.open("text/html", "replace")
	ventimp.document.write(content.html());
	ventimp.document.close();
	$("#researcherweb").html(temp);
	$(".cvnlink").css("display","inline");
	$(".elementoFotoAncho").css("width","100%");
	$(".print").css("display","inline");
	$(".enlaceDer").css("display","inline");
}
/*
	Toggles disabled all stylesheets in the document, but
	reactivate the given one to maintain it active
*/
function setActiveStyleSheet(title) 
{
   var i, a, main;
   for(i=0; (a = document.getElementsByTagName("link")[i]); i++) 
   {
     if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) 
     {
       a.disabled = true;
       if(a.getAttribute("title") == title) 
       	a.disabled = false;
     }
   }
}



/*
	Goes back to the last page in the history 
*/
function goBack()
{
	history.go(-1);
}


function addNewSubject(){
	var html = "";
	var num = $(".subjectField").length;
	html+="<div class=\"field subjectField\">";
	html+="<div class=\"label\">"; 
	html+=$(".subjectField").first().find(".label").html();
	html+="</div>";
	html+="				<select id=\"subjectId"+num+"\" name=\"subjectId["+num+"]\">";
	$.each($("#subjectId0").find("option"), function( index, value ) {
		  html += value.outerHTML;
		});
	html+="				</select>";
	html+="			</div>";
	
	$(".subjectField").last().after(html);
}


function addNewProject(){
	var html = "";
	var num = $(".projectField").length;
	html+="<div class=\"field projectField\">";
	html+="<div class=\"label\">"; 
	html+=$(".projectField").first().find(".label").html();
	html+="</div>";
	html+="				<select style=\"max-width:389px\" id=\"projectId"+num+"\" name=\"projects["+num+"]\">";
	$.each($("#projects0").find("option"), function( index, value ) {
		  html += value.outerHTML;
		});
	html+="				</select>";
	html+="			</div>";
	
	$(".projectField").last().after(html);
}


