//****************************************
//Script for the Home Premium Calculator
//****************************************
function calcHomePremium() 
{
  if (document.getElementById("QuoteCalculatorHome1_ddlState").value == "NJ")
  {
	
  }
  var txtDwel = (document.getElementById("QuoteCalculatorHome1_ddlDwelling").value.split(";"));
  //intCont = (eval(txtDwel[0]) / 2);
  
  
  if ((eval(txtDwel[0]) > 150000) && (document.getElementById("QuoteCalculatorHome1_ddlState").value == "NJ"))
  {
	intCont = 75000;
	document.getElementById("QuoteCalculatorHome1_ddlContentsExtra").value="0;0";
	document.getElementById("QuoteCalculatorHome1_ddlContentsExtra").disabled=true;
	
	//document.getElementById("QuoteCalculatorHome1_rblDeductible_0").style.visibility="hidden";
	//document.getElementById("QuoteCalculatorHome1_rblDeductible_1").style.visibility="hidden";
		
	document.getElementById("QuoteCalculatorHome1_rblDeductible_0").disabled=true;
	document.getElementById("QuoteCalculatorHome1_rblDeductible_1").disabled=true;
	document.getElementById("QuoteCalculatorHome1_rblDeductible_2").checked = true;	
	
	//remove 25000 and 50000
	if (document.getElementById("QuoteCalculatorHome1_ddlLiabilityExtra").options[1].text == "$25,000")
	{
	document.getElementById("QuoteCalculatorHome1_ddlLiabilityExtra").remove(1);
	document.getElementById("QuoteCalculatorHome1_ddlLiabilityExtra").remove(1);		
	}
	
	if (document.getElementById("QuoteCalculatorHome1_ddlLiabilityExtra").options.length < 3)
	{
		var opt = document.createElement('option');
		opt.text = "$275,000";
		opt.value = "275000;450";
		document.getElementById("QuoteCalculatorHome1_ddlLiabilityExtra").add(opt,4); 
	}
	        
  }
  else if ((eval(txtDwel[0]) > 150000) && (document.getElementById("QuoteCalculatorHome1_ddlState").value != "NJ"))
  {
	var st = document.getElementById("QuoteCalculatorHome1_ddlState").value;
	alert('The maximum dwelling for ' + st + ' is 150,000.');
	document.getElementById("QuoteCalculatorHome1_ddlDwelling").options[0].selected=true;
	txtDwel = (document.getElementById("QuoteCalculatorHome1_ddlDwelling").value.split(";"));
	
	intCont = (eval(txtDwel[0]) / 2);
	document.getElementById("QuoteCalculatorHome1_ddlContentsExtra").disabled=false;
	document.getElementById("QuoteCalculatorHome1_rblDeductible_0").disabled=false;
	document.getElementById("QuoteCalculatorHome1_rblDeductible_1").disabled=false;
	
	//Add 25000 and 50000 hard coded values
	if (document.getElementById("QuoteCalculatorHome1_ddlLiabilityExtra").options[1].text != "$25,000")
	{
	var optLia1 = document.createElement('option');
	optLia1.text = "$50,000";
    optLia1.value = "50000;120";
    document.getElementById("QuoteCalculatorHome1_ddlLiabilityExtra").add(optLia1,1); 
    
	var optLia2 = document.createElement('option');
	optLia2.text = "$25,000";
    optLia2.value = "25000;60";
    document.getElementById("QuoteCalculatorHome1_ddlLiabilityExtra").add(optLia2,1); 
	}
	
	if (document.getElementById("QuoteCalculatorHome1_ddlLiabilityExtra").options.length > 4)
	{
		if (document.getElementById("QuoteCalculatorHome1_ddlLiabilityExtra").options[4].text == "$275,000")
		{
		document.getElementById("QuoteCalculatorHome1_ddlLiabilityExtra").remove(4);
		document.getElementById("QuoteCalculatorHome1_ddlLiabilityExtra").remove(4);		
		}
	}
  }
  else
  {
	intCont = (eval(txtDwel[0]) / 2);
	document.getElementById("QuoteCalculatorHome1_ddlContentsExtra").disabled=false;
	document.getElementById("QuoteCalculatorHome1_rblDeductible_0").disabled=false;
	document.getElementById("QuoteCalculatorHome1_rblDeductible_1").disabled=false;
	
	//Add 25000 and 50000 hard coded values
	if (document.getElementById("QuoteCalculatorHome1_ddlLiabilityExtra").options[1].text != "$25,000")
	{
	var optLia1 = document.createElement('option');
	optLia1.text = "$50,000";
    optLia1.value = "50000;120";
    document.getElementById("QuoteCalculatorHome1_ddlLiabilityExtra").add(optLia1,1); 
    
	var optLia2 = document.createElement('option');
	optLia2.text = "$25,000";
    optLia2.value = "25000;60";
    document.getElementById("QuoteCalculatorHome1_ddlLiabilityExtra").add(optLia2,1); 
	}
	
	if (document.getElementById("QuoteCalculatorHome1_ddlLiabilityExtra").options.length > 4)
	{
		if (document.getElementById("QuoteCalculatorHome1_ddlLiabilityExtra").options[4].text == "$275,000")
		{
		document.getElementById("QuoteCalculatorHome1_ddlLiabilityExtra").remove(4);
		document.getElementById("QuoteCalculatorHome1_ddlLiabilityExtra").remove(4);		
		}
	}
	
	//document.getElementById("QuoteCalculatorHome1_ddlContentsExtra").style.visibility="visible";
	//document.getElementById("QuoteCalculatorHome1_rblDeductible_0").style.visibility="visible";
	//document.getElementById("QuoteCalculatorHome1_rblDeductible_1").style.visibility="visible";
	
  }
  if ((document.getElementById("QuoteCalculatorHome1_txtZip").value != "") &&
      (!isNaN(document.getElementById("QuoteCalculatorHome1_txtZip").value.slice(0,5))))
    {intZip = eval(document.getElementById("QuoteCalculatorHome1_txtZip").value.slice(0,5)); }
  else
    {intZip = 0; }
    
        
  if (((document.getElementById("QuoteCalculatorHome1_ddlState").value == "PA") && ((intZip < 19103) || (intZip > 19154)))||
			(document.getElementById("QuoteCalculatorHome1_ddlState").value == "IN"))
    { intDwel = eval(txtDwel[2]); }
  else
	{
		if ((document.getElementById("QuoteCalculatorHome1_ddlState").value == "PA") || 
			(document.getElementById("QuoteCalculatorHome1_ddlState").value == "DC") ||
			(document.getElementById("QuoteCalculatorHome1_ddlState").value == "IL") ||
			(document.getElementById("QuoteCalculatorHome1_ddlState").value == "NJ") ||
			(document.getElementById("QuoteCalculatorHome1_ddlState").value == "VA") ||
			(document.getElementById("QuoteCalculatorHome1_ddlState").value == "DE") ||
			(document.getElementById("QuoteCalculatorHome1_ddlState").value == "MD")) 


		  { intDwel = eval(txtDwel[3]); }
		else
		  { intDwel = eval(txtDwel[1]); }
	}
       
  var txtXCon= (document.getElementById("QuoteCalculatorHome1_ddlContentsExtra").value.split(";"));
  intXCon = eval(txtXCon[1]);
  intTotCont = (intCont + eval(txtXCon[0]));
  
  
  var txtXBur= (document.getElementById("QuoteCalculatorHome1_ddlBurglaryExtra").value.split(";"));
  intXBur = eval(txtXBur[1]);
  intBurg = 1000;
  intTotBurg = (intBurg + eval(txtXBur[0]));
  
  var txtXLia= (document.getElementById("QuoteCalculatorHome1_ddlLiabilityExtra").value.split(";"));
  intXLia = eval(txtXLia[1]);
  intLiab = 25000;
  intTotLiab = (intLiab + eval(txtXLia[0]));
  
  if ((eval(txtXLia[0])==75000) && (eval(txtDwel[0]) > 150000))
  {
	intXLia = 300;
  }
  
    
  if ((document.getElementById("QuoteCalculatorHome1_rblDeductible_0").checked == true) || (eval(txtDwel[0]) > 150000)) { intDedu = 1; };
  else if (document.getElementById("QuoteCalculatorHome1_rblDeductible_1").checked == true) { intDedu = 0.9; };
  else if (document.getElementById("QuoteCalculatorHome1_rblDeductible_2").checked == true) { intDedu = 0.75; };

  intPremiumANN = ((intDwel * intDedu) + intXCon + intXBur + intXLia);
  
  // update form values      
  document.getElementById("QuoteCalculatorHome1_intCont_Home").value = FormatNumber(intCont);
  document.getElementById("QuoteCalculatorHome1_intTotCont_Home").value = FormatNumber(intTotCont);
  document.getElementById("QuoteCalculatorHome1_intTotBurg_Home").value = FormatNumber(intTotBurg);
  document.getElementById("QuoteCalculatorHome1_intTotLiab_Home").value = FormatNumber(intTotLiab);
  
  document.getElementById("QuoteCalculatorHome1_intPremiumMTH_Home").value = FormatNumber(Math.round((intPremiumANN / 12) * 100)/100);
  document.getElementById("QuoteCalculatorHome1_intPremiumQTR_Home").value = FormatNumber(Math.round((intPremiumANN / 4) * 100)/100);
  document.getElementById("QuoteCalculatorHome1_intPremiumSEMI_Home").value = FormatNumber(Math.round((intPremiumANN / 2) * 100)/100);
  document.getElementById("QuoteCalculatorHome1_intPremiumANN_Home").value = FormatNumber(Math.round((intPremiumANN) * 100)/100);
}

//******************************************
//Validation script for the Home Calculator
//******************************************
function checkQuoteCalculatorHome() 
{
  if (document.getElementById("QuoteCalculatorHome1_ddlState").value == "")
  {
	alert("Please select a state.");
	document.getElementById("QuoteCalculatorHome1_ddlState").focus();
	return false;
  }
  
  if (document.getElementById("QuoteCalculatorHome1_ddlDwelling").value == "0;0;0;0")
  {
	document.getElementById("QuoteCalculatorHome1_ddlDwelling").focus();
	return false;
  }

  if ((document.getElementById("QuoteCalculatorHome1_intPremiumMTH_Home").value == "$0.00") &&
      (document.getElementById("QuoteCalculatorHome1_ddlDwelling").value != "0;0;0;0") &&
	  (document.getElementById("QuoteCalculatorHome1_ddlState").value == "PA"))
  {
	alert("The dwelling limit is not valid.");
	document.getElementById("QuoteCalculatorHome1_ddlDwelling").focus();
	return false;
  }
  
  /*
  if ((document.getElementById("QuoteCalculatorHome1_intPremiumMTH_Home").value == "$0.00") &&
      (document.getElementById("QuoteCalculatorHome1_ddlDwelling").value != "0;0;0;0") &&
	  (document.getElementById("QuoteCalculatorHome1_ddlState").value != "PA"))
  {
	alert("A dwelling limit above $100,000 is only valid in DC, IL, NJ, and PA.");
	document.getElementById("QuoteCalculatorHome1_ddlDwelling").focus();
	return false;
  }
  */
  if ((document.getElementById("QuoteCalculatorHome1_txtZip").value == "") &&
      (document.getElementById("QuoteCalculatorHome1_ddlState").value == "PA"))
  {
	alert("Please enter the zip code.");
	document.getElementById("QuoteCalculatorHome1_txtZip").focus();
	return false;
  }
  if ((document.getElementById("QuoteCalculatorHome1_txtZip").value.length < 5) &&
       (document.getElementById("QuoteCalculatorHome1_ddlState").value == "PA"))
  {
	alert("The zip code must be at least 5 digits long.");
	document.getElementById("QuoteCalculatorHome1_txtZip").focus();
	return false;
  }
  if ((isNaN(document.getElementById("QuoteCalculatorHome1_txtZip").value))&&
      (document.getElementById("QuoteCalculatorHome1_ddlState").value == "PA"))
  {
	alert("The first 5 digits of the zip code must be numbers.");
	document.getElementById("QuoteCalculatorHome1_txtZip").focus();
	return false;
  }
  return true;
}

//****************************************
//Script for the Rent Premium Calculator
//****************************************
function calcRentPremium() 
{

  var txtCont= (document.getElementById("QuoteCalculatorRent1_ddlContents").value.split(";"));
  intCont = eval(txtCont[1]);

  var txtBurg= (document.getElementById("QuoteCalculatorRent1_ddlBurglary").value.split(";"));
  intBurg = eval(txtBurg[1]);

  var txtLiab= (document.getElementById("QuoteCalculatorRent1_ddlLiability").value.split(";"));
  intLiab = eval(txtLiab[1]);
  
  if (document.getElementById("QuoteCalculatorRent1_rblDeductible_0").checked == true) { intDedu = 1; };
  if (document.getElementById("QuoteCalculatorRent1_rblDeductible_1").checked == true) { intDedu = 0.9; };  
  
  if (document.getElementById("QuoteCalculatorRent1_rblLivingExp_0").checked == true) { intLivi = 0; };
  if (document.getElementById("QuoteCalculatorRent1_rblLivingExp_1").checked == true) { intLivi = 12; };
    
  intPremiumANN = ((intCont * intDedu) + intBurg + intLiab + intLivi);
 
// update form values      
  
  document.getElementById("QuoteCalculatorRent1_intPremiumMTH_Rent").value = FormatNumber(Math.round((intPremiumANN / 12) * 100)/100);
  document.getElementById("QuoteCalculatorRent1_intPremiumQTR_Rent").value = FormatNumber(Math.round((intPremiumANN / 4) * 100)/100);
  document.getElementById("QuoteCalculatorRent1_intPremiumSEMI_Rent").value = FormatNumber(Math.round((intPremiumANN / 2) * 100)/100);
  document.getElementById("QuoteCalculatorRent1_intPremiumANN_Rent").value = FormatNumber(Math.round((intPremiumANN) * 100)/100);
}

//******************************************
//Validation script for the Rent Calculator
//******************************************
function checkQuoteCalculatorRent() 
{
  txtCont = (document.getElementById("QuoteCalculatorRent1_ddlContents").value.split(";"));
  intCont = eval(txtCont[0]);
  txtBurg = (document.getElementById("QuoteCalculatorRent1_ddlBurglary").value.split(";"));
  intBurg = eval(txtBurg[0]);
 
  if ((intCont > 10000) && (intBurg == 500))
  {
   
  	alert("The $500 Burglary Limit is only valid in combination with $10,000 Contents.");
	document.getElementById("QuoteCalculatorRent1_ddlBurglary").focus();
	return false;
  }
  
/*  if ((intBurg == 500) && 
      ((document.getElementById("QuoteCalculatorRent1_ddlLiability").value != "0;0") || 
      (document.getElementById("QuoteCalculatorRent1_rblDeductible_1").checked == true)))
  {
  	alert("The $500 Burglary Limit is only valid in combination with $10,000 Contents.");
	document.getElementById("QuoteCalculatorRent1_ddlBurglary").focus();
	return false;
  }*/
}

//****************************************
//Script for the HO8 Premium Calculator
//****************************************
function calcHO8Premium() 
{
    
  var txtDwel= (document.getElementById("QuoteCalculatorTenant1_ddlDwelling").value.split(";"));
    
  if ((document.getElementById("QuoteCalculatorTenant1_txtZip").value != "") &&
      (!isNaN(document.getElementById("QuoteCalculatorTenant1_txtZip").value.slice(0,5))))
    {intZip = eval(document.getElementById("QuoteCalculatorTenant1_txtZip").value.slice(0,5)); }
  else
    {intZip = 0; }
    
        
  if ((document.getElementById("QuoteCalculatorTenant1_ddlState").value == "PA") && ((intZip < 19103) || (intZip > 19154)))
    { intDwel = eval(txtDwel[1]); }
  else
	{
	  intDwel = eval(txtDwel[2]);
	}
  

  var txtLiab= (document.getElementById("QuoteCalculatorTenant1_ddlLiability").value.split(";"));
  intLiab = eval(txtLiab[1]);
  
  if (document.getElementById("QuoteCalculatorTenant1_rblDeductible_0").checked == true) { intDedu = 1; };
  if (document.getElementById("QuoteCalculatorTenant1_rblDeductible_1").checked == true) { intDedu = 0.9; };
  if (document.getElementById("QuoteCalculatorTenant1_rblDeductible_2").checked == true) { intDedu = 0.8; };  
 
    
  intPremiumANN = ((intDwel * intDedu) + intCont + intLiab);
  
  if (document.getElementById("QuoteCalculatorTenant1_rblStudentHousing_0").checked == true)
  {	intPremiumANN = intPremiumANN + (intPremiumANN * 0.2);}
  
  
  // update form values      
  document.getElementById("QuoteCalculatorTenant1_intPremiumQTR_Tenant").value = FormatNumber(Math.round((intPremiumANN / 4) * 100)/100);
  document.getElementById("QuoteCalculatorTenant1_intPremiumSEMI_Tenant").value = FormatNumber(Math.round((intPremiumANN / 2) * 100)/100);
  document.getElementById("QuoteCalculatorTenant1_intPremiumANN_Tenant").value = FormatNumber(Math.round((intPremiumANN) * 100)/100);
}

//****************************************
//Script for the Tenant Premium Calculator
//****************************************
function calcTenantPremium() 
{
  if (document.getElementById("QuoteCalculatorTenant1_rblStudentHousing_0").checked == true)
  {  document.getElementById('QuoteCalculatorTenant1_tblStudent').style.display="block"; }
  else
  {  document.getElementById('QuoteCalculatorTenant1_tblStudent').style.display="none"; }
  
  var txtDwel= (document.getElementById("QuoteCalculatorTenant1_ddlDwelling").value.split(";"));
    
  if ((document.getElementById("QuoteCalculatorTenant1_txtZip").value != "") &&
      (!isNaN(document.getElementById("QuoteCalculatorTenant1_txtZip").value.slice(0,5))))
    {intZip = eval(document.getElementById("QuoteCalculatorTenant1_txtZip").value.slice(0,5)); }
  else
    {intZip = 0; }
    
        // Philadelphia zip range is 19103-19154.
		// Philadelphia, ILLINOIS, NJ, DC & NJ receive the HIGHER rate.  NON-Philadelphia PA, IN & VA receive the LOWER rate
  if (
  		((document.getElementById("QuoteCalculatorTenant1_ddlState").value == "PA") && ((intZip < 19103) || (intZip > 19154))) 
	  || (document.getElementById("QuoteCalculatorTenant1_ddlState").value == "IN") 
	  || (document.getElementById("QuoteCalculatorTenant1_ddlState").value == "VA")
  	)
    { 
	
    intDwel = eval(txtDwel[1]); }
  else
	{
	
	  intDwel = eval(txtDwel[2]);
	}
  
  var txtCont= (document.getElementById("QuoteCalculatorTenant1_ddlContents").value.split(";"));
  intCont = eval(txtCont[1]);

  var txtLiab= (document.getElementById("QuoteCalculatorTenant1_ddlLiability").value.split(";"));
  intLiab = eval(txtLiab[1]);
  
  if (document.getElementById("QuoteCalculatorTenant1_rblDeductible_0").checked == true) { intDedu = 1; };
  if (document.getElementById("QuoteCalculatorTenant1_rblDeductible_1").checked == true) { intDedu = 0.9; };
  if (document.getElementById("QuoteCalculatorTenant1_rblDeductible_2").checked == true) { intDedu = 0.8; };  
 
    
  intPremiumANN = ((intDwel * intDedu) + intCont + intLiab);
  
  if (document.getElementById("QuoteCalculatorTenant1_rblStudentHousing_0").checked == true)
  {	intPremiumANN = intPremiumANN + (intPremiumANN * 0.2);}
  
  
  // update form values      
  document.getElementById("QuoteCalculatorTenant1_intPremiumQTR_Tenant").value = FormatNumber(Math.round((intPremiumANN / 4) * 100)/100);
  document.getElementById("QuoteCalculatorTenant1_intPremiumSEMI_Tenant").value = FormatNumber(Math.round((intPremiumANN / 2) * 100)/100);
  document.getElementById("QuoteCalculatorTenant1_intPremiumANN_Tenant").value = FormatNumber(Math.round((intPremiumANN) * 100)/100);
}

//******************************************
//Validation script for the Tenant Calculator
//******************************************
function checkQuoteCalculatorTenant() 
{
   
  if (document.getElementById("QuoteCalculatorTenant1_ddlState").value == "")
  {
	alert("Please select a state.");
	document.getElementById("QuoteCalculatorTenant1_ddlState").focus();
	return false;
  }
  
  if (document.getElementById("QuoteCalculatorTenant1_ddlDwelling").value == "0;0;0")
  {
	document.getElementById("QuoteCalculatorTenant1_ddlDwelling").focus();
	return false;
  }

  if ((document.getElementById("QuoteCalculatorTenant1_intPremiumQTR_Tenant").value == "$0.00") &&
      (document.getElementById("QuoteCalculatorTenant1_ddlDwelling").value != "0;0;0") 
      && (document.getElementById("QuoteCalculatorTenant1_ddlState").value == "PA"))
  {
	alert("The dwelling limit is not valid.");
	document.getElementById("QuoteCalculatorTenant1_ddlDwelling").focus();
	return false;
  }
  
  if ((document.getElementById("QuoteCalculatorTenant1_txtZip").value == "") &&
      (document.getElementById("QuoteCalculatorTenant1_ddlState").value == "PA"))
  {
	alert("Please enter the zip code.");
	document.getElementById("QuoteCalculatorTenant1_txtZip").focus();
	return false;
  }
  if ((document.getElementById("QuoteCalculatorTenant1_txtZip").value.length < 5) &&
       (document.getElementById("QuoteCalculatorTenant1_ddlState").value == "PA"))
  {
	alert("The zip code must be at least 5 digits long.");
	document.getElementById("QuoteCalculatorTenant1_txtZip").focus();
	return false;
  }
  if ((isNaN(document.getElementById("QuoteCalculatorTenant1_txtZip").value))&&
      (document.getElementById("QuoteCalculatorTenant1_ddlState").value == "PA"))
  {
	alert("The first 5 digits of the zip code must be numbers.");
	document.getElementById("QuoteCalculatorTenant1_txtZip").focus();
	return false;
  }
  return true;
}



//******************************************
//Validation script for the HO8 Calculator
//******************************************
function checkQuoteCalculatorHO8() 
{
   
  if (document.getElementById("QuoteCalculatorTenant1_ddlState").value == "")
  {
	alert("Please select a state.");
	document.getElementById("QuoteCalculatorTenant1_ddlState").focus();
	return false;
  }
  
  if (document.getElementById("QuoteCalculatorTenant1_ddlDwelling").value == "0;0;0")
  {
	document.getElementById("QuoteCalculatorTenant1_ddlDwelling").focus();
	return false;
  }

  if ((document.getElementById("QuoteCalculatorTenant1_intPremiumQTR_Tenant").value == "$0.00") &&
      (document.getElementById("QuoteCalculatorTenant1_ddlDwelling").value != "0;0;0") 
      && (document.getElementById("QuoteCalculatorTenant1_ddlState").value == "PA"))
  {
	alert("The dwelling limit is not valid.");
	document.getElementById("QuoteCalculatorTenant1_ddlDwelling").focus();
	return false;
  }
  
  if ((document.getElementById("QuoteCalculatorTenant1_txtZip").value == "") &&
      (document.getElementById("QuoteCalculatorTenant1_ddlState").value == "PA"))
  {
	alert("Please enter the zip code.");
	document.getElementById("QuoteCalculatorTenant1_txtZip").focus();
	return false;
  }
  if ((document.getElementById("QuoteCalculatorTenant1_txtZip").value.length < 5) &&
       (document.getElementById("QuoteCalculatorTenant1_ddlState").value == "PA"))
  {
	alert("The zip code must be at least 5 digits long.");
	document.getElementById("QuoteCalculatorTenant1_txtZip").focus();
	return false;
  }
  if ((isNaN(document.getElementById("QuoteCalculatorTenant1_txtZip").value))&&
      (document.getElementById("QuoteCalculatorTenant1_ddlState").value == "PA"))
  {
	alert("The first 5 digits of the zip code must be numbers.");
	document.getElementById("QuoteCalculatorTenant1_txtZip").focus();
	return false;
  }
  return true;
}


//****************************************
//Script to format the return values
//****************************************

function FormatNumber(number) {
  var strNumber = number+'';
  var strNumTmp = "";
  var strNumFormat = "";
  var intCount = 0;

//check for decimal number
  if (strNumber.indexOf('.') != -1){ //number ends with decimal point
    if (strNumber.indexOf('.') == strNumber.length-1){
      strNumber += "00";
    }
    if (strNumber.indexOf('.') == strNumber.length-2){ //number ends with single digit
      strNumber += "0";
    }
  
    var strInt = strNumber.split(".");
    strNumber = strInt[0]; //integer part
    var strDec = strInt[1] //decimal place
  }
  else {var strDec = "00";}

//add commas
  for (var i = strNumber.length-1; i >= 0; i--){
    var strOneChar = strNumber.charAt(i);
    if (intCount == 3){
      strNumTmp += ",";
      strNumTmp += strOneChar;
      intCount = 1;
      continue;
    }
    else {
      strNumTmp += strOneChar;
      intCount ++;
    }
  } //string is reversed

//re-reverse the string
  for (var j = strNumTmp.length-1; j >= 0; j--){
    var strOneChar = strNumTmp.charAt(j);
    strNumFormat += strOneChar;
  }

// add dollar sign and decimals from above
  strNumFormat = '$' + strNumFormat + "." + strDec;
  return strNumFormat;
}