// ******************************* methods below are used for servlets' calls *************************************


var SELECT_SITES_TO_DELETE	= "Please select the Voice Site(s) you would like to delete";
var DELETE_SITES		    = "Click OK if you would like to delete the selected Voice Site(s)";
var SELECT_PHONES_TO_DELETE = "Please select the Phone Line(s) you would like to delete";
var DELETE_PHONE_LINES      = "Click OK if you would like to delete the selected Phone Line(s)";
var CANT_DELETE_HOME_PAGE	= "You cannot delete the home page in your site.";
var DELETE_PAGE			    = "Would you like to delete currently selected page(s)?";
var SELECT_PAGES_TO_DELETE = "Please select the Page(s) you would like to delete";
var CANT_DELETE_LAST_PAGE	= "You cannot delete the last page in your site.\nThere must be at least one page in each site!";
var SELECT_LINKS_TO_DELETE	= "Please select the Link(s) you would like to delete";
var SELECT_KEYWORDS_TO_DELETE = "Please select the Keywords(s) you would like to delete";
var SELECT_PREFIX			= "Please select the ";
var SELECT_SUFFIX			= "(s) you would like to delete";
var DELETE_LINKS		    = "Click OK if you would like to delete the selected Link(s)";
var DELETE_KEYWORDS			= "Click OK if you would like to delete the selected Keyword(s)";
var DELETE_PREFIX			= "Click OK if you would like to delete the selected ";
var DELETE_SUFFIX 			= "(s)";
var SELECT_SMTH_TO_DELETE	= "You must select a file or folder to be deleted";
var WANT_DELETE			    = "Would you like to Delete ";
var ALL_WILL_BE_DELETED		= "?\nIf this is a folder all contents of it will be deleted.";
var RENAME_SOUND_FILE		= "Your sound file name can not contain any spaces. Please rename the file and upload again.";
var SELECT_SOUND_FILE		= "You must select a wav file to be added to your page.";
var PICK_FOLDER				= "You must select a folder to hold the sound files.";

function putDataInSelected()
{
    var wizardStateObj = document.getElementById("wizardState");
    if(wizardStateObj.value.indexOf("IN_") != -1)
        return;

    wizardStateObj.value = "IN_";
    // MM_showHideLayers('dp_get_selected','','hide','dp_put_selected','','show');
    document.getElementById("dp_put").src = "images/buttons/datapage/putOn.gif";
    document.getElementById("dp_get").src = "images/buttons/datapage/get.gif";

    dpResetPutDataIn();

    //Additions:
    document.getElementById("subType").value = "IN_INSERT";
    MM_showHideLayers('dp_continue','','show');
}

function getDataOutSelected()
{
    var wizardStateObj = document.getElementById("wizardState");
    if(wizardStateObj.value.indexOf("OUT_") != -1)
        return;

    wizardStateObj.value = "OUT_";
    //MM_showHideLayers('dp_get_selected','','show','dp_put_selected','','hide');
    document.getElementById("dp_put").src = "images/buttons/datapage/put.gif";
    document.getElementById("dp_get").src = "images/buttons/datapage/getOn.gif";

    dpResetGetDataOut();

    //Additions:
    document.getElementById("subType").value = "OUT_LOAD";
    MM_showHideLayers('dp_continue','','show');
}

function dpWizardSelect(button)
{
    var wizardStateObj = document.getElementById("wizardState");

    dpResetPutDataIn();
    dpResetGetDataOut();

    var source = button.src;
    button.src = source.substring(0, source.indexOf(".")) + "On.gif";
    wizardStateObj.value = button.id;

    document.getElementById("subType").value = button.id;
}

function dpResetPutDataIn()
{
    document.getElementById("IN_INSERT").src = "images/buttons/datapage/insert.gif";
    document.getElementById("IN_UPDATE").src = "images/buttons/datapage/update.gif";
    MM_showHideLayers('dp_continue','','hide');
}

function dpResetGetDataOut()
{
    document.getElementById("OUT_ACT").src = "images/buttons/datapage/act.gif";
    document.getElementById("OUT_PLAY").src = "images/buttons/datapage/play.gif";
    var loadVariables = document.getElementById("OUT_LOAD");
    if(loadVariables != null)
        loadVariables.src = "images/buttons/datapage/load.gif";
    MM_showHideLayers('dp_continue','','hide');
}

// DYNAMIC PAGE FUNCTIONS ----------------------------------------------------------------------------------------------

function changeResponseTypeOption()
{
    var selectedIndex = document.mainBodyForm.responseType.selectedIndex;
    if(selectedIndex == 0 || selectedIndex == 1 || selectedIndex == 2)
    {
        MM_showHideLayers('transactionDest','','show');
        MM_showHideLayers('parameterTab0HolderLayer','','show');
        MM_showHideLayers('parameterTab0SelectLayer','','show');
        document.mainBodyForm.parameterTab0SelectBox.selectedIndex = 7;
    }
    else
    {
        MM_showHideLayers('transactionDest','','hide');
        MM_showHideLayers('parameterTab0HolderLayer','','hide');
        MM_showHideLayers('parameterTab0SelectLayer','','hide');
        MM_showHideLayers('parameterTab0','','hide');
        MM_showHideLayers('parameterTab0NewPageLayer','','hide');
    }
}

var runTestWindow = null;
function runTest()
{
	runTestWindow = window.open("", "runTestWindow", "toolbar=no,status=yes,width=610,height=340,resizable=yes, scrollbars=yes");
	runTestWindow.focus();

	document.mainBodyForm.target = "runTestWindow";
	document.mainBodyForm.action = "/ResponseTest?command=testDynamicPage";
	document.mainBodyForm.submit();
	document.mainBodyForm.target = "";
	document.mainBodyForm.action = "/Layer";
}

function runDPTest()
{
	runTestWindow = window.open("", "runTestWindow", "toolbar=no,status=yes,width=610,height=340,resizable=yes, scrollbars=yes");
	runTestWindow.focus();

	document.mainBodyForm.target = "runTestWindow";
	var oldAction = document.mainBodyForm.action;
	document.mainBodyForm.action = "/DataPage?command=runTest";
	document.mainBodyForm.submit();
	document.mainBodyForm.target = "";
	document.mainBodyForm.action = oldAction;
}


function setHiddenStuff()
{
    obj1 = document.getElementById("submitVariables");
    obj2 = document.getElementById("submitVariablesDisplay");
    if(obj2.checked)
        obj1.value = "TRUE";
    else
        obj1.value = "FALSE";
}

//------------------------------------------------------------------------------------------------------------------------

function containedLayerSwap(layerToShowID, layerToHideID)
{
	collapseHideLayer(layerToHideID);
	expandShowLayer(layerToShowID);
}

function collapseHideLayer(layerId)
{
	layerToHide = document.getElementById(layerId);
	layerToHide.style.visibility = "hidden";
	layerToHide.style.position = "absolute";
	layerToHide.style.height = "0px";
}

function expandShowLayer(layerId)
{
	layerToShow = document.getElementById(layerId);
	layerToShow.style.position = "relative";
	layerToShow.style.visibility = "inherit";
	layerToShow.style.height = "auto";
}

function toggleHiddenValueForCheckbox(checkbox, hiddenID)
{
    hiddenInput = document.getElementById(hiddenID);
    if(checkbox.checked)
        hiddenInput.value = "TRUE";
    else
        hiddenInput.value = "FALSE";
}

function submitAndFreezeForm(theForm)
{
	elementCount = theForm.elements.length;
	theForm.submit();
	for(i=0; i < elementCount; i++)
	  theForm.elements[i].disabled = true;
}

function changeToAudioTab(i, promptType)
{
	expandShowLayer('AudioTab');
	collapseHideLayer('TabContentsContainer');
	document.mainBodyForm.TypeOfPromptToAdd.value = promptType;
	document.mainBodyForm.AudioInsertIndex.value = i;
}

//------------------ THIS GUY TRIMS THE STRING just like Java does string.trim() -----------------
function stringTrim()
{
	return this.replace(/^\s+/,'').replace(/\s+$/,'');
}
String.prototype.trim = stringTrim;

//------------------- NEW setAction -------------------------------
function setCommandAndAction(theForm, servletName, execMethod)
{
	theForm.action = servletName + "?command=" + execMethod;
}

function disableSubmitButtons(buttons)
{
	if (buttons[0] == null)
	{
		buttons.disabled = true;
	}
	else
	{
		for (i=0; i<buttons.length; i++)
			buttons[i].disabled = true;
	}
}

//-------------------- Form Validators ----------------------------
function validateHomeForm(theForm, checkBox)
{
	if(theForm.action.indexOf("removeDomains") != -1)
		return confirmDeleteSites(checkBox);
	else
		return true;
}

function validateResponseType(theForm, optionMenu)
{
	if(theForm.action.indexOf("testDynamicPage") != -1 && optionMenu.value == "")
	{
		alert ("Please select a response interpretation type before testing.");
		return false
	}
	else
		return true;
}

function validateNewPageEditorForm(theForm, checkBox, objectName, displayName)
{
	if(theForm.action.indexOf("remove" + objectName) != -1)
	{
		return confirmDeleteObject(checkBox, displayName);
	}
	else
		return true;
}

function validateSoundUploadForm(theForm)
{
	if(theForm.action.indexOf("selectFile") != -1)
		return confirmSelectSoundFile(theForm);
	else
		return true;
}

function validatePickFolderForm(theForm)
{
	if(theForm.action.indexOf("pickFolder") == -1)
		return true;

	var soundToBeAdded = "";
	for (i=0; i<theForm.prompts_audioFilename.length; i++)
	{
		if (theForm.prompts_audioFilename[i].checked)
		{
			soundToBeAdded = theForm.prompts_audioFilename[i].value.toLowerCase();
		}
	}

	if (soundToBeAdded == "")
	{
		alert(PICK_FOLDER);
		return false;
	}
	else
	{
		return true;
	}
}

function confirmDeleteSites(checkBox)
{
	if(isCheckBoxChecked(checkBox))
		return confirm(DELETE_SITES);

	alert(SELECT_SITES_TO_DELETE);
	return false;
}

function confirmDeleteObject(checkBox, displayName)
{
	if(isCheckBoxChecked(checkBox))
		return confirm(DELETE_PREFIX + displayName + DELETE_SUFFIX);

	alert(SELECT_PREFIX + displayName + SELECT_SUFFIX);
	return false;
}

function confirmSelectSoundFile(theForm)
{
	var soundToBeAdded = "";
	var errorType = theForm.errorType;
	for (i=0; i<theForm.prompts_audioFilename.length; i++)
	{
		if (theForm.prompts_audioFilename[i].checked)
		{
			soundToBeAdded = theForm.prompts_audioFilename[i].value.toLowerCase();
		}
	}

	if (theForm.prompts_audioFilename.checked)
	{
		soundToBeAdded = theForm.prompts_audioFilename.value.toLowerCase();
	}

	if (soundToBeAdded.lastIndexOf(" ") != -1)
	{
		alert(RENAME_SOUND_FILE);
		return false;
	}
	else if (soundToBeAdded == "" || (soundToBeAdded.lastIndexOf("wav") == -1 && soundToBeAdded.lastIndexOf("ulaw") == -1) )
	{
		alert(SELECT_SOUND_FILE);
		return false;
	}
	else
	{
		return true;
	}
}

function isCheckBoxChecked(checkBox)
{
	if(checkBox[0] == null)
	{
		if (checkBox.checked)
			return true;
	}
	else
	{
		for (i=0; i<checkBox.length; i++)
			if(checkBox[i].checked)
				return true;
	}
	return false;
}

//---------- MISC ---------------------------------------

function fillInSiteKeyword(checkBox, titleField, siteKeywordField)
{
        if (checkBox.checked && siteKeywordField.value == "")
                siteKeywordField.value = titleField.value.toLowerCase();
}

// used to check and uncheck all checkboxes
function checkBoxCheck(checkBoxName, selectedLinks)
{
	var state;
	if (checkBoxName.checked)
		state = true;
	else
		state = false;

	setAllLinksToState(selectedLinks, state);
}

function setAllLinksToState(links, state)
{
	if (links[0] == null)
	{
		links.checked = state;
	}
	else
	{
		for (i=0; i<links.length; i++)
			links[i].checked = state;
	}
}

function toggleOptionPanel(checkbox, optionPanelId, radioGroup)
{
	var layer = document.getElementById(optionPanelId);
	if (checkbox.checked)
	{
		layer.style.position = "relative";
		layer.style.visibility = "visible";
		radioGroup[1].checked = "true";
	}
	else
	{
		layer.style.position = "absolute";
		layer.style.height = "0px";
		layer.style.visibility = "hidden";
		radioGroup[0].checked = "true";
	}
}

//------------ STILL NEED TO BE HANDLED ---------------------------------------------

function removePhoneLine(theForm, checkBox)
{
	if(isCheckBoxChecked(checkBox))
	{
		if (confirm(DELETE_PHONE_LINES))
		{
			setAction(theForm, 'PhoneLineManager', 'removePhoneLine');
		}
	}
	else
	{
		alert(SELECT_PHONES_TO_DELETE);
	}
}

function togglePlans(plan)
{
	if(plan == "FreeTrial" && document.mainBodyForm.signUpPlan != null)
	{
		alert(document.mainBodyForm.signUpPlan.value);
		document.mainBodyForm.signUpPlan.value = "";
		document.mainBodyForm.signUpPlan.readOnly = true;
	}
	else if(plan == "SubscribeNow" && document.mainBodyForm.signUpPlan != null)
	{
		document.mainBodyForm.signUpPlan.readOnly = false;
	}
}

// used everywhere we need action to be set in the form
// sets action of the form passed in to execute servelet and execMethod passed in
function setAction(theForm, servletName, execMethod)
{
	theForm.action = "/" + servletName + "?command=" + execMethod;
	theForm.submit();
}

// used in virtualReceptionist.jsp
// in the function below "addContacts" is the TAG from metadata.props AddContactsTag
function addContacts(theForm, servletName, execMethod, contactType, numberOfContacts)
{
	theForm.addContacts.value = numberOfContacts;
	theForm.transferType.value = contactType;
	setAction(theForm, servletName, execMethod);
}

//----------------------------------------------------------------------------------
var expandKeywordsWindow = null;
var relatedInputBox = null;

function openKeywordsWindow(pageName, pageNumber, input)
{
	var ttsWindow;
	ttsWindow = window.open("/jsp/siteBuilder/ExpandKeywords.jsp?pageName="+pageName+"&pageNumber="+pageNumber+"&keywords="+input.value, "ttsWindow","toolbar=no,status=yes,width=510,height=200,resizable=yes, scrollbars=yes");
	expandKeywordsWindow = ttsWindow;
	relatedInputBox = input;
	expandKeywordsWindow.focus();
}

function openTTSWindow(ttsNum)
{
	var message;
	if (document.mainBodyForm.prompts_message.length > 1)
	{
		message = document.mainBodyForm.prompts_message[ttsNum].value;
	}
	else
		message = document.mainBodyForm.prompts_message.value;

	var ttsWindow = window.open("/TTS?command=playTTS&prompts_message=" + message, "expandKeywordsWindow","toolbar=no,status=yes,width=510,height=200,resizable=yes, scrollbars=yes");

	ttsWindow.focus();
}

function handleKeywordChange()
{
	if(expandKeywordsWindow != null)
		expandKeywordsWindow.close();
}

function updateKeywordsAndAddCommaOnEnter(e, textarea)
{
	var key;
	key = getkey(e);

	window.opener.relatedInputBox.value = textarea.value

	if (key == null)
		return true;
	if (key == 13)
	{
		textarea.value = textarea.value + ",";
		return true;
	}
	return true;
}

var uploadWindow = null;
// used in MessagePageEditor.jsp for multiple prompts
function openUploadSoundWindows(numOfPrompts, promptIndex)
{
	uploadWindow = window.open("/AudioManager?command=view&curDir=/&subDir=/&numOfPrompts=" + numOfPrompts + "&promptIndex=" + promptIndex, "uploadWindow", "toolbar=no,status=yes,width=410,height=450,resizable=yes, scrollbars=yes");
	uploadWindow.focus();
}

// used in MessagePageEditor.jsp
function openUploadSoundWindow()
{
	uploadWindow = window.open("/AudioManager?command=view&curDir=/&subDir=/", "uploadWindow", "toolbar=no,status=yes,width=410,height=450,resizable=yes, scrollbars=yes");
	uploadWindow.focus();
}

var pickWindow = null;
function openPickFolderWindow()
{
	pickWindow = window.open("/AudioManager?command=view&actionName=pick&curDir=/&subDir=/", "pickWindow", "toolbar=no,status=yes,width=410,height=450,resizable=yes, scrollbars=yes");
	pickWindow.focus();
}

function openPickPromptsFolderWindow()
{
    pickWindow = window.open("/AudioManager?command=view&actionName=pickPromptsDirectory&curDir=/&subDir=/", "pickWindow", "toolbar=no,status=yes,width=410,height=450,resizable=yes, scrollbars=yes");
	pickWindow.focus();
}

function openUploadSoundForErrorPrompts(errorType)
{
	uploadWindow = window.open("/AudioManager?command=view&curDir=/&subDir=/&errorType=" + errorType, "uploadWindow", "toolbar=no,status=yes,width=410,height=450,resizable=yes, scrollbars=yes");
	uploadWindow.focus();
}

function openUploadSoundForErrors(numOfPrompts, promptIndex, errorType)
{
	uploadWindow = window.open("/AudioManager?command=view&curDir=/&subDir=/&numOfPrompts=" + numOfPrompts + "&promptIndex=" + promptIndex + "&errorType=" + errorType, "uploadWindow", "toolbar=no,status=yes,width=410,height=450,resizable=yes, scrollbars=yes");
	uploadWindow.focus();
}

var varWindow = null;
function openVarWindow(domainCode, selectVarID)
{
    selectBox = document.getElementById(selectVarID);
    varID = selectBox.options[selectBox.selectedIndex].value
    varName = selectBox.options[selectBox.selectedIndex].text
    variablesUsedWindow = window.open("/jsp/shared/variablesUsed.jsp?domainCode=" + domainCode + "&varName=" + varName + "&varID=" + varID, "variablesUsedWindow", "toolbar=no,status=yes,width=460,height=200,resizable=yes, scrollbars=auto");
    variablesUsedWindow.focus();
}

function openVarWindow2(domainCode, varID, varName)
{
    variablesUsedWindow = window.open("/jsp/shared/variablesUsed.jsp?domainCode=" + domainCode + "&varName=" + varName + "&varID=" + varID, "variablesUsedWindow", "toolbar=no,status=yes,width=460,height=200,resizable=yes, scrollbars=auto");
    variablesUsedWindow.focus();
}


function openStructWindow(domainCode, varname, layerToShow, layerToHide)
{
    variablesUsedWindow = window.open("/jsp/shared/variablesUsed.jsp?domainCode=" + domainCode + "&varname=" + document.getElementById(varname).value + "&id=" + varname + "&layerToShow=" + layerToShow + "&layerToHide=" + layerToHide + "&isStruct=true", "variablesUsedWindow", "toolbar=no,status=yes,width=460,height=200,resizable=yes, scrollbars=auto");
    variablesUsedWindow.focus();
}

var openReferralWindow = null;
function openReferralMessageWindow(messageID)
{
	message = escape(document.getElementById(messageID).value);
	openReferralWindow = window.open("/Referrals?command=previewMessage&" + messageID + "=" + message);
	openReferralWindow.focus();
}

function clearSound(theForm, numOfPrompts, promptIndex, promptName)
{
	eval('theForm.' + promptName + '_' + promptIndex + '_audioFilename').value = "";
	eval('theForm.' + promptName + '_' + promptIndex + '_filetag').value="None";
	eval('theForm.' + promptName + '_' + promptIndex + '_audioFileLink').value="#";
}

function clearErrorSound(theForm, errorType)
{
	if(errorType == "lineBusy")
	{
		theForm.lineBusy_audioFilename.value="";
		theForm.lineBusy_filetag.value="None";
		theForm.lineBusy_audioFileLink.value="#";
	}
	if(errorType == "noAnswer")
	{
		theForm.noAnswer_audioFilename.value="";
		theForm.noAnswer_filetag.value="None";
		theForm.noAnswer_audioFileLink.value="#";
	}
	if(errorType == "callComplete")
	{
		theForm.callComplete_audioFilename.value="";
		theForm.callComplete_filetag.value="None";
		theForm.callComplete_audioFileLink.value="#";
	}
}

function clearSpecialTransferSound(theForm, thePromptName)
{
	if(thePromptName == "transferTimeUp")
	{
		theForm.transferTimeUp_audioFilename.value="";
		theForm.transferTimeUp_filetag.value="None";
		theForm.transferTimeUp_audioFileLink.value="#";
	}
	if(thePromptName == "onHoldMusicPrompt")
	{
		theForm.onHoldMusicPrompt_audioFilename.value="";
		theForm.onHoldMusicPrompt_filetag.value="None";
		theForm.onHoldMusicPrompt_audioFileLink.value="#";
	}
	if(thePromptName == "warnCallerOfTransferDurationPrompt")
	{
		theForm.warnCallerOfTransferDurationPrompt_audioFilename.value="";
		theForm.warnCallerOfTransferDurationPrompt_filetag.value="None";
		theForm.warnCallerOfTransferDurationPrompt_audioFileLink.value="#";
	}
}

function clearSpecialCallQueueSound(theForm, thePromptName)
{
	if(thePromptName == "musicLoopPrompt")
	{
		theForm.musicLoopPrompt_audioFilename.value="";
		theForm.musicLoopPrompt_filetag.value="None";
		theForm.musicLoopPrompt_audioFileLink.value="#";
	}
}

// used in soundUpload.jsp
// in the function below "prompts_audioFilename" is the TAG from metadata.props prompts_audioFilenameTag
// curDir and subDir are tags from from metadata.props currentDir and subDir respectively
function verifyDeleteDirectoryOrFile(theForm, currentDirectory)
{
	var toBeDeleted = "";
	for (i=0; i<theForm.prompts_audioFilename.length; i++)
	{
		if (theForm.prompts_audioFilename[i].checked)
			toBeDeleted = theForm.prompts_audioFilename[i].value;
	}

	if (theForm.prompts_audioFilename.checked)
	{
		toBeDeleted = theForm.prompts_audioFilename.value;
	}

	if (toBeDeleted == "")
	{
		alert(SELECT_SMTH_TO_DELETE);
	}
	else if(confirm(WANT_DELETE + toBeDeleted + ALL_WILL_BE_DELETED))
	{
		if (theForm.actionName == "pick")
			setCommandAndAction(theForm, "AudioManager", "delete&curDir=" + currentDirectory + "&subDir=" + toBeDeleted + "&actionName=pick");
		else
			setCommandAndAction(theForm, "AudioManager", "delete&curDir=" + currentDirectory + "&subDir=" + toBeDeleted);
	}
	else
	{
		if (theForm.actionName == "pick")
			setCommandAndAction(theForm, "AudioManager", "view&curDir=" + currentDirectory + "&actionName=pick");
		else
			setCommandAndAction(theForm, "AudioManager", "view&curDir=" + currentDirectory);
	}


}


//////////////////////////////////////////////////////////////
////        Magnifying glass section
//////////////////////////////////////////////////////////////
var magnifyingGlassWindow = null;

var magGlassDomain = null;
var magGlassPage = null;
var magGlassKeywords = null;

function setMagGlassVariables(domainObj, pageObj, index)
{
	magGlassDomain = domainObj[index];
	magGlassPage = pageObj[index];

	if (magGlassDomain == null)
		magGlassDomain = domainObj;

	if (magGlassPage == null)
		magGlassPage = pageObj;
}


function setMagGlassFields(domainCode, pageCode)
{
	if (window.opener.magGlassDomain != null && domainCode != null)
		window.opener.magGlassDomain.value = domainCode;

	if (window.opener.magGlassPage != null && pageCode != null)
		window.opener.magGlassPage.value = pageCode;

	closeMagnifyingGlassWindow();
}

// used in magnifying glass page
function openMagnifyingGlassWindow(domainObj, pageObj, index)
{
	setMagGlassVariables(domainObj, pageObj, index);

	var winOpts = "width=545,height=450,resizable=yes,scrollbars=yes,menubar=no,status=yes,toolbar=no,top=50,left=200";

	magnifyingGlassWindow = window.open("", "winFinder", winOpts);
	magnifyingGlassWindow.location="/DomainOverview?command=getOverviews";
	magnifyingGlassWindow.focus();
}

// used in magnifying glass page
function closeMagnifyingGlassWindow()
{
	window.location="/DomainOverview?command=teardownMagnifyingGlass";
	self.close();
}

//////////////////////////////////////////////////////////////
//        End magnifying glass section
//////////////////////////////////////////////////////////////

var addPageWindow = null;

// used in selecting pages to add to sitelevel keywords.
function openAddPageWindow()
{
	addPageWindow = window.open("/DomainEditor?command=setupAddSiteKeywords", "uploadWindow", "width=555,height=500,resizable=no,scrollbars=yes,menubar=no,status=yes,toolbar=no,top=50,left=200");
	addPageWindow.focus();
}

function redirect(url)
{
	window.location = url;
}

//Gets the key that was pressed
function getkey(e)
{
	if (window.event)
	   return window.event.keyCode;
	else if (e)
	   return e.which;
	else
	   return null;
}

//Filters the enter key and ignores it
function filterEnter(e)
{
	var key;
	key = getkey(e);
	if (key == null)
		return true;
	if (key == 13)
		return false;
	return true;
}

function openAngelContextSensitiveHelp(helpFile)
{
	var w = null;

	if (helpFile == "/help/index.html")
	{
		w = window.open(helpFile,'pop_apps','width=700,height=500,directories=no,status=yes,scrollbars=yes,resizable=yes,toolbar=yes,menubar=no,location=no');
		return;
	}

	if (w != null && w.name == 'help')
		  w.close();
	w = window.open('about:blank','pop_apps','width=700,height=500,directories=no,status=yes,scrollbars=yes,resizable=yes,toolbar=yes,menubar=no,location=no');
	w.document.write("<html>");
	w.document.write("<head>");
	w.document.write("<title>Angel.com - Help</TITLE>");
	w.document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"../main.css\"/>");
	w.document.write("</head>");
	w.document.write("<frameset cols=\"165,*\" frameborder=\"1\">");
	w.document.write("<frame src=\"/help/helpnav.html\" scrolling=\"auto\" name=\"leftnav\">");
	w.document.write("<frame src=\"" + helpFile + "\" scrolling=\"auto\" name=\"main\">");
	w.document.write("</frameset>");
	w.document.write("</frameset>");
	w.document.write("</html>");
	w.name="help";

}

function openNaturalPhoneContextSensitiveHelp(helpFile)
{
	var w = null;

	if (helpFile == "http://www.naturalphone.com/helpfiles/index.html")
	{
		w = window.open(helpFile,'pop_apps','width=700,height=500,directories=no,status=yes,scrollbars=yes,resizable=yes,toolbar=yes,menubar=no,location=no');
		return;
	}

	if (w != null && w.name == 'help')
		  w.close();
	w = window.open('about:blank','pop_apps','width=700,height=500,directories=no,status=yes,scrollbars=yes,resizable=yes,toolbar=yes,menubar=no,location=no');
	w.document.write("<html>");
	w.document.write("<head>");
	w.document.write("<title>NaturalPhone.com - Help</TITLE>");
	w.document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"../main.css\"/>");
	w.document.write("</head>");
	w.document.write("<frameset cols=\"165,*\" frameborder=\"1\">");
	w.document.write("<frame src=\"http://www.naturalphone.com/helpfiles/helpnav.html\" scrolling=\"auto\" name=\"leftnav\">");
	w.document.write("<frame src=\"" + helpFile + "\" scrolling=\"auto\" name=\"main\">");
	w.document.write("</frameset>");
	w.document.write("</frameset>");
	w.document.write("</html>");
	w.name="help";

}


function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function closeAndGoto(url) {
  if (window.opener && !window.opener.closed)
    window.opener.location = url;
  window.close();
}

function switchImage() {
   var imgArray = new Array('1','2','3','4','5','6','7','8');
   var test = Math.abs(Math.round(imgArray.length * Math.random()));
   if(test==0) test++;
   returnImg = '<IMG SRC="/images/quotes/'+ test + '.gif" WIDTH=151 HEIGHT=245 BORDER="0" name="leftImage">'
return returnImg;
}

/**
 * This function is used by navigation to enble an entire table element, to be selected as if it were a link
 */
function leftnav(o,e)
   {if (document.getElementById)
   {a=o.id.substring(1); p = "";r = "";g = e.target;
   if (g)
     { t = g.id;f = g.parentNode;
   if (f)
     {p = f.id;h = f.parentNode;
   if (h) r = h.id;}}
     else{h = e.srcElement;f = h.parentNode;
   if (f) p = f.id;t = h.id;}
   if (t==a || p==a || r==a)
      return true;location.href=document.getElementById(a).href}}


// browser rec code

version=parseInt(navigator.appVersion);
if (navigator.appVersion.indexOf('5.')>-1){version=5};
if (navigator.appVersion.indexOf('6.')>-1){version=6}; browser='OTHER';
if (navigator.appName=='Netscape'){browser='NS'+version;}
if (navigator.appName=='Microsoft Internet Explorer'){browser='MSIE'+version;}
if (navigator.appVersion.indexOf('MSIE 3')>0) {browser='MSIE3';}
if(browser == 'NS5'){browser='NS6'};
if (browser=='MSIE3') {window.location='update.html'}
if (browser=='MSIE4') {window.location='update.html'}
if (browser=='NS3') {window.location='update.html'}
if (browser=='NS4') {window.location='update.html'}
if (browser=='OTHER') {}


// homepage roll-over code

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

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_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function handleVariableSelect2(selectBox, index)
{
    obj1 = document.getElementById('isUserDefined_' + index);
    obj2 = document.getElementById('params_' + index + '_key');
    obj3 = document.getElementById('blocks_' + index + '_initializers_0_operator');

    if(obj1 != null && obj2 != null)
    {
        if(obj2.value == '')
            obj1.value = 'false';
        if(obj1.value == 'false')
        {
            if(selectBox.options[selectBox.selectedIndex].disabled == true)
                obj2.value = "";
            else
            {
                var rstext = selectBox.options[selectBox.selectedIndex].text;
                var listIndex = rstext.indexOf("[List]");
                if(listIndex != -1)
                	rstext = rstext.substring(0, listIndex-2);
                if(rstext.indexOf("Response: ") != -1)
                    obj2.value = rstext.substring(10);
                else
                    obj2.value = rstext;
            }
        }
    }
    if(obj3 != null)
    {
		var rstext = selectBox.options[selectBox.selectedIndex].text;
		var listIndex = rstext.indexOf("[List]");
		if(listIndex != -1)
			obj3.options[13].text = "sublist";
    	else
    		obj3.options[13].text = "substring";
    }
}


function handlePromptVariableSelect(selectBox, listLayerID)
{
	selectText = selectBox.options[selectBox.selectedIndex].text;

	if(selectText.indexOf("[List]") != -1)
		MM_showHideLayers(listLayerID,'','show');
	else
		MM_showHideLayers(listLayerID,'','hide');
}

function handleVariableSelectBack(textBoxID, selectBoxID, layerToHide, layerToShow)
{
    textBox = document.getElementById(textBoxID);
    selectBox = document.getElementById(selectBoxID);
    selectBox.selectedIndex = 0;

    for(i=0; i<selectBox.length; i++)
    {
        if(selectBox.options[i].value == textBox.value)
            selectBox.selectedIndex = i;
    }

    MM_showHideLayers(layerToHide,'','hide');
    MM_showHideLayers(layerToShow,'','show');
}

function handleVPageSelect(selectBox, layerName, index, currDomainCode, domainCodeTag, pageCodeTag, pageIDTag, newPageTypeTag, actionTypeTag, tagNameForVariableSelectedBoolean)
{
	var currItem = selectBox.options[selectBox.selectedIndex].value;
	obj1 = document.getElementById(domainCodeTag + "_" + index);
	obj2 = document.getElementById(pageCodeTag + "_" + index);
	obj3 = document.getElementById(pageIDTag + "_" + index);
	obj4 = document.getElementById(newPageTypeTag + "_" + index);
	obj6 = document.getElementById(tagNameForVariableSelectedBoolean);

    if(actionTypeTag != "")
        if(document.getElementById(actionTypeTag) != null)
            document.getElementById(actionTypeTag).value = "destination";

	if(currItem == "other") //This branch handles the manual vcode entry (i.e. pages in another site)
	{
		MM_showHideLayers(layerName + index,'','show');
		MM_showHideLayers(layerName + index + 'SelectLayer','','hide');
		obj1.value = "";
		obj2.value = "";
		obj3.value = "";
		obj4.value = "";
	}
	else if(currItem == "variable")
	{
		MM_showHideLayers(layerName + index + 'VLayer','','show');
		MM_showHideLayers(layerName + index + 'SelectLayer','','hide');
		obj3.value = "";
		obj4.value = "";
		obj6.value = "true";
	}
	else if (currItem == "hangup")
	{
	    if(actionTypeTag != "")
	        if(document.getElementById(actionTypeTag) != null)
	            document.getElementById(actionTypeTag).value = "hangup";
	}
	else if (currItem.indexOf("vpage") != -1) //This branch handles new page creation
	{
		obj1.value = currDomainCode;
		obj2.value = "";
		obj3.value = "";
		obj4.value = currItem;
	}
	else //This branch handles pages within this site
	{
		obj1.value = currDomainCode;
		var index = currItem.indexOf(",");
		var pageID = "";
		var pageCode = "";
		if(index != 0)
			pageID = currItem.substring(0, index);
		if(index != currItem.length - 1)
			pageCode = currItem.substring(index + 1);
		obj2.value = pageCode;
		obj3.value = pageID;
		obj4.value = "";
	}
}

function handleVPageSelectBack(layerName, index, currDomainCode, domainCodeTag, pageCodeTag, pageIDTag, newPageTypeTag)
{
	var destinationSelectBox = eval("document.mainBodyForm." + layerName + index + "SelectBox");
	for(i = 0; i<destinationSelectBox.options.length; i++)
	{
		if(destinationSelectBox.options[i].text == "Home Page")
		{
			destinationSelectBox.selectedIndex = i;
			i = destinationSelectBox.options.length;
		}
	}

	MM_showHideLayers(layerName + index,'','hide');
	MM_showHideLayers(layerName + index + 'NewPageLayer','','hide');
	MM_showHideLayers(layerName + index + 'SelectLayer','','show');

	obj1 = eval("document.mainBodyForm." + domainCodeTag + "[" + index + "]");
	obj2 = eval("document.mainBodyForm." + pageCodeTag + "[" + index + "]");
	obj3 = eval("document.mainBodyForm." + pageIDTag + "[" + index + "]");
	obj4 = eval("document.mainBodyForm." + newPageTypeTag + "[" + index + "]");
	if(obj1 == null) obj1 = eval("document.mainBodyForm." + domainCodeTag);
	if(obj2 == null) obj2 = eval("document.mainBodyForm." + pageCodeTag);
	if(obj3 == null) obj3 = eval("document.mainBodyForm." + pageIDTag);
	if(obj4 == null) obj4 = eval("document.mainBodyForm." + newPageTypeTag);

	obj1.value = currDomainCode;
	obj2.value = "";
	obj3.value = "";
	obj4.value = "";


}

function handleVPageSelectVariableBack(layerName, index, tagNameForVariableSelectedBoolean)
{
	obj6 = document.getElementById(tagNameForVariableSelectedBoolean);
	obj6.value = "false";

	var destinationSelectBox = eval("document.mainBodyForm." + layerName + index + "SelectBox");
	for(i = 0; i<destinationSelectBox.options.length; i++)
	{
		if(destinationSelectBox.options[i].text == "Home Page")
		{
			destinationSelectBox.selectedIndex = i;
			i = destinationSelectBox.options.length;
		}
	}

	MM_showHideLayers(layerName + index + 'VLayer','','hide');
	MM_showHideLayers(layerName + index + 'NewPageLayer','','hide');
	MM_showHideLayers(layerName + index + 'SelectLayer','','show');
}

var basicNumbers = "0123456789";
var dtmfCharacters = "0123456789,* ";
var phoneCharacters = "0123456789*-().# ";
var intlPhoneCharacters = "0123456789*-().#+ ";

//Function used to submit the input form when entered is pressed
function submitOnEnter(e, theForm, servletName, execMethod)
{
	var key;
	key = getkey(e);
	if (key == null)
		return true;
	if (key == 13)
	{
		setAction(theForm, servletName, execMethod);
		return false;
	}
	return true;
}

//A Combination of a restriction and submit on Enter function
function submitOnEnter2(e, theForm, servletName, execMethod, restrictedChars)
{
	var key;
	key = getkey(e);
	if (key == null)
		return true;
	if (key == 13)
	{
		setAction(theForm, servletName, execMethod);
		return false;
	}
	else
	{
		var keychar;
		keychar = String.fromCharCode(key);

		// control keys
		if ((key==null) || (key==0) || (key==8) || (key==9) || (key==27))
		   return true;
		// numbers
		else if (((restrictedChars).indexOf(keychar) > -1))
		   return true;

		return false;
	}
	return true;
}

function restrictCharacters(e, restrictedChars)
{
	var key;
	var keychar;

	if (window.event)
	   key = window.event.keyCode;
	else if (e)
	   key = e.which;
	else
	   return true;

	keychar = String.fromCharCode(key);

	// control keys
	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
	   return true;
	else if (restrictedChars.indexOf(keychar) > -1)
	   return false;
	else
	   return true;
}

function allowOnlyCharacters(value, e, allowedChars)
{
	var key;
	var keychar;

	if (window.event)
	   key = window.event.keyCode;
	else if (e)
	   key = e.which;
	else
	   return true;

	keychar = String.fromCharCode(key);

	// control keys
	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
	   return true;

	else if (((allowedChars).indexOf(keychar) > -1))
	   return true;

	return false;
}



function restrictToNumbers(myfield, e)
{
	var key;
	var keychar;

	if (window.event)
	   key = window.event.keyCode;
	else if (e)
	   key = e.which;
	else
	   return true;

	keychar = String.fromCharCode(key);

	// control keys
	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
	   return true;

	// numbers
	else if ((("0123456789").indexOf(keychar) > -1))
	   return true;

	return false;
}

function restrictToDtmf(myfield, e)
{
	var key;
	var keychar;

	if (window.event)
	   key = window.event.keyCode;
	else if (e)
	   key = e.which;
	else
	   return true;

	keychar = String.fromCharCode(key);

	// control keys
	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
	   return true;

	// numbers
	else if ((("0123456789,* ").indexOf(keychar) > -1))
	   return true;

	return false;
}

function restrictToNaturalNumbers(myfield, e)
{
	var key;
	var keychar;

	if (window.event)
	   key = window.event.keyCode;
	else if (e)
	   key = e.which;
	else
	   return true;

	keychar = String.fromCharCode(key);

	// control keys
	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
	   return true;

	// numbers
	else if ((("0123456789").indexOf(keychar) > -1))
	   return true;
	else if((("-").indexOf(keychar) > -1))
	{
	    if(myfield.value.indexOf("-") != 0)
	        myfield.value = "-" + myfield.value;
	    else if(myfield.value.length > 1)
	        myfield.value = myfield.value.substring(1);
	    else
	        myfield.value = "";
	    return false;
	}
	else if(((".").indexOf(keychar) > -1))
	    return myfield.value.indexOf(".") == -1;

	return false;
}

function restrictToPhoneNumberChars(myfield, e)
{
	var key;
	var keychar;

	if (window.event)
	   key = window.event.keyCode;
	else if (e)
	   key = e.which;
	else
	   return true;

	keychar = String.fromCharCode(key);

	// control keys
	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
	   return true;

	// numbers
	else if ((("0123456789*-().# ").indexOf(keychar) > -1))
	   return true;

	return false;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
	if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
	obj.visibility=v; }
}


function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}


// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// make all functions with similar functionality use the same basic function
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

function toggleCQMLoginInputDisplay(oCheckbox) {
	var oDivInputs = document.getElementById('cqm-login-inputs');
	if(oCheckbox.checked == true)
	{
		oDivInputs.style.display = 'block';
	}
	else
	{
		oDivInputs.style.display = 'none';
	}
}