/*
* Copyright (c) 2004 Lucid Technologies.
* All rights reserved.
*
* This software is the confidential and proprietary property of
* Lucid Technologies ('Confidential Information').  This Confidential
* Information and property shall only be used in strict accordance
* with the terms set forth in the Master Software License Agreement
* with Lucid Technologies.
*/

function chat() {
	alert("This service will be available shortly.\nPlease try again at a later time.");
}

function talk() {
	alert("This service will be available shortly.\nPlease try again at a later time.");
}

/*************************************************************
* Set global variables to use between validation methods
************************************************************/
var messagetmp = ""; // Temporary message storage
var isModified = false;
var targetpage = '';
var browserName = navigator.appName;
var browserVer = parseInt(navigator.appVersion);

/*************************************************************
* DELETE CONFIRMATION
************************************************************/
function confirmDelete(url)
{
	//return confirm("Are you sure you want to delete this item"+
	//	((desc != null) ? " ("+desc+")" : "")+"?");
	var confirmed = confirm("Are you sure you want to permanently delete this record?");
	if (url && confirmed) location = url;
	else if (url == null) return confirmed;
	else return false;
}

/******************************************************
* CSS DROP-DOWN MENU FUNCTIONS
*****************************************************/
var crrtTab = null;
function switchTab(id, group)
{
	// get parts to determine 1st in set
	var parts = id.split("_");
	var key = parts[0];
	var index = parts[1];

	// set default
	if (group == null) group = 0;
	if (crrtTab == null)
	{
		crrtTab = new Array();
		crrtTab[group] = key + "_" + 1;
	}

	// deactivate previous
	var old = document.getElementById(crrtTab[group]);
	if (old) old.className = "none";

	// activate current
	if (index)
	{
		var div = document.getElementById(id);
		div.className = "active";
		crrtTab[group] = id;
	}
}

/******************************************************
* Calendar day selection
*****************************************************/
var crrtCal;
function calClick(cal)
{
	if (crrtCal) document.getElementById(crrtCal).className = 'day';
	document.getElementById(cal).className = 'active';
	crrtCal = cal;
}


/******************************************************
* CSS DROP-DOWN MENU FUNCTIONS
*****************************************************/
var open_div = null;
function OpenAjax(box, params) {
	if (open_div != null) CloseAjax(open_div);
	document.getElementById("ajax").style.visibility = 'visible';
	document.getElementById("ajax_bg").style.display = '';
	document.getElementById("ajax_bg").style.height = "150%";
	document.getElementById("ajax_" + box).style.display = '';
	var pg = (box == "test") ? "Test" : "AjaxVideo";
	pg = (box == "address") ? "MyAddress" : pg;
	pg = (box == "social") ? "MySocial" : pg;
	pg = (box == "note") ? "Note" : pg;
	//getAjaxContent(pg + ".aspx", params, "ajax_" + box);
	open_div = box;
}
function CloseAjax(box) {
	document.getElementById("ajax").style.visibility = 'hidden';
	document.getElementById("ajax_bg").style.height = "auto";
	document.getElementById("ajax_bg").style.display = 'none';
	var div = document.getElementById("ajax_" + box);
	div.style.display = 'none';

	showIt(box + "_1");
	crrt2 = null;
	//div.innerHTML = '';
}

function showCell(id1, id2)
{
	if (id2 != null)
	{
		var old = document.getElementById(id2);
		old.style.display = "none";
	}
	var ele = document.getElementById(id1);
	var css = (ele.toString().indexOf("TableRow") > 0) ? "table-row" : "table-cell";
	ele.style.display = css;
}
function showMenu(id)
{
	var ele = document.getElementById(id);
	ele.style.display = (ele.style.display != 'block') ? "block" : "none";
}
var crrt = null, crrt2 = null, idx = null;
function show(div)
{
	if (crrt != null) hide(crrt);
	crrt = div;
	var obj = document.getElementById(div);
	if (obj != null) obj.style.visibility = 'visible';
}
function hide(div)
{
	if (div == null) return;
	var obj = document.getElementById(div);
	if (obj != null) obj.style.visibility = 'hidden';
}
function showIt(div, num)
{
	if (num != null) idx = num;
	if (crrt2 == null && div.indexOf("_") > 0) crrt2 = div.split("_")[0] + "_1";
	if (crrt2 != null) hideIt(crrt2);
	crrt2 = div;
	var obj = document.getElementById(div);
	if (obj != null) obj.style.display = 'block';
	//if (obj != null) obj.style.visibility = 'visible';
}
function hideIt(div, num)
{
	var obj = document.getElementById(div);
	//if (obj != null) obj.style.visibility = 'hidden';
	if (obj != null) obj.style.display = 'none';
}
function next(name, num, max)
{
	var ele = null;
	if (idx == null) idx = 1;
	var i = idx + num;
	if (i <= 0) i = max - 1;
	else if (i >= max) i = 1;
	if (crrt2 == null) crrt2 = name + "_1";
	showIt(name + "_" + i);
	idx = i;
}

/*************************************************************
* JS Cookies
************************************************************/
function setCookie(name, value, expires)
{
	var exp = new Date();
	exp.setDate(exp.getDate() + expires);
	document.cookie = name + "=" + escape(value) + ((expires != null && expires != undefined) ? ";expires=" + exp.toUTCString() : "");
}
function getCookie(name)
{
	if (document.cookie.length > 0)
	{
		var c_start = document.cookie.indexOf(name + "=");
		if (c_start != -1)
		{
			c_start = c_start + name.length + 1;
			c_end = document.cookie.indexOf(";", c_start);
			if (c_end == -1) c_end = document.cookie.length;
			return unescape(document.cookie.substring(c_start, c_end));
		}
	}
	return "";
}

/*************************************************************
* PAGE SCROLLING
************************************************************/
function toTop() { window.scrollTo(0, 0); }
function toBottom() { window.scrollTo(0, 6000); }

/******************************************************
* WINDOWS STATUS
*****************************************************/
function setStatusMsg(statusMsg)
{ window.status = (statusMsg != null) ? statusMsg : ''; }

/******************************************************
* openWin
*
* This method opens a new method with the specified
* size and url.
*****************************************************/
function openWin(URL, width, height, name)
{
	var settings = "toolbar=0,location=0,statusbar=0,menubar=0,resizable=1";
	var windowname = (name != null) ? name : 'winPop';
	if (name == null)
	{
		if (URL.indexOf(".aspx") > -1) windowname = URL.substring(0, URL.indexOf(".aspx"));
		while (windowname.indexOf("/") > -1)
		{ windowname = windowname.substring(windowname.indexOf("/") + 1); }
		if (windowname.length > 20) windowname = windowname.substring(0, 20);
	}

	/** scrollbars */
	settings += ",scrollbars=1";

	/** dimensions for specific pages */
	if (false) settings += ",width=400,height=450";
	else
	{
		if (width == null) settings += ",width=450,height=500";
		else settings += ",width=" + width + ",height=" + height;
	}
	window.child = window.open(URL, windowname, settings);
	if (window.opener == null) window.opener = self;
	child.focus();
}

/******************************************************
* DATE SELECTOR
*
* This method opens the Quick Calendar date selector.
*****************************************************/
function dateSelector(field, date, form)
{
	form = (form == null) ? "aspnetForm" : form;
	var params = "?field=" + field + "&form=" + form;
	if (date != null) params += "&date=" + date;
	openWin('DateSelector.aspx' + params, '160', '190');
}

// null function
function doNothing() { }

// number formatter/rounder
function round(number, decimalDigits)
{
	return Math.round(number * Math.pow(10, decimalDigits)) / Math.pow(10, decimalDigits);
}

// fade an image or element in from invis
function fadeIn(element, opacity)
{
	var reduceOpacityBy = 5;
	var rate = 30; // 15 fps

	if (opacity < 100)
	{
		opacity += reduceOpacityBy;
		if (opacity > 100) opacity = 100;

		if (element.filters)
		{
			try { element.filters.item("DXImageTransform.Microsoft.Alpha").opacity = opacity; }
			catch (e)
			{
				// If it is not set initially, the browser will throw an error.  This will set it if it is not set yet.
				element.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + opacity + ')';
			}
		}
		else element.style.opacity = opacity / 100;
	}

	if (opacity < 100)
	{
		setTimeout(function() { fadeIn(element, opacity); }, rate);
	}
}

