
//define a "new array" of pop-up windows to show bigger photos of granite brands
//write function "plainWindow" to open new windows
//and create variable "the_element"

var granite=new Array();
granite["Blue_Pearl"]='<img class="thumbnail" src="images/thumbnails/blue_pearl_no.jpg" border=1></a>';
granite["Black_Galaxy"]='<img class="thumbnail" src="images/thumbnails/black_galaxy.jpg" border=1></a>';
granite["Premium_Black"]='<img class="thumbnail" src="images/thumbnails/premium_black.jpg" border=1></a>';
granite["Kashmir_Gold"]='<img class="thumbnail" src="images/thumbnails/kashmir_gold.jpg" border=1></a>';
granite["Uba_Tuba"]='<img class="thumbnail" src="images/thumbnails/uba_tuba.jpg" border=1></a>';
granite["Bianco_Galaxy"]='<img class="thumbnail" src="images/thumbnails/bianco_galaxy.jpg" border=1></a>';
granite["Black_Pearl"]='<img class="thumbnail" src="images/thumbnails/black_pearl.jpg" border=1></a>';
granite["Kashmir_White"]='<img class="thumbnail" src="images/thumbnails/kashmir_white.jpg" border=1></a>';
granite["Multicolour_Red"]='<img class="thumbnail" src="images/thumbnails/multicolour_red.jpg" border=1></a>';
granite["Tan_Brown"]='<img class="thumbnail" src="images/thumbnails/tan_brown.jpg" border=1></a>';
granite["Bros_Blue"]='<img class="thumbnail" src="images/thumbnails/bros_blue.jpg" border=1></a>';
granite["App_Black"]='<img class="thumbnail" src="images/thumbnails/app_black.jpg" border=1></a>';
granite["Baltic_Brown"]='<img class="thumbnail" src="images/thumbnails/baltic_brown.jpg" border=1></a>';
granite["Padang_Dark"]='<img class="thumbnail" src="images/thumbnails/padang_dark.jpg" border=1></a>';
granite["Royal_Brown"]='<img class="thumbnail" src="images/thumbnails/royal_brown.jpg" border=1></a>';
granite["Royal_Red"]='<img class="thumbnail" src="images/thumbnails/royal_red.jpg" border=1></a>';
//granite["Fujian_White"]='<img class="thumbnail" src="images/thumbnails/fujian_white.jpg" border=1></a>';
granite["Verde_Vizag"]='<img class="thumbnail" src="images/thumbnails/verde_vizag.jpg" border=1></a>';
//granite["Emerald_Pearl"]='<img class="thumbnail" src="images/thumbnails/emerald_pearl_no.jpg" border=1></a>';

//////////////////////////////////////////////7
/* we have now 2 forms: "form_2" is to be filled in, "plans" takes its values from "form_2" and calculates worktop cost*/
function sumit(plans){ 
//in forms "form_2" and "plans" we fill in the fields "templating" and "fitting" simultaneously, other fields of "plans" take their values from "form_2" as entered by users
//----------------------Form validation for fields of "form_2"	begins------------------------
//------------------form_2 is the form visible for users and takes user input. 
//--------------1. Validate number of pieces---------------------------------
 if (document.form_2.pieces.value == "")
 {
 document.form_2.pieces.value = 0;
 }
var checkOK = "123";
  var checkStr = document.form_2.pieces.value;
  var allValid = true;
  var allNum = "";
  if (checkStr == "0" || checkStr =="")
  {
		alert("Please enter number of pieces!");
		document.form_2.pieces.focus();
		return (false);
  }
 if (checkStr != "0" || checkStr !="")
  {
  for (i = 0;  i < checkStr.length;  i++)
   {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
		{
		allValid = false;
		break;
		}
    }
   if (!allValid)
   {
    alert("Please enter a positive integer from 1 to 3!");
    document.form_2.pieces.focus();
    return (false);
   }
}

//------------------validate length_1----------
 if (document.form_2.length_1.value == "")
 {
 document.form_2.length_1.value = 0;
 }
var checkOK = "0123456789.,-";
  var checkStr = document.form_2.length_1.value;
  var allValid = true;
  var allNum = "";
  if (document.form_2.length_1.value=="0" || document.form_2.length_1.value=="")
  {
  alert("Please enter length of your worktop!");
  document.form_2.length_1.focus();
  return (false);
  }
  if (document.form_2.length_1.value != "0"){
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
		{
		allValid = false;
		break;
		}
    if (ch =="-")
	{
	alert("Please enter a positive number!");
	document.form_2.length_1.focus();
	return (false);
    }
    if (ch == "." || ch == "," || document.form_2.length_1.value < 100)
	{ alert("Please enter length in millimetres!");
	document.form_2.length_1.focus();
	return (false);
    }
  }
  if (!allValid)
  {
    alert("Please enter only digit characters!");
    document.form_2.length_1.focus();
    return (false);
  }
//---------------validate width_1 -------------------	
 if (document.form_2.width_1.value == "")
 {
 document.form_2.width_1.value = 0;
 }
var checkOK = "0123456789.,-";
  var checkStr = document.form_2.width_1.value;
  var allValid = true;
  var allNum = "";
  if (checkStr=="0" || checkStr=="" || checkStr > 1000)
  {
	window.alert("Please enter a width of 1000 or less!\n\nPlease contact us for width requirements over 1000mm");
	document.form_2.width_1.focus();
    return (false);
  }	
	if (checkStr != "0")
  {
  for (i = 0;  i < checkStr.length;  i++)
   {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
      if (j == checkOK.length)
		{
		allValid = false;
		break;
		}
	  if (ch =="-")
		{ alert("Please enter a positive number!");
		document.form_2.width_1.focus();
		return (false);
		}
	 if (ch == "." || ch == "," || checkStr < 100)
		{ alert("Please enter width greater than 100 in millimetres!");
		document.form_2.width_1.focus();
		return (false);
		}
	 if (checkStr > 700)
		{
		// document.form_2.width_1.value = "1100";
		alert("Width 1 - Widths over 700mm are charged at the rate for 1000mm to cover for the waste.\n\nYou can proceed with your quote but please also contact us for further information on this.");
		allValid = true;
		break;
		}
	 }
  if (!allValid)
	{
    alert("Please enter only digit characters!");
    document.form_2.width_1.focus();
    return (false);
	}
}
//Validate length_2
  if (document.form_2.pieces.value <=1) {
  document.form_2.length_2.value =0
  document.form_2.width_2.value =0
  }

 if (document.form_2.length_2.value == "")
 {
 document.form_2.length_2.value = 0;
 }
if (document.form_2.pieces.value >= "2" &&  document.form_2.length_2.value=="" || document.form_2.pieces.value >="2" && document.form_2.length_2.value =="0")
  {
	alert("Please enter length of Width 2!")
	document.form_2.length_2.focus();
	return (false);
  }

  var checkOK = "0123456789.,-";
  var checkStr = document.form_2.length_2.value;
  var allValid = true;
  var allNum = "";
  if (document.form_2.length_2.value != "0")
  {
     for (i = 0;  i < checkStr.length;  i++)
		{
		ch = checkStr.charAt(i);
		 for (j = 0;  j < checkOK.length;  j++)
		  if (ch == checkOK.charAt(j))
			break;
			if (j == checkOK.length)
			{
			allValid = false;
			break;
			}
			if (ch =="-")
			{
			alert("Please enter a positive number!");
			document.form_2.length_2.focus();
			return (false);
			}
	if (ch == "." || ch == "," || document.form_2.length_2.value < 100)
		{
		alert("Please enter length in millimetres!");
		document.form_2.length_2.focus();
		return (false);
		}
	}
	if (!allValid)
	{alert("Please enter only digit characters!");
    document.form_2.length_2.focus();
    return (false);
	}
}
//Validate width_2
 if (document.form_2.width_2.value == "")
 {
 document.form_2.width_2.value = 0;
 }
if (document.form_2.pieces.value >= "2" &&  document.form_2.width_2.value=="" || document.form_2.pieces.value >="2" && document.form_2.width_2.value =="0")
	{
	alert("Please enter a valid width for the Width 2!")
	document.form_2.width_2.focus();
	return (false);
	}

var checkOK = "0123456789.,-";
  var checkStr = document.form_2.width_2.value;
  var allValid = true;
  var allNum = "";

if (checkStr > 1000)
  {
	window.alert("Please enter a width of 1000 or less!\n\nPlease contact us for width requirements over 1000mm");
	document.form_2.width_2.focus();
    return (false);
  }

  if (document.form_2.width_2.value != "0")
  {
	for (i = 0;  i < checkStr.length;  i++)
	{
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
	if (ch =="-")
	{ alert("Please enter a positive number!");
	document.form_2.width_2.focus();
	return (false);
    }
	if (ch == "." || ch == "," || document.form_2.width_2.value < 100)
	{ alert("Please enter width in millimetres!");
	document.form_2.width_2.focus();
	return (false);
    }
		 if (checkStr > 700)
		{
		// document.form_2.width_2.value = "1100";
		alert("Width 2 - Note - Widths over 700mm are charged at the rate for 1000mm to cover for waste.\n\nYou can proceed with your quote but please also contact us for further information on this.");
		allValid = true;
		break;
		}
  }
  if (!allValid)
  {
    alert("Please enter only digit characters!");
    document.form_2.width_2.focus();
    return (false);
  }
 } 
//----------------validate 3rd piece------------
///////////////////////////////////////////////////////////
  if (document.form_2.pieces.value <=2) {
  document.form_2.length_3.value =0
  document.form_2.width_3.value =0
  }
  
//Validate length_3
 if (document.form_2.length_3.value == "")
 {
 document.form_2.length_3.value = 0;
 }
  if (document.form_2.pieces.value >= "3" &&  document.form_2.length_3.value=="" || document.form_2.pieces.value >="3" && document.form_2.length_3.value =="0")
  {
  alert("Please enter length of 3rd piece!")
	document.form_2.length_3.focus();
	return (false);
  }

var checkOK = "0123456789.,";
  var checkStr = document.form_2.length_3.value;
  var allValid = true;
  var allNum = "";


  if (document.form_2.length_3.value != "0"){
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
if (ch == "." || ch == "," || document.form_2.length_3.value < 100)
	{ alert("Please enter length of 3rd piece in millimetres!");
	document.form_2.length_3.focus();
	return (false);
    }
 }
  if (!allValid)
  {
    alert("Please enter only digit characters!");
    document.form_2.length_3.focus();
    return (false);
  }
 }
//Validate width_3
 if (document.form_2.width_3.value == "")
 {
 document.form_2.width_3.value = 0;
 }
if (document.form_2.pieces.value >= "3" &&  document.form_2.width_3.value=="" || document.form_2.pieces.value >="3" && document.form_2.width_3.value =="0")
    {
	alert("Please enter width of 3rd piece!")
	document.form_2.width_3.focus();
	return (false);
	}
var checkOK = "0123456789.,";
  var checkStr = document.form_2.width_3.value;
  var allValid = true;
  var allNum = "";

if (checkStr > 1000)
  {
	window.alert("Please enter a width of 1000 or less!\n\nPlease contact us for width requirements over 1000mm");
	document.form_2.width_3.focus();
    return (false);
  }

  if (document.form_2.width_3.value != "0")
  {
	for (i = 0;  i < checkStr.length;  i++)
	{
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
	if (ch =="-")
	{ alert("Please enter a positive number!");
	document.form_2.width_3.focus();
	return (false);
    }
	if (ch == "." || ch == "," || document.form_2.width_3.value < 100)
	{ alert("Please enter width in millimetres!");
	document.form_2.width_3.focus();
	return (false);
    }
		 if (checkStr > 700)
		{
		// document.form_2.width_3.value = "1100";
		alert("Width 3 - Widths over 700mm are charged at the rate for 1000mm to cover for waste.\n\nYou can proceed with your quote but please also contact us for further information on this.");
		allValid = true;
		break;
		}
  }
  if (!allValid)
  {
    alert("Please enter only digit characters!");
    document.form_2.width_3.focus();
    return (false);
  }
}

//-------2. Validate length of straight polished edges, straight profile
 if (document.form_2.straight.value == "")
 {
 document.form_2.straight.value = 0;
}
var checkOK = "0123456789.,";
  var checkStr = document.form_2.straight.value;
  var allValid = true;
//  var allNum = "";
 
 if (checkStr < "0")
 {
 alert("Please enter a positive number!");
 document.form_2.straight.focus();
 return (false);
 }
  if (document.form_2.straight.value != "0"){
	for (i = 0;  i < checkStr.length;  i++)
	{
	 ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
			if (ch == checkOK.charAt(j))
			break;
			if (j == checkOK.length)
			{
			allValid = false;
			break;
			}
	if (ch == "." || ch == "," || document.form_2.straight.value < 100)
		{ alert("Please enter length of straight polished edges in millimetres!");
		document.form_2.straight.focus();
		return (false);
		}
	}
  if (!allValid)
  {
    alert("Please enter only digit characters!");
    document.form_2.straight.focus();
    return (false);
  }
}
//validate straight polished edges, halfrounded profile
 if (document.form_2.halfrounded.value == "")
 {
 document.form_2.halfrounded.value = 0;
}

var checkOK = "0123456789.,";
  var checkStr = document.form_2.halfrounded.value;
  var allValid = true;
  var allNum = "";
 if (checkStr < "0")
 {
 alert("Please enter a positive number!");
 document.form_2.halfrounded.focus();
 return (false);
 }
  if (document.form_2.halfrounded.value != "0"){
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
if (ch == "." || ch == "," || document.form_2.halfrounded.value < 100)
	{ alert("Please enter length of halfrounded edges in millimetres!");
	document.form_2.halfrounded.focus();
	return (false);
    }
 }
  if (!allValid)
  {
    alert("Please enter only digit characters!");
    document.form_2.halfrounded.focus();
    return (false);
	}
  }
//validate straight polished edges, rounded profile
 if (document.form_2.rounded.value == "")
 {
 document.form_2.rounded.value = 0;
}
var checkOK = "0123456789.,";
  var checkStr = document.form_2.rounded.value;
  var allValid = true;
  var allNum = "";
 if (checkStr < "0")
 {
 alert("Please enter a positive number!");
 document.form_2.rounded.focus();
 return (false);
 }
  if (document.form_2.rounded.value != "0"){
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
if (ch == "." || ch == "," || document.form_2.rounded.value < 100)
	{ alert("Please enter length of rounded edges in millimetres!");
	document.form_2.rounded.focus();
	return (false);
    }
 }
  if (!allValid)
  {
    alert("Please enter only digit characters!");
    document.form_2.rounded.focus();
    return (false);
	}
  }
//-----------------3. Validate curved polished edges, straight profile
 if (document.form_2.straight_c.value == "")
 {
 document.form_2.straight_c.value = 0;
}

var checkOK = "0123456789.,";
  var checkStr = document.form_2.straight_c.value;
  var allValid = true;
  var allNum = "";
 if (checkStr < "0")
 {
 alert("Please enter a positive number!");
 document.form_2.straight_c.focus();
 return (false);
 }
  if (document.form_2.straight_c.value != "0"){
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
if (ch == "." || ch == "," || document.form_2.straight_c.value < 100)
	{ alert("Please enter length of curved edges in millimetres!");
	document.form_2.straight_c.focus();
	return (false);
    }
 }
  if (!allValid)
  {
    alert("Please enter only digit characters!");
    document.form_2.straight_c.focus();
    return (false);
	}
  }
//validate curved polished edges, halfrounded profile
 if (document.form_2.halfrounded_c.value == "")
 {
 document.form_2.halfrounded_c.value = 0;
}
var checkOK = "0123456789.,";
  var checkStr = document.form_2.halfrounded_c.value;
  var allValid = true;
  var allNum = "";
 if (checkStr < "0")
 {
 alert("Please enter a positive number!");
 document.form_2.halfrounded_c.focus();
 return (false);
 }
  if (document.form_2.halfrounded_c.value != "0"){
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
if (ch == "." || ch == "," || document.form_2.halfrounded_c.value < 100)
	{ alert("Please enter length of curved edges in millimetres!");
	document.form_2.halfrounded_c.focus();
	return (false);
    }
 }
  if (!allValid)
  {
    alert("Please enter only digit characters!");
    document.form_2.halfrounded_c.focus();
    return (false);
	}
  }
//validate curved polished edges, rounded profile
 if (document.form_2.rounded_c.value == "")
 {
 document.form_2.rounded_c.value = 0;
}
var checkOK = "0123456789.,";
  var checkStr = document.form_2.rounded_c.value;
  var allValid = true;
  var allNum = "";
 if (checkStr < "0")
 {
 alert("Please enter a positive number!");
 document.form_2.rounded_c.focus();
 return (false);
 }
  if (document.form_2.rounded_c.value != "0"){
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
if (ch == "." || ch == "," || document.form_2.rounded_c.value < 100)
	{ alert("Please enter length of curved edges in millimetres!");
	document.form_2.rounded_c.focus();
	return (false);
    }
 }
  if (!allValid)
  {
    alert("Please enter only digit characters!");
    document.form_2.rounded_c.focus();
    return (false);
	}
  }
//-----------------4. Validate number of rounded corners R<100mm 
  if (document.form_2.roundcornera.value == "")
 {
 document.form_2.roundcornera.value = 0;
}
 var checkStr = document.form_2.roundcornera.value;
  var prsVal = parseFloat(checkStr);
  var checkOK = "0123456789.,";
  var allValid = true;
  var allNum = "";
 if (checkStr < "0")
 {
 alert("Please enter a positive number!");
 document.form_2.roundcornera.focus();
 return (false);
 }

 if (isNaN(prsVal)) 
  {
    alert("Please enter a numeric value in the \"rounded corners R<100\" field!");
    document.form_2.roundcornera.focus();
    return (false);
  }	
  if (checkStr != "0"){
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
if (ch == "." || ch == ",")
	{ alert("Please enter an integer number in the \"rounded corners R<100\" field!");
	document.form_2.roundcornera.focus();
	return (false);
    }
 }
  }
//-------------------5. Validate number of rounded corners 100<R<300mm 
  if (document.form_2.roundcornerb.value == "")
 {
 document.form_2.roundcornerb.value = 0;
}
 var checkStr = document.form_2.roundcornerb.value;
  var prsVal = parseFloat(checkStr);
  var checkOK = "0123456789.,";
  var allValid = true;
  var allNum = "";
 if (checkStr < "0")
 {
 alert("Please enter a positive number!");
 document.form_2.roundcornerb.focus();
 return (false);
 }
 if (isNaN(prsVal)) 
  {
    alert("Please enter a numeric value in the \"rounded corners 100<R<300\" field.");
    document.form_2.roundcornerb.focus();
    return (false);
  }	
  if (checkStr != "0"){
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
if (ch == "." || ch == ",")
	{ alert("Please enter an integer number in the \"rounded corners 100<R<300\" field!");
	document.form_2.roundcornerb.focus();
	return (false);
    }
}
}
//-----------------------------6.Validate upstands 
//Validate splashwidth
  if (document.form_2.splashwidth.value == "")
 {
 document.form_2.splashwidth.value = 0;
}
if (document.form_2.splashlength.value !=0 && document.form_2.splashwidth.value == 0)
{
alert("Please enter the upstand height!");
document.form_2.splashwidth.focus();
return (false);
}
 
 var checkStr = document.form_2.splashwidth.value;
  var prsVal = parseFloat(checkStr);
 if (checkStr < "0")
 {
 alert("Please enter a positive number!");
 document.form_2.splashwidth.focus();
 return (false);
 }
 if (isNaN(prsVal)) 
  {
    alert("Please enter a numeric value in the \"upstand height\" field.");
    document.form_2.splashwidth.focus();
    return (false);
  }	
  if (checkStr != "0"){
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
if (ch == "." || ch == "," || document.form_2.splashwidth.value < 2)
	{ alert("Please enter upstand height in millimetres!");
	document.form_2.splashwidth.focus();
	return (false);
    }
}
}
//Validate splashlength
  if (document.form_2.splashlength.value == "")
 {
 document.form_2.splashlength.value = 0;
}
if (document.form_2.splashwidth.value !=0 && document.form_2.splashlength.value == 0)
{
alert("Please enter the upstand length!");
document.form_2.splashlength.focus();
return (false);
}

 var checkStr = document.form_2.splashlength.value;
  var prsVal = parseFloat(checkStr);
 if (checkStr < "0")
 {
 alert("Please enter a positive number!");
 document.form_2.splashlength.focus();
 return (false);
 }
 if (isNaN(prsVal)) 
  {
    alert("Please enter a numeric value in the \"upstand length\" field.");
    document.form_2.splashlength.focus();
    return (false);
  }	
  if (checkStr != "0"){
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
if (ch == "." || ch == "," || document.form_2.splashlength.value < 100)
	{ alert("Please enter upstand length in millimetres!");
	document.form_2.splashlength.focus();
	return (false);
    }
}
}
//---------------------7. Validate number of draining grooves 
   if (document.form_2.draininggroove.value == "")
 {
 document.form_2.draininggroove.value = 0;
}
var checkStr = document.form_2.draininggroove.value;
  var prsVal = parseFloat(checkStr);
 if (checkStr < "0")
 {
 alert("Please enter a positive number!");
 document.form_2.draininggroove.focus();
 return (false);
 }
 if (isNaN(prsVal)) 
  {
    alert("Please enter a numeric value in the \"draining grooves\" field.");
    document.form_2.draininggroove.focus();
    return (false);
  }	
//------------------8. Validate number of cutouts for sink 

// 8a. top-mounted (standard) 
  if (document.form_2.Polished_Cut_Out.value == "")
 {
 document.form_2.Polished_Cut_Out.value = 0;
}
 var checkStr = document.form_2.Polished_Cut_Out.value;
  var prsVal = parseFloat(checkStr);
 if (checkStr < "0")
 {
 alert("Please enter a positive number!");
 document.form_2.Polished_Cut_Out.focus();
 return (false);
 }
 if (isNaN(prsVal)) 
  {
    alert("Please enter a numeric value in the \"top-mounted\" field.");
    document.form_2.Polished_Cut_Out.focus();
    return (false);
  }	

//8b. flush-fit
 if (document.form_2.UN_Polished_Cut_Outs_For_Sink.value == "")
 {
 document.form_2.UN_Polished_Cut_Outs_For_Sink.value = 0;
}
  var checkStr = document.form_2.UN_Polished_Cut_Outs_For_Sink.value;
  var prsVal = parseFloat(checkStr);
 if (checkStr < "0")
 {
 alert("Please enter a positive number!");
 document.form_2.UN_Polished_Cut_Outs_For_Sink.focus();
 return (false);
 }
 if (isNaN(prsVal)) 
  {
    alert("Please enter a numeric value in the \"flush-fit\" field.");
    document.form_2.UN_Polished_Cut_Outs_For_Sink.focus();
    return (false);
  }	
//-------------------------9. Validate number of cutouts for Sunken_Drainers
  if (document.form_2.Sunken_Drainers.value == "")
 {
 document.form_2.Sunken_Drainers.value = 0;
}
 var checkStr = document.form_2.Sunken_Drainers.value;
  var prsVal = parseFloat(checkStr);
 if (checkStr < "0")
 {
 alert("Please enter a positive number!");
 document.form_2.Sunken_Drainers.focus();
 return (false);
 }
 if (isNaN(prsVal)) 
  {
    alert("Please enter a numeric value in the \"cutouts for Sunken_Drainers\" field.");
    document.form_2.Sunken_Drainers.focus();
    return (false);
  }	
//-----------------10. Validate number of tapholes 
if (document.form_2.taphole.value == "")
	{
	document.form_2.taphole.value = 0;
	}
var checkStr = document.form_2.taphole.value;
  var prsVal = parseFloat(checkStr);
  var checkOK = "0123456789.,";
 if (checkStr < "0")
	{
	alert("Please enter a positive number!");
	document.form_2.taphole.focus();
	return (false);
	}
 if (isNaN(prsVal)) 
  {
    alert("Please enter a numeric value in the \"tap and switch holes\" field.");
    document.form_2.taphole.focus();
    return (false);
  }	
//Validation of form_2 ends

L_1=document.form_2.length_1.value;
L_2=document.form_2.length_2.value;
L_3=document.form_2.length_3.value;

te=15;
tempsum=(L_1*te+L_2*te+L_3*te)/1000;
//	if (tempsum < 60){
//	document.form_2.templating.value = 110;
	document.plans.templating.value = 100;
//	}
//	else if (tempsum >=60){
//	document.form_2.templating.value = parseInt(tempsum+50);
//	document.plans.templating.value=parseInt(tempsum+50);
//	}
fi=40;
fitsum=tempsum/15*40;

//if (fitsum < 140){
document.form_2.fitting.value = "POA";
plans.fitting.value = "POA";
//}
//else if (fitsum >= 140){
//document.form_2.fitting.value = parseInt(fitsum);
//plans.fitting.value = parseInt(fitsum);
//}

document.plans.brand.value=document.form_1.brand[document.form_1.brand.selectedIndex].value
document.plans.pieces.value=document.form_2.pieces.value
document.plans.length_1.value=document.form_2.length_1.value
document.plans.width_1.value=document.form_2.width_1.value
document.plans.length_2.value=document.form_2.length_2.value
document.plans.width_2.value=document.form_2.width_2.value
document.plans.length_3.value=document.form_2.length_3.value
document.plans.width_3.value=document.form_2.width_3.value
//document.plans.straight.value=document.form_2.straight.value
//document.plans.halfrounded.value=document.form_2.halfrounded.value
//document.plans.rounded.value=document.form_2.rounded.value
//document.plans.straight_c.value=document.form_2.straight_c.value
//document.plans.halfrounded_c.value=document.form_2.halfrounded_c.value
//document.plans.rounded_c.value=document.form_2.rounded_c.value
document.plans.roundcornera.value=document.form_2.roundcornera.value
document.plans.roundcornerb.value=document.form_2.roundcornerb.value
document.plans.Polished_Cut_Out.value=document.form_2.Polished_Cut_Out.value
document.plans.UN_Polished_Cut_Outs_For_Sink.value=document.form_2.UN_Polished_Cut_Outs_For_Sink.value
document.plans.Sunken_Drainers.value=document.form_2.Sunken_Drainers.value
document.plans.taphole.value=document.form_2.taphole.value
document.plans.draininggroove.value=document.form_2.draininggroove.value
document.plans.splashwidth.value=document.form_2.splashwidth.value
document.plans.splashlength.value=document.form_2.splashlength.value

// App_Black
	gpa=205

// Baltic_Brown
	gpb=205

// Bianco_Galaxy
	gpc=225

// Kashmir_Gold
	gpd=260
	
// Verde_Vizag
	gpe=200

// Padang_Dark
	gpf=200

// Royal_Red
	gpg=200

// Fujian_White
	gph=200

// Black_Pearl
	gpi=225

// Leopard_Skin
	gpj=200

// Maple_Red
	gpk=200

// Swedish_Tan
	gpl=200

// Rusty_Tan
	gpn=180

// TJI_Red
	gpo=200

// Royal_Brown
	gpp=200

// English_Teak
	gpq=200

// Mega_Indian_Dakota
	gpr=200

// Multicolour_Red
	gps=225
	
// Sea_Waves
	gpt=200

// Tan_Brown
	gpu=225
	
// Emerald_Pearl
	gpv=270

// Blue_Pearl
	gpw=270
	
// Uba_Tuba
	gpx=240

// Kashmir_Gold
	gpy=260

// Premium_Black
	gpz=260

// Bros_Blue
	gpaa=210

// Black_Galaxy
	gpbb=270

if (plans.brand.value=="App_Black"){
			gpm=gpa;
	} else {
		if (plans.brand.value=="Baltic_Brown"){
			gpm=gpb;
	} else {
		if (plans.brand.value=="Bianco_Galaxy"){
			gpm=gpc;
	} else {
		if (plans.brand.value=="Kashmir_Gold"){
			gpm=gpd;
	} else {
		if (plans.brand.value=="Verde_Vizag"){
			gpm=gpe;		
	} else {
		if (plans.brand.value=="Padang_Dark"){
			gpm=gpf;
	} else {
		if (plans.brand.value=="Royal_Red"){
			gpm=gpg;			
	} else {
		if (plans.brand.value=="Fujian_White"){
			gpm=gph;
	} else {
		if (plans.brand.value=="Black_Pearl"){
			gpm=gpi;			
	} else {
		if (plans.brand.value=="Leopard_Skin"){
			gpm=gpj;
	} else {
		if (plans.brand.value=="Maple_Red"){
			gpm=gpk;
	} else {
		if (plans.brand.value=="Swedish_Tan"){
			gpm=gpl;
	} else {
		if (plans.brand.value=="Rusty_Tan"){
			gpm=gpn;
	} else {
		if (plans.brand.value=="TJI_Red"){
			gpm=gpo;
	} else {
		if (plans.brand.value=="Royal_Brown"){
			gpm=gpp;
	} else {
		if (plans.brand.value=="English_Teak"){
			gpm=gpq;
	} else {
		if (plans.brand.value=="Mega_Indian_Dakota"){
			gpm=gpr;
	} else {
		if (plans.brand.value=="Multicolour_Red"){
			gpm=gps;
	} else {
		if (plans.brand.value=="Sea_Waves"){
			gpm=gpt;
	} else {
		if (plans.brand.value=="Tan_Brown"){
			gpm=gpu;
	} else {
		if (plans.brand.value=="Emerald_Pearl"){
			gpm=gpv;
	} else {
		if (plans.brand.value=="Blue_Pearl"){
			gpm=gpw;
	} else {
		if (plans.brand.value=="Uba_Tuba"){
			gpm=gpx;
	} else {
		if (plans.brand.value=="Kashmir_Gold"){
			gpm=gpy;
	} else {
		if (plans.brand.value=="Premium_Black"){
			gpm=gpz;
	} else {
		if (plans.brand.value=="Bros_Blue"){
			gpm=gpaa;
	} else {
			gpm=gpbb;
		
		}}}}}}}}}}}}}}}}}}}}}}}}}
	}

//set new variables for length and width of each piece (up to 7 pieces) and calculate "gm = total square metres of granite"
//lengths of 3 pieces in millimetres
 gml_1=document.plans.length_1.value;
 gml_2=document.plans.length_2.value;
 gml_3=document.plans.length_3.value;
//widths of 3 pieces in millimetres

if (document.plans.width_1.value < 601)
	{
	gmw_1= 600
	}

else if (document.plans.width_1.value < 631)
	{
	gmw_1=630
	}

else if (document.plans.width_1.value < 701)
	{
	gmw_1=700
	}

else if (document.plans.width_1.value < 1001)
	{
	gmw_1=1100
	}

if (document.plans.width_2.value < 601)
	{
	gmw_2= 600
	}

else if (document.plans.width_2.value < 631)
	{
	gmw_2=630
	}

else if (document.plans.width_2.value < 701)
	{
	gmw_2=700
	}

else if (document.plans.width_2.value < 1001)
	{
	gmw_2=1100
	}

if (document.plans.width_3.value < 601)
	{
	gmw_3= 600
	}

else if (document.plans.width_3.value < 631)
	{
	gmw_3=630
	}

else if (document.plans.width_3.value < 701)
	{
	gmw_3=700
	}

else if (document.plans.width_3.value < 1001)
	{
	gmw_3=1100
	}

//calculate surface area of all pieces in square millimetres
 gm_1=gml_1*gmw_1;
 gm_2=gml_2*gmw_2;
 gm_3=gml_3*gmw_3;
//calculate total surface area of worktops in sq millimetres and convert to sq metres
 gmm_total=gm_1+gm_2+gm_3;
 gm_total=gmm_total/1000000;

//calculate surface area of splashbacks in sq metres
gmsw=document.plans.splashwidth.value;
gmsl=document.plans.splashlength.value;
gms=gmsw*gmsl/1000000;

//cost of straight polished edges
	pmstr=10/1000; 	
	pmhr=20/1000;
	pmfr=26/1000;
//cost of curved polished edges
	cmstr=26/1000;
	cmhr=38/1000;
	cmfr=43/1000;
//cost of slightly rounded corners R=5mm 
	rca=10;
//cost or rounded corners R<100mm
	rcb=40;
//cost of splashbacks: (cost of granite)+(cost of polished edge)+(cost of fitting)
	//sb=gpm*gms/1.33+gmsl/1000*(10+10);
//cost of splashbacks: (cost of granite)+(cost of polished edge)+(cost of fitting)
	sb=(1+(1.2*gpm/1.33))*gms;
//cost of draining grooves (1 set of 5 grooves)
	dg=125;
//cost of cutouts for sink
	sco=125;
	ff=80;
	uco=105;
	uuco=120;
//number of cutouts for Sunken_Drainers
	Sunken_Drainers=300;
//cost of tap and switch holes
	th=15;
//cost of templating is hardcoded in form_2 as "templating.value=110" 
	
//cost of transport and fitting is hardcoded in form_2 as "fitting.value=140"

//calculate total working cost plus cost of splashbacks 
//workcost = (pmstr * plans.straight.value) + (pmhr * plans.halfrounded.value)+(pmfr * plans.rounded.value) + 
//(cmstr * plans.straight_c.value) + (cmhr * plans.halfrounded_c.value) + (cmfr * plans.rounded_c.value) + (rca * plans.roundcornera.value) + (rcb * plans.roundcornerb.value) + (sb) + (dg * plans.draininggroove.value) + (sco * plans.Polished_Cut_Out.value) + (ff * plans.UN_Polished_Cut_Outs_For_Sink.value) + (Sunken_Drainers * plans.Sunken_Drainers.value) + (th * plans.taphole.value) + (1 * plans.templating.value) +  (1 * plans.fitting.value);
//plans.estimate.value = parseInt(gm_total*gpm+workcost);
//plans.check.value = parseInt(gm_total*gpm+workcost);
workcost = (rca * plans.roundcornera.value) + (rcb * plans.roundcornerb.value) + (sb) + 
(dg * plans.draininggroove.value) + (sco * plans.Polished_Cut_Out.value) + (ff * plans.UN_Polished_Cut_Outs_For_Sink.value) + (Sunken_Drainers * plans.Sunken_Drainers.value) + (th * plans.taphole.value)
//+ (1 * plans.templating.value) +  (1 * plans.fitting.value);
plans.estimate.value = parseInt(gm_total*gpm+workcost);
plans.check.value = parseInt(gm_total*gpm+workcost);} 
}
//-->
