var gErrorUrl="";

function launch(url) {
   self.name = "opener";
   remote = open(url, "remote", "resizable,scrollbars,status,width=700,height=800");
 }

function openWindow(windowlink)
{
	newwin=window.open(windowlink, 'newwin', 'height=500, width=750, toolbar=no, location=no,directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=no');
}

function OpenHelpErrorHandler()
{
    if (gErrorUrl != "")
    {
        location.href = gErrorUrl;
        return true;
    }
    else
    {
        return false;
    }
}


function OpenHelp(url)
{
    // special case for folders
    folderindex = location.href.indexOf("/nss-folder/");
    if (folderindex >= 0)
    {
		qsindex = location.href.indexOf("?");
		if (qsindex < 0 || folderindex < qsindex)
		{
        	objectendindex = location.href.indexOf("/", folderindex + 12);
        	url = location.href.substring(0, folderindex) + "/" + location.href.substring(folderindex + 12, objectendindex) + "/" + url;
		} // only if /nss-folder/ was found before the query string
    }

    window.onerror = OpenHelpErrorHandler;
    gErrorUrl = url;
    var hWnd = window.open(url, "NVOHelp", "menubar=yes,toolbar=yes,width=595,height=400,resizable=yes,scrollbars=yes");
	if (!hWnd.opener) hWnd.opener = self;
	if (hWnd.focus != null) hWnd.focus();
    gErrorUrl = "";
}


function FindElement(elementName)
{
	var i = 0;

    for (i = 0; i < document.nvoForm.elements.length; i++)
	{
		if (document.nvoForm.elements[i].name == elementName)
		{
			return document.nvoForm.elements[i];
		}
	}
    return null;
}

function RemoveFocusAll()
{
	var vers = navigator.appVersion;
	if (vers.indexOf("Mac") != -1 && vers.indexOf("IE") != -1)
	{
		var i = 0;

    	for (i = document.nvoForm.elements.length - 1; i >= 0 ; i--)
		{
			if (document.nvoForm.elements[i].type == "text" || document.nvoForm.elements[i].type == "textarea")
			{
				document.nvoForm.elements[i].blur();
			}
		}
	}
}


// this is the action string that is used to save the standard items on a page

function GetStdAction()
{
	var hidePage = (document.nvoForm.hidePage && document.nvoForm.hidePage.checked) ? "ON" : "OFF";

	if (hidePage == "ON") // if hidden page, go back home
	{
		document.nvoForm.NVORedirect.value = document.nvoForm.hostAddressForHiddenPage.value;
	}

    return "Set(.Sitemap.Name." + document.nvoForm.ObjectUID.value + "=" + escape(document.nvoForm.PageName.value)
    			+ "&.Sitemap.Title." + document.nvoForm.ObjectUID.value + "=" + escape(document.nvoForm.PageTitle.value)
    			+ "&.Sitemap.Hide." + document.nvoForm.ObjectUID.value + "=" + hidePage +");";
}

var gSaveAndGoURL = "";
var gChanged = false;

function DoGoto(url)
{
	RemoveFocusAll();
    if (gChanged || "" == "")
    {
        gSaveAndGoURL = url;
        DoSave();
    }
    else
    {
        location.href = ReplaceString(url, "*", "");
    }
}

// save the form data and goto the specified url

function SaveAndGo(url)
{
	RemoveFocusAll();
    if (gChanged)
    {
        gSaveAndGoURL = url;
        DoSave();
    }
    else
    {
        location.href = url;
    }
}


function Changed(url)
{
	gChanged = true;
}


function IsNetscape()
{
	return (navigator.appName.substring(0, 8) == "Netscape");
}


function WarnIfUsingOldBrowser()
{
	if (parseInt(navigator.appVersion) < 4)
	{
		if (IsNetscape())
			alert("Editing your web site requires a newer version of Netscape Communicator. Visit Netscape's web site at www.netscape.com to obtain the newest version. Failure to do so may result in unreliable behavior.");
		else
			alert("Editing your web site requires a newer version of Internet Explorer. Visit Microsoft's web site at www.microsoft.com to obtain the newest version. Failure to do so may result in unreliable behavior.");
	}
}

function NormalizeObjectName(name)
{
	var	newName = "";

	for (i = 0; i < name.length; i++)

	{
		charCode = name.charCodeAt(i);
		if (charCode < 0)
			charCode += 256;

		// Remove the chars \ / : * ? \" < > | '
		// and handle only ascii values between 32 and 128

		if (charCode == 47			//	/
			|| charCode == 92		//	\
			|| charCode == 58		//	:
			|| charCode == 42		//	*
			|| charCode == 63		//	?
			|| charCode == 34		//	"
			|| charCode == 60		//	<
			|| charCode == 62		//	>
			|| charCode == 124		//	|
			|| charCode == 39)		//	'
		{
			// do nothing
		}
		else if (charCode > 32 && charCode < 128)
			newName += name.substr(i, 1);
	}

	// if we eliminated all chars, name the object "page"
	if (newName == "")
		newName = "page";

	return newName;

} // NormalizeObjectName

function DoButton(buttonAction)
{
	if ((document.nvoForm.PageName) && (document.nvoForm.PageName.value == ""))
    {
    	alert("The Page Name is required and cannot be left blank. Please enter a valid name.");
    	document.nvoForm.PageName.focus();
    	document.nvoForm.PageName.select();
    	location.href = "#pagename";
    	return;
    }

	if (gSaveAndGoURL != "")
    {
        document.nvoForm.NVORedirect.value = gSaveAndGoURL;
    }

    document.nvoForm.NVOAction.value = buttonAction;
	document.nvoForm.submit();
}


function DoMoveItem(where, uid)
{
    DoButton("MoveRecord(List=Sitemap&uid=" + uid + "&Where=" + where + ")");
}


window.errorLoadingApplet = false;


// This script is called when the user clicks on the client link before
// the browser has had time to launch the applet

function AppletErrorHandler()
{
    alert("Please wait for the page to complete loading and then try again.");
    return true;
}


// This javascript is used launch a helper app

function StartHelper(host, service, hostAddress, extra)
{

    if (navigator.appVersion.indexOf("Macintosh") != -1)
    {
		if (navigator.mimeTypes)
		{
            mimetype = navigator.mimeTypes["application/netopia"];
            if (mimetype && mimetype.enabledPlugin)
			{
	            location.href = "http://" + hostAddress + "/pages/common/" + host + ".nhtml?service=" + service + "&back=" + escape(location.href) + "&extra=" + escape(extra);
    		}
			else
			{
				alert("You must have the FREE Visitor Software in order to use this feature. Please download and install the Visitor Software.");
				location.href = "http://" + hostAddress + "/bin/download.nhtml";
			}
		} // if we can check for mimeTypes supported
		else
		{
            location.href = "http://" + hostAddress + "/pages/common/" + host + ".nhtml?service=" + service + "&back=" + escape(location.href) + "&extra=" + escape(extra);
		} // else go to plugin start page
    }
	else
	{
	    if (window.errorLoadingApplet)
	    {
	        alert("You must have Java enabled in your browser in order to use this feature.");
	    }
	    else
	    {
	        window.onerror = AppletErrorHandler;

	        installed = document.cc.isClassInstalled("com.netopia.ns.version.client.VisitorClient");
	        if (installed)
	        {
	            location.href = "http://" + hostAddress + "/pages/common/" + host + ".netopia?service=" + service + "&extra=" + escape(extra);
	        }
	        else
	        {
	            alert("You must have the FREE Visitor Software in order to use this feature. Please download and install the Visitor Software.");
	            location.href = "http://" + hostAddress + "/bin/download.nhtml";
	        }
	    }
    } // else it's Windows
}

// pulls a parameter out of a comma delimeted string
// For example, given the string "a,b,c", passing
// index 0 would return "a", 1 would return "b", etc...
function GetField(rec, fieldindex)
{
    var     i;
    var     istart = 0;
    var     iend = 0;

    for (i = 0; i < fieldindex; i++)
    {
        istart = rec.indexOf(",", istart) + 1;
    }

    iend = rec.indexOf(",", istart);
    if (iend < 0)
    {
        iend = rec.length;
    }

    var temp = rec.substring(istart, iend);
    return temp;
}


function StdDelete(singularname, pluralname, profile, list, stdeditpage)
{
    var     action = "";
    var     count = 0;
	var		m1, m2;

    if (stdeditpage)
        action = GetStdAction();

    action = "UseProfile(Name=" + profile + ");Save()";

    for (i = 0; i < document.nvoForm.elements.length; i++)
    {
		el = document.nvoForm.elements[i];
		if (el.name == "cb" && el.checked)
        {
            uid = GetField(el.value, 0);
            action +=";Delete(List=" + list + "&UID=" + uid + ")";
            count++;
        }
    }

    if (count > 1)
    {
		m1 = "Are you sure that you want to delete ^^^count^^^ ^^^pluralname^^^?";
		m2 = ReplaceString(m1, "^^^count^^^", count);
        if (confirm(ReplaceString(m2, "^^^pluralname^^^", pluralname)))
        {
            DoButton(action);
        }
    }
    else
    {
	    if (count == 1)
	    {
			m1 = "Are you sure that you want to delete ^^^count^^^ ^^^singularname^^^?";
			m2 = ReplaceString(m1, "^^^count^^^", count);
	        if (confirm(ReplaceString(m2, "^^^singularname^^^", singularname)))
	        {
	            DoButton(action);
	        }
	    }
	    else
	    {
			m1 = "Please use the check boxes to select the ^^^pluralname^^^ and then click Delete.";
	        alert(ReplaceString(m1, "^^^pluralname^^^", pluralname));
	    }
	}
}


function StdMove(name, moveurl, helpurl, profile, list, field, doneurl, query, uid, extraretparms)
{
    var     startuid = "";
    var     enduid = "";

	if (!uid)
		uid = "";

    for (i = 0; i < document.nvoForm.elements.length; i++)
    {
		el = document.nvoForm.elements[i];
		if (el.name == "cb" && el.checked)
        {
            if (startuid.length == 0)
                startuid = GetField(el.value, 0);
            else
                enduid = GetField(el.value, 0);
        }
    }

    if (startuid.length > 0)
    {
        if (enduid.length == 0)
            enduid = startuid;
		action = moveurl + "?startuid=" + startuid + "&enduid=" + enduid + "&profile=" + profile + "&list=" + list + "&field=" + field +
				  "&name=" + escape(name) + "&doneurl=" + doneurl + "&uid=" + uid + "&helpurl=" + helpurl + query;
		if (extraretparms)
			action += "&extraretparms=" + extraretparms;
        SaveAndGo(action);
    }
    else
    {
		var   message = "Please use the check boxes to select the ^^^name^^^ and then click Move.";
		alert(ReplaceString(message, "^^^name^^^", name));
    }
}


function StdEdit(name, editurl, editlisturl, query)
{
    var     uidlist = ",";
    var     count = 0;

    for (i = 0; i < document.nvoForm.elements.length; i++)
    {
		el = document.nvoForm.elements[i];
		if (el.name == "cb" && el.checked)
        {
            uid = GetField(el.value, 0);
            uidlist += uid + ",";
            count++;
        }
    }

    if (count > 0)
    {
        if (count == 1)
            SaveAndGo(editurl + "?uid=" + uid + query);
        else
        {
            if (editlisturl == "")
                alert("Please select just one item to edit.")
            else
                SaveAndGo(editlisturl + "?count=" + count + "&uidlist=" + uidlist + query);
        }
    }
    else
    {
		var message = "Please use the check boxes to select the ^^^name^^^ and then click Edit.";
        alert(ReplaceString(message, "^^^name^^^", name));
    }
}


function ReplaceString(org, match, replace)
{
    var     dst = "";
    var     starti = 0;
    var     endi = 0;

    while ((endi = org.indexOf(match, starti)) >= 0)
    {
        dst += org.substring(starti, endi) + replace;
        starti = endi + match.length;
    }

    dst += org.substring(starti, org.length);

    return dst;
}


function IsTrue(value)
{
	upperCaseValue = value.toUpperCase();
	return ((upperCaseValue == "")
			|| (upperCaseValue != "NO"
				&& upperCaseValue != "FALSE"
				&& upperCaseValue != "OFF"
				&& upperCaseValue != "0"));
}

function DoSelectAll()
{
	for (var i=0; i < document.nvoForm.elements.length; i++)
	{
		el = document.nvoForm.elements[i];
		if (el.name == "cb")
			el.checked = (document.nvoForm.allSelected.value == "check");
	}

	//toggle values
	if (document.nvoForm.allSelected.value == "check")
		document.nvoForm.allSelected.value = "uncheck";
	else
		document.nvoForm.allSelected.value = "check";
}


function setStatusBar(msg) {
	window.status = msg;
	return true
}


function FindSelectedElement(name, buttonName, action, messageNone, messageTooMany)
{
	sel = null;

	numsel = 0;
	for (i = 0; i < document.nvoForm.elements.length; i++)
	{
		el = document.nvoForm.elements[i];
		if (el.name == name && el.checked)
		{
			numsel++;
			sel = el;
		}
	}

	if (numsel == 0)
	{

		alert(ReplaceString(messageNone, "^^^buttonName^^^", buttonName));
	}
	else if (numsel > 1)
	{
		alert(ReplaceString(messageTooMany, "^^^action^^^", action));
		sel = null;
	}

	return sel;
}

function CheckURL(urlElement)
{
	if (urlElement.value.length > 0 && urlElement.value.indexOf("://") == -1)
	{
		urlElement.value = "http://" + urlElement.value
	}
	urlElement.value = ReplaceString(urlElement.value, " ", "%20");
	Changed();
}

function popup(url) {

newwin=window.open(url,'newwin','height=500,width=700,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no');

}

if (parseInt(navigator.appVersion) >= 3)
{
hibullet = new Image;
hibullet.src = "/look/images/hibullet.gif";
}
function DoMouseOver(index)
{
document["nav" + index].src = "/look/images/hibullet.gif";
// eval("document.nav"+ index + ".src='http://www.tiffanybadges.co.uk/look/images/hibullet.gif'");
}
function DoMouseOut(index)
{
document["nav" + index].src = "/look/images/bullet.gif";
// eval("document.nav"+ index + ".src='http://www.tiffanybadges.co.uk/look/images/bullet.gif'");
}
