﻿try
{
	KSLaw.Internet.Navigation = {};
}
catch(ex)
{
	KSLaw = { Internet: { Navigation: {} } };
}

KSLaw.Internet.Navigation.SearchBox = 
{
	checkSearchbasicsearch: function()
	{
		var searchForm = document.getElementById("basicsearch");
		for (var i = 0; i < searchForm.elements.length; i++)
		{
			if (searchForm.elements[i].name == "us_SearchText" && searchForm.elements[i].value != "")
			{
				return true;
			}
		}
		return false;
	},

	submitSearchbasicsearch: function()
	{
		if (this.checkSearchbasicsearch())
		{
			var searchForm = document.getElementById("basicsearch");
			searchForm.submit();
		}
		else
		{
			alert('Please enter criteria to search the King & Spalding site.');
		}
	},

	handleKeyDownbasicsearch: function(evt)
	{
		evt = (evt) ? evt : ((event) ? event : null);
		if (evt.keyCode == 13)
		{
			if (this.checkSearchbasicsearch())
			{
				return true;
			}
			else
			{
				alert('Please enter criteria to search the King & Spalding site.');
				return false;
			}
		}
		return true;
	},

	clearDefaultText: function(input)
	{
		if (input.value == "Search K&S")
			input.value = "";
	},

	setDefaultText: function(input)
	{
		if (input.value == "")
			input.value = "Search K&S";
	}
};


KSLaw.Internet.Navigation.notAvailable = function()
{
	alert("This feature is not available yet, and nobody knows if it ever will...");
	return false;
}




KSLaw.Internet.Navigation.TranslateMenu =
{
	init: function()
	{
		var menu = document.getElementById("TranslateActionLink");

		if (!menu)
			return;

		menu.onclick = function(e) { KSLaw.Internet.Navigation.TranslateMenu.showTranslateMenu(); };
		menu.onmouseover = function(e) { KSLaw.Internet.Navigation.TranslateMenu.showTranslateMenu(); };
		menu.onmouseout = function(e) { KSLaw.Internet.Navigation.TranslateMenu.hideTranslateMenu(e); };

		var div = document.createElement("div");
		//menu.appendChild(div);
		document.body.appendChild(div);

		div.id = "TranslateMenuPopup";
		//div.onmouseover = function(e) { KSLaw.Internet.Navigation.TranslateMenu.showTranslateMenu(); };
		div.onmouseout = function(e) { KSLaw.Internet.Navigation.TranslateMenu.hideTranslateMenu(e); };
		div.style.left = "0px";
		div.style.top = "0px";
		var point = KSLaw.Internet.Core.getLocation(menu);
		div.style.left = point.x + "px";
		div.style.top = point.y + 21 + "px";
	},

	showTranslateMenu: function(e)
	{
		var menu = document.getElementById("TranslateActionLink");
		var menupopup = document.getElementById("TranslateMenuPopup");

		var point = KSLaw.Internet.Core.getLocation(menu);
		menupopup.style.left = point.x + "px";
		menupopup.style.top = point.y + 21 + "px";

		menupopup.style.display = "block";
	},

	hasParent: function(element, id)
	{
		if (!element || element == undefined)
			return false;

		if (element.parentNode == undefined && element.id == undefined)
			return false;

		while (element.parentNode != undefined)
		{
			element = element.parentNode;
			if (element.id == id)
				return true;
		}

		return false;
	},

	hideTranslateMenu: function(e)
	{
		if (!e)
			var e = window.event;
		var target = e.relatedTarget || e.toElement;

		if (!this.hasParent(target, "TranslateActionLink") && !this.hasParent(target, "TranslateMenuPopup"))
		{
			var menupopup = document.getElementById("TranslateMenuPopup");
			menupopup.style.display = "none";
		}
	},

	updateTranslateMenu: function(locales, currentLocale)
	{
		var menupopup = document.getElementById("TranslateMenuPopup");

		if (!menupopup)
			return;

		var languages = this.parseLocales(locales);

		if (languages.length == 0)
			return;

		if (currentLocale == undefined || currentLocale == null || currentLocale == "" || currentLocale == "EMPTY_STRING")
			currentLocale = "en";

		if (languages.length == 1 && languages[0].locale == currentLocale)
			return;

		var menu = document.getElementById("TranslateActionLink");
		menu.style.display = "inline-block";

		//debugger;
		for (var i = 0; i < languages.length; i++)
		{
			var div = document.createElement("div");
			menupopup.appendChild(div);

			var anchor = document.createElement("a");
			div.appendChild(anchor);

			if (document.location.search != "")
			{
				if (document.location.search.indexOf("ss_locale=") == -1)
					anchor.href = document.location.search + "&ss_locale=" + languages[i].locale;
				else
				{
					anchor.href = document.location.search.replace(/ss_locale=../i, "ss_locale=" + languages[i].locale);
				}
			}
			else
				anchor.href = "?ss_locale=" + languages[i].locale;
			anchor.innerHTML = languages[i].name;
		}
	},

	getLocaleName: function(locale)
	{
		switch (locale.toLowerCase())
		{
			case "en":
			case "en-us":
				return "ENGLISH";
				break;
			case "ar":
			case "ar-ae":
				return "&#1575;&#1604;&#1604;&#1594;&#1577; &#1575;&#1604;&#1593;&#1585;&#1576;&#1610;&#1577;";
				break;
			case "es":
				return "ESPAÑOL";
				break;
			case "fr":
				return "FRANÇAIS";
				break;
			case "de":
				return "DEUTSCHE";
				break;
			case "ru":
				return "РУССКИЙ";
				break;
		}
	},

	parseLocales: function(locales)
	{
		var languages = new Array();

		if (locales.length > 0)
		{
			var joinedLocales = locales.join(",").split(",").sort();

			for (var locale = joinedLocales.shift(); locale != null; locale = joinedLocales.shift())
			{
				if (locale != "EMPTY_STRING" && (languages.length == 0 || languages[languages.length - 1].locale != locale))
					languages.push({ "locale": locale, "name": this.getLocaleName(locale) });
			}
		}

		return languages;
	}
};


//SHARE BUTTON SCRIPTS

KSLaw.Internet.Navigation.ShareMenu = function (holderId, contentId)
{
	var ID = "divShareMenuPopup", HEIGHT = 20;

	this.init = function ()
	{
		var h = document.getElementById(holderId);
		if (!h)
			return;
		h.onmouseover = function (e) { open(); };
		h.onmouseout = function (e) { close(e); };
		var div = document.createElement("div");
		div.id = ID;
		div.style.position = "absolute";
		div.style.display = "none";
		var c = document.getElementById(contentId);
		var tbl = KSLaw.Internet.Core.getChildrenByTagName(c, "TABLE", true)[0], img = null;
		for (var i = 0; i < tbl.rows.length; i++)
		{
			// preload all images
			img = document.createElement("IMG");
			img.src = tbl.rows[i].getAttribute("roll");
			img.src = tbl.rows[i].getAttribute("idle");
			// set idle rows
			shareRowSet(tbl.rows[i], false);
		}
		div.innerHTML = c.innerHTML;
		c.innerHTML = "";
		document.body.appendChild(div);
		div.onmouseout = function (e) { close(e); };
	};
	var open = function ()
	{
		var c = document.getElementById(ID);
		var p = KSLaw.Internet.Core.getLocation(document.getElementById(holderId));
		c.style.left = p.x + "px";
		c.style.top = p.y + HEIGHT + "px";
		c.style.display = "";
	};
	var close = function (e)
	{
		if (!e) e = window.event;
		var target = e.relatedTarget || e.toElement;
		if (KSLaw.Internet.Core.getParentById(target, ID) == null)
			document.getElementById(ID).style.display = "none";
	};
};
function shareRowSet(row, over)
{
	row.className = over ? "shareTrOver" : "shareTrOut";
	KSLaw.Internet.Core.getChildrenByTagName(row, "IMG", true)[0].src = row.getAttribute(over ? "roll" : "idle");
};
function shareRowClick(row)
{
	window.open(row.getAttribute("url") + window.location);
};

// email disclaimer function
function emailAgreement(emailAddress)
{
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open('http://www.kslaw.com/EmailAgreement?Email=' + emailAddress, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=400,height=350');");
};


// This is the implementation of SimpleSwap
// by Jehiah Czebotar
// Version 1.1 - June 10, 2005
// Distributed under Creative Commons
//
// Include this script on your page
// then make image rollovers simple like:
// <img src="/images/ss_img.gif" oversrc="/images/ss_img_over.gif">
//
// http://jehiah.com/archive/simple-swap
// 


function SimpleSwap(el,which){
  el.src=el.getAttribute(which || "origsrc");
}

function SimpleSwapSetup(){
  var x = document.getElementsByTagName("img");
  for (var i=0;i<x.length;i++){
    var oversrc = x[i].getAttribute("oversrc");
    if (!oversrc) continue;
      
    // preload image
    // comment the next two lines to disable image pre-loading
    x[i].oversrc_img = new Image();
    x[i].oversrc_img.src=oversrc;
    // set event handlers
    x[i].onmouseover = new Function("SimpleSwap(this,'oversrc');");
    x[i].onmouseout = new Function("SimpleSwap(this);");
    // save original src
    x[i].setAttribute("origsrc",x[i].src);
  }
}

var PreSimpleSwapOnload =(window.onload)? window.onload : function(){};
window.onload = function(){PreSimpleSwapOnload(); SimpleSwapSetup();}

