function autoSelectInquiry()
{
	showDiv(0);
	var iType
	iType=document.location.search;
	iType=iType.substring(7,iType.length)
	if ((iType>0)&&(iType<(document.forms['EmailForm'].InquiryTypeDropDown.length)))
	{
		document.forms['EmailForm'].InquiryTypeDropDown.options[iType].selected=true;
		for (var i=0; i < document.forms['EmailForm'].InquiryTypeDropDown.length;i++)
		{
			if((document.forms['EmailForm'].InquiryTypeDropDown.options[i].value)==iType)
			{
				document.forms['EmailForm'].InquiryTypeDropDown.options[iType].selected=true;
				showDiv(iType);
			}
		}
	}
	document.EmailForm.InquiryTypeDropDown.selectedIndex=0;
}

function resetStyle(lblName)
{
	lblName = "lbl" + lblName;
	document.getElementById(lblName).style.color="black";
	document.getElementById(lblName).style.fontWeight="normal";
}

function displayAttachmentInput()
{
	document.getElementById("dependent-upload-link").style.display = 'none';
	document.getElementById("dependent-upload").style.display = 'block';
}

function showDiv(optionValue)
{
	//Reset Styles
	resetStyle("FirstName");
	resetStyle("LastName");
	resetStyle("EmailAddress");
	resetStyle("PhoneNumber");
	resetStyle("AccountNumber")
	resetStyle("InquiryOther");
	resetStyle("InvoiceNumber");
	resetStyle("InquiryDescription");
	resetStyle("ProductLine");
	resetStyle("Product");
	resetStyle("BinderTaxYear");
	resetStyle("BinderTaxYear");
	resetStyle("TrustNumber");
	resetStyle("TrustTaxYear");
	resetStyle("ElectronicFiling");
	resetStyle("DescriptionOfRequest");
	resetStyle("Attachment")

	// first hide all dependent divs
	document.getElementById("dependent-inquiry-other").style.display = 'none';
	document.getElementById("dependent-inquiry-other").style.display = 'none';
	document.getElementById("Inquiry-Details-Fieldset").style.display = 'none';
	document.getElementById("dependent-inquiry-description").style.display = 'none';
	document.getElementById("dependent-invoice-number").style.display = 'none';
	document.getElementById("dependent-product-line").style.display = 'none';
	document.getElementById("dependent-product").style.display = 'none';
	document.getElementById("dependent-binder-number").style.display = 'none';
	document.getElementById("dependent-binder-tax-year").style.display = 'none';
	document.getElementById("dependent-trust-number").style.display = 'none';
	document.getElementById("dependent-trust-tax-year").style.display = 'none';
	document.getElementById("dependent-electronic-filing").style.display = 'none';
	document.getElementById("dependent-upload-help").style.display = 'none';
	document.getElementById("dependent-upload-link").style.display = 'none';
	document.getElementById("dependent-upload").style.display = 'none';

	document.getElementById("Contact-Method-Fieldset").style.display = 'none';
	document.getElementById("dependent-response-optional").style.display = 'none';
	document.getElementById("Submit-Buttons").style.display = 'none';
	document.EmailForm.ProductLineDropDown.selectedIndex=0;
	document.EmailForm.ProductDropDown.selectedIndex=0;
	
	switch (optionValue)
	{
		//Account Management
		case "1":
			window.document.EmailForm.FormType.value="1";

			document.getElementById("Inquiry-Details-Fieldset").style.display = 'block';
			document.getElementById("dependent-inquiry-description").style.display = 'block';
			document.getElementById("dependent-invoice-number").style.display = 'block';
			document.getElementById("dependent-upload-link").style.display = 'block';

			document.getElementById("Contact-Method-Fieldset").style.display = 'block';

			document.getElementById("Submit-Buttons").style.display = 'block';
			break

		//Product Support
		case "2":
			window.document.EmailForm.FormType.value="2";

			AddAllProductLines();
			
			document.getElementById("Inquiry-Details-Fieldset").style.display = 'block';
			document.getElementById("dependent-product-line").style.display = 'block';
			document.getElementById("dependent-upload-help").style.display = 'block';
			document.getElementById("dependent-upload-link").style.display = 'block';

			document.getElementById("Contact-Method-Fieldset").style.display = 'block';

			document.getElementById("Submit-Buttons").style.display = 'block';
			break

		//Systems Support
		case "3":
			window.document.EmailForm.FormType.value="3";

			AddSystemProductLines();
			
			document.getElementById("Inquiry-Details-Fieldset").style.display = 'block';
			document.getElementById("dependent-product-line").style.display = 'block';
			document.getElementById("dependent-product").style.display = 'block';
			document.getElementById("dependent-binder-number").style.display = 'block';
			document.getElementById("dependent-binder-tax-year").style.display = 'block';
			document.getElementById("dependent-upload-help").style.display = 'block';
			document.getElementById("dependent-upload-link").style.display = 'block';

			document.getElementById("Contact-Method-Fieldset").style.display = 'block';

			document.getElementById("Submit-Buttons").style.display = 'block';
			break

		//Other
		case "4":
			window.document.EmailForm.FormType.value="4";
			
			document.getElementById("dependent-inquiry-other").style.display = 'block';

			document.getElementById("Inquiry-Details-Fieldset").style.display = 'block';
			document.getElementById("dependent-upload-link").style.display = 'block';

			document.getElementById("Contact-Method-Fieldset").style.display = 'block';

			document.getElementById("Submit-Buttons").style.display = 'block';
			break

	} //switch
} //showDiv

function AddFFSProducts()
{
	var selbox = document.EmailForm.ProductDropDown;
	selbox.length=1;
	selbox.options[0] = new Option('- Select Product -','00');

	selbox.options[selbox.options.length] = new Option('1041 & Related State Fiduciary Returns','1041 & Related State Fiduciary Returns');
	selbox.options[selbox.options.length] = new Option('706 & Related State Death & Insurance Tax Returns','706 & Related State Death & Insurance Tax Returns');
	selbox.options[selbox.options.length] = new Option('709','709');
	selbox.options[selbox.options.length] = new Option('FAS','FAS');
	selbox.options[selbox.options.length] = new Option('ZCALC','ZCALC');
}

function AddInSourceProducts()
{
	var selbox = document.EmailForm.ProductDropDown;
	selbox.length=1;
	selbox.options[0] = new Option('- Select Product -','00');

	selbox.options[selbox.options.length] = new Option('InSource CS Domestic','InSource CS Domestic');
	selbox.options[selbox.options.length] = new Option('InSource CS International','InSource CS International');
	selbox.options[selbox.options.length] = new Option('InSource CS Provisions','InSource CS Provisions');
	selbox.options[selbox.options.length] = new Option('InSource Exchange','InSource Exchange');
	selbox.options[selbox.options.length] = new Option('InSource Express CD','InSource Express CD');
	selbox.options[selbox.options.length] = new Option('InSource Express RS','InSource Express RS');
	selbox.options[selbox.options.length] = new Option('InSource FIN48','InSource FIN48');
	selbox.options[selbox.options.length] = new Option('InSource OneSource Tax','InSource OneSource Tax');
	selbox.options[selbox.options.length] = new Option('InSource RS Domestic','InSource RS Domestic');
	selbox.options[selbox.options.length] = new Option('InSource RS Fixed Assets','InSource RS Fixed Assets');
	selbox.options[selbox.options.length] = new Option('InSource RS International','InSource RS International');
	selbox.options[selbox.options.length] = new Option('InSource RS Provisions','InSource RS Provisions');
	selbox.options[selbox.options.length] = new Option('InSource S&U','InSource S&U');
	selbox.options[selbox.options.length] = new Option('InSource S&U RS','InSource S&U RS');
	selbox.options[selbox.options.length] = new Option('InSource Tax Calendar','InSource Tax Calendar');
	selbox.options[selbox.options.length] = new Option('InSource Workflow Manager','InSource Workflow Manager');
}

function AddOneSourceProducts()
{
	var selbox = document.EmailForm.ProductDropDown;
	selbox.length=1;
	selbox.options[0] = new Option('- Select Product -','00');

	selbox.options[selbox.options.length] = new Option('OneSource Workflow Manager','OneSource Workflow Manager');
	selbox.options[selbox.options.length] = new Option('OneSource Calendar','OneSource Calendar');
	selbox.options[selbox.options.length] = new Option('OneSource Tax','OneSource Tax');
	selbox.options[selbox.options.length] = new Option('OneSource Entity Manager','OneSource Entitiy Manager');
	selbox.options[selbox.options.length] = new Option('Other','Other');
}

function AddAllProductLines()
{
	var selbox = document.EmailForm.ProductLineDropDown;
	selbox.length=1;
	selbox.options[0] = new Option('- Select One -','');

	selbox.options[selbox.options.length] = new Option('eComply','eComply');
	selbox.options[selbox.options.length] = new Option('FPS','FPS');
	selbox.options[selbox.options.length] = new Option('InSource','InSource');
	selbox.options[selbox.options.length] = new Option('OneSource','OneSource');
	selbox.options[selbox.options.length] = new Option('TrustEase','TrustEase');
	selbox.options[selbox.options.length] = new Option('Other','Other');
}

function AddSystemProductLines()
{
	var selbox = document.EmailForm.ProductLineDropDown;
	selbox.length=1;
	selbox.options[0] = new Option('- Select One -','');

	selbox.options[selbox.options.length] = new Option('InSource','InSource');
	selbox.options[selbox.options.length] = new Option('OneSource','OneSource');
}

function changeProductLine(FormType)
{
	switch (document.EmailForm.ProductLineDropDown.value)
	{
		case "FPS":
			document.getElementById("dependent-product").style.display = 'block';
			AddFFSProducts();
			break
		case "InSource":
			document.getElementById("dependent-product").style.display = 'block';
			AddInSourceProducts();
			break
		case "OneSource":
			document.getElementById("dependent-product").style.display = 'block';
			AddOneSourceProducts();
			break
		default:
			document.getElementById("dependent-product").style.display = 'block';
			document.getElementById("dependent-product").style.display = 'none';
			break
	}

	if (document.EmailForm.ProductLineDropDown.value=="InSource")
	{
		document.getElementById("dependent-binder-number").style.display = 'block';
		document.getElementById("dependent-binder-tax-year").style.display = 'block';
		if (FormType=="2")
		{
			document.getElementById("dependent-electronic-filing").style.display = 'block';
		}
	}
	else
	{
		document.getElementById("dependent-binder-number").style.display = 'none';
		document.getElementById("dependent-binder-tax-year").style.display = 'none';
		document.getElementById("dependent-electronic-filing").style.display = 'none';
	}

	if ((document.EmailForm.ProductLineDropDown.value=="TrustEase")&&(FormType=="2"))
	{
		document.getElementById("dependent-trust-number").style.display = 'block';
		document.getElementById("dependent-trust-tax-year").style.display = 'block';
	}
	else
	{
		document.getElementById("dependent-trust-number").style.display = 'none';
		document.getElementById("dependent-trust-tax-year").style.display = 'none';
	}
}

function changeBinderNumber(FormType)
{
	if (document.EmailForm.BinderNumberTextBox.value!="")
	{
		document.getElementById("dependent-binder-tax-year-required").style.visibility="visible";
	}
	else
	{
		document.getElementById("dependent-binder-tax-year-required").style.visibility="hidden";
	}
}

function SubmitForm()
{
	strFormType = document.EmailForm.FormType.value;

	strErr = ""; //clear error label
	flag = true; //unset flag

	//unset all style colors
	resetStyle("FirstName");
	resetStyle("LastName");
	resetStyle("EmailAddress");
	resetStyle("PhoneNumber");
	resetStyle("AccountNumber")
	resetStyle("InvoiceNumber");
	resetStyle("InquiryDescription");
	resetStyle("ProductLine");
	resetStyle("Product");
	resetStyle("BinderTaxYear");
	resetStyle("TrustNumber");
	resetStyle("TrustTaxYear");
	resetStyle("ElectronicFiling");
	resetStyle("DescriptionOfRequest");
	resetStyle("Attachment")
	
	validateForm();
	if(flag){
		document.EmailForm.action="SendEmail.asp";
		document.EmailForm.submit();
	}
	else
		alert(strErr);
}

function validateForm()
{
	validRequired("FirstName");
	validRequired("LastName");
	validRequired("EmailAddress");
	validRequired("PhoneNumber");
	validRequired("AccountNumber");
	validRequired("DescriptionOfRequest");
	
	if(strFormType=="1")
	{
		validRequired("InquiryDescription");
		validRequired("InvoiceNumber");
	}

	if(strFormType=="2")
	{
		validRequired("ProductLine");
		validRequired("Product");
		validRequired("BinderTaxYear");
		validRequired("TrustNumber");
		validRequired("TrustTaxYear");
		validRequired("ElectronicFiling");
	}
	
	if(strFormType=="3")
	{
		validRequired("Product");
		validRequired("BinderTaxYear");
	}

	if(strFormType=="4")
	{
		validRequired("InquiryOther");
	}

	if(!flag){strErr = strErr + "Please complete all required fields (shown in bold red)";}
}

function validRequired(lblName)
{
	// First Name Validation
	if((lblName=="FirstName") && (document.EmailForm.FirstNameTextBox.value==""))
	{
		document.getElementById('lbl' + lblName).style.color="red";
		document.getElementById('lbl' + lblName).style.fontWeight="bold";
		flag = false;
	}

	// Last Name Validation
	if((lblName=="LastName") && (document.EmailForm.LastNameTextBox.value==""))
	{
		document.getElementById('lbl' + lblName).style.color="red";
		document.getElementById('lbl' + lblName).style.fontWeight="bold";
		flag = false;
	}

	// Email Validation
	if((lblName=="EmailAddress") && (document.EmailForm.EmailAddressTextBox.value==""))
	{
		document.getElementById('lbl' + lblName).style.color="red";
		document.getElementById('lbl' + lblName).style.fontWeight="bold";
		flag = false;
	}
	if((lblName=="EmailAddress") && (document.EmailForm.EmailAddressTextBox.value!=""))
	{
		str=document.EmailForm.EmailAddressTextBox.value;
		if (str.indexOf("@") == -1){
			document.getElementById('lbl' + lblName).style.color="red";
			document.getElementById('lbl' + lblName).style.fontWeight="bold";
			flag = false;
			alert("Please enter a valid email address.");
		}
		if (str.indexOf(".") == -1)
		{
			document.getElementById('lbl' + lblName).style.color="red";
			document.getElementById('lbl' + lblName).style.fontWeight="bold";
			flag = false;
			alert("Please enter a valid email address.");
		}
		else
		{
			var atPos = str.indexOf("@")
			if (str.indexOf(".",atPos) == -1)
			{
				document.getElementById('lbl' + lblName).style.color="red";
				document.getElementById('lbl' + lblName).style.fontWeight="bold";
				flag = false;
				alert("Please enter a valid email address.");
			}
		}
	}

	// Phone Validation
	if(lblName=="PhoneNumber"){
		if (document.EmailForm.PhoneNumberTextBox.value=="")
		{
			document.getElementById('lbl' + lblName).style.color="red";
			document.getElementById('lbl' + lblName).style.fontWeight="bold";
			flag = false;
		}
		else
		{
			if (document.EmailForm.PhoneNumberTextBox.value!="")
			{
				if (document.EmailForm.PhoneNumberTextBox.value.length < 10) 
				{ 
					document.getElementById('lbl' + lblName).style.color="red";
					document.getElementById('lbl' + lblName).style.fontWeight="bold";
					flag = false;
					alert('Phone numbers should include at least 10 digits.')
				}
				else
				{	
					x=0
					for (j=0; j<document.EmailForm.PhoneNumberTextBox.value.length; j++) 
					{
						x=x+1 
						if ((document.EmailForm.PhoneNumberTextBox.value.charAt(j) < "0") || (document.EmailForm.PhoneNumberTextBox.value.charAt(j) > "9")) 
						{ 
							x=x-1
						}
					}
					if (x<10)
					{
						document.getElementById('lbl' + lblName).style.color="red";
						document.getElementById('lbl' + lblName).style.fontWeight="bold";
						flag = false;
						alert('Phone numbers should include at least 10 digits.')
					}
			 	}
			}
		}
	}

	// Account Number Validation
	if((lblName=="AccountNumber") && (document.EmailForm.AccountNumberTextBox.value==""))
	{
		document.getElementById('lbl' + lblName).style.color="red";
		document.getElementById('lbl' + lblName).style.fontWeight="bold";
		flag = false;
	}
	if((lblName=="AccountNumber") && (document.EmailForm.AccountNumberTextBox.value!=""))
	{
		if (document.EmailForm.AccountNumberTextBox.value!="")
		{
			var acctNumRegEx = new RegExp("^[A-Za-z0-9]{1,20}$");
			if (!acctNumRegEx.test(document.EmailForm.AccountNumberTextBox.value))
			{ 
				document.getElementById('lbl' + lblName).style.color="red";
				document.getElementById('lbl' + lblName).style.fontWeight="bold";
				flag = false;
				alert('Please review your account number for accuracy and resubmit.')
			}
		}
	}

	// Inquiry Other Validation
	if((lblName=="InquiryOther") && (document.EmailForm.InquiryOtherTextBox.value==""))
	{
		document.getElementById('lbl' + lblName).style.color="red";
		document.getElementById('lbl' + lblName).style.fontWeight="bold";
		flag = false;
	}

	// Inquiry Description
	if(lblName=="InquiryDescription")
	{
		selectedButton = -1;
		for (i=document.EmailForm.InquiryDescRadio.length-1; i > -1; i--)
		{
			if (document.EmailForm.InquiryDescRadio[i].checked)
			{
				selectedButton = i; i = -1;
			}
		}
		if (selectedButton == -1)
		{
			document.getElementById('lbl' + lblName).style.color="red";
			document.getElementById('lbl' + lblName).style.fontWeight="bold";
			flag = false;
		}
	}

	// Invoice Number Validation
	if((lblName=="InvoiceNumber") && (document.EmailForm.InvoiceNumberTextBox.value!=""))
	{
		if (document.EmailForm.InvoiceNumberTextBox.value!="")
		{
			var acctNumRegEx = new RegExp("^[A-Za-z0-9]{7,14}$");
			if (!acctNumRegEx.test(document.EmailForm.InvoiceNumberTextBox.value))
			{ 
				document.getElementById('lbl' + lblName).style.color="red";
				document.getElementById('lbl' + lblName).style.fontWeight="bold";
				flag = false;
				alert('Please review your invoice number for accuracy and resubmit.')
			}
		}
	}

	// Product Line Validation
	if (lblName=="ProductLine")
	{
		if (document.EmailForm.FormType.value=="2")
		{
			if (document.EmailForm.ProductLineDropDown.selectedIndex==0)
			{
				document.getElementById('lbl' + lblName).style.color="red";
				document.getElementById('lbl' + lblName).style.fontWeight="bold";
				flag = false;
			}
		}
	}

	// Product Validation
	if (lblName=="Product")
	{
		if (document.EmailForm.FormType.value=="2")
		{
			if ((document.EmailForm.ProductLineDropDown.value=="InSource")||(document.EmailForm.ProductLineDropDown.value=="FPS"))
			{
				if (document.EmailForm.ProductDropDown.selectedIndex==0)
				{
					document.getElementById('lbl' + lblName).style.color="red";
					document.getElementById('lbl' + lblName).style.fontWeight="bold";
					flag = false;
				}
			}
		}
		if (document.EmailForm.FormType.value=="3")
		{
			if (document.EmailForm.ProductDropDown.selectedIndex==0)
			{
				document.getElementById('lbl' + lblName).style.color="red";
				document.getElementById('lbl' + lblName).style.fontWeight="bold";
				flag = false;
			}
		}
	}

	// Binder Tax Year Validation
	if((lblName=="BinderTaxYear") && (document.EmailForm.BinderNumberTextBox.value!=""))
	{
		if (document.EmailForm.ProductLineDropDown.value=="InSource")
		{
			if (document.EmailForm.BinderTaxYearTextBox.value=="")
			{
				document.getElementById('lbl' + lblName).style.color="red";
				document.getElementById('lbl' + lblName).style.fontWeight="bold";
				flag = false;
				alert('Please provide a Tax Year and resubmit.')
			}
			else
			{
				var binTaxYearRegEx = new RegExp("^[0-9]{4}$");
				if (!binTaxYearRegEx.test(document.EmailForm.BinderTaxYearTextBox.value))
				{ 
					document.getElementById('lbl' + lblName).style.color="red";
					document.getElementById('lbl' + lblName).style.fontWeight="bold";
					flag = false;
					alert('Please provide a 4 digit tax year and resubmit.')
				}
			}
		}
	}

	// Trust Number Validation
	if(lblName=="TrustNumber")
	{
		if (document.EmailForm.ProductLineDropDown.value=="TrustEase")
		{
			if(document.EmailForm.TrustNumberTextBox.value=="")
			{
				document.getElementById('lbl' + lblName).style.color="red";
				document.getElementById('lbl' + lblName).style.fontWeight="bold";
				flag = false;
			}
		}
	}
	if((lblName=="TrustNumber") && (document.EmailForm.TrustNumberTextBox.value!=""))
	{
		if (document.EmailForm.TrustNumberTextBox.value!="")
		{
			var acctNumRegEx = new RegExp("^[A-Za-z0-9]{1,20}$");
			if (!acctNumRegEx.test(document.EmailForm.TrustNumberTextBox.value))
			{ 
				document.getElementById('lbl' + lblName).style.color="red";
				document.getElementById('lbl' + lblName).style.fontWeight="bold";
				flag = false;
				alert('Please review your trust number for accuracy and resubmit.')
			}
		}
	}

	// Trust Tax Year Validation
	if(lblName=="TrustTaxYear")
	{
		if (document.EmailForm.ProductLineDropDown.value=="TrustEase")
		{
			if(document.EmailForm.TrustTaxYearTextBox.value=="")
			{
				document.getElementById('lbl' + lblName).style.color="red";
				document.getElementById('lbl' + lblName).style.fontWeight="bold";
				flag = false;
			}
		}
	}
	if((lblName=="TrustTaxYear") && (document.EmailForm.TrustNumberTextBox.value!=""))
	{
		if (document.EmailForm.TrustTaxYearTextBox.value=="")
		{
			document.getElementById('lbl' + lblName).style.color="red";
			document.getElementById('lbl' + lblName).style.fontWeight="bold";
			flag = false;
			alert('Please provide a Tax Year and resubmit.')
		}
		else
		{
			var truTaxYearRegEx = new RegExp("^[0-9]{4}$");
			if (!truTaxYearRegEx.test(document.EmailForm.TrustTaxYearTextBox.value))
			{ 
				document.getElementById('lbl' + lblName).style.color="red";
				document.getElementById('lbl' + lblName).style.fontWeight="bold";
				flag = false;
				alert('Please provide a 4 digit tax year and resubmit.')
			}
		}
	}

	// Who is impacted?
	if(lblName=="ElectronicFiling")
	{
		if (document.EmailForm.ProductLineDropDown.value=="InSource")
		{
			selectedButton = -1;
			for (i=document.EmailForm.ElectronicFilingRadio.length-1; i > -1; i--)
			{
				if (document.EmailForm.ElectronicFilingRadio[i].checked)
				{
					selectedButton = i; i = -1;
				}
			}
			if (selectedButton == -1)
			{
					document.getElementById('lbl' + lblName).style.color="red";
					document.getElementById('lbl' + lblName).style.fontWeight="bold";
					flag = false;
					alert('Please indicate whether or not this is an electronic filing question and resubmit.')
			}
		}
	}

	// How would you like us to respond
	if(lblName==8)
	{
		selectedButton = -1;
		for (i=document.EmailForm.ResponseRadio.length-1; i > -1; i--)
		{
			if (document.EmailForm.ResponseRadio[i].checked)
			{
				selectedButton = i; i = -1;
			}
		}
		if (selectedButton == -1)
		{
			document.getElementById('lbl' + lblName).style.color="red";
			document.getElementById('lbl' + lblName).style.fontWeight="bold";
			flag = false;
		}
	}
	
	// Requests/Comments
	if((lblName=="DescriptionOfRequest") && (document.EmailForm.DescrptionOfRequestTextArea.value==""))
	{
		document.getElementById('lbl' + lblName).style.color="red";
		document.getElementById('lbl' + lblName).style.fontWeight="bold";
		flag = false;
	}

	if((lblName=="Attachment") && (document.EmailForm.FilAttach.value!=""))
	{
		var ext = document.EmailForm.FilAttach.value;
		ext = ext.substring(ext.length-3,ext.length);
		ext = ext.toLowerCase();
		if ((ext == 'exe')||(ext=='.js')||(ext=='.vb')||(ext=='asp')||(ext=='dll')||(ext=='scr')||(ext=='bat')||(ext=='reg')||(ext=='cab')||(ext=='mp3'))
		{
			alert('You selected a .'+ext+
			' file; Please select a text-based file.');
			flag = false;;
		}
	}
}

