/*
   ###############################################################################################
   #                     PROYECTO: hotelnet
   #                     Funciones Javascript comunes a toda la aplicación                       
   #                     Gheras 10/05/2002                                                   
   ###############################################################################################
*/

/*
Funcion que busca un valor en una lista de un formulario, si lo encuentra, devuelve el
indice del elemento y si no es así devuelve -1.
*/
	function IndexOf(Lista, sValue){
        var nReturn = -1;
        if (Lista.length){
           for (i=0;i < Lista.options.length;i++){
             if(Lista.options[i].value == sValue){
               nReturn = i;
             }
           }
        }
        return nReturn;
	}

/* Funcion que elimina un elemento una lista de un formulario
   - Lista: Lista de la que se eliminarán los elementos
   - sValArray: Lista de valores que seviran para identificar los elementos que queremos eliminar
   - sSeparator: Caracter que separa los valores
*/
	function DelListItem(Lista,sValArray,sSeparator){
        var aID = sValArray.split(sSeparator);
        for (a=0;a < aID.length;a++){
          for (i=0;i < Lista.options.length;i++){
            sAux = Lista.options[i].value;
            if (sAux == aID[a]){
              Lista.options[i] = null;
              //Si elimino el ultimo elemento y estaba seleccionado, selecciono el anterior.
              if(Lista.options.selectedIndex == -1){
                Lista.options.selectedIndex = Lista.options.length - 1;
              }
              break;
            }
          }
        }
	}

/* Funcion que modifica/inserta el valor de un elemento de la lista de un formulario
   - Lista: Lista de la que se moficará el elemento
   - sText: Texto del Item
   - sValue: Valor del Item
   - nIndex: Indice del Item, si se omite (nIndex = '') o tiene valor -1, se inserta un nuevo elemento
   - bSelect: Indica si se debe seleccionar el elemento introducido
*/
	function EditListItem(Lista,nIndex,sText,sValue,bSelect){
        if ((nIndex == '') || (nIndex == -1)){
          nIndex = Lista.options.length;
          Lista.options.length = nIndex + 1;
        }
        Lista.options[nIndex].text = sText;
        Lista.options[nIndex].value = sValue;
        if (bSelect)
          Lista.options.selectedIndex = nIndex;
	}

/* Abre una ventana */
	function MM_openBrWindow(theURL,winName,features) { //v2.0
		window.open(theURL,winName,features);
	}

// Funcion que realiza la validacion de las fechas
	function isDate(fecha){
		alert(fecha);
		var sMensaje = true;
		var ddTopeSup = 30;
		var dd,mm,aa;

		if (isWhitespace(fecha)){
			sMensaje = false;
		}else{

		fecha = new Date(fecha);

		dd = fecha.getDay();
		mm = fecha.getMonth();
		aa = fecha.getYear();

		if (aa < 1 || isNaN(Number(aa))) {
		sMensaje = false;
		}
		if ((mm < 1) || (mm > 12) || isNaN(Number(mm))){
		sMensaje = false;
		}else{
		if (mm == 2){
			ddTopeSup = 28;
		   if (((aa % 400) == 0) || ((aa % 4) == 0 && (aa % 100) != 0)){
			   ddTopeSup = 29;
			}
		}else{
			if ((mm == 1) || (mm == 3) || (mm == 5) || (mm == 7) || (mm == 8) || (mm == 10) || (mm == 12))
				ddTopeSup = 31;
			}
		}
		if ((dd < 1) || (dd > ddTopeSup) || isNaN(Number(dd))){
			sMensaje = false;
		}

		}
		return sMensaje;
	}

// Devuelve true si el string s está vacio o contiene espacios en blanco
	function isWhitespace (s)
	{ 
		var whitespace = " \t\n\r";
		var i;

		// Está vacio
		if (isEmpty(s)) return true;

		// Comprueba caracter a caracter del string hasta que encuentra uno distinto de espacio
		for (i = 0; i < s.length; i++)
			{ 
				var c = s.charAt(i);

				if (whitespace.indexOf(c) == -1) return false;
					}
					return true;
					}  

// Comprueba si un string está vacio  
	function isEmpty(s)
		{ return ((s == null) || (s.length == 0))
	}
 
 
/* Visualiza el tamaño del control (Textarea gemeralmente). Para no exceder de los
   caracteres indicados. */

	function textCounter(field,cntfield,maxlimit) {
		if (field.value.length > maxlimit)
			field.value = field.value.substring(0, maxlimit);
		else
		cntfield.value = maxlimit - field.value.length;
	}


/* Crea ventana emergente totalmente configurable por parametros  
	valores de argumento=0 o 1
	ejemplo: openAWindow( 'prueba.htm', 'nombreVentana', 200, 200, 1, 0, 0, 1, 0, 0, 0, 0, 0)
*/	
function openAWindow( pageToLoad, winName, width, height, center, location, menubar, resizable, scrollbars, status, titlebar, toolbar, hotkeys) {
xposition=0; yposition=0;
if ((parseInt(navigator.appVersion) >= 4 ) && (center)){
xposition = (screen.width - width) / 2;
yposition = (screen.height - height) / 2;
}
args = "width=" + width + "," 
+ "height=" + height + "," 
+ "location=" + location + "," 
+ "menubar=" + menubar + "," 
+ "resizable=" + resizable + "," 
+ "scrollbars=" + scrollbars + "," 
+ "status=" + status + "," 
+ "titlebar=" + titlebar + "," 
+ "toolbar=" + toolbar + "," 
+ "hotkeys=" + hotkeys + "," 
+ "screenx=" + xposition + "," //NN Only
+ "screeny=" + yposition + "," //NN Only
+ "left=" + xposition + "," //IE Only
+ "top=" + yposition; //IE Only
window.open( pageToLoad,winName,args );
}

//---------------------- 
var fecha=new Date();
dia=fecha.getDate();
mes=fecha.getMonth()+1;
anio=fecha.getYear();
if (dia<10) dia="0"+dia;
if (mes<10) mes="0"+mes;
if (anio<2000) anio += 1900;


//Comprueba si el email introducido es válido
	function checkEmail(email){
		var isEmail = email.match(/^\w+(-\w+)*(\.\w+(-\w+)*)*@\w+(-\w+)*(\.\w+(-\w+)*)*\.([a-z]{3}|[a-z]{2})$/);
		if (!isEmail) {
			//La dirección de correo no es válida
			return false;
		} else {
			//La dirección de correo es correcta
			return true;
		}
	}


function openWin(catUrl)
{
window.open(catUrl,'PartnersImprimir','width=600,height=500,location=no,toolbar=no,directories=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,left=100,top=100');
}

aDays = new Array('Lunes','Martes','Miercoles','Jueves','Viernes','Sábado','Domingo');
aMonths = new Array('enero','febrero','marzo','abril','mayo','junio','julio','agosto','septiembre','octubre','noviembre','diciembre')
function TheDate() {
	var txt='', date;
	date = new Date();
	ds = date.getDay()-1; (ds<0)? ds=6:ds=ds;
	txt += aDays[ds]+', '+date.getDate() + ' de '+aMonths[date.getMonth()]+' de '+date.getFullYear();
	return txt;
}


//funciones Dreamweaver
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
