isIE=document.all;
isNN=!document.all&&document.getElementById;
isN4=document.layers;
	var oscurecer=5;
	var velocidad=1;
	var oscuroahora=0;
	
	function submenu(id){
if (document.getElementById("menu" + id)){
	document.getElementById("Layer1").innerHTML= "<table border='0' cellpadding='0' cellspacing='0' onmouseover='espera=2;' >" + document.getElementById("menu" + id).innerHTML + "</table>";
	document.getElementById("Layer1").style.width=document.getElementById("menu" + id).offsetWidth;
	
	document.getElementById("Layer1").style.left=(findPosX(document.getElementById("0-" +id+"lnk"))+document.getElementById("0-" +id + "lnk").offsetWidth/2)-(document.getElementById("menu" + id).offsetWidth/2);
	document.getElementById("Layer1").style.top=findPosY(document.getElementById("0-" +id+"lnk"))-30;
	oscuroahora=0;
	show();}
	else{
	document.getElementById("Layer1").innerHTML= "";
	document.getElementById("Layer1").style.width="1px";
	
	document.getElementById("Layer1").style.left=-1000;
	document.getElementById("Layer1").style.top=-1000;
	}
	}
var masinfopen=0;	
function masinfo(){
if (masinfopen==0){

document.getElementById('lateralizq').innerHTML="<table border=\"0\" width=\"200\">" + document.getElementById('lateralinfo').innerHTML + "</table>";
document.getElementById('divContent').innerHTML="<table border=\"0\" width=\"100%\">" + document.getElementById('mainfopnl').innerHTML + "</table>";
hallarbarra();
}
}	
	function show(){
	
oscuroahora=oscuroahora + oscurecer;

if (oscuroahora<75){
if (isIE){
document.getElementById("Layer1").filters.alpha.opacity=oscuroahora;
}
else{
document.getElementById("Layer1").style.MozOpacity=oscuroahora/100;
}

setTimeout ('show ()', velocidad); 
}
else{

}

}
	function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	var printstring = '';
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	window.status = printstring;
	return curtop;
}
function seccion(nivel,id){
for (i=0;i<=20;i++){
	if (document.getElementById("0-" +i + 'lnk')){
	document.getElementById("0-" +i+"lnk").style.color="";
		}
}
ant="";
document.getElementById("seccion").innerHTML=document.getElementById(nivel + "-" +id+"lnk").innerHTML;
document.getElementById(nivel + "-" +id+"lnk").style.color="#0a5879";
document.getElementById('divContent').innerHTML="<table width='560' height='300'><tr><td align='center' class='b14'>Cargando secci&oacute;n,<br>espere un momento, por favor ...</td></tr></table>";
document.getElementById('secb').innerHTML="";
index.cargarseccion(nivel,id,cargadeseccion);
}
var ant="";
function img(imagen){
if (document.getElementById('imagenizq')){
document.getElementById('imagenizq').src="imagenes/menus/" + imagen;
}
else{
document.getElementById('lateralizq').innerHTML="<img src='imagenes/menus/" + imagen + "'>";
}
}
function cargadeseccion(res)
{
if (res.error != null){
    alert("Se ha producido el siguiente error:\n" + res.error);}
else {

for(var i=0; i<res.value.Tables[0].Rows.length; i++){
document.getElementById('divContent').innerHTML=res.value.Tables[0].Rows[0].texto;
if (res.value.Tables[0].Rows[0].izquierda==""){
}else{
document.getElementById('lateralizq').innerHTML=res.value.Tables[0].Rows[0].izquierda;
}
}
	//document.getElementById('divContent').innerHTML=res.value;
	hallarbarra();
}
}
function registro(){
if ( document.getElementById('usuario').value=="" | document.getElementById('pass').value==""){
alert("Indique usuario y contrase&ntilde;a")
}
else{
index.registro(document.getElementById('usuario').value,document.getElementById('pass').value,finregistro)
}
}
function finregistro(res){
if (res.error!=null){
alert("Se ha producido el siguiente error:\n" & res.error);
}
else{
if (res.value.Tables[0].Rows[0].texto=="nousr"){
alert("El usuario o la password son incorrectas");
}
else{
for(var i=0; i<res.value.Tables[0].Rows.length; i++){
document.getElementById('divContent').innerHTML=res.value.Tables[0].Rows[0].texto;
document.getElementById('lateralizq').innerHTML=res.value.Tables[0].Rows[0].izquierda;
}
	//document.getElementById('divContent').innerHTML=res.value;
	hallarbarra();
	}
}
}
function averia(){
alert(document.getElementById('personacontacto').value);
} 
var nivelpriv;
function priv(nivel){
if (nivel==5){
seccion(0,1);
}else{
nivelpriv=nivel;
document.getElementById('divContent').innerHTML="<table width='560' height='300'><tr><td align='center' class='b14'>Cargando secci&oacute;n,<br>espere un momento, por favor ...</td></tr></table>";
document.getElementById('secb').innerHTML="";
privada.cargarpriv(nivel,cargadeprivado);
}
}
function cargadeprivado(res)
{
if (res.error != null){
    alert("Se ha producido el siguiente error:\n" + res.error);}
else {
document.getElementById('divContent').innerHTML=res.value;
	//document.getElementById('divContent').innerHTML=res.value;
	hallarbarra();
	if (nivelpriv==2){
	document.getElementById('secb').innerHTML="Actualizando los datos de su cesta...";
	privada.cargarcesta(cargadecesta);
	}
}
}
function cargadecesta(res)
{
if (res.error != null){
    alert("Se ha producido el siguiente error:\n" + res.error);}
else {
document.getElementById('secb').innerHTML=res.value;
	//document.getElementById('divContent').innerHTML=res.value;
	
}
}
function addpedido(idrec){
document.getElementById('infocesta').innerHTML="<div align='center' class='n12b'>Agregando el producto a su cesta<br>Cuando se haya agregado la ventana del producto se cerrar&aacute;</div>";
privada.addcesta(idrec,document.getElementById('idpedido').value,cargadecestarec);
}
function cargadecestarec(res){
if (res.error != null){
    alert("Se ha producido el siguiente error:\n" + res.error);}
else {
document.getElementById('secb').innerHTML="Actualizando los datos de su cesta...";
clrecambio();
privada.cargarcesta(cargadecesta);	
}
}
function garantia(){
if (document.getElementById('codigo').value==""){
alert("Indique el codigo de su maquina");
}
else{
privada.chkgarantia(document.getElementById('codigo').value,garantiacb);
}
}
function garantiacb(res){
if (res.error != null){
    alert("Se ha producido el siguiente error:\n" + res.error);}
else {
document.getElementById('resultadogarantia').innerHTML=res.value;
	}
}
function pedido(pedido){
document.getElementById('divContent').innerHTML="<table width='560' height='300'><tr><td align='center' class='b14'>Cargando su pedido,<br>espere un momento, por favor ...</td></tr></table>";
privada.verpedido(pedido,0,cargadeseccion);
}
function pedidohis(pedido){
document.getElementById('divContent').innerHTML="<table width='560' height='300'><tr><td align='center' class='b14'>Cargando su pedido,<br>espere un momento, por favor ...</td></tr></table>";
privada.verpedido(pedido,1,cargadeseccion);
}
var articuloact;
function actpg(obj){
if (isNaN(obj.value) == true)
   {
     obj.value=obj.value.replace(/[^\d]*/gi,"")
      
   }
   else{
   if (obj.value==""){
   obj.value=0;
   articuloact=obj.id.replace("recambio","");
   privada.actpedido(0,obj.id,actpedido);
   }else{
   articuloact=obj.id.replace("recambio","");
   privada.actpedido(obj.value,obj.id,actpedido);
   }
   }
} 
function actpedido(res){
if (res.error != null){
    alert("Se ha producido el siguiente error:\n" + res.error);}
else {
if (res.value=="ok"){
var precioactnew=document.getElementById('preciosing'+articuloact).innerHTML.replace(",",".");
var precioant=document.getElementById('preciosub' + articuloact).innerHTML.replace(",",".");
var subprecio=Number(document.getElementById('recambio'+articuloact).value)*Number(precioactnew) ;

document.getElementById('preciosub' + articuloact).innerHTML=subprecio.toFixed(2);
var pedtotal=Number(document.getElementById('totprec').innerHTML.replace(",",".")-precioant)+Number(document.getElementById('preciosub' + articuloact).innerHTML.replace(",","."));
document.getElementById('totprec').innerHTML=pedtotal.toFixed(2);
document.getElementById('pedidototal').innerHTML=pedtotal.toFixed(2);
}
	}
}
function recambio(id){
document.getElementById('caparecambio').innerHTML="<table width='306' border='0' cellpadding='0' cellspacing='5' background='imagenes/fondorecambio.jpg'>" +
  "<tr>" +
   " <td height='21' colspan='2' class='n12'>Cargando</td>" +
  "</tr>" +
 " <tr>" +
  "  <td height='150' colspan='2'><div align='center' class='n12b'>Cargando datos del producto seleccionado,<br>" +
 "     espere un momento, por favor ..." +
"</div></td>" +
 " </tr>" +
  "<tr>" +
  " <td height='20' colspan='2' class='n12s'>Precio</td>" +
  "</tr>" +
 " <tr>" +
  "  <td height='80' colspan='2' valign='top' class='n12s'>Descripcion:</td>" +
 " </tr>" +
 " <tr>" +
   " <td width='144' height='30' class='r12'>A&ntilde;adir al pedido </td>" +
  "  <td width='147'><div align='right' class='n12b'>Cerrar</div></td>" +
 " </tr>" +
"</table>"
document.getElementById('caparecambio').style.left=findPosX(document.getElementById('guia'))+320 ;
document.getElementById('caparecambio').style.top=findPosY(document.getElementById('guia'))+80;
privada.recambiosel(id,recambiocb);
}

function recambiocb(res){
if (res.error != null){
    alert("Se ha producido el siguiente error:\n" + res.error);}
else {
document.getElementById('caparecambio').innerHTML=res.value;
	}
}
function clrecambio(){
document.getElementById('caparecambio').innerHTML="";
document.getElementById('caparecambio').style.left="-1000px";
document.getElementById('caparecambio').style.top="-1000px";
}

function sndcons(){
	
index.consulta(document.getElementById('nombre').value,document.getElementById('mail').value,document.getElementById('telefono').value,document.getElementById('comentario').value,resultado);
}
function sndconspedido(){
document.getElementById('btcons').innerHTML="&nbsp;&nbsp;Enviando su consulta...&nbsp;&nbsp;";
index.consultapedido(document.getElementById('nombre').value,document.getElementById('mail').value,document.getElementById('telefono').value,document.getElementById('comentario').value,document.getElementById('txtfrm').innerHTML,resultado);
}
function resultado(res)
{
if (res.error != null){
    alert("Se ha producido el siguiente error:\n" + res.error);
document.getElementById('btcons').innerHTML="&nbsp;&nbsp;Enviar&nbsp;&nbsp;";
	}
else {
	if(res.value=='ok'){
		alert("Su consulta se ha enviado correctamente\nMuchas gracias por su confianza");
priv(6);
		}else{
		alert(res.value);
		document.getElementById('btcons').innerHTML="&nbsp;&nbsp;Enviar&nbsp;&nbsp;";
		}

}
}
function enviarpedido(pedido){
document.getElementById('fnpedidobt').innerHTML="&nbsp;&nbsp;Enviando su pedido...&nbsp;&nbsp;";
document.getElementById('fnpedidobt').href="";
privada.sndpedido(pedido,0,finpedido);
	}
function averia(){
document.getElementById('btsnd').innerHTML="&nbsp;&nbsp;Enviando su averia...&nbsp;&nbsp;";
index.sndpriv(document.getElementById('personacontacto').value,document.getElementById('telefono').value,document.getElementById('codigomaquina').value,document.getElementById('averia').value,'averia',finsndpriv)
	}
function apoyo(){
document.getElementById('btsnd').innerHTML="&nbsp;&nbsp;Enviando su consulta...&nbsp;&nbsp;";
index.sndpriv(document.getElementById('personacontacto').value,document.getElementById('telefono').value,document.getElementById('codigomaquina').value,document.getElementById('consulta').value,'apoyo',finsndpriv)
	}
function finsndpriv(res){
if (res.error != null){
    alert("Se ha producido el siguiente error:\n" + res.error);}
else {
	if (res.value=='ok'){
		alert("Su consulta se ha enviado correctamente");
		priv(2);
	}
		else{
			document.getElementById('btsnd').innerHTML="&nbsp;&nbsp;Enviar consulta&nbsp;&nbsp;";
		alert(res.value);	
			}
		

}	
	}	
function finpedido(res){
if (res.error != null){
    alert("Se ha producido el siguiente error:\n" + res.error);}
else {
	if (res.value=='ok'){
		alert("Su pedido se ha enviado correctamente");
		priv(2);
	}
		else{
		alert(res.value);	
			}
		

}	
	}
function consultapedido(id){
index.cargarconsultapedido(id,cargadeprivado);
	}
//----------------------------------------------funciones div text-------
isHot=false;

function ddInit(e){
 
    topDog=isIE ? "BODY" : "HTML";
  whichDog=isIE ? document.all.scrinside : document.getElementById("scrinside");  
  hotDog=isIE ? event.srcElement : e.target;  
  while (hotDog.id!="titleBar"&&hotDog.tagName!=topDog){
    hotDog=isIE ? hotDog.parentElement : hotDog.parentNode;
  }  
  
  if (hotDog.id=="titleBar"){
    offsetx=isIE ? event.clientX : e.clientX;
    offsety=isIE ? event.clientY : e.clientY;
    nowX=parseInt(whichDog.style.left);
    nowY=parseInt(whichDog.style.top);
    ddEnabled=true;
   
  document.onmousemove=dd;
  }
  
  
}

function dd(e){
  if (!ddEnabled) return;
  whichDog.style.top=isIE ? nowY+event.clientY-offsety : nowY+e.clientY-offsety; //comentar esto para mover solo horizontalmente
  var altura=whichDog.style.top;
 alturadef=altura.replace("px","")
 if (alturadef<=0){
document.getElementById('scrinside').style.top=1;
alturadef=0;
}
else if (alturadef*factor>=alturadiferencial){
document.getElementById('scrinside').style.top=(alturadiferencial/factor)-1;
alturadef=alturadiferencial/factor;
}
  document.getElementById('divContent').style.top=-alturadef*factor;
  alturadef=-alturadef*factor;
  
  return false;  
    
}

var activarscroll;
function handleMouseWheel(e)
{
if (!e) e = window.event;
if (activarscroll==0){
return false;
}{
if ( e.wheelDelta <= 0 || e.detail > 0) {
if (alturadef-30<=-alturadiferencial){
alturadef=-alturadiferencial;
document.getElementById('divContent').style.top=alturadef;
document.getElementById('scrinside').style.top=(-alturadef/factor)-1;
}
else
{
alturadef=alturadef-30;
 document.getElementById('divContent').style.top=alturadef;
 document.getElementById('scrinside').style.top=(-alturadef/factor)-1;
 //document.getElementById('posicionx').value=-alturadiferencial;
  }
 }
else {

if (alturadef+30>=0)
{alturadef=0;
document.getElementById('divContent').style.top=0;
document.getElementById('scrinside').style.top=(-alturadef/factor)+1;
}
else
{alturadef=alturadef+30;
  document.getElementById('divContent').style.top=alturadef;
  document.getElementById('scrinside').style.top=(-alturadef/factor)+1;
  }
   }}
  
}
var alturadef=0;
  var alturacontenedor;
  var alturadiferencial;
  var factor;
  var alturascroll;
function hallarbarra()
{
  document.getElementById('divContent').style.top=0;
  document.getElementById('scrinside').style.top=1;
 alturadef=0;
  var alturacontenedor=document.getElementById('divContainer').offsetHeight;
  var barrascroll=document.getElementById('divContent').offsetHeight/alturacontenedor;
  var valorbarra=document.getElementById('Layerscroll').offsetHeight/barrascroll;
 
  if (valorbarra>=320){
	  document.getElementById('Layerscroll').style.position="absolute";
	 	document.getElementById('Layerscroll').style.top=-1000;
		document.getElementById('Layerscroll').style.left=-1000;
		activarscroll=0; 
		valorbarra=0;
	   }
	   else{
		   document.getElementById('Layerscroll').style.position="relative";
	 	document.getElementById('Layerscroll').style.top=0;
		document.getElementById('Layerscroll').style.left=0;
		activarscroll=1;  
		   }
  document.getElementById('scr').style.height=valorbarra;
  alturascroll=document.getElementById('Layerscroll').offsetHeight- document.getElementById('scrinside').offsetHeight;
   alturadiferencial =document.getElementById('divContent').offsetHeight-alturacontenedor;
   factor=alturadiferencial/alturascroll;

if (window.addEventListener) {
	
	
var mapElem = document.getElementById('divContent');
mapElem.addEventListener("DOMMouseScroll", handleMouseWheel, true); }
else { document.getElementById('divContent').onmousewheel = handleMouseWheel; }

}

document.onmousedown=ddInit;
document.onmouseup=Function("ddEnabled=false;");

//---------------------------------
