/*
 * Fremex JavaScript Library v1.3
 *
 * Date: 2009-02-06 08:48:00
 * Version: 1.0
 */


/**
* Abre una ventana
* @param string url Dirección de destino
* @param integer w Ancho de la ventana
* @param integer h Alto de la ventana
* @param string  pr Parámetros
* @param string  nm Nombre
*/
function oW(url,w,h,pr,nm){
	var top=(parseInt(oEx.height())-h)/2;
	var left=(parseInt(oEx.width())-w)/2;
	var p="top="+top+",left="+left+",width="+w+",height="+h;
	if(pr!=undefined) p=p+","+pr;
	if(nm!=undefined) nm="";
	window.open(url,nm,p);
}



/**
* Abre una direccion directamente, preferiblemente ficheros
* @param string url Dirección de destino
*/
function oF(url){ window.open(url,"",""); }

/**
* Redirecciona a una direccion
* @param string url Dirección
* @param id marco de destino
*/
function goUrl(url,id){
	if(id!=undefined)
		window.location.href=url;
	else
		window.location.href=url;
}

var windowOpen=false;

var oEx={
	show:function(t,w,h,file,func){
		var e=$("#win");
		if(!e){ return; }
		e.height(h).width(w);
		e.css("position","absolute");
		e.css("top",(parseInt(this.height())/2)+(parseInt(this.scrollHeight()))+"px");
		e.css("left","50%");
		e.css("marginTop",(-parseInt(h/2))+"px");
		e.css("marginLeft",-parseInt(w/2)+"px");
		e.css("z-index","1000");
		$("#whtml").height(h-70);
		//Título ventana
		$("#cbar").html(t);

		//Mostramos las capas y la opacidad
		this.opacity();
		e.fadeIn("fast");
		if(file!=""){
			$("#whtml").html("<div class='aviso'>"+imgLoad+" cargando</div>");
			$("#whtml").load(file,function(){
				if(func!=undefined){ eval(func+"()"); }
			});
		}
		windowOpen=true;
	},

	close:function(){
		var e=$("#win");
		if(e){ e.fadeOut("fast"); }
		$("#Lopacity").hide();
		windowOpen=false;
	},

	opacity:function(){
		var e=$("#Lopacity");
		if(!e){
			var newE=document.createElement("div");
			newE.id="Lopacity";
			document.body.appendChild(newE);
			e=$("#Lopacity");
		}

		e.css("position","absolute");
		e.css("zIndex","999");
		e.css("top","0");
		e.css("left","0");
		e.height(parseInt(this.realHeight())); e.width(parseInt(this.realWidth()));
		e.css("background-color","#3b3b38");
		e.css("filter","alpha(opacity=80)");
		e.css("opacity","0.8");
		e.show();
		if($.browser.msie )	this.iframeOpacity();
	},
	iframeOpacity:function(){
		var e=$("#iframeOpa");
		if(!e){
			var newE=document.createElement("iframe");
			newE.id="iframeOpa";
			document.body.appendChild(newE);
			e=$("#iframeOpa");
		}
		e.css("position","absolute");
		e.css("zIndex","998");
		e.css("top","0");
		e.css("left","0");
		e.height(parseInt(this.realHeight())); e.width(parseInt(this.realWidth()));
		e.css("filter","progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)");
		e.show();
},

	height:function(){
		if(window.innerHeight){
			return window.innerHeight;
   		}else if(document.body.parentElement.clientHeight){
			return document.body.parentElement.clientHeight;
		}else if(document.body && document.body.clientHeight){
			return document.body.clientHeight;
		}
		return 0;
	},
	width:function(){
		if (window.innerWidth) {
       		return window.innerWidth;
   		}else if (document.body.parentElement.clientWidth){
			return document.body.parentElement.clientWidth;
		}else if (document.body && document.body.clientWidth) {
       		return document.body.clientWidth;
		}
   		return 0;
	},
	realHeight:function(){
		var y=0;
		var y1=document.body.offsetHeight;
		var y2=parseInt(this.height());
		(y1>y2)?y=y1:y=y2;
		return y;
	},
	realWidth:function(){
		var x=0;
		var x1=document.body.offsetWidth;
		var x2=parseInt(this.width());
		(x1>x2)?x=x1:x=x2;
		return x1;
	},
	scrollHeight:function(){
		var sh=0;
		if(document.body && typeof(document.body.scrollTop)!="undefined"){
   			sh += document.body.scrollTop;
			if(document.body.parentNode&&typeof(document.body.parentNode.scrollTop)!="undefined"){
				sh += document.body.parentNode.scrollTop;
			}
 		}else if(typeof(window.pageYOffset)!="undefined"){
			sh += window.pageYffset;
    	}
		return sh;
	},
	scrollWidth:function(){
		var sw=0;
		if(document.body && typeof(document.body.scrollLeft)!="undefined"){
    		sw += document.body.scrollLeft;
			if(document.body.parentNode&&typeof(document.body.parentNode.scrollLeft)!="undefined"){
				sw += document.body.parentNode.scrollLeft;
			}
    	}else if(typeof(window.pageXOffset)!= "undefined"){
			sw += window.pageXOffset;
    	}
		return sw;
	}
};

var urlLogin=u+"app/validation/";


function sendLogin(){

	var url=urlLogin+"login.php";
	var param=$("#flogin").serialize();
	$("#pentrar").after("<span id='load' class='loading'>"+imgLoad+" enviado</span>");
	$.ajax({
		type: "post",
		url:  urlLogin+"login.php",
		data: $("#flogin").serialize(),
		complete: function(request){
			var json=eval("("+request.responseText+")");
			if(json.status){
				window.location.href=json.url;
			}else{
				$("#msnLogin").show().html(json.message);
				$("#pwd").value="";
			}
			$("#load").remove();
		}
	});
}

function showRecordar(){
	$("#Lentrar").hide();
	$("#linkr").hide();
	$("#linki").show();
	$("#Lrecordar").show();
	$("#msnLogin").hide();
	$("#msn").html("");
}


function showIdentifi(){
	$("#Lentrar").show();
	$("#linkr").show();
	$("#linki").hide();
	$("#Lrecordar").hide();
	$("#msnLogin").hide();
	$("#msn").html("");
}


function reloadCaptcha(){
	$('#captcha').attr('src',u+'includes/controls/securimage/securimage_show.php?' + Math.random());
}




