// ----------------------------------------------------------------------------------------------------------------

function Center(aPanel, aElement, deltaX, deltaY)
{
	var EsIE = IsIE();
	var ScrollLeft = EsIE ? document.body["scrollLeft"] : window.pageXOffset;
	var ScrollTop  = EsIE ? document.body["scrollTop"] : window.pageYOffset;
	
	var PanelCenterX = aPanel.clientWidth >> 1;
	var PanelCenterY = aPanel.clientHeight >> 1;
	var ElementCenterX = parseInt(aElement.style.width) >> 1;
	var ElementCenterY = parseInt(aElement.style.height) >> 1;
	aElement.style.left = PanelCenterX - ElementCenterX + deltaX + ScrollLeft;
	aElement.style.top = PanelCenterY - ElementCenterY + deltaY + ScrollTop;		
}

// ----------------------------------------------------------------------------------------------------------------

function IsAnyChecked(Sender)
{
	var Result = false;
	if (Sender)
	{
		if (Sender.length)
		{
			for (var i=0; i < Sender.length; i++)
				if (Sender[i].checked)
				{
					Result = true;
					break;
				}
		}
		else
			Result = Sender.checked;
	}
	return Result;
}

// ----------------------------------------------------------------------------------------------------------------

function SelectedText(aSelect)
{
 return (aSelect && aSelect.options)? aSelect.options[aSelect.selectedIndex].text: "";			
}

// ----------------------------------------------------------------------------------------------------------------

function SubmitConEnter(aForm)
{
	if ((event) && (event.keyCode == 13))
	{
		event.keyCode = 0;
		aForm.submit();
	}
}

// ----------------------------------------------------------------------------------------------------------------

function Tabulador()
{
	//key = document.all? event.keyCode : event.which;
	if (document.all)
	{
		if (event.keyCode == 13)
		{
			event.keyCode = 9;
		}
	}
}

// ----------------------------------------------------------------------------------------------------------------

function EuroToPts(Value)
{
	return parseInt(Value * 166.386 + 0.5);
}

// ----------------------------------------------------------------------------------------------------------------

function PtsToEuro(Value)
{
	return Math.round(parseInt((Value / 166.386 + 0.005) * 100) / 100);
}

// ----------------------------------------------------------------------------------------------------------------

function ShowSupportOnLine(Referer)
{
	window.open("http://www.ofertahosting.com/soUsuarios/index.asp?r=" + Referer, "soporte", "width=547,height=510");
}

// ----------------------------------------------------------------------------------------------------------------

function CurrencyHint(Sender, DefaultHint)
{
	var Euro = true;
	var Value = Sender.value;
	if (Value.substr(Value.length - 1, 1) == "*")
	{
		Euro = false;
		Value = Value.substring(0, Value.length - 2);			
	}
		
	Value = parseFloat(Sender.value);
	if (Value)
	{
		if (Euro)
		{
			Sender.title = Value + " € => " + EuroToPts(Value) + " Pts";
		}
		else
		{
			var CurrencyValue = PtsToEuro(Value);
			Sender.value = CurrencyValue;
			Sender.title = CurrencyValue + " € => " + Value + " Pts";
		}
	}
	else
		Sender.title = DefaultHint;
}

// ----------------------------------------------------------------------------------------------------------------

function IsIE()
{
	return (document.all? true : false);
}

// ----------------------------------------------------------------------------------------------------------------

function DesktopCenter(aWindow)
{
	var aWindowWidth = IsIE()? document.body.clientWidth: window.innerWidth;
	var aWindowHeight = IsIE()? document.body.clientHeight: window.innerHeight;
		
	aWindow.moveTo((screen.width >>> 1) - (aWindowWidth >>> 1), (screen.height >>> 1) - (aWindowHeight >>> 1));
	aWindow.focus();
}

// ----------------------------------------------------------------------------------------------------------------

function CheckNotAllFilled(fm, prefix, count)
{
	var Result = 0;
	for (var i=0; i < count; i++)
	{
		if (fm[prefix + (i + 1)])
		{
			if (fm[prefix + (i + 1)].value == "")			
			{
				Result = i + 1;	
				break;
			}
		}
	}
	return Result;
}

// ----------------------------------------------------------------------------------------------------------------

function ClearCommand(Target)
{
	for (var i = 0; i < Target.elements.length; i++)
		Target.elements[i].value = "";
}
		
// ----------------------------------------------------------------------------------------------------------------

function UncheckAll(aElement)
{
	if (aElement.length)		
	{
		for (var i = 0; i < aElement.length; i++)
			aElement[i].checked = false;
	}
	else
		aElement.checked = false;
}

// ----------------------------------------------------------------------------------------------------------------

function GetObject(aObject)
{
	return typeof aObject == "string" ? document.getElementById(aObject) : aObject;
}
// ----------------------------------------------------------------------------------------------------------------

function ClearSelectFrom(aSelect, aIndex)
{
	aIndex = aIndex ? aIndex : 0;
	aSelect = GetObject(aSelect);
	while (aSelect.options.length && aSelect.options.length > aIndex)
		aSelect.options[aIndex] = null;
}

// ----------------------------------------------------------------------------------------------------------------

function _FrameImageResizeWindow(aWindow, Img)
{
	var Width;
	var Height;
	var ImageWidth = null;
	var ImageHeight = null;

	if (Img.offsetWidth > screen.width)
	{
		Width = screen.width;
		ImageWidth = Width;
	}
	else
		Width = Img.offsetWidth;

	if (Img.offsetHeight > screen.height)
	{
		Height = screen.height;
		ImageHeight = Height;
	}
	else
		Height = Img.offsetHeight;			

	aWindow.resizeTo(Width + 10, Height + 25);
	aWindow.moveTo((screen.width - Width) >>> 1, (screen.height - Height) >>> 1);
	
	
	if (ImageWidth)
		Img.width = ImageWidth;
		
	if (ImageHeight)
		Img.height = ImageHeight;
}

// ----------------------------------------------------------------------------------------------------------------

function ZoomToActualSize(aImg, aWindowName)
{	
	var aWindow = window.open("", aWindowName, "width=640,height=480,resizable");			
	aWindow.document.open();
	aWindow.document.write("<table width='100%' height='100%' border='0' cellpadding='0' cellspacing='0'>" +												 		
												 "<tr>" +
												 "<td align='center' valign='middle'>" +
												 "<img id='zoomimg' border='0' src='" + aImg.src + "' />" +
												 "</td>" +
												 "</tr>" +
												 "</table>");

	aWindow.document.close();	
	aWindow.document.body.style.margin = "0px;";

	Img = aWindow.document.getElementById("zoomimg");
	Img.onload = function(){_FrameImageResizeWindow(aWindow, Img)};	
}

// ----------------------------------------------------------------------------------------------------------------

function DNICharControl(aDNI)
{
	if (aDNI)
	{
		var ControlChars = "TRWAGMYFPDXBNJZSQVHLCKET";	
		return ControlChars.charAt(aDNI % 23);
	}
	else
		return "";
}

// ----------------------------------------------------------------------------------------------------------------

function SelectIndexOfValue(aSelect, aValue)
{
	var Result = -1;
	with (aSelect)
	{
		for(var i=0; i < options.length; i++)
		{
			if (options[i].value == aValue)
			{
				Result = i;
				break;
			}
		}
	}
	return Result;
}
// ----------------------------------------------------------------------------------------------------------------

function SelectIndexOfText(aSelect, aText)
{
	var Result = -1;
	var UCaseText = aText.toUpperCase;
	with (aSelect)
	{
		for(var i=0; i < options.length; i++)
		{
			if (options[i].text.toUpperCase == UCaseText)
			{
				Result = i;
				break;
			}
		}
	}
	return Result;
}

// ----------------------------------------------------------------------------------------------------------------

function HasOnlyThisChars(aString, aCharSet)
{
	for (var i = 0; i < aString.length; i++)
	{
		if (aCharSet.indexOf(aString.substr(i, 1)) == -1)
			return false;
	}
	return true;
}

// ----------------------------------------------------------------------------------------------------------------

function HasOnlyNumbers(aString)
{
	return HasOnlyThisChars(aString, "0123456789");
}

// ----------------------------------------------------------------------------------------------------------------

function SelectSellAll(aSelect, aBoolean)
{
	if (aSelect.options)
	{
		aBoolean = aBoolean == false ? false : true;
		for (var i=0; i < aSelect.options.length; i++)
			aSelect.options[i].selected = aBoolean;
	}
}

// ----------------------------------------------------------------------------------------------------------------

function PreloadImages(PathImages, ImagesList)
{
	var Images = new Array();	
	for (var i=0; i < ImagesList.length; i++)
	{
		Images[i] = new Image();
		Images[i].src = PathImages + ImagesList[i];
	}	
}

// ----------------------------------------------------------------------------------------------------------------

