/***  
*	Configurator Utils
*	AUTHOR: Dominik Bauset
*	LAST MODIFIED: 26/01/2005
*
*	CONTENT:function update(iCurrTab)
*			function dispCustomULen()
*			function ULen_warning()
*			function validULen()
*			function checkULen()
*			function dispCustomSABL()
*			function SABL_warning()
*			function validSABL()
*			function checkSABL()
*			function dispCustomPLen()
*			function PLen_warning()
*			function validPLen()
*			function checkPLen()
*			function dispCables()
*
*	This code may NOT be reproduced without due credit to Kayden Inc.
***/

//function used to switch tabs
function update(iCurrTab)
{

	//assume validity for all tabs
	var validForm = true
	//check on specification tab
	if(document.configForm.tab.value == "spc")
	{
		//validate form for proper length ONLY if they exist
		if(document.configForm.ULen)
		{
		
			validForm = validULen();
			
		}
		else if(document.configForm.SABL)
		{
			validForm = validSABL();
		}
		else if(document.configForm.PLen)
		{
			validForm = validPLen();
		}
	}
	//only submit valid configurations
	if(validForm)
	{
		document.configForm.tab.value = iCurrTab;
		document.configForm.submit();
	}
};


//function displays the insertion 'u' length custom box
function dispCustomULen()
{
	var o = cssObj('customLenBox');
	
	if(document.configForm.ULen[0].checked && (document.configForm.ULen[0].value == "0000")) // ULen[0] = custom if value "0000"
	{
		
		o.setStyle('display', 'block');
		// written by sricharan
		if(document.configForm.PCmn.checked!=false && document.configForm.PCmn.checked!=undefined)
		{
		
		if(document.configForm.PCmn[0].checked || document.configForm.PCmn[1].checked)
		{
		
		if(document.configForm.txtqueries.value=="410" || document.configForm.txtqueries.value=="810")
		{
			document.getElementById("customWarning").innerHTML = 'Available in 1/2" increments<br />Minimum length = 2.5"; Maximum length = 24"';	
		}
		}
		}
		else
		{
		document.getElementById("customWarning").innerHTML = 'Available in 1/2" increments<br />Minimum length = 2.5"; Maximum length = 120"';	
		}
	}
	else
	{
		o.setStyle('display', 'none');
	}
};

//function displays custom u length warning based on type
function ULen_warning()
{

	if(document.configForm.CType[0].checked) // CType[0] = inches
	{
		try
		{
			if(document.configForm.PCmn[0].checked || document.configForm.PCmn[1].checked )
			{
				if(document.configForm.txtqueries.value=="810" || document.configForm.txtqueries.value=="410")
				{
						document.getElementById("customWarning").innerHTML = 'Available in 1/2" increments<br />Minimum length = 2.5"; Maximum length = 24"';
				}
				else
			{
				document.getElementById("customWarning").innerHTML = 'Available in 1/2" increments<br />Minimum length = 2.5"; Maximum length = 120"';
			}
			}
			else
			{
				document.getElementById("customWarning").innerHTML = 'Available in 1/2" increments<br />Minimum length = 2.5"; Maximum length = 120"';
			}
		}
		catch(err)
		{
			document.getElementById("customWarning").innerHTML = 'Available in 1/2" increments<br />Minimum length = 2.5"; Maximum length = 120"';
		}
		
	}
	else
	{
		try
		{
		
			if(document.configForm.PCmn[0].checked || document.configForm.PCmn[1].checked)
			{
				if(document.configForm.txtqueries.value=="810" || document.configForm.txtqueries.value=="410")
				{
					document.getElementById("customWarning").innerHTML = 'Available in 1cm increments<br />Minimum length = 6cm; Maximum length = 60.96cm';
				}
				else 
			{
				document.getElementById("customWarning").innerHTML = 'Available in 1cm increments<br />Minimum length = 6cm; Maximum length = 305cm';
			
			}
			}
			else 
			{
				document.getElementById("customWarning").innerHTML = 'Available in 1cm increments<br />Minimum length = 6cm; Maximum length = 305cm';
			
			}
		
		}
		catch(err)
		{
		
			document.getElementById("customWarning").innerHTML = 'Available in 1cm increments<br />Minimum length = 6cm; Maximum length = 305cm';
		}
	}
	
	
};



function ULen_warning_mnpt()
{

	if(document.configForm.CType[0].checked) // CType[0] = inches
	{
		
		document.getElementById("customWarning").innerHTML = 'Available in 1/2" increments<br />Minimum length = 2.5"; Maximum length = 24"';
	}
	else
	{
	
		document.getElementById("customWarning").innerHTML = 'Available in 1cm increments<br />Minimum length = 6cm; Maximum length = 60.96cm';
	}
	
};
function ULen_warning1()
{
	if(document.configForm.CType[0].checked) // CType[0] = inches
	{
		
		document.getElementById("customWarning").innerHTML = 'Available in 1/2" increments<br />Minimum length = 2.5"; Maximum length = 6"';
	}
	else
	{
	
		document.getElementById("customWarning").innerHTML = 'Available in 1cm increments<br />Minimum length = 6cm; Maximum length = 305cm';
	}
	
};

function ULen_warning2()
{
	if(document.configForm.CType[0].checked) // CType[0] = inches
	{
		
		document.getElementById("customWarning").innerHTML = 'Available in 1/2" increments<br />Minimum length = 2.5"; Maximum length = 120"';
	}
	else
	{
	
		document.getElementById("customWarning").innerHTML = 'Available in 1cm increments<br />Minimum length = 6cm; Maximum length = 305cm';
	}
	
};


//function to validate config form
function validULen()
{
	//check to if u length has multiple choices
	if(document.configForm.ULen[0])
	{
		if(document.configForm.ULen[0].checked)
		{
			if(checkULen())
			{
				document.configForm.CNum.focus();
				return false;
			}
		}
	}
	else //check if single choice is custom
	{
		if(document.configForm.ULen.value == "0000")
		{
			if(checkULen())
			{
				document.configForm.CNum.focus();
				return false;
			}
		}
	}
	return true;
}


//function validates the U Length number based on type 
function checkULen()
{
try
{

var Num ="";
	if(document.configForm.CNum != null && document.configForm.CNum != undefined)
            {  
	var Num = document.configForm.CNum.value;
	}
	else
	{
	Num ="";
	}
 	if(isNaN(Num))//check that number is a digit value, not alpha.
	{
		alert ('Please enter a numerical value for insertion \'U\' length');
		return true;
	}
	else
	{
		if(document.configForm.CType[0].checked) //inches
		{
		
			if(document.configForm.PCmn[0].checked || document.configForm.PCmn[1].checked)		
		   {
		   if(document.configForm.txtqueries.value=="410" || document.configForm.txtqueries.value=="810")
		    {
		if(Num < 2.5)		//check for lower inches boundary
			{
				alert ('Minimum custom insertion \'U\' length = 2.5\"');
				return true;
			}
			else if(Num > 24)	//check for upper inches boundary
			{
			
				alert ('Maximum custom insertion \'U\' length = 24\"');
			
				return true;
			}
				
			else	//check for increments of half inches ONLY
			{
				var period = document.configForm.CNum.value.indexOf(".");
				if(period != -1) //decimal number present
				{
					if(!(document.configForm.CNum.value.substr(period) == 0 || document.configForm.CNum.value.substr(period) == 0.5 || document.configForm.CNum.value.substr(period) == "."))//remove all decimal values unless it's equal to zero or 5
					{
						alert ('Please enter insertion \'U\' lengths in 1/2" increments');
						return true;
					}
				}
			}
			}
			
			
		}
		else
		{
		
			if(Num < 2.5)		//check for lower inches boundary
			{
				alert ('Minimum custom insertion \'U\' length = 2.5\"');
				return true;
			}
			else if(Num > 120)	//check for upper inches boundary
			{
			
				alert ('Maximum custom insertion \'U\' length = 120.0\"');
			
				return true;
			}
					
			else	//check for increments of half inches ONLY
			{
				var period = document.configForm.CNum.value.indexOf(".");
				if(period != -1) //decimal number present
				{
					if(!(document.configForm.CNum.value.substr(period) == 0 || document.configForm.CNum.value.substr(period) == 0.5 || document.configForm.CNum.value.substr(period) == "."))//remove all decimal values unless it's equal to zero or 5
					{
						alert ('Please enter insertion \'U\' lengths in 1/2" increments');
						return true;
					}
				}
			}
		}
		}
		
		else
		{
		
		if(document.configForm.PCmn[0].checked || document.configForm.PCmn[1].checked)
		{
		if(document.configForm.txtqueries.value=="410" || document.configForm.txtqueries.value=="810")
		{
		if(Num < 6.0)		//check for lower centimeters boundary
			{
				alert ('Minimum custom insertion \'U\' length = 6.0 cm');
				return true;
			}
			else if(Num > 60.96)	//check for upper centimeters boundary
			{
				alert ('Maximum custom insertion \'U\' length = 60.96 cm');
				return true;
			}
			
			else	//check for increments of whole centimeters ONLY
			{
				var period = document.configForm.CNum.value.indexOf(".");
				if(period != -1) //decimal number present
				{
					if(!(document.configForm.CNum.value.substr(period) == 0 || document.configForm.CNum.value.substr(period) == "."))//remove all decimal values unless it's equal to zero
					{
						alert ('Please enter insertion \'U\' lengths in 1cm increments');
						return true;
					}
				}
			}
			}
			
		}
		else
		{
			if(Num < 6.0)		//check for lower centimeters boundary
			{
				alert ('Minimum custom insertion \'U\' length = 6.0 cm');
				return true;
			}
			else if(Num > 305)	//check for upper centimeters boundary
			{
				alert ('Maximum custom insertion \'U\' length = 305.0 cm');
				return true;
			}
			else	//check for increments of whole centimeters ONLY
			{
				var period = document.configForm.CNum.value.indexOf(".");
				if(period != -1) //decimal number present
				{
					if(!(document.configForm.CNum.value.substr(period) == 0 || document.configForm.CNum.value.substr(period) == "."))//remove all decimal values unless it's equal to zero
					{
						alert ('Please enter insertion \'U\' lengths in 1cm increments');
						return true;
					}
				}
			}
		}
		}
		
	}
	return false;
	}
	catch(trr)
	{
var Num ="";
	if(document.configForm.CNum != null || document.configForm.CNum != undefined)
            {  
	var Num = document.configForm.CNum.value;
	}
	else
	{
	Num ="";
	}
	
	if(isNaN(Num))//check that number is a digit value, not alpha.
	{
		alert ('Please enter a numerical value for insertion \'U\' length');
		return true;
	}
	
	else
	{
	//alert(document.configForm.CType);
            //var onum =document.configForm.CType.value;
            
            if(document.configForm.CType != null && document.configForm.CType != undefined)
            {            
		if(document.configForm.CType[0].checked) //inches
		{
			if(Num < 2.5)		//check for lower inches boundary
			{
				alert ('Minimum custom insertion \'U\' length = 2.5\"');
				return true;
			}
			else if(Num > 120)	//check for upper inches boundary
			{
			
				alert ('Maximum custom insertion \'U\' length = 120.0\"');
			
				return true;
			}			
			else	//check for increments of half inches ONLY
			{
				var period = document.configForm.CNum.value.indexOf(".");
				if(period != -1) //decimal number present
				{
					if(!(document.configForm.CNum.value.substr(period) == 0 || document.configForm.CNum.value.substr(period) == 0.5 || document.configForm.CNum.value.substr(period) == "."))//remove all decimal values unless it's equal to zero or 5
					{
						alert ('Please enter insertion \'U\' lengths in 1/2" increments');
						return true;
					}
				}
			}
		}
		
		
		else
		{
		
		
			if(Num < 6.0)		//check for lower centimeters boundary
			{
				alert ('Minimum custom insertion \'U\' length = 6.0 cm');
				return true;
			}
			else if(Num > 305)	//check for upper centimeters boundary
			{
				alert ('Maximum custom insertion \'U\' length = 305.0 cm');
				return true;
			}
			else	//check for increments of whole centimeters ONLY
			{
				var period = document.configForm.CNum.value.indexOf(".");
				if(period != -1) //decimal number present
				{
					if(!(document.configForm.CNum.value.substr(period) == 0 || document.configForm.CNum.value.substr(period) == "."))//remove all decimal values unless it's equal to zero
					{
						alert ('Please enter insertion \'U\' lengths in 1cm increments');
						return true;
					}
				}
			}
		}
		}
		
	}
	return false;
	}
};


//function displays the sensor assembly body length custom box option
function dispCustomSABL()
{
	var o = cssObj('customLenBox');
	if(document.configForm.SABL[0].checked && (document.configForm.SABL[0].value == "0000")) // SABL[0] = custom if value "0000"
	{
		o.setStyle('display', 'block');
	}
	else
	{
		o.setStyle('display', 'none');
	}
};


//function displays the sensor assembly body length warning based on type
function SABL_warning()
{
var sablnote="";
if(document.configForm.txtqueries.value=="832" || document.configForm.txtqueries.value=="432" || document.configForm.txtqueries.value=="P52")  
{
sablnote='<br><br><span style=\"color:#000000;\"><b>Note:</b>&nbsp;Some flange sizes / types require minimum overall<br> lengths larger than 7\" - Consult kayden for details.</span><br>';
}
	if(document.configForm.CType[0].checked) // CType[0] = inches
	{
	
		document.getElementById("customWarning").innerHTML = 'Available in 1/2" increments<br />Minimum overall length = 7"; Maximum overall length = 72"' +''+ sablnote;
	
	}
	else
	{
		document.getElementById("customWarning").innerHTML = 'Available in 1cm increments<br />Minimum overall length = 18cm; Maximum overall length = 182cm' +''+ sablnote;
	}
};


//function to validate config form
function validSABL()
{
	//check to if sensor assembly body length has multiple choices
	if(document.configForm.SABL[0])
	{
		if(document.configForm.SABL[0].checked)
		{
			if(checkSABL())
			{
				document.configForm.CNum.focus();
				return false;
			}
		}
	}
	else //check if single choice is custom
	{
		if(document.configForm.SABL.value == "0000")
		{
			if(checkSABL())
			{
				document.configForm.CNum.focus();
				return false;
			}
		}
	}
	return true;
}


//function validates the sensor assembly body Length number based on type 
function checkSABL()
{var Num ="";
	if(document.configForm.CNum != null || document.configForm.CNum != undefined)
            {  
	var Num = document.configForm.CNum.value;
	}
	else
	{
	Num ="";
	}
	 
	if(isNaN(Num))//check that number is a digit value, not alpha.
	{
		alert ('Please enter a numerical value for sensor assembly body length');
		return true;
	}
	else
	{
		if(document.configForm.CType[0].checked) //inches
		{
			if(Num < 7)		//check for lower inches boundary
			{
				alert ('Minimum custom sensor assembly body length = 7.0\"');
				return true;
			}
			else if(Num > 72)	//check for upper inches boundary
			{
				alert ('Maximum custom sensor assembly body length = 72.0\"');
				return true;
			}
			else	//check for increments of half inches ONLY
			{
				var period = document.configForm.CNum.value.indexOf(".");
				if(period != -1) //decimal number present
				{
					if(!(document.configForm.CNum.value.substr(period) == 0 || document.configForm.CNum.value.substr(period) == 0.5 || document.configForm.CNum.value.substr(period) == "."))//remove all decimal values unless it's equal to zero or 5
					{
						alert ('Please enter sensor assembly body lengths in 1/2" increments');
						return true;
					}
				}
			}
		}
		else
		{
			if(Num < 18)		//check for lower centimeters boundary
			{
				alert ('Minimum custom sensor assembly body length = 18.0 cm');
				return true;
			}
			else if(Num > 182)	//check for upper centimeters boundary
			{
				alert ('Maximum custom sensor assembly body length = 182.0 cm');
				return true;
			}
			else	//check for increments of whole centimeters ONLY
			{
				var period = document.configForm.CNum.value.indexOf(".");
				if(period != -1) //decimal number present
				{
					if(!(document.configForm.CNum.value.substr(period) == 0 || document.configForm.CNum.value.substr(period) == "."))//remove all decimal values unless it's equal to zero
					{
						alert ('Please enter sensor assembly body lengths in 1cm increments');
						return true;
					}
				}
			}
		}
	}
	return false;
};

function oneOrNoCheckboxGroup (checkbox) {

  var checkboxGroup =checkbox.form[checkbox.name];
 for (var c = 0; c < checkboxGroup.length; c++)
    if (checkboxGroup[c] != checkbox)
      checkboxGroup[c].checked = false;
}

function radioCheckboxGroup (checkbox) {
//alert(checkbox.form[checkbox.name]);
  var checkboxGroup = checkbox.form[checkbox.name];
  for (var c = 0; c < checkboxGroup.length; c++)
    if (checkboxGroup[c] != checkbox)
      checkboxGroup[c].checked = false;
  return checkbox.checked;
}

//function displays the probe length custom box option
function dispCustomPLen()
{
	var o = cssObj('customLenBox');
	if(document.configForm.PLen[0].checked && (document.configForm.PLen[0].value == "0000")) // PLen[0] = custom if value "0000"
	{
		o.setStyle('display', 'block');
	}
	else
	{
		o.setStyle('display', 'none');
	}
};


//function displays the sensor assembly body length warning based on type
function PLen_warning()
{
	if(document.configForm.CType[0].checked) // CType[0] = inches
	{
		document.getElementById("customWarning").innerHTML = 'Available in 1/2" increments<br />Minimum length = 12"; Maximum length = 360"';
	}
	else
	{
		document.getElementById("customWarning").innerHTML = 'Available in 1cm increments<br />Minimum length = 30cm; Maximum length = 914cm';
	}
};


//function to validate config form
function validPLen()
{
	//check to if sensor assembly body length has multiple choices
	if(document.configForm.PLen[0])
	{
		if(document.configForm.PLen[0].checked)
		{
			if(checkPLen())
			{
				document.configForm.CNum.focus();
				return false;
			}
		}
	}
	else //check if single choice is custom
	{
		if(document.configForm.PLen.value == "0000")
		{
			if(checkPLen())
			{
				document.configForm.CNum.focus();
				return false;
			}
		}
	}
	return true;
}


//function validates the probe Length number based on type 
function checkPLen()
{
	var Num = document.configForm.CNum.value;
	if(isNaN(Num))//check that number is a digit value, not alpha.
	{
		alert ('Please enter a numerical value for probe length');
		return true;
	}
	else
	{
		if(document.configForm.CType[0].checked) //inches
		{
			if(Num < 12)		//check for lower inches boundary
			{
				alert ('Minimum custom probe length = 12.0\"');
				return true;
			}
			else if(Num > 360)	//check for upper inches boundary
			{
				alert ('Maximum custom probe length = 360.0\"');
				return true;
			}
			else	//check for increments of half inches ONLY
			{
				var period = document.configForm.CNum.value.indexOf(".");
				if(period != -1) //decimal number present
				{
					if(!(document.configForm.CNum.value.substr(period) == 0 || document.configForm.CNum.value.substr(period) == 0.5 || document.configForm.CNum.value.substr(period) == "."))//remove all decimal values unless it's equal to zero or 5
					{
						alert ('Please enter probe lengths in 1/2" increments');
						return true;
					}
				}
			}
		}
		else
		{
			if(Num < 30)		//check for lower centimeters boundary
			{
				alert ('Minimum custom probe length = 30.0 cm');
				return true;
			}
			else if(Num > 914)	//check for upper centimeters boundary
			{
				alert ('Maximum custom probe length = 914.0 cm');
				return true;
			}
			else	//check for increments of whole centimeters ONLY
			{
				var period = document.configForm.CNum.value.indexOf(".");
				if(period != -1) //decimal number present
				{
					if(!(document.configForm.CNum.value.substr(period) == 0 || document.configForm.CNum.value.substr(period) == "."))//remove all decimal values unless it's equal to zero
					{
						alert ('Please enter probe lengths in 1cm increments');
						return true;
					}
				}
			}
		}
	}
	return false;
};


//function displays the cables & lengths box for Remote Enclosures
function dispCables()
{
	var o = cssObj('cableLen');
	if(document.configForm.REnc[0].checked) // REnc[0] = custom
	{
		o.setStyle('display', 'none');
	}
	else
	{
		o.setStyle('display', 'block');
	}
};



