// Copyright Andy Watts, Imaner Consultants
// Created for PAD, www.vote4animals.org.uk
// Do not use without permission
// Please email if you would like to use any of this code
// consultants@imaner.net, www.imaner.net

function showParty(party) {
var partyCode = -1;
partyCode = party;
var listOfParties = new Array("Not set","Conservative","Green","Labour","Liberal Democrats","Plaid Cymru","Scottish National Party","Democratic Unionist Party","Sinn Fein","Social, Democratic and Labour Party","Ulster Unionist Party","Independent","Respect");
	if (partyCode >= 0) {
	return listOfParties[partyCode];
	}
}

var edms = new Array("EDM 92","EDM 98","EDM 1704","EDM 811","EDM 1247","EDM 1411","EDM 1718","EDM 4","EDM 74","EDM 480","EDM 1215","EDM 1279","EDM 127","EDM 135","EDM 137","EDM 97");
var edmDesc = new Array("(Animal testing of drugs)","(Welfare of animals)","(Use of Primates in Scientific Procedures)","(Animal Procedures)","(Sale of Foie Gras)","(Testing of Recreational Drugs on Animals)","(Health Service Ombudsman's Report PA-2823)","(Use of Animals to test Food Additives)","(Ombudsman and Suffering in Animal Experiments)","(Animal Protection Policy)","(Household Products)","(Animal Testing of Cosmetics)","(Ombudsman and Suffering in Animal Experiments)","(Animal Protection Policy)","(Animal Testing of Cosmetics)","(Animal Protection Policy)");
var edmLinks = new Array("edm92.htm","edm98.htm","edm1704.htm","edm811.htm","edm1247.htm","edm1411.htm","edm1718.htm","edm4.htm","edm74.htm","edm480.htm","edm1215.htm","edm1279.htm","edm127.htm","edm135.htm","edm137.htm","edm97.htm");
var edmActionLinks = new Array("contactedm92.htm","contactedm98.htm","contactedm1704.htm","contactedm811.htm","contactedm1247.htm","contactedm1411.htm","contactedm1718.htm","contactedm4.htm","contactedm74.htm","contactedm480.htm","contactedm1215.htm","contactedm1279.htm","contactedm127.htm","contactedm135.htm","contactedm137.htm","contactedm97.htm"); // Can Sign Letters
var edmActionLinks2 = new Array("contactedm92a.htm","contactedm98a.htm","contactedm1704a.htm","contactedm811a.htm","contactedm1247a.htm","contactedm1411.htm","contactedm1718a.htm","contactedm4.htm","contactedm74a.htm","contactedm480a.htm","contactedm1215.htm","contactedm1279a.htm","contactedm127a.htm","contactedm135a.htm","contactedm137a.htm","contactedm97.htm"); //Cannot Sign Letters
var edmActions = new Array("Click here to lobby your MP on this issue","Your MP has already signed, so no action needed","Click here to lobby your MP on this issue");
//var edmActions = new Array("","",""); //Post 2007/2008 session


function showEDMAnswerImage(answer,cantSign) {
var answerCode = -1;
var edmImages = new Array("../images/no.gif","../images/yes.gif","../images/cant.gif");
var edmAlts = new Array("Not Signed","Signed","Cannot Sign");
answerCode = answer;
	if (answerCode >= 0 && cantSign == 0) { //Can sign - pass in answers
	var imageText = '<img src="'+edmImages[answerCode]+'" width="26" height="26" alt="'+edmAlts[answerCode]+'">';
	document.write(imageText);
	}
	else { // Cant Sign - pass in 2 for cannot sign
	var imageText = '<img src="'+edmImages[2]+'" width="26" height="26" alt="'+edmAlts[2]+'">';
	document.write(imageText);
	}
}

function showQAnswerImage(answer) {
var answerCode = -1;
answerCode = answer;
var listOfImages = new Array("../images/none.gif","../images/yes.gif","../images/no.gif","../images/stop.gif");
var listOfAlts = new Array("No Response","Yes","No","Prevaricated");
	if (answerCode >= 0) {
	var imageText = '<img src="'+listOfImages[answerCode]+'" width="26" height="26" alt="'+listOfAlts[answerCode]+'">';
	document.write(imageText);
	}
}

function writeCurrentDetails(cText) {
	document.write('<h2>Your MP: '+cText[1]+' ('+showParty(cText[2])+'), '+cText[0]+'</h2>');
}

function writeEDMAnswers(pText,pNo) {
pNo = pNo-1;
// Require offset into the MP array for this EDM
// e.g. EDM 1 at pos 10, EDM 2 at pos 11
// Offset calculated from pNo
var offSet = 11;
offSet += pNo;

if (pText[4] == 1) { // If can't sign overall then do not even put out ones that have signed

	// If can't sign - ActionLinks2 - supporting Letter
document.write('<strong><a href="'+relpath+edmLinks[pNo]+'" class="noline">'+edms[pNo]+' '+edmDesc[pNo]+'</a></strong><br><a href="javascript:openContactPage(c1,\'../'+edmActionLinks2[pNo]+'\')">'+edmActions[(pText[offSet])]+'</a>');
//document.write('<strong><a href="'+relpath+edmLinks[pNo]+'" class="noline">'+edms[pNo]+' '+edmDesc[pNo]+'</a></strong><br>'+edmActions[(pText[offSet])]); //Post 2007/2008 session

}

else { //Start else - Can Sign

	if (pText[offSet] == 0) { // If can sign and not signed
		document.write('<strong><a href="'+relpath+edmLinks[pNo]+'" class="noline">'+edms[pNo]+' '+edmDesc[pNo]+'</a></strong><br><a href="javascript:openContactPage(c1,\'../'+edmActionLinks[pNo]+'\')">'+edmActions[(pText[offSet])]+'</a>');
		//document.write('<strong><a href="'+relpath+edmLinks[pNo]+'" class="noline">'+edms[pNo]+' '+edmDesc[pNo]+'</a></strong><br>'+edmActions[(pText[offSet])]); //Post 2007/2008 session

	}

	if (pText[offSet] == 1) { // If has signed
		document.write('<strong><a href="'+relpath+edmLinks[pNo]+'" class="noline">'+edms[pNo]+' '+edmDesc[pNo]+'</a></strong><br>'+edmActions[(pText[offSet])]);
	}

	if (pText[offSet] == 2) { // If can't sign - ActionLinks2 - supporting Letter
		document.write('<strong><a href="'+relpath+edmLinks[pNo]+'" class="noline">'+edms[pNo]+' '+edmDesc[pNo]+'</a></strong><br><a href="javascript:openContactPage(c1,\'../'+edmActionLinks2[pNo]+'\')">'+edmActions[(pText[offSet])]+'</a>');
		//document.write('<strong><a href="'+relpath+edmLinks[pNo]+'" class="noline">'+edms[pNo]+' '+edmDesc[pNo]+'</a></strong><br>'+edmActions[(pText[offSet])]); //Post 2007/2008 session
	}

} //End else
} //End WriteEDMAnswers function

function writeEDMAnswerImage(pText,pNo) {
pNo = pNo-1;
// Require offset into the MP array for this EDM
// e.g. EDM 1 at pos 10, EDM 2 at pos 11
// Offset calculated from pNo
var offSet = 11;
offSet += pNo;

var cantSign = 0;
if (pText[4] == 1) {cantSign=1}; // If can't sign overall then do not even put out ones that have signed

showEDMAnswerImage(pText[offSet],cantSign);

}

function writeQAnswerImage(pText,pNo) {
pNo = pNo-1;
// Require offset into the MP array for this Q
// e.g. Q1 at pos 4, Q2  at pos 5
// Offset calculated from pNo
var offSet = 5;
offSet += pNo;

showQAnswerImage(pText[offSet]);

}

function writeMPEmail(pText) {
	if (doesExist(pText[3])) { 
	wrongEmailText = " (if this email address does not work please <a href=\"mailto:pad@vote4animals.org.uk\">let us know</a> so we can update it).";
	document.write('or email: '+pText[3]+wrongEmailText)
	};	
}

function writePADComment(pText) {
	if (doesExist(pText)) {
	document.write(pText);
	}
	else {
	document.write("Pending");
	}
}

function doesExist(inputValue) {
	var aCharExists=0
	if (inputValue) {
		for (var i=0; i<inputValue.length; i++) {
			if (inputValue.charAt(i) != " ") {			
				aCharExists = 1
			}
		}
	}
	if (!aCharExists) {
		return false			
	}
	else {
		return true
	}
}

var chasm = screen.availWidth;
var mount = screen.availHeight;
var contactCandidate = new Array();

function openContactPage(candidateArray,edmLink) {
	contactCandidate = candidateArray;
	msgWindow=window.open(edmLink,'ContactPageWindow','width=600,height=450,left=' + ((chasm - 600 - 10) * .5) + ',top=' + ((mount - 600 - 30) * .5) + ',directories=no,location=no,menubar=no,scrollbars=yes,status=no,titlebar=no,toolbar=no');
	if (msgWindow.opener == null) msgWindow.opener = self;
}