//function CalcAdjustments()
//function UpdateSubjectProperty()
//function CallStats(myform)
//function EMailMultiples(PropType)
//function PrintMultiples(PropType)
//function FormatC(theValue, InOrOut)
//function openNewWindow(fileName,windowName,theWidth,theHeight) 
//function checkPrice()
//function numbercheck(numberitem)
	
function CalcAdjustments()
{
	var TotalAdditions = 0;
	var TotalSubtractions = 0;
	var TotalSugg = 0;
	var TotalAvePrice = 0;
	var CurValue = "";
	var MinList = 0;
	var MaxList = 0;
	var SQFT = 0;
	//var newcount = 0;
	var TempString = "";
	
	if(!document.mainform.AddAmount1.value == "")
		TotalAdditions = TotalAdditions + parseInt(document.mainform.AddAmount1.value);
		//document.mainform.AddAmount1Print.value = document.mainform.AddAmount1.value;
		//document.mainform.AddText1Print.value = document.mainform.AddText1.value;
	if(!document.mainform.AddAmount2.value == "")
		TotalAdditions = TotalAdditions + parseInt(document.mainform.AddAmount2.value);
		//document.mainform.AddAmount2Print.value = document.mainform.AddAmount2.value;
		//document.mainform.AddText2Print.value = document.mainform.AddText2.value;
	if(!document.mainform.AddAmount3.value == "")
		TotalAdditions = TotalAdditions + parseInt(document.mainform.AddAmount3.value);
		//document.mainform.AddAmount3Print.value = document.mainform.AddAmount3.value;
		//document.mainform.AddText3Print.value = document.mainform.AddText3.value;
	
	if(!document.mainform.SubAmount1.value == "")
		TotalSubtractions = TotalSubtractions + parseInt(document.mainform.SubAmount1.value);
		//document.mainform.SubAmount1Print.value = document.mainform.SubAmount1.value;
		//document.mainform.SubText1Print.value = document.mainform.SubText1.value;
	if(!document.mainform.SubAmount2.value == "")
		TotalSubtractions = TotalSubtractions + parseInt(document.mainform.SubAmount2.value);
		//document.mainform.SubAmount2Print.value = document.mainform.SubAmount2.value;
		//document.mainform.SubText2Print.value = document.mainform.SubText2.value;
	if(!document.mainform.SubAmount3.value == "")
		TotalSubtractions = TotalSubtractions + parseInt(document.mainform.SubAmount3.value);
		//document.mainform.SubAmount3Print.value = document.mainform.SubAmount3.value;
		//document.mainform.SubText3Print.value = document.mainform.SubText3.value;
	
	//Get Average Sale Price
	CurValue = parseInt(FormatC(document.mainform.AveSalePrice.value, "O"));
	//Compute Target Price
	TotalSugg = CurValue + TotalAdditions - TotalSubtractions;
	//Show new Values
	document.mainform.TargPrice.value = TotalSugg;
	document.mainform.TargPrice.value = "$" + FormatC(document.mainform.TargPrice.value, "I");
	//document.mainform.TargPricePrint.value = document.mainform.TargPrice.value;
	document.mainform.intTotalAdd.value = TotalAdditions;
	document.mainform.intTotalAdd.value = "$" + FormatC(document.mainform.intTotalAdd.value, "I");
	//document.mainform.intTotalAddPrint.value = TotalAdditions;
	//document.mainform.intTotalAddPrint.value = FormatC(document.mainform.intTotalAddPrint.value, "I");
	document.mainform.intTotalSub.value = TotalSubtractions;
	document.mainform.intTotalSub.value = "-$" + FormatC(document.mainform.intTotalSub.value, "I");
	//document.mainform.intTotalSubPrint.value = TotalSubtractions;
	//document.mainform.intTotalSubPrint.value = FormatC(document.mainform.intTotalSubPrint.value, "I");
	
	var AdjustmentRange = parseInt(document.mainform.AdjustmentRange.value);
	if(AdjustmentRange == 100)
		CurValue = 0;
	if(AdjustmentRange > 100)
		CurValue = parseInt(TotalSugg * ((AdjustmentRange-100)/100));
	if(AdjustmentRange < 100)
		CurValue = parseInt(TotalSugg * ((AdjustmentRange)/100));
	MinList = TotalSugg - CurValue;
	MaxList = TotalSugg + CurValue;
	
	if(MinList >= 0)
		{
		document.mainform.NewMinList.value = MinList;
		document.mainform.NewMinList.value = "$" + FormatC(document.mainform.NewMinList.value, "I");
		//document.mainform.MinPricePrint.value = MinList;
		//document.mainform.MinPricePrint.value = FormatC(document.mainform.MinPricePrint.value, "I");
		}
	if(MaxList >= 0)
		{
		document.mainform.NewMaxList.value = MaxList;
		document.mainform.NewMaxList.value = "$" + FormatC(document.mainform.NewMaxList.value, "I");
		//document.mainform.MaxPricePrint.value = MaxList;
		//document.mainform.MaxPricePrint.value = FormatC(document.mainform.MaxPricePrint.value, "I");
		}
		
	//SQFT = document.mainform.calc_SQFT.value;
	SQFT = document.mainform.SubjSqft.value;
	//document.mainform.SugPricePrint.value = parseInt(document.mainform.SugPrice.value);
	
	if(SQFT > 0)
		{
		document.mainform.NewMinSQFT.value = parseInt(MinList/SQFT);
		document.mainform.NewMinSQFT.value = "$" + FormatC(document.mainform.NewMinSQFT.value, "I");
		//document.mainform.MinPriceSQFTPrint.value = document.mainform.NewMinSQFT.value;
		document.mainform.NewMaxSQFT.value = parseInt(MaxList/SQFT);
		document.mainform.NewMaxSQFT.value = "$" + FormatC(document.mainform.NewMaxSQFT.value, "I");
		//document.mainform.MaxPriceSQFTPrint.value = document.mainform.NewMaxSQFT.value;
	
		document.mainform.TargPriceSQFT.value = parseInt(TotalSugg/SQFT);
		document.mainform.TargPriceSQFT.value = "$" + FormatC(document.mainform.TargPriceSQFT.value, "I");
		//document.mainform.TargPriceSQFTPrint.value = document.mainform.TargPriceSQFT.value;
		
		if(document.mainform.SugPrice.value > 0)
			{
			document.mainform.SugPriceSQFT.value = parseInt(document.mainform.SugPrice.value/SQFT);
			document.mainform.SugPriceSQFT.value = "$" + FormatC(document.mainform.SugPriceSQFT.value, "I");
			//document.mainform.SugPriceSQFTPrint.value = document.mainform.SugPriceSQFT.value;
			}
		else
			document.mainform.SugPriceSQFT.value = "$0";
		}
	else  // SQFT=0 so $ per SQFT = $0
		{
		document.mainform.NewMinSQFT.value = "$0";
		document.mainform.NewMaxSQFT.value = "$0";
		document.mainform.TargPriceSQFT.value = "$0";
		//document.mainform.TargPriceSQFTPrint.value = "$0";
		document.mainform.SugPriceSQFT.value = "$0";
		}
	
	//document.mainform.DeBugText.value = MinList; //TempString;//TotalSugg;
	
}

function UpdateSubjectProperty()
{
	SubjNamePrint.innerHTML = document.mainform.SubjName.value;
	SubjAddPrint.innerHTML = document.mainform.SubjAdd.value + ", " + document.mainform.SubjCSZ.value;
	if(!document.mainform.Feature1.value == "")
		SubjBullet1Print.innerHTML = "<img src='images/red_diam.gif' WIDTH=11 HEIGHT=11 border=0><font face=Arial size=3>" + document.mainform.Feature1.value + "</font>";
	else
		SubjBullet1Print.innerHTML = "";
	if(!document.mainform.Feature2.value == "")
		SubjBullet2Print.innerHTML = "<img src='images/red_diam.gif' WIDTH=11 HEIGHT=11 border=0><font face=Arial size=3>" + document.mainform.Feature2.value + "</font>";
	else
		SubjBullet2Print.innerHTML = "";
	if(!document.mainform.Feature3.value == "")
		SubjBullet3Print.innerHTML = "<img src='images/red_diam.gif' WIDTH=11 HEIGHT=11 border=0><font face=Arial size=3>" + document.mainform.Feature3.value + "</font>";
	else
		SubjBullet3Print.innerHTML = "";
	if(!document.mainform.Feature4.value == "")
		SubjBullet4Print.innerHTML = "<img src='images/red_diam.gif' WIDTH=11 HEIGHT=11 border=0><font face=Arial size=3>" + document.mainform.Feature4.value + "</font>";
	else
		SubjBullet4Print.innerHTML = "";
	if(!document.mainform.Feature5.value == "")
		SubjBullet5Print.innerHTML = "<img src='images/red_diam.gif' WIDTH=11 HEIGHT=11 border=0><font face=Arial size=3>" + document.mainform.Feature5.value + "</font>";
	else
		SubjBullet5Print.innerHTML = "";
}

function CallStats(myform)
{
	var myArea = ""
	if(myform.SubjArea.value.length > 2)
		{
		for (i=0; i < 2; i++)
			myArea = myArea  + myform.SubjArea.value.charAt(i)
		}
	else
		myArea = myform.SubjArea.value;
		
	location.href="/CMT_Statistics.asp?start_date=6&START_PRICE=" + myform.minPrice.value + "&END_PRICE=" + myform.maxPrice.value + "&AREA='" + myArea + "'&prop_type=" + myform.SubjPType.value + "&search=1"
	//location.href="/testview.asp?start_date=6&START_PRICE=" + myform.minPrice.value + "&END_PRICE=" + myform.maxPrice.value + "&AREA='" + myArea + "'&prop_type=" + myform.SubjPType.value + "&search=1"
}


function EMailMultiples(PropType)
{
	var MinList		= document.mainform.NewMinList.value;
	var MaxList		= document.mainform.NewMaxList.value;
	var Area		= document.mainform.SubjArea.value;
	var Suggested	= document.mainform.SugPrice.value;

	openNewWindow('http://' + domain + '/wizards/cma_email/wiz_CMA_Email.asp?prop_type=' + PropType + '&price_low=' + MinList + '&price_high=' + MaxList + '&sugg=' + Suggested,'newMessageWindow',400,400);
	//openNewWindow('http://' + domain + '/wizards/cma_email/wiz_CMA_Email.asp?prop_type=" & PropType & "&ReportID=" & trim(request("ReportID")) & "&price_low=' + MinList + '&price_high=' + MaxList + '&sugg=' + document.mainform.SugPrice.value,'newMessageWindow',400,400);
}


function PrintMultiples(PropType)
{
	var MinList		= document.mainform.NewMinList.value;
	var MaxList		= document.mainform.NewMaxList.value;
	var Area		= document.mainform.SubjArea.value;
	var Suggested	= document.mainform.SugPrice.value;

	window.location = 'http://' + domain + '/wizards/cma_print/wiz_CMA_Print.asp?prop_type=' + PropType + '&price_low=' + MinList + '&price_high=' + MaxList + '&sugg=' + Suggested;
	//openNewWindow('wiz_CMA_Email.asp?prop_type=" & PropType & "&ReportID=" & trim(request("ReportID")) & "&price_low=' + MinList + '&price_high=' + MaxList + '&sugg=' + document.mainform.SugPrice.value,'newMessageWindow',400,400);
}


function FormatC(theValue, InOrOut)
{
	var CurValue = "";
	var newcount = 0;
	
	//theValue = theValue.toString
	
	switch (InOrOut)
	{
	case "O":
		for (var i = 0; i < theValue.length; i++)
			{
			if(theValue.charAt(i) != ",")
				{
				CurValue = CurValue + theValue.charAt(i);
				newcount = newcount + 1;
				}
			}
		return CurValue;
	break;
	
	case "I":
		for (var i = theValue.length; i >= 0; i--)
			{
			if(newcount == 4)
				{
				CurValue = "," + CurValue;
				newcount = 0;
				i++;
				}
			else
				CurValue = theValue.charAt(i) + CurValue;
			newcount = newcount + 1;
			//if(!i == theValue.length && !i == 0)
			}
		return CurValue;
	break;
	
	}
	
}

function checkPrice()
{
	if (!int_val_check(document.mainform.elements[Get_Fieldname(document.mainform, "SugPrice")],99999999))
		return false;
	else
		return true;
}

function numbercheck(numberitem)
{
	var itemtext;
	itemtext=numberitem.value;
	if(itemtext=="")
		return;
	if(!isaPosInt(itemtext))
	{
		alert("You must enter a number in this box.");
		numberitem.value="";
	}
}
