/* HACK TRANSPARENCIA */
$(document).ready(function() {
	//$('.bg-trans').css('opacity', 0.5);
/*	$('.bg-trans').css({ opacity: 0.9 });	*/	
	$('.top-negro').css ({ opacity:0.9 });
	$('.down-negro').css ({ opacity:0.9 });
});
/*********** FUNCION REMOVER CARRO DE COMPRAS *******************/
$(document).ready(function(){
	$(".btn_cancelar").click(function() {
		$(this).parent().parent().remove();
		calcularValores();
		//$('td div.btn_cancelar').parent().find('td').hide();
	});
});

/*********** FUNCION ACTUALIZAR CARRO DE COMPRAS *****************/
$(document).ready(function() {
	$('.btn-act-carro').click(function() {
		calcularValores();
		return false;
	});
});

function calcularValores() {
	var totales = new Array();
	$('.items-carro-compra').children('tbody').find('tr').each(function() {
		var cantidad = $(this).find('td').eq(0).find('input').val();
		var valor = $(this).find('td').eq(2).find('input').val();
		
		var total = cantidad*valor;
		totales.push(total);
		
		$(this).find('td').eq(3).find('strong').text('$'+separarMiles(total));
	});	
	
	//calcular total de totales
	var megaTotal = 0;
	for(t in totales) megaTotal += totales[t];
	
	$('.resumen-compra').find('input').val(megaTotal);
	$('.resumen-compra').find('p').text('Total: $'+separarMiles(megaTotal));
}

/*********************************/
/*       OTRAS FUNCIONES         */
function separarMiles(nStr) {
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? ',' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) x1 = x1.replace(rgx, '$1' + '.' + '$2');
	return x1 + x2;
}

function soloNumeros(evt){
	var key = evt.keyCode ? evt.keyCode : evt.which ;
	return (key <= 31 || (key >= 48 && key <= 57)); 
}
/****************** DISABLED ELEMENTS ***********************/
$(document).ready(function() {	
	$('#box').click(function() {
		if(!$('#nombre-env').is(":disabled")) {
			$('#nombre-env').attr("disabled", true); 
			$('#direccion-env').attr("disabled", true); 
			$('#comuna-env').attr("disabled", true); 
			$('#ciudad-env').attr("disabled", true); 
			$('#region-env').attr("disabled", true); 
			$('#precio-env').attr("disabled", true); 
		} else {
			$('#nombre-env').removeAttr("disabled");
			$('#direccion-env').removeAttr("disabled"); 
			$('#comuna-env').removeAttr("disabled");
			$('#ciudad-env').removeAttr("disabled");
			$('#region-env').removeAttr("disabled");
			$('#precio-env').removeAttr("disabled");
		}
	});
});
/******************** insterta borde ********************/
 $(document).ready(function(){
    $("h2").after("<div class=\"borde-titulo\"></div>");
  });
/************************* botonera **********************/

/*	$("#dummy-programas").ready(function() {
		$(".programas").addClass("programas-selected");
	});*/


/*$(document).ready (funtion (){
	$("#dummy-programas").ready(function() {
		$(".programas").addClass("programas-selected");
	});
});*//****************************//* Inicializa Titulos Flash *//****************************/$(document).ready (function (){	var convertToFlash = function(h1){					var texto = h1.html();					var id = 'x' + Math.random(); 		h1.empty().append($('<div></div>').attr('id',id));		swfobject.embedSWF("/v2/wp-content/themes/oasis_2/convertToFlash.swf", id, "565", "50", "9.0.0","expressInstall.swf", {'texto':texto}, {wmode: 'transparent'});	};		var h1 = $("h1.convertToFlash");	$.each(h1,function(i,val){					convertToFlash($(val));	});});
