function F_ready_inicio(){ 
  $('BTN_find').onclick = function(){
    location.href='buscar.php?busca='+$('E_find').value+'&idioma='+lenguaje;
  };
  AjaxRequest('ajax/inicio.php?accion=actualizaciones_inicio&idioma='+lenguaje, 'POST', 'DIV_updates', false, false, false);
}

function F_ready_buscar(){
  $('BTN_find').onclick = function(){
		  location.href='buscar.php?busca='+$('E_find').value+'&idioma='+lenguaje;
  };
  if(buscar != '')
	  AjaxRequest('ajax/inicio.php?accion=buscar&buscar='+buscar+'&idioma='+lenguaje, 'POST', 'DIV_respuesta', false, false, false);
};

function F_ready_productos(){
   $('BTN_find').onclick = function(){
	  location.href='buscar.php?busca='+$('E_find').value+'&idioma='+lenguaje;
   };
   
   if(PARAM_line_clave != '')
	   F_carga_descripcion_linea(PARAM_line_clave,PARAM_line_nombre);
   else{
	   AjaxRequest('ajax/inicio.php?accion=carga_listado_lineas&idioma='+lenguaje, 'POST', 'DIV_lineas', false, false, false);
	   AjaxRequest('ajax/inicio.php?accion=carga_nuevos_productos&idioma='+lenguaje, 'POST', 'DIV_productos', false, false, false);
   }
   P_elimina_carrito(1000);
};
function F_ready_productos_artkey(){
	AjaxRequest('ajax/inicio.php?accion=carga_productos_artkey&idioma='+lenguaje, 'POST', 'DIV_productos_artkey', false, false, false);
    $('BTN_find').onclick = function(){
		location.href='buscar.php?busca='+$('E_find').value+'&idioma='+lenguaje;
    };
};

function F_carga_descripcion_linea(line_clave,line_nombre){
	AjaxRequest('ajax/inicio.php?accion=carga_descripcion_linea&idioma='+lenguaje+'&line_clave='+line_clave, 'POST', 'DIV_lineas', false, false, false);
	AjaxRequest('ajax/inicio.php?accion=carga_sublineas_linea&idioma='+lenguaje+'&line_clave='+line_clave+'&line_nombre='+line_nombre, 'POST', 'DIV_sublineas', false, false, false);	
	AjaxRequest('ajax/inicio.php?accion=carga_productos_linea&idioma='+lenguaje+'&line_clave='+line_clave, 'POST', 'DIV_productos', false, false, false);	
}

/**********************************************************************************************************************************************************/
function F_ready_clientes(){
	$('B_loggin').onclick= function(){
		if($('usua_correo').value != '' && $('usua_password').value != ''){
			AjaxRequest('ajax/inicio.php?accion=loggin&usua_correo='+$('usua_correo').value+'&usua_password='+$('usua_password').value, 'POST', 'DIV_respuesta', "$('DIV_respuesta').style.display= 'none';", " if(eval(ajax.responseText))location.href='config/sis_inicio.php';else{$('DIV_respuesta').style.display= 'block'; $('DIV_respuesta').innerHTML ='<br><br><img src=\"images/bullet_red.png\" align=\"left\" /><span class=\"fecha\">Usuario o contrase&ntilde;a incorrecta.</span>';}", false);
		}
		else
			$('DIV_respuesta').innerHTML ='<br><br><img src="images/bullet_red.png" align="left" /><span class="fecha">Complete los datos porfavor.</span>';
	};
    $('BTN_find').onclick = function(){
		  location.href='buscar.php?busca='+$('E_find').value+'&idioma='+lenguaje;
  };
}
/**********************************************************************************************************************************************************/
function F_ready_noticias(){
	AjaxRequest('ajax/inicio.php?accion=carga_noticias&idioma='+lenguaje, 'POST', 'DIV_noticias', false, false, false);
    $('BTN_find').onclick = function(){
		  location.href='buscar.php?busca='+$('E_find').value+'&idioma='+lenguaje;
  };
}

function F_ready_empleos(){
	AjaxRequest('ajax/inicio.php?accion=carga_empleos&idioma='+lenguaje, 'POST', 'DIV_empleos', false, false, false);
    $('BTN_find').onclick = function(){
		  location.href='buscar.php?busca='+$('E_find').value+'&idioma='+lenguaje;
  };
}
/***********************************************************************************************************************************************************/
function F_ready_contacto_clientes(){
	$('BTN_contacto').onclick = function(){
		$('FORM_contacto_proveedores').style.display = 'none';
		$('FORM_contacto').style.display = 'block';
		$('BTN_contacto').className = 'in_page';
		$('BTN_contacto_proveedores').className = null;
		return false;
	};
	$('usua_cp').onkeyup= function (){F_es_numero(this,10,0);};
	$('usua_telefono').onkeyup= function (){F_es_numero(this,20,0);};
	$('usua_fax').onkeyup= function (){F_es_numero(this,20,0);};
	$('B_registro').onclick = function(){
		if($('H_validacion').value != $('E_validacion').value){
			alert('Por favor introduzca el codigo de la imagen.');
		}
		else{
			if($('FORM_contacto').style.display == 'block'){
				if(!valEmail($('usua_correo').value)){
					  alert('La direccion de correo no es valida.');
					  return;
			    }
			}else{
				if(!valEmail($('prov_email_contacto').value)){
					  alert('La direccion de correo no es valida.');
					  return;
			    }
		  }
		  $('peus_preferencia_pisos').value    = $('peus_preferencia_recubrimientos').checked == true ? 'S' : 'N';      
		  $('peus_preferencia_pisos').value    = $('peus_preferencia_pisos').checked == true ? 'S' : 'N';           
		  $('peus_preferencia_muros').value    = $('peus_preferencia_muros').checked == true ? 'S' : 'N';             
	   	  $('peus_preferencia_plafones').value = $('peus_preferencia_plafones').checked == true ? 'S' : 'N';              
		  $('peus_preferencia_fachadas').value = $('peus_preferencia_fachadas' ).checked == true ? 'S' : 'N';                
		  $('peus_preferencia_techos').value   = $('peus_preferencia_techos').checked == true ? 'S' : 'N';               
		  $('peus_preferencia_domos').value    = $('peus_preferencia_domos').checked == true ? 'S' : 'N';               
          $('peus_preferencia_texturas').value = $('peus_preferencia_texturas').checked == true ? 'S' : 'N'; 
          if($('FORM_contacto').style.display == 'block')
        	  AjaxRequest('ajax/inicio.php?accion=inserta_contacto&idioma='+lenguaje+$F('FORM_contacto')+'&E_validacion='+$('E_validacion').value, 'POST', 'DIV_respuesta', false, "if(ajax.responseText.indexOf('ERROR')== -1)F_auto_loggin('"+$('H_validacion').value+"','"+$('usua_correo').value+"')", false);
          else
        	  AjaxRequest('ajax/inicio.php?accion=inserta_contacto_proveedores&idioma='+lenguaje+$F('FORM_contacto_proveedores')+'&E_validacion='+$('E_validacion').value, 'POST', 'DIV_respuesta', false, false, false);
	   }
    };
    $('BTN_find').onclick = function(){
		  location.href='buscar.php?busca='+$('E_find').value+'&idioma='+lenguaje;
  };
}
function F_auto_loggin(pass,mail){
	AjaxRequest('ajax/inicio.php?accion=loggin&usua_correo='+mail+'&usua_password='+pass, 'POST', 'DIV_respuesta', "$('DIV_respuesta').style.display= 'none';", " if(eval(ajax.responseText))location.href='productos.php';else{$('DIV_respuesta').style.display= 'block'; $('DIV_respuesta').innerHTML ='<br><br><img src=\"images/bullet_red.png\" align=\"left\" /><span class=\"fecha\">Usuario o contrase&ntilde;a incorrecta.</span>';}", false);
}

function F_ready_contacto_proveedores(){
	$('BTN_contacto_proveedores').onclick = function(){
		$('FORM_contacto_proveedores').style.display = 'block';
		$('FORM_contacto').style.display = 'none';
		$('BTN_contacto_proveedores').className = 'in_page';
		$('BTN_contacto').className = null;
	    return false;
	}
	$('usua_cp').onkeyup= function (){F_es_numero(this,10,0);}
	$('usua_telefono').onkeyup= function (){F_es_numero(this,20,0);}
	$('usua_fax').onkeyup= function (){F_es_numero(this,20,0);}
	$('B_registro').onclick = function(){
		if($('H_validacion').value != $('E_validacion').value){
			alert('Por favor introduzca el codigo de la imagen.');
		}
		else{
			if($('FORM_contacto').style.display == 'block'){
	
				if(!valEmail($('usua_correo').value)){
					  alert('La direccion de correo no es valida.');
					  return;
			    }
			}else{

				if(!valEmail($('prov_email_contacto').value)){
					  alert('La direccion de correo no es valida.');
					  return;
			    }
		  
		  }	
		  $('peus_preferencia_pisos').value    = $('peus_preferencia_recubrimientos').checked == true ? 'S' : 'N';      
		  $('peus_preferencia_pisos').value    = $('peus_preferencia_pisos').checked == true ? 'S' : 'N';           
		  $('peus_preferencia_muros').value    = $('peus_preferencia_muros').checked == true ? 'S' : 'N';             
	   	  $('peus_preferencia_plafones').value = $('peus_preferencia_plafones').checked == true ? 'S' : 'N';              
		  $('peus_preferencia_fachadas').value = $('peus_preferencia_fachadas' ).checked == true ? 'S' : 'N';                
		  $('peus_preferencia_techos').value   = $('peus_preferencia_techos').checked == true ? 'S' : 'N';               
		  $('peus_preferencia_domos').value    = $('peus_preferencia_domos').checked == true ? 'S' : 'N';               
          $('peus_preferencia_texturas').value = $('peus_preferencia_texturas').checked == true ? 'S' : 'N'; 
          if($('FORM_contacto').style.display == 'block')
        	  AjaxRequest('ajax/inicio.php?accion=inserta_contacto&idioma='+lenguaje+$F('FORM_contacto')+'&E_validacion='+$('E_validacion').value, 'POST', 'DIV_respuesta', false, false, false);
          else
        	  AjaxRequest('ajax/inicio.php?accion=inserta_contacto_proveedores&idioma='+lenguaje+$F('FORM_contacto_proveedores')+'&E_validacion='+$('E_validacion').value, 'POST', 'DIV_respuesta', false, false, false);
	   }
    };
    $('BTN_find').onclick = function(){
		  location.href='buscar.php?busca='+$('E_find').value+'&idioma='+lenguaje;
  };	
}

function F_carga_productos_sublinea(line_clave,line_nombre){
	AjaxRequest('ajax/inicio.php?accion=carga_productos_sublinea&idioma='+lenguaje+'&line_clave='+line_clave+'&line_nombre='+line_nombre, 'POST', 'DIV_productos', false, false, false);	
}
function F_compartir_email(a){
	if(document.title == 'Artkeytechturall - Productos')
	  AjaxRequest('ajax/inicio.php?accion=compartir_linea_mail&&line_clave='+$('H_clave_compartir').value+'&email_amigo='+$('E_email_amigo').value+'&idioma='+lenguaje+'&usua_nombre='+usua_nombre, 'POST', 'DIV_respuesta_compartir', false, 'F_destroy_message();', false);	
	else
      AjaxRequest('ajax/inicio.php?accion=compartir_noticia_mail&noti_clave='+$('H_clave_compartir'+a).value+'&email_amigo='+$('E_email_amigo').value+'&idioma='+lenguaje+'&usua_nombre=Artkeytechturall', 'POST', 'DIV_respuesta_compartir', false, 'F_destroy_message();', false);	
}


function reset_tabla_sublineas(){
	var trs = $('TABLE_sublineas').getElementsByTagName('tr');
	for(var a = 0; a<= trs.length; a++){
		if($('descripcion_'+a)){
			$('descripcion_'+a).style.display = 'none';
		}
	}
}
function F_ready_archivos(){
	$('BTN_find').onclick = function(){
	    location.href='buscar.php?busca='+$('E_find').value+'&idioma='+lenguaje;
	  };
	AjaxRequest('ajax/inicio.php?accion=carga_archivos_download', 'POST', 'DIV_downloads', false, false, false);
}
function F_ready_contacto(){
	$('BTN_find').onclick = function(){
	    location.href='buscar.php?busca='+$('E_find').value+'&idioma='+lenguaje;
	};
};
/************************************ FUNCTIONES DEL CARRITO **************************************************************************/



function P_agregar_al_carrito(prod_clave){
	 AjaxRequest('ajax/inicio.php?accion=agregar_al_carrito&prod_clave='+prod_clave, 'POST', 'DIV_carrito', false, "$('DIV_carrito').style.display='block';", false);		
}
function P_elimina_carrito(prod_clave){
	AjaxRequest('ajax/inicio.php?accion=quitar_al_carrito&prod_clave='+prod_clave, 'POST', 'DIV_carrito', false, "$('DIV_carrito').style.display='block';", false);		
}
function P_ver_precio(){
	var cantidades = $('DIV_carrito').getElementsByTagName('input');
	var parametros = "";
	for(var a= 0; a <= cantidades.length-1; a++){
		parametros+="&cantidad_"+a+"="+cantidades[a].value;
	}
	AjaxRequest('ajax/inicio.php?accion=ver_precio'+parametros, 'POST', false, false, "F_show_precio(ajax.responseText);", false);		
}
function P_generar_pedido(){
	var cantidades = $('DIV_carrito').getElementsByTagName('input');
	var parametros = "";
	for(var a= 0; a <= cantidades.length-1; a++){
		parametros+="&cantidad_"+a+"="+cantidades[a].value;
	}F_destroy_message();
	AjaxRequest('ajax/inicio.php?accion=generar_pedido'+parametros, 'POST', 'DIV_carrito', false, "$('DIV_carrito').style.display='block';", false);		
}





