//	Javascript included in ContactUs.xslt
//	Created by Ajai, 24 Jan 2005. Copied fom ContactUs_v3,js and changed display of Establishment to Organisation for BSF.
//  Amended:	Ajai 29/03/07 - VAE 15359. Made non logged in Job title and Organisation field based on Customer Type selection
//				Ajai 08/02/08 - 17547,17562,17563,17564,17570 Nature of message changes. 

function validate()
{
	var validated = false;
	var strError = new String();
	var bIE = browserName == 'IE';
	
	document.frmFeedback.elements['inpAction'].value = 'SUBMIT';
	
	// Update Textual Email Type Hidden Element.
	document.frmFeedback.elements['inpEmailType'].value = document.frmFeedback.elements['inpVisibleEmailType'].options[document.frmFeedback.elements['inpVisibleEmailType'].selectedIndex].text;

	//If we are not changing login stuff then get types to determine the routing
    // Nick Pattman 23-Jul corrected test for logindetails for JScript compliancy
    
    
    // Check that we've chosen area of enquiry
	if (document.frmFeedback.elements['inpEmailTypeID'].value == '0')
	{
		strError += '* The area of your enquiry \n';
	}    
    
    
    if (document.frmFeedback.elements['inpVisibleEmailType'].options[document.frmFeedback.elements['inpVisibleEmailType'].selectedIndex].text == 'Product or Sales query')
			{
			if (document.frmFeedback.inpRegionType['0'].checked == false && document.frmFeedback.inpRegionType['1'].checked == false && document.frmFeedback.inpRegionType['2'].checked == false)
			{
			strError += '* What is your region? \n'; 		
			if (bIE && document.all.tdRegionType) 
				document.all.tdRegionType.className = 'dataerror'; 
			} 
			else 
				if (bIE) 
					document.all.tdRegionType.className = 'data1';
				
						
				
			if (document.frmFeedback.inpRegionType['0'].checked == true)
			{
				document.frmFeedback.elements['inpEmailTypeID'].value = document.frmFeedback.inpRegionType['0'].value;
				document.frmFeedback.elements['inpEmailType'].value = 'Product or Sales Query – UK North';
			}
			if (document.frmFeedback.inpRegionType['1'].checked == true)
			{
				document.frmFeedback.elements['inpEmailTypeID'].value = document.frmFeedback.inpRegionType['1'].value;
				document.frmFeedback.elements['inpEmailType'].value = 'Product or Sales Query – UK South';
			}
			if (document.frmFeedback.inpRegionType['2'].checked == true)
			{
				document.frmFeedback.elements['inpEmailTypeID'].value = document.frmFeedback.inpRegionType['2'].value;
				document.frmFeedback.elements['inpEmailType'].value = 'Product or Sales Query – International';
			}			
						
		}
		else
		{
			if (bIE && document.all.tdRegionType) 
				document.all.tdRegionType.className = 'data1';
					
			document.frmFeedback.elements['inpEmailType'].value =	document.frmFeedback.elements['inpVisibleEmailType'].options[document.frmFeedback.elements['inpVisibleEmailType'].selectedIndex].text;
			document.frmFeedback.elements['inpEmailTypeID'].value = document.frmFeedback.elements['inpVisibleEmailType'].value;
		}
	
	
	
	//If not logged in we need details from form elements. Check them

	if (document.frmFeedback.elements['IsLoggedIn'].value == '0')
	{	
		if (document.frmFeedback.elements.inpReply['0'].checked == true)
		{
			if (document.frmFeedback.elements['inpTitle'].value.length < 1)
			{
				strError += '* Title \n';
				if (bIE)
					document.all.tdTitle.className = 'dataerror';
			}
			else {
				if (bIE)
					document.all.tdTitle.className = 'data1';
			}
			if (document.frmFeedback.elements['inpForename'].value.length < 1)
			{
				strError += '* Forename \n';
				if (bIE)
					document.all.tdForename.className = 'dataerror';
			}
			else
				if (bIE)
					document.all.tdForename.className = 'data1';
			 
			if (document.frmFeedback.elements['inpSurname'].value.length < 1)
			{
				strError += '* Surname \n';
				if (bIE)
					document.all.tdSurname.className = 'dataerror';				
			}
			else
				if (bIE)
					document.all.tdSurname.className = 'data1';
					
			if (document.frmFeedback.inpCustType[0].checked == false &&
				document.frmFeedback.inpCustType[1].checked == false &&
				document.frmFeedback.inpCustType[2].checked == false )
			{	
				strError += '* Which best describes you? \n';				
				
				if (bIE && document.all.tdCustType)
					document.all.tdCustType.className = 'dataerror';
				
			}
			else
				if (bIE)
					document.all.tdCustType.className = 'data1';
			
			if (document.frmFeedback.inpCustType[0].checked == true ||
				document.frmFeedback.inpCustType[1].checked == true )
				{								
					if (document.frmFeedback.elements['inpJobTitle'].value.length < 1)
					{
						strError += '* Job Title \n';
						if (bIE && document.all.tdJobTitle)
							document.all.tdJobTitle.className = 'dataerror';
					}
					else
						if (bIE && document.all.tdJobTitle)
							document.all.tdJobTitle.className = 'data1';
							
					if (document.frmFeedback.elements['inpEstablishment'].value.length < 1)
					{
						strError += '* Organisation \n';
						if (bIE && document.all.tdEstablishment)
							document.all.tdEstablishment.className = 'dataerror';
					}
					else
						if (bIE && document.all.tdEstablishment)
							document.all.tdEstablishment.className = 'data1';
				}
			if (document.frmFeedback.inpCustType[2].checked == true)
			{
				document.frmFeedback.elements['inpJobTitle'].value='';
				if (bIE && document.all.tdJobTitle)
							document.all.tdJobTitle.className = 'data1';
				document.frmFeedback.elements['inpEstablishment'].value='';	
				if (bIE && document.all.tdEstablishment)
							document.all.tdEstablishment.className = 'data1';
			}
			if (document.frmFeedback.elements['inpAddress'].value.length < 1)
			{
				strError += '* Address \n';
				if (bIE && document.all.tdAddress)
					document.all.tdAddress.className = 'dataerror';
			}
			else
				if (bIE && document.all.tdAddress)
					document.all.tdAddress.className = 'data1';
					
			
			if (document.frmFeedback.elements['inpVisibleEmailType'].options[document.frmFeedback.elements['inpVisibleEmailType'].selectedIndex].text == 'Technical Support')
			{
				if (document.frmFeedback.elements['inpCustomerNo'].value.length < 1)
				{
				strError += '* Customer Number \n';
				if (bIE)
					document.all.tdCustomerNo.className = 'dataerror';
				}
			}
			else
				if (bIE)
					document.all.tdCustomerNo.className = 'data1';
			
			//check they've entered a communication value for the communication reply type they've chosen

			if (document.frmFeedback.elements.inpReply['0'].checked == true)
			{
				if (document.frmFeedback.elements.inpReplyType['0'].checked == true)
				{
					if (document.frmFeedback.elements['inpCustomerEmail'].value.length == 0)
					{
						strError +='* An email address if you would like us to reply by email \n';
						if (bIE)
							document.all.tdEmail.className = 'dataerror'
					}
					else
						if (bIE)
							document.all.tdEmail.className = 'data1'
				}
				else
					if (bIE)
						document.all.tdEmail.className = 'data1'		
			}			
			if (browserVersion >= 4.0)
			{
				if (document.frmFeedback.elements['inpCustomerEmail'].value.length > 0)
				{
					if (checkEmail(document.frmFeedback.elements['inpCustomerEmail'].value) != true)
					{
						strError += '* The email address supplied appears to be invalid, \n' +
						'   (if you do not have a valid email address please \n' +
						'   provide us with a contact telephone number) \n';
						if (bIE)
							document.all.tdEmail.className = 'dataerror';
						//document.frmFeedback.elements['inpCustomerEmail'].value = '';
					}
					else
						if (bIE)
							document.all.tdEmail.className = 'data1';
				}
			}
		}
	}
	
	

	//check they've entered some comments / feedback.
	
	if (document.frmFeedback.elements['inpFeedback'].value.length < 1)
	{
		strError += '* Comments \n';
		if (bIE)
			document.all.tdComments.className = 'dataerror';		
	}
	else
		if (bIE)
			document.all.tdComments.className = 'data1';			
	
	if (document.frmFeedback.elements.inpReply['0'].checked == true)
	{
		if (document.frmFeedback.elements.inpReplyType['1'].checked == true)
		{
			if (document.frmFeedback.elements['inpCustTelephone'].value.length == 0)
			{
				strError +='* A telephone number if you would like us to reply by phone \n';
				if (bIE && document.all.tdTelephone)
					document.all.tdTelephone.className = 'dataerror';
			}
			else
				if (bIE && document.all.tdTelephone)
					document.all.tdTelephone.className = 'data1'
		}
		else
			if (bIE && document.all.tdTelephone)
				document.all.tdTelephone.className = 'data1'
	}

	if (document.frmFeedback.elements.inpReply['0'].checked == true)
	{
		if (document.frmFeedback.elements.inpReplyType['2'].checked == true)
		{
			if (document.frmFeedback.elements.inpCustFax.value.length == 0)
			{
				strError +='* A fax number if you would like us to reply by fax \n';
				if (bIE && document.all.tdFax)
					document.all.tdFax.className = 'dataerror';
			}
			else
				if (bIE && document.all.tdFax)
					document.all.tdFax.className = 'data1';
		}
		else
			if (bIE && document.all.tdFax)
				document.all.tdFax.className = 'data1';		
	}		
	
	
	
	// Check JobTitle and Address If logged in!
	if (!document.frmFeedback.elements['inpOptionalJobtitle'])
	{
		if (document.frmFeedback.elements['inpJobTitle'].value.length < 1)
		{
			strError += '* Job Title \n';
			if (bIE && document.all.tdJobTitle)
				document.all.tdJobTitle.className = 'dataerror';
		}
		else
			if (bIE && document.all.tdJobTitle)
					document.all.tdJobTitle.className = 'data1';
	}							
	if (document.frmFeedback.elements['inpAddress'].value.length < 1)
	{
		strError += '* Address \n';
		if (bIE && document.all.tdAddress)
			document.all.tdAddress.className = 'dataerror';
	}
	else
		if (bIE && document.all.tdAddress)
			document.all.tdAddress.className = 'data1';
	
	//Check for Area of Interest (aka. Web Sector).
	//Note - if attribute possessed, get the value from a hidden element, otherwise from a combo.
	
	if (document.frmFeedback.elements['inpHaveAttribute'].value == '0')
	{
		if (document.frmFeedback.elements['inpWebSectorID'].options[document.frmFeedback.elements['inpWebSectorID'].selectedIndex].value == '0')
		{
			strError += '* Your main area of interest \n';
			if (bIE && document.all.tdInterest !=null)
				document.all.tdInterest.className = 'dataerror';	
		}
		else
			if (bIE && document.all.tdInterest !=null)
				document.all.tdInterest.className = 'data1'
	}
	else
	{
		if (document.frmFeedback.elements['inpWebSectorID'].value == '0')
		{
			strError += '* Your main area of interest \n';
			if (bIE && document.all.tdInterest !=null)
				document.all.tdInterest.className = 'dataerror';
		}
		else
			if (bIE && document.all.tdInterest !=null)
				document.all.tdInterest.className = 'data1';
	}
	
	if (strError.length < 1) validated = true;
	
	if (validated == true)
	{
		return true;
	}
	else
	{
		alert('Could not post form. \n ' + 
			  'Please provide us with the following information and retry : \n \n' 
			  + strError);
		return false;
	}
}

function UpdateWebSector()
{
	document.frmFeedback.elements['inpWebSector'].value = document.frmFeedback.elements['inpWebSectorID'].options[document.frmFeedback.elements['inpWebSectorID'].selectedIndex].text;
}


function DisplayEmail()
{ 
	if (document.frmFeedback.elements['IsLoggedIn'].value == '2')
	{
		document.frmFeedback.elements['inpCommunication'].value = document.frmFeedback.elements['inpCustomerEmail'].value;
		document.getElementById('ChosenValue').innerText = document.frmFeedback.elements['inpCustomerEmail'].value;
	}
}
	
function DisplayTelephone()
{
	if (document.frmFeedback.elements['IsLoggedIn'].value == '2')
	{ 
		document.frmFeedback.elements['inpCommunication'].value = document.frmFeedback.elements['inpCustTelephone'].value;
		document.getElementById('ChosenValue').innerText = document.frmFeedback.elements['inpCustTelephone'].value;
	}
}	
	
function DisplayFax()
{
	if (document.frmFeedback.elements['IsLoggedIn'].value == '2')
	{
		document.frmFeedback.elements['inpCommunication'].value = document.frmFeedback.elements['inpCustFax'].value;
		document.getElementById('ChosenValue').innerText = document.frmFeedback.elements['inpCustFax'].value;
	}
}


function EditCommunication()
{	
	if (document.frmFeedback.elements.inpReplyType['0'].checked == true)
	{
		document.frmCommunications.elements['inpCommType'].value = 'EMail';
		document.frmCommunications.elements['inpCommunicationID'].value = document.frmFeedback.elements['inpEmailCommunicationID'].value;
	}
	if (document.frmFeedback.elements.inpReplyType['1'].checked == true)
	{
		document.frmCommunications.elements['inpCommType'].value = 'Telephone';
		document.frmCommunications.elements['inpCommunicationID'].value = document.frmFeedback.elements['inpTelephoneCommunicationID'].value;
	}		
	if (document.frmFeedback.elements.inpReplyType['2'].checked == true)
	{
		document.frmCommunications.elements['inpCommunicationID'].value = document.frmFeedback.elements['inpFaxCommunicationID'].value;
		document.frmCommunications.elements['inpCommType'].value = 'Fax';
	}	
	if (document.frmFeedback.elements['inpCommunication'].value == '')
	{
		document.frmCommunications.elements['inpAction'].value = 'NEW'
	}
	else
	{
		document.frmCommunications.elements['inpAction'].value = 'EDIT'
	}
	
	document.frmCommunications.elements['inpCustFamMemID'].value = document.frmFeedback.elements['inpCustFamMemID'].value;
	document.frmCommunications.elements['Bounce_ChosenEmailTypeID'].value = document.frmFeedback.elements['inpVisibleEmailType'].options[document.frmFeedback.elements['inpVisibleEmailType'].selectedIndex].value;
	
	//If Web Sector Combo not displayed, get value from Hidden Input element instead.
	if (document.frmFeedback.elements['inpHaveAttribute'].value == '0')
	{
		document.frmCommunications.elements['Bounce_ChosenWebSectorID'].value = document.frmFeedback.elements['inpWebSectorID'].options[document.frmFeedback.elements['inpWebSectorID'].selectedIndex].value;
		document.frmCommunications.elements['Bounce_ChosenWebSector'].value = document.frmFeedback.elements['inpWebSectorID'].options[document.frmFeedback.elements['inpWebSectorID'].selectedIndex].text;
	}
	else
	{
		document.frmCommunications.elements['Bounce_ChosenWebSectorID'].value = document.frmFeedback.elements['inpWebSectorID'].value;
	}

	document.frmCommunications.elements['Bounce_ChosenComments'].value = document.frmFeedback.elements['inpFeedback'].value;
	
	if (document.frmFeedback.elements.inpReplyType['0'].checked == true)
	{
		document.frmCommunications.elements['Bounce_ChosenReplyType'].value = 'Email';
	}
	else
	{
		if (document.frmFeedback.elements.inpReplyType['1'].checked == true)
		{
			document.frmCommunications.elements['Bounce_ChosenReplyType'].value = 'Telephone';
		}
		else
		{
			if (document.frmFeedback.elements.inpReplyType['2'].checked == true)
			{
				document.frmCommunications.elements['Bounce_ChosenReplyType'].value = 'Fax';
			}
		}
	}
		
	if (document.frmFeedback.elements.inpReply['0'].checked == true)
	{
		document.frmCommunications.elements['Bounce_ChosenReply'].value = 'Yes';
	}
	else 
	{
		document.frmCommunications.elements['Bounce_ChosenReply'].value = 'No';
	}
	
	document.frmCommunications.elements['Bounce_ChosenJobTitle'].value = document.frmFeedback.elements['inpJobTitle'].value;
	document.frmCommunications.elements['Bounce_ChosenAddress'].value = document.frmFeedback.elements['inpAddress'].value;
	
	document.frmCommunications.submit();
}

function ToggleJobOrgDisplay()
{	
	var bIE = browserName == 'IE';
	if (document.frmFeedback.elements.inpCustType['2'].checked == true) 
	{
	document.getElementById('trJobTitle').style.display='none';
	document.getElementById('trJobTitle').style.visibility='hidden';	
	
	document.getElementById('trOrgName').style.display='none';
	document.getElementById('trOrgName').style.visibility='hidden';	
	}
	else
	{
		document.getElementById('trJobTitle').style.display='';
		document.getElementById('trJobTitle').style.visibility='';	
	
		document.getElementById('trOrgName').style.display='';
		document.getElementById('trOrgName').style.visibility='';
	}
	if (bIE && document.all.tdJobTitle)
					document.all.tdJobTitle.className = 'data1';
	if (bIE && document.all.tdEstablishment)
					document.all.tdEstablishment.className = 'data1';					
}


function VisibleEmailType()
{
	var selectedIndex = document.frmFeedback.elements['inpVisibleEmailType'].selectedIndex;				
	if ((document.frmFeedback.elements['inpVisibleEmailType'].options[selectedIndex].text == 'Product or Sales query' ||  document.frmFeedback.elements['inpEmailType'].value == 'Product or Sales query') && document.frmFeedback.inpDisplayRegion.value == 'true')
	{		
		document.getElementById('trRegion').style.display='';
		document.getElementById('trRegion').style.visibility='';
	}
	else
	{
		document.getElementById('trRegion').style.display='none';
		document.getElementById('trRegion').style.visibility='hidden';
		
	}
}