// ATL JavaScript include

// Cookie class
function Cookie(document, name, hours, path, domain, secure) {
	this.$document = document;
	this.$name = name;
	
	if (hours)
		this.$expiration = new Date((new Date()).getTime() + hours * 3600000);
	else
		this.$expiration = null;
	
	if (path) this.$path = path; else this.$path = null;
	if (domain) this.$domain = domain; else this.$domain = null;
	if (secure) this.$secure = true; else this.$secure = false;
}

function _Cookie_Store() {
	var cookieval = "";
	for (var prop in this) {
		if ((prop.charAt(0) == '$') || ((typeof this[prop]) == 'function'))
			continue;
		if (cookieval != "") cookieval += '&';
		cookieval += prop + ':' + escape(this[prop]);
	}
	
	var cookie = this.$name + '=' + cookieval;
	if (this.$expiration)
		cookie += '; expires=' + this.$expiration.toGMTString();

	if (this.$path) cookie += '; path=' + this.$path;
	if (this.$domain) cookie += '; domain=' + this.$domain;
	if (this.$secure) cookie += '; secure';
	
	this.$document.cookie = cookie;
}

function _Cookie_Load() {
	var allcookies = this.$document.cookie;
	if (allcookies == "") return false;
	
	var start = allcookies.indexOf(this.$name + '=');
	if (start == -1) return false;
	start += this.$name.length + 1;
	var end = allcookies.indexOf(';', start);
	if (end == -1) end = allcookies.length;
	var cookieval = allcookies.substring(start, end);
	
	var a = cookieval.split('&');
	for (var i = 0; i < a.length; i++)
		a[i] = a[i].split(':');
	
	for (var i = 0; i < a.length; i++) {
		this[a[i][0]] = unescape(a[i][1]);
	}
	
	return true;
}

function _Cookie_Remove() {
	var cookie;
	cookie = this.$name + '=';
	if (this.$path) cookie += '; path=' + this.$path;
	if (this.$domain) cookie += '; domain=' + this.$domain;
	cookie += '; expires=Fri, 02-Jan-1970 00:00:00 GMT';
	
	this.$document.cookie = cookie;
}

new Cookie();
Cookie.prototype.store = _Cookie_Store;
Cookie.prototype.load= _Cookie_Load;
Cookie.prototype.remove = _Cookie_Remove;
// Cookie class

// Clipboard functions
var clipboard=null;

function addToClipboard(id) {
	if (clipboard.entries == null) clipboard.entries = new Array();
	for (var i = 0; i < clipboard.entries.length; i++) {
		if (clipboard.entries[i] == id) {
			alert("This provider is already on your clipboard");
			return false;
		}
	}

	clipboard.entries[clipboard.entries.length] = id;
	clipboard.store();
	alert("This provider has been added to your clipboard");
	//_alert("This provider has been added to your clipboard");
}

function removeFromClipboard(id) {
	if (clipboard.entries == null || clipboard.entries.length == 0) return false;

	var entries = new Array();

	for (var i = 0; i < clipboard.entries.length; i++) {
		if (clipboard.entries[i] != id && clipboard.entries[i] != null)
			entries[entries.length] = clipboard.entries[i];
	}
	clipboard.entries = entries;

	clipboard.store();
	window.location.reload(true);
}

function clearClipboard() {
	if (! confirm("Are you sure you want to clear your clipboard?")) return false;
//	if (! _confirm("Are you sure you want to clear your clipboard?")) return false;
	clipboard.entries.length = 0;
	clipboard.store();
	window.location.reload(true);
}

function init_clipboard() {
	clipboard = new Cookie(document, "LL_Clipboard", 24, "/");
	if (!clipboard.load() || !clipboard.entries) {
		clipboard.entries = new Array();
	}
	else {
		clipboard.entries = clipboard.entries.split(',');
	}

	clipboard.store();
}
// Clipboard functions

// Menu functions
var leftX = 0;
var rightX = 0;
var topY = 0;
var bottomY = 0;
var lastMenu = null;

if (document.all)    {n=1;ie=2;fShow="visible";fHide="hidden";}
if (document.layers) {n=2;ie=1;fShow="show";   fHide="hide";}

nsOffset = new Array();

function displaySubMenu(id) {
	hideLast();
	if (document.layers && document.layers[id + "_submenu"]) {
		document.layers[id + "_submenu"].left = (window.innerWidth - 740) / 2 - 10 + nsOffset[id];

		document.layers[id + "_submenu"].top = 110;
		document.layers[id + "_submenu"].visibility = "visible";

		leftX  = document.layers[id + "_submenu"].left;
		rightX = leftX + document.layers[id + "_submenu"].clip.width;
		topY  = document.layers[id + "_submenu"].top;
		bottomY = topY + document.layers[id + "_submenu"].clip.height;
	}
	else if (document.all && document.all[id + "_submenu"]) {
		document.all[id + "_submenu"].style.left = totalOffset(document.all[id], 'offsetLeft');
		document.all[id + "_submenu"].style.top = totalOffset(document.all[id], 'offsetTop') + 15;
		document.all[id + "_submenu"].style.visibility = "visible";

		leftX = document.all[id + "_submenu"].style.posLeft;
		rightX = leftX + document.all[id + "_submenu"].offsetWidth;
		topY = document.all[id + "_submenu"].style.posTop;
		bottomY = topY + document.all[id + "_submenu"].offsetHeight;
	}

	if (document.images && document.images[id + "_img"])
		document.images[id + "_img"].src = "images/menu/menu_" + id + "_over.gif";

	lastMenu = id;
}

function hideLast() {
	if (document.images && document.images[lastMenu + "_img"])
		document.images[lastMenu + "_img"].src = "images/menu/menu_" + lastMenu + "_up.gif";

	if (document.layers && document.layers[lastMenu + "_submenu"])
		document.layers[lastMenu + "_submenu"].visibility = "hidden";
	else if (document.all && document.all[lastMenu + "_submenu"])
		document.all[lastMenu + "_submenu"].style.visibility = "hidden";
}

function updateMenu(e) {

	if (! (document.layers && document.layers[lastMenu + "_submenu"]) 
			|| (document.all && document.all[lastMenu + "_submenu"])) {
	
		return;
	}
			

	if (document.all) {
		var x = window.event.clientX;
		var y = window.event.clientY;

		//if (x > rightX || x < leftX || y < topY - 20 || y > bottomY) { hideLast(); }
		if (x > rightX || x < leftX) { hideLast(); }
	}
	else if (document.layers) {
		var x = e.pageX;
		var y = e.pageY;

		//if (x > rightX || x < leftX || y < topY - 20 || y > bottomY) { hideLast(); }
		if (x > rightX || x < leftX) { hideLast(); }
	}
}

function totalOffset(id, offset) {
	var totalOffset = 0;
	var item = eval('id');

	do {
		totalOffset += eval('item.' + offset);
		item = eval('item.offsetParent');
	} while (item != null);

	return totalOffset;
}

function goToCategory(category) {
	if (category == '' || category == null) {
		return false;
	}

	if (category == 'CelebrityAgency') {
		window.location='/celebrities.html';
		return false;
	}
	else if (category == 'TVCrew') {
		window.location='/tvcrew.html';
		return false;
	}
	
	pt = document.categoryform.LL_ProviderType;
	for(i = 0; i < pt.options.length; i++) {
		if (pt.options[i].value == category) {
			pt.selectedIndex = i;
			//document.categoryform.submit();
			window.location='/forms/?LL_ProviderType=' + pt.options[i].value;
		}
	}
	
	return false;
}
function init_menu() {
	if (document.images) {
		var menu_up = new Array();
		menu_up[0] =  new Image(); menu_up[0].src  = 'images/menu_helpdesk_up.gif';
		menu_up[1] =  new Image(); menu_up[1].src  = 'images/menu_logfiles_up.gif';
		menu_up[2] =  new Image(); menu_up[2].src  = 'images/menu_resources_up.gif';
		menu_up[3] =  new Image(); menu_up[3].src  = 'images/menu_operations_up.gif';
		menu_up[4] =  new Image(); menu_up[4].src  = 'images/menu_training_up.gif';
		menu_up[5] =  new Image(); menu_up[5].src  = 'images/menu_media_up.gif';
		menu_up[6] =  new Image(); menu_up[6].src  = 'images/menu/menu_contacts_up.gif';

		var menu_over = new Array();
		menu_over[0]  = new Image(); menu_over[0].src  = 'images/menu_helpdesk_over.gif';
		menu_over[1]  = new Image(); menu_over[1].src  = 'images/menu_logfiles_over.gif';
		menu_over[2]  = new Image(); menu_over[2].src  = 'images/menu_resources_over.gif';
		menu_over[3]  = new Image(); menu_over[3].src  = 'images/menu_operations_over.gif';
		menu_over[4]  = new Image(); menu_over[4].src  = 'images/menu_training_over.gif';
		menu_over[5]  = new Image(); menu_over[5].src  = 'images/menu_media_over.gif';
		menu_over[6]  = new Image(); menu_over[6].src  = 'images/menu_contacts_over.gif';
	}

	if (document.all) {
		document.body.onclick = hideLast;
		document.body.onscroll = hideLast;
		document.body.onmousemove = updateMenu;
	}

	else if (document.layers) {
		document.onmousedown = hideLast;
		window.captureEvents(Event.MOUSEMOVE);
		window.onmousemove = updateMenu;

		nsOffset.helpdesk = 291;
		nsOffset.logfiles = nsOffset.helpdesk +  + document.images["helpdesk_img"].width;
		nsOffset.resources = nsOffset.logfiles +  + document.images["logfiles_img"].width;
		nsOffset.operations = nsOffset.resources +  + document.images["resources_img"].width;
		nsOffset.media = nsOffset.operations +  + document.images["operations_img"].width;
		nsOffset.training = nsOffset.media +  + document.images["media_img"].width;
		nsOffset.contacts = nsOffset.training +  + document.images["training_img"].width;
	}
}
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_jumpMenuGo(selName,targ,restore){ //v3.0
  var selObj = MM_findObj(selName); if (selObj) MM_jumpMenu(targ,selObj,restore);
}

// Menu functions

