var selectedField;

function checkKleurValues(msg1, msg2) {
    var total = 0;
    var c = $('.color_identity');
    
    $('.kleurvalue').each(
      function(i) {
        total = total+parseInt($('.kleurvalue')[i].value);
      }
    );
    
    if ((c[0].value == "") || (c[1].value == "") || (c[2].value == "")) {
        alert(msg1);
        return false;
    }
    if ((total == 0)) {
        alert(msg1);
		return false;
	}  	
	if(isNaN(c[2].value) ) {
        alert(msg1);
        return false;
	}
    if (total != 1000 && total > 0) {
		a=confirm(msg2);
		if(a) {
		} else {
		return false;
		}
	}
	if(total = 0) { 
        alert(msg1);
        return false;
	}
    
   
    return true;   
}

function checkKleurValuesSpot(msg1, msg2) {
    var total = 0;
    var c = $('.color_identity');
    
    $('.kleurvalue').each(
      function(i) {
        total = total+parseInt($('.kleurvalue')[i].value);
      }
    );
	

    //if ((c[0].value == "") || (c[1].value == "") || (c[2].value == "")) {
	if ((c[0].value == "") && (c[1].value == "")) {		
        alert(msg1);
        return false;
    }
	
    if ((total == 0)) {
        alert(msg1);
		return false;
	}  	
	if(isNaN(c[1].value) ) {
        alert(msg1);
        return false;
	}
    if ((total != 1000)) {
		a=confirm(msg2);
		if(a) {
		} else {
		return false;
		}
	} 
    
    return true;   
}

function correctie() {
	var total = 0;
    $('.editgram').each(
        function (i) {
            $(this).css({border:"1px #999999 solid",background:"transparent"});
            $('.editgram')[i].readOnly = false;
			total = total+parseInt($('.editgram')[i].value);
			
        }
    );
    $('#calField').fadeIn(2000);
	$('#calField2').fadeIn(2000);
	//alert(total);
	//$('.ingram').attr('value',total);
	//$('.ingram').value = total;
	document.getElementById('ingram').value=total;
}

function disable(e) {
    $('.editgram').each(
        function (i) {
            if ($('.editgram')[i].id != e.id) {
                $(this).css("backgroundColor","#CCCCCC");
                $('.editgram')[i].readOnly = true;
            }
        }
    );
    selectedField = e.id;
}

function calculateGram() {
    var x = "weight_in_mill_"+selectedField.split("_")[3];
    var ratio = $("#weight_in_gram_"+selectedField.split("_")[3]).val() / $("#"+x).val();
    var totalGram = 0;
    var tmp;
    
    $('.edit').each(
        function(i) {
            $('.editgram')[i].value = parseFloat(parseFloat($('.edit')[i].value*ratio).toFixed(2));
            tmp = $('.edit')[i].value*ratio;
            totalGram = totalGram+tmp;
        }
    );
    $('.calculate').attr('value',parseFloat(parseFloat(totalGram).toFixed(2)));
	//alert(x);
    
}


function formulier() {
    $('#formulier').fadeIn(2000);
	$('#button2').css("display","none");
	$('#button4').fadeIn(2000);
}