// JavaScript Document
function LoginIndex(){
	var Usuario = document.frmLogeu.unicoUser.value;
	var Pasword = document.frmLogeu.unicoPass.value;
	goAJAX("BlokeInfo","ajax/login.php", "usu="+Usuario+"&pwr="+Pasword, "LoginPaso();");
}    

function EnviComentarios(){
	var name = document.comment_form.name.value;
	var comentario = document.comment_form.comment_body.value;
	var parent_id = document.comment_form.parent_id.value;
	var descarga = document.comment_form.descarga.value;
	//alert("datos de respuesta: " + name);
	goAJAX("wrapper","ajax/comentarios.php", "&usuario="+name+"&comentario="+comentario+"&parent_id="+parent_id+"&descarga="+descarga,"");
}
      
function LoginPaso(){
	var cualete = document.frmPaso.cualete.value;
	var usuarie = document.frmPaso.usuarie.value;
	if(cualete==1){
		alert('Bienvenido '+usuarie+'!! A disfrutar...');
	}else{
		alert('NICKNAME o PASSWORD incorrecto!! Por favor intentelo nuevamente...');
	}
	location.reload();
}
function Logged(){
	goAJAX('BlokeInfo','ajax/comUs.php', '');
	OcultarVtna();
}

function agregarFav(){
   direc = "http://www.theprincex.com";
   titut = "The Prince X | Descargas de Peliculas y Videos X";
   if ((navigator.appName=="Microsoft Internet Explorer") && (parseInt(navigator.appVersion)>=4)) {
      window.external.AddFavorite(direc,titut);
   } else {
      if(navigator.appName=="Netscape"){
         window.sidebar.addPanel(titut,direc,"");
      }
   }
}
function buskalo(){
	var sStr = document.ForBuska.sStr.value;
	if((sStr=="Buscar")||(sStr.length<=2)){
		alert('Para iniciar la busqueda, introduce un minimo de 3 caracteres!');
		return false;
	}
	sStr = sStr.replace("/", "+");
	sStr = sStr.replace(" ", "+");
	sStr = sStr.replace("20%", "+");
	document.location.href='buscar-'+sStr+'.html';
}

function mostrarOcularEfecto(id){
	if($(id).style.display=='none'){
Effect.Appear(id, { duration: 2.0 });
}else{	
new Effect.BlindUp(id, {duration: 1.0});
}
}

function mostrarOcularEfecto(id){
	if($(id).style.display=='none'){
Effect.Appear(id, { duration: 2.0 });
}else{	
new Effect.BlindUp(id, {duration: 1.0});
}
}

function mostrarOcularFichas(id){
	if($(id).style.display=='none'){
Effect.SwitchOn(id, { duration: 1.0 });
}else{	
new Effect.SwitchOff(id, {duration: 1.0});
}
}

function mostrarOcularEntrevistas(id){
if($(id).style.display=='none'){
Effect.BlindDown(id, { duration: 1.0 }); 
}else{	
new Effect.BlindUp(id, {duration: 1.0}); 
}
}


///////////////////////////////////////////// Agrandara el tamaņo del texarea sin dejar mostrar el barra 
// http://jroller.com/rmcmahon/entry/resizingtextarea_with_prototype
// Usage: <% apply_behaviour "textarea", "new ResizingTextArea(this);" %>
 
var ResizingTextArea = Class.create();
 
ResizingTextArea.prototype = {
    defaultRows: 1,
    initialize: function(field)
    {
        this.defaultRows = Math.max(field.rows, 1);
        this.resizeNeeded = this.resizeNeeded.bindAsEventListener(this);
        Event.observe(field, "click", this.resizeNeeded);
        Event.observe(field, "keyup", this.resizeNeeded);
    },
 
    resizeNeeded: function(event)
    {
        var t = Event.element(event);
        var lines = t.value.split('\n');
        var newRows = lines.length + 1;
        var oldRows = t.rows;
        for (var i = 0; i < lines.length; i++)
        {
            var line = lines[i];
            if (line.length >= t.cols) newRows += Math.floor(line.length / t.cols);
        }
        if (newRows > t.rows) t.rows = newRows;
        if (newRows < t.rows) t.rows = Math.max(this.defaultRows, newRows);
    }
}
function activarCampo(id){
get(id).disabled="";
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

ocument.observe("dom:loaded", function() {

	// we get all elements with a class set to 'expand'.
	var elements = $$('.expand');
	// size() uses the array's native length property
	// if the array has more than 0 items, we do the loop
	if (elements.size() > 0) {
		for (var index = 0, length = elements.size(); index < length; ++index)	{
			autoExpandContract(elements[index]);
		}
	}
	
	
	function getStyleFromCSS(el, style) {
	
		// get styles from our CSS
		var value = $(el).getStyle(style);
		
		// if styles are not defined in our CSS
		if(!value) {
		
			// for other browsers. Actually this equals 'window'. Use that if Opera fails on you.
			if(document.defaultView) {
				//	getComputedStyle() requires two parameters. 
				//		The first is a reference to the element. 
				//		The second is either the name of a pseudo element ('before', 'after', 'first-line'), 
				//		or null just for the element itself
				// getPropertyValue() 
				//		returns the value of the property if it has been set. 
				// 		Returns an empty string if the property has not been set.
				value = document.defaultView.getComputedStyle(el, null).getPropertyValue(style);
				
		   // for IE
			} else if(el.currentStyle) {
				//	As well as being an actual usable value, 
				//	the returned value for several styles may be their 
				// 	default values, such as 'auto', 'normal', 'inherit',...
				value = el.currentStyle[style];
				if (value.substring(value.length-2,value.length) == "px") {
					alert('style' + style);
					value = value+'px';
				}
			}
		}
		
		// if the value we got from our element has more than 0 characters...
		if(value.length > 0){
		
			// if the value returned has the word px in it, we check for the letter x
			if (value.charAt(value.length-1) == "x") {
			
				// substring()
                //	get all characters from the 0th place to the total String length - 2
				// parseInt() 
                //	Only the first number in the string is returned! 
                //  Leading and trailing spaces are allowed.
				//  If the first character cannot be converted to a number, parseInt() returns NaN.
				value = parseInt(value.substring(0,value.length-2)) 
			} 
		}
		return value;	
	
	} // end getStyleFromCSS()

	function autoExpandContract(el) {

		// get height of the element
		var __heightFromElement = el.offsetHeight;
		
		// get height of the element set in the styles
		var __heightFromCSS = parseInt(getStyleFromCSS(el, 'height'));
		
		// If the height style is set in the CSS and it's bigger than 0px, resize the element to that height
		if (__heightFromCSS > 0) {
			__heightFromElement = __heightFromCSS;
		}

		// adjust the textarea, for all good browsers: overflow:hidden to lose the scrollbars, 
		// for IE use overflowX:auto to let that browser decide whether to show scrollbars
		$(el).setStyle({overflow: 'hidden', overflowX: 'auto'});
		
		// set the width and height to the correct values
		el.style.width = getStyleFromCSS(el, 'width')+'px';
		el.style.height = getStyleFromCSS(el, 'height')+'px';
		
		// create a new element that will be used to track the dimensions
		var dummy_id = Math.floor(Math.random()*99999) + '_dummy';
		var div = document.createElement('div');
		
		// we use setAttribute() here instead of writeAttribute which is a prototype method due to IE6
		div.setAttribute('id',dummy_id);
		document.body.appendChild(div);
		var dummy = $(dummy_id);
	
		// match the new elements style to the el
		dummy.style.fontFamily = getStyleFromCSS(el, 'font-family');
		dummy.style.fontWeight = getStyleFromCSS(el, 'font-weight');
        dummy.style.fontSize = getStyleFromCSS(el, 'font-size')+'px';
        
        // fornicate with IE (not a check for IE7 though, just IE6)
        if (navigator.userAgent.indexOf('MSIE') !=-1) {
            dummy.style.width = getStyleFromCSS(el, 'width');
            
        // Play  nice with the good browsers
        } else {
            dummy.style.width = getStyleFromCSS(el, 'width')+'px';
        }
        dummy.style.padding = getStyleFromCSS(el, 'padding');
        dummy.style.margin = getStyleFromCSS(el, 'margin');
		dummy.style.overflowX = 'auto';
		// hide the created div away
		dummy.style.position = 'absolute';
		dummy.style.top = '0px';
		dummy.style.left = '-9999px';
		dummy.innerHTML = ' 42';
		
		var __lineHeight = dummy.offsetHeight;
		
		var checkExpandContract = function(){
			// place text inside the element in a new var called html
			var html = el.value;
			html = html.replace(/\n/g, '<br>');
			if (dummy.innerHTML != html) {
				dummy.innerHTML = html;
				var __dummyHeight = dummy.offsetHeight;
				var __elHeight = el.offsetHeight;
				
				// if the height from our element is not the same as the height from our dummy we just made...
				// example: 150px != 250px
				if (__elHeight != __dummyHeight) {
				
					// example: 250px > 200px					
					if (__dummyHeight > __heightFromElement) {
					
						// example: height = (250+0)px
						el.style.height = (__dummyHeight+__lineHeight) + 'px';
					} else {
						el.style.height = __heightFromElement+'px';
					}
				}
			}
		}
		
		var expandElement = function()	{
			interval = window.setInterval(function() {checkExpandContract()}, 250);
		}
		
		var contractElement = function() {
			clearInterval(interval);
		}
		
		// Put eventListeners to our elements 	
		$(el).observe('focus', expandElement);
		$(el).observe('blur', contractElement);
		checkExpandContract();
	} // end autoExpandContract()
});

