// JavaScript Document
var CARpvp = 0;
var CARcant = 0;
var CARtotal = 0;

var HDDpvp = 0;
var HDDcant = 0;
var HDDtotal = 0;

var PLBIpvp = 0;
var PLBIcant = 0;
var PLBItotal = 0;

var PLBApvp = 0;
var PLBAcant = 0;
var PLBAtotal = 0;

var MICIpvp = 0;
var MICIcant = 0;
var MICItotal = 0;

var MICApvp = 0;
var MICAcant = 0;
var MICAtotal = 0;

var MEMpvp = 0;
var MEMcant = 0;
var MEMtotal = 0;

var MONpvp = 0;
var MONcant = 0;
var MONtotal = 0;

var VGApvp = 0;
var VGAcant = 0;
var VGAtotal = 0;

var GDRpvp = 0;
var GDRcant = 0;
var GDRtotal = 0;

var TECpvp = 0;
var TECcant = 0;
var TECtotal = 0;

var RATpvp = 0;
var RATcant = 0;
var RATtotal = 0;

var ALTpvp = 0;
var ALTcant = 0;
var ALTtotal = 0;

var MEXpvp = 0;
var MEXcant = 0;
var MEXtotal = 0;

var MOBpvp = 0;
var MOBcant = 0;
var MOBtotal = 0;

//Componentes
var COMPOpvp = 0;
var COMPOcant = 0;
var COMPOtotal = 0;


//Subtotal Equipo Base
var sub_base = 0;
var sub_compo = 0;

//Control Intel - AMD
plba_on = false;
mica_on = false;
plbi_on = false;
mici_on = false;

var idcompo;
var descripcompo='';
var cont = 0;
var filascompo = 0;

var off = '';
var on = '<img src="img/presuk_ver.gif" width="20" height="20" />';

var img_plbi_off = '<img src="img/pk_plbi_off.png" />';
var img_mici_off = '<img src="img/pk_mici_off.png" />';
var img_plba_off = '<img src="img/pk_plba_off.png" />';
var img_mica_off = '<img src="img/pk_mica_off.png" />';

var img_plbi_on = '<img src="img/pk_plbi.png" />';
var img_mici_on = '<img src="img/pk_mici.png" />';
var img_plba_on = '<img src="img/pk_plba.png" />';
var img_mica_on = '<img src="img/pk_mica.png" />';

function reset(){
	CARpvp = 0;
	CARcant = 1;
	CARtotal = 0;
	
	HDDpvp = 0;
	HDDcant = 1;
	HDDtotal = 0;
	
	PLBIpvp = 0;
	PLBIcant = 1;
	PLBItotal = 0;
	
	PLBApvp = 0;
	PLBAcant = 1;
	PLBAtotal = 0;

	MICIpvp = 0;
	MICIcant = 1;
	MICItotal = 0;

	MICApvp = 0;
	MICAcant = 1;
	MICAtotal = 0;
	
	MEMpvp = 0;
	MEMcant = 1;
	MEMtotal = 0;

	MONpvp = 0;
	MONcant = 1;
	MONtotal = 0;
	
	VGApvp = 0;
	VGAcant = 1;
	VGAtotal = 0;
	
	GDRpvp = 0;
	GDRcant = 1;
	GDRtotal = 0;

	TECpvp = 0;
	TECcant = 1;
	TECtotal = 0;
	
	RATpvp = 0;
	RATcant = 1;
	RATtotal = 0;
	
	ALTpvp = 0;
	ALTcant = 1;
	ALTtotal = 0;
	
	MEXpvp = 0;
	MEXcant = 1;
	MEXtotal = 0;
	
	MOBpvp = 0;
	MOBcant = 1;
	MOBtotal = 0;
	
	//Subtotal Equipo Base
	sub_base = 0;
	sub_compo = 0;
}

//SUBTOTALES -----------------------------------------------------------------------------------------

$(document).ready(function(){
$("#inicio").css("border","dotted 1px black");						   
						   
$('#h_contador').attr('value', '0');

function suma_base(){
	sub_base = CARtotal+HDDtotal+PLBItotal+PLBAtotal+MICItotal+MICAtotal+MEMtotal+MONtotal+VGAtotal+GDRtotal+TECtotal+RATtotal+ALTtotal+MEXtotal+MOBtotal;
	$("#supertotal").attr('value', number_format(sub_base+sub_compo,2,',','.') + ' ' + String.fromCharCode(8364));
}

function suma_compo(){
	sub_compo = sub_compo + COMPOtotal;
	$('#base_compo').attr('value', number_format(sub_compo,2,',','.'));
	$("#supertotal").attr('value', number_format(sub_base+sub_compo,2,',','.') + ' ' + String.fromCharCode(8364));
}

function inutil_amd(){
	//placa base
	$('#lplba').attr('selectedIndex',0);
	$('#lplba').attr('disabled',true);
	PLBAtotal = 0;
	PLBApvp = 0;
	PLBAcant = 1;
	suma_base();
	$("#base").attr('value', number_format(sub_base,2,',','.'));
	$("#total_plba").attr('value', number_format(PLBAtotal,2,',','.'));
	$("#pvp_plba").attr('value', number_format(PLBApvp,2,',','.'));
	$("#cant_plba").attr('value', PLBAcant);
	$("#z_plba").html(off);
	$("#img_plba").html(img_plba_off);
	
	//micro
	$('#lmica').attr('selectedIndex',0);
	$('#lmica').attr('disabled',true);
	MICAtotal = 0;
	MICApvp = 0;
	MICAcant = 1;
	suma_base();
	$("#base").attr('value', number_format(sub_base,2,',','.'));
	$("#total_mica").attr('value', number_format(MICAtotal,2,',','.'));
	$("#pvp_mica").attr('value', number_format(MICApvp,2,',','.'));
	$("#cant_mica").attr('value', MICAcant);
	$("#z_mica").html(off);	
	$("#img_mica").html(img_mica_off);
}

function util_amd(){
	if(!plbi_on && !mici_on){
		$('#lplba').attr('disabled',false);
		$("#z_plba").html(off);
		$('#lmica').attr('disabled',false);
		$("#z_mica").html(off);
		$("#img_plba").html(img_plba_on);
		$("#img_mica").html(img_mica_on);
	}
}


function inutil_intel(){
	//placa base
	$('#lplbi').attr('selectedIndex',0);
	$('#lplbi').attr('disabled',true);
	PLBItotal = 0;
	PLBIpvp = 0;
	PLBIcant = 1;
	suma_base();
	$("#base").attr('value', number_format(sub_base,2,',','.'));
	$("#total_plbi").attr('value', number_format(PLBItotal,2,',','.'));
	$("#pvp_plbi").attr('value', number_format(PLBIpvp,2,',','.'));
	$("#cant_plbi").attr('value', PLBIcant);
	$("#z_plbi").html(off);
	$("#img_plbi").html(img_plbi_off);
	
	//micro
	$('#lmici').attr('selectedIndex',0);
	$('#lmici').attr('disabled',true);
	MICItotal = 0;
	MICIpvp = 0;
	MICIcant = 1;
	suma_base();
	$("#base").attr('value', number_format(sub_base,2,',','.'));
	$("#total_mici").attr('value', number_format(MICItotal,2,',','.'));
	$("#pvp_mici").attr('value', number_format(MICIpvp,2,',','.'));
	$("#cant_mici").attr('value', MICIcant);
	$("#z_mici").html(off);	
	$("#img_mici").html(img_mici_off);
}

function util_intel(){
	if(!plba_on && !mica_on){
		$('#lplbi').attr('disabled',false);
		$("#z_plbi").html(off);
		$('#lmici').attr('disabled',false);
		$("#z_mici").html(off);
		$("#img_plbi").html(img_plbi_on);
		$("#img_mici").html(img_mici_on);
	}
}

//CARCASA --------------------------------------------------------------------------------------------

	//Combo -------------------------------------
	$("#lcar").change(function(){
		var id;
		id = $('#lcar').val();
		if(id != 0){
			aux = "detalle.php\?id=" + id + "\&keepThis=true\&TB_iframe=true\&height=495\&width=850";
			$("#z_car").html(on);
			$("#y_car").attr('href',aux);
		}else{
			$("#z_car").html(off);
			$("#y_car").attr('href',off);
		}
		$.get('precio_ajax.php',{'id':id},function(precio){
			CARpvp = parseFloat(precio);
			CARcant = 1;
			CARtotal = CARpvp;
			suma_base();
			$("#base").attr('value', number_format(sub_base,2,',','.'));
			$("#total_car").attr('value', number_format(CARtotal,2,',','.'));
			$("#pvp_car").attr('value', number_format(CARpvp,2,',','.'));
			$("#cant_car").attr('value', CARcant);
		});
	});

	//Mas ---------------------------------------
	$('#mas_car').click(function(){
		CARcant = parseInt($('#cant_car').val());
		if((CARcant < 50) && (CARpvp > 0)){
			CARcant++;
			CARtotal = CARpvp * CARcant;
			$("#cant_car").attr('value', CARcant);
			suma_base();
			$("#total_car").attr('value', number_format(CARtotal,2,',','.'));
			$("#base").attr('value', number_format(sub_base,2,',','.'));
		}
	});
	
	//Menos --------------------------------------
	$('#menos_car').click(function(){
		CARcant = parseInt($('#cant_car').val());
		if(CARcant > 1){
			CARcant--;
			CARtotal = CARpvp * CARcant;
			$("#cant_car").attr('value', CARcant);
			suma_base();
			$("#total_car").attr('value', number_format(CARtotal,2,',','.'));
			$("#base").attr('value', number_format(sub_base,2,',','.'));
		}
	});


	//DISCO DURO --------------------------------------------------------------------------------------------
	//Combo -------------------------------------
	$("#lhdd").change(function(){
		id = $('#lhdd').val();
		if(id != 0){
			aux = "detalle.php\?id=" + id + "\&keepThis=true\&TB_iframe=true\&height=495\&width=850";
			$("#z_hdd").html(on);
			$("#y_hdd").attr('href',aux);
		}else{
			$("#z_hdd").html(off);
			$("#y_hdd").attr('href',off);
		}
		$.get('precio_ajax.php',{'id':id},function(precio){
			HDDpvp = parseFloat(precio);
			HDDcant = 1;
			HDDtotal = HDDpvp;
			suma_base();
			$("#base").attr('value', number_format(sub_base,2,',','.'));
			$("#total_hdd").attr('value', number_format(HDDtotal,2,',','.'));
			$("#pvp_hdd").attr('value', number_format(HDDpvp,2,',','.'));
			$("#cant_hdd").attr('value', HDDcant);
		});
	});
	
	//Mas ---------------------------------------
	$('#mas_hdd').click(function(){
		HDDcant = parseInt($('#cant_hdd').val());
		if((HDDcant < 50) && (HDDpvp > 0)){
			HDDcant++;
			HDDtotal = HDDpvp * HDDcant;
			$("#cant_hdd").attr('value', HDDcant);
			suma_base();
			$("#total_hdd").attr('value', number_format(HDDtotal,2,',','.'));
			$("#base").attr('value', number_format(sub_base,2,',','.'));
		}
	});
	
	//Menos --------------------------------------
	$('#menos_hdd').click(function(){
		HDDcant = parseInt($('#cant_hdd').val());
		if(HDDcant > 1){
			HDDcant--;
			HDDtotal = HDDpvp * HDDcant;
			$("#cant_hdd").attr('value', HDDcant);
			suma_base();
			$("#total_hdd").attr('value', number_format(HDDtotal,2,',','.'));
			$("#base").attr('value', number_format(sub_base,2,',','.'));
		}
	});	

	//PLACA INTEL --------------------------------------------------------------------------------------------
	//Combo -------------------------------------
	$("#lplbi").change(function(){
		var id;
		id = $('#lplbi').val();
		if(id != 0){
			aux = "detalle.php\?id=" + id + "\&keepThis=true\&TB_iframe=true\&height=495\&width=850";
			$("#z_plbi").html(on);
			$("#y_plbi").attr('href',aux);
			plbi_on = true;
			inutil_amd();
		}else{
			$("#z_plbi").html(off);
			$("#y_plbi").attr('href',off);
			plbi_on = false;
			util_amd();
		}		
		$.get('precio_ajax.php',{'id':id},function(precio){
			PLBIpvp = parseFloat(precio);
			PLBIcant = 1;
			PLBItotal = PLBIpvp;
			suma_base();
			$("#base").attr('value', number_format(sub_base,2,',','.'));
			$("#total_plbi").attr('value', number_format(PLBItotal,2,',','.'));
			$("#pvp_plbi").attr('value', number_format(PLBIpvp,2,',','.'));
			$("#cant_plbi").attr('value', PLBIcant);
		});
	});
	
	//Mas ---------------------------------------
	$('#mas_plbi').click(function(){
		PLBIcant = parseInt($('#cant_plbi').val());
		if((PLBIcant < 50) && (PLBIpvp > 0)){
			PLBIcant++;
			PLBItotal = PLBIpvp * PLBIcant;
			$("#cant_plbi").attr('value', PLBIcant);
			suma_base();
			$("#total_plbi").attr('value', number_format(PLBItotal,2,',','.'));
			$("#base").attr('value', number_format(sub_base,2,',','.'));
		}
	});
	
	//Menos --------------------------------------
	$('#menos_plbi').click(function(){
		PLBIcant = parseInt($('#cant_plbi').val());
		if(PLBIcant > 1){
			PLBIcant--;
			PLBItotal = PLBIpvp * PLBIcant;
			$("#cant_plbi").attr('value', PLBIcant);
			suma_base();
			$("#total_plbi").attr('value', number_format(PLBItotal,2,',','.'));
			$("#base").attr('value', number_format(sub_base,2,',','.'));
		}
	});

	//PLACA AMD --------------------------------------------------------------------------------------------
	//Combo -------------------------------------
	$("#lplba").change(function(){
		var id;
		id = $('#lplba').val();
		if(id != 0){
			aux = "detalle.php\?id=" + id + "\&keepThis=true\&TB_iframe=true\&height=495\&width=850";
			$("#z_plba").html(on);
			$("#y_plba").attr('href',aux);
			plba_on = true;
			inutil_intel();
		}else{
			$("#z_plba").html(off);
			$("#y_plba").attr('href',off);
			plba_on = false;
			util_intel();
		}
		$.get('precio_ajax.php',{'id':id},function(precio){
			PLBApvp = parseFloat(precio);
			PLBAcant = 1;
			PLBAtotal = PLBApvp;
			suma_base();
			$("#base").attr('value', number_format(sub_base,2,',','.'));
			$("#total_plba").attr('value', number_format(PLBAtotal,2,',','.'));
			$("#pvp_plba").attr('value', number_format(PLBApvp,2,',','.'));
			$("#cant_plba").attr('value', PLBAcant);
		});
	});
	
	//Mas ---------------------------------------
	$('#mas_plba').click(function(){
		PLBAcant = parseInt($('#cant_plba').val());
		if((PLBAcant < 50) && (PLBApvp > 0)){
			PLBAcant++;
			PLBAtotal = PLBApvp * PLBAcant;
			$("#cant_plba").attr('value', PLBAcant);
			suma_base();
			$("#total_plba").attr('value', number_format(PLBAtotal,2,',','.'));
			$("#base").attr('value', number_format(sub_base,2,',','.'));
		}
	});
	
	//Menos --------------------------------------
	$('#menos_plba').click(function(){
		PLBAcant = parseInt($('#cant_plba').val());
		if(PLBAcant > 1){
			PLBAcant--;
			PLBAtotal = PLBApvp * PLBAcant;
			$("#cant_plba").attr('value', PLBAcant);
			suma_base();
			$("#total_plba").attr('value', number_format(PLBAtotal,2,',','.'));
			$("#base").attr('value', number_format(sub_base,2,',','.'));
		}
	});

	//MICI --------------------------------------------------------------------------------------------
	//Combo -------------------------------------
	$("#lmici").change(function(){
		var id;
		id = $('#lmici').val();
		if(id != 0){
			aux = "detalle.php\?id=" + id + "\&keepThis=true\&TB_iframe=true\&height=495\&width=850";
			$("#z_mici").html(on);
			$("#y_mici").attr('href',aux);
			mici_on = true;
			inutil_amd();
		}else{
			$("#z_mici").html(off);
			$("#y_mici").attr('href',off);
			mici_on = false;
			util_amd();
		}
		$.get('precio_ajax.php',{'id':id},function(precio){
			MICIpvp = parseFloat(precio);
			MICIcant = 1;
			MICItotal = MICIpvp;
			suma_base();
			$("#base").attr('value', number_format(sub_base,2,',','.'));
			$("#total_mici").attr('value', number_format(MICItotal,2,',','.'));
			$("#pvp_mici").attr('value', number_format(MICIpvp,2,',','.'));
			$("#cant_mici").attr('value', MICIcant);
		});
	});
	
	//Mas ---------------------------------------
	$('#mas_mici').click(function(){
		MICIcant = parseInt($('#cant_mici').val());
		if((MICIcant < 50) && (MICIpvp > 0)){
			MICIcant++;
			MICItotal = MICIpvp * MICIcant;
			$("#cant_mici").attr('value', MICIcant);
			suma_base();
			$("#total_mici").attr('value', number_format(MICItotal,2,',','.'));
			$("#base").attr('value', number_format(sub_base,2,',','.'));
		}
	});
	
	//Menos --------------------------------------
	$('#menos_mici').click(function(){
		MICIcant = parseInt($('#cant_mici').val());
		if(MICIcant > 1){
			MICIcant--;
			MICItotal = MICIpvp * MICIcant;
			$("#cant_mici").attr('value', MICIcant);
			suma_base();
			$("#total_mici").attr('value', number_format(MICItotal,2,',','.'));
			$("#base").attr('value', number_format(sub_base,2,',','.'));
		}
	});

	//MICA --------------------------------------------------------------------------------------------
	//Combo -------------------------------------
	$("#lmica").change(function(){
		var id;
		id = $('#lmica').val();
		if(id != 0){
			aux = "detalle.php\?id=" + id + "\&keepThis=true\&TB_iframe=true\&height=495\&width=850";
			$("#z_mica").html(on);
			$("#y_mica").attr('href',aux);
			mica_on = true;
			inutil_intel();
		}else{
			$("#z_mica").html(off);
			$("#y_mica").attr('href',off);
			mica_on = false;
			util_intel();
		}
		$.get('precio_ajax.php',{'id':id},function(precio){
			MICApvp = parseFloat(precio);
			MICAcant = 1;
			MICAtotal = MICApvp;
			suma_base();
			$("#base").attr('value', number_format(sub_base,2,',','.'));
			$("#total_mica").attr('value', number_format(MICAtotal,2,',','.'));
			$("#pvp_mica").attr('value', number_format(MICApvp,2,',','.'));
			$("#cant_mica").attr('value', MICAcant);
		});
	});
	
	//Mas ---------------------------------------
	$('#mas_mica').click(function(){
		MICAcant = parseInt($('#cant_mica').val());
		if((MICAcant < 50) && (MICApvp > 0)){
			MICAcant++;
			MICAtotal = MICApvp * MICAcant;
			$("#cant_mica").attr('value', MICAcant);
			suma_base();
			$("#total_mica").attr('value', number_format(MICAtotal,2,',','.'));
			$("#base").attr('value', number_format(sub_base,2,',','.'));
		}
	});
	
	//Menos --------------------------------------
	$('#menos_mica').click(function(){
		MICAcant = parseInt($('#cant_mica').val());
		if(MICAcant > 1){
			MICAcant--;
			MICAtotal = MICApvp * MICAcant;
			$("#cant_mica").attr('value', MICAcant);
			suma_base();
			$("#total_mica").attr('value', number_format(MICAtotal,2,',','.'));
			$("#base").attr('value', number_format(sub_base,2,',','.'));
		}
	});

	//MEM --------------------------------------------------------------------------------------------
	//Combo -------------------------------------
	$("#lmem").change(function(){
		var id;
		id = $('#lmem').val();
		if(id != 0){
			aux = "detalle.php\?id=" + id + "\&keepThis=true\&TB_iframe=true\&height=495\&width=850";
			$("#z_mem").html(on);
			$("#y_mem").attr('href',aux);
		}else{
			$("#z_mem").html(off);
			$("#y_mem").attr('href',off);
		}
		$.get('precio_ajax.php',{'id':id},function(precio){
			MEMpvp = parseFloat(precio);
			MEMcant = 1;
			MEMtotal = MEMpvp;
			suma_base();
			$("#base").attr('value', number_format(sub_base,2,',','.'));
			$("#total_mem").attr('value', number_format(MEMtotal,2,',','.'));
			$("#pvp_mem").attr('value', number_format(MEMpvp,2,',','.'));
			$("#cant_mem").attr('value', MEMcant);
		});
	});
	
	//Mas ---------------------------------------
	$('#mas_mem').click(function(){
		MEMcant = parseInt($('#cant_mem').val());
		if((MEMcant < 50) && (MEMpvp > 0)){
			MEMcant++;
			MEMtotal = MEMpvp * MEMcant;
			$("#cant_mem").attr('value', MEMcant);
			suma_base();
			$("#total_mem").attr('value', number_format(MEMtotal,2,',','.'));
			$("#base").attr('value', number_format(sub_base,2,',','.'));
		}
	});
	
	//Menos --------------------------------------
	$('#menos_mem').click(function(){
		MEMcant = parseInt($('#cant_mem').val());
		if(MEMcant > 1){
			MEMcant--;
			MEMtotal = MEMpvp * MEMcant;
			$("#cant_mem").attr('value', MEMcant);
			suma_base();
			$("#total_mem").attr('value', number_format(MEMtotal,2,',','.'));
			$("#base").attr('value', number_format(sub_base,2,',','.'));
		}
	});

	//MON --------------------------------------------------------------------------------------------
	//Combo -------------------------------------
	$("#lmon").change(function(){
		var id;
		id = $('#lmon').val();
		if(id != 0){
			aux = "detalle.php\?id=" + id + "\&keepThis=true\&TB_iframe=true\&height=495\&width=850";
			$("#z_mon").html(on);
			$("#y_mon").attr('href',aux);
		}else{
			$("#z_mon").html(off);
			$("#y_mon").attr('href',off);
		}
		$.get('precio_ajax.php',{'id':id},function(precio){
			MONpvp = parseFloat(precio);
			MONcant = 1;
			MONtotal = MONpvp;
			suma_base();
			$("#base").attr('value', number_format(sub_base,2,',','.'));
			$("#total_mon").attr('value', number_format(MONtotal,2,',','.'));
			$("#pvp_mon").attr('value', number_format(MONpvp,2,',','.'));
			$("#cant_mon").attr('value', MONcant);
		});
	});
	
	//Mas ---------------------------------------
	$('#mas_mon').click(function(){
		MONcant = parseInt($('#cant_mon').val());
		if((MONcant < 50) && (MONpvp > 0)){
			MONcant++;
			MONtotal = MONpvp * MONcant;
			$("#cant_mon").attr('value', MONcant);
			suma_base();
			$("#total_mon").attr('value', number_format(MONtotal,2,',','.'));
			$("#base").attr('value', number_format(sub_base,2,',','.'));
		}
	});
	
	//Menos --------------------------------------
	$('#menos_mon').click(function(){
		MONcant = parseInt($('#cant_mon').val());
		if(MONcant > 1){
			MONcant--;
			MONtotal = MONpvp * MONcant;
			$("#cant_mon").attr('value', MONcant);
			suma_base();
			$("#total_mon").attr('value', number_format(MONtotal,2,',','.'));
			$("#base").attr('value', number_format(sub_base,2,',','.'));
		}
	});

	//VGA --------------------------------------------------------------------------------------------
	//Combo -------------------------------------
	$("#lvga").change(function(){
		var id;
		id = $('#lvga').val();
		if(id != 0){
			aux = "detalle.php\?id=" + id + "\&keepThis=true\&TB_iframe=true\&height=495\&width=850";
			$("#z_vga").html(on);
			$("#y_vga").attr('href',aux);
		}else{
			$("#z_vga").html(off);
			$("#y_vga").attr('href',off);
		}
		$.get('precio_ajax.php',{'id':id},function(precio){
			VGApvp = parseFloat(precio);
			VGAcant = 1;
			VGAtotal = VGApvp;
			suma_base();
			$("#base").attr('value', number_format(sub_base,2,',','.'));
			$("#total_vga").attr('value', number_format(VGAtotal,2,',','.'));
			$("#pvp_vga").attr('value', number_format(VGApvp,2,',','.'));
			$("#cant_vga").attr('value', VGAcant);
		});
	});
	
	//Mas ---------------------------------------
	$('#mas_vga').click(function(){
		VGAcant = parseInt($('#cant_vga').val());
		if((VGAcant < 50) && (VGApvp > 0)){
			VGAcant++;
			VGAtotal = VGApvp * VGAcant;
			$("#cant_vga").attr('value', VGAcant);
			suma_base();
			$("#total_vga").attr('value', number_format(VGAtotal,2,',','.'));
			$("#base").attr('value', number_format(sub_base,2,',','.'));
		}
	});
	
	//Menos --------------------------------------
	$('#menos_vga').click(function(){
		VGAcant = parseInt($('#cant_vga').val());
		if(VGAcant > 1){
			VGAcant--;
			VGAtotal = VGApvp * VGAcant;
			$("#cant_vga").attr('value', VGAcant);
			suma_base();
			$("#total_vga").attr('value', number_format(VGAtotal,2,',','.'));
			$("#base").attr('value', number_format(sub_base,2,',','.'));
		}
	});


	//GDR --------------------------------------------------------------------------------------------
	//Combo -------------------------------------
	$("#lgdr").change(function(){
		var id;
		id = $('#lgdr').val();
		if(id != 0){
			aux = "detalle.php\?id=" + id + "\&keepThis=true\&TB_iframe=true\&height=495\&width=850";
			$("#z_gdr").html(on);
			$("#y_gdr").attr('href',aux);
		}else{
			$("#z_gdr").html(off);
			$("#y_gdr").attr('href',off);
		}
		$.get('precio_ajax.php',{'id':id},function(precio){
			GDRpvp = parseFloat(precio);
			GDRcant = 1;
			GDRtotal = GDRpvp;
			suma_base();
			$("#base").attr('value', number_format(sub_base,2,',','.'));
			$("#total_gdr").attr('value', number_format(GDRtotal,2,',','.'));
			$("#pvp_gdr").attr('value', number_format(GDRpvp,2,',','.'));
			$("#cant_gdr").attr('value', GDRcant);
		});
	});
	
	//Mas ---------------------------------------
	$('#mas_gdr').click(function(){
		GDRcant = parseInt($('#cant_gdr').val());
		if((GDRcant < 50) && (GDRpvp > 0)){
			GDRcant++;
			GDRtotal = GDRpvp * GDRcant;
			$("#cant_gdr").attr('value', GDRcant);
			suma_base();
			$("#total_gdr").attr('value', number_format(GDRtotal,2,',','.'));
			$("#base").attr('value', number_format(sub_base,2,',','.'));
		}
	});
	
	//Menos --------------------------------------
	$('#menos_gdr').click(function(){
		GDRcant = parseInt($('#cant_gdr').val());
		if(GDRcant > 1){
			GDRcant--;
			GDRtotal = GDRpvp * GDRcant;
			$("#cant_gdr").attr('value', GDRcant);
			suma_base();
			$("#total_gdr").attr('value', number_format(GDRtotal,2,',','.'));
			$("#base").attr('value', number_format(sub_base,2,',','.'));
		}
	});

	//TEC --------------------------------------------------------------------------------------------
	//Combo -------------------------------------
	$("#ltec").change(function(){
		var id;
		id = $('#ltec').val();
		if(id != 0){
			aux = "detalle.php\?id=" + id + "\&keepThis=true\&TB_iframe=true\&height=495\&width=850";
			$("#z_tec").html(on);
			$("#y_tec").attr('href',aux);
		}else{
			$("#z_tec").html(off);
			$("#y_tec").attr('href',off);
		}
		$.get('precio_ajax.php',{'id':id},function(precio){
			TECpvp = parseFloat(precio);
			TECcant = 1;
			TECtotal = TECpvp;
			suma_base();
			$("#base").attr('value', number_format(sub_base,2,',','.'));
			$("#total_tec").attr('value', number_format(TECtotal,2,',','.'));
			$("#pvp_tec").attr('value', number_format(TECpvp,2,',','.'));
			$("#cant_tec").attr('value', TECcant);
		});
	});
	
	//Mas ---------------------------------------
	$('#mas_tec').click(function(){
		TECcant = parseInt($('#cant_tec').val());
		if((TECcant < 50) && (TECpvp > 0)){
			TECcant++;
			TECtotal = TECpvp * TECcant;
			$("#cant_tec").attr('value', TECcant);
			suma_base();
			$("#total_tec").attr('value', number_format(TECtotal,2,',','.'));
			$("#base").attr('value', number_format(sub_base,2,',','.'));
		}
	});
	
	//Menos --------------------------------------
	$('#menos_tec').click(function(){
		TECcant = parseInt($('#cant_tec').val());
		if(TECcant > 1){
			TECcant--;
			TECtotal = TECpvp * TECcant;
			$("#cant_tec").attr('value', TECcant);
			suma_base();
			$("#total_tec").attr('value', number_format(TECtotal,2,',','.'));
			$("#base").attr('value', number_format(sub_base,2,',','.'));
		}
	});

	//RAT --------------------------------------------------------------------------------------------
	//Combo -------------------------------------
	$("#lrat").change(function(){
		var id;
		id = $('#lrat').val();
		if(id != 0){
			aux = "detalle.php\?id=" + id + "\&keepThis=true\&TB_iframe=true\&height=495\&width=850";
			$("#z_rat").html(on);
			$("#y_rat").attr('href',aux);
		}else{
			$("#z_rat").html(off);
			$("#y_rat").attr('href',off);
		}
		$.get('precio_ajax.php',{'id':id},function(precio){
			RATpvp = parseFloat(precio);
			RATcant = 1;
			RATtotal = RATpvp;
			suma_base();
			$("#base").attr('value', number_format(sub_base,2,',','.'));
			$("#total_rat").attr('value', number_format(RATtotal,2,',','.'));
			$("#pvp_rat").attr('value', number_format(RATpvp,2,',','.'));
			$("#cant_rat").attr('value', RATcant);
		});
	});
	
	//Mas ---------------------------------------
	$('#mas_rat').click(function(){
		RATcant = parseInt($('#cant_rat').val());
		if((RATcant < 50) && (RATpvp > 0)){
			RATcant++;
			RATtotal = RATpvp * RATcant;
			$("#cant_rat").attr('value', RATcant);
			suma_base();
			$("#total_rat").attr('value', number_format(RATtotal,2,',','.'));
			$("#base").attr('value', number_format(sub_base,2,',','.'));
		}
	});
	
	//Menos --------------------------------------
	$('#menos_rat').click(function(){
		RATcant = parseInt($('#cant_rat').val());
		if(RATcant > 1){
			RATcant--;
			RATtotal = RATpvp * RATcant;
			$("#cant_rat").attr('value', RATcant);
			suma_base();
			$("#total_rat").attr('value', number_format(RATtotal,2,',','.'));
			$("#base").attr('value', number_format(sub_base,2,',','.'));
		}
	});

	//ALT --------------------------------------------------------------------------------------------
	//Combo -------------------------------------
	$("#lalt").change(function(){
		var id;
		id = $('#lalt').val();
		if(id != 0){
			aux = "detalle.php\?id=" + id + "\&keepThis=true\&TB_iframe=true\&height=495\&width=850";
			$("#z_alt").html(on);
			$("#y_alt").attr('href',aux);
		}else{
			$("#z_alt").html(off);
			$("#y_alt").attr('href',off);
		}
		$.get('precio_ajax.php',{'id':id},function(precio){
			ALTpvp = parseFloat(precio);
			ALTcant = 1;
			ALTtotal = ALTpvp;
			suma_base();
			$("#base").attr('value', number_format(sub_base,2,',','.'));
			$("#total_alt").attr('value', number_format(ALTtotal,2,',','.'));
			$("#pvp_alt").attr('value', number_format(ALTpvp,2,',','.'));
			$("#cant_alt").attr('value', ALTcant);
		});
	});
	
	//Mas ---------------------------------------
	$('#mas_alt').click(function(){
		ALTcant = parseInt($('#cant_alt').val());
		if((ALTcant < 50) && (ALTpvp > 0)){
			ALTcant++;
			ALTtotal = ALTpvp * ALTcant;
			$("#cant_alt").attr('value', ALTcant);
			suma_base();
			$("#total_alt").attr('value', number_format(ALTtotal,2,',','.'));
			$("#base").attr('value', number_format(sub_base,2,',','.'));
		}
	});
	
	//Menos --------------------------------------
	$('#menos_alt').click(function(){
		ALTcant = parseInt($('#cant_alt').val());
		if(ALTcant > 1){
			ALTcant--;
			ALTtotal = ALTpvp * ALTcant;
			$("#cant_alt").attr('value', ALTcant);
			suma_base();
			$("#total_alt").attr('value', number_format(ALTtotal,2,',','.'));
			$("#base").attr('value', number_format(sub_base,2,',','.'));
		}
	});

	//MEX --------------------------------------------------------------------------------------------
	//Combo -------------------------------------
	$("#lmex").change(function(){
		var id;
		id = $('#lmex').val();
		if(id != 0){
			aux = "detalle.php\?id=" + id + "\&keepThis=true\&TB_iframe=true\&height=495\&width=850";
			$("#z_mex").html(on);
			$("#y_mex").attr('href',aux);
		}else{
			$("#z_mex").html(off);
			$("#y_mex").attr('href',off);
		}
		$.get('precio_ajax.php',{'id':id},function(precio){
			MEXpvp = parseFloat(precio);
			MEXcant = 1;
			MEXtotal = MEXpvp;
			suma_base();
			$("#base").attr('value', number_format(sub_base,2,',','.'));
			$("#total_mex").attr('value', number_format(MEXtotal,2,',','.'));
			$("#pvp_mex").attr('value', number_format(MEXpvp,2,',','.'));
			$("#cant_mex").attr('value', MEXcant);
		});
	});
	
	//Mas ---------------------------------------
	$('#mas_mex').click(function(){
		MEXcant = parseInt($('#cant_mex').val());
		if((MEXcant < 50) && (MEXpvp > 0)){
			MEXcant++;
			MEXtotal = MEXpvp * MEXcant;
			$("#cant_mex").attr('value', MEXcant);
			suma_base();
			$("#total_mex").attr('value', number_format(MEXtotal,2,',','.'));
			$("#base").attr('value', number_format(sub_base,2,',','.'));
		}
	});
	
	//Menos --------------------------------------
	$('#menos_mex').click(function(){
		MEXcant = parseInt($('#cant_mex').val());
		if(MEXcant > 1){
			MEXcant--;
			MEXtotal = MEXpvp * MEXcant;
			$("#cant_mex").attr('value', MEXcant);
			suma_base();
			$("#total_mex").attr('value', number_format(MEXtotal,2,',','.'));
			$("#base").attr('value', number_format(sub_base,2,',','.'));
		}
	});

	//MOB --------------------------------------------------------------------------------------------
	//Combo -------------------------------------
	$("#lmob").change(function(){
		var id;
		id = $('#lmob').val();
		if(id != 0){
			aux = "detalle.php\?id=" + id + "\&keepThis=true\&TB_iframe=true\&height=495\&width=850";
			$("#z_mob").html(on);
			$("#y_mob").attr('href',aux);
		}else{
			$("#z_mob").html(off);
			$("#y_mob").attr('href',off);
		}
		$.get('precio_ajax.php',{'id':id},function(precio){
			MOBpvp = parseFloat(precio);
			MOBcant = 1;
			MOBtotal = MOBpvp;
			suma_base();
			$("#base").attr('value', number_format(sub_base,2,',','.'));
			$("#total_mob").attr('value', number_format(MOBtotal,2,',','.'));
			$("#pvp_mob").attr('value', number_format(MOBpvp,2,',','.'));
			$("#cant_mob").attr('value', MOBcant);
		});
	});
	
	//Mas ---------------------------------------
	$('#mas_mob').click(function(){
		MOBcant = parseInt($('#cant_mob').val());
		if((MOBcant < 50) && (MOBpvp > 0)){
			MOBcant++;
			MOBtotal = MOBpvp * MOBcant;
			$("#cant_mob").attr('value', MOBcant);
			suma_base();
			$("#total_mob").attr('value', number_format(MOBtotal,2,',','.'));
			$("#base").attr('value', number_format(sub_base,2,',','.'));
		}
	});
	
	//Menos --------------------------------------
	$('#menos_mob').click(function(){
		MOBcant = parseInt($('#cant_mob').val());
		if(MOBcant > 1){
			MOBcant--;
			MOBtotal = MOBpvp * MOBcant;
			$("#cant_mob").attr('value', MOBcant);
			suma_base();
			$("#total_mob").attr('value', number_format(MOBtotal,2,',','.'));
			$("#base").attr('value', number_format(sub_base,2,',','.'));
		}
	});

	//COMPONENTES -------------------------------------------------------------------------------------

	//Familia AJAX --------------------------------------
	$('#lfamilia').change(function(){
		var fam;
		fam = $('#lfamilia').val(); 
		$.get('compo_ajax.php',{'fam':fam},function(lista){
			$('#lcompo').html(lista);
			$('#lcompo').change();
		});
	});
	

	$('#anyadir').click(function(){
		if(COMPOpvp > 0){
			if(filascompo<10){	
				filascompo++;
				cont++;
				var farrago = '<tr id="fila'+cont+'"><td width="46" height="22" align="center"><input type="hidden" name="h_COMPOid_'+cont+'" id="h_COMPOid_'+cont+'" /><input type="hidden" name="h_COMPOdes_'+cont+'" id="h_COMPOdes_'+cont+'" /><input type="hidden" name="h_COMPOtotal_'+cont+'" id="h_COMPOtotal_'+cont+'" /><div id="z_compo1"><a href="detalle.php?id='+idcompo+'" target="_blank"><img src="img/presuk_ver.gif" width="20" height="20" /></a></div></td><td width="562" height="22"><input name="compo'+cont+'" type="text" class="presuk_pvp_comp" id="compo'+cont+'" value="Aqui va el texto del articulo..." readonly="true" /></td><td width="105" height="22" align="center"><input name="pvp_compo'+cont+'" type="text" class="presuk_pvp" id="pvp_compo'+cont+'" value="0,00" readonly="true"/></td><td width="51" height="22" align="center"><input name="cant_compo'+cont+'" type="text" class="presuk_cant" id="cant_compo'+cont+'" value="1" readonly="true"/></td><td width="101" height="22" align="center"><input name="total_compo'+cont+'" type="text" class="presuk_total" id="total_compo'+cont+'" value="0,00" readonly="true"/></td><td width="75" height="22" align="center"><img src="img/pk_borrar.png" width="60" height="20" onclick="borrarFila('+cont+')"/></td></tr>';
				$('#tabla').append(farrago);
				$('#compo'+cont).attr('value', descripcompo);
				$('#pvp_compo'+cont).attr('value', number_format(COMPOpvp,2,',','.'));
				$('#total_compo'+cont).attr('value', number_format(COMPOtotal,2,',','.'));
				$('#cant_compo'+cont).attr('value', COMPOcant);
				//Ocultos del ocultismo....
				$('#h_COMPOid_'+cont).attr('value', idcompo);
				$('#h_COMPOdes_'+cont).attr('value', descripcompo);
				$('#h_COMPOtotal_'+cont).attr('value', COMPOtotal);
				$('#h_contador').attr('value', cont);
				suma_compo();
				$('#lfamilia').attr('selectedIndex',0);
				$('#lfamilia').change();
			}else{
				alert('Maximo 10 componentes');	
			}
		}
	});


	//COMPONENTES --------------------------------------------------------------------------------------------
	//Combo -------------------------------------
	$("#lcompo").change(function(){
		idcompo = $('#lcompo').val();
		if(idcompo != 0){
			aux = "detalle.php\?id=" + idcompo + "\&keepThis=true\&TB_iframe=true\&height=495\&width=850";
			$("#z_compo").html(on);
			$("#y_compo").attr('href',aux);
			
			$.get('descrip_ajax.php',{'id':idcompo},function(texto){
				descripcompo = texto;	
			});
		}else{
			$("#z_compo").html(off);
			$("#y_compo").attr('href',off);	
		}
		$.get('precio_ajax.php',{'id':idcompo},function(precio){
			COMPOpvp = parseFloat(precio);
			COMPOcant = 1;
			COMPOtotal = COMPOpvp;
			$("#total_compo").attr('value', number_format(COMPOtotal,2,',','.'));
			$("#pvp_compo").attr('value', number_format(COMPOpvp,2,',','.'));
			$("#cant_compo").attr('value', COMPOcant);
		});
	});

	//Mas ---------------------------------------
	$('#mas_compo').click(function(){
		COMPOcant = parseInt($('#cant_compo').val());
		if((COMPOcant < 50) && (COMPOpvp > 0)){
			COMPOcant++;
			COMPOtotal = COMPOpvp * COMPOcant;
			$("#cant_compo").attr('value', COMPOcant);
			$("#total_compo").attr('value', number_format(COMPOtotal,2,',','.'));
		}
	});

	//Menos --------------------------------------
	$('#menos_compo').click(function(){
		COMPOcant = parseInt($('#cant_compo').val());
		if(COMPOcant > 1){
			COMPOcant--;
			COMPOtotal = COMPOpvp * COMPOcant;
			$("#cant_compo").attr('value', COMPOcant);
			$("#total_compo").attr('value', number_format(COMPOtotal,2,',','.'));
		}
	});
	
});//End DOM

 var borrarFila = function (indice){
	resta = $('#h_COMPOtotal_'+indice).val();
	sub_compo = sub_compo - resta;
	$('#base_compo').attr('value', number_format(sub_compo,2,',','.'));
	$("#supertotal").attr('value', number_format(sub_base+sub_compo,2,',','.') + ' ' + String.fromCharCode(8364));
	filascompo--;
  	$("#fila" + indice).remove();
 }
