function GetParameter(parameterName, parameterList)
{
   var parameterValue ="";
   index = parameterList.indexOf(parameterName);
   
   if (-1 != index)
   {
      index = parameterList.indexOf("=", index);
      if (-1 != index)
      {
         var index2 = parameterList.indexOf("&", index);

         if (-1 == index2)
         {
            parameterValue=parameterList.substr(index+1, parameterList.length-index);
         }
         else
         { 
            parameterValue = parameterList.substr(index+1, index2-index-1); 
         }
      }   
   }
   return parameterValue;
}

function GetRadioButtonValue(radiobutton)
{
   var txtValue = "";
   for (var i=0; i<radiobutton.length; ++i)
   {
      if(radiobutton[i].checked)
      {
         txtValue = radiobutton[i].value;      
      }
   }
   return txtValue;
}
function ValidateEmail()
{
	var email = document.AuthenticationForm.EmailAddress.value;
	
	if ((email.toLowerCase() == "cakers@stoeppelwerth.com") ||		//Test email
	(email.toLowerCase() == "andrewkalynda@sbcglobal.net") )      //Test email
	{
//	   document.AuthenticationForm.txtBuilder.value = "Stoeppelwerth and Associates test account";
      document.AuthenticationForm.txtBuilder.value = "Beazer Homes";
	}
	else if (
	(email.toLowerCase() == "brendab@arborhomesllc.com") ||        // Arbor Homes
	(email.toLowerCase() == "ashleyh@arborhomesllc.com") ||        // Arbor Homes
	(email.toLowerCase() == "laceyc@arborhomesllc.com") ||         // Arbor Homes
	(email.toLowerCase() == "mindym@arborhomesllc.com"))           // Arbor Homes
	{
	   document.AuthenticationForm.txtBuilder.value = "Arbor Homes";
   }	
   else if (
   (email.toLowerCase() == "tmerritt@beazer.com") ||
   (email.toLowerCase() == "blyons@beazer.com") ||
   (email.toLowerCase() == "indystarts@beazer.com"))
   {
      document.AuthenticationForm.txtBuilder.value = "Beazer Homes";
   }
   else
   {
      document.AuthenticationForm.txtBuilder.value = "";
   }
}

function AuthenticateOrder1 () 
{	
	if ((! document.AuthenticationForm.EmailAddress.value))
	{
		alert("Please enter a valid Email Address");
		return false;
	}

	var email = document.AuthenticationForm.EmailAddress.value;
	
	if ((email.toLowerCase() == "cakers@stoeppelwerth.com") ||		//Test email
	(email.toLowerCase() == "andrewkalynda@sbcglobal.net"))         //Test email
	{
	   //document.AuthenticationForm.txtBuilder.value = "Stoeppelwerth and Associates test account";
	   document.AuthenticationForm.txtBuilder.value = "Beazer Homes";
	}
	else if((email.toLowerCase() == "brendab@arborhomesllc.com") ||        // Arbor Homes
	(email.toLowerCase() == "ashleyh@arborhomesllc.com") ||        // Arbor Homes
	(email.toLowerCase() == "laceyc@arborhomesllc.com") ||         // Arbor Homes
	(email.toLowerCase() == "mindym@arborhomesllc.com"))         // Arbor Homes
	{
	   document.AuthenticationForm.txtBuilder.value = "Arbor Homes";
	}
	else if ((email.toLowerCase() == "tmerritt@beazer.com") ||
	         (email.toLowerCase() == "blyons@beazer.com")
		 (email.toLowerCase() == "indystarts@beazer.com"))
	{
	   document.AuthenticationForm.txtBuilder.value = "Beazer Homes";
	}
	else
	{
		alert("The email address entered is not valid");
		return false;
	}
	
}

function AuthenticateOrder2 () 
{
   //first get the passed in values
   var strURL = document.URL;
   var strEmailAddress = GetParameter("EmailAddress", strURL);  
   var strBuilder = GetParameter("txtBuilder", strURL);  
   document.OrderCommonForm.EmailAddress.value = strEmailAddress;
   document.OrderCommonForm.txtBuilder.value = strBuilder;
   
   var ddSubdivision = document.getElementById("cbSubdivision");
	var optionsSubdivision = ddSubdivision.options[ddSubdivision.selectedIndex];
	var Subdivision = optionsSubdivision.text;

	if (Subdivision == "Please Choose a Subdivision...")
	{
		alert("Please Select a subdivision");
		return false;
	}

	if (Subdivision == "Other - Please Specify:" && !document.OrderCommonForm.txtSubdivisionOther.value )
	{
		alert("If you select \"Other - Please Specify\", you must have a value in the text box");
		return false;
	}

   if (!document.OrderCommonForm.txtLot.value)
   {
      alert("Please enter a lot number");
      return false;
   }

	if (!document.OrderCommonForm.cbFit.checked
		&& !document.OrderCommonForm.cbPlotPlan.checked
		&& !document.OrderCommonForm.cbRevision.checked
		&& !document.OrderCommonForm.cbStaking.checked
		&& !document.OrderCommonForm.cbRestake.checked
		&& !document.OrderCommonForm.cbPinning.checked
		&& !document.OrderCommonForm.cbOther.checked
		)
	{
		alert ("You must select one or more values under \"Work Requested:\"");
		return false;
	}
	
	if (document.OrderCommonForm.cbOther.checked && !document.OrderCommonForm.txtOther.value)
	{
		alert("If the type of work selected is \"Other\", you must enter something in the text box");
		return false;
	}
}

function AuthenticateOrder3()
{
   //Get all of the values from the first two pages
   var strURL = document.URL;
   document.OrderArborForm.EmailAddress.value = GetParameter("EmailAddress", strURL);  
   document.OrderArborForm.txtBuilder.value = GetParameter("txtBuilder", strURL);  
   document.OrderArborForm.cbSubdivision.value = GetParameter("cbSubdivision", strURL);  
   document.OrderArborForm.txtSubdivisionOther.value = GetParameter("txtSubdivisionOther", strURL);  
   document.OrderArborForm.txtSection.value = GetParameter("txtSection", strURL);  
   document.OrderArborForm.txtLot.value = GetParameter("txtLot", strURL);  
   document.OrderArborForm.cbFit.value = GetParameter("cbFit", strURL);  
   document.OrderArborForm.cbPlotPlan.value = GetParameter("cbPlotPlan", strURL);  
   document.OrderArborForm.cbRevision.value = GetParameter("cbRevision", strURL);  
   document.OrderArborForm.cbStaking.value = GetParameter("cbStaking", strURL);  
   document.OrderArborForm.cbRestake.value = GetParameter("cbRestake", strURL);  
   document.OrderArborForm.cbPinning.value = GetParameter("cbPinning", strURL);  
   document.OrderArborForm.cbOther.value = GetParameter("cbOther", strURL);  
   document.OrderArborForm.txtOther.value = GetParameter("txtOther", strURL);  

   //Validate new criteria.
   if (!document.OrderArborForm.txtModel.value)
   {
      alert("Please enter a valid Model");
      return false;
   }
      
   if (!GetRadioButtonValue(document.OrderArborForm.rbElevation))
   {
      alert("Please Select an Elevation.");
      return false;
   }

   if ( document.OrderArborForm.cbFit.value || document.OrderArborForm.cbPlotPlan.value )
   {
      if (!GetRadioButtonValue(document.OrderArborForm.rbFoundation))
      {
         alert("Please Select an Foundation Type.");
         return false;
      }

      if (!GetRadioButtonValue(document.OrderArborForm.rbGarage))
      {
         alert("Please Select the Garage Size");
         return false;
      }
      
      if (!GetRadioButtonValue(document.OrderArborForm.rbGarageHand))
      {
         alert("Please Select the Garage Direction (RH/LH).");
         return false;
      }

      if (!GetRadioButtonValue(document.OrderArborForm.rbGarageLoad))
      {
         alert("Please Select the Garage Type (Front, Side, Etc).");
         return false;
      }
   }

   if (document.OrderArborForm.cbPatio.checked && (!document.OrderArborForm.txtPatioWidth.value || !document.OrderArborForm.txtPatioDepth.value))
   {
      alert("If you are selecting a patio, you must enter a width and a depth.");
      return false;
   }
   
   if (document.OrderArborForm.cbDeck.checked && (!document.OrderArborForm.txtDeckWidth.value || !document.OrderArborForm.txtDeckDepth.value))
   {
      alert("If you are selecting a deck, you must enter a width and a depth.");
      return false;
   }
   
   if (document.OrderArborForm.cbExtOptionsOther.checked && !document.OrderArborForm.txtExtOptionsOther.value)
   {
      alert("If you are selecting Exterior Options - Other, you must list the options desired.");
      return false;
   }

   if (document.OrderArborForm.cbHouseAdditionsOther.checked && !document.OrderArborForm.txtHouseAdditionsOther.value)
   {
      alert("If you are selecting House Additions - Other, you must list the options desired.");
      return false;
   }

   if ("Other" == GetRadioButtonValue(document.OrderArborForm.rbBrick) && !document.OrderArborForm.txtBrickOther.value)
   {
      alert("If you are selecting Brick Locations - Other, you must list the options desired.");
      return false;
   }
   
   
   return true;   
}

function getPageValues()
{
   var strURL = document.URL;
   document.orderform.EmailAddress.value = GetParameter("EmailAddress", strURL);  
   document.orderform.txtBuilder.value = GetParameter("txtBuilder", strURL);  
   
   return true;
}

function SubmitReloadPage2()
{
   document.forms[0].action.value = "Page 2 Partial";
   document.forms[0].submit();
}

function AuthenticateBeazer3()
{
   //Get all of the values from the first two pages
   var strURL = document.URL;
   document.OrderArborForm.EmailAddress.value = GetParameter("EmailAddress", strURL);  
   document.OrderArborForm.txtBuilder.value = GetParameter("txtBuilder", strURL);  
   document.OrderArborForm.cbSubdivision.value = GetParameter("cbSubdivision", strURL);  
   document.OrderArborForm.txtSubdivisionOther.value = GetParameter("txtSubdivisionOther", strURL);  
   document.OrderArborForm.txtSection.value = GetParameter("txtSection", strURL);  
   document.OrderArborForm.txtLot.value = GetParameter("txtLot", strURL);  
   document.OrderArborForm.cbFit.value = GetParameter("cbFit", strURL);  
   document.OrderArborForm.cbPlotPlan.value = GetParameter("cbPlotPlan", strURL);  
   document.OrderArborForm.cbRevision.value = GetParameter("cbRevision", strURL);  
   document.OrderArborForm.cbStaking.value = GetParameter("cbStaking", strURL);  
   document.OrderArborForm.cbRestake.value = GetParameter("cbRestake", strURL);  
   document.OrderArborForm.cbPinning.value = GetParameter("cbPinning", strURL);  
   document.OrderArborForm.cbOther.value = GetParameter("cbOther", strURL);  
   document.OrderArborForm.txtOther.value = GetParameter("txtOther", strURL);  

   //Validate new criteria.
   if (!document.OrderArborForm.txtModel.value)
   {
      alert("Please enter a valid Model");
      return false;
   }

   if (!document.OrderArborForm.txtElevation.value)
   {
      alert("Please Select an Elevation.");
      return false;
   }

   if ( document.OrderArborForm.cbFit.value || document.OrderArborForm.cbPlotPlan.value )
   {
      if (!GetRadioButtonValue(document.OrderArborForm.rbFoundation))
      {
         alert("Please Select an Foundation Type.");
         return false;
      }

      if (!GetRadioButtonValue(document.OrderArborForm.rbGarage))
      {
         alert("Please Select the Garage Size");
         return false;
      }
      
      if (!GetRadioButtonValue(document.OrderArborForm.rbGarageHand))
      {
         alert("Please Select the Garage Direction (RH/LH).");
         return false;
      }

      if (!GetRadioButtonValue(document.OrderArborForm.rbSod))
      {
         alert("Please select Sod line.");
         return false;
      }

   }

   if (document.OrderArborForm.cbPatio.checked && (!document.OrderArborForm.txtPatioWidth.value || !document.OrderArborForm.txtPatioDepth.value))
   {
      alert("If you are selecting a patio, you must enter a width and a depth.");
      return false;
   }
   
   if (document.OrderArborForm.cbDeck.checked && (!document.OrderArborForm.txtDeckWidth.value || !document.OrderArborForm.txtDeckDepth.value))
   {
      alert("If you are selecting a deck, you must enter a width and a depth.");
      return false;
   }
   
   if (document.OrderArborForm.cbBayWindow.checked && !document.OrderArborForm.txtBayLocation.value)
   {
      alert("If you are selecting a bay window, you must select the location for it.");
      return false;
   }

   if (document.OrderArborForm.cbExtOptionsOther.checked && !document.OrderArborForm.txtExtOptionsOther.value)
   {
      alert("If you are selecting Exterior Options - Other, you must list the options desired.");
      return false;
   }

   if ("Other" == GetRadioButtonValue(document.OrderArborForm.rbBrick) && !document.OrderArborForm.txtBrickOther.value)
   {
      alert("If you are selecting Brick Locations - Other, you must list the options desired.");
      return false;
   }
   
   
   return true;   
}