liltype.ccp = new liltype();

liltype.push(liltype.ccp);

liltype.top().primaryNavXV = function(node)
{
	var parentNode, n;
	if (node.nodeType == 1)
	{
		if (node.nodeName == "LI")
		{
			if ((liltype.CNU.match(node.className, "level_2")) &&
					!this.expandedL2)
			{
				parentNode = liltype.GPN(node, "LI", "level_1");
				liltype.CNU.addToNode(parentNode, "expanded");
				liltype.CNU.delFromNode(parentNode, "collapsed");
				this.expandedL2 = true;
			}
		}
		else if (node.nodeName == "A")
		{
			if ((node.innerHTML.toLowerCase().replace(/\&[^\s;]+;/g, "").replace(/[^a-z0-9]/g, "") == this.docTitleMatch) &&
					(this.docTitleMatch != "home"))
			{
				liltype.CNU.addToNode(node, "active");
				parentNode = liltype.GPN(node, "LI");
				while (parentNode)
				{
					liltype.CNU.delFromNode(parentNode, "collapsed");
					liltype.CNU.addToNode(parentNode, "expanded");
					parentNode = liltype.GPN(parentNode, "LI");
				}
			}
		}
		else if ((node.nodeName == "DIV") && (node.id == "icl_container"))
		{
			node.parentNode.style.display = "none";
		}
	}
	return true;
}

liltype.top().initPrimaryNav = function(id)
{
	this.expandedL2 = false;
	this.docTitleMatch = document.title.toLowerCase().replace(/\|.+$/g, "").replace(/\&[^\s;]+;/g, "").replace(/[^a-z0-9]/g, "");
	this.pnxvc = 0;
	liltype.xVerseNode(liltype.ds(id), this, "primaryNavXV");
}

liltype.top().initPPFactsXV = function(node)
{
	var parentNode;
	if ((node.nodeType == 1) &&
	    (node.nodeName == "UL"))
	{
		this.facts.push(node);
		node.style.display = "none";
	}
	return true;
}

liltype.top().initPPFacts = function(id)
{
	this.facts = new Array();
	liltype.xVerseNode(liltype.ds(id), this, "initPPFactsXV");
	this.facts[Math.round(Math.random() * (this.facts.length - 1))].style.display = "inline";
	this.facts = null;
}


liltype.top().initAAHXV = function(node)
{
	var parentNode;
	if ((node.nodeType == 1) &&
	    (node.nodeName == "DIV") &&
	    (liltype.CNU.matchNode(node, "action_alert_item")))
	{
		this.aais.push(node);
		node.style.display = "none";
	}
	return true;
}

liltype.top().initAAH = function(id)
{
	this.aais = new Array();
	liltype.xVerseNode(liltype.ds(id), this, "initAAHXV");
	this.aais[Math.round(Math.random() * (this.aais.length - 1))].style.display = "block";
	this.aais = null;
}


liltype.top().initBreadCrumb = function(id, sectionCode)
{
	var rgs, regexp, understandHTML, node = liltype.ds(id);
	//var urlC = liltype.endoil.getURLC();

	if (node && node.innerHTML)
	{
		node.innerHTML = node.innerHTML.replace(/<a\s[^>]+>\s*<\/a>\s*\&gt;/i, "");
		//understandHTML = 
		//	'<a class="Path" href="http://www.kintera.org/site/c.'+urlC+'/b.4093913/">Understand</a> &gt;';
		regexp = new RegExp("(<a\\s[^>]+>Home</a>\\s+&gt;)", "i");

/*
		if (sectionCode)
		{
			switch (sectionCode)
			{
				case "fbg":
					node.innerHTML =
						node.innerHTML.replace(regexp, "$1 "+understandHTML+' <a class="Path" href="http://www.kintera.org/site/c.'+urlC+'/b.4090047/">Fool\'s Black Gold</a> &gt;');
					break;
				case "coc":
					node.innerHTML =
						node.innerHTML.replace(regexp, "$1 "+understandHTML+' <a class="Path" href="http://www.kintera.org/site/c.'+urlC+'/b.4090073/">Costs of Consumption</a> &gt;');
					break;
				case "sar":
					node.innerHTML =
						node.innerHTML.replace(regexp, "$1 "+understandHTML+' <a class="Path" href="http://www.kintera.org/site/c.'+urlC+'/b.4104349/">Science &amp; Research</a> &gt;');
					break;
				case "kth":
					node.innerHTML =
						node.innerHTML.replace(regexp, "$1 "+' <a class="Path" href="http://www.kintera.org/site/c.'+urlC+'/b.4090075/">Kick The Habit</a> &gt;');
					break;
				case "about":
					if (!document.title.match(/^\s*about\s*\|/i))
					{
						node.innerHTML =
							node.innerHTML.replace(regexp, "$1 "+' <a class="Path" href="http://www.kintera.org/site/lookup.asp?c='+urlC+'&b=4097567">About</a> &gt;');
					}
					break;
			}
		}
		else
		{
			switch (liltype.endoil.getURLB())
			{
				case "4090047":
				case "4090073":
				case "4104349":
					node.innerHTML =
						node.innerHTML.replace(regexp, "$1 "+understandHTML);
					break;
			}
		}
*/
		
		node.innerHTML = node.innerHTML.replace(/\&gt;\s+<font[^>]+>.+<\/font>/i, "");
	}
}


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().onClickSAS = function(a, code)
{
	switch (code)
	{
		case 'digg':
			a.href =
				"http://digg.com/submit?phase=2&url="+encodeURIComponent(window.location.href)+"&title="+encodeURIComponent(document.title)+"bodytext=&topic=environment";
			return true;
			break;
		case "hugg":
			this.formHugg.submit();
			return false;
			break;
		case "email":
			popUpDialogResizeableVarSize
			(
				"F1EE9E21EEF24BE888C44660079AF138",
				"email2friend",
				"/site/email2friend.asp?c="+this.getURLC()+"&b="+this.getURLB()+"&email_url="+escape("/site/pp.aspx?c="+this.getURLC()+"&b="+this.getURLB()),
				700,
				525
			);
			return false;
			break;
		case "newsvine":
			window.open("http://www.newsvine.com/_wine/save?popoff=1&u="+encodeURIComponent(window.location.href),"newsvine","toolbar=no,width=590,height=600,resizable=yes,scrollbars=yes");
			return false;
			break;
		case "facebook":
			var u=location.href;
			var t=document.title;
			window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
			break;
		case "del.icio.us":
			a.href="http://del.icio.us/post";
			window.open("http://del.icio.us/post?v=4&noui&jump=close&url="+encodeURIComponent(location.href)+"&title="+encodeURIComponent(document.title), "delicious","toolbar=no,width=700,height=400");
			return false;
			break;
/*
		case "print":
			a.href = 
				"http://www.kintera.org/site/pp.aspx?c="+this.getURLC()+"&b="+this.getURLB()+"&printmode=1";
			return true;
			break;
		case "furl":
			a.href =
				"http://www.furl.net/storeIt.jsp?u="+encodeURIComponent(window.location.href)+"&t="+encodeURIComponent(document.title);
			return true;
			break;
*/
	}
}

liltype.top().getOffsetTop = function(el)
{
	if (el.offsetParent)
	{
		return (isNaN(el.offsetTop) ? 0 : el.offsetTop) + this.getOffsetTop(el.offsetParent);
	}
	return isNaN(el.offsetTop) ? 0 : el.offsetTop;
}

liltype.top().hackHomePage = function()
{
	var navEl, boxEl, boxFootEl, navOffsetY, boxOffsetY, boxHeight;

	navOffsetY = 47; // Horizontal padding
	boxOffsetY = 12; // Horizontal padding
	navEl = liltype.ds("block-menu-72");
	boxEl = liltype.ds("hp_box_a_1");
	boxFootEl = liltype.ds("hp_box_a_foot_1");
	
	if (!boxEl.offsetHeight || !navEl.offsetHeight || !boxFootEl.offsetHeight)
	{
		setTimeout("liltype.ccp.hackHomePage();", 32);
		return;
	}
	
	boxHeight = boxEl.offsetHeight + boxFootEl.offsetHeight;
	
	if (boxHeight > navEl.offsetHeight)
	{
		navEl.style.height = (boxHeight  - navOffsetY)+"px";
	}
	else
	{
		boxEl.style.height = (navEl.offsetHeight - boxOffsetY)+"px";
	}
	
	navOffsetY = 10; // Horizontal padding
	boxOffsetY = 0; // Horizontal padding
	navEl = liltype.ds("block-block-21");
	boxEl = liltype.ds("hp_box_c_content_1");
	
	boxHeight = boxEl.offsetHeight + (this.getOffsetTop(boxEl) - this.getOffsetTop(navEl));

	if (boxHeight > navEl.offsetHeight)
	{
		navEl.style.height = (boxHeight - navOffsetY)+"px";
	}
	else
	{
		boxEl.style.height = (navEl.offsetHeight - boxOffsetY - (this.getOffsetTop(boxEl) - this.getOffsetTop(navEl)))+"px";
	}
	
}



liltype.top().contactFormHackXV = function(node)
{
	if (node.nodeType == 1)
	{
		if ((node.nodeName == "TD") &&
		    liltype.CNU.match(node.className, "CTtitle") &&
		    node.innerHTML.match(/contact\s+us/i))
		{
			node.style.display = "none";
		}
		else if ((node.nodeName == "TR") &&
		         liltype.CNU.match(node.className, "CTsubtitle"))
		{
			this.inCTSubtitleRow = true;
		}
		else if ((node.nodeName == "TD") &&
		         this.inCTSubtitleRow)
		{
			node.innerHTML += "<br/><font class=\"Alert\">* required information<"+"/font>";
			this.inCTSubtitleRow = false;
		}
		else if ((node.nodeName == "FONT") &&
		         node.innerHTML.match(/required\s+information/i) &&
		         !this.removedReqdInfo)
		{
			node.parentNode.parentNode.style.display = "none";
			this.removedReqdInfo = true;
		}
	}
	return true;
}

liltype.top().contactFormHack = function(id)
// Perform Various hacks to the Contact Form
{
	this.inCTSubtitleRow = false;
	this.removedReqdInfo = false;
	//liltype.xVerseNode(liltype.ds(id), this, "contactFormHackXV");
}

liltype.top().donateFormHackXV = function(node)
{
	if (node.nodeType == 1)
	{
		if ((node.nodeName == "B") && node.innerHTML.match(/general\s+subscription/i))
		{
			node.innerHTML = "I&rsquo;d Like to Get Clean Ports eNews Updates";
			return false;
		}
		else if ((node.nodeName == "TR") && 
						 liltype.CNU.match(node.className, "CTsubtitle") &&
						 node.innerHTML.match(/subscribe\s+to\s+our\s+enewsletter/i) && 
						 node.innerHTML.match(/<font[^>]*>/i) && 
						 node.innerHTML.match(/<b[^>]*>/i))
		{
			node.style.display = "none";
		}
		else if ((node.nodeName == "SELECT") &&
		         node.name &&
		         (node.name == "BillCountry"))
		{
			node.className = liltype.CNU.add(node.className, "bill_country");
		}
		else if (node.id == "donation_type_copy")
		{
			node.style.display = "none";
		}
	}
	return true;
}

liltype.top().donateFormHack = function(id)
// Perform Various hacks to the Join Us! Form
{
	liltype.xVerseNode(liltype.ds(id), this, "donateFormHackXV");
}

liltype.top().onJoinSubmit = function(form)
{
	var expry, rgs;

	expry = new Date();
	expry.setTime(expry.getTime() + 60000);

	document.cookie =
		"ccpje="+encodeURIComponent(form.email.value)+
		"; expires="+(expry.toUTCString ? expry.toUTCString() : expry.toGMTString())+
		"; path=/";

	document.cookie =
		"ccpjz="+encodeURIComponent(form.zip.value)+
		"; expires="+(expry.toUTCString ? expry.toUTCString() : expry.toGMTString())+
		"; path=/";

	return true;
}

liltype.top().onJoinLoad = function(formId)
{
	var rgs, form;
	form = liltype.ds(formId);

	rgs = document.cookie.match(/ccpje=([^;]+)(;|$)/);
	if (rgs && rgs[1].length)
	{
		form.email_address.value = decodeURIComponent(rgs[1]);
	}

	rgs = document.cookie.match(/ccpjz=([^;]+)(;|$)/);
	if (rgs && rgs[1].length)
	{
		form.zip.value = decodeURIComponent(rgs[1]);
	}
}
liltype.top().newsListingHack = function()
{
	var node, root, i, c;
	node = liltype.ds("listingPagination");
	if (node)
	{
		root = node.parentNode;
		for (i = 0, c = root.childNodes.length; i < c; i++)
		{
			node = root.childNodes[i];
			if (node && 
					(node.nodeType == 1) &&
					(node.nodeName == "SPAN"))
			{
				node.innerHTML = node.innerHTML.replace(/^\s*Date\s*Created:\s*/i, "");
			}
		}
	}
}

liltype.pop();

