function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
		num = "0";
		sign = (num == (num = Math.abs(num)));
		num = Math.floor(num*100+0.50000000001);
		cents = num%100;
		num = Math.floor(num/100).toString();
	if(cents<10)
		cents = "0" + cents;
		for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
			num = num.substring(0,num.length-(4*i+3))+','+
			num.substring(num.length-(4*i+3));
		
	return (((sign)?'':'-') + '$' + num + '.' + cents);
}				
		
function toggle(id)
{					
		if (document.all[id].style.display == "") {
		document.all[id].style.display = "none";				
		}
		else {				
		document.all[id].style.display = "";				
		}
}			

var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;

if (checkIt('konqueror'))
{
	browser = "Konqueror";
	OS = "Linux";
}
else if (checkIt('safari')) browser = "Safari"
else if (checkIt('omniweb')) browser = "OmniWeb"
else if (checkIt('opera')) browser = "Opera"
else if (checkIt('webtv')) browser = "WebTV";
else if (checkIt('icab')) browser = "iCab"
else if (checkIt('msie')) browser = "Internet Explorer"
else if (!checkIt('compatible'))
{
	browser = "Netscape Navigator"
	version = detect.charAt(8);
}
else browser = "An unknown browser";

if (!version) version = detect.charAt(place + thestring.length);

if (!OS)
{
	if (checkIt('linux')) OS = "Linux";
	else if (checkIt('x11')) OS = "Unix";
	else if (checkIt('mac')) OS = "Mac"
	else if (checkIt('win')) OS = "Windows"
	else OS = "an unknown operating system";
}

function checkIt(string)
{
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}		

function CheckThis(msg, ChoiceID, Type, IDExt, AdjustType) {
	var val;
	var ListPriceVal;
	var SalePriceVal;
	var YouSaveVal;
	var strPrice;
	var strListPrice;
	var strSalePrice;
	var strYouSave;			
	
	if (checkIt('msie'))
	{
		strPrice = document.getElementById("lblSitePrice").innerText;
		//strListPrice = document.getElementById("lblListPrice").innerText;				

		if (document.getElementById("lblListPrice") && document.getElementById("lblListPrice").innerText.length > 0)
		{
			strListPrice = document.getElementById("lblListPrice").innerText;
		}
		else
		{
			strListPrice = "-1";
			ListPriceVal = -1;
		}
						
		if (document.getElementById("lblSalePrice") && document.getElementById("lblSalePrice").innerText.length > 0)
		{
			strSalePrice = document.getElementById("lblSalePrice").innerText;
		}
		else
		{
			strSalePrice = "-1";
			SalePriceVal = -1;
		}
		
		if (document.getElementById("lblYouSave") && document.getElementById("lblYouSave").innerText.length > 0)
		{
			strYouSave = document.getElementById("lblYouSave").innerText;
		}
		else
		{
			strYouSave = "-1";
			YouSaveVal = -1;
		}				
						
		strPrice = strPrice.replace("$", "");
		strPrice = strPrice.replace(",", "");
		
		strListPrice = strListPrice.replace("$", "");
		strListPrice = strListPrice.replace(",", "");

		strSalePrice = strSalePrice.replace("$", "");
		strSalePrice = strSalePrice.replace(",", "");
					
		if (Type == "SELECT") {
			msg = document.getElementById("Choice" + ChoiceID).options[document.getElementById("Choice" + ChoiceID).selectedIndex].attributes["PriceAdjust"].value;
			}
		else if (Type == "CHECKBOX")
		{
			if (document.getElementById("Choice" + ChoiceID + "-" + IDExt).checked == false)
				{
					msg = -1 * msg;
				}
		}
			
		val = parseFloat(strPrice);
		
		ListPriceVal = parseFloat(strListPrice);
		SalePriceVal = parseFloat(strSalePrice);							
		
		var priceAdjust = document.getElementById("priceAdjust" + ChoiceID).value;
		
		
									
		if (Type == "CHECKBOX")
		{
			val = val + parseFloat(msg);
			if (AdjustType == 2)
			{
				ListPriceVal = ListPriceVal + (parseFloat(msg) * 1.3);
			}
			else
			{
				ListPriceVal = ListPriceVal + parseFloat(msg);
			}						
			
			SalePriceVal = SalePriceVal + parseFloat(msg);				
			
			if (strSalePrice != "-1")
			{
				YouSaveVal = ListPriceVal - SalePriceVal;
			}
			else
			{
				YouSaveVal = ListPriceVal - val;
			}
		}
		else
		{
			val = val + (parseFloat(msg) - parseFloat(priceAdjust));
			if (AdjustType == 2)
			{					
				ListPriceVal = ListPriceVal + ((parseFloat(msg) * 1.3) - (parseFloat(priceAdjust) * 1.3));
			}
			else
			{
				ListPriceVal = ListPriceVal + (parseFloat(msg) - parseFloat(priceAdjust));
			}
			SalePriceVal = SalePriceVal + (parseFloat(msg) - parseFloat(priceAdjust));		
					
			if (strSalePrice != "-1")
			{
				YouSaveVal = ListPriceVal - SalePriceVal;
			}
			else
			{
				YouSaveVal = ListPriceVal - val;
			}
		}
		
		document.getElementById("lblSitePrice").innerText = formatCurrency(val);
		if (document.getElementById("lblListPrice") && document.getElementById("lblListPrice").innerText.length > 0)
		{
			document.getElementById("lblListPrice").innerText = formatCurrency(ListPriceVal);
		}
		if (strSalePrice != "-1")
		{
			document.getElementById("lblSalePrice").innerText = formatCurrency(SalePriceVal);
		}
		if (strYouSave != "-1")
		{
			document.getElementById("lblYouSave").innerText = formatCurrency(YouSaveVal);
		}
		
		document.getElementById("priceAdjust" + ChoiceID).value = parseFloat(msg);
	}
	else
	{
		strPrice = document.getElementById("lblSitePrice").textContent;
		//strListPrice = document.getElementById("lblListPrice").textContent;				

		if (document.getElementById("lblListPrice") && document.getElementById("lblListPrice").textContent.length > 0)
		{
			strListPrice = document.getElementById("lblListPrice").textContent;
		}
		else
		{
			strListPrice = "-1";
			ListPriceVal = -1;
		}
						
		if (document.getElementById("lblSalePrice") && document.getElementById("lblSalePrice").textContent.length > 0)
		{
			strSalePrice = document.getElementById("lblSalePrice").textContent;
		}
		else
		{
			strSalePrice = "-1";
			SalePriceVal = -1;
		}
		
		if (document.getElementById("lblYouSave") && document.getElementById("lblYouSave").textContent.length > 0)
		{
			strYouSave = document.getElementById("lblYouSave").textContent;
		}
		else
		{
			strYouSave = "-1";
			YouSaveVal = -1;
		}				
						
		strPrice = strPrice.replace("$", "");
		strPrice = strPrice.replace(",", "");
		
		strListPrice = strListPrice.replace("$", "");
		strListPrice = strListPrice.replace(",", "");

		strSalePrice = strSalePrice.replace("$", "");
		strSalePrice = strSalePrice.replace(",", "");
					
		if (Type == "SELECT") {
			msg = document.getElementById("Choice" + ChoiceID).options[document.getElementById("Choice" + ChoiceID).selectedIndex].attributes["PriceAdjust"].value;
			}
		else if (Type == "CHECKBOX")
		{
			if (document.getElementById("Choice" + ChoiceID + "-" + IDExt).checked == false)
				{
					msg = -1 * msg;
				}
		}
			
		val = parseFloat(strPrice);
		
		ListPriceVal = parseFloat(strListPrice);
		SalePriceVal = parseFloat(strSalePrice);							
		
		var priceAdjust = document.getElementById("priceAdjust" + ChoiceID).value;
		
		
									
		if (Type == "CHECKBOX")
		{
			val = val + parseFloat(msg);
			if (AdjustType == 2)
			{
				ListPriceVal = ListPriceVal + (parseFloat(msg) * 1.3);
			}
			else
			{
				ListPriceVal = ListPriceVal + parseFloat(msg);
			}						
			
			SalePriceVal = SalePriceVal + parseFloat(msg);				
			
			if (strSalePrice != "-1")
			{
				YouSaveVal = ListPriceVal - SalePriceVal;
			}
			else
			{
				YouSaveVal = ListPriceVal - val;
			}
		}
		else
		{
			val = val + (parseFloat(msg) - parseFloat(priceAdjust));
			if (AdjustType == 2)
			{					
				ListPriceVal = ListPriceVal + ((parseFloat(msg) * 1.3) - (parseFloat(priceAdjust) * 1.3));
			}
			else
			{
				ListPriceVal = ListPriceVal + (parseFloat(msg) - parseFloat(priceAdjust));
			}
			SalePriceVal = SalePriceVal + (parseFloat(msg) - parseFloat(priceAdjust));		
					
			if (strSalePrice != "-1")
			{
				YouSaveVal = ListPriceVal - SalePriceVal;
			}
			else
			{
				YouSaveVal = ListPriceVal - val;
			}
		}
		
		document.getElementById("lblSitePrice").textContent = formatCurrency(val);
		if (document.getElementById("lblListPrice") && document.getElementById("lblListPrice").textContent.length > 0)
		{
			document.getElementById("lblListPrice").textContent = formatCurrency(ListPriceVal);
		}
		if (strSalePrice != "-1")
		{
			document.getElementById("lblSalePrice").textContent = formatCurrency(SalePriceVal);
		}
		if (strYouSave != "-1")
		{
			document.getElementById("lblYouSave").textContent = formatCurrency(YouSaveVal);
		}
		
		document.getElementById("priceAdjust" + ChoiceID).value = parseFloat(msg);
	}
}