$(document).ready(function() {
													 
	/* PNG Fix */
	$('#nav li a, .png').pngfix();
	$('.bgtrans, .bgtrans2').pngfix({sizingMethod: 'scale'});
	
	/*Accordion*/
	if($('#acc01').length>0 ){		jQuery('#acc01').accordion({			header: 'a.head',			alwaysOpen: false,			autoheight: false		});	}
	if($('#acc02').length>0 ){		jQuery('#acc02').accordion({			header: 'a.head',			alwaysOpen: false,			autoheight: false		});	}
	
	$('.tproduction tr').each(function(){ $(this).find('td:first').addClass('firstcol'); $(this).find('td:eq(3), td:eq(4)').attr('align','left'); });
	$('.tproduction tr:odd, .tdownloads tr:odd').addClass('alt');
	$('.list01 li:odd').addClass('alt');
	
	$('#lang').change(function(){
		if( $(this).val() == 'spa' ){
			var loc = document.URL;
			var urlspl = loc.split('/en/');
			url = urlspl[1];
			location.href = urlspl[0] + '/es/' + urlspl[1];
		}
		if( $(this).val() == 'eng' ){
			var loc = document.URL;
			var urlspl = loc.split('/es/');
			url = urlspl[1];
			location.href = urlspl[0] + '/en/' + urlspl[1];
		}
	});
	
	//Calcular valores liquid
	$('#calculate').click(function(){
		
		//valores txt
		var v1 = $('#v1').attr('value');
		var v2 = $('#v2').attr('value');
		var v3 = $('#v3').attr('value');
		var v4 = $('#v4').attr('value');
		var v5 = $('#v5').attr('value');
		var v6 = $('#v6').attr('value');
		var v7 = $('#v7').attr('value');
		var v8 = $('#v8').attr('value');
		var v9 = $('#v9').attr('value');
		var v10 = $('#v10').attr('value');
		var v11 = $('#v11').attr('value');
		var v12 = $('#v12').attr('value');
		//valores peso
		var can1 = '4.964';
		var can2 = '0.700';
		var can3 = '0.004';
		var can4 = '0.980';
		var can5 = '1.052';
		var can6 = '1.800';
		var can7 = '1.500';
		var can8 = '214.000';
		var can9 = '6.620';
		var can10 = '250.000';
		var can11 = '0.005';
		var can12 = '0.750';
		//costos
		var ils1 = v1*can1;
		var ils2 = v2*can2;
		var ils3 = v3*can3;
		var ils4 = v4*can4;
		var ils5 = v5*can5;
		var ils6 = v6*can6;
		var ils7 = v7*can7;
		var ils8 = v8*can8;
		var ils9 = v9*can9;
		var ils10 = v10*can10;
		var ils11 = v11*can11;
		var ils12 = v12*can12;
		//pinta cantidad
		//alert(ils1);
		$('#ils1').text(ils1.toFixed(3));
		$('#ils2').text(ils2.toFixed(3));
		$('#ils3').text(ils3.toFixed(3));
		$('#ils4').text(ils4.toFixed(3));
		$('#ils5').text(ils5.toFixed(3));
		$('#ils6').text(ils6.toFixed(3));
		$('#ils7').text(ils7.toFixed(3));
		$('#ils8').text(ils8.toFixed(3));
		$('#ils9').text(ils9.toFixed(3));
		$('#ils10').text(ils10.toFixed(3));
		$('#ils11').text(ils11.toFixed(3));
		$('#ils12').text(ils12.toFixed(3));
		//Sumatoria costo
		var ilsT = ils1 + ils2 + ils3 + ils4 + ils5 + ils6 + ils7 + ils8 + ils9 + ils10 + ils11 + ils12;
		//pinta sumatoria
		$('#ilsT').text(ilsT.toFixed(3));
		//Porcentajes
		var p1 = (ils1 / ilsT)*100;
		var p2 = (ils2 / ilsT)*100;
		var p3 = (ils3 / ilsT)*100;
		var p4 = (ils4 / ilsT)*100;
		var p5 = (ils5 / ilsT)*100;
		var p6 = (ils6 / ilsT)*100;
		var p7 = (ils7 / ilsT)*100;
		var p8 = (ils8 / ilsT)*100;
		var p9 = (ils9 / ilsT)*100;
		var p10 = (ils10 / ilsT)*100;
		var p11 = (ils11 / ilsT)*100;
		var p12 = (ils12 / ilsT)*100;
		//pintar porcentajes
		$('#p1').text(p1.toFixed(3));
		$('#p2').text(p2.toFixed(3));
		$('#p3').text(p3.toFixed(3));
		$('#p4').text(p4.toFixed(3));
		$('#p5').text(p5.toFixed(3));
		$('#p6').text(p6.toFixed(3));
		$('#p7').text(p7.toFixed(3));
		$('#p8').text(p8.toFixed(3));
		$('#p9').text(p9.toFixed(3));
		$('#p10').text(p10.toFixed(3));
		$('#p11').text(p11.toFixed(3));
		$('#p12').text(p12.toFixed(3));
		//suma porcentajes
		var pT = p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 + p11 + p12;
		//pinta total porcentaje
		$('#pT').text(pT.toFixed(3));
		
		return false;
	});

	
	/*Contact - Countries*/
	$('#countries a').click(function(){
	
		var cid = $(this).attr('href');
		$('.dInfo').hide();
		$(cid).show();
		return false;
	
	});
	
	$('#fcontacto').ajaxForm( { beforeSubmit: validate , success:showResponse} );
	
});

function validate(formData, jqForm, options) { 
				    
	var txtName = $('input[name=name]').fieldValue(); 
	var txtEmail = $('input[name=email]').fieldValue();

		 
	// usernameValue and passwordValue are arrays but we can do simple 
	// "not" tests to see if the arrays are empty 
	if (!txtName[0] || !txtEmail[0]) { 
			alert('Por favor coloque su nombre y su Correo Electrónico');
			return false; 
	}
}
				
function showResponse(responseText, statusText, xhr, $form)  { 
	$(".msg").show();
}
