﻿//.s.

var bDebug = true;


/*******************************************************
* .s. GE = getElementById
*******************************************************/

function $(sId)
{
	if (document.getElementById(sId))
		return document.getElementById(sId);
	else
		return null;   //.s Para que si no existe el obj, no pete
	
}

/*******************************************************
* .s Error en la petición
* 
*******************************************************/

function OnReqError(result)
{
    ProgressOff();
    
    str = "Prestige Software - Control de Errores.\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 Error en el script
* 
*******************************************************/

if (!bDebug)
	window.onerror = ControlErrorScript;

function ControlErrorScript(msg,url,linenumber)
{
	if (!bDebug)
	{
		ProgressOff();
		str = "Prestige Software - Control de Errores.\n\nSe ha producido un error en la aplicación:\n\n";
		str += "Mensaje: " + msg + "\n";
		str += "URL: " + url + "\n";
		str += "Línea: " + linenumber + "\n";
		
		alert(str);
		return true;
	}
}

/*******************************************************
 * 
 * 
 *******************************************************/

function OnTimeout()
{
	ProgressOff();
	
	alert ("Parece que no existe comunicación con el servidor.\nInténtalo más tarde o revisa tu conexión.")
}


/*******************************************************
* 
* 
*******************************************************/

function _Posicion(obj)
{
	var Punto = new Object();
	
	Punto.x = 0;
	Punto.y = 0;

	//while (obj.tagName != "BODY")
	while (obj.offsetParent)
	{
		Punto.x += obj.offsetLeft;
		Punto.y += obj.offsetTop;
		
		obj = obj.offsetParent;
	}
	
	//alert (document.body.leftMargin)
	//Punto.x	+= document.body.leftMargin;
	//Punto.y	+= document.body.topMargin;
	
	return Punto;
}

/*******************************************************
 * 
 * .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);
	
	
	//	var iDate_Dia	= parseInt(sDate.substr(0, 2));
	//	var iDate_Mes	= parseInt(sDate.substr(3, 2));
	//	var iDate_Year	= parseInt(sDate.substr(6, 2));

	//	var fDate = new Date(2000 + iDate_Year, iDate_Mes, iDate_Dia);
	//	
	//	return fDate;
}

/*******************************************************
 * 
 * .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 DateAddDays(pFecha,pDias)
{
	var d = Str2Date(pFecha);
	var d2 = new Date(d.getFullYear(),d.getMonth(),d.getDate() + pDias);
	return Date2Str(d2);
}
/*******************************************************
* 
* 
*******************************************************/

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;
	}

}

/*******************************************************
* Diferencia de Días
* la devolución son d
*******************************************************/
function DiffFecha(sDesde,sHasta)
{
	var dDesde = Str2Date(sDesde);
	var dHasta = Str2Date(sHasta);
	
	return parseInt((dHasta.getTime()- dDesde.getTime())/(86400000),0);	
}

/*******************************************************
 * 
 * .s. 
 * 
 *******************************************************/
 
function InfoShow(sTxt)
{
	if (document.getElementById("divInfo"))
	{
		document.body.removeChild(document.getElementById("divInfo"));
	}	
	
	shtml = "<table border='0' cellpadding='0' cellspacing='0' style='width:100%' class='WndTitle'>";
	shtml += "<tr><td class='HeadVista'>Información</tr></table>";
	shtml += "<br style='height:10px' class='panel'/>";
	shtml += "<table border='0' cellpadding='2' cellspacing='0' align='left'>";
	shtml += "<tr><td><img src='./_Images/warning32x32.gif' /></td>";
	shtml += "<td class='tx14'>" + sTxt + "</td></tr>";
	//shtml += "<tr><td><img src='../_Images/Progress.gif' /></td></tr>";
	shtml += "</table>";
	shtml += "<br style='height:10px' />";
	
	var oDivInfo = document.createElement("DIV");
	document.body.appendChild(oDivInfo);
	oDivInfo.style.position	= "absolute";
	oDivInfo.id				= "divInfo";
	oDivInfo.className		= "panel";
	oDivInfo.style.width	= "275px";
	
	//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);
	oDivInfo.style.top		= (document.body.clientHeight / 2) - (oDivInfo.offsetHeight / 2);
	
	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 (!$("dv_Progress"))
	{
		var oDivProgress = document.createElement("DIV");
		document.body.appendChild(oDivProgress);
		oDivProgress.style.position	= "absolute";
		oDivProgress.id				= "dv_Progress";
		oDivProgress.className		= "backpop";
		oDivProgress.style.width	= "275px";
		oDivProgress.style.zorder	= "5000";
	}
	else
	{
		var oDivProgress = $("dv_Progress");
	}
	
	//shtml = "<div class='backpop' id='dv_Progress' style='position:absolute;width:275px;'>";
	shtml = "<table border='0' cellpadding='0' cellspacing='0' style='width:100%'>";
	shtml += "<tr><td class='HeadVista'>Espera...</tr></table>";
	shtml += "<br />";
	shtml += "<table border='0' cellpadding='5' cellspacing='0' align='left'>";
	shtml += "<tr><td><img src='../_images/loading.gif' align='absmiddle'/></td><td class='tx14'>" + sMensaje + "</td></tr>";
	shtml += "<tr><td style='height:10px'></td></tr>";
	//shtml += "<tr><td class='tx14'>" + sMensaje + "</td></tr>";
	//shtml += "<tr><td><img src='../_Images/Progress.gif' /></td></tr>";
	
	shtml += "</table>";
	//shtml += "<br />";
	
	oDivProgress.innerHTML = shtml;
	
	oDivProgress.style.left		= (document.body.clientWidth / 2) - (275 / 2);
	oDivProgress.style.top		= (document.body.clientHeight / 2) - (oDivProgress.offsetHeight / 2);

}

/*******************************************************
* 
* 
*******************************************************/

function ProgressOff()
{
	if ($("dv_Progress"))
	{
		document.body.removeChild($("dv_Progress"));
	} 
}

/*******************************************************
* 
* 
*******************************************************/

function ShowInCenter(sObj)
{
	var oObj = $(sObj);
	
	oObj.style.position		= "absolute";
	oObj.style.display		= "";
	
	oObj.style.left			= (document.body.clientWidth / 2) - (oObj.offsetWidth / 2) + "px";
	oObj.style.top			= (document.body.clientHeight / 2) - (oObj.offsetHeight / 2) + "px";

}


/*******************************************************
* 
* 
*******************************************************/

function FormatoHora(sHora)
{
	if (sHora == null){ return; }
	
	if (sHora.indexOf(":") > 0)
		return sHora.replace(":","");
	else
		return sHora.substr(0,2) + ":" + sHora.substr(2,2);
}


/*******************************************************
* 
* 
*******************************************************/

function ShowObj(sId,sHtml)
{
	try
	{
		$(sId).style.display = "";
		return;
	}
	catch(e)
	{
	}
}

function ShowObj(sId)
{
	try
	{
		$(sId).style.display = "";
		return;
	}
	catch(e)
	{
	}
}

/*******************************************************
* 
* 
*******************************************************/

function HideObj(sId)
{
	try
	{
		$(sId).style.display = "none";
		return;
	}
	catch(e)
	{
	}
}

/*******************************************************
* 
* 
*******************************************************/

function PuntoComa(pNum)
{
	m_PuntoComa = ((1/2)+"").substring(1,2);
	
	return parseFloat(pNum.replace(".",m_PuntoComa).replace(",",m_PuntoComa));
}

