window.onload = standard_onload;

function standard_onload()
{
	if (document.getElementById) 
	{
		visionLogo = document.getElementById("visionlogo");
		if (visionLogo != null)
		{
			visionLogo.onclick = function() 
			{
				window.location = 'http://www.visionunderwriting.co.uk/index.php';
				return false;
			}
		}

		getRegisteredBox = document.getElementById("getregistered");
		if (getRegisteredBox != null)
		{
			getRegisteredBox.onclick = function() 
			{
				window.location = 'register.php';
			}
			getRegisteredBox.onmouseover = function() 
			{
				this.className = "over";
			}
			getRegisteredBox.onmouseout = function() 
			{
				this.className = "";
			}

			// Add favourites link on homepage
			if (window.external)
			{
				var newDiv = document.createElement('div');
				newDiv.setAttribute('id', 'favouriteDiv');
				var newImg = document.createElement('img');
				newImg.setAttribute('src', 'images/favourites.png');
				var newLink = document.createElement('a');
				newLink.setAttribute('href', '');
				newLink.setAttribute('title', 'Add Vision Online to your favourites');
				newLink.setAttribute('id', 'favouriteLink');
				var newText = document.createTextNode('Click here to add Vision Online to your favourites');
				var rightColumn = document.getElementById("rightcolumn");
				newLink.appendChild(newText);
				newDiv.appendChild(newImg);
				newDiv.appendChild(newLink);
				rightColumn.appendChild(newDiv);
				var newLink = document.getElementById("favouriteLink");
				newLink.onclick = function()
				{
					window.external.AddFavorite('http://www.visionunderwriting.co.uk', 'Vision Online');
					return false;
				}			
			}
		}

		menuUL = document.getElementById("menu");
		if (menuUL != null)
		{
			menuLinks = menuUL.getElementsByTagName("a");
			for (aIndex = 0; aIndex < menuLinks.length; aIndex++)
			{
				if (menuLinks[aIndex].className == 'insuresafe')
				{
					menuLinks[aIndex].onclick = function() 
					{
						if (!confirm("You are now leaving Vision Online to join Vision Insuresafe. Vision Insuresafe is an interactive Health & Safety web-site that is subject to an annual membership subscription. You are free to view the open features of the site although you will need to subscribe to be able to access most features. If you wish to know more, please contact Vision.")) return false;
					}
				}
			}
		}

		clientUL = document.getElementById("clientmenu");
		if (clientUL != null)
		{
			clientULlinks = clientUL.getElementsByTagName("a");
			for (aIndex = 0; aIndex < clientULlinks.length; aIndex++)
			{
				if (clientULlinks[aIndex].id == 'logout')
				{
					clientULlinks[aIndex].onclick = function() 
					{
						if (!confirm("Are you sure you wish to log out of the Vision Online system? If you click Ok you will be logged out and returned to the home page. Click Cancel to abort.")) return false;
					}
				}
			}
		}

		insurersBox = document.getElementById("insurers");
		if (insurersBox != null)
		{
			insurersBox.onclick = function() 
			{
				window.location = 'products_insurers.php';
			}
		}

		solicitorsBox = document.getElementById("solicitors");
		if (solicitorsBox != null)
		{
			solicitorsBox.onclick = function() 
			{
				window.location = 'products_solicitors.php';
			}
		}

		accountantsBox = document.getElementById("accountants");
		if (accountantsBox != null)
		{
			accountantsBox.onclick = function() 
			{
				window.location = 'products_accountants.php';
			}
		}
		
		printlink = document.getElementById("printinvoice");
		if (printlink != null)
		{
			if (printlink.className == 'backtooptions') printlink.innerHTML = '<a onclick="GoToPreviousPage(); return false;" href=""><img alt="Click here to return to the options page" src="../images/backbutton2.gif"></img></a><a onclick="window.print(); return false;" href=""><img alt="Click here to print the document" src="../images/printbutton2.gif"></img></a>';
			else printlink.innerHTML = '<a onclick="window.print(); return false;" href=""><img alt="Click here to print the document" src="../images/printbutton2.gif"></img></a>';
		}

		printlink = document.getElementById("printinvoice2");
		if (printlink != null)
		{
			if (printlink.className == 'backtooptions') printlink.innerHTML = '<a onclick="GoToPreviousPage(); return false;" href=""><img alt="Click here to return to the options page" src="../images/backbutton2.gif"></img></a><a onclick="window.print(); return false;" href=""><img alt="Click here to print the document" src="../images/printbutton2.gif"></img></a>';
			else printlink.innerHTML = '<a onclick="window.print(); return false;" href=""><img alt="Click here to print the document" src="../images/printbutton2.gif"></img></a>';
		}
		
		backlinkonly = document.getElementById("backonlylink");
		if (backlinkonly != null)
		{
			backlinkonly.innerHTML = '<a onclick="GoToPreviousPage(); return false;" href=""><img alt="Click here to return to the options page" src="../images/backbutton2.gif"></img></a>';		
		}
			
		confirmationSpan = document.getElementById("confirmationspan");
		if (confirmationSpan != null)
		{
			confirmationSpan.innerHTML =   '<a onclick="GoToPreviousPage(); return false;" href=""><img alt="Click here to return to the options page" src="../images/backbutton2.gif" style="display: inline"></img></a>'
										 + '<a onclick="window.print(); return false;" href=""><img alt="Click here to print the document" src="../images/printbutton2.gif" style="display: inline"></img></a>'
										 + '<a onclick="FinalConfirmationCheck(); return false;" href=""><img alt="Click here to submit your details to Vision and view the associated documents" src="../images/continuebutton2.gif" style="display: inline"></img></a>';
		}
		confirmationSpan = document.getElementById("confirmationtop");
		if (confirmationSpan != null)
		{
			confirmationSpan.innerHTML =   '<a onclick="GoToPreviousPage(); return false;" href=""><img alt="Click here to return to the options page" src="../images/backbutton2.gif" style="display: inline; margin: 0 10px 0 20px;"></img></a>'
										 + '<a onclick="window.print(); return false;" href=""><img alt="Click here to print the document" src="../images/printbutton2.gif" style="display: inline; margin: 0 10px;"></img></a>'
										 + '<a onclick="FinalConfirmationCheck(); return false;" href=""><img alt="Click here to submit your details to Vision and view the associated documents" src="../images/continuebutton2.gif" style="display: inline; margin: 0 10px;"></img></a>';
		}

		saveButtonSpan = document.getElementById("savequotespan");
		if (saveButtonSpan != null)
		{
			saveButtonSpan.innerHTML = '<a onclick="document.forms[\'savequoteform\'].submit(); return false;" href=""><img alt="Click here to save this quote" src="../images/savebutton2.gif" style="display: inline"></img></a>';
		}

		saveButtonSpan = document.getElementById("savecopyquotespan");
		if (saveButtonSpan != null)
		{
			saveButtonSpan.innerHTML = '<a onclick="document.forms[\'savecopyquoteform\'].submit(); return false;" href=""><img alt="Click here to save a copy of this quote" src="../images/savecopybutton2.gif" style="display: inline"></img></a>';
		}

		viewDocSpan = document.getElementById("viewdocspan");
		if (viewDocSpan != null)
		{
			viewDocSpan.innerHTML = '<a onclick="document.forms[\'empprotoptions\'].submit(); return false;" href=""><img alt="Click here to view the selected document" src="../images/viewdocbutton2.gif" style="display: inline"></img></a>';
		}

		viewDocSpan = document.getElementById("viewdocspantop");
		if (viewDocSpan != null)
		{
			viewDocSpan.innerHTML = '<a onclick="document.forms[\'empprotoptions\'].submit(); return false;" href=""><img alt="Click here to view the selected document" src="../images/viewdocbutton2.gif" style="display: inline"></img></a>';
		}

		// Show Graphical Submit/Reset Buttons
		aSubmitButtonSpan = document.getElementById("continuebtn");
		if (aSubmitButtonSpan != null)
		{
			aSubmitButtonSpan.innerHTML = '<a onclick="if ((document.forms[0].onsubmit == null) || (document.forms[0].onsubmit())) document.forms[0].submit(); return false;" href=""><img alt="Click here to continue" src="../images/continuebutton2.gif" style="display: inline"></img></a>';
		}

		aResetButtonSpan = document.getElementById("resetbtn");
		if (aResetButtonSpan != null)
		{
			aResetButtonSpan.innerHTML = '<a onclick="document.forms[0].reset(); return false;" href=""><img alt="Click here to clear the form" src="../images/clearbutton.gif" style="display: inline"></img></a>';
		}
		
		aBackButtonSpan = document.getElementById("backbtn");
		if (aBackButtonSpan != null)
		{
			aBackButtonSpan.innerHTML = '<a onclick="GoToPreviousPage(); return false;" href=""><img alt="Click here to go back" src="../images/backbutton2.gif" style="display: inline"></img></a>';
		}

		// Show Advice Buttons
		aAdviceSpan = document.getElementById("adviceactionprev");
		if (aAdviceSpan != null) aAdviceSpan.innerHTML = '<a onclick="window.; return false;" href=""><img alt="Click here to view the previous advice" src="../images/previousbutton2.gif" style="display: inline"></img></a>';

		// Clear Space from Textareas
		var aTextAreas = document.getElementsByTagName("textarea");
		for (var aIndex = 0; aIndex < aTextAreas.length; aIndex++) 
		{
			if (aTextAreas[aIndex].value == ' ' ) aTextAreas[aIndex].value = '';
		}

		// Hide EPP Claims Details
		claimsDiv = document.getElementById("claimsdetailsdiv");
		
		if (claimsDiv != null)
		{
			empDisputesYesRadio = document.getElementById('ProposerClaimsYes');
			empDisputesNoRadio = document.getElementById('ProposerClaimsNo');
			claimsDetailsYesRadio = document.getElementById('ProposerClaimsDetailsNow');
			claimsDetailsLaterRadio = document.getElementById('ProposerClaimsDetailsLater');
			proposerClaimsTextDiv = document.getElementById('claimsdetailstext');

			if (! empDisputesYesRadio.checked) claimsDiv.style.display = 'none';
			empDisputesYesRadio.onclick = function()
										  {
										  	document.getElementById("claimsdetailsdiv").style.display = 'inline'; 
											window.alert('In view of your claims experience, underwriters will review this proposal and the premium illustrated may change.');
										  }
			empDisputesNoRadio.onclick = function()
										 {
											document.getElementById('NumberOfClaims').value = '0'; 
											document.getElementById('claimsdetailsdiv').style.display = 'none'; 
											document.getElementById('ProposerClaimsDetailsNow').checked = false;
											document.getElementById('ProposerClaimsDetailsLater').checked = false;
										 }

			if (! claimsDetailsYesRadio.checked) proposerClaimsTextDiv.style.display = 'none';			
			claimsDetailsYesRadio.onclick = function(){document.getElementById("claimsdetailstext").style.display = 'inline'; }
			claimsDetailsLaterRadio.onclick = function()
										 {
											document.getElementById("claimsdetailstext").style.display = 'none'; ;
										 }

		}
	
		var adminFuncs = document.getElementById("adminfuncs");
		if (adminFuncs != null)
		{
			adminFuncs.innerHTML = ' <a id="adminlink" href="" onclick="ShowSection(this);return false;"><img src="../images/icons/zoomin.jpg" alt="Display" style="display: inline; margin: 0px; padding: 0 0 0 195px;"></img></a> <a href="" onclick="HideSection(this);return false;"><img src="../images/icons/zoomout.jpg" alt="Hide" style="display: inline; margin: 0 10px 0 15px; padding: 0px;"></img></a>';
			HideSection(document.getElementById("adminlink"));
		}

		var memberDetails = document.getElementById("memberdetails");
		if (memberDetails != null)
		{
			memberDetails.innerHTML = ' <a id="memberlink" href="" onclick="ShowSection(this);return false;"><img src="../images/icons/zoomin.jpg" alt="Hide" style="display: inline; margin: 0px; padding: 0 0 0 195px;"></img></a> <a href="" onclick="HideSection(this);return false;"><img src="../images/icons/zoomout.jpg" alt="Hide" style="display: inline; margin: 0 10px 0 15px; padding: 0px;"></img></a>';
			HideSection(document.getElementById("memberlink"));
		}

		var statusDetails = document.getElementById("statusdetails");
		if (statusDetails != null)
		{
			statusDetails.innerHTML = ' <a id="statuslink" href="" onclick="ShowSection(this);return false;"><img src="../images/icons/zoomin.jpg" alt="Hide" style="display: inline; margin: 0px; padding: 0 0 0 195px;"></img></a> <a href="" onclick="HideSection(this);return false;"><img src="../images/icons/zoomout.jpg" alt="Hide" style="display: inline; margin: 0 10px 0 15px; padding: 0px;"></img></a>';
			HideSection(document.getElementById("statuslink"));
		}
				
		jumpback = document.getElementById("jumpback");
		if (jumpback != null)
		{
			jumpback.innerHTML = '<p>If you wish to try a different configuration for this quote please <a onclick="JumpBackToEditForm(); return false;" href="">click here to return to the original form</a>.<p>';			
		}

		var aPopUpWindow = document.getElementById('popup');
		if (aPopUpWindow != null) aPopUpWindow.onclick = JSFnPopUpWindow;

		var aPopUpWideWindow = document.getElementById('popup_wide');
		if (aPopUpWideWindow != null) BatchPopUpWindow();
	}
}

function JSFnPopUpWindow()
{
	var aPopUpWindow = document.getElementById('popup');
	var aPopUpWideWindow = document.getElementById('popup_wide');
	
	if (aPopUpWindow != null) aWidth = '530px';
	else if (aPopUpWideWindow != null) aWidth = '750px';
	
	var aWindow = window.open(this.href, 'popup', 'scrollbars=yes, menubar=no, resizeable=no, toolbar=no, width=' + aWidth + ', height=580px')
	aWindow.focus();
	return false;
}

function BatchPopUpWindow()
{
	aLinks = document.getElementsByTagName("a");
	
	for (aIndex = 0; aIndex < aLinks.length; aIndex++) 
	{		
		aLinks[aIndex].onclick = JSFnPopUpWindow;
	}
}

function ShowSection(aLink)
{
	aInputs = aLink.parentNode.parentNode.parentNode.getElementsByTagName("input");
	for (aIndex = 0; aIndex < aInputs.length; aIndex++) 
	{
		if (aInputs[aIndex].className != 'checkbox') aInputs[aIndex].style.display = 'block';
		else aInputs[aIndex].style.display = 'inline';
	}
	aTextAreas = aLink.parentNode.parentNode.parentNode.getElementsByTagName("textarea");
	for (aIndex = 0; aIndex < aTextAreas.length; aIndex++) aTextAreas[aIndex].style.display = 'block';
	aLabels = aLink.parentNode.parentNode.parentNode.getElementsByTagName("label");
	for (aIndex = 0; aIndex < aLabels.length; aIndex++) aLabels[aIndex].style.display = 'block';
	aParagraphs = aLink.parentNode.parentNode.parentNode.getElementsByTagName("p");
	for (aIndex = 0; aIndex < aParagraphs.length; aIndex++) aParagraphs[aIndex].style.display = 'block';
	aULs = aLink.parentNode.parentNode.parentNode.getElementsByTagName("ul");
	for (aIndex = 0; aIndex < aULs.length; aIndex++) aULs[aIndex].style.display = 'block';
	aSelects = aLink.parentNode.parentNode.parentNode.getElementsByTagName("select");
	for (aIndex = 0; aIndex < aSelects.length; aIndex++) aSelects[aIndex].style.display = 'block';
	aTables = aLink.parentNode.parentNode.parentNode.getElementsByTagName("table");
	for (aIndex = 0; aIndex < aTables.length; aIndex++) aTables[aIndex].style.display = '';
	aDivs = aLink.parentNode.parentNode.parentNode.getElementsByTagName("div");
	for (aIndex = 0; aIndex < aDivs.length; aIndex++) aDivs[aIndex].style.display = '';
//	aStrongs = aLink.parentNode.parentNode.parentNode.getElementsByTagName("strong");
//	for (aIndex = 0; aIndex < aStrongs.length; aIndex++) aStrongs[aIndex].style.display = 'block';	
}

function HideSection(aLink)
{
	aInputs = aLink.parentNode.parentNode.parentNode.getElementsByTagName("input");
	for (aIndex = 0; aIndex < aInputs.length; aIndex++) aInputs[aIndex].style.display = 'none';
	aTextAreas = aLink.parentNode.parentNode.parentNode.getElementsByTagName("textarea");
	for (aIndex = 0; aIndex < aTextAreas.length; aIndex++) aTextAreas[aIndex].style.display = 'none';
	aLabels = aLink.parentNode.parentNode.parentNode.getElementsByTagName("label");
	for (aIndex = 0; aIndex < aLabels.length; aIndex++) aLabels[aIndex].style.display = 'none';
	aParagraphs = aLink.parentNode.parentNode.parentNode.getElementsByTagName("p");
	for (aIndex = 0; aIndex < aParagraphs.length; aIndex++) aParagraphs[aIndex].style.display = 'none';
	aULs = aLink.parentNode.parentNode.parentNode.getElementsByTagName("ul");
	for (aIndex = 0; aIndex < aULs.length; aIndex++) aULs[aIndex].style.display = 'none';
	aSelects = aLink.parentNode.parentNode.parentNode.getElementsByTagName("select");
	for (aIndex = 0; aIndex < aSelects.length; aIndex++) aSelects[aIndex].style.display = 'none';
	aTables = aLink.parentNode.parentNode.parentNode.getElementsByTagName("table");
	for (aIndex = 0; aIndex < aTables.length; aIndex++) aTables[aIndex].style.display = 'none';
	aDivs = aLink.parentNode.parentNode.parentNode.getElementsByTagName("div");
	for (aIndex = 0; aIndex < aDivs.length; aIndex++) aDivs[aIndex].style.display = 'none';
//	aStrongs = aLink.parentNode.parentNode.parentNode.getElementsByTagName("strong");
//	for (aIndex = 0; aIndex < aStrongs.length; aIndex++) aStrongs[aIndex].style.display = 'none';
}

function FinalConfirmationCheck()
{
	if (    (document.forms[0].id != 'eppconfirmationform')
		 && (document.forms[0].id != 'epsconfirmationform')
		 && (document.forms[0].id != 'doliabilityquoteconfirmation')
		 && (document.forms[0].id != 'piraterquoteconfirmation'))
	{
		if (confirm("Submitting this form will confirm the illustration request and inform Vision.  Do you wish to continue?"))
		{
			document.forms[0].submit();
		}
	}
	else document.forms[0].submit();
}

function GoToPreviousPage()
{
	var aPreviousPage = document.getElementById("previouspage");
	var aReturning = document.getElementById("returning");
	if (aPreviousPage != null)
	{
		if (aReturning != null) aReturning.value = 'true';
		document.forms[0].action = aPreviousPage.value;
		document.forms[0].submit();		
	}
	else history.go(-1);
}

function JumpBackToEditForm()
{
	aFormNumber = document.forms.length - 1;
	aApplicationPage = 'epsquoterequest' + document.getElementById("SchemeNbr").value + '.php';
	document.forms[aFormNumber].action = aApplicationPage;
	document.forms[aFormNumber].submit();
}