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 recuperarClave(base) {
	window.open(base+"/forgotPassword.aspx", "myWindow", "status = 1, height = 163, width = 372, resizable = 0" );
}


function error_alert(errorcode){
	switch(errorcode){
			case 1:
				alert('Usuario o contrasena incorrectos');
			break;
			case 2:
				alert('Hubo un error en la votación. Inténtelo en unos minutos');
			break;
			case 3:
				alert('En este momento no se pueden realizar compras en el portal. Contáctenos para más información.');
			break;
			case 4:
				alert('Se produjo un error en el proceso de pago. Contáctenos para más información.');
			break;
			case 5:
				alert('El producto seleccionado no posee el stock suficiente.');
			break;
			case 6:
				alert('El nombre de usuario ya existe');
			break;
			case 7:
				alert('Hubo un error al intentar actualizar sus datos');
			break;
			case 8:
				alert('Error en el costo de envío');
			break;
			case 9:
				alert('El registro ha sido removido o se encuentra deshabilitado');
			break;
			case 10:
				alert('Su cuenta se encuentra inactiva. Contáctenos para más información.');
			break;
			case 666:
				alert('Se ha producido un error');
			break;
	}
	if(errorcode>0){
	document.location.reload();
	}
}

var consultaMode=0;
function showConsulta(){
	var formulario_consulta = document.getElementById('contact_form');
	if(consultaMode==0){
		formulario_consulta.style.display="inline";
		consultaMode=1;
	}else{
		formulario_consulta.style.display="none";
		consultaMode=0;
	}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
/*
function MM_setTextOfTextfield(formulario,objId,x,newText,checkText) { //v9.0
  with (document){
	if(getElementById){
		  var obj = document.forms[formulario][objId];
	}
	if(obj && obj.value==checkText){
		obj.value = newText;
	}
  }
}
*/
function MM_setTextOfTextfield(formulario,objId,x,newText,checkText) { //v9.0
  with (document){
	if(getElementById){
		  var obj = document.forms[formulario][objId];
	}
	if(obj && obj.value==checkText){
		obj.value = newText;
	}
  }
}

function MM_resetField(formulario,objId,checkText) { //v9.0
  with (document){
	if(getElementById){
		  var obj = document.forms[formulario][objId];
	}
	if(obj && obj.value==""){
		obj.value = checkText;
	}
  }
}

function getElementsByClassName(clsName){
   var i;
   var matches=new Array();
   var els = document.getElementsByTagName('*');
   for(i=0; i<els.length; i++) {
      if(els.item(i).className==clsName) {
         matches.push(els.item(i));
      }
   }
   return matches;
}

function openmenu(cual,url){
			if(categoriaexpand && categoriaexpand!=0 && categoriaexpand!=cual){
				var occb = getElementsByClassName('padre_'+categoriaexpand);
				if(occb && occb.length>0){				
					for(i=0;i<occb.length;i++){
						occb[i].style.display="none";				
					}
				}				
			}
			var occ = getElementsByClassName('padre_'+cual);
			if(occ && occ.length>0){				
				for(i=0;i<occ.length;i++){
					occ[i].style.display="inline-block";				
				}
				categoriaexpand=cual;
			}else{
				document.location.href=url;	
			}

}


function __setKw(){
	document.getElementById('Keywords').value = document.getElementById('Name').value;
}
function setCategoria(valor,nombre){
	document.getElementById('textsearch').innerHTML = nombre;
	document.getElementById('nav').style.display = "none";
	document.getElementById('Id').value = valor;
	setTimeout( function(){	document.getElementById('nav').style.display = "inline";},2);
	//document.buscador.Name.focus();
}
function setHidden(campo,valor,lista,nombre){
	document.getElementById('nav'+lista).style.display = "none";
	document.getElementById(campo).value = valor;
	document.getElementById('textsearch_'+lista).innerHTML = "<font color='#000000'><b>"+nombre+"</b></font>";
	setTimeout( function(){	document.getElementById('nav'+lista).style.display = "inline";},2);
}

function inspector(el) {
var str ="";
for (var i in el){
	str+= i + ": " + el.getAttribute(i) + "<br>";
}
document.write(str);
}

function qty_add(sumar,minStock,stock){
	var cantidad_form = document.getElementById('Quantity');
	var cantidad = parseInt(cantidad_form.value);
	if(sumar > 0){
		if(stock > cantidad){
			cantidad_form.value=cantidad+1;
		}		
	}else{
		if(cantidad > minStock && cantidad > 1){
			cantidad_form.value=cantidad-1;
		}
	}	
}


function MM_validateFormSuscribe() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateFormSuscribe.arguments;
    for (i=0; i<(args.length-2); i+=3){
		test=args[i+2];
		val=document.forms['susc'].elements[(args[i])];	
		
		if(val.value=="nombre y apellido" || val.value=="e-mail"){			
			valor="";
		}else{
			valor=val.value;
		}
		
		if (val){
			nm=val.name;
			if(nm=="suscriberFirstName"){
				nm="nombre y apellido";
			}
			if(nm=="suscriberName"){
				nm="e-mail";
			}
			if((val=valor)!=""){
				if (test.indexOf('isEmail')!=-1) {
					p=val.indexOf('@');
					if (p<1 || p==(val.length-1)) errors+='- '+val+' no es un email válido.\n';
				}else if (test!='R') {
					num = parseFloat(val);
					if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
					if (test.indexOf('inRange') != -1) {
						p=test.indexOf(':');
						min=test.substring(8,p);
						max=test.substring(p+1);
						if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
					}
				}
			}else if(test.charAt(0) == 'R')errors += '- '+nm+' debe estar completo.\n';
		}
    }
	if (errors) alert('Error al enviar el formulario:\n'+errors);
    document.MM_returnValue = (errors == '');
} }



function MM_validateFormLogin() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateFormLogin.arguments;
    for (i=0; i<(args.length-2); i+=3){
		test=args[i+2];
		val=document.forms['login'].elements[(args[i])];	
		if(val.value=="usuario" || val.value=="password"){			
			valor="";			
		}else{
			valor=val.value;	
		}
		if (val){
			nm=val.name;
			if(nm=="customerName"){			
				nm="usuario";	
			}
			if(nm=="customerPassword"){			
				nm="password";	
			}
			if((val=valor)!=""){
				if (test.indexOf('isEmail')!=-1) {
					p=val.indexOf('@');
					if (p<1 || p==(val.length-1)) errors+='- '+val+' no es un email válido.\n';
				}else if (test!='R') {
					num = parseFloat(val);
					if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
					if (test.indexOf('inRange') != -1) {
						p=test.indexOf(':');
						min=test.substring(8,p);
						max=test.substring(p+1);
						if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
					}
				}
			}else if(test.charAt(0) == 'R')errors += '- '+nm+' debe estar completo.\n';
		}
    }
	if (errors) alert('Error al enviar el formulario:\n'+errors);
    document.MM_returnValue = (errors == '');
} }



function MM_validateFormContact() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateFormContact.arguments;
    for (i=0; i<(args.length-2); i+=3){
		test=args[i+2];
		val=document.forms['consulta'].elements[(args[i])];	
		/*
		if(val.value=="nombre y apellido" || val.value=="email"){			
			valor="";			
		}else{
			valor=val.value;	
		}
		*/
		valor=val.value;
		if (val){
			nm=val.name;
			if(nm=="txtFirstName"){			
				nm="Nombre y Apellido";	
			}
			if(nm=="txtEmail"){			
				nm="E-mail";	
			}
			if(nm=="Comentario"){			
				nm="Comentario";	
			}
			if((val=valor)!=""){
				if (test.indexOf('isEmail')!=-1) {
					p=val.indexOf('@');
					if (p<1 || p==(val.length-1)) errors+='- '+val+' no es un email válido.\n';
				}else if (test!='R') {
					num = parseFloat(val);
					if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
					if (test.indexOf('inRange') != -1) {
						p=test.indexOf(':');
						min=test.substring(8,p);
						max=test.substring(p+1);
						if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
					}
				}
			}else if(test.charAt(0) == 'R')errors += '- '+nm+' debe estar completo.\n';
		}
    }
	if (errors) alert('Error al enviar el formulario:\n'+errors);
    document.MM_returnValue = (errors == '');
} }


function MM_validateFormComment() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateFormComment.arguments;
    for (i=0; i<(args.length-2); i+=3){
		test=args[i+2];
		val=document.forms['myform'].elements[(args[i])];	
		if(val.value=="nombre y apellido" || val.value=="email"){			
			valor="";			
		}else{
			valor=val.value;	
		}
		if (val){
			nm=val.name;
			if(nm=="postName"){			
				nm="nombre";	
			}
			if(nm=="postMail"){			
				nm="email";	
			}
			if(nm=="postText"){			
				nm="comentario";	
			}
			if((val=valor)!=""){
				if (test.indexOf('isEmail')!=-1) {
					p=val.indexOf('@');
					if (p<1 || p==(val.length-1)) errors+='- '+val+' no es un email válido.\n';
				}else if (test!='R') {
					num = parseFloat(val);
					if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
					if (test.indexOf('inRange') != -1) {
						p=test.indexOf(':');
						min=test.substring(8,p);
						max=test.substring(p+1);
						if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
					}
				}
			}else if(test.charAt(0) == 'R')errors += '- '+nm+' debe estar completo.\n';
		}
    }
	if (errors) alert('Error al enviar el formulario:\n'+errors);
    document.MM_returnValue = (errors == '');
} }



function MM_validateFormServices() { //v4.0

  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateFormServices.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
		
		
		if(val.value=="Número de Orden" || val.value=="N&uacute;mero de Orden"){			
			valor="";
			terror="Por favor complete el número de orden";
		}else if(val.value=="buscar..."){			
			valor="";
			terror="Por favor ingrese el texto a buscar";
		}else{
			valor=val.value;
		}
		
		//alert(valor);
		
      if (val) { nm=val.name; if ((val=valor)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
    } if (errors) alert(terror);
    document.MM_returnValue = (errors == '');
} }


function MM_validateFormReg() { //v4.0
error_text="Error al enviar el formulario";	
error_email="no es un email válido";
error_pie="debe estar completo";

  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateFormReg.arguments;	
	var k = 0;
    for (i=0; i<(args.length-2); i+=3){
		test=args[i+2];
		val=document.forms['f_registracion'][args[i]];
		valor=val.value;
		
		if (val){
			nm=val.name;			
			if(nm=="customerName"){			
				nm="email";	
			}
			if(nm=="customerPassword"){			
				nm="password";	
			}
			if(nm=="customerCompany"){			
					nm="empresa";	
			}
			
			if(nm=="customerIdentificationNumber"){			
				nm="CUIT";
			}
			
			if(nm=="customerFirstName"){	
					nm="Nombre";	
			}
			if(nm=="customerLastName"){	
					nm="Apellido";	
			}
			if(nm=="customerPhone"){			
					nm="Teléfono";	
			}
			if(nm=="customerAddress"){			
					nm="Domicilio";	
			}
			if(nm=="customerCity"){			
					nm="Localidad";	
			}
			if(nm=="customerCountry"){			
					nm="País";	
			}
			if(nm=="customerState"){			
					nm="Provincia";	
			}
			if(nm=="customerPostalCode"){			
					nm="Código Postal";	
			}
			if(valor!="" && valor!=nm){
				if (test.indexOf('isEmail')!=-1) {
					p=valor.indexOf('@');
					if (p<1 || p==(valor.length-1)) errors+='- '+valor+' '+error_email+'.\n';
				}else if (test!='R') {
					num = parseFloat(val);
					if (isNaN(valor)) errors+='- '+nm+' must contain a number.\n';
					if (test.indexOf('inRange') != -1) {
						p=test.indexOf(':');
						min=test.substring(8,p);
						max=test.substring(p+1);
						if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
					}
				}
			}else if(test.charAt(0) == 'R')errors += '- '+nm+' '+error_pie+'.\n';
		}
    }
	if (errors) alert(error_text+':\n'+errors);
    document.MM_returnValue = (errors == '');
} }





						function buildMarcas(){
							var espacioMarcas = document.getElementById('marcas_cat');
							var conc = '';
							var mass=1;
							conc += '<select name="marcas_sel" id="marcas_sel" onchange="subMarcas(this.options[this.selectedIndex].value,this.options[this.selectedIndex])"> <option class="optionoff" disabled="disabled" selected="selected">Seleccione la marca</option>';
							if(marq.length>1){
								for(m=1;m<marq.length;m++){
									if(marq[m][2]==2){
										var ssel ="";
										if( (marcaId && marcaId==marq[m][1])){
											ssel=" selected='selected'";
											hayMarcaSel=mass;										
										}
										conc += "<option value='"+marq[m][1]+"' id='op_marca_"+m+"'"+ssel+">"+marq[m][0]+"</option>\n";
										mass++;
									}
								}
							}
							conc += ' </select>';
							espacioMarcas.innerHTML = conc;
						}
						
						function buildCategorias(){	
							if(buscadorPadre==0){
								buscadorPadre = buscarCat(buscadorId);
				 			}
							var mass=1;
							var espacioCat = document.getElementById('cat');
							var conc = '';
							conc += '<select name="cat_sel" id="cat_sel" onchange="subCat(this.options[this.selectedIndex].value,this.options[this.selectedIndex])"> <option class="optionoff" disabled="disabled" selected="selected">Seleccione el tipo de parte</option> ';
							if(cats.length>1){								
								for(m=1;m<cats.length;m++){
									if(cats[m][2]==2){
										var ssel ="";
										if( (buscadorId && buscadorId==cats[m][1]) || (buscadorPadre && buscadorPadre==cats[m][1]) ){
											ssel=" selected='selected'";
											hayCatSel = mass;	
										}
										conc += "<option value='"+cats[m][1]+"' id='op_cat_"+m+"'"+ssel+">"+cats[m][0]+"</option>\n";
										mass++;
									}
								}
							}
							conc += ' </select>';
							espacioCat.innerHTML = conc;			

						}
						
						function subMarcas(marca,orden){

							if(marca && marca>0){
								var espacioSubMarcas = document.getElementById('marcas_subcat');
								document.getElementById('SearchButton').className  = "header_search_boton_on";
								document.getElementById('SearchButton').disabled  = false;	
								var mass=1;
								var conc2 = '';
								conc2 += '<select name="submarcas_sel" id="submarcas_sel" onchange="setCategoria(this.options[this.selectedIndex].value,0)"> <option value="-1" selected="selected">Todos</option>';								
									for(m=1;m<marq.length;m++){
										if(marq[m][3]==marca){
											var ssel ="";
											if(modeloId && modeloId==marq[m][1]){
											   ssel=" selected='selected'";
											   haySubMarcaSel = marq[m][1];
											}
											conc2 += "<option value='"+marq[m][1]+"'"+ssel+">"+marq[m][0]+"</option>\n";
											mass++;
										}
									}
								conc2 += '</select>';				
								espacioSubMarcas.innerHTML = conc2;
								marcaSel=orden.id;
								setCategoria(marca,0);
							}else{					
								var catOrig = document.getElementById(marcaSel);								
								catOrig.selected = true;
							}			
						}
						
						function subCat(catt,orden){
							setCategoria(0,catt);
							if(catt && catt>0){
								var espacioSubCat = document.getElementById('subcat');								
								var conc2 = '';
								conc2 += '<select name="subcat_sel" id="subcat_sel" onchange="setCategoria(0,this.options[this.selectedIndex].value)"> <option value="-1" selected="selected">Todos</option> ';								
									for(m=1;m<cats.length;m++){										
										if(cats[m][3]==catt){
											var ssel ="";
											if( (buscadorId && buscadorId==cats[m][1]) || (buscadorPadre && buscadorPadre==cats[m][1]) ){
												ssel=" selected='selected'";
												haySubCatSel = cats[m][1];
											}
											conc2 += "<option value='"+cats[m][1]+"'"+ssel+">"+cats[m][0]+"</option>\n";
										}
									}
								conc2 += '</select>';				
								espacioSubCat.innerHTML = conc2;
								catIdSel=orden.id;
								//setCategoria(marca,0);
							}else{					
								var subcatOrig = document.getElementById(catIdSel);								
								subcatOrig.selected = true;
							}			
						}
						
						
						function buscarPadre(id){
							for(i=0;i<marq.length;i++){
								var elemento = marq[i];
								if(elemento[1]==id && elemento[2]==3){
									return elemento[3];
								}								
							}							
						}
						function buscarCat(id){
							for(i=0;i<cats.length;i++){
								var elemento = cats[i];
								if(elemento[1]==id && elemento[2]==3){
									return elemento[3];
								}								
							}							
						}
						
						function setCategoria(marca,categoria){
							//si le paso el tipo de categoria
							document.getElementById('SearchButton').disabled  = false;
							document.getElementById('SearchButton').className  = "header_search_boton_on";
							if(categoria!=0){								
								if(categoria!=-1){
									if(modeloSel!=-1){
										document.getElementById('Categories').value = categoria+","+modeloSel;
									}else{
										document.getElementById('Categories').value = categoria+",";
									}
									catSel = categoria;
								}else{
									var padre = document.getElementById('cat_sel').options[document.getElementById('cat_sel').selectedIndex].value;
									if(modeloSel!=-1){
										if(padre && padre!=-1){
										document.getElementById('Categories').value = padre+","+modeloSel;
										}else{
										document.getElementById('Categories').value = ","+modeloSel;	
										}
									}else{
										if(padre && padre!=-1){
										document.getElementById('Categories').value = padre+",";
										}
									}
								}
							}else if(marca!=0){
								if(marca!=-1){
									var padre = buscarPadre(marca);
									if(padre){
										modeloSel=padre+","+marca;
									}else{
										modeloSel=marca;
									}
									if(catSel && catSel!=-1){
									document.getElementById('Categories').value = catSel+","+modeloSel;
									}else{
									document.getElementById('Categories').value = ","+modeloSel;
									}
								}else{
									setCategoria(document.getElementById('marcas_sel').options[hayMarcaSel].value,categoria)
								}						
							}							
						}					

function desplegar(cual,url){
			if((categoriaexpand!=0 && categoriaexpand!=cual) || categoriaexpand==0){
					if(categoriaexpand!=0){
						$('.btn-child-'+categoriaexpand).css("display","none");
						$('.btn-'+categoriaexpand).css("background-image","url("+RootPath+"/Templates/_css/_img/menu-left-btn.gif)");
					}
					var btnChild = $('.btn-child-'+cual).css("display","inline-block");
					if(btnChild.length>0){
						$('.btn-'+cual).css("background-image","none");
						//btnChild[btnChild.length-1].style.marginBottom='15px';
					}else{						
						document.location.href = url;	
					}
				categoriaexpand=cual;
				
			}else if(categoriaexpand==cual){
					$('.btn-child-'+categoriaexpand).css("display","none");
					$('.btn-'+categoriaexpand).css("background-image","url("+RootPath+"/Templates/_css/_img/menu-left-btn.gif)");
				categoriaexpand=0;
			}
}



function autoDesplegar(){	
	if(idPage && idPage.length > 1){		
		var btnChild = $('.btn-child-'+idPage[1]).css("display","inline-block");
		if(btnChild.length>0){
			//$('.btn-'+idPage[1]).css("background-image","none");
			//btnChild[btnChild.length-1].style.marginBottom='15px';
			categoriaexpand=idPage[1];
		}
	}
	if(idPage && idPage.length > 2){
		var btnChild = document.getElementById('btn-'+window.idPage[2]);
		if(btnChild){
			//btnChild.removeAttribute("href");
			btnChild.className = 'boton-2-sel';
		}
	}
	
}


function setDate__(inp){
    $('#'+inp).val($('#'+inp+'_d').val()+'-'+$('#'+inp+'_m').val()+'-'+$('#'+inp+'_y').val());

}


function _dispFdata(OPath, fid, ttl){
            var url=OPath+'/_fdef.aspx?Id='+fid;
              var $dlg = $('<div> <p align="center">Espere por favor...</p><p align="center"><img src="'+OPath+'/Templates/_css/_img/loader.gif" border="0" /></p></div>').appendTo('body');								 
                $dlg.dialog({
				        modal:true,
				        width:500,
				        height: 500,
				        title:ttl
				    });
				    $.get(url, function(data){  
				  
				        $dlg.html(data);				        			        				        
				    });             
            return false;
    }
