//////////////////////////////////////////////////////////////////////////
//
// zz_varios.js : Fichero con varias funciones de utilidad javascript
//
//////////////////////////////////////////////////////////////////////////

function isDate(dateStr) {

	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
	var matchArray = dateStr.match(datePat); // is the format ok?

	if (matchArray == null) {return false;}

	day = matchArray[1];
	month = matchArray[3]; 
	year = matchArray[5];

	if (day < 1 || day > 31) {return false;}
	if (month < 1 || month > 12) {return false;}
	if ((month==4 || month==6 || month==9 || month==11) && day==31) {return false;}
	if (month == 2) {
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day > 29 || (day==29 && !isleap)) {return false;}
	}
	return true;
}


function noDisponible() {
	alert('Página en construcción.\n\nOpción disponible próximamente.\n\nDisculpe las molestias.');
}

function showDialog(url, width, height) {
	var navegador = navigator.appName;

	// Internet Explorer: Ventana modal con el showModalDialog
	if (navegador == "Microsoft Internet Explorer") {
		var resultado = window.showModalDialog(url,"","dialogHeight=" + height + "px;dialogWidth=" + width + "px;status=no;toolbar=no;center=yes")

	// Resto de navegadores
	}else{
		var resultado = window.open(url,"","height=" + height + ", width=" + width + ", status=no, toolbar=no, center=yes, scrollbar=yes, resize=yes")
	}

	if (resultado == "REFRESH") location.reload(true);
}

function showWindow(url, width, height) {
	var resultado = window.open(url,"","height=" + height + ", width=" + width + "), status=no, toolbar=no, center=yes, scrollbars=yes");
	//var resultado = window.open(url,"","height=" + height + ", width=" + width + "), status=yes, toolbar=yes, center=yes, scrollbars=yes, resizable=yes");
	if (resultado == "REFRESH") location.reload(true);
}

function getRadioValue(radio)
{
	var i = radio.length;
	if (!i) {
		return '';
	}
	do
		if (radio[--i].checked)
		return radio[i].value;
	while (i);
	return '';
}

function isNumeric(sText)
{
	var ValidChars = "0123456789.,";
	var IsNumber=true;
	var Char;

	for (i = 0; i < sText.length && IsNumber == true; i++) {
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) {
			IsNumber = false;
		}
	}
	return IsNumber;
}

function Round(int, decimals)
{
	int = int * Math.pow(10, decimals);
	int = Math.round(int);
	int = int / Math.pow(10, decimals);
	return int;
}
