/*
	OCEA Tools
*/
	jQuery.noConflict();
	OCEA = new Object();
	
	OCEA.badEmailDomains = new Array
	(
		/\@sheriff-fin\..+$/i,
		/\@danapoint\..+$/i,
		/\@cdc.\..+$/i,
		/\@ocwr\..+$/i,
		/\@hhs\..+$/i,
		/\@factoc\..+$/i,
		/\@altdef\..+$/i,
		/\@occl\..+$/i,
		/\@newportbeachca\..+$/i,
		/\@acsd\..+$/i,
		/\@auhsd\..+$/i,
		/\@losal\..+$/i,
		/\@occr\..+$/i,
		/\@ocparks\..+$/i,
		/\@garden-grove\..+$/i,
		/\@cfcoc\..+$/i,
		/\@ocpw\..+$/i,
		/\@ocwd\..+$/i,
		/\@pfrd\..+$/i,
		/\@comm\..+$/i,
		/\@papg\..+$/i,
		/\@ocvcd\..+$/i,
		/\@ocpll\..+$/i,
		/\@ocfa\..+$/i,
		/\@occourt\..+$/i,
		/\@occourts\..+$/i,
		/\@csa\..+$/i,
		/\@ttc\..+$/i,
		/\@pubdef\..+$/i,
		/\@rov\..+$/i,
		/\@ocprob\..+$/i,
		/\@prob\..+$/i,
		/\@pdsd\..+$/i,
		/\@ocers\..+$/i,
		/\@ocair\..+$/i,
		/\@iad\..+$/i,
		/\@hcd\..+$/i,
		/\@hcs\..+$/i,
		/\@ocpl\..+$/i,
		/\@coco\..+$/i,
		/\@ceoit\..+$/i,
		/\@rec\..+$/i,
		/\@iwmd\..+$/i,
		/\@ocsdfinancial\..+$/i,
		/\@ocsd\..+$/i,
		/\@fss\..+$/i,
		/\@da\..+$/i,
		/\@ochca\..+$/i,
		/\@css\..+$/i,
		/\@assessor\..+$/i,
		/\@ocgov\..+$/i,
		/\@rdmd\..+$/i,
		/\@ac\..+$/i,
		/\@ssa\..+$/i,
		/\@occr\..+$/i,
		/\@ascdef\..+$/i,
		/\@oclafco\..+$/i,
		/\@ci\..+$/i,
		/\@city\..+$/i,
		/\@.*mesawater\..+$/i,
		/\@.*anaheim\..+$/i,
		/\@.*yorba-linda\..+$/i,
		/\@.*san-clemente\..+$/i,
		/\@.*missionviejo\..+$/i,
		/\@.*tustinca\..+$/i
	);
	
	OCEA.getURLB = function(url)
	{
		var r;
		url = url ? url :  window.location.href;
		if (r = url.match(/\/b\.([0-9]+)\//))
		{
			return r[1];
		}
		else if (r = url.match(/(\?|\&)b=([0-9]+)(\&|$)/))
		{
			return r[2];
		}
	}
	
	OCEA.getURLC = function(url)
	{
		var r;
		url = url ? url :  window.location.href;
		if (r = url.match(/\/c\.([0-9a-z]+)\//i))
		{
			return r[1];
		}
		else if (r = url.match(/(\?|\&)c=([0-9a-z]+)(\&|$)/i))
		{
			return r[2];
		}
	}
	
	OCEA.fixPrimaryNavWidths = function(widths, selector)
	{
		var jq = jQuery(selector), imgStub;
		for (i = 0, c = jq.length; i < c; i++)
		{
			jq.eq(i).css("width", widths[i]["width"]+"px");
			if (imgStub = widths[i]["background-image"])
			{
				jQuery("a", jq.eq(i)).eq(0).css("background-image", "url(/atf/cf/%7B7f82cdb3-cda6-46e5-bebe-99a9fdd69fa9%7D/"+imgStub+")").html("");
			}
		}
	}

	OCEA.promoActionBox = new Object();
	OCEA.promoActionBox.activeTabInd = null;
	OCEA.promoActionBox.tabCount = 0;
	OCEA.promoActionBox.jqc = null;

	OCEA.promoActionBox.activateTab = function(tabInd)
	{
		tabInd = Number(tabInd);
		if (this.activeTabInd !== null)
		{
			jQuery("div.content_"+this.activeTabInd, this.jqc).css("display", "none");
		}
		jQuery("div.content_"+tabInd, this.jqc).css("display", "block");
		this.activeTabInd = tabInd;
	}

	OCEA.promoActionBox.onTabClick = function()
	{
		var m = this.className.match(/(^|\s)tab_([0-9]+)(\s|$)/);
		OCEA.promoActionBox.activateTab(m ? m[2] : 0);
		return false;
	}

	OCEA.promoActionBox.onArrowLClick = function()
	{
		var box = OCEA.promoActionBox;
		if (box.activeTabInd == 0)
		{
			box.activateTab(box.tabCount - 1);
		}
		else
		{
			box.activateTab(box.activeTabInd - 1);
		}
		return false;
	}

	OCEA.promoActionBox.onArrowRClick = function()
	{
		var box = OCEA.promoActionBox;
		if (box.activeTabInd == box.tabCount - 1)
		{
			box.activateTab(0);
		}
		else
		{
			box.activateTab(box.activeTabInd + 1);
		}
		return false;
	}

	OCEA.promoActionBox.init = function(selector)
	{
		var jqGroups, jqTabs, jqContents;
		this.jqc = jQuery(selector);

		jqTabs = jQuery("div.tabs", this.jqc);
		jqContents = jQuery("div.contents", this.jqc);
		jqGroups = jQuery("div.group", this.jqc);
		for (i = 0, c = jqGroups.length; i < c; i++)
		{
			jQuery("div.tab a", jqGroups.eq(i)).addClass("tab_"+i).click(this.onTabClick);
			jqTabs.append(jQuery("div.tab", jqGroups.eq(i)));
			jqContents.append(jQuery("div.content", jqGroups.eq(i)).addClass("content_"+i).css("display", "none"));
			jqGroups.eq(i).css("display", "none");
			this.tabCount++;
		}
		jQuery("a.arrow_l", this.jqc).click(this.onArrowLClick);
		jQuery("a.arrow_r", this.jqc).click(this.onArrowRClick);
		this.activateTab(0);
	}

	OCEA.makeEnrollemtTOC = function()
	{
		var jqc = jQuery("div#enrollment_guide_container");
		var jq, imgStub, htmlToc;
		
		htmlToc = "";
		jq = jQuery("div.enrollment_guide_item h3", jqc)
		for (i = 0, c = jq.length; i < c; i++)
		{
			jq.eq(i).before('<a name="toc_item_'+i+'"> </a>');
			htmlToc +=
			 '<a href="#toc_item_'+i+'">'+jq.eq(i).html()+'</a>';
		}
		jQuery("div.enrollment_guide_toc_links", jqc).html(htmlToc);
	}


	OCEA.fixNutshellBox = function()
	{
		var jq, jqc = jQuery("div.in_a_nutshell div.content");
		jqc = jqc.eq(jqc.length - 1);
		
		jQuery("div.nutshell_data", jqc).css("display", "none");
	
		jq = jQuery("a.nutshell_link", jqc).click
		(
			function ()
			{
				var a = jQuery(this).toggleClass("visible");
				var div = a.next().toggleClass("visible");
				if (div.hasClass("visible"))
				{
					div.css("display", "block");
					jQuery("span.data_open", a).css("display", "inline");
					jQuery("span.data_closed", a).css("display", "none");
				}
				else
				{
					div.css("display", "none");
					jQuery("span.data_open", a).css("display", "none");
					jQuery("span.data_closed", a).css("display", "inline");
				}
				return false;
			}
		)
	}
	
	OCEA.fixDeptLocalNav = function(sections, skips)
	{
		var i, c, j, d, section, links, link, sublinks, state;
		var skipInd = new Array();
		var sectionInd = new Array();

		for (i = 0, c = skips.length; i < c; i++)
		{
			skipInd[skips[i]] = true;
		}
		
		for (i = 0, c = sections.length; i < c; i++)
		{
			sectionInd[sections[i]] = true;
		}
		
		links = jQuery("div#left ul.inThis a");
		for (i = 0, c = links.length; i < c; i++)
		{
			if (sectionInd[OCEA.getURLB((section = links.eq(i)).attr("href"))])
			{
				sublinks = jQuery("ul a", section.parent());
				for (j = 0, d = sublinks.length; j < d; j++)
				{							
					if (!skipInd[OCEA.getURLB((link = sublinks.eq(j)).attr("href"))])
					{
						link.parent().css("display", "none");
					}
				}
			}
		}
	}

	OCEA.sprintHeaderImgRot = function(srcDefault)
	{
		var jq;
		if ((jq = jQuery("div#header_rotating_image img")).length)
		{
			return jq.eq(Math.round(Math.random() * (jq.length - 1))).attr("src");
		}
		else
		{
			return srcDefault;
		}
	}

	jQuery("div#breadcrumb").ready
	(
		function()
		{
			var jq;
			if ((jq = jQuery("div#breadcrumb")).length)
			{
				jq.html(jq.html().substr(0, jq.html().lastIndexOf("&gt;")));
			}
		}
	);

	jQuery("table.CDtablein").ready
	(
		function()
		{
			var jqc = jQuery("table.CDtablein");
			var jq = jQuery("tr", jqc);
			jq.eq(0).addClass("row1");
			jq.eq(1).addClass("row2");
		}
	);

	jQuery(document).ready
	(
		function()
		{
			var jqc, jq, i, c, n;
			
			/* Strip out inline styles for all tables */
			jQuery("table").attr("style", "").attr("cellpadding", "0").attr("cellspacing", "0");

			/* Fix padding on some pages */
			if ((jqc = jQuery("body.two_col_layout")).length)
			{
				/* FF Bug w/ table widths */
				jQuery("table.ktf_web_feature td", jqc).eq(0).css("width", jQuery("table.ktf_web_feature", jqc).get(0).offsetWidth+"px");
			}
			
			/* Fix padding on some pages */
			jqc = jQuery("div#container");
			if (!jQuery("div.intMiddleFull", jqc).length &&
			    !jQuery("div#intMiddle3", jqc).length &&
			    !jQuery("div#right3", jqc).length  &&
			    !jQuery("div#middle3", jqc).length /* &&
			    (!(jq = jQuery("table.ktf_web_feature div", jqc).eq(0)).attr("class"))*/)
			{
				/* jq.addClass("intMiddleFull"); */
				jq = jQuery("table.ktf_web_feature", jqc).addClass("noinnertpl");
				jQuery("table[cellspacing='10']", jq).attr("cellspacing", "0");
			}
			
			/* Fix tables w/ hard coded cellpadding and cellspacing in content listings */
			if (jQuery("span.NLbody").length || jQuery("span.NLtitle").addClass("intMiddleFull").length)
			{
				(jq = jQuery("table.ktf_web_feature table")).attr("cellpadding", "0").attr("cellspacing", "0").css("width", "auto");
				jq.eq(0).css("width", jQuery("table.ktf_web_feature").get(0).offsetWidth+"px");
			}

			/* Fix inline news listing */
			jQuery("div#icl_container_inh ul li").eq(0).addClass("first");

			/* Fix Quick links graphic */
			if (jQuery.browser.mozilla && ((jq = jQuery("div.quick_links_box")).length))
			{
				jq.prev().get(0).src = jq.prev().get(0).src.replace(/\.png/, "-moz.gif");
			}

			/* Set banned email domains */
			jq = jQuery("input[type='text']");
			var ef = function()
			{
				var i, c;
				if (this.value.length)
				{
					for (i = 0, c = OCEA.badEmailDomains.length; i < c; i++)
					{
						if (this.value.match(OCEA.badEmailDomains[i]))
						{
							alert("Invalid Email Domain.  Official department/city email addresses are not accepted. Please use your personal home email address.");
							this.value = "";
							return;
						}
					}
				}
			}
			for (i = 0, c = jq.length; i < c; i++)
			{
				n = jq.eq(i).attr("name");
				if ((n.match(/mail/i)) &&
						(!n.match(/_[0-9]/i)))
				{
					jq.eq(i).blur(ef);
				}
			}

			/* Focus the login form */
			if (window.location.pathname.match(/login/i))
			{
				try
				{
					jQuery("form").get(0).elements.LoginName.focus();
				}
				catch (e)
				{
					// ignore
				}
			}
		}
	);
	
	jQuery("#maincontent").ready
	(
		function()
		{
			var ns, i, c;
			if ((ns = jQuery("#maincontent .venuebox")).length)
			{
				for (i = 0, c = ns.length; i < c; i++)
				{
					if (i % 3)
					{
						ns.eq(i).addClass("notfirst");
					}
				}
			}
		}
	);
	
	OCEA.fixTixPrimaryNav = function(primaryNavDat)
	{
		var html, i, c, a, lis = jQuery("ul#nav li.off"), dat, li;
		for (i = 0, c = lis.length; i < c; i++)
		{
			dat = primaryNavDat[i];
			li = lis.eq(i);
			a = jQuery("a", li.attr("id", dat[0])).eq(0);
			a.html("<span>"+a.html()+"</span>");

			if (dat[1] == 2)
			{
				jQuery("ul", li).addClass("tworow");
			}
		}
	}

	jQuery("div#kt_supporter_id").ready
	(
		function()
		{
			var j;
			if ((j = jQuery("div#kt_supporter_id")).length)
			{
				if (j.eq(0).html().match(/\*\*supporter_id\*\*/))
				{
					jQuery("img.buyonline").css("display", "none");
				}
			}
		}
	);
