﻿// Functions for job editing
// May 2007 : Javascript
// Tim Surtell @ Clario

var PayAmountMaximumHadFocus

var arrStoredSpecialismsValue = new Array;
var arrStoredSpecialismsText = new Array;

//************************************************************************************************************
function SetupPage()
	{
	// Initialise variables
	PayAmountMaximumHadFocus = false;

	// Override OnClick events for finish buttons
	document.getElementById("btnFinish").onclick = ChangeStatus;
	if (document.getElementById("btnFinishAddNewJob"))
		{
		document.getElementById("btnFinishAddNewJob").onclick = ChangeStatus;
		}

	// Position tips
	if (tips.indexOf("A") != -1)
		{
		SetTipPosition("A", 10, -8);
		}
	if (tips.indexOf("B") != -1)
		{
		SetTipPosition('B', 10, -8);
		}
	if (tips.indexOf("C") != -1)
		{
		SetTipPosition('C', 10, -8);
		}
	if (tips.indexOf("D") != -1)
		{
		SetTipPosition('D', 10, -132);
		if (document.getElementById("chkExpandCollapseFilterQuestions").checked == true)
			{
			SetTipPosition('D', 10, -8);
			}
		}
	if (tips.indexOf("E") != -1)
		{
		SetTipPosition('E', 10, -132);
		if (document.getElementById("chkExpandCollapseFilterQuestions").checked == true)
			{
			SetTipPosition('E', 10, -8);
			}
		}
	if (tips.indexOf("F") != -1)
		{
		SetTipPosition('F', -90, -26);
		}
	if (tips.indexOf("G") != -1)
		{
		SetTipPosition('G', 5, -8);
		}
		
	// Contact Details
	if (document.getElementById("chkExpandCollapseContactDetails").checked == true)
		{
		document.getElementById("trContactDetails").style.display = "";
		}

	// Salary
	UpdateDisplay();

	// Specialisms
    StoreSpecialisms(document.getElementById("lstSpecialism1_lstSpecialisms"));
    SectorChanged(document.getElementById("lstSector1_lstSectors"));
    SectorChanged(document.getElementById("lstSector2_lstSectors"));

	// Filter Questions
	if (document.getElementById("chkExpandCollapseFilterQuestions").checked == false)
		{
		document.getElementById("trFilterQuestions").style.display = "none";
		}

	// Documents
	if (document.getElementById("chkExpandCollapseDocuments").checked == false)
		{
		document.getElementById("trDocuments").style.display = "none";
		}

	// Application Details
	if (document.getElementById("chkApplyViaWebsite").checked == true)
		{
		document.getElementById("trApplyViaWebsite").style.display = "";
		}
	if (document.getElementById("chkApplyByTelephone").checked == true)
		{
		document.getElementById("trApplyByTelephone").style.display = "";
		}
	if (document.getElementById("chkApplyByFax").checked == true)
		{
		document.getElementById("trApplyByFax").style.display = "";
		}
	if (document.getElementById("chkApplyByPost").checked == true)
		{
		document.getElementById("trApplyByPost").style.display = "";
		}
	
	// Set focus
	if (window.location.href.indexOf("#") == -1)
		{
		document.getElementById("txtTitle").focus();
		document.getElementById("txtTitle").select();
		}
	}
//************************************************************************************************************
function ChangeStatus()
	{
	// Show uploading status icon
	document.getElementById("imgFinishStatus").src = "Images/Icons/icon_status_uploading.gif";
	
	// Do usual ASP.Net validation
	if (typeof(Page_ClientValidate) == 'function') Page_ClientValidate();
	
	// If the page is invalid, hide uploading status icon
	if (Page_IsValid == false)
		{
		document.getElementById("imgFinishStatus").src = "Images/trans_pixel.gif";
		}
	}
//************************************************************************************************************
function ExpandCollapseContactDetails()
	{
	if (document.getElementById("chkExpandCollapseContactDetails").checked == true)
		{
		document.getElementById("trContactDetails").style.display = "";
		document.getElementById("txtContactForename").focus();
		document.getElementById("txtContactForename").select();	
		}
	else
		{
		document.getElementById("trContactDetails").style.display = "none";
		}
	}
//************************************************************************************************************
function ExpandCollapseFilterQuestions()
	{
	if (document.getElementById("chkExpandCollapseFilterQuestions").checked == true)
		{
		document.getElementById("trFilterQuestions").style.display = "";
		document.getElementById("repFiltersList__ctl0_txtQuestion").focus();
		document.getElementById("repFiltersList__ctl0_txtQuestion").select();	
		}
	else
		{
		document.getElementById("trFilterQuestions").style.display = "none";
		}
	}
//************************************************************************************************************
function ExpandCollapseDocuments()
	{
	if (document.getElementById("chkExpandCollapseDocuments").checked == true)
		{
		document.getElementById("trDocuments").style.display = "";
		document.getElementById("filNewDocumentFile").focus();
		document.getElementById("filNewDocumentFile").select();	
		}
	else
		{
		document.getElementById("trDocuments").style.display = "none";
		}
	}
//************************************************************************************************************
function ExpandCollapseApplyViaWebsite()
	{
	if (document.getElementById("chkApplyViaWebsite").checked == true)
		{
		document.getElementById("trApplyViaWebsite").style.display = "";
		if (document.getElementById("chkApplyByWebsite").checked == false)
			{
			document.getElementById("chkApplyByEmail").checked = true;
			}
		}
	else
		{
		document.getElementById("trApplyViaWebsite").style.display = "none";
		}
	}
//************************************************************************************************************
function ExpandCollapseApplyByTelephone()
	{
	if (document.getElementById("chkApplyByTelephone").checked == true)
		{
		document.getElementById("trApplyByTelephone").style.display = "";
		document.getElementById("txtApplicationTelephone").focus();
		document.getElementById("txtApplicationTelephone").select();	
		}
	else
		{
		document.getElementById("trApplyByTelephone").style.display = "none";
		}
	}
//************************************************************************************************************
function ExpandCollapseApplyByFax()
	{
	if (document.getElementById("chkApplyByFax").checked == true)
		{
		document.getElementById("trApplyByFax").style.display = "";
		document.getElementById("txtApplicationFax").focus();
		document.getElementById("txtApplicationFax").select();	
		}
	else
		{
		document.getElementById("trApplyByFax").style.display = "none";
		}
	}
//************************************************************************************************************
function ExpandCollapseApplyByPost()
	{
	if (document.getElementById("chkApplyByPost").checked == true)
		{
		document.getElementById("trApplyByPost").style.display = "";
		document.getElementById("txtApplicationForename").focus();
		document.getElementById("txtApplicationForename").select();	
		}
	else
		{
		document.getElementById("trApplyByPost").style.display = "none";
		}
	}
//************************************************************************************************************
function ClientUserChanged(ClientUser)
	{
	if (ClientUser[ClientUser.selectedIndex].value == 0)
		{
		// Clear details
		document.getElementById("txtContactForename").value = "";
		document.getElementById("txtContactSurname").value = "";
		document.getElementById("txtContactTelephone").value = "";
		document.getElementById("txtContactFax").value = "";
		document.getElementById("txtContactEmailAddress").value = "";
		document.getElementById("lstContactDetailsDomain_lstDomains").selectedIndex = 0;
		document.getElementById("chkHideName").checked = false;
		document.getElementById("chkHideTelephone").checked = false;
		document.getElementById("chkHideFax").checked = false;
		document.getElementById("txtReferencePrefix").value = "";
		document.getElementById("hdnReferencePrefix").value = "";
		document.getElementById("spnJobsExpireAfter").innerText = "?";

		document.getElementById("txtApplicationEmailAddress").value = "";
		document.getElementById("lstApplicationDetailsDomain_lstDomains").selectedIndex = 0;
		document.getElementById("txtApplicationTelephone").value = "";
		document.getElementById("txtApplicationFax").value = "";
		document.getElementById("txtApplicationForename").value = "";
		document.getElementById("txtApplicationSurname").value = "";
		document.getElementById("txtApplicationAddress1").value = "";
		document.getElementById("txtApplicationAddress2").value = "";
		document.getElementById("txtApplicationAddressCity").value = "";
		document.getElementById("txtApplicationAddressPostcode").value = "";
		}
	else
		{
		var xmlHttp;
			
		// Instantiate a XMLHttpRequest object
		try
			{
			// Firefox, Opera 8.0+, Safari
			xmlHttp = new XMLHttpRequest();
			}
		catch (e)
			{
			// Internet Explorer
			try
				{
				xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
				}
			catch (e)
				{
				try
					{
					xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
					}
				catch (e)
					{
					alert("Your browser does not support AJAX!");
					}
				}
			}
			
		// Create a function to respond to XMLHttpRequest state changes
		xmlHttp.onreadystatechange = function()
			{
			if(xmlHttp.readyState == 4)
				{
				// Populate details by splitting returned data on new line character
				var ReturnedFields = xmlHttp.responseText.split("\n");
				
				// Contact Details
				document.getElementById("txtContactForename").value = ReturnedFields[0];
				document.getElementById("txtContactSurname").value = ReturnedFields[1];
				document.getElementById("txtContactTelephone").value = ReturnedFields[2];
				document.getElementById("txtContactFax").value = ReturnedFields[3];
				document.getElementById("txtContactEmailAddress").value = ReturnedFields[4];

				// Contact Email Address
				document.getElementById("lstContactDetailsDomain_lstDomains").selectedIndex = 0;
				for (var LoopCounter = 0; LoopCounter < document.getElementById("lstContactDetailsDomain_lstDomains").length; LoopCounter++)
					{
					if (ReturnedFields[5] == document.getElementById("lstContactDetailsDomain_lstDomains")[LoopCounter].value)
						{
						document.getElementById("lstContactDetailsDomain_lstDomains").selectedIndex = LoopCounter;
						}
					}
				
				// 'Hide' checkboxes
				if (ReturnedFields[6] == "True")
					{
					document.getElementById("chkHideName").checked = true;
					}
				else
					{
					document.getElementById("chkHideName").checked = false;
					}
				if (ReturnedFields[7] == "True")
					{
					document.getElementById("chkHideTelephone").checked = true;
					}
				else
					{
					document.getElementById("chkHideTelephone").checked = false;
					}
				if (ReturnedFields[8] == "True")
					{
					document.getElementById("chkHideFax").checked = true;
					}
				else
					{
					document.getElementById("chkHideFax").checked = false;
					}
							
				// Job Details
				document.getElementById("txtReferencePrefix").value = ReturnedFields[9];
				document.getElementById("hdnReferencePrefix").value = ReturnedFields[9];

				// Jobs Expire After
				document.getElementById("spnJobsExpireAfter").innerText = ReturnedFields[10];
				
				// Application Details
				document.getElementById("txtApplicationEmailAddress").value = ReturnedFields[4];
				document.getElementById("txtApplicationTelephone").value = ReturnedFields[2];
				document.getElementById("txtApplicationFax").value = ReturnedFields[3];
				document.getElementById("txtApplicationForename").value = ReturnedFields[0];
				document.getElementById("txtApplicationSurname").value = ReturnedFields[1];
				document.getElementById("txtApplicationAddress1").value = ReturnedFields[11];
				document.getElementById("txtApplicationAddress2").value = ReturnedFields[12];
				document.getElementById("txtApplicationAddressCity").value = ReturnedFields[13];
				document.getElementById("txtApplicationAddressPostcode").value = ReturnedFields[14];
				
				// Application Email Address
				document.getElementById("lstApplicationDetailsDomain_lstDomains").selectedIndex = 0;
				for (var LoopCounter = 0; LoopCounter < document.getElementById("lstApplicationDetailsDomain_lstDomains").length; LoopCounter++)
					{
					if (ReturnedFields[5] == document.getElementById("lstApplicationDetailsDomain_lstDomains")[LoopCounter].value)
						{
						document.getElementById("lstApplicationDetailsDomain_lstDomains").selectedIndex = LoopCounter;
						}
					}
				}
			}

			// Send request using XMLHttpRequest
			xmlHttp.open("GET", ajaxPath + "/get_clientuser_ajax.aspx?ClientUserID=" + ClientUser[ClientUser.selectedIndex].value, true);
			xmlHttp.send(null);
		}
	}
//************************************************************************************************************
function ContactForenameChanged()
	{
	document.getElementById("txtApplicationForename").value = document.getElementById("txtContactForename").value;
	}
//************************************************************************************************************
function ContactSurnameChanged()
	{
	document.getElementById("txtApplicationSurname").value = document.getElementById("txtContactSurname").value;
	}
//************************************************************************************************************
function ContactTelephoneChanged()
	{
	document.getElementById("txtApplicationTelephone").value = document.getElementById("txtContactTelephone").value;
	}
//************************************************************************************************************
function ContactFaxChanged()
	{
	document.getElementById("txtApplicationFax").value = document.getElementById("txtContactFax").value;
	}
//************************************************************************************************************
function ContactEmailAddressChanged()
	{
	document.getElementById("txtApplicationEmailAddress").value = document.getElementById("txtContactEmailAddress").value;
	}
//************************************************************************************************************
function DomainChanged(Domain)
	{
	if (Domain.id == "lstContactDetailsDomain_lstDomains")
		{
		// In Contact Details
		document.getElementById("lstApplicationDetailsDomain_lstDomains").selectedIndex = 0;
		for (var LoopCounter = 0; LoopCounter < document.getElementById("lstApplicationDetailsDomain_lstDomains").length; LoopCounter++)
			{
			if (Domain[Domain.selectedIndex].value == document.getElementById("lstApplicationDetailsDomain_lstDomains")[LoopCounter].value)
				{
				document.getElementById("lstApplicationDetailsDomain_lstDomains").selectedIndex = LoopCounter;
				}
			}
		}
	else
		{
		// In Application Details
		ApplicationEmailAddressChanged();
		}
	}
//************************************************************************************************************
function StoreSpecialisms(Specialisms) {
	for (intLoopCounter = 1; intLoopCounter < Specialisms.length; intLoopCounter++) {
	    arrStoredSpecialismsValue[intLoopCounter] = Specialisms.options[intLoopCounter].value;
	    arrStoredSpecialismsText[intLoopCounter] = Specialisms.options[intLoopCounter].text;
	}
}
//************************************************************************************************************
function SectorChanged(Sector) {
    if (Sector.id == "lstSector1_lstSectors") {
        var Specialisms = document.getElementById("lstSpecialism1_lstSpecialisms");
    }
    else {
        var Specialisms = document.getElementById("lstSpecialism2_lstSpecialisms");
    }

	var CurrentlySelectedSpecialism = Specialisms.value;

	// Clear list, except for prompt text
	do {
	    Specialisms.remove(1);
	}
	while (Specialisms.length > 1)

	// Add back only those specialisms in the selected sector
	for (intLoopCounter = 1; intLoopCounter < arrStoredSpecialismsValue.length; intLoopCounter++) {
	    if (arrStoredSpecialismsValue[intLoopCounter].substr(0, 1) == Sector.value) {
	        Specialisms.options[Specialisms.length] = new Option(arrStoredSpecialismsText[intLoopCounter], arrStoredSpecialismsValue[intLoopCounter]);
	        if (CurrentlySelectedSpecialism == arrStoredSpecialismsValue[intLoopCounter]) {
	            Specialisms.value = CurrentlySelectedSpecialism;
	        }
	    }
	}
}
//************************************************************************************************************
function SpecialismChanged(Specialism)
	{
	// Do nothing
	}
//************************************************************************************************************
function PayAmountMinimumChanged()
	{
	// If the maximum pay has not been in focus, copy minimum pay to maximum pay
	if (PayAmountMaximumHadFocus == false)
		{
		document.getElementById("txtPayAmountMaximum").value = FormatAsCurrency(document.getElementById("txtPayAmountMinimum").value);
		}

	UpdatePayPeriod();
	}
//************************************************************************************************************
function PayAmountMaximumChanged()
	{
	UpdatePayPeriod();
	}
//************************************************************************************************************
function PayAmountMinimumGotFocus()
	{
	document.getElementById("txtPayAmountMinimum").select();
}
//************************************************************************************************************
function PayAmountMaximumGotFocus()
	{
	PayAmountMaximumHadFocus = true;
	
	document.getElementById("txtPayAmountMaximum").select();
	}
//************************************************************************************************************
function PayAmountMinimumLostFocus()
	{
	document.getElementById("txtPayAmountMinimum").value = document.getElementById("txtPayAmountMinimum").value.toString().replace('k', '000');
	document.getElementById("txtPayAmountMinimum").value = document.getElementById("txtPayAmountMinimum").value.toString().replace(/[^0-9.]/g, '');

	document.getElementById("txtPayAmountMinimum").value = FormatAsCurrency(document.getElementById("txtPayAmountMinimum").value);

	// Make sure minimum is lower than maximum
	if (document.getElementById("txtPayAmountMinimum").value != "" && ConvertToNumber(document.getElementById("txtPayAmountMinimum").value) > ConvertToNumber(document.getElementById("txtPayAmountMaximum").value))
		{
		document.getElementById("txtPayAmountMaximum").value = document.getElementById("txtPayAmountMinimum").value;
		}

	UpdatePayPeriod();
	}
//************************************************************************************************************
function PayAmountMaximumLostFocus()
	{
	document.getElementById("txtPayAmountMaximum").value = document.getElementById("txtPayAmountMaximum").value.toString().replace('k', '000');
	document.getElementById("txtPayAmountMaximum").value = document.getElementById("txtPayAmountMaximum").value.toString().replace(/[^0-9.]/g, '');

	document.getElementById("txtPayAmountMaximum").value = FormatAsCurrency(document.getElementById("txtPayAmountMaximum").value);

	// Make sure minimum is lower than maximum
	if (document.getElementById("txtPayAmountMaximum").value != "" && ConvertToNumber(document.getElementById("txtPayAmountMinimum").value) > ConvertToNumber(document.getElementById("txtPayAmountMaximum").value))
		{
		document.getElementById("txtPayAmountMinimum").value = document.getElementById("txtPayAmountMaximum").value;
		}

	UpdatePayPeriod();
	}
//************************************************************************************************************
function UpdatePayPeriod()
	{
	var payAmountPerAnnum
	
	payAmountPerAnnum = ConvertToNumber(document.getElementById("txtPayAmountMaximum").value)

	if (payAmountPerAnnum == 0)
		{
		payAmountPerAnnum = ConvertToNumber(document.getElementById("txtPayAmountMinimum").value)
		}

	if (payAmountPerAnnum == 0)
		{
		UpdateNotes();		
		return;
		}
	
	// Pre-select pay period
	if (payAmountPerAnnum <= 50)
		{
		document.getElementById("lstPayPeriod").selectedIndex = 1; // Per hour
		}
	else
		{
		if (payAmountPerAnnum <= 375)
			{
			document.getElementById("lstPayPeriod").selectedIndex = 2; // Per day
			}
		else
			{
			if (payAmountPerAnnum <= 1875)
				{
				document.getElementById("lstPayPeriod").selectedIndex = 3; // Per week
				}
			else
				{
				if (payAmountPerAnnum <= 7500)
					{
					document.getElementById("lstPayPeriod").selectedIndex = 4; // Per month
					}
				else
					{
					document.getElementById("lstPayPeriod").selectedIndex = 5; // Per year
					}
				}
			}
		}
	
	UpdateNotes();		
}
//************************************************************************************************************
function UpdateNotes()
	{
	if (document.getElementById("chkPayAmountIsHidden").checked == true && document.getElementById("txtPayNotes").value == "")
		{
		document.getElementById("txtPayNotes").value = "Competitive";
		}
	UpdateDisplay();
	}
//************************************************************************************************************
function UpdateDisplay()
	{
	var payAmountMin, payAmountMax
	var displayHTML
	
	payAmountMin = ConvertToNumber(document.getElementById("txtPayAmountMinimum").value)
	payAmountMax = ConvertToNumber(document.getElementById("txtPayAmountMaximum").value)

	// Default to blank
	displayHTML = "<br>&nbsp;";
	document.getElementById("spnDisplay").innerHTML = displayHTML;

	// If both values are blank, or IsHidden is true, just show notes
	if ((payAmountMin == 0 && payAmountMax == 0) || document.getElementById("chkPayAmountIsHidden").checked == true)
		{
		if (document.getElementById("txtPayNotes").value != "")
			{
			document.getElementById("spnDisplay").innerHTML = "This will display as:<br><b>" + document.getElementById("txtPayNotes").value + "</b>";
			}
		return;
		}
	
	// If both values are entered, show both values and notes
	if (payAmountMin > 0 && payAmountMax > 0)
		{
		if (payAmountMin != payAmountMax)
			{
			displayHTML = "This will display as:<br><b>" + "£" + FormatAsCurrency(payAmountMin) + " - £" + FormatAsCurrency(payAmountMax);
			}
		else
			{
			displayHTML = "This will display as:<br><b>" + "£" + FormatAsCurrency(payAmountMin);
			}
			
		//Add pay period and notes
		switch(document.getElementById("lstPayPeriod").selectedIndex)
			{
			case 1:
				displayHTML = displayHTML + " ph " + document.getElementById("txtPayNotes").value + "</b>";
				break;
			case 2:
				displayHTML = displayHTML + " pd " + document.getElementById("txtPayNotes").value + "</b>";
				break;
			case 3:
				displayHTML = displayHTML + " pw " + document.getElementById("txtPayNotes").value + "</b>";
				break;
			case 4:
				displayHTML = displayHTML + " pm " + document.getElementById("txtPayNotes").value + "</b>";
				break;
			case 5:
				displayHTML = displayHTML + " pa " + document.getElementById("txtPayNotes").value + "</b>";
				break;
			default:
				displayHTML = "<br>&nbsp;";
			}
	 	document.getElementById("spnDisplay").innerHTML = displayHTML;
		return;
		}

	// Show one or the other, plus notes
	if (payAmountMin == 0)
		{
		displayHTML = "This will display as:<br><b>" + "Up to £" + FormatAsCurrency(payAmountMax);
		}
	else
		{
		displayHTML = "This will display as:<br><b>" + "£" + FormatAsCurrency(payAmountMin) + "+";
		}

	//Add pay period and notes
	switch(document.getElementById("lstPayPeriod").selectedIndex)
		{
		case 1:
			displayHTML = displayHTML + " ph " + document.getElementById("txtPayNotes").value + "</b>";
			break;
		case 2:
			displayHTML = displayHTML + " pd " + document.getElementById("txtPayNotes").value + "</b>";
			break;
		case 3:
			displayHTML = displayHTML + " pw " + document.getElementById("txtPayNotes").value + "</b>";
			break;
		case 4:
			displayHTML = displayHTML + " pm " + document.getElementById("txtPayNotes").value + "</b>";
			break;
		case 5:
			displayHTML = displayHTML + " pa " + document.getElementById("txtPayNotes").value + "</b>";
			break;
		default:
			displayHTML = "<br>&nbsp;";
		}

 	document.getElementById("spnDisplay").innerHTML = displayHTML;
	}
//************************************************************************************************************
function SpecialismChanged(Specialism)
	{
	// Do nothing
	}
//************************************************************************************************************
function AreaChanged(Area)
	{
	// Do nothing
	}
//************************************************************************************************************
function FilterChanged(Filter)
	{
	Filter.checked = true;
	}
//************************************************************************************************************
function ApplicationEmailAddressChanged()
	{
	document.getElementById("chkApplyByEmail").checked = true;
	}
//************************************************************************************************************
function ApplicationURLChanged()
	{
	document.getElementById("chkApplyByWebsite").checked = true;
	}
//************************************************************************************************************
function ValidateApplicationDetails(sender, args)
	{
	if (document.getElementById("chkApplyViaWebsite").checked == false && document.getElementById("chkApplyByTelephone").checked == false && document.getElementById("chkApplyByFax").checked == false && document.getElementById("chkApplyByPost").checked == false)
		{
		args.IsValid = false;
		}
	else
		{
		args.IsValid = true;
		}
	}
//************************************************************************************************************
function ValidateContactEmailAddressLength(sender, args)
	{
	if (document.getElementById("txtContactEmailAddress").value.length + document.getElementById("lstContactDetailsDomain_lstDomains")[document.getElementById("lstContactDetailsDomain_lstDomains").selectedIndex].value.length > 255)
		{
		args.IsValid = false;
		}
	else
		{
		args.IsValid = true;
		}
	}
//************************************************************************************************************
function ValidateContactEmailAddressFormat(sender, args)
	{
	if (document.getElementById("txtContactEmailAddress").value.indexOf("@") != -1)
		{
		args.IsValid = false;
		}
	else
		{
		args.IsValid = true;
		}
	}
//************************************************************************************************************
function ValidateApplicationEmailAddressLength(sender, args)
	{
	if (document.getElementById("chkApplyViaWebsite").checked == true && document.getElementById("chkApplyByEmail").checked == true)
		{
		if (document.getElementById("txtApplicationEmailAddress").value.length + document.getElementById("lstApplicationDetailsDomain_lstDomains")[document.getElementById("lstApplicationDetailsDomain_lstDomains").selectedIndex].value.length > 255)
			{
			args.IsValid = false;
			}
		else
			{
			args.IsValid = true;
			}
		}
	else
		{
		args.IsValid = true;
		}
	}
//************************************************************************************************************
function ValidateApplicationEmailAddressFormat(sender, args)
	{
	if (document.getElementById("chkApplyViaWebsite").checked == true && document.getElementById("chkApplyByEmail").checked == true)
		{
		if (document.getElementById("txtApplicationEmailAddress").value.indexOf("@") != -1)
			{
			args.IsValid = false;
			}
		else
			{
			args.IsValid = true;
			}
		}
	else
		{
		args.IsValid = true;
		}
	}
//************************************************************************************************************
function ValidateApplicationDetailsDomain(sender, args)
	{
	if (document.getElementById("chkApplyViaWebsite").checked == true && document.getElementById("chkApplyByEmail").checked == true)
		{
		if (document.getElementById("lstApplicationDetailsDomain_lstDomains")[document.getElementById("lstApplicationDetailsDomain_lstDomains").selectedIndex].value.length = 0)
			{
			args.IsValid = false;
			}
		else
			{
			args.IsValid = true;
			}
		}
	else
		{
		args.IsValid = true;
		}
	}
//************************************************************************************************************
function ValidateApplicationURLLength(sender, args)
	{
	if (document.getElementById("chkApplyViaWebsite").checked == true && document.getElementById("chkApplyByWebsite").checked == true)
		{
		if (document.getElementById("txtApplicationURL").value.length > 255)
			{
			args.IsValid = false;
			}
		else
			{
			args.IsValid = true;
			}
		}
	else
		{
		args.IsValid = true;
		}
	}
//************************************************************************************************************
function ValidateApplicationTelephone(sender, args)
	{
	if (document.getElementById("chkApplyByTelephone").checked == true)
		{
		if (document.getElementById("txtApplicationTelephone").value.length > 25)
			{
			args.IsValid = false;
			}
		else
			{
			args.IsValid = true;
			}
		}
	else
		{
		args.IsValid = true;
		}
	}
//************************************************************************************************************
function ValidateApplicationFax(sender, args)
	{
	if (document.getElementById("chkApplyByFax").checked == true)
		{
		if (document.getElementById("txtApplicationFax").value.length > 25)
			{
			args.IsValid = false;
			}
		else
			{
			args.IsValid = true;
			}
		}
	else
		{
		args.IsValid = true;
		}
	}
//************************************************************************************************************
function ValidateApplicationForename(sender, args)
	{
	if (document.getElementById("chkApplyByPost").checked == true)
		{
		if (document.getElementById("txtApplicationForename").value.length > 25)
			{
			args.IsValid = false;
			}
		else
			{
			args.IsValid = true;
			}
		}
	else
		{
		args.IsValid = true;
		}
	}
//************************************************************************************************************
function ValidateApplicationSurname(sender, args)
	{
	if (document.getElementById("chkApplyByPost").checked == true)
		{
		if (document.getElementById("txtApplicationSurname").value.length > 25)
			{
			args.IsValid = false;
			}
		else
			{
			args.IsValid = true;
			}
		}
	else
		{
		args.IsValid = true;
		}
	}
//************************************************************************************************************
function ValidateApplicationAddress1(sender, args)
	{
	if (document.getElementById("chkApplyByPost").checked == true)
		{
		if (document.getElementById("txtApplicationAddress1").value.length > 50)
			{
			args.IsValid = false;
			}
		else
			{
			args.IsValid = true;
			}
		}
	else
		{
		args.IsValid = true;
		}
	}
//************************************************************************************************************
function ValidateApplicationAddressCity(sender, args)
	{
	if (document.getElementById("chkApplyByPost").checked == true)
		{
		if (document.getElementById("txtApplicationAddressCity").value.length > 25)
			{
			args.IsValid = false;
			}
		else
			{
			args.IsValid = true;
			}
		}
	else
		{
		args.IsValid = true;
		}
	}
//************************************************************************************************************
function ValidateApplicationAddressPostcode(sender, args)
	{
	if (document.getElementById("chkApplyByPost").checked == true)
		{
		if (document.getElementById("txtApplicationAddressPostcode").value.length < 6 || document.getElementById("txtApplicationAddressPostcode").value.length > 8)
			{
			args.IsValid = false;
			}
		else
			{
			args.IsValid = true;
			}
		}
	else
		{
		args.IsValid = true;
		}
	}
