// JavaScript Document
function switchimage(filename, alttag)
{
	if (document.getElementById)
	{
        document.getElementById("imagedisplay").style.backgroundImage = "url(../images/" + filename + ")";
		document.getElementById("imagetitle").innerHTML = "<h2>" + alttag + "</h2>";
	}
    else /*if (document.all)*/
	{
        document.all["imagedisplay"].style.backgroundImage = "url(../images/" + filename + ")";
		document.all["imagetitle"].innerHTML = "<h2>" + alttag + "</h2>";
	}
}

function switchtileimage(filename, alttag)
{
	if (document.getElementById)
	{
        document.getElementById("imagetiledisplay").src = "../images/" + filename;
		document.getElementById("imagetitle").innerHTML = "<h2>" + alttag + "</h2>";
		document.getElementById("emailquery").innerHTML = "<label><a hre"+"f='mai"+"lto:sal"+"es@"+"dorami"+"cs."+"ie?sub"+"ject=Website Enquiry – Pavigres 21 – "+alttag+"'>Contact us about this colour</a></label>";
	}
    else /*if (document.all)*/
	{
        document.all["imagetiledisplay"].src = "../images/" + filename;
		document.all["imagetitle"].innerHTML = "<h2>" + alttag + "</h2>";
		document.all["emailquery"].innerHTML = "<label><a hre"+"f='mai"+"lto:sal"+"es@"+"dorami"+"cs."+"ie?sub"+"ject=Website Enquiry – Pavigres 21 – "+alttag+"'>Contact us about this colour</a></label>";
	}
}

function selectmetric()
{
	if (document.getElementById)
	{
		document.getElementById("measurementsys1").checked = "checked";
		document.getElementById("wall1_label").innerHTML = "m";
		document.getElementById("floor_label").innerHTML = "m";
		document.getElementById("wall2_label").innerHTML = "m";
		document.getElementById("floorprice_label").innerHTML = "per m";
		document.getElementById("wall3_label").innerHTML = "m";
		document.getElementById("wall4_label").innerHTML = "m";
		document.getElementById("floorsub_label").innerHTML = "m";
		document.getElementById("wallprice_label").innerHTML = "per m";
		document.getElementById("wallsubdoor_label").innerHTML = "m";
		document.getElementById("wallsubwindow_label").innerHTML = "m";
		document.getElementById("wallsubbath_label").innerHTML = "m";
	}
	calculateform();
}

function selectimperial()
{
	if (document.getElementById)
	{
		document.getElementById("measurementsys2").checked = "checked";
		document.getElementById("wall1_label").innerHTML = "ft";
		document.getElementById("floor_label").innerHTML = "ft";
		document.getElementById("wall2_label").innerHTML = "ft";
		document.getElementById("floorprice_label").innerHTML = "per ft";
		document.getElementById("wall3_label").innerHTML = "ft";
		document.getElementById("wall4_label").innerHTML = "ft";
		document.getElementById("floorsub_label").innerHTML = "ft";
		document.getElementById("wallprice_label").innerHTML = "per ft";
		document.getElementById("wallsubdoor_label").innerHTML = "ft";
		document.getElementById("wallsubwindow_label").innerHTML = "ft";
		document.getElementById("wallsubbath_label").innerHTML = "ft";
	}
	calculateform();
}

function calculateform()
{	
	$wall1width = 0;
	$wall1height = 0;
	$floorwidth = 0;
	$floorheight = 0;
	$wall2width = 0;
	$wall2height = 0;
	$floorprice = 0;
	$wall3width = 0;
	$wall3height = 0;
	$wall4width = 0;
	$wall4height = 0;
	$floorsubwidth = 0;
	$floorsubheight = 0;
	$wallprice = 0;
	$wallsubdoorwidth = 0;
	$wallsubdoorheight = 0;
	$wallsubwindowwidth = 0;
	$wallsubwindowheight = 0;
	$wallsubbathwidth = 0;
	$wallsubbathheight = 0;

	$totalwallarea = 0;
	$totalwallprice = 0;
	$totalfloorarea = 0;
	$totalfloorprice = 0;
	$totalprice = 0;

	$pagecontent = "";
	
	if (document.getElementById)
	{
		$measurementsystem = document.getElementById("measurementsys1").checked;
		if ($measurementsystem)
			$units = "m";
		else
			$units = "ft";

		if (document.getElementById("wall1width").value == "") document.getElementById("wall1width").value=0;
		if (document.getElementById("wall1height").value == "")	document.getElementById("wall1height").value=0;
		if (document.getElementById("floorwidth").value == "") document.getElementById("floorwidth").value=0;
		if (document.getElementById("floorheight").value == "") document.getElementById("floorheight").value=0;
		if (document.getElementById("wall2width").value == "") document.getElementById("wall2width").value=0;
		if (document.getElementById("wall2height").value == "") document.getElementById("wall2height").value=0;
		if (document.getElementById("floorprice").value == "") document.getElementById("floorprice").value=0;
		if (document.getElementById("wall3width").value == "") document.getElementById("wall3width").value=0;
		if (document.getElementById("wall3height").value == "") document.getElementById("wall3height").value=0;
		if (document.getElementById("wall4width").value == "") document.getElementById("wall4width").value=0;
		if (document.getElementById("wall4height").value == "") document.getElementById("wall4height").value=0;
		if (document.getElementById("floorsubwidth").value == "") document.getElementById("floorsubwidth").value=0;
		if (document.getElementById("floorsubheight").value == "") document.getElementById("floorsubheight").value=0;
		if (document.getElementById("wallprice").value == "") document.getElementById("wallprice").value=0;
		if (document.getElementById("wallsubdoorwidth").value == "") document.getElementById("wallsubdoorwidth").value=0;
		if (document.getElementById("wallsubdoorheight").value == "") document.getElementById("wallsubdoorheight").value=0;
		if (document.getElementById("wallsubwindowwidth").value == "") document.getElementById("wallsubwindowwidth").value=0;
		if (document.getElementById("wallsubwindowheight").value == "") document.getElementById("wallsubwindowheight").value=0;
		if (document.getElementById("wallsubbathwidth").value == "") document.getElementById("wallsubbathwidth").value=0;
		if (document.getElementById("wallsubbathheight").value == "") document.getElementById("wallsubbathheight").value=0;

		$wall1width = parseFloat(document.getElementById("wall1width").value);
		$wall1height = parseFloat(document.getElementById("wall1height").value);
		$floorwidth = parseFloat(document.getElementById("floorwidth").value);
		$floorheight = parseFloat(document.getElementById("floorheight").value);
		$wall2width = parseFloat(document.getElementById("wall2width").value);
		$wall2height = parseFloat(document.getElementById("wall2height").value);
		$floorprice = parseFloat(document.getElementById("floorprice").value);
		$wall3width = parseFloat(document.getElementById("wall3width").value);
		$wall3height = parseFloat(document.getElementById("wall3height").value);
		$wall4width = parseFloat(document.getElementById("wall4width").value);
		$wall4height = parseFloat(document.getElementById("wall4height").value);
		$floorsubwidth = parseFloat(document.getElementById("floorsubwidth").value);
		$floorsubheight = parseFloat(document.getElementById("floorsubheight").value);
		$wallprice = parseFloat(document.getElementById("wallprice").value);
		$wallsubdoorwidth = parseFloat(document.getElementById("wallsubdoorwidth").value);
		$wallsubdoorheight = parseFloat(document.getElementById("wallsubdoorheight").value);
		$wallsubwindowwidth = parseFloat(document.getElementById("wallsubwindowwidth").value);
		$wallsubwindowheight = parseFloat(document.getElementById("wallsubwindowheight").value);
		$wallsubbathwidth = parseFloat(document.getElementById("wallsubbathwidth").value);
		$wallsubbathheight = parseFloat(document.getElementById("wallsubbathheight").value);
	}
	
	if(!isNaN($wall1width) && !isNaN($wall1height) && !isNaN($wall2width) && !isNaN($wall2height) && !isNaN($wall3width) && !isNaN($wall3height) && !isNaN($wall4width) && !isNaN($wall4height) && !isNaN($floorwidth) && !isNaN($floorheight) && !isNaN($wallprice) && !isNaN($floorprice))
	{
		$totalwallarea = ($wall1width*$wall1height) + ($wall2width*$wall2height) + ($wall3width*$wall3height) + ($wall4width*$wall4height);
		$totalwallarea = $totalwallarea - ($wallsubdoorwidth*$wallsubdoorheight) - ($wallsubwindowwidth*$wallsubwindowheight) - ($wallsubbathwidth*$wallsubbathheight);
		$totalfloorarea = ($floorwidth*$floorheight) - ($floorsubwidth*$floorsubheight);

		$totalwallprice = $totalwallarea*$wallprice;
		$totalfloorprice = $totalfloorarea*$floorprice;

		$totalprice = $totalwallprice+$totalfloorprice;

		$pagecontent = "<h2 style=\"font-size:1.3em;\">Results</h2>";
		$pagecontent += "Wall area: <strong>" + $totalwallarea.toFixed(2) + " " + $units + "<span class=\"superscript\">2</span></strong><br />";
		$pagecontent += "Wall price: <strong>&euro;" + $totalwallprice.toFixed(2) + "</strong><br /><br />";
		$pagecontent += "Floor area: <strong>" + $totalfloorarea.toFixed(2) + " " +$units + "<span class=\"superscript\">2</span></strong><br />";
		$pagecontent += "Floor price: <strong>&euro;" + $totalfloorprice.toFixed(2) + "</strong><br /><br />";
		$pagecontent += "Total price: <strong>&euro;" + $totalprice.toFixed(2) + "</strong>";

	}
	else
	{
		$pagecontent = "<h2 style=\"font-size:1.3em;\">Oops!</h2><br />You have entered an invalid value. Please make sure you've entered only numbers.";
			
		if (isNaN($wall1width))
			document.getElementById("wall1width").select()
		else if (isNaN($wall1height))
			document.getElementById("wall1height").select()
		else if (isNaN($wall2width))
			document.getElementById("wall2width").select()
		else if (isNaN($wall2height))
			document.getElementById("wall2height").select()
		else if (isNaN($wall3width))
			document.getElementById("wall3width").select()
		else if (isNaN($wall3height))
			document.getElementById("wall3height").select()
		else if (isNaN($wall4width))
			document.getElementById("wall4width").select()
		else if (isNaN($wall4height))
			document.getElementById("wall4height").select()
		else if (isNaN($floorwidth))
			document.getElementById("floorwidth").select()
		else if (isNaN($floorheight))
			document.getElementById("floorheight").select()
		else if (isNaN($wallprice))
			document.getElementById("wallprice").select()
		else if (isNaN($floorprice))
			document.getElementById("floorprice").select()
	}

	document.getElementById("calculatorresults").innerHTML = $pagecontent;
}

function resetCalc()
{
	document.getElementById("wall1width").value=0;
	document.getElementById("wall1height").value=0;
	document.getElementById("floorwidth").value=0;
	document.getElementById("floorheight").value=0;
	document.getElementById("wall2width").value=0;
	document.getElementById("wall2height").value=0;
	document.getElementById("floorprice").value=0;
	document.getElementById("wall3width").value=0;
	document.getElementById("wall3height").value=0;
	document.getElementById("wall4width").value=0;
	document.getElementById("wall4height").value=0;
	document.getElementById("floorsubwidth").value=0;
	document.getElementById("floorsubheight").value=0;
	document.getElementById("wallprice").value=0;
	document.getElementById("wallsubdoorwidth").value=0;
	document.getElementById("wallsubdoorheight").value=0;
	document.getElementById("wallsubwindowwidth").value=0;
	document.getElementById("wallsubwindowheight").value=0;
	document.getElementById("wallsubbathwidth").value=0;
	document.getElementById("wallsubbathheight").value=0;	
}

function showImage(filename, caption)
{
	if (document.getElementById)
	{
		document.getElementById("largeimage").innerHTML = "<img src=\"../images/portfolio/"+filename+"\" /><div id=\"largeimagecaption\"><h2>"+caption+"</h2></div>";
	}
	else
	{
		document.all("largeimage").innerHTML = "<img src=\"../images/portfolio/"+filename+"\" /><div id=\"largeimagecaption\"><h2>"+caption+"</h2></div>";
	}
}

function showGroup(id, filename, caption)
{
	if (document.getElementById)
	{
		for ($i = 1; $i <= 9; $i++)
		{
			if ($i == id.charAt(1))
			{
				for ($j = 1; $j <= 4; $j++)
				{
					document.getElementById("i"+$i+$j).className = "portfolioimg_active";
					document.getElementById("a"+$i+$j).className = "aactive";
				}
			}
			else
			{
				if (document.getElementById("i"+$i+"1").className != "portfolioimg_inactive")
				{
					for ($j = 1; $j <= 4; $j++)
					{
						if ($j == 1)
						{
							document.getElementById("i"+$i+$j).className = "portfolioimg_inactive";	
							document.getElementById("a"+$i+$j).className = "ainactive";
						}
						else
						{
							document.getElementById("i"+$i+$j).className = "portfolioimg_hidden";
							document.getElementById("a"+$i+$j).className = "ahidden";
						}
					}
				}
			}
		}
		document.getElementById("largeimage").innerHTML = "<img src=\"../images/portfolio/"+filename+"\" /><div id=\"largeimagecaption\"><h2>"+caption+"</h2></div>";
	}
	else
	{
		for ($i = 1; $i <= 9; $i++)
		{
			if ($i == id.charAt(1))
			{
				for ($j = 1; $j <= 4; $j++)
				{
					document.all("i"+$i+$j).className = "portfolioimg_active";
					document.all("a"+$i+$j).className = "aactive";
				}
			}
			else
			{
				if (document.all("i"+$i+"1").className != "portfolioimg_inactive")
				{
					for ($j = 1; $j <= 4; $j++)
					{
						if ($j == 1)
						{
							document.all("i"+$i+$j).className = "portfolioimg_inactive";	
							document.all("a"+$i+$j).className = "ainactive";
						}
						else
						{
							document.all("i"+$i+$j).className = "portfolioimg_hidden";
							document.all("a"+$i+$j).className = "ahidden";
						}
					}
				}
			}
		}
		document.all("largeimage").innerHTML = "<img src=\"../images/portfolio/"+filename+"\" /><div id=\"largeimagecaption\"><h2>"+caption+"</h2></div>";
	}
}

window.onload = show;
function show(id) {
var d = document.getElementById(id);
	for (var i = 1; i<=3; i++) {
		if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display='none';}
	}
if (d) {d.style.display='block';}
}

