var tipo_papel;
var imagen_actual_mediana;
var posx;
var posy;
var strComparar = "";
var intSKU 		= 0;
var imagen_actual_mediana;
document.onclick = GetMousePosition;

$(document).ready(function() { 
	ResolutionSet();
});

function ResolutionSet() {
	w = $(window).width();
	h = $(window).height();
	
	$.post("i_browser_ajax.asp", { w: w, h: h },
	function(data){
		//alert("Data Loaded: " + data);
	});	
}

function GetMousePosition(e)
{
  if (!e) var e = window.event;
  if (e.pageX || e.pageY)
  {
     posx = e.pageX;
     posy = e.pageY;
  }
  else if (e.clientX || e.clientY)
  {
     posx = e.clientX + document.body.scrollLeft;
     posy = e.clientY + document.body.scrollTop;
  }	
}

function SolicitudPersonalizacion(sku) {

	if(sku != "") {
		var url = "solicitud_pers.asp";
		$.post(url, { ajax: "S", sku: sku },
		function(data){
			data = unescape(data);			
		});	
	
	}

}

function WinOpen(strArchivo, strVentana, strPropiedades)
{a = window.open(strArchivo,strVentana,strPropiedades);}

function valNumerico(evento) {
	evento = window.event ? evento.keyCode : evento.which;
	if (
	(evento == 46 || evento == 8 || evento == 9) ||
	(evento > 34 && evento < 41) || 
	(evento > 47 && evento < 58) || 
	(evento > 95 && evento < 106) || 
	(evento >= 112 && evento <=123) 
     ) {
	   return true;
	} else {
	   return false;
	}	
}

function Set_Cookie( name, value, expires, path, domain, secure )
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	/*
	if the expires variable is set, make the correct
	expires time, the current script below will set
	it for x number of days, to make it for hours,
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )
	{
	expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
	( ( path ) ? ";path=" + path : "" ) +
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

function Delete_Cookie( name, path, domain ) {
if ( Get_Cookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function CallMe() {

	var url = "callme.asp";
	$.post(url, { ajax: "S", h: h },
	function(data){
		data = unescape(data);			
		alert(data);		
	});	
 }

function cambia_cmbMarca(equipo_id) {

	if(equipo_id != "") {

		//var url = "i_insumos_ajax.asp?equipo_id=" + equipo_id;
		var url = "i_insumos_ajax.asp";

		$.post(url, { equipo_id: equipo_id},
		function(data){

			//Elimina los resultados actuales
			var divInsumos = document.getElementById("divInsumos");

			if (divInsumos!=null) {
			   divInsumos.style.visibility = "hidden";
			}
				
			var cmbMarca = document.getElementById("cmbMarca");			
			//Elimina el contenido del combo que se va a cargar
			while (cmbMarca.length >1) {
			  cmbMarca.options[1] = null;
			}

			//Elimina el contenido del combo Modelo
			var cmbModelo = document.getElementById("cmbModelo");
			if(cmbModelo!=null) {
			  while (cmbModelo.length >1) {
				 cmbModelo.options[1] = null;
			  }
			}
				
			var arrRegistros = data.split("#");
			if(arrRegistros.length >0) {
				  
			  for(var i=0;i<arrRegistros.length;i++) {			
				 var arrItem  = arrRegistros[i].split("|");
				 if(arrItem[0]!= "") {		   			        
					//Agrega los nuevos valores.			
					oOption = new Option(arrItem[1], arrItem[0]);
					try {
					   cmbMarca.add(oOption, null);
					} catch(ex) {
					   cmbMarca.add(oOption);
					}
				 }
			  }
			}		
		
		
		});	
	}
}

function cambia_cmbModelo(marca_id) {
		
	if(marca_id != "") {
		var url = "i_insumos_ajax.asp";

		$.post(url, { marca_id: marca_id},
		function(data){
		
			var cmbModelo = document.getElementById("cmbModelo");
				
			//Elimina los resultados actuales
			var divInsumos = document.getElementById("divInsumos");
			if (divInsumos!=null) {
			   divInsumos.style.visibility = "hidden";
			}
							
			//Elimina el contenido del combo que se va a cargar
			while (cmbModelo.length >1) {
			  cmbModelo.options[1] = null;
			}

			var arrRegistros = data.split("#");
			if(arrRegistros.length >0) {
				  
			  for(var i=0;i<arrRegistros.length;i++) {			
				 var arrItem  = arrRegistros[i].split("|");
				 if(arrItem[0]!= "") {		   			        
					//Agrega los nuevos valores.			
					oOption = new Option(arrItem[1], arrItem[0]);
					try {
					   cmbModelo.add(oOption, null);
					} catch(ex) {
					   cmbModelo.add(oOption);
					}
				 }
			  }
			}		
		
		
		});
	}
}

//$(function()
//{
//	if (Get_Cookie("Carrito") == "" || Get_Cookie("Carrito") == null) {Set_Cookie( "Carrito", 'MAX', 30, '/', '', '' );}
//	if (Get_Cookie("Insumos") == "" || Get_Cookie("Insumos") == null) {Set_Cookie( "Insumos", 'MAX', 30, '/', '', '' );}	
//
//	$("#mostrar_carrito").click(function(event) {
//		if (Get_Cookie('Carrito') == "MIN") {Set_Cookie( 'Carrito', 'MAX', 30, '/', '', '' ); document.images["cab_carrito"].src = 'img_argentina/cab_carrito_min.gif';}
//		else if (Get_Cookie('Carrito') == "MAX") {Set_Cookie( 'Carrito', 'MIN', 30, '/', '', '' ); document.images["cab_carrito"].src = 'img_argentina/cab_carrito_max.gif';}
//		else {
//			Set_Cookie( 'Carrito', 'MAX', 30, '/', '', '' );
//			if (document.images["cab_carrito"].src == 'img_argentina/cab_carrito_max.gif'){
//				document.images["cab_carrito"].src = 'img_argentina/cab_carrito_min.gif';
//			}
//			else
//			{
//				document.images["cab_carrito"].src = 'img_argentina/cab_carrito_max.gif'; 
//			}
//		}
//
//		event.preventDefault();
//		
//		$("#caja_carrito").slideToggle("show");
//		
//});

//	if (Get_Cookie('Carrito') == "MIN") {Set_Cookie( 'Carrito', 'MAX', 30, '/', '', '' ); document.images["cab_carrito"].src = 'img_argentina/cab_carrito_min.gif';}
//	else if (Get_Cookie('Carrito') == "MAX") {Set_Cookie( 'Carrito', 'MIN', 30, '/', '', '' ); document.images["cab_carrito"].src = 'img_argentina/cab_carrito_max.gif';}
//
//		
//	$("#mostrar_insumos").click(function(event) {
//
//		if (Get_Cookie('Insumos') == "MIN") {Set_Cookie( 'Insumos', 'MAX', 30, '/', '', '' ); document.images["cab_busca_insumos"].src = 'img_argentina/cab_busca_insumos_min.gif';}
//		else if (Get_Cookie('Insumos') == "MAX") {Set_Cookie( 'Insumos', 'MIN', 30, '/', '', '' ); document.images["cab_busca_insumos"].src = 'img_argentina/cab_busca_insumos_max.gif';}
//		else {
//			Set_Cookie( 'Insumos', 'MAX', 30, '/', '', '' );
//			if (document.images["cab_busca_insumos"].src == 'img_argentina/cab_busca_insumos_max.gif'){
//					document.images["cab_busca_insumos"].src = 'img_argentina/cab_busca_insumos_min.gif';
//				}
//			else
//				{
//					document.images["cab_busca_insumos"].src = 'img_argentina/cab_busca_insumos_max.gif'; 
//				}	
//		}
//		
//		event.preventDefault();
//			
//		$("#caja_insumos").slideToggle("show");
//	});

//});

function ShowRecordatorios() {
    var div = document.getElementById("divRecordatoriosmail");
	
	if (div.style.display=="inline") {
		div.style.display="none";
		div.style.visibility="hidden";	
	} else {
		div.style.display="inline";
		div.style.visibility="visible";
	}
}

function ShowAvisoStock() {
    var div = document.getElementById("divAvisoStock");
	
	if (div.style.display=="inline") {
		div.style.display="none";
		div.style.visibility="hidden";	
	} else {
		div.style.display="inline";
		div.style.visibility="visible";
	}
}

function limpiar()
{
  document.getElementById("txtPregNueva").value = "";		
}

function ShowRecomendar()
{
    var div = document.getElementById("divRecomendarProduct");
//alert(div.style.display);
	if (div.style.display=="inline") {
		div.style.display="none";
	
	} else {
		div.style.display="inline";
		
	}
	

}

function Pasar_imagen(archivo)
{

	document.images["producto_g"].src = 'Assets/p/' + archivo + '.jpg'; 
	imagen_actual_mediana = archivo;
	
}
	
function SolapaContenicoFaq(div)
{
	
	
	if (document.getElementById(div).style.display =="inline")
	{
		document.getElementById(div).style.display ="none";
		document.getElementById('ver_pregunta').style.display ="Inline";
		document.getElementById('ocultar_pregunta').style.display ="none";
		document.getElementById("boton_minimizar").style.display ='none';	
		
		
	}
	else
	{
		document.getElementById(div).style.display ="inline"; 
		document.getElementById('ver_pregunta').style.display ="none";
		document.getElementById('ocultar_pregunta').style.display ="inline";
		document.getElementById("boton_minimizar").style.display ='inline';	
	}
	
}

function SolapaContenicoTec(nombrediv)
{	
	if (document.getElementById(nombrediv).style.display =="inline")
	{
		document.getElementById("ver_tecnicas").innerHTML  = 'Ver notas tecnicas'
		document.getElementById(nombrediv).style.display ="none"; 
		
	}
	else
	{
		document.getElementById("ver_tecnicas").innerHTML  = 'Ocultar notas tecnicas'
		document.getElementById(nombrediv).style.display ="inline"; 
		document.getElementById("boton_minimizar").style.display ='inline';	
	}
	
}	
	
function SolapaPrincipal(nombrediv)
{
		
	document.getElementById("boton_minimizar").style.display ='inline';	
	
	if (nombrediv=="especificaciones")
		{
			document.getElementById("prod_bkg_con_b").style.display ='inline';  
			document.getElementById("prod_bkg_sin_b").style.display ='none';  
			document.getElementById("info_faq").style.display ='none';  			
			document.getElementById("prod_Tec").style.display ='inline'; 
		}
	else
		{
			if (document.getElementById('ver_pregunta') != null)
			{
				document.getElementById('ver_pregunta').style.display ="none";
				document.getElementById('ocultar_pregunta').style.display ="inline";
			}
			
			document.getElementById("prod_bkg_sin_b").style.display ='inline';  
			document.getElementById("prod_bkg_con_b").style.display ='none';  			
			document.getElementById("prod_Tec").style.display ='none';  			
			document.getElementById("info_faq").style.display ='inline'; 
			document.getElementById("info_preguntas_frecuentes").style.display ='inline'; 
			
		}

document.getElementById("Tec_mas_tec").style.display ='none'; 

}

function minimizar(codigo)
	{
		document.getElementById("boton_minimizar").style.display ='none'; 
		
		
		if (codigo == 2)
		{
			if (document.getElementById("prod_bkg_con_b").style.display =='inline' || document.getElementById("prod_Tec").style.display =='')
			{
				document.getElementById("prod_Tec").style.display ='none';  
				document.getElementById("prod_Tec").style.position='relative';
				
				document.getElementById("Tec_mas_tec").style.display ='inline'; 
				document.getElementById("ver_tecnicas").innerHTML  = 'Ver notas tecnicas'
				
			}
			else
			{
				document.getElementById("info_preguntas_frecuentes").style.display ="none"; 
				document.getElementById('ver_pregunta').style.display ="Inline";
				document.getElementById('ocultar_pregunta').style.display ="none";
			}
		
		}
		else
		{
			document.getElementById("info_preguntas_frecuentes").style.display ="none"; 
			document.getElementById('ver_pregunta').style.display ="Inline";
			document.getElementById('ocultar_pregunta').style.display ="none";
			
		}
	}	
	
function abrirImagenGrande(strSKU,strName)
{
	WinOpen('product_ampliar.asp?' + 'sku='+ imagen_actual_mediana ,'ProductAmpliar','width=540,height=590,left=158,top=1,screenX=0,screenY=00,resizable=Yes,scrollbars=yes, toolbar=no, location=no, directories=no, status=no, menubar=no, copyhistory=yes')
}


//=================================================================================
function imprime_boleto(strLink)
{
  window.open(strLink,"Boleto","left=0,top=0,height=500,width=700,status=no,toolbar=no,menubar=yes,location=no,scrollbars=yes,resizable=yes");
}
//=====================================================
function imprimir(numero)
{
	var url = "receipt_imprimir.asp?numero=" + numero;
	var a = window.open(url, null,"LOCATION=no,TOOLBAR=no,DIRECTORIES=no,MENUBAR=no,SCROLLBARS=yes,RESIZABLE=no");

	//'TOOLBAR=no,DIRECTORIES=no,MENUBAR=no,SCROLLBARS=NO,RESIZABLE=no,WIDTH=460,HEIGHT=500'
}
//=====================================================
function generaExcel()
{
	document.getElementById("strExcel").value = "S";
	document.getElementById("frm").submit();
	
	//document.redirect();
}
function Setea_accion(accion)
{
	document.getElementById("tipo_accion").value = accion;
	document.formacciones.submit();
}
//=================================================================================
function marca_hit(word)
{
	var url = "similar_hit.asp";

	$.post(url, { strWord: word},
	function(data){
		//alert("Data Loaded: " + data);
	});		
	
}
//=================================================================================
//=================================================================================
function seleccion_comparar(objChk, strSKU)
{
	if(!objChk.checked) {
		strComparar = replaceString(strComparar, strSKU + ",", "");
		intSKU--;

	} else if (intSKU==4) {
		alert("Debe seleccionar como máximo 4 articulos para comparar");
		objChk.checked = false;

	}  else {
		strComparar += strSKU + ",";
		intSKU++;

	} 
  
} 
//=================================================================================
//=================================================================================
function replaceString(sString, sReplaceThis, sWithThis) { 

	if (sReplaceThis != "" && sReplaceThis != sWithThis) {
		var counter = 0;
		var start   = 0;
		var before  = "";
		var after   = "";

		while (counter < sString.length) {
			start = sString.indexOf(sReplaceThis, counter);
			if (start == -1) {
				break;
			} else {
				before  = sString.substr(0, start);
				after   = sString.substr(start + sReplaceThis.length, sString.length);
				sString = before + sWithThis + after;
				counter = before.length + sWithThis.length;
			}
		}
	}

	return sString;
}
//=================================================================================
//=================================================================================
function control_comparar()
{
	if (intSKU < 2)  {
		alert("Debe seleccionar como mínimo 2 artículos para comparar");
	} else {
		document.location.href = "comparar.asp?chkSKU=" + strComparar;
	}
}
//=================================================================================
//=================================================================================
function imprime_boleto(strLink)
{
	window.open(strLink,"Boleto","left=0,top=0,height=500,width=700,status=no,toolbar=no,menubar=yes,location=no,scrollbars=yes,resizable=yes");
}

function CierreCompra() 
{
	document.frmBasket.target.value = "cierre_compra.asp";
	document.frmBasket.submit();
}

function CierreCompraSplit(strUns)
{
	document.frmBasket.target.value = "xt_orderform_split.asp";
	document.frmBasket.uns.value = strUns;
	document.frmBasket.submit();
}

function CambiaAnio(equipo, anio) {
	var url = "mis_maquinas_anio_ajax.asp";
	$.post(url, { modelo_id: equipo, anio: anio },
	function(data){
		//alert("Data Loaded: " + data);
	});		
}

function AvisoStockOpen(sku) {

  document.frmAvisoStock.txtAvisoStockSKU.value = sku;
  document.frmAvisoStock.submit();
  return;

  var div = document.getElementById("divAvisoStock");
  div.style.position="absolute";
  div.style.left = posx - 200;
  div.style.top = posy; 
  div.style.display="inline";
  div.style.visibility="visible";
  
  document.frmAvisoStock.txtAvisoStockSKU.value = sku;
}

function AvisoStockClose() {
  var div = document.getElementById("divAvisoStock");
  div.style.position="absolute";       
  div.style.left = posx - 200;
  div.style.top = posy;  
  div.style.visibility="hidden";  
  div.style.display="none"; 
  
  document.frmAvisoStock.txtAvisoStockSKU.value = "";
  }

function BannersCarga() {
    ResolutionSet();

    var url = "default_banners.asp";
    $.post(url, {  },
    function(data){
        $('#banners').html(data);
    }); 

}

function BorrarCodigo(intI) {
  eval("document.frmRapidoCodigo.qty" + intI + ".value = ''");
  eval("document.frmRapidoCodigo.sku" + intI + ".value = ''");
  document.getElementById("divVal" + intI).innerHTML = "";
  document.getElementById("divSustituto" + intI).innerHTML = "";
  document.getElementById("divAccion" + intI).innerHTML = "";
  document.getElementById("divAccion" + intI).innerHTML = "";
  document.getElementById("divPrecio" + intI).innerHTML = "";
  
}

function ValidaProductos() {
	document.frmRapidoCodigo.accion.value='mas productos';
	document.frmRapidoCodigo.submit();
}

function Mas_productos() {

	document.frmRapidoCodigo.ProdCant.value='30';
	//	alert(document.frmRapidoCodigo.ProdCant.value);
	document.frmRapidoCodigo.submit();
}


function cambia_cmbformato(papel_id,gramaje_id) {
tipo_papel = papel_id

	if (document.getElementById("formato_id_" + papel_id ).value=="0")
	{
		if(papel_id != "" ) {
			
			var url = "i_papel_ajax.asp";

			$.post(url, { papel_id: papel_id, gramaje_id: gramaje_id },
			function(data){

			
				//Elimina los resultados actuales
				var divResultado = document.getElementById("divResultado");

				if (divResultado != null) {
				   divResultado.style.visibility = "hidden";
				}
					
				//Elimina el contenido del combo Modelo
				var formato_id_ = document.getElementById("formato_id_" + tipo_papel );
				if(formato_id_!=null) {
				  while (formato_id_.length >1) {
					 formato_id_.options[1] = null;
				  }
				}
					
				var arrRegistros = res.split("#");
				if(arrRegistros.length >0) {
					  
				  for(var i=0;i<arrRegistros.length;i++) {			
					 var arrItem  = arrRegistros[i].split("|");
					 if(arrItem[0]!= "") {		   			        
						//Agrega los nuevos valores.			
						oOption = new Option(arrItem[1], arrItem[0]);
						try {
						   formato_id_.add(oOption, null);
						} catch(ex) {
						   formato_id_.add(oOption);
						}
					 }
				  }
				}
			
			
			});	
		}
	}	
}
/**************************************************************************************************************************/
function cambia_cmbformato_Process() {
var res;

	if(res = ajax_handler()) {
		
	}
}

function cambia_cmbGramaje(papel_id,formato_id) {
	tipo_papel = papel_id;

	if (document.getElementById("gramaje_id_" + tipo_papel ).value=="0")
	{
	
		if(papel_id != "" ) {
			if (formato_id == 15){
				document.getElementById("gramaje_id_" + papel_id).style.display = "inline";
			}	
			if (formato_id == 17){
				document.getElementById("gramaje_id_" + papel_id).style.display = "none";
			}	
			if (formato_id == 16){
				document.getElementById("gramaje_id_" + papel_id).style.display = "none";
			}	
			
			
			var url = "i_papel_ajax.asp";
			
			$.post(url, { papel_id: papel_id, formato_id: formato_id },
			function(data){

				//Elimina los resultados actuales
				var divResultado = document.getElementById("divResultado");

				if (divResultado!=null) {
				   divResultado.style.visibility = "hidden";
				}
					
				//Elimina el contenido del combo Modelo
				var gramaje_id = document.getElementById("gramaje_id_" + tipo_papel );
				if(gramaje_id!=null) {
				  while (gramaje_id.length >1) {
					 gramaje_id.options[1] = null;
				  }
				}
					
				var arrRegistros = data.split("#");
				if(arrRegistros.length >0) {
					  
				  for(var i=0;i<arrRegistros.length;i++) {			
					 var arrItem  = arrRegistros[i].split("|");
					 if(arrItem[0]!= "") {		   			        
						//Agrega los nuevos valores.			
						oOption = new Option(arrItem[1], arrItem[0]);
						try {
						   gramaje_id.add(oOption, null);
						} catch(ex) {
						   gramaje_id.add(oOption);
						}
					 }
				  }
				}			
			
			});	
			
		}
	}	
}
