  //var postproceso=new Array();
  var transparency=new Object(); //objeto que contiene la capa de transparencia
  var xmlhttp = false;// variable que sirve de conexion para usar implementacion AJAX
  //var error_box=new Array();//contiene los objetos que servir�n para mostrar los mensajes de error
  var info_box=new Array();//contiene los objetos contenedores que sirven para mostrar informacion de ayuda
  var find_required=false;//contiene un valor booleano para saber si se quiere saber los campos que son requeridos
  var color_texterror="error_color_text";

  //window.onload=init;//rutina de inicio
  
	//class particularidades (){}desarrollar para poner todas las excepciones en una clase que las mantenga

  function preValidate(objId){//controla si el elemento debe ser pasado al servidor para prevalidacion
	var e=document.getElementById(objId);
	if(e.title=="VALIDATE" || e.title=="REQUIRED_VALIDATE"){// comprobamos si se precisa validacion
		if(iss_empty(e)){
			if(e.title=="REQUIRED_VALIDATE"){
				paint_error(e);//navigation(objId);
			}
			return false;
		}
		oculta_error(e);
		return true;
    }else if(e.title=="REQUIRED"){//comprobamos si se puede activar el boton next
      if(!iss_empty(e)){oculta_error(e);return true;}
      else{paint_error(e);navigation(objId);}
	  return false;
    }
	return false;
  }

  function navigation(objID){//comprueba si se pueden activar los botones para pasar al siguiente paso del registro
    
    //recorremos todos los objetos del form y si todos los requeridos estan completados y/o validados, se libera el acceso al siguiente paso
    var nonext=false;//nos indica si se puede activar el boton de siguiente paso
    var obj=null;//contiene el objeto que ha iniciado el evento validador o requerido
    var divid; // contiene el id del DIV contenedor del objeto obj
	if(document.forms.length<1){return;}
    var formdefault="form_siguiente";
    while (true){
      if (objID!=null){
        obj=document.getElementById(objID);
      }
      if (objID==null){
        if(document.forms.length<1){return;}
		obj=document.getElementById(formdefault);
      }else if(obj.tagName!="FORM"){
        obj=obj.form;
      }
	for(var i=0;i<obj.elements.length  ;i++){//recorremos todos los elementos del form y comprobamos si el objeto pertenece al DIV contenedor
      var e=obj.elements[i];
      switch(e.type){
      case "text":
      case "password":
      case "textarea":
		if (e.title=="REQUIRED_VALIDATE" && have_error(e)){nonext=true;break;}
        if ((e.title=="REQUIRED" || e.title=="REQUIRED_VALIDATE") && iss_empty(e)){nonext=true;if(find_required){paint_error(e);}}
        break;
      case "select-one":
      case "select-multiple":
        if (e.title=="REQUIRED_VALIDATE" && have_error(e)){nonext=true;break;}
	      if ((e.title=="REQUIRED" || e.title=="REQUIRED_VALIDATE") && iss_empty(e)){nonext=true;if(find_required){paint_error(e);}}
        break;
      case "checkbox":
        if ((e.title=="REQUIRED" || e.title=="REQUIRED_VALIDATE") && iss_empty(e)){nonext=true;if(find_required){paint_error(e);}}
        break;
      case "hidden":
		if ((e.title=="REQUIRED" || e.title=="REQUIRED_VALIDATE") && iss_empty(e)){nonext=true;}
		break;
      }
	  if(nonext && !find_required){break;}
    }
	break;
    }
    find_required=false;
    var next=document.getElementById(obj.obj.buttonid);
	if (next!=null){
		var name_class=next.className.split("_");
		if (name_class[name_class.length-1]=="activo"){
			name_class.pop();
		}
		name_class=name_class.join("_");
		nonext? next.className=name_class:next.className=name_class+"_activo";
		//alert("objetoid: "+objID+" formulario: "+obj.id+" "+name_class+"="+!nonext+"; clase: "+next.className);
	}
  }

  function iss_empty(obj){
    //funcion que especifica para un elemento dado si esta vacio, unchecked, unselected
    var empty=true;
    switch (obj.type){
      case "text":
      case "password":
      case "textarea":
        if (obj.value!=""){empty=false;}
        break;
      case "radio":
      case "checkbox":
        var elem=document.getElementsByName(obj.name);
        for(var i=0;i<elem.length;i++){
          if(elem[i].checked){empty=false;break;}
        }
        break;
      case "select-one":
        if(obj.options[obj.selectedIndex].value!="FAKE"){empty=false;}
        break;
      case "select-multiple":
        for(var i=0;i<obj.options.length;i++){
          if(obj.options[i].selected){empty=false;break;}
        }
        break;
      case "hidden":
		if(obj.value=='true'){empty=false;}
        break;
      }
   return empty;
  }
  
  function have_error(obj){
    //funcion que especifica para un elemento dado si la etiqueta de texto asociada esta marcada como error o no
    var error=false;
    var labelid=obj.id+"_TG";
    if (document.getElementById(labelid).className==color_texterror){return true;}
    return error;
  }
  
  function paint_error(obj){
    //funcion que cambia el color a una etiqueta
    var labelid=obj.id+"_TG";
    switch (obj.tagName){
    case "SELECT":
    case "TEXTAREA":
    case "INPUT":
      switch (obj.type){
       case "checkbox":
        if(obj.name!=obj.id){labelid=obj.name+"_TG";}
        break;
      }
    default:
    }
    addclass(color_texterror,document.getElementById(labelid));
  }
  
  function oculta_error(obj){
    //funcion que limpia las cajas de error o informacion
    unpaint_error(obj);// quitamos la clase de error para la lista LI
document.getElementById("error_text").innerHTML="";
	$("#dialog_error").dialog('close');
  }
  
  function muestra_error(obj,msg){
    //funcion que muestra las cajas de error o informacion
    paint_error(obj);// mostramos la clase de error para la lista LI
    document.getElementById("error_text").innerHTML=msg;
	$("#dialog_error").dialog('open');
  }
  
  function unpaint_error(obj){
    //funcion que cambia el color a una etiqueta
    var labelid=obj.id+"_TG";
    switch (obj.tagName){
    case "SELECT":
    case "TEXTAREA":
    case "INPUT":
      switch (obj.type){
       case "checkbox":
        if(obj.name!=obj.id){labelid=obj.name+"_TG";}
        break;
      }
    default:
    }
    delclass(color_texterror,document.getElementById(labelid));
  }
  
  function exist_class(nameclass,obj){
	if ( obj.nodeType != 1 ) return false;
	var desglose=obj.className.split(" ");
	for(var i=0;i<desglose.length;i++){
		if(desglose[i].replace(/ /g,'')==nameclass){
			return true;
		}
	}
	return false;
  }
  
  function addclass(nameclass,obj){
    // primero quitamos la clase para que no este repetida
	var str=obj.className.split(nameclass);
    obj.className=str.join('');
    //y luego la a�adimos
    obj.className +=" "+nameclass;
  }
  
  function delclass(nameclass,obj){
    var str=obj.className.split(nameclass);
    obj.className=str.join('');
  }
  
  function showPending(objid){//si un DIV tiene elementos requeridos sin rellenar, mostramos cuales estan sin rellena
	find_required=true;
    navigation(objid);
    document.getElementById("error_text").innerHTML= C_COMPLETAR;
	$("#dialog_error").dialog('open');
	//error_box[0].innerHTML="Erase una vez un planeta triste y oscuro y la luz descubri� un bonito mundo de color. Un viejo relojo canta su cancion daba daba da daba da... Debe rellenar correctamente los campos marcados en rojo";
    //error_box[0].className="error_box";
  }

  function hidebox(obj){
	if(exist_class("hidebox",obj)){
		delclass("hidebox",obj);
	}
	if(obj.className.replace(/ /g,'')!=''){
		obj.prevclass=obj.className;
	}
	obj.className="hidebox";
  }
  
  function showbox(obj){
	if("prevclass" in obj){
		obj.className=obj.prevclass;
	}else{
		delclass("hidebox",obj);
	}
  }
    
  /*function showinfo(obj){
    var id=obj.id.split("_");
    id=id[id.length-1].split("");
    if(id[0]!="I" || id.length>2){id=0;}else{id=id[1];}
    info_box[id].className="info_box";
  }*/
  /*function hideinfo(obj){
    var id=obj.id.split("_");
    id=id[id.length-1].split("");
    if(id[0]!="I" || id.length>2){id=0;}else{id=id[1];}
    info_box[id].className="hidebox";
  }*/

  
  
  
// dropdown menu peque�ito en la cabecera para reformar otro dia //

  function dropmenu(){
document.getElementById('dropdown').onmouseover=function(){
	document.getElementById('productos').style.visibility="visible"}
document.getElementById('dropdown').onmouseout=function(){
	document.getElementById('productos').style.visibility="hidden"}
	document.getElementById('productos').onmouseover=function(){
	document.getElementById('productos').style.visibility="visible"}
document.getElementById('productos').onmouseout=function(){
	document.getElementById('productos').style.visibility="hidden"}
}






 /*
*
*			PROCESANODOS
*
*/   
  function procesanodos(unnodo){
    //tiene hijos el nodo dado?
    if(unnodo.hasChildNodes()){
      //mientras tenga hijos, bajamos
      procesanodos(unnodo.firstChild);
    }
    //procesamos la hoja
    if(unnodo.nodeType==1){
		procesaclases(unnodo);
		e=unnodo;
		if(e.tagName=="FORM"){
			o=new Object();
			o.buttonid=e.id.substring(5);
			e.obj=o;
			e.onsubmit=function(){return false;}
		}
		if(!(common_elements(e) || casos_particulares(e))){
		if (e.title=="VALIDATE" || e.title=="REQUIRED_VALIDATE" || e.title=="REQUIRED"){
			switch(e.type){
			case "text":
			case "textarea":
			case "password":
			case "select-one":
				e.onchange=function(){
					if(preValidate(this.id)){
						if(this.title=="REQUIRED"){
							navigation(this.id);
						}else{
							runajax(this,pathbase+phpscript);//funcion que envia una peticion al servidor
						}
					}else{
						navigation(this.id);
					}
				}
				break;
			case "select-multiple":
			case "radio":
			case "checkbox":
				e.onclick=function(){
					preValidate(this.id);
					navigation(this.id);
				}
				break;
			}
		}
		}
    }
	
    //pasamos al siguiente hermano
    $nextsib=unnodo.nextSibling;
    if($nextsib!=null){
      procesanodos($nextsib);
    }
  }

 /* function showtransparency(){
	if ("IE6" in transparency){
		showbox(transparency.IE6);
	}
	showbox(transparency.div);
	}
  
  function hidetransparency(){
	if ("IE6" in transparency){
		hidebox(transparency.IE6);
	}
	hidebox(transparency.div);
  }
*/
  function common_elements(elem){
	if(exist_class("transparency_div",elem)){
		transparency.div=elem;
		return true;
	}
	if(exist_class("transparency_IE6",elem)){
		transparency.IE6=elem;
		return true;
	}
	if(exist_class("next_button",elem) || exist_class("next_button_activo",elem)){
        switch(elem.id){
			case "guardar":
				elem.href="users/register/save/"+this.id;
				break;
			case "siguiente":
				elem.onclick=function(){
					if(this.className=="next_button_activo"){
						enviar("siguiente",null);
					}else{
						showPending("form_"+this.id);
					}
				}
				break;

		}
		return true;
	}
	if(exist_class("back_button",elem)){
        elem.onclick=function(){
			enviar("anterior");
		}		
		return true;
	}	
	if(exist_class("boton_guardar_activo",elem) || exist_class("boton_guardar",elem)){
		switch(elem.id){
			case "close_error":
				elem.onclick=function(){$("#dialog_error").dialog('close');}
				return true;
			case "cancel_layer":
				elem.onclick=function(){$("#promtdialog").dialog('close');}
				return true;
			case "save_layer":
				return true;
		}
	}
	/*if(exist_class("error_box",elem)){
        error_box.push(elem);
		return true;	
	}*/
	return false;
  }

  
  function init(){
  procesadialogs();
  
  procesanodos(document.getElementsByTagName("BODY")[0]);
  //ocultamos todas las cajas de error e informativas
  /*for(var k=0;k<error_box.length;k++){
    error_box[k].className="hidebox";
  }
  for(var k=0;k<info_box.length;k++){
    info_box[k].className="hidebox";
  }*/
  var h=document.getElementById("container").offsetHeight;
  /*alert(h);
  if ("IE6" in transparency){
	transparency.IE6.height=h;
  }
  transparency.div.height=h;
  alert(transparency.div.height);*/
  navigation();//si no existe ningun elemento required entonces el boton next se activa
  //persiana();
  //hidetransparency();
}



function fix_price(price) {
	price = price.replace(',', '.');
	price = parseFloat(price);
	if( isNaN(price) ) {
		price = '';
	}
	else if( price<0.01 ) {
		price = '';
	}
	return price;
}



$(document).ready(function () {
 	dropmenu(); //activamos el menu desplegable
	
	
	
	// infobox -----------------------------------
	$('.info, .alert').live('mouseover', function() {
		$(this).find('.sugerencia').css({
			display: "block"
		});
		$(this).find('a').attr('target','_blank');
	});
	
	$('.info, .alert').live('mouseout', function() {
		$(this).find('.sugerencia').css({
			display: "none"
		});
	});
	// infobox end -------------------------------
	
})
