// Imagenes de Sustitucion
<!--
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_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_findObj(n, d) { //v4.01
  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 && d.getElementById) x=d.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];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
//-->

// Menu y Administración en general

function preloader(visible)
{
	if (visible==0){
		document.getElementById('preloader').style.display='none';
	} else {
		document.getElementById('preloader').style.display='block';
	}
}

function muestramenu(quemenu,estado){
 document.getElementById(quemenu).style.display=estado;
}

function muestrafondo(quemenu,estado){
  if (estado){
	 document.getElementById(quemenu).style.background = '#ECEDFA';
  } else {
	 document.getElementById(quemenu).style.background = 'none';	  	
  }
}

function nombre_archivo(formulario,campo,valor) {
	
  fic = eval('document.'+formulario+'.'+campo+'.value');
  fic = fic.split('\\');
  nombre=fic[fic.length-1];
  if (nombre!=""){
	  document.getElementById(valor).value=nombre;
  }
  
}

// Fechas
function MostrarFecha()
   {
   var nombres_dias = new Array("Domingo", "Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sábado")
   var nombres_meses = new Array("Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre")

   var fecha_actual = new Date()

   dia_mes = fecha_actual.getDate()		//dia del mes
   dia_semana = fecha_actual.getDay()		//dia de la semana
   mes = fecha_actual.getMonth() + 1
   anio = fecha_actual.getYear()

   if (anio < 100)					//pasa el año a 4 digitos
      anio = '19' + anio
   else if ( ( anio > 100 ) && ( anio < 999 ) ) {	//efecto 2000
      var cadena_anio = new String(anio)
      anio = '20' + cadena_anio.substring(1,3)
   }

   //escribe en pagina
   document.write(nombres_dias[dia_semana] + ", " + dia_mes + " de " + nombres_meses[mes - 1] + " de " + anio)
   }

// Fin Fechas

// Rutinas AJAX
/*
function actualizar_ajax(rutina,formulario,parametro,valor,tag){

        if (!tag) tag='cuerpo';
		
		var url,argumentos,argumento;	

		if (parametro!=''){
			argumento='&'+escape(parametro)+'='+escape(valor);
		}else{
			argumento='';			
		}
	
		url = 'index.php?jump='+escape(rutina)+argumento;

		if (formulario!=''){
			argumentos={asynchronous:true, evalScripts:true, parameters:Form.serialize(formulario), onComplete:preloader(1)};
		}else {
			argumentos={asynchronous:true, evalScripts:true, onComplete:preloader(0)};
		}
        var myAjax = new Ajax.Updater(tag, 
		url,
		argumentos);

}

function call_ajax2(url,formulario,tag)
{
        if (!tag) tag='cuerpo';

		if (formulario!=''){
			argumentos={asynchronous:true, evalScripts:true, parameters:Form.serialize(formulario)};
		}else {
			argumentos={asynchronous:true, evalScripts:true};
		}
        var myAjax = new Ajax.Updater(tag, 
		url,
		argumentos);
}
*/

function call_ajax(url,tag,opciones)
{

        if (!tag) tag='cuerpo';
		argumentos={asynchronous:true, evalScripts:true};
		
		for (var i in opciones) {
            argumentos[i]=opciones[i];
			switch (i){
				case ('formulario') : argumentos['parameters']= Form.serialize(opciones[i]);
									  break;
				case ('completo')   : argumentos['onComplete']= eval(opciones[i]);
									  break;
			}
		}

//        alert(argumentos['asynchronous']);
        var myAjax = new Ajax.Updater(tag, 
		url,
		argumentos);
}

function check_form(formulario)
{
	error="";
	
	switch (formulario) {
		case 'producto' :
			fields=	new Array('codigo','tarifavp','descripcion');
			texts=	new Array("Codigo","Precio PVP","Descripcion");
			break;
	}


	for (i=0;i<fields.length;i++) {
		v=eval('document.'+formulario+'.'+fields[i]+'.value');
		if (v==""){
			error+="Por favor, compruebe campo "+texts[i]+"\n";
		}
	}
	if (formulario=='producto'){
		precio=document.producto.tarifavp.value;
		
		if (!precio.match(/^[0-9]+(.[0-9]+)*$/)){		
			error+="Por favor, Precio PVP debe ser campo numerico con dos decimales maximo (X.XX)"+"\n";
		}		
	}

	if (error!=""){
		alert(error);
	}

	document.estatus = (error=="");
}

