var CCCodeWindow;

function popupccc(){
  CCCodeWindow = window.open("http://www.spectruminput.com/products/precisefp/CreditCardSecurityCode.htm", "Credit Card Security Code", "toolbar=0,location=0, directories=0,status=0,menubar=0, scrollbars=0,resizable=0,width=470,height=300"); 
}


var numb = "0123456789.,";

function res(t,v){
var w = "";
var i=0;
var kropka=0;
for (i=0; i < t.value.length; i++) {
if(t.value.charAt(i)==".")
  kropka++;
x = t.value.charAt(i);
var w_temp = "";
if (v.indexOf(x,0) != -1 && kropka<2){
	if(kropka==1){
		if((t.value.length-t.value.indexOf('.')+2)==3 || (t.value.length-t.value.indexOf('.')+2)==4 || (t.value.length-t.value.indexOf('.')+2)==5){
			w +=x;
		}
		else
		{
			
			w += t.value.charAt(t.value.indexOf('.')) + t.value.charAt(t.value.indexOf('.')+1) + t.value.charAt(t.value.indexOf('.')+2);
		}
	}
	else {
		w += x;
	}
 }
}
t.value = w;
t.value = addCommas(t.value.replace(/,/g,''));
}

function addCommas(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 formatNum(num,decimals){
	return num.fixed(decimals);
}


function update(form)
{
var client = 0;
var hour = 0;
var cN = form.clientNumber.value; 
var hR = form.hourRate.value;

if(cN!="" && hR!="")
{
	client = parseFloat(form.clientNumber.value.replace(/,/g,''));
	hour = parseFloat(form.hourRate.value.replace(/,/g,''));
} else
{
	client =0;
	hour =0;
}
var suma_godzin = 0;
var g1 = 0;
var g2 = 0;
var g3 = 0;
var g4 = 0;
var tH = 0;
form.paperNumber.value=="" ? g1=0 : g1=parseFloat(form.paperNumber.value.replace(/,/g,''));
form.dataEntry.value=="" ? g2=0 : g2=parseFloat(form.dataEntry.value.replace(/,/g,''));
form.crm.value=="" ? g3=0 : g3=parseFloat(form.crm.value.replace(/,/g,''));
form.waitTime.value=="" ? g4=0 : g4=parseFloat(form.waitTime.value.replace(/,/g,''));
suma_godzin=g1+g2+g3+g4;
var tH = suma_godzin * client;
tH=addCommas(tH.toFixed(2));
form.totalHours.value=tH;
form.hourlyRate.value=addCommas(hour.toFixed(2));
var labor = 0;
labor = parseFloat(form.totalHours.value.replace(/,/g,''))*parseFloat(form.hourlyRate.value.replace(/,/g,''));
form.totalLabor.value=addCommas(labor.toFixed(2));
var post = 2 * client;
form.postageSavings.value=addCommas(post.toFixed(2));
var lp = 0;
lp = parseFloat(form.postageSavings.value.replace(/,/g,''))+parseFloat(form.totalLabor.value.replace(/,/g,''));
form.laborPost.value=addCommas(lp.toFixed(2));
var ns = 0;
ns = parseFloat(form.laborPost.value.replace(/,/g,''))+parseFloat(form.preciseFP.value.replace(/,/g,''));
form.netSavings.value=addCommas(ns.toFixed(2));
}
