function roundit(Num, Places) {
	if (Places > 0) {
		if ((Num.toString().length - Num.toString().lastIndexOf('.')) > (Places + 1)) {
		  var Rounder = Math.pow(10, Places);
		  return Math.round(Num * Rounder) / Rounder;
		}
	else return Num;
	}
   	else return Math.round(Num);
}
function xGetElementById(e) {
  if(typeof(e)!='string') return e;
  if(document.getElementById) e=document.getElementById(e);
  else if(document.all) e=document.all[e];
  else e=null;
  return e;
}
function calculate() {
	var doc = document.estimate;

	try{
		fedrate = parseFloat(doc.cmn_fedrate.value);
		if(isNaN(fedrate)) fedrate=0;
	}catch(e){
		fedrate = 0;
	}
	try{
		staterate = parseFloat(doc.cmn_staterate.value);
		if(isNaN(staterate)) staterate=0;
	}catch(e){
		staterate = 0;
	}
	try{
		selfrate = parseFloat(doc.cmn_selfrate.value);
		if(isNaN(selfrate)) selfrate=0;
	}catch(e){
		selfrate = 0;
	}
	try{
		ins = parseFloat(doc.cmn_insurance.value);
		if(isNaN(ins)) ins=0;
	}catch(e){
		ins = 0;
	}
	try{
		ltc = parseFloat(doc.cmn_ltc.value);
		if(isNaN(ltc)) ltc=0;
	}catch(e){
		ltc = 0;
	}
	try{
		other = parseFloat(doc.cmn_other.value);
		if(isNaN(other)) other=0;
	}catch(e){
		other = 0;
	}
	if(doc.cmn_subScorp[0].checked){
		scorp="Y";
	}else{
		scorp="N";
	}
	try{
		state = doc.cmn_state.value;
	}catch(e){
		state = "";
	}
	if(state=="") {
		alert("Please select your state.");
	}else{
		
		calcLink = "http://www.baseonline.com/calc105.asp?"+
			"fedrate="+fedrate+
			"&staterate="+staterate+
			"&selfrate="+selfrate+
			"&ins="+ins+
			"&ltc="+ltc+
			"&scorp="+scorp+
			"&other="+other+
			"&state="+state;
		

		GB_show("Tax Savings Calculator", calcLink, 670, 480);



	}
}


function itemizedcalc()
{
document.estimate.cmn_other.value = roundit(+document.CalcItemized.exp_1.value + +document.CalcItemized.exp_2.value + +document.CalcItemized.exp_3.value + +document.CalcItemized.exp_4.value + +document.CalcItemized.exp_5.value + +document.CalcItemized.exp_6.value + +document.CalcItemized.exp_7.value + +document.CalcItemized.exp_8.value + +document.CalcItemized.exp_9.value + +document.CalcItemized.exp_10.value + +document.CalcItemized.exp_11.value + +document.CalcItemized.exp_12.value + +document.CalcItemized.exp_13.value + +document.CalcItemized.exp_14.value + +document.CalcItemized.exp_15.value + +document.CalcItemized.exp_16.value + +document.CalcItemized.exp_17.value + +document.CalcItemized.exp_18.value + +document.CalcItemized.exp_19.value + +document.CalcItemized.exp_20.value + +document.CalcItemized.exp_21.value + +document.CalcItemized.exp_22.value + +document.CalcItemized.exp_23.value + +document.CalcItemized.exp_24.value + +document.CalcItemized.exp_25.value + +document.CalcItemized.exp_26.value + +document.CalcItemized.exp_27.value + +document.CalcItemized.exp_28.value + +document.CalcItemized.exp_29.value + +document.CalcItemized.exp_30.value + +document.CalcItemized.exp_31.value, 2);

$(".panel").toggle("fast");
$(".trigger").toggleClass("active");


var origcolor = 'white';
var flashcolor = 'yellow';
var seconds = 1;

document.estimate.cmn_other.style.backgroundColor = flashcolor;


 var t = setTimeout(function(){
	document.estimate.cmn_other.style.backgroundColor = origcolor;
    },(seconds*1000));


}


function closeitemized()
{
$(".panel").hide();
$(".trigger").toggleClass("active");
}

function closetaxtable()
{
     $(".taxbracket").toggle("fast"); 
     $(".FedTaxTable").toggleClass("active");


}


function pickFedRate( fedrate, serate ) {
	var doc = document.estimate;
	doc.cmn_fedrate.value = fedrate;
	doc.cmn_selfrate.value = serate;

	highlightFor('yellow', 1, 'white')
}


function clearInput() {
var doc = document.CalcItemized;


var frm_elements = doc.elements;

for (i = 0; i < frm_elements.length; i++)
{
    field_type = frm_elements[i].type.toLowerCase();
    switch (field_type)
    {
    case "text":
    case "password":
    case "textarea":
    case "hidden":
        frm_elements[i].value = "";
        break;
    case "radio":
    case "checkbox":
        if (frm_elements[i].checked)
        {
            frm_elements[i].checked = false;
        }
        break;
    case "select-one":
    case "select-multi":
        frm_elements[i].selectedIndex = -1;
        break;
    default:
        break;
    }
}

}

function clearInputMain() 
{
var doc = document.estimate;
doc.cmn_insurance.value = ""
doc.cmn_ltc.value = ""
doc.cmn_other.value = ""
doc.cmn_state.value = ""
doc.cmn_fedrate.value = ".15"
doc.cmn_staterate.value = ".05"
doc.cmn_selfrate.value = ".133"

var origcolor = 'white';
var flashcolor = '#A9363A';
var seconds = 1;

doc.cmn_insurance.style.backgroundColor = flashcolor;
doc.cmn_ltc.style.backgroundColor = flashcolor;
doc.cmn_other.style.backgroundColor = flashcolor;
doc.cmn_state.style.backgroundColor = flashcolor;
doc.cmn_fedrate.style.backgroundColor = flashcolor;
doc.cmn_staterate.style.backgroundColor = flashcolor;
doc.cmn_selfrate.style.backgroundColor = flashcolor;

 var t = setTimeout(function(){
       doc.cmn_insurance.style.backgroundColor = origcolor;
      doc.cmn_ltc.style.backgroundColor = origcolor;
	doc.cmn_other.style.backgroundColor = origcolor;
	doc.cmn_state.style.backgroundColor = origcolor;
	doc.cmn_fedrate.style.backgroundColor = origcolor;
	doc.cmn_staterate.style.backgroundColor = origcolor;
	doc.cmn_selfrate.style.backgroundColor = origcolor;
    },(seconds*1000));

}


function highlightFor(color,seconds, origcolor){
    var element = document.getElementById('fedrate')
    var element2 = document.getElementById('selfrate')
    element.style.backgroundColor = color;
    element2.style.backgroundColor = color;
    var t = setTimeout(function(){
       element.style.backgroundColor = origcolor;
       element2.style.backgroundColor = origcolor;
    },(seconds*1000));
}



