var windowa = null;
var windowb = null;
var openwindows = 0;

var selectedObj = null;
var selectedFrame = 1;
var visibleMessage = null;
var poa = 0;
var payticket = 0;
var step2 = 0;

function doRoll(obj) {
	document.getElementById(obj.parentNode.id + "Arrow").className = "arrowSelected";
	obj.className = "listSelected";
}
function undoRoll(obj,override) {
	if (obj != selectedObj || override) {
		document.getElementById(obj.parentNode.id + "Arrow").className = "arrow";
		obj.className = "list";
	}
}
function doSelect(obj,n) {
	if (selectedObj != null) undoRoll(selectedObj,true);
	selectedObj = obj;
	window.parent.switchImage(n);
}

function doSelect2(obj,n,m) {
	if (selectedObj != null) undoRoll(selectedObj,true);
	selectedObj = obj;
	//alert('m =' + m);
	if (m==1)
	{
		poa=1;
		payticket=0;		
	}
	else if (m==2)
	{
		poa=0;
		payticket=1;
	}
	window.parent.switchImage(n);
	
	window.parent.poa=poa;
	window.parent.payticket=payticket;
	window.parent.frames[2].location.href="/iframes/blank.html";
	window.parent.step2=0;
}

function doSelect3(obj,n,step2On) {
	if (selectedObj != null) undoRoll(selectedObj,true);
	selectedObj = obj;
	window.parent.switchImage(n);
	//alert('step2On = ' + step2On);
	if (step2On==1)
	{
	    step2 = 1;
	}
	else
	{
	    step2 = 0;
	}
	window.parent.step2=step2;
}

function switchImage(n) {
	document.getElementById("step"+selectedFrame+"Gif").src = "../images/step"+selectedFrame+"Off.gif"
	selectedFrame = n;
	document.getElementById("step"+n+"Gif").src = "../images/step"+n+"On.gif"
}

function showMessageOld(n) {
	//if message already showing
	if (visibleMessage != null) {
		//hide message
		document.getElementById("message"+visibleMessage).style.display = "none";
		//if message that was showing is not the same one as one whose button was clicked, show new one
		if (visibleMessage != n) {
			visibleMessage = n;
			document.getElementById("message"+visibleMessage).style.display = "";
		}
		//else no visible message
		else visibleMessage = null;
	}
	//else no message showing
	else {
		visibleMessage = n;
		document.getElementById("message"+visibleMessage).style.display = "";
	}
}
function showMessageWorking(n) {
	document.getElementById("message"+n).style.display = "";
}

function showMessage(n) {
	document.getElementById("message"+n).style.display = "";
	if (n==2)
	{
		if (poa == 0 && payticket==1)
		{			
			document.getElementById("message"+21).style.display = ""; // Payticket
			document.getElementById("message"+22).style.display = "none"; // POA
			document.getElementById("message"+3).style.display = "none";
			document.getElementById("message"+31).style.display = "none";
		}
		if (poa == 1 && payticket==0)
		{
			document.getElementById("message"+21).style.display = "none"; // Payticket
			document.getElementById("message"+22).style.display = ""; // POA
			document.getElementById("message"+3).style.display = "none";
			document.getElementById("message"+31).style.display = "none";
		}
	}	
	
	
	if (n==3)
	{
		if (poa == 0 && payticket==1)
		{			
			document.getElementById("message"+21).style.display = "none"; // Payticket
			document.getElementById("message"+22).style.display = "none"; // POA
		}
		else if (poa == 1 && payticket==0)
		{
			document.getElementById("message"+21).style.display = "none"; // Payticket
			document.getElementById("message"+22).style.display = "none"; // POA
		}
		
		if (step2==1)
		{
			document.getElementById("message"+3).style.display = "none";
			document.getElementById("message"+31).style.display = "";		
		}
		else
		{
			document.getElementById("message"+3).style.display = "";
			document.getElementById("message"+31).style.display = "none";
		}
	}	
	
}

function hideMessageWorking(n) {
	document.getElementById("message"+n).style.display = "none";
}

function hideMessage(n) {
	document.getElementById("message"+n).style.display = "none";
	if (poa == 0 && payticket==1)
	{
		document.getElementById("message"+21).style.display = "none";
		document.getElementById("message"+22).style.display = "none";
		document.getElementById("message"+3).style.display = "none";
		document.getElementById("message"+31).style.display = "none";
	}
	else if (poa == 1 && payticket==0)
	{		
		document.getElementById("message"+21).style.display = "none";
		document.getElementById("message"+22).style.display = "none";
		document.getElementById("message"+3).style.display = "none";
		document.getElementById("message"+31).style.display = "none";
	}
	else if (poa == 0 && payticket==0)
	{		
		document.getElementById("message"+21).style.display = "none";
		document.getElementById("message"+22).style.display = "none";
		document.getElementById("message"+3).style.display = "none";
		document.getElementById("message"+31).style.display = "none";
	}
}

function noMatch() {
alert ("Please return to step one and try again.  If you need help, mouse over the question marks beside each step name, or read the FAQ in our get help section.  Thank you")
}

function popUpLrg1(newUrl,bigTicket,w,h) {
var winW = (screen.width - w) / 2;
var winH = (screen.height - h) / 2;
window.open(newUrl,"","toolbar=0,status=0,menubar=0,directories=0,resize=0,scrollbars=0,location=0,width="+w+",height="+h+",left="+winW+",top="+winH);
}

function popUpLrg (newUrl,bigTicket,w,h) {
var winW = (screen.width - w) / 2;
var winH = (screen.height - h) / 2;
msgWindow=window.open("","","toolbar=0,status=0,menubar=0,directories=0,resize=0,scrollbars=1,location=0,width="+w+",height="+h+",left="+winW+",top="+winH);
msgWindow.document.write("<HEAD><TITLE>Message window</TITLE><link href='/css/style.css' type='text/css' rel='stylesheet' media='all' /></HEAD>")   
msgWindow.document.write("<font color=\"#2061A2\"><small>If your ticket looks like the image shown below, close this window and click the YES button to proceed. If your ticket does not look like the image below, close this window and go back to Step 1.</small></font><br><br>")
msgWindow.document.write("<img src=" + newUrl + " alt='If your ticket looks like the image shown below, close this window and click the YES button to proceed.If your ticket does not look like the image below, close this window and go back to Step 1.'><br>")

}

function popUpLrgNotice (newUrl,bigTicket,w,h) {
var winW = (screen.width - w) / 2;
var winH = (screen.height - h) / 2;
msgWindow=window.open("","","toolbar=0,status=0,menubar=0,directories=0,resize=0,scrollbars=1,location=0,width="+w+",height="+h+",left="+winW+",top="+winH);
msgWindow.document.write("<HEAD><TITLE>Message window</TITLE><link href='/css/style.css' type='text/css' rel='stylesheet' media='all' /></HEAD>")   
msgWindow.document.write("<font color=\"#2061A2\"><small>If your Notice looks like the image shown below, close this window and click the YES button to proceed. If your Notice does not look like the image below, close this window and go back to Step 1.</small></font><br><br>")
msgWindow.document.write("<img src=" + newUrl + " alt='If your Notice looks like the image shown below, close this window and click the YES button to proceed.If your Notice does not look like the image below, close this window and go back to Step 1.'><br>")
}

function checkWindowStatus() {

    if (windowa != null && windowa.closed) 
    {
        openwindows = 0
        return;

    }//end if

    return;
}

function toTicketInfo(city, cityname) {

    checkWindowStatus();

    var munic = city;
    if (!confirm("You are about to pay a PARKING TICKET for " + cityname + ", Continue?")) {
	return;
    }

    if (munic != "" && openwindows == 0) {
        windowa = window.open("https://www.paytickets.ca/unp/UNPFrontControllerServlet?LANG=en&OPCODE=FormInfo&APP_ID=" + munic +"&BRAND=central","window1","width=660,height=650,resizable=yes,scrollbars=yes,menubar=no,toolbar=no,directories=no,location=no,status=yes");
        openwindows = 1;
        return; 
    }
    return;

}

function toPOA(district, name, section) {

    if (!confirm("You are about to pay a SPEEDING/TRAFFIC/PROVINCIAL OFFENCES for " + name + ", Continue?")) {
	return;
    }
    
    if (district != null && district != "")
    {       	
        //var s = "https://www.paytickets.ca/poa/TicketInfoServlet?APPID=poa&LANG=en&BRANDING=" + district +"&SECTION=" + section;                
        var s = "https://www.paytickets.ca/poa/TicketInfoServlet?APPID=poa&LANG=en&BRANDING=central" + "&SECTION=" + section;
        window.open(s,"window1","width=660,height=650,resizable=yes,scrollbars=yes,menubar=no,toolbar=no,directories=no,location=no,status=yes");
    }
    else
    {    	
        var s = "https://www.paytickets.ca/poa/TicketInfoServlet?APPID=poa&LANG=en&BRANDING=central" + "&SECTION=" + section;        
        window.open(s,"window1","width=660,height=650,resizable=yes,scrollbars=yes,menubar=no,toolbar=no,directories=no,location=no,status=yes");        
    }

    return;

}
