var sContactInfo;
var strErrorMsg= "An error occurred while fetching contact details. Please select other option.";

function GetContactDetails() {
var objAll = document.all;
  var sHTML='';
	sHTML = "<div style='width:550px;'>" + sHTML;
	if(sOptSel == "Gen")
		sHTML+=getGenContactDetails('customerqueries');
	//for Members and Employers
	else if(sOptSel == "Pol") {
		sHTML+=drawContactDetails(objAll("SelPolicy").value);
	}
	//for IFA's and others
	else if( sOptSel == "PolSel") {
		if (trim(objAll("txtPolRef").value) == "")	{
			alert("Policy Number is empty. Please enter a valid number.");
			objAll("txtPolRef").focus();
		} else if ( checkInt(objAll("txtPolRef").value,8) == -1) {
			objAll("txtPolRef").focus();
		} else {
			sTemp="?Type=POL&Ref="+ objAll("txtPolRef").value;
			GetDetails(sTemp);
			if (sContactInfo != "false" && sContactInfo != "Invalid Number")
				sHTML+=drawContactDetails("Policy~"+sContactInfo);
			else {
				if (sContactInfo == "false")
					alert(strErrorMsg);
				if (sContactInfo == "Invalid Number")
					alert("An invalid policy number has been entered. Please enter a valid number.");
			}
		}
	}
	else if(sOptSel == "SPol" ||sOptSel == "SchSel") {
		if (trim(objAll("txtSchRef").value) == "")	{
			alert("Scheme Number is empty. Please enter a valid number.");
			objAll("txtSchRef").focus();
		} else if ( checkInt(objAll("txtSchRef").value,8) == -1) {
			objAll("txtSchRef").focus();
		} else {
			sTemp="?Type="+objAll("SelSchCat").value+"&Ref="+ objAll("txtSchRef").value;
			GetDetails(sTemp);
			if (sContactInfo != "false" && sContactInfo != "Invalid Number")
				sHTML+=drawContactDetails("Scheme~"+sContactInfo);
			else {
				if (sContactInfo == "false")
					alert(strErrorMsg);
				if (sContactInfo == "Invalid Number")
					alert("An invalid scheme number has been entered. Please enter a valid number.");
			}
		}
	}
	else if(sOptSel == "Web") {
		sHTML+=getWebContactDetails('eface');
	}
	else if(sOptSel == "IFANB") {
		sHTML+=getIFAContactDetails('ppu');
	}
	else {
		alert('Please select an option');
		sHTML="";
	}		
	if (sHTML != "<div style='width:550px;'>")
		document.all["disDetails"].innerHTML = sHTML + '</div>';
	else
		document.all["disDetails"].innerHTML = "";
}

function GetDetails(sArgument){
	try { 
	    var xmlContDet = new ActiveXObject("Microsoft.XMLHTTP");
		sContactInfo="";
	    xmlContDet.Open("GET", "/EServiceCMS/getContactDetails.asp"+sArgument, false);
	    xmlContDet.Send();
	    sContactInfo = xmlContDet.responseText;
//		alert("MF Output: " + sContactInfo);
	   	delete xmlContDet;
	}
	catch(e){
		alert("Sorry, Your system has no supporting XMLhttp component");
		sContactInfo = false;
	}
}
	
function nextPage()	{
	history.back(1);
}

function document_onkeypress()
{
	if(event.keyCode == 13)	{
		event.keyCode = 0;
		GetContactDetails();
	}
}

function hideoption(opt)
{
	var objAll=document.all;
	if(opt == "SchSel" || opt == "SPol")
	{
		if (opt == "SPol")
			objAll("optITR")[0].checked = true;
		objAll("SchemeInput").style.display="block";
		objAll.txtSchRef.focus();
		objAll("PolInput").style.display="none";
		objAll("txtPolRef").value="";
	}
	else if (opt == "PolSel")
	{
		objAll("PolInput").style.display="block";
		objAll.txtPolRef.focus();
		objAll("SchemeInput").style.display="none";
		objAll("txtSchRef").value="";
	}
	document.all["disDetails"].innerHTML = "";
}	

var sOptSel="Gen";
function setOption(sDetType) {
	var objAll=document.all;
	sOptSel=sDetType;
	if (objAll("SchPolInput")) {
		if ( sOptSel == "SPol") 
			objAll("SchPolInput").style.display="block";
		else
			objAll("SchPolInput").style.display="none";
	}
	if (objAll("AvlPolicy")) {
		if ( sOptSel == "Pol") 
			objAll("AvlPolicy").style.display="block";
		else
			objAll("AvlPolicy").style.display="none";
	}
	document.all["disDetails"].innerHTML = "";
	return;
}

function getGenContactDetails(sEmailPrefix) {
  var sGenHTML='';
  var sSLIHTML='';
	sGenHTML='<table cellspacing=0 cellpadding=0 border=0 width=100%>';
	sGenHTML= sGenHTML + '<thead><tr>';
	sGenHTML= sGenHTML + '	<th scope=col colspan=2>The contact details for Scottish Life are:</th>';
	sGenHTML= sGenHTML + '</tr></thead>';
	sGenHTML= sGenHTML + '<tbody><tr>';
	sGenHTML= sGenHTML + '	<th scope=row id=ContactUsFldName valign=top><p>Email</p></th>';
	sGenHTML= sGenHTML + '	<td id=ContactUsFldValue valign=top><span id="Contactemail"><a href="mailto:'+sEmailPrefix+'@scottishlife.co.uk"><p align=left>'+sEmailPrefix+'@scottishlife.co.uk<p></a></span></td>';
	sGenHTML= sGenHTML + '</tr>';
	sGenHTML= sGenHTML + '<tr>';
	sGenHTML= sGenHTML + '	<th scope=row id=ContactUsFldName valign=top><p>Telephone Number</p></th>';
	sGenHTML= sGenHTML + '	<td id=ContactUsFldValue valign=top><p align=left>0870 606 2000';
	sGenHTML= sGenHTML + '	<br>(8.00am to 6.00pm Mon - Thurs and 8.00am to 5.00pm on Friday)</p>';
	sGenHTML= sGenHTML + '	</td>';
	sGenHTML= sGenHTML + '</tr>';
	sGenHTML= sGenHTML + drawPostAddress('');
	sGenHTML= sGenHTML + '</tbody>';
	sSLIHTML= sSLIHTML + getSLIContactDetails('enquiries');
	return sGenHTML + sSLIHTML + '</table>';
}

function getWebContactDetails(sEmailPrefix) {
  var sGenHTML='';
	sGenHTML='<table cellspacing=0 cellpadding=0 border=0 width=100%>';
	sGenHTML= sGenHTML + '<thead><tr>';
	sGenHTML= sGenHTML + '	<th scope=col colspan=2>The contact details are:</th>';
	sGenHTML= sGenHTML + '</tr></thead>';
	sGenHTML= sGenHTML + '<tbody><tr>';
	sGenHTML= sGenHTML + '	<th scope=row id=ContactUsFldName valign=top><p>Email</p></th>';
	sGenHTML= sGenHTML + '	<td id=ContactUsFldValue valign=top><span id="Contactemail"><a href="mailto:'+sEmailPrefix+'@scottishlife.co.uk"><p align=left>'+sEmailPrefix+'@scottishlife.co.uk<p></a></span></td>';
	sGenHTML= sGenHTML + '</tr>';
	sGenHTML= sGenHTML + '<tr>';
	sGenHTML= sGenHTML + '	<th scope=row id=ContactUsFldName valign=top><p>Telephone Number</p></th>';
	sGenHTML= sGenHTML + '	<td id=ContactUsFldValue valign=top><p align=left>0845 60 50 40 1';
	sGenHTML= sGenHTML + '	<br>(8.00am to 6.00pm Mon - Thurs and 8.00am to 5.00pm on Friday)</p>';
	sGenHTML= sGenHTML + '	</td>';
	sGenHTML= sGenHTML + '</tr>';
	sGenHTML= sGenHTML + '<tr>';
	sGenHTML= sGenHTML + '	<th scope=row id=ContactUsFldName valign=top><p>International Telephone Number</p></th>';
	sGenHTML= sGenHTML + '	<td id=ContactUsFldValue valign=top><p align=left>+44 131 456 7575';
	sGenHTML= sGenHTML + '	</td>';
	sGenHTML= sGenHTML + '</tr>';
	sGenHTML= sGenHTML + drawPostAddress('');
	sGenHTML= sGenHTML + '</tbody></table>';

	return sGenHTML;
}

function getIFAContactDetails(sEmailPrefix) {
  var sGenHTML='';
	sGenHTML='<table cellspacing=0 cellpadding=0 border=0 width=100%>';
	sGenHTML= sGenHTML + '<thead><tr>';
	sGenHTML= sGenHTML + '	<th scope=col colspan=2>The contact details are:</th>';
	sGenHTML= sGenHTML + '</tr></thead>';
	sGenHTML= sGenHTML + '<tbody><tr>';
	sGenHTML= sGenHTML + '	<th scope=row id=ContactUsFldName valign=top><p>Email</p></th>';
	sGenHTML= sGenHTML + '	<td id=ContactUsFldValue valign=top><span id="Contactemail"><a href="mailto:'+sEmailPrefix+'@scottishlife.co.uk"><p align=left>'+sEmailPrefix+'@scottishlife.co.uk<p></a></span></td>';
	sGenHTML= sGenHTML + '</tr>';
	sGenHTML= sGenHTML + '<tr>';
	sGenHTML= sGenHTML + '	<th scope=row id=ContactUsFldName valign=top><p>Telephone Number</p></th>';
	sGenHTML= sGenHTML + '	<td id=ContactUsFldValue valign=top><p align=left>0131 456 6101';
	sGenHTML= sGenHTML + '	<br>(8.00am to 6.00pm Mon - Thurs and 8.00am to 5.00pm on Friday)</p>';
	sGenHTML= sGenHTML + '	</td>';
	sGenHTML= sGenHTML + '</tr>';
	sGenHTML= sGenHTML + drawPostAddress('');
	sGenHTML= sGenHTML + '</tbody></table>';

	return sGenHTML;
}

function getSLIContactDetails(sEmailPrefix) {
  var sGenHTML='';
	sGenHTML= sGenHTML + '<thead><tr>';
	sGenHTML= sGenHTML + '	<th scope=col colspan=2>The contact details for Scottish Life International are:</th>';
	sGenHTML= sGenHTML + '</tr></thead>';
	sGenHTML= sGenHTML + '<tbody><tr>';
	sGenHTML= sGenHTML + '	<th scope=row id=ContactUsFldName valign=top><p>Email</p></th>';
	sGenHTML= sGenHTML + '	<td id=ContactUsFldValue valign=top><span id="Contactemail"><a href="mailto:'+sEmailPrefix+'@sli.co.im"><p align=left>'+sEmailPrefix+'@sli.co.im<p></a></span></td>';
	sGenHTML= sGenHTML + '</tr>';
	sGenHTML= sGenHTML + '<tr>';
	sGenHTML= sGenHTML + '	<th scope=row id=ContactUsFldName valign=top><p>Telephone Number</p></th>';
	sGenHTML= sGenHTML + '	<td id=ContactUsFldValue valign=top><p align=left>+44 1624 611 077';
	sGenHTML= sGenHTML + '	<br>(8.00am to 6.00pm Mon - Thurs and 8.00am to 5.00pm on Friday)</p>';
	sGenHTML= sGenHTML + '	</td>';
	sGenHTML= sGenHTML + '</tr>';
	sGenHTML= sGenHTML + drawPostAddressSLI('');
	sGenHTML= sGenHTML + '</tbody>';
	
	return sGenHTML;
}

function drawContactDetails(sDetails) 
{
  var arrDetail;
  var sGenHTML='';
	var sType, sRefNumber, sDeptName, sEmailID, sPhoneNo, sPrimryName, sSecName,sSerTeamNam;
	var sRelationNam, sDelvryNam, sSerTeam, sPlatinum, sPrimaryContct, sSecContct, sRelationContct;
	var sSerTeamCont, sDelvryContct, sSchType,sPolRefer, sEpuScheme, sContactDesc;
	// Decode the details
	arrDetail= sDetails.split("~");
	sType= arrDetail[0];
	sRefNumber= (arrDetail[2])?arrDetail[2]:0;	
	sDeptName= (arrDetail[3])?arrDetail[3]:'';
	sEmailID= (arrDetail[4])?arrDetail[4]:'';
	sPhoneNo= (arrDetail[5])?arrDetail[5]:'';
	sSchType =  (arrDetail[6])?arrDetail[6]:'';
	sPrimryName = (arrDetail[7])?arrDetail[7]:'';
	sPrimaryContct = (arrDetail[8])?arrDetail[8]:'';
	sSecName =	(arrDetail[9])?arrDetail[9]:'';
	sSecContct = (arrDetail[10])?arrDetail[10]:'';
	sRelationNam =	(arrDetail[11])?arrDetail[11]:'';
	sRelationContct = (arrDetail[12])?arrDetail[12]:'';
	sSerTeamNam = (arrDetail[13])?arrDetail[13]:'';
	sSerTeamCont = (arrDetail[14])?arrDetail[14]:'';
	sDelvryNam =	(arrDetail[15])?arrDetail[15]:'';
	sDelvryContct = (arrDetail[16])?arrDetail[16]:'';
	sSerTeam = (arrDetail[17])?arrDetail[17]:'';
	sPlatinum = (arrDetail[18])?arrDetail[18]:'';
	sPolRefer = (arrDetail[19])?arrDetail[19]:'';
    sEpuScheme = (arrDetail[20])?arrDetail[20]:'';
	
	// when e-mail is not set up in mainframe, use this generic e-mail ID
	if (trim(sEmailID) == "") 
		sEmailID='CustomerQueries@scottishlife.co.uk';
	sEmailID=sEmailID.toLowerCase( );
	sGenHTML='<table cellspacing=0 border=0 cellpadding=0 width=100%>';
	sGenHTML= sGenHTML + '<thead><tr>';
	sGenHTML= sGenHTML + '	<th scope=col colspan=2>The contact details for your Scottish Life '+sType+' are:</th>';
	sGenHTML= sGenHTML + '</tr></thead>';

	if (sType == "Policy" ) 
	{
		sGenHTML= sGenHTML + '<tbody><tr>';
		sGenHTML= sGenHTML + '	<th scope=row id=ContactUsFldName valign=top><p>Policy Number</p></th>';
		if(sPolRefer == 'Y')
			sGenHTML = sGenHTML + '	<td id=ContactUsFldValue valign=top><p align=left>'+sSchType+' '+ parseFloat(sRefNumber)+'</p></td>';
		else
			sGenHTML = sGenHTML + '	<td id=ContactUsFldValue valign=top><p align=left>'+ parseFloat(sRefNumber)+'</p></td>';
		sGenHTML= sGenHTML + '</tr>';
	} 
	else if (sType == "Scheme" ) 
	{
		sGenHTML= sGenHTML + '<tbody><tr>';
		sGenHTML= sGenHTML + '	<th scope=row id=ContactUsFldName valign=top><p>Scheme Number:</p></th>';
		sGenHTML= sGenHTML + '	<td id=ContactUsFldValue valign=top><p align=left>'+sSchType+' '+ parseFloat(sRefNumber)+'</p></td>';
		sGenHTML= sGenHTML + '</tr>';
	}
	if(sPolRefer == 'Y')
	{
		if(sSerTeam != ' ')
		{
			sGenHTML = sGenHTML + '<tr>';
			sGenHTML = sGenHTML + '	<th scope=row id=ContactUsFldName valign=top><p>Servicing Team </p></th>';
			sGenHTML = sGenHTML + '	<td id=ContactUsFldValue valign=top><p align=left>'+sSerTeam+'</p></td>';
			sGenHTML = sGenHTML + '</tr>';	
		}
	}
	sGenHTML= sGenHTML + '<tr>';
	sGenHTML= sGenHTML + '	<th scope=row id=ContactUsFldName width=30% valign=top><p>Email</p></th>';
	sGenHTML= sGenHTML + '	<td id=ContactUsFldValue><span id="Contactemail" valign=top><a href="mailto:'+sEmailID+'"><p align=left>'+sEmailID+'</p></a></span></td>';
	sGenHTML= sGenHTML + '</tr>';
	if(sPolRefer == 'N')
	{
		if(sPhoneNo != ' ')
		{
			sGenHTML= sGenHTML + '<tr>';
			sGenHTML= sGenHTML + '	<th scope=row id=ContactUsFldName valign=top><p>Telephone Number</p></th>';
			sGenHTML= sGenHTML + '	<td id=ContactUsFldValue valign=top><p align=left>'+sPhoneNo+'</p></td>';
			sGenHTML= sGenHTML + '</tr>';
		}
	}
	sGenHTML= sGenHTML + drawPostAddress(sDeptName);
	if(sPolRefer == 'Y')
	{
		if (trim(sPrimryName) != '')
		{
			sGenHTML = sGenHTML + '<tr>';
			sGenHTML = sGenHTML + '	<th scope=row id=ContactUsFldName valign=top><p>Primary Named Contact </p></th>';
			sGenHTML = sGenHTML + '	<td id=ContactUsFldValue valign=top><p align=left>'+ sPrimryName+'<br>'+ sPrimaryContct +'</p></td>';
			sGenHTML = sGenHTML + '</tr>';
		}
	}
	if(sPolRefer == 'Y')
	{
		if(trim(sSecName)!= '')
		{
			sGenHTML = sGenHTML + '<tr>';
			sGenHTML = sGenHTML + '	<th scope=row id=ContactUsFldName valign=top><p>Secondary Named Contact </p></th>';
			sGenHTML = sGenHTML + '	<td id=ContactUsFldValue valign=top><p align=left>'+sSecName+'<br>'+sSecContct+'</p></td>';
			sGenHTML = sGenHTML + '</tr>';
		}
	}
	if((sPlatinum == 'Y')&&(sPolRefer == 'Y'))
	{
	    if (sEpuScheme == 'Y')
	        sContactDesc = 'Customer Experience Team Manager ';
	    else
	        sContactDesc = 'Servicing Team Manager ';

		if(trim(sSerTeamNam) != '')
		{
			sGenHTML = sGenHTML + '<tr>';
			sGenHTML = sGenHTML + '	<th scope=row id=ContactUsFldName valign=top><p>' + sContactDesc + '</p></th>';
			sGenHTML = sGenHTML + '	<td id=ContactUsFldValue valign=top><p align=left>'+sSerTeamNam+'<br>'+sSerTeamCont+' </p></td>';
			sGenHTML = sGenHTML + '</tr>';
		}
	}
	if(sPolRefer == 'Y')
	{
	    if (sEpuScheme == 'Y')
	        sContactDesc = 'Client Relationship Manager ';
	    else
	        sContactDesc = 'Relationship Manager ';

		if(trim(sRelationNam) != '')
		{
			sGenHTML = sGenHTML + '<tr>';
			sGenHTML = sGenHTML + '	<th scope=row id=ContactUsFldName valign=top><p>' + sContactDesc + '</p></th>';
			sGenHTML = sGenHTML + '	<td id=ContactUsFldValue valign=top><p align=left>'+sRelationNam+'<br>'+sRelationContct+'</p></td>';
			sGenHTML = sGenHTML + '</tr>';
		}
	}	
		
	if((sPlatinum == 'Y')&&(sPolRefer == 'Y'))
	{
	    if (sEpuScheme == 'Y')
	        sContactDesc = 'Customer Experience Manager ';
	    else
	        sContactDesc = 'Service Delivery Manager ';

		if(trim(sDelvryNam) != '')
		{
			sGenHTML = sGenHTML + '<tr>';
			sGenHTML = sGenHTML + '	<th scope=row id=ContactUsFldName valign=top><p>' + sContactDesc + '</p></th>';
			sGenHTML = sGenHTML + '	<td id=ContactUsFldValue valign=top><p align=left>'+sDelvryNam+'<br>'+sDelvryContct+'</p></td>';
			sGenHTML = sGenHTML + '	</td>';
			sGenHTML = sGenHTML + '</tr>';
		}
	}
	sGenHTML= sGenHTML + '</tbody></table>';
	return sGenHTML;
}

function drawPostAddress(sDeptName) {
  var sGenHTML='';	
  var sDept1='';
	sGenHTML= sGenHTML + '<tr>';
	sGenHTML= sGenHTML + '	<th scope=row id=ContactUsFldName valign=top><p>Postal Address</p></th>';
	sGenHTML= sGenHTML + '	<td id=ContactUsFldValue valign=top><p align=left>';
	sGenHTML= sGenHTML + '		 Scottish Life<br>';
	sDept1 = sDeptName.slice(0,4);
	if (sDept1 == "SIPP") {		
		sDeptName="<span>SIPP Administration Team</span>";
		sGenHTML= sGenHTML + sDeptName +' <br>';
	} else if (trim(sDeptName) != "") {
		sDeptName=sDeptName.toLowerCase( );
		sDeptName="<span style='text-transform : capitalize;'>"+sDeptName+"</span>";
		sGenHTML= sGenHTML + sDeptName +' <br>';
	}
	sGenHTML= sGenHTML + '		 St Andrew House <br>';
	sGenHTML= sGenHTML + '		 1 Thistle Street <br>';
	sGenHTML= sGenHTML + '		 Edinburgh <br>';
	sGenHTML= sGenHTML + '		 EH2 1DG <br>';
	sGenHTML= sGenHTML + '</p></td>';
	sGenHTML= sGenHTML + '</tr>';

	return sGenHTML;
}

function drawPostAddressSLI(sDeptName) {
  var sGenHTML='';	
	sGenHTML= sGenHTML + '<tr>';
	sGenHTML= sGenHTML + '	<th scope=row id=ContactUsFldName valign=top><p>Postal Address</p></th>';
	sGenHTML= sGenHTML + '	<td id=ContactUsFldValue valign=top><p align=left>';
	sGenHTML= sGenHTML + '		 Scottish Life International<br>';
	if (trim(sDeptName) != "") {
		sDeptName=sDeptName.toLowerCase( );
		sDeptName="<span style='text-transform : capitalize;'>"+sDeptName+"</span>";
		sGenHTML= sGenHTML + sDeptName +' <br>';
	}
	sGenHTML= sGenHTML + '		 Clarendon House <br>';
	sGenHTML= sGenHTML + '		 Victoria Street <br>';
	sGenHTML= sGenHTML + '		 Douglas <br>';
	sGenHTML= sGenHTML + '		 Isle of Man <br>';
	sGenHTML= sGenHTML + '		 IM1 2LN <br>';
	sGenHTML= sGenHTML + '</p></td>';
	sGenHTML= sGenHTML + '</tr>';

	return sGenHTML;
}

