﻿//.s.

var bDebug = true;


/*******************************************************
* .s. GE = getElementById
*******************************************************/

function GE(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 + parseInt(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 InfoShow(sTxt)
{
	if (document.getElementById("divInfo"))
	{
		document.body.removeChild(document.getElementById("divInfo"));
	}	
	
	shtml = "<table border='0' cellpadding='0' cellspacing='0' style='width:100%'>";
	shtml += "<tr><td class='InfoShow_Title'>&nbsp;Información</tr></table>";
	shtml += "<br />";
	shtml += "<table border='0' cellpadding='5' cellspacing='0' align='left'>";
	shtml += "<tr><td><img src='_Images/Warning32x32.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	= "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);
	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 (!GE("dv_Progress"))
	{
		var oDivProgress = document.createElement("DIV");
		document.body.appendChild(oDivProgress);
		oDivProgress.style.position	= "absolute";
		oDivProgress.id				= "dv_Progress";
		oDivProgress.className		= "Progress_Dv";
		oDivProgress.style.width	= "275px";
		oDivProgress.style.zorder	= "5000";
	}
	else
	{
		var oDivProgress = GE("dv_Progress");
	}
	
	shtml = "<table border='0' cellpadding='0' cellspacing='0' style='width:100%'>";
	shtml += "<tr><td class='Progress_Title'>Espera...</tr></table>";
	//shtml += "<br />";
	shtml += "<table border='0' cellpadding='2' cellspacing='0' align='center'>";
	shtml += "<tr><td class='Progress_Txt'>" + 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 (GE("dv_Progress"))
	{
		document.body.removeChild(GE("dv_Progress"));
	} 
}

/*******************************************************
* 
* 
*******************************************************/

function ShowInCenter(sObj)
{
	var oObj = GE(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 ShowWindowModal(sContenido)
//{
//	
//	if (document.getElementById("dv_WindowModal"))
//	{
//		document.body.removeChild(document.getElementById("dv_WindowModal"));
//	}	
//	
//	var oDivW = document.createElement("DIV");
//	oDivW.style.position	= "absolute";
//	oDivW.style.overflow	= "auto";
//	oDivW.id				= "dv_WindowModal";
//	
//	document.body.appendChild(oDivW);

//	//oDivInfo.innerHTML = "<span style='float:left;display:inline;'><img src='../_Images/InfoShowIco.jpg' border='0' align='absmiddle'/></span><span style='float:left;padding:10px;display:inline' class='divInfoTxt'>" + sTxt + "</span>";
//	
//	oDivW.innerHTML = sContenido;
//	
//	oDivW.style.height = "300px";
//	
//	oDivW.style.left		= (document.body.clientWidth / 2) - (oDivW.offsetWidth / 2);
//	oDivW.style.top			= (document.body.clientHeight / 2) - (oDivW.offsetHeight / 2);
//	
//	oDivW.onmouseout = _AutoHideModal;

//}

/*******************************************************
* 
* 
*******************************************************/

//function _AutoHideModal(e)
//{
//	if (!e) var e = window.event;
//		
//	var oDestino = (e.relatedTarget) ? e.relatedTarget : e.toElement;

//	while (oDestino != null && oDestino.nodeName != "DIV" && oDestino.nodeName != "BODY")
//		oDestino = oDestino.parentNode
//	
//	if ( oDestino == null || oDestino.nodeName == "BODY")
//	{
//		document.body.removeChild(document.getElementById("dv_WindowModal"));
//		return;
//	}	

//}

///*******************************************************
//* 
//* 
//*******************************************************/

//function HideWindowModal()
//{
//	if (document.getElementById("dv_WindowModal"))
//	{
//		document.body.removeChild(document.getElementById("dv_WindowModal"));
//	}	

//}

/*******************************************************
* 
* 
*******************************************************/

function FormatoHora(sHora)
{
	if (sHora.indexOf(":") > 0)
		return sHora.replace(":","");
	else
		return sHora.substr(0,2) + ":" + sHora.substr(2,2);
}

/*******************************************************
* .s. Devuelve el texto de un array de cbitem segun value. 
*		NO POSICIÓN
* 
*******************************************************/

function GetCbItemText(pVItems,pValue)
{
	for (i = 0;i < pVItems.length;i++)
	{
		if (pVItems[i].Value == pValue)
			return pVItems[i].Text;
	}
	return "";
}

/*******************************************************
* 
* 
*******************************************************/

function ShowToolTip(e,sMensaje)
{
	if (!e) var e = window.event;
	
	if (!GE("dv_ToolTip"))
	{
		var odv_ToolTip = document.createElement("DIV");
		document.body.appendChild(odv_ToolTip);
		odv_ToolTip.style.position	= "absolute";
		odv_ToolTip.id				= "dv_ToolTip";
		//odv_ToolTip.className		= "backpop";
	}
	else
	{
		var odv_ToolTip = GE("dv_ToolTip");
	}
		
	odv_ToolTip.innerHTML		= sMensaje;
	odv_ToolTip.style.display	= "";
	odv_ToolTip.style.left		= e.clientX - (odv_ToolTip.offsetWidth / 2);
	odv_ToolTip.style.top		= e.clientY - odv_ToolTip.offsetHeight - 5;
}

/*******************************************************
* 
* 
*******************************************************/

function HideToolTip()
{
	if (GE("dv_ToolTip"))
		GE("dv_ToolTip").style.display = "none";

}

/*******************************************************
* .s. pvHoras = array de destino
* 
*******************************************************/

function FillCbHoras(pvHoras)
{
	//.s. Llenando vector de horas
	var iHoraInicial = 8;
	for (i = 0;i<24;i++)
	{
		if (iHoraInicial > 23)
			iHoraInicial = 0;
		
		sHora = iHoraInicial.toString().length == 1 ? "0" + iHoraInicial : iHoraInicial;
		
		var oCbItem = new Object();
		oCbItem.Value	= sHora + "00";
		oCbItem.Text	= sHora + ":00";
		pvHoras.push(oCbItem);
		
		var oCbItem = new Object();
		oCbItem.Value	= sHora + "30";
		oCbItem.Text	= sHora + ":30";
		pvHoras.push(oCbItem);
		
		iHoraInicial++
	}
}

/*******************************************************
* 
* 
*******************************************************/

function ShowObj(sId)
{
	GE(sId).style.display = "";
	return;
}

/*******************************************************
* 
* 
*******************************************************/

function HideObj(sId)
{
	GE(sId).style.display = "none";
	return;
}





/*******************************************************
* 
* 
*******************************************************/



var _RunRoll = {

	Index				: 0,
	Fotos				: [],
	Contenedor			: null,
	InnerContenedor		: null,
	AniSpeed			: 1500,
	i                   :0,
	
	Ini : function (pContenedor,pFotos)
	{
		Contenedor = $("#" + pContenedor);
		Contenedor.css("overflow","hidden");
		_RunRoll.Fotos		= pFotos;
		
		InnerContenedor = $("<div id='RollInnerDiv' ></div>");
		
		sHTML = "<img id='"+ _RunRoll.i +"' src='" + _RunRoll.Fotos[_RunRoll.Index] + "'></img>";
		
		InnerContenedor.html(sHTML);
		
		_RunRoll.Contenedor = Contenedor;
		Contenedor.append(InnerContenedor);
		
		_RunRoll.Step();

	},
	
	Step : function()
	{
	    
	    _RunRoll.Index++;
	    _RunRoll.i++;
		if (_RunRoll.Index >= _RunRoll.Fotos.length){
			
			IncrementoScrollTop = $("#RollInnerDiv img").eq(_RunRoll.Index).outerHeight();
		    _RunRoll.Contenedor.animate({"scrollTop" : _RunRoll.Contenedor.scrollTop() + IncrementoScrollTop},_RunRoll.AniSpeed);
		    		
		    
			_RunRoll.Index = 0;
			
			for(k=_RunRoll.i-_RunRoll.Fotos.length;k<_RunRoll.i;k++)
			{
			    $("#"+k).remove();
			}
			
		}
	    
		Img = $("<img id='"+_RunRoll.i+"' src='" + _RunRoll.Fotos[_RunRoll.Index] + "'></img>");
		
		
		$("#RollInnerDiv").append(Img);
		
		IncrementoScrollTop = $("#RollInnerDiv img").eq(_RunRoll.Index).outerHeight();
		_RunRoll.Contenedor.animate({"scrollTop" : _RunRoll.Contenedor.scrollTop() + IncrementoScrollTop},_RunRoll.AniSpeed);
		setTimeout(_RunRoll.Step,4000);	
	}
	
};

(function($){ $.fn.extend(_RunRoll) })(jQuery);