﻿function recuperarClave() {
	window.open( "forgotPassword.aspx", "myWindow", "status = 1, height = 243, 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 ha sido desactivada. 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 desplegar(cual){
	  with (document){
		if(getElementById){	
			//alert(categoriaexpand + " - " + cual);
			if((categoriaexpand!=0 && categoriaexpand!=cual) || categoriaexpand==0){
				var obj2 = getElementById('boton_1_hijos_'+categoriaexpand);
				if(obj2){
					obj2.className = "boton_1_hijos";
				}
				var obj = getElementById('boton_1_hijos_'+cual);
				if(obj){
					obj.className = "boton_1_hijos_on";
					categoriaexpand=cual;
				}
			}else if(categoriaexpand==cual){
				var obj = getElementById('boton_1_hijos_'+cual);
				if(obj){
					obj.className = "boton_1_hijos";
					categoriaexpand=0;
				}	
			}			
		}
	  }
}
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=="email"){			
			valor="";			
		}else{
			valor=val.value;	
		}
		if (val){
			nm=val.name;
			if(nm=="customerName"){			
				nm="nombre y apellido";	
			}
			if(nm=="customerEmail"){			
				nm="email";	
			}
			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;	
		}
		if (val){
			nm=val.name;
			if(nm=="txtFirstName"){			
				nm="nombre y apellido";	
			}
			if(nm=="txtEmail"){			
				nm="email";	
			}
			if(nm=="Comentario"){			
				nm="consulta";	
			}
			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 _viewProductDetails(id) {
				
				var $data = $('<div> <p align="center"><img src="/Templates/_includes/_NGNAjaxLogin/loader.gif" border="0" /></p></div>').appendTo('body');								 
				    $data.dialog({
				        modal:true,
				        width:400
				    });
				    $data.load('/Cm/DetSmall.aspx?Id='+id);
			
				
				/*var $data = $('<div></div>').load('/Cm/DetSmall.aspx?Id='+id,function() {
				    $data.appendTo('body');
				    $data.dialog({
				        modal:true,
				        width:400
				    });
				    
				} );
				*/
				/*
				var src = $link.attr('href');
				var title = $link.siblings('img').attr('alt');
				var $modal = $('img[src$="'+src+'"]');

				if ($modal.length) {
					$modal.dialog('open')
				} else {
					var img = $('<img alt="'+title+'" width="384" height="288" style="display:none;padding: 8px;" />')
						.attr('src',src).appendTo('body');
					setTimeout(function() {
						img.dialog({
								title: title,
								width: 400,
								modal: true
							});
					}, 1);
				}*/
				return false;
			}


function _selShippingA(id){
    var $holder = $('#_shipOptHolder');
    $('div.blockMe').block({ message: null });
    
    //$holder.html('<div> <p align="center"><img src="/Templates/_includes/_NGNAjaxLogin/loader.gif" border="0" /></p></div>');    
    $holder.load('/Cm/_shippingSel.aspx?selDir='+id,function() {
				    
				   $('#_pmtPM').load('/Cm/_shippingMethods.aspx', function(){
				   
				        $('div.blockMe').unblock({ message: null });
				   })
				   
				   // $('div.blockMe').unblock({ message: null });
                                           
				    //$holder.unblock(); 
				    
				} );
				return false;
}


function _sendWL(){

	var $data = $('<div> <p align="center"><img src="/Templates/_includes/_NGNAjaxLogin/loader.gif" border="0" /></p></div>').appendTo('body');								 
				    $data.dialog({
				        title:'Enviar Lista de deseos',
				        modal:true,
				        width:400
				    });
				    $data.load('/Cm/SendWl.aspx', function(){
				        $('#sndM').click(function() {
				        
				         $.get('/_bfw.aspx?_action=_sm&MailTo='+$('#fMAilTo').val(), function(dato){  
				                /*if(dato=='0')
				                
				                $dlg.html(dato);*/
				                $data.dialog('close');
				                			        				        
				            });
				        
				        
                      
                        });
				    });
}



function setCookie(name, value)
         {
         //If name is the empty string, it places a ; at the beginning
         //of document.cookie, causing clearCookies() to malfunction.
         
       var days = 30;
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();    	
	   
         
         if(name != '')
             document.cookie = name+"="+value+expires+"; path=/";
         }

function getCookie(name)
         {
         //Without this, it will return the first value 
         //in document.cookie when name is the empty string.
         if(name == '')
            return('');
         
         name_index = document.cookie.indexOf(name + '=');
         
         if(name_index == -1)
            return('');
         
         cookie_value =  document.cookie.substr(name_index + name.length + 1, 
                                                document.cookie.length);
         
         //All cookie name-value pairs end with a semi-colon, except the last one.
         end_of_cookie = cookie_value.indexOf(';');
         if(end_of_cookie != -1)
            cookie_value = cookie_value.substr(0, end_of_cookie);

         //Restores all the blank spaces.
         space = cookie_value.indexOf('+');
         while(space != -1)
              { 
              cookie_value = cookie_value.substr(0, space) + ' ' + 
              cookie_value.substr(space + 1, cookie_value.length);
							 
              space = cookie_value.indexOf('+');
              }

         return(cookie_value);
         }

function clearCookie(name)
         {                  
         expires = new Date();
         expires.setYear(expires.getYear() - 1);

         document.cookie = name + '=null' + '; expires=' + expires; 		 
         }
         
function clearCookies()
         {
         Cookies = document.cookie;
         Cookie = Cookies;
         expires = new Date();
         expires.setYear(expires.getYear() - 1);

         while(Cookie.length > 0)
              {
              //All cookie name-value pairs end with a semi-colon, except the last one.
              Cookie = Cookies.substr(0, Cookies.indexOf(';'));
              Cookies = Cookies.substr(Cookies.indexOf(';') + 1, Cookies.length);

              if(Cookie != '')
                 document.cookie = Cookie + '; expires=' + expires;
              else
                 document.cookie = Cookies + '; expires=' + expires;			  			  	  
              }		 		 
         }


         $(function() {




         /* State in regis */

         /* sel state! */
         $('#_frUs_ #customerState').change(function() {


                var _stSel = $('#_frUs_ #customerState option:selected').val();
             if (_stSel == '1') {
                 $('#ctdid_City').html('Barrio');
                 $('#ctrid_Department').hide();

                 $('#customerCitySel').attr('name', 'customerCity');
                 $('#customerCitySel').show();

                 $('#customerCity').attr('name', 'customerCityNo');
                 $('#customerCity').hide();

                 var oldSelVal = $('#customerCity').val();
                 $("#customerCitySel").val(oldSelVal).attr("selected", "selected");
                 //$("#aDepartment").val(oldSelVal);
             } else {

                $('#ctdid_City').html('Ciudad');
                $('#ctrid_Department').show();
                $('#customerCitySel').attr('name', 'customerCityNo');
                $('#customerCitySel').hide();
                $('#customerCity').attr('name', 'customerCity');
                $('#customerCity').show();
                 //$('#aCity').val($('#aCitySel option:selected').val());

             }


         });




             /* sel state! */
             $('#modShp #aState').change(function() {


                 var _stSel = $('#modShp #aState option:selected').val();
                 if (_stSel == '1') {
                     $('#td_City').html('Barrio');
                     $('#tr_Department').hide();

                     $('#aCitySel').attr('name', 'aCity');
                     $('#aCitySel').show();

                     $('#aCity').attr('name', 'aCityNo');
                     $('#aCity').hide();

                     var oldSelVal = $('#aCity').val();
                     $("#aCitySel").val(oldSelVal).attr("selected", "selected");
                     //$("#aDepartment").val(oldSelVal);
                 } else {

                     $('#td_City').html('Ciudad');
                     $('#tr_Department').show();
                     $('#aCitySel').attr('name', 'aCityNo');
                     $('#aCitySel').hide();
                     $('#aCity').attr('name', 'aCity');
                     $('#aCity').show();
                     //$('#aCity').val($('#aCitySel option:selected').val());

                 }


             });


             //selecciona el barrio
             $('#modShp #aCitySel').change(function() {
                 $('#aDepartment').val($('#aCitySel option:selected').val());
             });

             if (/*getCookie('new-wl-news')==''*/1 != 1) {
                 setCookie('new-wl-news', '0134nd4923784yjndwe')
                 var $data = $('<div><a href="http://www.cdmarket.com.ar/View/3479/killzone-3.aspx"><img src="http://www.cdmarket.com.ar/img/killzone3-popup.jpg" border="0"/></a</div>').appendTo('body');
                 $data.dialog({
                     title: 'Novedades en CD Market!',
                     modal: true,
                     width: 545,
                     height: 600
                 });

             }

         });
    
