	
	function populateBusline(theForm)
	{
		theForm.callsA.value = "200,000";
		theForm.callsB.value = theForm.callsA.value;
		theForm.minutesA.value = "400,000";
		theForm.minutesB.value = "100,000";
		theForm.minutesC.value = "300,000";
		theForm.hoursA.value = "6,666";
		theForm.hoursB.value = "1,666";
		theForm.hoursC.value = "5,000";
		theForm.costA.value = "$133,333";
		theForm.costB.value = "$33,333";
		theForm.costC.value = "$100,000";
		theForm.hourlyWage.value = "20";
	}

	function populateHandyline(theForm)
	{
		theForm.callsA.value = "200,000";
		theForm.callsB.value = theForm.callsA.value;
		theForm.minutesA.value = "800,000";
		theForm.minutesB.value = "560,000";
		theForm.minutesC.value = "240,000";
		theForm.hoursA.value = "13,333";
		theForm.hoursB.value = "9,333";
		theForm.hoursC.value = "4,000";
		theForm.costA.value = "$266,666";
		theForm.costB.value = "$186,666";
		theForm.costC.value = "$80,000";
		theForm.hourlyWage.value = "20";
	}
	function validateForm(formName)
	{
		resultVal= true;
		if (formName == "busline")
		{
			if (document.busline.callsA.value == "")
			{
				alert ("You need to fill in how many calls Property A handles annually");
				resultVal= false;
			}
			else
			{
				if (!checkNum(document.busline.callsA.value))
				{
					alert ("You must enter a positive numerical value for how many calls Property A handles annually");
					resultVal= false;
				}
			}
			if (document.busline.hourlyWage.value == "")
			{
				alert ("You need to fill in how much Agent Labor costs per hour");
				resultVal= false;
			}
			else
			{
				if (!checkNum(document.busline.hourlyWage.value))
				{
					alert("You must enter a positive numerical value for how much Agent Labor costs per hour");
					resultVal= false;
				}
			}
		}
		else
		{
			if (document.handyline.callsA.value == "")
			{
				alert ("You need to fill in how many calls Property A handles annually");
				resultVal= false;
			}
			else
			{
				if (!checkNum(document.handyline.callsA.value))
				{
					alert ("You must enter a positive numerical value for how many calls Property A handles annually");
					resultVal= false;
				}
			}
			if (document.handyline.hourlyWage.value == "")
			{
				alert ("You need to fill in how much Agent Labor costs per hour");
				resultVal= false;
			}
			else
			{
				if (!checkNum(document.handyline.hourlyWage.value))
				{
					alert("You must enter a numerical value for how much Agent Labor costs per hour");
					resultVal= false;
				}
			}
		}
		if (resultVal)
			calculateValues(formName);
	}  

	function calculateValues(formName)
	{
		var callsA = 0.0;
		var callsB = 0.0;
		var hourlyWage = 0.0;
		var propertyAMinutes = 0.0;
		var propertyBMinutes = 0.0;
		var percentByAgentA = 0.0;
		var percentByIVRA = 0.0;
		var percentByAgentB = 0.0;
		var percentByIVRB = 0.0;
		
		if (formName == "busline")
		{
			callsA = stripCommas(document.busline.callsA.value);
			callsB = callsA;
			hourlyWage = document.busline.hourlyWage.value;
			propertyAMinutes = 2;
		    propertyBMinutes = 2;
			percentByAgentA = 1.0;
			percentByIVRA = 0.0;
			percentByAgentB = 0.25;
			percentByIVRB = 0.75;
		}
		else
		{
			callsA = stripCommas(document.handyline.callsA.value);
			callsB = callsA;
			hourlyWage = document.handyline.hourlyWage.value;
			propertyAMinutes = 4;
		    propertyBMinutes = 4;
			percentByAgentA = 1.0;
			percentByIVRA = 0.0;
			percentByAgentB = 0.7;
			percentByIVRB = 0.3;
		}
		agentMinutesA = callsA * propertyAMinutes * percentByAgentA;
		agentMinutesB = callsB * propertyBMinutes * percentByAgentB;
		agentMinutesC = agentMinutesA - agentMinutesB;
		
		agentHoursA = agentMinutesA / 60;
		agentHoursB = agentMinutesB / 60;
		agentHoursC = agentHoursA - agentHoursB;
		totalCostA = agentHoursA * hourlyWage;
		totalCostB = agentHoursB * hourlyWage;
		totalCostC = totalCostA - totalCostB;
		outputToForm(formName, agentMinutesA, agentMinutesB, agentMinutesC, agentHoursA, agentHoursB, agentHoursC, totalCostA, totalCostB, totalCostC,callsA);
	}
	
	function outputToForm(formName, agentMinutesA, agentMinutesB, agentMinutesC, agentHoursA, agentHoursB, agentHoursC, totalCostA, totalCostB, totalCostC,callsA)
	{
		if (formName == "busline")
		{
 	    document.busline.callsB.value = spaceout(callsA);
			document.busline.minutesA.value = spaceout(roundOff2(agentMinutesA));
			document.busline.minutesB.value = spaceout(roundOff2(agentMinutesB));
			document.busline.minutesC.value = spaceout(roundOff2(agentMinutesC));
			document.busline.hoursA.value = spaceout(roundOff2(agentHoursA));
			document.busline.hoursB.value = spaceout(roundOff2(agentHoursB));
			document.busline.hoursC.value = spaceout(roundOff2(agentHoursC));
			document.busline.costA.value = "$" + spaceout((roundOff2(totalCostA)));
			document.busline.costB.value = "$" + spaceout((roundOff2(totalCostB)));
			document.busline.costC.value = "$" + spaceout((roundOff2(totalCostC)));
		}
		else
		{
		  document.handyline.callsB.value = spaceout(callsA);
			document.handyline.minutesA.value = spaceout(roundOff2(agentMinutesA));
			document.handyline.minutesB.value = spaceout(roundOff2(agentMinutesB));
			document.handyline.minutesC.value = spaceout(roundOff2(agentMinutesC));
			document.handyline.hoursA.value = spaceout(roundOff2(agentHoursA));
			document.handyline.hoursB.value = spaceout(roundOff2(agentHoursB));
			document.handyline.hoursC.value = spaceout(roundOff2(agentHoursC));
			document.handyline.costA.value = "$" + spaceout((roundOff2(totalCostA)));
			document.handyline.costB.value = "$" + spaceout((roundOff2(totalCostB)));
			document.handyline.costC.value = "$" + spaceout((roundOff2(totalCostC)));
		}
	}
	function roundOff2(value)
	{
		var tempValue = 0;
		var tempString = "";
		var tempIndex = 0;
		tempString = value.toString();
		tempIndex = tempString.indexOf("."); // 1 based
		if (tempIndex != -1)
			return (tempString.substring(0,(tempIndex)));
		else
			return value;
	}
		
    function checkNum(thisValue)
    {
	   tempValue = stripCommas(thisValue);
       if (isNaN(tempValue))
			return false;
		 else
		     return true; 
    }
    

function openNewWin(url)
{
   var relativeWidth = screen.width;
   var relativeHeight = screen.width / 2.13;  
   var settings = 'resizable=yes,screenX=0,screenY=0,width=' + relativeWidth + ',height=' + relativeHeight;
window.open(url,'newWindow',settings);
}

function spaceout(number)
{
	numString = number.toString();
	numStringLen = numString.length;
	iterations = numStringLen / 3;
	iterations = Math.floor(iterations);
	remainder = numStringLen % 3;
	if ((iterations < 1) || (numStringLen < 4))
		return numString;
	else
	{
	  iterations++;
		partsArray = new Array();
		currIndex = 0;
  	
		for (i=0; i<iterations; i++)
		{
			 if (i == 0)
			 {
	 		 		partsArray[i] = (numString.substring(0,remainder));
					currIndex = remainder;
			 }
			 else
			 {
			   partsArray[i] = (numString.substring(currIndex, currIndex+3));  
				 currIndex += 3;
			}
		}
		
		returnString = "";
		for (i=0; i<iterations; i++)
		{
		 		if (i != (iterations-1))
			 		  returnString += (partsArray[i] + ",");
				else
						returnString += partsArray[i];
		}
		if (remainder == 0)
			 returnString = returnString.substring(1,returnString.length);
		return returnString;
				
	}
}

function stripCommas(numValue)
{
  returnString = "";
  numString = numValue.toString();
  if (numString.indexOf(",") != -1)
  {
	   re = /,/g
  	 returnString = numString.replace(re,"");
  	 return returnString;       
   }
  else
  		return Math.round(numValue);
}	