var gCallback=null;

function writeDiv(div, content) {
  // TODO: Portability of this code
  var body;
  body = document.getElementById(div);
  body.innerHTML='';
  body.innerHTML=content;
}

// Generic Function to Control Display of Popup
function popupDisplay(title, body, callback, width, top){
  var popup;

	writeDiv('popupBody', body);
	writeDiv('popupTitle', title);

  popup=document.getElementById('popup');  
	
	// Centre relative to main page
	// The height is controlled by what is written to the body.
	if (!width){width=500;}
	if (!top){top=100;}

    // if the window is scrolled, then I want to offset
    if (window.innerHeight){top = top + window.pageYOffset;}
	else if (document.documentElement && document.documentElement.scrollTop)
	{top = top + document.documentElement.scrollTop;}
	else if (document.body){top = top + document.body.scrollTop;}

	popup.style.width=width;
	popup.style.left=(800-width)/2;
	popup.style.top=top;

  popup.style.visibility="visible";

	gCallback = callback;
}
function popupClose(param){
  var popup, rv;
  rv = true;
  if (gCallback){rv = gCallback(param);}
  if (rv){
    popup=document.getElementById('popup');  
    popup.style.visibility="hidden";
	writeDiv('popupBody', "");
	}
}

// I want to collect some information when the mover exits, so I 
// can reduce the redundant nagging. If the data collection is
// complete then this function should be silent. If the data
// collection is incomplete, then it should let the user know
function doFinishLater() {
    if (AccountStatus1[0] == 1 && AccountStatus2['NotDone'] == 0 && AccountStatus2['DoneNotConfirmed'] == 0 && AccountStatus2['Confirmed'] > 0) {
    // Nothing to do. Just Logout - Need an alternative message here - not so urgent
    location='fFinishLater';
    return false;
    }
    body="<iframe name=finishlaterframe src='FinishLater.html' width=100% height=400 frameborder=0 scrolling=no noresize></iframe>";
   popupDisplay('Exit the Registration Process', body, null, 500, 50);
   finishlaterframe.focus();
   return false;
}

function doProgressReport() {
    body="<iframe name=progressreportframe src='ProgressReport.html' width=100% height=440 frameborder=0 scrolling=auto noresize></iframe>";
   popupDisplay('Progress Report', body, null, 620, 50);
   progressreportframe.focus();
   return false;
}

function doPrintOutSummary() {
    body="<iframe name=printoutframe src='PrintOutSummary.html' width=100% height=440 frameborder=0 scrolling=auto noresize></iframe>";
   popupDisplay('Print Out Summary', body, null, 620, 50);
   printoutframe.focus();
   return false;
}

function doChangePassword() {
    body="<iframe name=changepassframe src='ChangePass.html' width=100% height=300 frameborder=0 scrolling=auto noresize></iframe>";
   popupDisplay('Change Password', body, null, 500, 50);
   changepassframe.focus();
   return false;
}

function doTermsConditions() {
   body="<iframe name=termsframe src='/p/terms.html?ispopup=1' width=100% height=500 frameborder=2 scrolling=auto noresize></iframe>";
   popupDisplay('Terms &amp; Conditions', body, null, 500, 50);
   termsframe.focus();
   return false;
}

function doFAQ(Section) {
   body="<iframe name=faqframe src='/p/faq.html?ispopup=1#"+Section+"' width=100% height=500 frameborder=2 scrolling=auto noresize></iframe>";
   popupDisplay('NewAddress.ie Process FAQ', body, null, 650, 50);
   faqframe.focus();
   return false;
}


function ConfirmOldAddressCallback(rv) {
document.getElementById('page5Day').style.visibility='visible';
document.getElementById('page5Month').style.visibility='visible';
document.getElementById('page5Year').style.visibility='visible';
return true;
}

function doConfirmOldAddress(a1,a2,a3,a4,a5) {
var h=[];
h[h.length]='<p style="font-size:14px;font-weight:bold;font-family:verdana;color:black;">Can you receive post at your old address?</p>';

h[h.length]='<p align=center style="font-size:12px;font-family:verdana;color:black;padding:0 10 0 10;">';
h[h.length]='For your security, NewAddress.ie will post a "Signature Pack" to you.<br><br>This pack will ';
h[h.length]='include forms for companies who require your signature, e.g. Banks.';
h[h.length]='It also gives you a chance to supply account numbers that you do not have now.<br><br>';
h[h.length]='<b>If you cannot ';
h[h.length]='receive post at your old address (below), select the second option at the bottom and we will send the Pack';
h[h.length]='to your new address instead.</b></p>';

h[h.length]='<table summary="" align=center>';
h[h.length]='<tr><td style="color:black;font-size:12px;weight:bold;">';
h[h.length]=a1+'<br>';
h[h.length]=a2+'<br>';
if (a3.length > 0){ h[h.length]=a3+'<br>';}
if (a4.length > 0){ h[h.length]=a4+'<br>';}
if (a5.length > 0){ h[h.length]=a5+'<br>';}
h[h.length]='</td></tr>';
h[h.length]='</table>';
h[h.length]='<br>';
h[h.length]='<table summary="" align=center>';
h[h.length]='<tr>';
h[h.length]='<td style="color:black;font-size:12px;"><input type=radio name="CanReceive" id=CanReceive1 value="Y" checked></td>';
h[h.length]='<td style="color:black;font-size:12px;">';
h[h.length]='<a onclick="'+"document.getElementById('CanReceive2').checked=false;document.getElementById('CanReceive1').checked=true;" +'">';
h[h.length]='<b>I <i>can</i> receive post at the above address.</b> Please send the Signature';
h[h.length]='Pack to this address.</a></td>';
h[h.length]='</tr>';
h[h.length]='<tr>';
h[h.length]='<td style="color:black;font-size:12px;"><input type=radio name="CanReceive" id=CanReceive2 value="N"></td>';
h[h.length]='<td style="color:black;font-size:12px;">';
h[h.length]='<a onclick="'+"document.getElementById('CanReceive2').checked=true;document.getElementById('CanReceive1').checked=false;" +'">';
h[h.length]='<b>I <i>cannot</i> receive post at the above address.</b> Please send the Signature';
h[h.length]='Pack to my new address instead.</a></td>';
h[h.length]='</tr>';
h[h.length]='</table>';
h[h.length]='<br>';
h[h.length]='';

h[h.length]='<table align="center" cellspacing=0 cellpadding=0 height=20 border=0>';
h[h.length]='<tr><td><img src="/i/spacer.gif" alt="" width=1 height=10></td></tr>';
h[h.length]='<tr><td width=170>';
h[h.length]='<a onclick="' + "if(document.getElementById('CanReceive2').checked){document.getElementById('page3OldAddressUnavail').checked=true;}document.getElementById('MainForm').submit(); return false;" + '" class="Action" href="#">Continue</a>';
h[h.length]='</td>';
h[h.length]='</table>';

document.getElementById('page5Day').style.visibility='hidden';
document.getElementById('page5Month').style.visibility='hidden';
document.getElementById('page5Year').style.visibility='hidden';

   popupDisplay('Where should we send post now?', h.join('\n'), ConfirmOldAddressCallback, 550, 50);
   return false;
}
function MyPopUpWin(link) {
var iMyWidth;
var iMyHeight;
iMyWidth = ((window.screen.width-700)/2);
iMyHeight = ((window.screen.height-550)/2);
//Open the window.
var win2 = window.open(link,"microsite","status=no,height=500,width=700,resizable=yes,left=" + iMyWidth + ",top=" + iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + iMyHeight + ",toolbar=no,menubar=no,scrollbars=1,location=no,directories=no");
win2.focus();
}
