/***************************/
//@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 popupMsjStatus = 0;

//loading popup with jQuery magic!
function loadPopupMsj(){
	//loads popup only if it is disabled
	if(popupMsjStatus==0){
		$("#msjForm").html( $("#msjFormDummy").html() ) ;
		$("#msjForm").fadeIn("slow");
		popupMsjStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopupMsj(){
	//disables popup only if it is enabled
	if(popupMsjStatus==1){
		$("#msjForm").fadeOut("slow");
		popupMsjStatus = 0;
	}
}

//centering popup
function centerPopupMsj(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#msjForm").height();
	var popupWidth = $("#msjForm").width();

//alert(screen.width);
//alert($("#popupWindow").width());
//alert((screen.width-popupWidth)/2);
		//centering
	$("#msjForm").css({
		"position": "absolute",
		"top": (windowHeight/2-popupHeight/2),
		"left": (screen.width - popupWidth)/2
	});
	//only need force for IE6

}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){

	//LOADING POPUP
	//Click the buttonPopup event!
	$("#buttonPopup").click(function(){
		//centering with css
		centerPopupMsj();
		//load popup
		loadPopupMsj();
	});

	//CLOSING POPUP
	//Click the x event!
	$("#popupMsjPubClose").click(function(){
		disablePopupMsj();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupMsjStatus==1){
			disablePopupMsj();
		}
	});

});

/*
* Mensaje nuevo
*/

function msjAjaxRequest(url) {
	$('#workingMsjs').html('<img src="wp-content/themes/default/images/indicator.gif" border="0">');
    $('#msjForm').load(url, "",
        function(responseText, textStatus, XMLHttpRequest) {
            if(textStatus == 'error') {
                $('#msjsContenedor').html('<p>Ocurri&oacute; un error al obtener la informaci&oacute;n</p>');
            }
        }
    );

}
function msjAjaxPostNuevo(url, paraId, msjTxt) {
	//alert("accion=respmsj&msjid="+msjId+"&msjtxt="+msjTxt);
	$.ajax({
		type: "POST",
		url: url,
		data: "accion=envmsj&paraid="+paraId+"&msjtxt="+msjTxt,
		success: function(data){
			if( data!='session expired' ) {
				$('#msjForm').html(data);
			} else {
				alert("La sesion ha expirado, por favor ingresa de nuevo a tu cuenta");
				window.location.reload(true);
			}
		}
	});
}