﻿/*******************************************************
* .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);

/*******************************************************
* .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);   
}

/*******************************************************
* .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;
	}
}


/*******************************************************
* 
* 
*******************************************************/

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();
}

/*******************************************************
* 
* 
*******************************************************/

function GetFecha(iDias)
{
	var dFecha = new Date();
	dFecha = new Date(dFecha.getFullYear(),dFecha.getMonth(),dFecha.getDate() + iDias);
	return Date2Str(dFecha);
}

/*******************************************************
* .s. Incrementa una fecha segun sección
* .s. sFecha = dd/mm/aa
* .s. sSeccion	= d -> dia
* .s.			  m -> mes
* .s.			  a -> año
* .s.
* .s. la devolución es dd/mm/aa
*******************************************************/

function AddFecha(sFecha,sSeccion,iIncremento)
{
	iIncremento = parseInt(iIncremento);  	
	var dFecha = Str2Date(sFecha);
				
	switch (sSeccion)
	{
		case "d":
			dFecha = new Date(dFecha.getFullYear(),dFecha.getMonth(),dFecha.getDate() + iIncremento);
			return Date2Str(dFecha);
			break;
		case "m":
			dFecha = new Date(dFecha.getFullYear(),dFecha.getMonth() + iIncremento,dFecha.getDate());
			return Date2Str(dFecha);
			break;
		case "a":
			dFecha = new Date(dFecha.getFullYear() + iIncremento,dFecha.getMonth(),dFecha.getDate());
			return Date2Str(dFecha);
			break;
	}

}

/*******************************************************
* .s. Diferencia de Días
* .s. la devolución son d
*******************************************************/

function DiffFecha(sDesde,sHasta)
{
	var dDesde = Str2Date(sDesde);
	var dHasta = Str2Date(sHasta);
	return parseFloat((dHasta.getTime()- dDesde.getTime())/(86400000),0).toFixed();	
}

/*******************************************************
*
*.s. Dependencia: DiffFecha
*******************************************************/

function CompruebaDesdeHasta(pDesde,pHasta)
{
	if (pDesde == "" || pHasta == "")
		return false;

	if (DiffFecha(pDesde,pHasta) < 0)
		return false;
	
	return true;
}

/*******************************************************
* .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;
}