liltype.ifaw = new liltype();

liltype.push(liltype.ifaw);

liltype.top().getURLB = function()
{
	var r;
	if (r = window.location.href.match(/\/b\.([0-9]+)\//))
	{
		return r[1];
	}
	else if (r = window.location.href.match(/(\?|\&)b=([0-9]+)(\&|$)/))
	{
		return r[2];
	}
}

liltype.top().getURLC = function()
{
	var r;
	if (r = window.location.href.match(/\/c\.([0-9a-z]+)\//i))
	{
		return r[1];
	}
	else if (r = window.location.href.match(/(\?|\&)c=([0-9a-z]+)(\&|$)/i))
	{
		return r[2];
	}
}

liltype.top().sprintSubmitButton = function(onclick, fnPre, fnPost, dat)
{
	var buttLangCode = "";
	dat = dat ? dat : {};
	dat["className"] = dat["className"] ? dat["className"] : "ifaw_custom_submit_button";
	dat["name"] = dat["name"] ? dat["name"] : "ifaw_custom_submit_button";
	switch (this.getURLC())
	{
		case "muIVLcMQJpE":
			buttLangCode = "-NL";
			break;
		case "fdKHIMNpEoG":
			buttLangCode = "-DE";
			break;
		case "goIJLPOnGjF":
		case "ljJXJ8MLIsE":
			buttLangCode = "-FR";
			break;
		case "fdJHKLNmFmG":
			buttLangCode = "-CN";
			break;
		case "kiKSL4PNLvF":
			buttLangCode = "-RU";
			break;
		case "hfILKWOBJqG":
			buttLangCode = "-ES";
			break;
		case "fdKHIQNpEkG":
			buttLangCode = "-JP";
			break;
	}
	return (
		'<input '+
			'class="'+dat["className"]+'" '+
			'type="image" '+
			(onclick ? ('onclick="'+onclick+'" ') : '')+
			(dat["name"] ? ('name="'+dat["name"]+'" ') : '')+
			(dat["alt"] ? ('alt="'+dat["alt"]+'" ') : '')+
			'style="background-color: #DE8C29;" '+
			'src="/atf/cf/%7B0d7e718b-27f3-40ca-b62b-13d20cbbb1fc%7D/'+fnPre+buttLangCode+fnPost+'" '+
		'/>'
	);
}


liltype.top().fixForm = function()
{
	var i, c, el, els, el2;

	if (document.getElementById)
	{

		/* Swap login button */
		if (!(el = document.getElementById("ctl00_lgnLogin_btnLogin")))
		{
			if (!(el = document.getElementById("ctl00_ctl00_lgnLogin_btnLogin")))
			{
				el = null;
			}
		}

		if (el)
		{
			el.src = "/atf/cf/%7B0D7E718B-27F3-40CA-B62B-13D20CBBB1FC%7D/BTN_LOGIN.GIF";
			el.style.backgroundImage = "none";
			el.style.width = "71px";
			el.style.height = "19px";
			el.style.backgroundColor = "#DE8C29";
			el.style.margin = "8px 0px 8px 0px";
			el.style.padding = "0px";
		}

		if (liltype.ds("ad_Main_Lgn_wrpr"))
		{
			if (el = liltype.ds("ad_Id_Item_wpr"))
			{
				liltype.classNameUtil.addNode(el, "wloginbox");
			}
		}

		els = document.getElementsByTagName("fieldset");
		el2 = null;
		for (i = 0, c = els.length; i < c; i++)
		{
			if (liltype.CNU.match(els[i].className, "ad_RegInfo"))
			{
				el2 = els[i].nextSibling;
			}
		}
		if ((el = liltype.ds("ad_RegInfo_p")) && el2)
		{
			el2.parentNode.insertBefore(el, el2);
		}
		
	}
	
	/*
		jQuery Stuff
	*/
	var html, jq, jq2, jq3, jq_tgt, butt_type, butt_onclick, butt_lang_ext, n;

	/* Move req'd info - all forms */
	if (!(html = (jq = jQuery("table#TableRequiredInfo font.Alert").parent().eq(0)).html()))
	{
		html = (jq = jQuery("table#TableDescription font.Alert").parent().eq(0)).html();
	}
	jq.css("display", "none");
	jQuery("table#TableInner").parent().append(html).css("background-color", "white");

	/* Correctly align captcha field - all forms */
	jQuery("td", jQuery("img#imgCaptcha").parent().parent().parent()).eq(2).css("text-align", "right");

	/* Change textarea size - all forms */
	if (jQuery("body.three_col_layout").length)
	{
		jQuery("textarea").addClass("input_three_col");
		jQuery("input[type='text']").addClass("input_three_col");
		jQuery("select").addClass("input_three_col");
		
		jq = jQuery("table#TableInner tr");
		for (i = 0, c = jq.length; i < c; i++)
		{
			if ((jq2 = jQuery("td", jq.eq(i))).length == 2)
			{
				jq2.eq(0).addClass("first_col");
			}
		}
	}
	else
	{
		jQuery("textarea").css("width", "352px");
		jQuery("textarea").css("height", "80px");
	}

	/* Substitue Submit button - all forms except donation form */
	if (!((jq = jQuery("input.HtmlButton[type='button']")).length))
	{
		jq = jQuery("input.HtmlButton[type='submit']")
	}
	
	if (jq.length && !document.getElementById("FormDonation"))
	{
		switch (this.getURLC())
		{
			case "fdKHIMNpEoG":
			/* Hack on German site because of too long language */
				if ((n = document.getElementById("switch_label_text_a")) &&
				    ((jq2 = jQuery("form#ContactForm textarea[name='Field4694380']").eq(0)).length))
				{
					jq3 = jq2.parent().parent().parent();
					jq3.before
					(
						'<tr>'+
							'<td colspan="3" align="left">'+
								'<font class="CT">'+n.innerHTML+'</font>'+
								'<font class="Alert">*</font>'+
							'</td>'+
						'</tr>'+
						'<tr>'+
							'<td colspan="3" align="left" id="switch_label_text_a_it">'+
							'</td>'+
						'</tr>'
					);
					jQuery("td#switch_label_text_a_it").append(jq2);
					jq3.css("display", "none");
				}
				break;
		}

		if (!window.location.href.match(/\/login.asp/i) ||
				(window.location.href.match(/\/login.asp/i) && window.navigator.userAgent.match(/msie/i)))
		{
			jq.after(this.sprintSubmitButton(jq.attr("onclick"), "BTN_SUBMIT", ".GIF"));

			jq.css("display", "none");
		}
	}

	if (el = liltype.ds("FormDonation"))
	{
		this.fixDonationForm(el);
	}
	else if (el = liltype.ds("frmAdvocacy"))
	{
		this.fixAdvocacyForm(el);
	}
	else if (el = liltype.ds("ContactForm"))
	{
		this.fixContactForm(el);
	}
	else if (window.location.href.match(/\/login.asp/i))
	{
		this.fixLoginForm(jQuery("form"));
	}
	
	this.genericXlate();
}

liltype.ifaw.setDonationOther = function(form)
{
	var amtEl = form.PledgeLevelOther;
	amtEl.value = amtEl.value.replace(/^([^\.]+)\..*$/g, '$1');
	amtEl.value = amtEl.value.replace(/[^0-9]/g, '');
	form.Amount.value = amtEl.value;
	jQuery("input#RadioOtherAmt", form).get(0).checked = true;
}

liltype.top().fixContactForm = function(form)
{
	var jq, jq_src;
	/* Remove check all icons - create account form */
	jQuery("img[src='/spherelite/images/allchecks.gif']", form).parent().parent().css("display", "none");

	jq_src = null;
	if ((jq = jQuery("table#TableButton font.CT strong.form_footnote", form)).length)
	{
		jQuery("strong", jq.parent()).css("display", "none");
		if (jQuery("br", jq.parent()).length > 1)
		{
			jQuery("br", jq.parent()).eq(1).css("display", "none");
		}
		jq.parent().parent().css("display", "none");
		jq_src = jq.parent();
	}
	
	if (jq_src &&
	    ((jq = jQuery("table.CTtablein font.CTtablein strong.segmentation_selector", form)).length))
	{
		jq.after(jq_src);
	}
}

liltype.top().fixDonationForm = function(form)
{
	var i, c, jq, tds, tr, jqsrc, submit_button_lang_ext, swap_submit_button, currency_symbol;
	var jqCtxt = jQuery(form);
	
	submit_button_lang_ext = "";
	currency_symbol = "$";
	swap_submit_button = true;
	switch (this.getURLC())
	{
		case "muIVLcMQJpE":
			submit_button_lang_ext = "-NL";
			return;
			break;
		case "fdKHIMNpEoG":
			submit_button_lang_ext = "-DE";
			currency_symbol = "&euro;";
			swap_submit_button = false;
			break;
		case "goIJLPOnGjF":
		/* FR-fr */
			submit_button_lang_ext = "-FR";
			currency_symbol = "&euro;";
			swap_submit_button = false;
			break;
		case "ljJXJ8MLIsE":
		/* CA-fr */
			submit_button_lang_ext = "-FR";
			swap_submit_button = false;
			break;
		case "fdJHKLNmFmG":
			submit_button_lang_ext = "-CN";
			swap_submit_button = false;
			break;
		case "kiKSL4PNLvF":
			submit_button_lang_ext = "-RU";
			swap_submit_button = false;
			break;
		case "hfILKWOBJqG":
			submit_button_lang_ext = "-ES";
			swap_submit_button = false;
			break;
		case "fdKHIQNpEkG":
			submit_button_lang_ext = "-JP";
			swap_submit_button = false;
			break;

		case "mkIVL6MQJvE":
			currency_symbol = "&euro;";
			break;

		case "kiKRL6POLtF":
			currency_symbol = "&pound;";
			break;
	}

	/* 
		- Hide "Level" row from table
		- Make donation levels line up horizontally, not vertically
		- Add "other ammount"
		- Add "min free gift text"
		- Add "free gift" checkbox
	*/
		if ((jq = jQuery("table#TablePledgeLevelInner", jqCtxt)).length)
		{
			tds = jQuery("td", jq);
			for (i = 0, c = tds.length; i < c; i++)
			{
				if (i < 2)
				{
					tr = jQuery(tds.get(i).parentNode);
					tds.eq(i).css("display", "none");
				}
				else
				{
					tr.append(tds.eq(i).css("background-image", "none"));
				}
			}
			
			/* Donation "Other" Amount */
			tr.append
			(
				'<td nowrap="nowrap" style="background-image: none;">'+
				'	<font class="CT">&nbsp; <input name="PledgeLevelID" value="t" onclick="liltype.ifaw.setDonationOther(this.form);" id="RadioOtherAmt" type="radio" /> &nbsp;</font>'+
				'</td>'+
				'<td valign="middle" style="background-image: none;">'+
				'	<font class="CT"><span class="donation_level_other">Other</span> '+currency_symbol+'</font>&nbsp;<input class="pledge_level_other" name="PledgeLevelOther" value="" onchange="liltype.ifaw.setDonationOther(this.form);" type="text" maxlength="12" size="12"/><font class="CT">.00</font>'+
				'</td>'
			);

			/* Move "Free Gift" checkbox */
			var freeGiftFields = new Array("Field4692771", "Field4695312", "Field4695311", "Field4695313", "Field4695314", "Field4695315", "Field4695316");
			for (i = 0, c = freeGiftFields.length; i < c; i++)
			{
				if ((jqsrc = jQuery("input[name='"+freeGiftFields[i]+"']", jqCtxt)).length)
				{
					jqsrc.parent().parent().parent().css("display", "none");
					jq.after(jqsrc.parent());
			
					/* Donation free gift blurb */
					jq.after("<div><font class=\"CT\"><span class=\"donation_free_gift_txt\">($25 is the minimum donation for which you can receive a gift)</span></font></div>");
					break;
				}
			}
		}

	/*
		- Change action alert Blurb
	*/
		if ((jq = jQuery("input[name='CampaignID'][type='checkbox']", jqCtxt)).length)
		{
			jQuery("tr.CTsubtitle td font.CTtablein", jq.parent().parent().parent()).eq(0).html("<span class=\"sign_up_for_action_alerts\">Sign Up For Action Alerts</span>");
			jQuery("td font.CT b", jq.parent().parent()).eq(0).html("<span class=\"i_want_action_alerts\">I would like to receive IFAW Action Alerts</span>");
			if (jq.parent().parent().parent().get(0).tagName == "TBODY")
			{
				jq.parent().parent().parent().parent().addClass("donor_dotted_border");
			}
			else
			{
				jq.parent().parent().parent().addClass("donor_dotted_border");
			}
		}

	/*
		- Make button image
	*/
		if (swap_submit_button && (jq = jQuery("input#SubmitButton", jqCtxt)).length)
		{
			jq.after(this.sprintSubmitButton(jq.attr("onclick"), "BTN_DONATE", ".GIF"));
			jq.css("display", "none");
			jq.parent().addClass("donor_dotted_border");
		}

	/*
		START: translations
	*/
		var ctxtSrc = liltype.ds("donation_form_translations");

		if (ctxtSrc)
		{
			jQuery("table#TablePledgeLevelOuter font", jqCtxt).eq(0).html(jQuery("div.DonationLevelHeader", ctxtSrc).html());

			jQuery("span.donation_level_other", jqCtxt).eq(0).html(jQuery("div.DonationLevelOther", ctxtSrc).html());

			jQuery("span.donation_free_gift_txt", jqCtxt).eq(0).html(jQuery("div.FreeGiftMinNotice", ctxtSrc).html());

			if ((jq = jQuery(liltype.ds("RecurringOptionN"))).length)
			{
				jq2 = jq.parent();
				jq.parent().parent().prepend(jq);
				jq2.html(jQuery("div.RecurringOptionN", ctxtSrc).html());
			}

			if ((jq = jQuery(liltype.ds("Amount"))).length)
			{
				jQuery("label", jq.parent().parent().parent()).eq(0).html(jQuery("div.Amount", ctxtSrc).html());
			}

			if ((jq = jQuery(liltype.ds("RecurringOptionY"))).length)
			{
				jq2 = jq.parent();
				jq.parent().parent().prepend(jq);
				jq2.html(jQuery("div.RecurringOptionY", ctxtSrc).html());
			}

			if ((jq = jQuery(liltype.ds("RecurringAmount"))).length)
			{
				jQuery("td font", jq.parent().parent().parent().parent()).eq(0).html(jQuery("div.RecurringAmount", ctxtSrc).html());
			}

			if ((jq = jQuery(liltype.ds("BillingScheduleID"))).length)
			{
				jQuery("td font", jq.parent().parent().parent().parent()).eq(2).html(jQuery("div.BillingScheduleID", ctxtSrc).html());
				jQuery("td font", jq.parent().parent().parent().parent()).eq(5).html(jQuery("div.RecurringAmountNote", ctxtSrc).html());
			}

			if ((jq = jQuery(liltype.ds("CardName"))).length)
			{
				jQuery("td font label", jq.parent().parent().parent()).eq(0).html(jQuery("div.CardName", ctxtSrc).html());
			}

			if ((jq = jQuery(liltype.ds("CardNumber"))).length)
			{
				jQuery("td font label", jq.parent().parent().parent()).eq(0).html(jQuery("div.CardNumber", ctxtSrc).html());
			}

			if ((jq = jQuery("select[name='CardType']", jqCtxt)).length)
			{
				jQuery("td font", jq.parent().parent().parent()).eq(0).html(jQuery("div.CardType", ctxtSrc).html());
			}

			if ((jq = jQuery("select[name='CardExpmn']", jqCtxt)).length)
			{
				jQuery("td font", jq.parent().parent().parent()).eq(0).html(jQuery("div.CardExpmn", ctxtSrc).html());
			}

			if ((jq = jQuery(liltype.ds("CheckAddress"))).length)
			{
				jQuery("td font", jq.parent().parent().parent()).eq(1).html(jQuery("div.CheckAddress", ctxtSrc).html());
				jq.parent().parent().css("text-align", "right");
			}

			jQuery("span.sign_up_for_action_alerts", jqCtxt).eq(0).html(jQuery("div.SignUpForActionAlerts", ctxtSrc).html());

			jQuery("span.i_want_action_alerts", jqCtxt).eq(0).html(jQuery("div.ReceiveActionAlerts", ctxtSrc).html());

			if ((jq = jQuery(liltype.ds("SubmitButton"))).length)
			{
				jQuery("small", jq.parent().parent().parent()).eq(0).html(jQuery("div.SubmitProcessedMsg", ctxtSrc).html());
			}
		}
	/*
		END: translations
	*/
}

liltype.top().fixAdvocacyForm = function(form)
{
	var i, c, jqTgt, jqSrc, jqCtxt, el;
	
	if (el = liltype.ds("ad_Main_Lgn_H2"))
	{
		el.innerHTML = "<span>Log In<"+"/span>";
	}

	if (el = liltype.ds("ad_Main_Lgn_wrpr"))
	{
		el.innerHTML =
			'<div class="right_col_bar"><div class="left_part"><'+'/div><'+'/div>'+
			el.innerHTML+'<div class="right_col_box_a_cap"><div class="left_part"><'+'/div><'+'/div>';
	}

	/* Swap login button, change "Please sign in to Login name: */
	jQuery("label.ad_sbmt", form).css("display", "none");
	jQuery("label[for='ctl00_ctl00_lgnLogin_txtUsername']").html("Login name:");

	els = document.getElementsByTagName("img");
	for (i = 0, c = els.length; i < c; i++)
	{
		el = els[i];
		if (el.className == "ad_Item")
		{
			el.style.borderLeft = "1px solid #dc8e2a";
			el.style.borderRight = "1px solid #dc8e2a";
			el.style.borderTop = "1px solid #dc8e2a";
			el.style.borderBottom = "1px solid #dc8e2a";
		}
	}

	if (jqSrc = liltype.ds("ctl00_ctl00_regRegister_cmdSubmitRegistration"))
	{
		jqSrc = jQuery(liltype.ds("ctl00_ctl00_regRegister_cmdSubmitRegistration"));
		jqSrc.css("width", "auto").css("height", "auto");
		jqSrc.after(this.sprintSubmitButton(jqSrc.attr("onclick"), "BTN_SUBMIT", ".GIF", {"name" : jqSrc.attr("name")}));
		jQuery("input.ifaw_custom_submit_button", jqSrc.parent()).css("width", "auto").css("height", "auto");
		jqSrc.remove();
	}

	jqCtxt = liltype.ds("ad_Reg_wpr");
	jQuery("h2#ad_Reg_H2", jqCtxt).css("display", "none");
	jQuery("p#ad_Reg_p", jqCtxt).css("display", "none");
	jQuery("fieldset.ad_MkLgn", jqCtxt).css("display", "none");
	jQuery("p#ad_MkLgn_p", jqCtxt).css("display", "none");
	jQuery("h3.legend", jqCtxt).eq(2).css("display", "none");
	jQuery("label.ad_chk", jqCtxt).css("display", "none");
	jQuery("input#ctl00_ctl00_regRegister_chkIsRemembered_Register", jqCtxt).css("display", "none");
	jQuery("label.ad_sbmt", jqCtxt).css("display", "none");
	
	jQuery("p#ad_RegInfo_p", jqCtxt).addClass("alert");
	jQuery("p#ad_RegInfo_p", jqCtxt).css("text-align", "right");

	jQuery("h3.legend", jqCtxt).eq(0).after(jQuery("p#ad_RegInfo_p", jqCtxt));

	/*
		START: translations
	*/
		if ((jqSrc = jQuery("div#action_form_translations")).length)
		{
			jqCtxt = jQuery(form);

			if ((jq = jQuery("input#ctl00_lgnLogin_txtUsername", jqCtxt)).length)
			{
				jq.prev().html(jQuery("div.UserName", jqSrc).html());
			}

			if ((jq = jQuery("input#ctl00_lgnLogin_txtPassword", jqCtxt)).length)
			{
				jq.prev().html(jQuery("div.Password", jqSrc).html());
			}

			if ((jq = jQuery("input#ctl00_lgnLogin_chkIsRemembered", jqCtxt)).length)
			{
				jq.next().html(jQuery("div.RememberMe", jqSrc).html());
				//jq.next().css("display", "inline");
			}

			if ((jq = jQuery("a.ad_forgot", jqCtxt)).length)
			{
				jq.html(jQuery("div.ForgotYourPassword", jqSrc).html());
			}

			if ((jq = jQuery("a.ad_join", jqCtxt)).length)
			{
				jq.html(jQuery("div.NotAMember", jqSrc).html());
			}
		}
	/*
		END: translations
	*/
}
	
liltype.top().fixLoginForm = function(form)
{
	var jqSrc = jQuery("div#action_form_translations");
	if (jqSrc.length)
	{
		jQuery("font", jQuery("input[name='LoginName']").parent().parent()).html(jQuery("div.UserName", jqSrc).html());
		jQuery("font", jQuery("input[name='Password']").parent().parent()).html(jQuery("div.Password", jqSrc).html());
		jQuery("td", jQuery("input[name='remember_me']").parent().parent()).eq(1).html(jQuery("div.RememberMe", jqSrc).html());
		jQuery("td", jQuery("a[href*='LoginRetrieval']").parent().parent()).eq(1).html(jQuery("div.RememberMe", jqSrc).html());
	}
}

	
liltype.top().initGenericXlate = function()
{
	var langCode = "";

	switch (this.getURLC())
	{
		case "muIVLcMQJpE":
			langCode = "NL";
			break;
		case "fdKHIMNpEoG":
			langCode = "DE";
			break;
		case "goIJLPOnGjF":
		case "ljJXJ8MLIsE":
			langCode = "FR";
			break;
		case "fdJHKLNmFmG":
			langCode = "CN";
			break;
		case "kiKSL4PNLvF":
			langCode = "RU";
			break;
		case "hfILKWOBJqG":
			langCode = "ES";
			break;
		case "fdKHIQNpEkG":
			langCode = "JP";
			break;
	}

	if (langCode)
	{
		document.write('<script src="/atf/cf/%7B0D7E718B-27F3-40CA-B62B-13D20CBBB1FC%7D/GENERIC-TRANSLATION-'+langCode+'.JS" type="text/javascript"><'+'/script>');
	}
}
liltype.top().initGenericXlate();

liltype.top().genericXlate = function()
{
	var i, c, jq;
	if (!this.genericTranslations)
	{
		return;
	}

	/* capcha */
	jQuery("caption", liltype.ds("TableButton")).html(this.genericTranslations.capcha+"<font color=\"red\">*<"+"/font>");

	/* required info */
	jq = jQuery("font.Alert");
	for (i = 0, c = jq.length; i < c; i++)
	{
		if (jq.eq(i).html().match(/required/i))
		{
			jq.eq(i).html("* "+this.genericTranslations.required);
		}
	}

	/* default select options */
	jq = jQuery("option");
	for (i = 0, c = jq.length; i < c; i++)
	{
		if (jq.eq(i).html().match(/\-\- please make a selection \-\-/i))
		{
			jq.eq(i).html("-- "+this.genericTranslations.selection+" --");
		}
	}
}
liltype.pop();

jQuery(document).ready
(
	function () 
	{
		window.parent.location.href= decodeURIComponent(window.name) + "#scrollup";
		
		if (document.getElementById("FormDonation"))
		/* Add verisign logo */
		{
			jQuery("body").append('<div style="text-align: center;"><img src="/atf/cf/%7B0D7E718B-27F3-40CA-B62B-13D20CBBB1FC%7D/VERISIGN-LOGO.GIF" alt="Verisign" width="108" height="57" border="0" /><'+'/div>');
		}
	}
);


jQuery(document).ready
(
	function()
	{
		var m, t, f, params = {}, i, c, k, f;
		try
		{
			if (m = decodeURIComponent(window.name).match(/\?([^\#]+)(\#|$)/))
			{
				m = m[1].split(/\&/);
				for (i = 0, c = m.length; i < c; i++)
				{
					t = m[i].split(/=/);
					params[decodeURIComponent(t[0].replace(/\+/, " "))] = decodeURIComponent(t[1].replace(/\+/, " "));
				}

				if (c)
				{
					f = jQuery("#ContactForm");
					for (k in params)
					{
						if ((n = jQuery("input[name='"+k+"']", f)).length)
						{
							n.val(params[k]);
						}
					}
				}
			}
		}
		catch(e)
		{
			//Ignore
		}
	}
);

