/**********************************************************************************************************************
File: lib_functions.js
Info: Librería de funciones javascript: capas, mensajes, efectos.... 
Params: 
Security: 
Author: SiPoX 
Version: 1.0 - 21/08/2006 
**********************************************************************************************************************/

// Función que muestra un mensaje pasado como parámetro
function showMessage(message)
{
	alert(message);
}


// Función que oculta / muestra las capas ocultas
function hsLayer(nCapa)
{

	var estado;
	var aux;

	estado = document.getElementById(nCapa).style.display;

	if (estado == "none" || estado == "") document.getElementById(nCapa).style.display="block";
	else if (estado == "block") document.getElementById(nCapa).style.display="none";
	
	//alert(estado);
}		

	
	
// Función que muestra una capa oculta
function showLayer(nCapa)
{
	document.getElementById(nCapa).style.display="block";
}	


// Función que oculta una capa visible
function hideLayer(nCapa)
{
	document.getElementById(nCapa).style.display="none";	
}	


// Función que oculta una capa visible
function hidePopup()
{		
	$("#change_box").fadeOut("slow");
	
	document.getElementById("page").style.opacity="1.0";
	
	if (scrollCachePosition > 0) {
           window.top.scroll(0,scrollCachePosition);
           //Reseteamos la variable scrollCachePosition a 0 para poder ejecutar el script tantas veces sea necesario.
           scrollCachePosition = 0;
       }
}	

function goTop()
{
	window.top.scroll(0,0);
}



function infoBox(layerShow, layerD)
{	
	document.getElementById(layerShow).style.display="block";
	
	if (document.getElementById(layerD) != null) document.getElementById(layerD).style.opacity="0.8";
}


function setOpacity(layer, value)
{
	document.getElementById(layer).style.opacity=value; 	
}


/* Función que pone una mano cuando se pasa el ratón por encima de un div */
function mano(a)
{
	if (navigator.appName=="Netscape")
	{
		a.style.cursor='pointer';
	}
	else
	{
		a.style.cursor='hand';
	}
}


/* Función de redireccionamiento */
function goSection(dir)
{
	this.document.location='index.php?mdl='+dir;
}


function selProfile()
{
	var i;
	
    for (i=0;i<document.selP.type.length;i++)
    {
       if (document.selP.type[i].checked)
          break;
    }
   
    this.document.location='index.php?mdl=registry&p='+this.document.selP.type[i].value;
}


/* Función de redireccionamiento, indicamos mod a activar y modulo de procedencia */
function irMod(mod, mdl)
{	
	this.document.location='lbr/job_change_mod.php?mod_se='+ mod + '&mdl_se='+mdl;
}


function toLayer(layer)
{
	//Effect.ScrollTo(layer);
	$("#" + layer).slideDown("slow");
}


/* Funcion que quita todos los estados de las pestañas */
function QuitarTodos(mod)
{
	document.getElementById("cs_select").style.backgroundImage="url(none)";
	document.getElementById("dod_select").style.backgroundImage="url(none)";
	document.getElementById("tfc_select").style.backgroundImage="url(none)";
	switch (mod)
	{
		case 1:
			document.getElementById("cs_select").style.backgroundImage="url(ntf/cs_select2.gif)";
			document.getElementById("banner").style.backgroundImage="url(ntf/b02.gif)";
			break;
		case 2: 
			document.getElementById("dod_select").style.backgroundImage="url(ntf/dod_select2.gif)";
			document.getElementById("banner").style.backgroundImage="url(ntf/b06.gif)";
			break;
		case 3: 
			document.getElementById("tfc_select").style.backgroundImage="url(ntf/tfc_select2.gif)";
			document.getElementById("banner").style.backgroundImage="url(ntf/b05.gif)";
			break;
		default: document.getElementById("cs_select").style.backgroundImage="url(ntf/cs_select2.gif)";
			break;
	}
}


/* RollOver pestañas mod */
function RollOverMod(mod)
{
	document.getElementById(mod).style.backgroundImage="url(ntf/"+ mod +".gif)";
}


/* RollOut pestañas mod */
function RollOutMod(mod)
{
	document.getElementById(mod).style.backgroundImage="url(none)";		
}


/* Funcion que carga los estilos segun el navegador */
function LoadStyles()
{
	if ((navigator.appName).indexOf("Microsoft")!=-1)
	{
		document.write('<LINK REL="stylesheet" HREF="MMstyleIE.css" TYPE="text/css" >');
	}	
	else
	{
		document.write('<LINK REL="stylesheet" HREF="MMstyleFF.css" TYPE="text/css" >');
	}
}


function loadFriends()
{
	var f;
	
	f = this.document.SF_Film.friends.value;
	
	if (f == 2) 
	{
		genContent('search_ff', 'rqt/search_ff.php');		
	}
	else 
		document.getElementById('search_ff').style.display = "none";
	
	if (f == 3) 
		document.getElementById('search_own').style.display = "none";
	else 
	{		
		genContent('search_own', 'rqt/search_own.php?p=' + f);	
	}
	
	if (f == 0) 
		if (document.getElementById('town2')) document.getElementById('town2').style.display="none";
	else 
		if (document.getElementById('town2')) document.getElementById('town2').style.display="block";
}


function loadTags(id)
{
	var f = this.document.New_Tag.tags_auto.value;
	
	var tags = f.split(", ");
	
	var num = tags.length;
	
	var rest;
	
	if (num == 0) rest = f;
	else rest = tags[num - 1]; 

	genContent('list_of_tags', 'rqt/add_tag_generate.php?id=' + id + '&i=' + rest);	
}

function putTag(id, text)
{
	var f = this.document.New_Tag.tags_auto.value;
	
	if (f.indexOf(",") < 0) 
	{		
		this.document.New_Tag.tags_auto.value = text + ", ";
	}
	else 
	{		
		this.document.New_Tag.tags_auto.value = this.document.New_Tag.tags_auto.value + text + ", ";
	}
	
	this.document.New_Tag.tags.value = this.document.New_Tag.tags.value + "," + id;
	
	this.document.New_Tag.tags_auto.focus();
}

function checkLenght(max)
{
	var f = this.document.FormW.text.value;
	var num = f.length;

	if (num > max) this.document.FormW.text.value = f.substr(0, 1000);	
}

function noBlogResource()
{
	var f;
	
	f = this.document.New_Resource.category.value;
		
	if (f == 12 || f == 14) 
	{
		this.document.New_Resource.resource_id.disabled = false;
		
		if (this.document.New_Resource.resource_id.value != 0) 
		{
			this.document.New_Resource.language.disabled = true;
			this.document.New_Resource.language.value = "default";				
		}
		else 
			this.document.New_Resource.language.disabled = false;	
					
	}
	else
	{
		this.document.New_Resource.resource_id.value = "0";
		this.document.New_Resource.resource_id.disabled = true;
		this.document.New_Resource.language.disabled = false;
	}
	
	
	if (f == 14 && this.document.New_Resource.resource_id.value != 0)
	{
		this.document.New_Resource.url.disabled = true;
		this.document.New_Resource.title.disabled = true;
	}		
	else
	{
		this.document.New_Resource.url.disabled = false;
		this.document.New_Resource.title.disabled = false;
	}
	
}


function addOne(num)
{
	aux=eval('this.document.formBuy.units_' + num + '.value;');
	aux= (aux * 1) + 1;
	
	if (isNaN(aux)) aux = 1;
	
	eval('this.document.formBuy.units_' + num + '.value='+aux+';');
}

function minOne(num)
{
	aux=eval('this.document.formBuy.units_' + num + '.value;');
	aux=(aux * 1) - 1;
	
	if (aux < 1) aux = 0;
	
	if (isNaN(aux)) aux = 1;
	
	eval('this.document.formBuy.units_' + num + '.value='+aux+';');
}


function lTrim(sStr)
{
	while (sStr.charAt(0) == " ")
    sStr = sStr.substr(1, sStr.length - 1);
    return sStr;
}

function rTrim(sStr)
{
     while (sStr.charAt(sStr.length - 1) == " ")

      sStr = sStr.substr(0, sStr.length - 1);

     return sStr;
}

 
function allTrim(sStr)
{
     return rTrim(lTrim(sStr));
}


/**************** POPUP CSS ******************************************/

//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!	

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;
var scrollCachePosition = 0;

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#page").css({
			"opacity": "0.4"
		});
		$("#page").fadeIn("slow");
		$("#change_box").fadeIn("slow");		
		
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#page").fadeOut("slow");
		$("#change_box").fadeOut("slow");
		popupStatus = 0;
		
		if (scrollCachePosition > 0) {
           window.top.scroll(0,scrollCachePosition);
           //Reseteamos la variable scrollCachePosition a 0 para poder ejecutar el script tantas veces sea necesario.
           scrollCachePosition = 0;
       }
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#change_box").height();
	var popupWidth = $("#change_box").width();
	//centering
	$("#change_box").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	

	//document.documentElement.scrollTop;
	//$("#change_box").css({
		//"height": windowHeight
	//});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
		
	//LOADING POPUP
	//Click the button event!
	$(".link_popup").click(function(){
		
		scrollCachePosition = $(window).scrollTop();
		
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
		
		window.top.scroll(0,0);
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupClose").click(function(){
		disablePopup();
	});
	//Click out event!
	//$("#page").click(function(){
		//disablePopup();
	//});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});


//Función que oculta / muestra las capas ocultas
function readMore(id)
{
	var estadon;
	var estador;
	var aux;

	estadon = document.getElementById("nmore_" + id).style.display;
	estador = document.getElementById("rmore_" + id).style.display;

	if (estadon=="none") document.getElementById("nmore_" + id).style.display="block";
	else if (estadon=="block" || estadon=="") document.getElementById("nmore_" + id).style.display="none";
	
	if (estador=="none" || estador=="") document.getElementById("rmore_" + id).style.display="block";
	else if (estador=="block") document.getElementById("rmore_" + id).style.display="none";
	
	//alert(estado);
}		


function showMap(address, z)
{	
	var latlng = new google.maps.LatLng(-34.397, 150.644);
	var myOptions = {			   
				zoom: z,
				mapTypeId: google.maps.MapTypeId.ROADMAP
        		}


	var map = new google.maps.Map(document.getElementById("ewn_map"), myOptions);
		     
	var geocoder = new google.maps.Geocoder();

	geocoder.geocode( { 'address': address}, function(results, status) {
	      if (status == google.maps.GeocoderStatus.OK) {
	        map.setCenter(results[0].geometry.location);
	        var marker = new google.maps.Marker({
	            map: map, 
	            position: results[0].geometry.location
	        });
	        
	        
	      } else {
	        alert("Geocode was not successful for the following reason: " + status);
	      }
	    });	
	
}


