function UnformatNumber(number) {
    if (!number)
        number = 0;
    // make string..
    number = number + '';
    // remove 1000 sep
    while (number.indexOf('.') != -1) 
        number = number.replace('.', '');
    // change ',' to '.'
    number = number.replace(',', '.');
    return parseFloat(number);
}

function FormatNumber(number, precision) {
    if (!number) number = 0;
    var precision = precision == 0 || precision ? precision : 2;
    // make string..
    number = number + '';
    var minus = false;
    if (number.charAt(0) == '-') {
        minus = true;
        number = number.slice(1);
    }
    number = number.replace(',', '.');
    // round
    number = toFixed(number, precision);
    //Non numeric value
    if (number == 'NaN.NaN') return '0,00';
    if (number == 'Infinity') return '0,00';
    // add 1000 sep
    var tmp = number.split(".");
    var c = '';
    for (var i = tmp[0].length; i != -1; i--) {
        c += tmp[0].charAt(i);
        if ((tmp[0].length - i) == 0 || i == 0)
            continue;
        if ((tmp[0].length - i) % 3 == 0)
            c += '.';
    }
    // reverse c
    c = c.split("").reverse().join("");
    if (minus)
        c = '-' + c;
    return precision == 0 ? c : c + ',' + tmp[1];
}

function FormatNumber2(number, precision) {
    if (!number) number = 0;
    var precision = precision == 0 || precision ? precision : 2;
    // make string..
    number = number + '';
    var minus = false;
    if (number.charAt(0) == '-') {
        minus = true;
        number = number.slice(1);
    }
    number = number.replace(',', '.');
    // round
    number = toFixed(number, precision);
    //Non numeric value
    if (number == 'NaN.NaN') return '0,00';
    if (number == 'Infinity') return '0,00';
    var tmp = number.split(".");
    var c = '';
    for (var i = tmp[0].length; i != -1; i--) {
        c += tmp[0].charAt(i);
        if ((tmp[0].length - i) == 0 || i == 0)
            continue;
        if ((tmp[0].length - i) % 3 == 0)
            c += '';
    }
    // reverse c
    c = c.split("").reverse().join("");
    if (minus)
        c = '-' + c;
    return precision == 0 ? c : c + ',' + tmp[1];
}

function QuantityFormat(number,precision){
	if (!number) number = 0;
    var precision = precision == 0 || precision ? precision : 2;
    // make string..
    number = number + '';
    var minus = false;
    if (number.charAt(0) == '-') {
        minus = true;
        number = number.slice(1);
    }
    number = number.replace(',', '.');
    // round
    number = toFixed(number, precision);
    //Non numeric value
    if (number == 'NaN.NaN') return '0.000000';
    if (number == 'Infinity') return '0.000000';
    // add 1000 sep
    var tmp = number.split(".");
    var c = '';
    for (var i = tmp[0].length; i != -1; i--) {
        c += tmp[0].charAt(i);
        if ((tmp[0].length - i) == 0 || i == 0)
            continue;
        if ((tmp[0].length - i) % 3 == 0)
            c += '';
    }
    // reverse c
    c = c.split("").reverse().join("");
    if (minus)
        c = '-' + c;
    return precision == 0 ? c : c + '.' + tmp[1];
}

function toFixed(value, precision) {
	 var X = String(value);
	 var precyzja = typeof precision !== 'undefined' ? parseInt(precision)  : 2;
	 precyzja = isNaN(precyzja) ? 2 : precyzja;
	 var wynik = null;
	 if (X.indexOf('.') >= 0) {
	   var tab = X.split('.');
	   if (tab[1].length >= (precyzja + 1)) {
	     if (parseInt(tab[1][precyzja]) < 5) {
	       tab[1] = tab[1].slice(0, precyzja);
	     } else {
	       tab[1] = tab[1].slice(0, precyzja);
	       var tmp = parseInt(tab[1]);
	       tmp = tmp + 1;
	       tab[1] = String(tmp);
	       if (tab[1].length > precyzja) {
	         tmp = '';
	         while (tmp.length < precyzja) {
	           tmp += '0';
	         }
	         tab[1] = tmp;
	         tmp = parseInt(tab[0]);
	         tmp = tmp + 1;
	         tab[0] = String(tmp);
	       }

	       if (tab[1].length < precyzja) {
	         tmp = '';
	         while (tmp.length < precyzja - 1) {
	           tmp += '0';
	         }
	         tab[1] = String(tmp) + String(tab[1]);
	       }
	     }
	   }
	   wynik = parseFloat(tab[0] + '.' + tab[1]).toFixed(precyzja);
	 } else {
	   wynik = parseFloat(X).toFixed(precyzja);
	 }

	 return wynik;
	}


/*
	this is not number function !!@#$%^
*/
function checkIsTheSameContractor(){
	var error=false;
	var val='';
	 $("input:checkbox[name='mass[]']:checked").each(function() {
	      
	       if(val==''){
	        
	    	   val=$("#mass_"+$(this).val()).val();
	    	   if($("#mass_inv_"+$(this).val()).val()!=''){
	    		   error=true;
	    	   }
	       } else {
	    	   if( $("#mass_"+$(this).val()).val()!=val){
	    		   error=true;
	    	   }
	    	   val=$("#mass_"+$(this).val()).val();
	    	   if($("#mass_inv_"+$(this).val()).val()!=''){
	    		   error=true;
	    	   }
	       }
	      
	  });
	 return error;
	 
}

function gotoInvoice(){
	var error=false;
	var val='';
	var ids=new Array();
	 $("input:checkbox[name='mass[]']:checked").each(function() {
		 $(this).val();
		 ids.push( $(this).val());
	      
	  });

	  window.open("index.php?module=EcmInvoiceOuts&action=EditView&isWZ=true&record="+ids.join('@'));
}