﻿/*******************************************************
* .s. Extends de Prestige de JQUERY
* 
*******************************************************/

var PrestigeJS = 
{
	//.s. Dialogo en medio doc
	dialog : function(speed)
	{
		$(this).centerInDocument();
		$(this).show(speed);
	},
	
	/**************************************/
	//.s. Centra obj en doc
	/**************************************/
	
    centerInDocument : function()
    {
		$(this).css("position","absolute");
		
		$(this).css("left",(document.body.clientWidth / 2) - ($(this).outerWidth() / 2));
		$(this).css("top",(document.body.clientHeight / 2) - ($(this).outerHeight() / 2));	
		
		return $(this);
    },
    
    /**************************************/
	//.s. Para los checkbox
	/**************************************/
    
    checked : function (pbool)
    {
		if (pbool == null)
			return $(this).is(":checked");
		
		$(this).attr("checked",pbool);
		return $(this);
    },
    
     /**************************************/
	//.s. Ed's disabled
	/**************************************/
	disabled : function (pbool)
	{
		if (pbool == null)
			return $(this).is(":disabled");
		
		if (pbool)
			$(this).attr("disabled",true);
		else
			$(this).removeAttr("disabled");
		return $(this);
	}
};
//.s. Aplico Extends
(function($){ $.fn.extend(PrestigeJS) })(jQuery);


	


/*******************************************************
* 
*******************************************************/

var glData;

//.s. intento instanciar el engine
try
{
	glData = parent.vEngine;
}
catch(e)
{
	//.s. Sino espero intervención manual
}

/*******************************************************
* .s Error en la petición
* 
*******************************************************/

function OnReqError(result)
{
    ProgressOff();
    
    str = "Prestige Software:\n\nSe ha producido un error en la petición:\n\n";
    
    if (result.get_exceptionType)
		str += "Excepción:" + result.get_exceptionType() + "\n";
	
	if (result.get_message)
		str += "Mensanje:" + result.get_message() + "\n";
	
	alert (str);   

}

/*******************************************************
* .s. Timeout
*******************************************************/

function OnTimeout(result)
{
    ProgressOff();
    
    str = "Prestige Software:\n\nSe ha superado el tiempo de espera de respuesta.";
	
	alert (str);   
}

/*******************************************************
* 
*******************************************************/

function MaxInput(oImput,iSize)
{
	if(oImput != ""){
		if($(oImput)!=null){
			iSize = parseInt(iSize);
			sText = $(oImput).value;
 	
			if (sText.length >iSize)
				$(oImput).value = sText.substr(0,iSize)
		}
	}
}

/*******************************************************
* .s Es un número. Admite decimales
* 
*******************************************************/

function IsNumber(pValor)
{
	if (pValor == "") {return false; }
	
	return 	isNaN(iVal(pValor)) ? false : true
}

/*******************************************************
* .s Establece el decimal
* 
*******************************************************/

function iVal(pValor)
{
	if (pValor == "") {return 0;}
	
	PuntoComa = (1 / 2);
	PuntoComa = String(PuntoComa).substr(1,1);
	
	pValor = String(pValor).replace(/[,.]/,PuntoComa);
	
	return pValor;
}

/*******************************************************
 * 
 * .s. Convierte en datetime fechas string en formato dd/mm/aa
 * 
 *******************************************************/

function Str2Date(sDate)
{
    
	iYear	= 2000 + parseFloat(sDate.substr(6,2));
	iMes	= sDate.substr(3,2) - 1;
	iDia	= parseFloat(sDate.substr(0,2))
	
	return new Date(iYear,iMes,iDia);
}

/*******************************************************
 * 
 * .s. Devuelve dd/mm/aa
 * 
 *******************************************************/

function Date2Str(fDate)
{
	var sDia;
	sDia = fDate.getDate() > 9 ? fDate.getDate() : "0" + fDate.getDate();

	var sMes;
	sMes = fDate.getMonth()+1 > 9 ? fDate.getMonth()+1 : "0" + (fDate.getMonth()+1);
	
	var sAno;
	sAno = fDate.getFullYear().toString().substr(2, 2);
	
	return sDia + "/" + sMes + "/" + sAno;

}

/*******************************************************
 * 
 * .s. 
 * 
 *******************************************************/
 
function InfoShow(sTxt)
{
	if (document.getElementById("divInfo"))
	{
		document.body.removeChild(document.getElementById("divInfo"));
	}	
	
	shtml = "<div class='InfoShow_Title'>&nbsp;Información</div>";
	shtml += "<table border='0' cellpadding='5' cellspacing='0' align='left'>";
	shtml += "<tr><td><img src='_Images/Warning32x32.png' /></td>";
	shtml += "<td class='InfoShow_Txt'>" + sTxt + "</td></tr>";
	shtml += "</table>";
	shtml += "<br /><br /><br />";
	
	var oDivInfo = document.createElement("DIV");
	document.body.appendChild(oDivInfo);
	oDivInfo.style.position	= "absolute";
	oDivInfo.id				= "divInfo";
	oDivInfo.className		= "InfoShow_Dv";
	oDivInfo.style.width	= "350px";
	oDivInfo.innerHTML = shtml;
	
	oDivInfo.style.left		= (document.body.clientWidth / 2) - (oDivInfo.offsetWidth / 2) + "px";
	oDivInfo.style.top		= (document.body.clientHeight / 2) - (oDivInfo.offsetHeight / 2) + "px";
	
	oDivInfo.onmousedown = function()
	{
		document.body.removeChild(document.getElementById("divInfo"));
		document.onmousedown = null;
	}
	
	document.onmousedown = function()
	{
		document.body.removeChild(document.getElementById("divInfo"));
		document.onmousedown = null;
	}
}

/*******************************************************
* .p.
* 
*******************************************************/
function InfoShowCorrect(sTxt)
{
	if (document.getElementById("divInfo"))
	{
		document.body.removeChild(document.getElementById("divInfo"));
	}	
	
	shtml = "<div class='InfoShow_Title' >&nbsp;Información</div>";
	shtml += "<table border='0' cellpadding='5' cellspacing='0' align='left'>";
	shtml += "<tr><td><img src='_Images/check2.gif' /></td>";
	shtml += "<td class='InfoShow_Txt'>" + sTxt + "</td></tr>";
	shtml += "</table>";
	shtml += "<br /><br /><br />";
	
	var oDivInfo = document.createElement("DIV");
	document.body.appendChild(oDivInfo);
	oDivInfo.style.position	= "absolute";
	oDivInfo.id				= "divInfo";
	oDivInfo.className		= "InfoShow_Dv";
	oDivInfo.style.width	= "300px";
	oDivInfo.innerHTML = shtml;
	;

	oDivInfo.style.left		= (document.body.clientWidth / 2) - (oDivInfo.offsetWidth / 2) + "px";
	oDivInfo.style.top		= (document.body.clientHeight / 2) - (oDivInfo.offsetHeight / 2) + "px";
	
	oDivInfo.onmousedown = function()
	{
		document.body.removeChild(document.getElementById("divInfo"));
		document.onmousedown = null;
	}
	
	document.onmousedown = function()
	{
		document.body.removeChild(document.getElementById("divInfo"));
		document.onmousedown = null;
	}


}

/*******************************************************
* 
* 
*******************************************************/

function ProgressOn(sMensaje)
{
	if (!document.body){ return; }
	
	if ($("#dvProgress").length > 0)
		var oDivProgress = $("#dvProgress");
	else
	{
		var oDivProgress  = $("<div id='dvProgress'></div>");
		$("body").append(oDivProgress);
	}
	
	shtml = "<div class='content'><div class='head'>Espera...</div>";
	shtml += "<div class='body'>";
	shtml += "<img src='_Images/loadinfo.net.gif' align='absmiddle' />" + sMensaje;
	shtml += "</div></div>";
	
	oDivProgress.html(shtml);
	oDivProgress.centerInDocument();
}

/*******************************************************
* 
* 
*******************************************************/

function ProgressOff()
{
	if ($("#dvProgress").length > 0)
		$("#dvProgress").remove();
}

/*******************************************************
* 
* 
*******************************************************/



/*******************************************************
* .s. Recoge el value de los checks seleccionados.
* .s. Requiere q se establezca el value.
* .s. El partialid de los checks valido
* .s. Dependencias JQuery
*******************************************************/

function GetChChurro(PartialId)
{
	sChurro = "";
	$(":checkbox[id^='" + PartialId + "']:checked").each(function()
	{
		sChurro += $(this).attr("value") + "#";
	});
	return sChurro;
}


/*******************************************************
 * 
 * .p. 
 * 
 *******************************************************/
 
function InfoShowEn(sTxt)
{
	if (document.getElementById("divInfo"))
	{
		document.body.removeChild(document.getElementById("divInfo"));
	}	
	
	shtml = "<div class='InfoShow_Title'>&nbsp;Information</div>";
	shtml += "<table border='0' cellpadding='5' cellspacing='0' align='left'>";
	shtml += "<tr><td><img src='_Images/Warning32x32.png' /></td>";
	shtml += "<td class='InfoShow_Txt'>" + sTxt + "</td></tr>";
	shtml += "</table>";
	shtml += "<br /><br /><br />";
	
	var oDivInfo = document.createElement("DIV");
	document.body.appendChild(oDivInfo);
	oDivInfo.style.position	= "absolute";
	oDivInfo.id				= "divInfo";
	oDivInfo.className		= "InfoShow_Dv";
	oDivInfo.style.width	= "350px";
	
	//oDivInfo.innerHTML = "<span style='float:left;padding:10px;display:inline' class='divInfoTxt'>" + sTxt + "</span>";
	oDivInfo.innerHTML = shtml;
	
	//if (oDivInfo.offsetWidth < 225)
	//	oDivInfo.style.width = "225px";
	
	//oDivInfo.style.height	= "56px";
	oDivInfo.style.left		= (document.body.clientWidth / 2) - (oDivInfo.offsetWidth / 2) + "px";
	oDivInfo.style.top		= (document.body.clientHeight / 2) - (oDivInfo.offsetHeight / 2) + "px";
	
	oDivInfo.onmousedown = function()
	{
		document.body.removeChild(document.getElementById("divInfo"));
		document.onmousedown = null;
	}
	
	document.onmousedown = function()
	{
		document.body.removeChild(document.getElementById("divInfo"));
		document.onmousedown = null;
	}
}

/*******************************************************
 * 
 * .p. 
 * 
 *******************************************************/


    function ChangeIconMenu()
    {
    
        //.p. para sustituir los iconos del menu superior
        $("#dvMenuSuperior img").each(function()//.p. para poder repintar el contendor al pasar el mouse
        {   
            if($(this).attr("fixed")!= "yes"){
            
            
                $(this).hover(
                   
                    function(){ $(this).attr("src","Images/bt_"+$(this).attr("name")+"_Hover.png") },
                    
                    function(){
                                     if($(this).attr("fixed")!= "yes")
                                     { 
                                        $(this).attr("src","Images/bt_"+$(this).attr("name")+".png")
                                     }
                              }
                );
                
            } 
                
            
        }); 
        
        //.p. para sustituir los iconos del submenu
         $("#dvMenuInfo  img").each(function(){
         
         
         
                                $(this).hover(
                                    
                                    function(){ $(this).attr("src","../Images/bt_"+$(this).attr("name")+"_Hover.png") },
                                    
                                    function(){
                                                     if($(this).attr("fixed")!= "yes")
                                                     { 
                                                        $(this).attr("src","../Images/bt_"+$(this).attr("name")+".png")
                                                     }
                                              }
                                );
         
         
                                $(this).click( 
                                    
                                    function(){
                                                      $("#dvMenuInfo  img").each(     function(){  
                                                                                                        $(this).attr("src","../Images/bt_"+$(this).attr("name")+".png"); 
                                                                                                        $(this).attr("fixed","no");
                                                                                                    });
                                                                
                                                        $(this).attr("fixed","yes"); 
                                                        $(this).attr("src","../Images/bt_"+$(this).attr("name")+"Hover.png");
                                                                     
                                                }); 
                        });
                                                    
    }
