
function NewSite(sXMLFile, form) {

	var pages = "Home";
	var iIdx = 0;
	var bTest = true;
    var cPages = 1;
    var limit = form.limit.value;

	if (StripSpaces(form.site_name.value) == '') {
		alert('Please specify a name for your site.');
		document.main.site_name.focus();
		return;
	}
    /* 
	else if (!isNotExt(form.site_name.value)) {
		alert('Your chosen name has spaces or special characters that can\'t be used to name a site. You must use a different name.');
		document.main.site_name.focus();
		return;
	}	
	*/
	else if (!isLatin1(form.site_name.value)) {
		form.site_name.value = getLatin1OnlyString(form.site_name.value);
		alert('Your chosen name has unsupported characters. The characters have been removed. If the remaining text is acceptable, click the Continue button again.');
	    return;
    }	
    
	if (form.page) {
		while (bTest) {
			if (form.page[iIdx]) {
				if (form.page[iIdx].checked == true) {
					if (pages.length > 0) pages = pages + ",";
					pages = pages + form.page[iIdx].value;
                    cPages++;
				}
			}
			else {
				bTest = false;
			}
			iIdx++;		
		}
	}
	
	cmd = '/servlet/SiteBuilderServlet?Command=NewSite';
	cmd += '&XMLFile=' + sXMLFile;
	cmd += '&SiteTitle=' + escape(form.site_name.value);
	cmd += '&Pages=' + escape(pages);
	
	if (form.blank) {
	  if (form.blank.checked) {
		cmd += '&BlankPage=true';	
		cmd += '&BlankXMLFile=blank_page.xml';
		cmd += '&CopyLayout=1';
        cPages++;
      }
	}
    
    if (limit >= 0)
    {
        if (cPages > limit)
        {
            window.open('/trellix/sitebuilder/startup_over_page_limit.html?limit='+limit,null,'height=225,width=400,status=no,toolbar=no,menubar=no,location=no');
            return;
        }
    }
	
	var sfUrl = '/trellix/sitebuilder/f_set_design_start.jsp?origDesign=' + escape(Get_Main_Cookie('design'));
	Delete_Main_Cookie('design', '', '/', '');
	sfUrl = escape(sfUrl);
	cmd += '&sUrl=' + sfUrl;
	cmd += '&fUrl=' + sfUrl;
		
	if ((Get_Cookie('debug') * 1) > 0) DebugMsg(cmd);
	
	Delete_Cookie('XMLFile', '/', '');
	
//	who cares about browsers too old to implement location.replace()?
//	if( document.images )	// test to see if browser is current enough
		top.location.replace(cmd);	// use this to prevent problems from use of back button
//	else
//		top.location.href = cmd;
}
	
function EditItem(coords, type, subType, dest)
{
	Set_Cookie('coords', coords, '', '/', '');
	Set_Main_Cookie('type', type, '', '/', '');
	Set_Cookie('help', '0', '', '/', '');
	
	if (type == 'Para') {
		top.location.href = '/trellix/sitebuilder/f_edit_text.html';
	}
	else if (type == 'Title') {
		top.location.href = '/trellix/sitebuilder/f_edit_title.html';
	}	
	else if (type == 'Img') {
		top.location.href = '/trellix/sitebuilder/f_edit_picture.jsp';
	}
	else if (type == 'Link') {
		top.location.href = '/trellix/sitebuilder/f_edit_link.html';
	}
	else if (type == 'PassThruGem') {
		if (subType == 'JSP') {
			buf = '/trellix/sitebuilder/gem/' + dest;
			for (var i = 4; i < arguments.length; i++)
				buf += arguments[i] + ',';
			top.location.href = buf;
		}
		else if (subType == 'JS') {
			buf = dest + '(';
			for (var i = 0; i < arguments.length; i++)
				buf += arguments[i] + ',';
			buf += ')';			
			eval(buf);
		}
		else if (subType == 'NE' || subType == '' || !(subType)) {
			alert('To edit this Web Gem\'s settings, you must delete this Web Gem and add a new one with the correct settings.');
		}
		else {
			alert('ERROR: Invalid gem sub-type.');
		}
	}
	else if (type == 'Gem') {
		if (subType == 'framed'){
			top.location.href = '/trellix/sitebuilder/f_gem_edit.html';
		}
		else if (subType == 'unframed'){
			var cmd;
			cmd = '/servlet/SiteBuilderServlet';
			cmd = cmd + '?Command=GemCreate&Mode=edit&PartnerNum=10';
			cmd = cmd + '&PageNum=' + Get_Cookie('page_num');
			cmd = cmd + '&Coords=' + Get_Cookie('coords');
			cmd = cmd + '&fUrl=/trellix/sitebuilder/f_edit_page.html';		
			top.location.href = cmd;
		}
		else
			alert('This Web Gem has no editable settings.');
	}
	else {
		alert('ERROR: Editing of this object type is currently not supported.');
	}
}

function SetPage(page_num, mode)
{
	switch (mode) {
		case 0:
			Set_Cookie('page_num', page_num, '', '/', '');	
			document.location.href = '/servlet/SiteBuilderServlet?Command=RenderPage&PageNum=' + page_num + '&Mode=' + mode;			
			break;
		case 1:
		case 2:
			Set_Cookie('page_num', page_num, '', '/', '');	
			document.location.href = '/servlet/SiteBuilderServlet?Command=RenderPage&PageNum=' + page_num + '&Mode=' + mode;
			break;
		case 3:
			alert('Unable to navigate to other pages while in delete mode. To exit delete mode click the Cancel icon below.');
			break;
		case 4:
			alert('Unable to navigate to other pages while in move selection mode. To exit move selection mode click the Cancel icon below.');
			break;
		case 5:
			alert('Unable to navigate to other pages while in copy selection mode. To exit copy selection mode click the Cancel icon below.');		
			break;
		case 6:
		case 7:
			Set_Cookie('page_num', page_num, '', '/', '');	
			document.location.href = '/servlet/SiteBuilderServlet?Command=RenderPage&PageNum=' + page_num + '&Mode=' + mode;
			break;
		case 8:
			alert('Unable to navigate to other pages while in layout and design selection modes.');
			break;
		default:
			alert('ERROR: Unknown mode');
	}
}

function EditPage(page_num)
{
	Set_Cookie('page_num', page_num, '', '/', '');	
	top.location.href = '/trellix/sitebuilder/f_edit_page.html';
}

function DeletePage(page_num) /* form used for check box ver. */
{
	/* coords = GetCoords(form); */
	
	if (page_num == '') {
		alert('Please select one or more pages to delete by clicking the check boxes next to your page names.');
	}
	else {
		cmd = '/servlet/SiteBuilderServlet?Command=DeletePage&PageNum=' + page_num +'&SrcCoords=' + page_num + '&sUrl=/trellix/sitebuilder/f_site_organizer.html&fUrl=/trellix/sitebuilder/f_site_organizer.html';
		if ((Get_Cookie('debug') * 1) > 0) DebugMsg(cmd);		
		top.location.href = cmd;
	}
}

function MovePage(page_num)
{
	cmd = '/servlet/SiteBuilderServlet?Command=MovePage';
	cmd += '&PageNumSrc=' + Get_Cookie('page_num');
	cmd += '&PageNumDest=' + page_num;
	cmd += '&sUrl=/trellix/sitebuilder/f_site_organizer.html';
	cmd += '&fUrl=/trellix/sitebuilder/f_site_organizer.html';
	
	if ((Get_Cookie('debug') * 1) > 0) DebugMsg(cmd);
	
	top.location.href = cmd;
}

function InsertItem(coords)
{
	Set_Cookie('coords', coords, '', '/', '');
	AddType();
}

function AddType()
{
	type = Get_Main_Cookie('type');

	if (type == 'Para') {
		top.location.href = '/trellix/sitebuilder/f_add_text.html';
	}
	else if (type == 'Img') {
		top.location.href = '/trellix/sitebuilder/add_call_picture_chooser.html';
	}
	else if (type == 'Link') {
		top.location.href = '/trellix/sitebuilder/f_choose_link.html';
	}
	else if (type == 'WebGem') {
		top.location.href = '/trellix/sitebuilder/f_add_gem.html';
	}
	else {
		alert('ERROR: The type of item you are attempting to insert (' + type + ') has not been implemented.');
	}
}

function CoordList(doc) {
   // CoordList enumerates the form fields in the given document,
   // looking for fields named F0E1D2C3B4A5 that are checked on,
   // and return their values concatenated by a comma.
   // The ungainly name F0...A5 will hopefully not collide with a user-chosen name.
   var result = "";
   var separator = "";
   for (var x=0; x < doc.forms.length; x++) {
      for (var y=0; y < doc.forms[x].elements.length; y++) {
         if (doc.forms[x].elements[y].name == "F0E1D2C3B4A5" &&
             doc.forms[x].elements[y].checked) {
               result += separator + doc.forms[x].elements[y].value;
               separator = ",";
         }
      }
   }
   return result;
}


function DeleteItem(coords)
{
	if (coords == 0) {
		coords = CoordList(parent.fBody.document);
	}

	cmd = '/servlet/SiteBuilderServlet?Command=RemoveObject&Type=p&sUrl=/trellix/sitebuilder/f_edit_page.html&fUrl=/trellix/sitebuilder/f_edit_page.html&PageNum=' + Get_Cookie('page_num') + '&Coords=' + coords;
	if ((Get_Cookie('debug') * 1) > 0) DebugMsg(cmd);		
	top.location.href = cmd;
}

function GetCoordsMove()
{
	var coords = CoordList(parent.fBody.document);
	Set_Cookie('coords', coords, '', '/', '');
}

function GetCoordsCopy()
{
	var coords = CoordList(parent.fBody.document);
	Set_Cookie('coords', coords, '', '/', '');
}



function MoveItem(src, dest)
{
	if (src == '0') {
		src = Get_Cookie('coords');
	}	

	sCmd = '/servlet/SiteBuilderServlet?Command=MoveElements&Type=p&sUrl=/trellix/sitebuilder/f_edit_page.html&fUrl=/trellix/sitebuilder/f_edit_page.html&SrcCoords=' + src + '&DestCoords=' + dest;
	top.location.href = sCmd;
}

function CopyItem(src, dest)
{
	if (src == '0') {
		src = Get_Cookie('coords');
	}	

	sCmd = '/servlet/SiteBuilderServlet?Command=CopyElements&Type=p&sUrl=/trellix/sitebuilder/f_edit_page.html&fUrl=/trellix/sitebuilder/f_edit_page.html&SrcCoords=' + src + '&DestCoords=' + dest;
	top.location.href = sCmd;
}

function AddPassThruGem(cmdForm)
{
	if (Get_Cookie('gem_invite') == '1')
		cmdForm.Command.value = 'SetPassThruGemContents';
	else
		cmdForm.Command.value = 'InsertPassThruGem';

	cmdForm.PageNum.value = Get_Cookie('page_num');
	cmdForm.Coords.value = Get_Cookie('coords');
	cmdForm.sUrl.value = '/trellix/sitebuilder/f_edit_page.html';
	cmdForm.fUrl.value = '/trellix/sitebuilder/f_edit_page.html';



	Delete_Cookie('coords', '/', '');
	Delete_Cookie('gem_class_id', '/', '');
	Delete_Cookie('gem_invite', '/', '');
	
   	cmdForm.submit();		
}	

function UpdatePassThruGem(cmdForm)
{
	cmdForm.Command.value = 'SetPassThruGemContents';
	cmdForm.PageNum.value = Get_Cookie('page_num');
	cmdForm.Coords.value = Get_Cookie('coords');
	cmdForm.sUrl.value = '/trellix/sitebuilder/f_edit_page.html';
	cmdForm.fUrl.value = '/trellix/sitebuilder/f_edit_page.html';
	


	Delete_Cookie('coords', '/', '');
	
	cmdForm.submit();	
}	

function InsertGem( gemClassId, gemClassVer )
{
	var cmd;

	cmd = '/servlet/SiteBuilderServlet';
	cmd = cmd + '?Command=InsertGem';
	cmd = cmd + '&attClassId=' + gemClassId;
	cmd = cmd + '&attClassVer=' + gemClassVer;
	cmd = cmd + '&PageNum=' + Get_Cookie('page_num');
	cmd = cmd + '&Coords=' + Get_Cookie('coords');
	if (Get_Cookie('gem_invite') == '1')
		cmd = cmd + '&Mode=invite';
	else
		cmd = cmd + '&Mode=create';

	cmd = cmd + '&sUrl=/trellix/sitebuilder/f_edit_page.html';
	cmd = cmd + '&fUrl=/trellix/sitebuilder/f_edit_page.html';		

	Delete_Cookie('coords', '/', '');
	Delete_Cookie('gem_invite', '/', '');

	top.location.href = cmd;
}

function InvokeService( gemClassId, bFramed, returnUrl )
{
	Set_Cookie('coords', '0', '', '/', '');
	InsertBGem( gemClassId, bFramed, returnUrl );
}

function InsertBGem( gemClassId, bFramed, returnUrl )
{
	var cmd;

	if (returnUrl){
		Set_Cookie('gem_return', returnUrl, '', '/', '');
	}
	else{
		Delete_Cookie('gem_return', '/', '');
	}
	if (bFramed == true){
		Set_Cookie('gem_class_id', gemClassId, '', '/', '');
		top.location.href = '/trellix/sitebuilder/f_gem_create.html';
	}
	else{
		cmd = '/servlet/SiteBuilderServlet';
		cmd = cmd + '?Command=GemCreate';
		cmd = cmd + '&ClassId=' + gemClassId;
		if (Get_Cookie('gem_invite') == '1')
			cmd = cmd + '&Mode=invite';
		else
			cmd = cmd + '&Mode=create';
		cmd = cmd + '&PartnerNum=10';
		cmd = cmd + '&PageNum=' + Get_Cookie('page_num');
		cmd = cmd + '&Coords=' + Get_Cookie('coords');
		cmd = cmd + '&fUrl=/trellix/sitebuilder/f_edit_page.html';		

		top.location.href =  cmd;
	}
}

function xmldecl()
{
	return '<?xml version="1.0" encoding="iso-8859-1"?>';
}

function simplestarttag(name)
{
	return "<" + name + ">";
}

function endtag(name)
{
	return "</" + name + ">";
}

function simpleelement(name, value)
{
	return simplestarttag(name) + value + endtag(name);
}

function findLast( tarray, start, depth )
{
	var els = tarray[start][0].split(/\//);
	var i = start + 1;
	for( ; i < tarray.length; i++ )
	{
		cels = tarray[i][0].split(/\//);
		if( cels.length < depth )
			break;
		var j = 0;
		for( ; (j < depth) && (els[j]==cels[j]) ; j++ );
		if( j < depth )
			break;
	}
	return i;
}

function BuildTextCmd(form, cmdForm)
{
	with (form) {
		cmdForm.Type.value = 'Para';
		cmdForm.Contents.value = content.value;
		/* cmdForm.Contents.value = escape(content.value); */
		
		if (!FontName[4].checked) {
			for (i=0; i < 4; i++) {
				if (FontName[i].checked) {
					fontName = FontName[i].value;
				}
			}
			cmdForm.attFontName.value = fontName;
		}
		
		if (FontStyle.value == '-1') {		
		        cmdForm.attFontStyle.value = '';			
                } else {
		        cmdForm.attFontStyle.value = FontStyle.value;			
		}

		if (!FontSize[7].checked) {		
			for (i=0; i < 7; i++) {
				if (FontSize[i].checked) {
					fontSize = FontSize[i].value;
				}
			}
			cmdForm.attFontSize.value = fontSize;			
		}
		
		cmdForm.attColor.value = Color.value;
		cmdForm.attAlign.value = Align[Align.selectedIndex].value;		
		cmdForm.PageNum.value = Get_Cookie('page_num');
		cmdForm.Coords.value = Get_Cookie('coords');
		cmdForm.sUrl.value = '/trellix/sitebuilder/f_edit_page.html';
		cmdForm.fUrl.value = '/trellix/sitebuilder/f_edit_page.html';
	}
}

function AddText(form, cmdForm)
{
	if (form.content.value.length < 1) {
		alert('Unable to create an empty text object. Please enter text or select cancel.');
		return;
	}
	if (!isLatin1(form.content.value)) {
        form.content.value = getLatin1OnlyString(form.content.value);
        alert('The text contains unsupported characters. The characters have been removed. If the remaining text is acceptable, click the Done button again.');
        return;
    }	
	
	cmdForm.Command.value = 'InsertObject';
	BuildTextCmd(form, cmdForm);
	
	cmdForm.submit();
	
	Delete_Cookie('coords', '/', '');
}

function UpdateText(form, cmdForm)
{
	if (Get_Cookie('coords') == '') {
		alert('No object to update. This problem could occur if you are using your browsers navigation buttons, back and forward. Select the Cancel button to continue.');
	}
	else if (form.content.value.length < 1) {
		alert('Unable to create an empty text paragraph. If you are trying to delete this text paragraph click the Delete Item button. Otherwise enter text or click the Cancel button.');
		return;
	}  
	else if (!isLatin1(form.content.value)) {
        form.content.value = getLatin1OnlyString(form.content.value);
        alert('The text contains unsupported characters. The characters have been removed. If the remaining text is acceptable, click the Done button again.');
        return;
    }	
	else {
		cmdForm.Command.value = 'SetObjectContents';
		BuildTextCmd(form, cmdForm);
		cmdForm.submit();		
	}

	Delete_Cookie('coords', '/', '');	
}


function EditTitle(pageNum, coord)  // Prepare to enter the f_edit_title.html page.
{
	Set_Cookie('page_num', pageNum, '', '/', '');
	Set_Cookie('coords', coord, '', '/', '');
	Set_Cookie('s_o', 'y', '', '/', '');       // Flag to return to Site Organizer.
	top.location.href = '/trellix/sitebuilder/f_edit_title.html';	
}


function UpdateTitle(form)    // Prepare to exit the f_edit_title.html page.
{
	if (StripSpaces(form.content.value) == '') {
		alert('Please specify a title.');
		return;
	}
	if (Get_Cookie('coords') == '') {
		alert('No object to update. This problem could occur if you are using your browsers navigation buttons, back and forward. Select the Cancel button to continue.');
	}
	else if (form.content.value.length < 1) {
		alert('Unable to create an empty title. Please enter text or select cancel.');
		return;
	}	
	else if (!isLatin1(form.content.value)) {
        form.content.value = getLatin1OnlyString(form.content.value);
        alert('The text contains unsupported characters. The characters have been removed. If the remaining text is acceptable, click the Done button again.');
        return;
    }	
	else {
		if (form.content.value.length > 1500) {
			alert('The amount of text entered is too large for a single paragraph (1500 character limit). Please split your text into mutiple paragraphs.');
			return;
		}	
	

      var returnPage = 'f_edit_page.html';
      if (Get_Cookie('s_o') == 'y') {
         returnPage = 'f_site_organizer.html';
         Delete_Cookie('s_o', '/', '');	
      }

	
		with (form) {
			cmd = '/servlet/SiteBuilderServlet';
			cmd += '?Command=SetObjectContents';
			cmd += '&Type=Para';
			cmd += '&Contents=' + escape(content.value);
			cmd += '&PageNum=' + Get_Cookie('page_num');
			cmd += '&Coords=' + Get_Cookie('coords');
			cmd += '&sUrl=/trellix/sitebuilder/' + returnPage;
			cmd += '&fUrl=/trellix/sitebuilder/' + returnPage;			
		}
		if ((Get_Cookie('debug') * 1) > 0) DebugMsg(cmd);		
	
		top.location.href = cmd;
	}

	Delete_Cookie('coords', '/', '');	
}

function BuildLinkCmd(form)
{
	with (form) {
	
		if (!FontName[4].checked) {
			for (i=0; i < 4; i++) {
				if (FontName[i].checked) {
					fontName = FontName[i].value;
				}
			}
			buf = '&attFontName=' + escape(fontName);
		}
		else {
			buf = '&attFontName=';		
		}	

		if (FontStyle.value == '-1') {		
			buf += '&attFontStyle=';
		}
		else {
			buf += '&attFontStyle=' + FontStyle.value;	
		}

		if (!FontSize[7].checked) {		
			for (i=0; i < 7; i++) {
				if (FontSize[i].checked) {
					fontSize = FontSize[i].value;
				}
			}
			buf += '&attFontSize=' + fontSize;	
		}
		else {
			buf += '&attFontSize=';
		}
		
		buf += '&attAlign=' + Align[Align.selectedIndex].value;		
		buf += '&PageNum=' + Get_Cookie('page_num');
		buf += '&Coords=' + Get_Cookie('coords');
		buf += '&sUrl=/trellix/sitebuilder/f_edit_page.html';
		buf += '&fUrl=/trellix/sitebuilder/f_edit_page.html';
	}

	return buf;
}

function AddUrlLink(form)
{
	if (StripSpaces(form.u_link_name.value) == '') {
		alert('You are attempting to add an empty web page link. Please enter text for your link or select cancel.');
		return;
	}
	if (!isLatin1(form.u_link_name.value)) {
        form.u_link_name.value = getLatin1OnlyString(form.u_link_name.value);    
		alert('The text that your visitors will click has special characters that can\'t be used on a site. The characters have been removed. If the remaining text is acceptable, click the Done button again.');
		return;
	}		
	form.u_link_url.value = StripSpaces(form.u_link_url.value);
    if (!isNotExt(form.u_link_url.value)) {
		alert('The URL has special characters that can\'t be used on a URL. ');
		return;
	}	

	cmd = '/servlet/SiteBuilderServlet';
	cmd += '?Command=InsertObject';
	cmd += '&Type=Link';	
	cmd += '&attLinkType=U';
	cmd += '&Contents=' + escape(form.u_link_name.value);
	cmd += '&attHRef=' + escape(UrlCheck(form.u_link_url.value));
	cmd += '&attTarget=' + form.link_target[form.link_target.selectedIndex].value;	
	cmd += BuildLinkCmd(form);

	if ((Get_Cookie('debug') * 1) > 0) DebugMsg(cmd);
	top.location.href = cmd;
	
	Delete_Cookie('coords', '/', ''); 	
}

function UpdateUrlLink(form)
{
	if (Get_Cookie('coords') == '') {
		alert('No object to update. This problem could occur if you are using your browsers navigation buttons, back and forward. Select the Cancel button to continue.');
	}
	else {
		if (StripSpaces(form.u_link_name.value) == '') {
			alert('You are attempting to add an empty web page link. Please enter text for your link or select cancel.');
			return;
		}
    	if (!isLatin1(form.u_link_name.value)) {
            form.u_link_name.value = getLatin1OnlyString(form.u_link_name.value);    
    		alert('The text that your visitors will click has special characters that can\'t be used on a site. The characters have been removed. If the remaining text is acceptable, click the Done button again.');
    		return;
    	}	   
	    form.u_link_url.value = StripSpaces(form.u_link_url.value);         
    	if (!isNotExt(form.u_link_url.value)) {
    		alert('The URL has special characters that can\'t be used on a URL. ');
    		return;
    	}	
		
		cmd = '/servlet/SiteBuilderServlet';
		cmd += '?Command=SetObjectContents';
		cmd += '&Type=Link';	
		cmd += '&LinkType=U';
		cmd += '&Contents=' + escape(form.u_link_name.value);	
		cmd += '&attHRef=' + escape(UrlCheck(form.u_link_url.value));		
		cmd += '&attTarget=' + form.link_target[form.link_target.selectedIndex].value;				
		cmd += BuildLinkCmd(form);		

		if ((Get_Cookie('debug') * 1) > 0) DebugMsg(cmd);		
	
		top.location.href = cmd;
	}

	Delete_Cookie('coords', '/', '');	
}

function AddMailLink(form)
{
	if (StripSpaces(form.m_link_name.value) == '') {
		alert('You are attempting to add an empty email link. Please enter text for your email link or select cancel.');
		return;
	}
	if (StripSpaces(form.m_link_url.value) == '') {
		alert('You are attempting to add an empty email link. Please enter email address or select cancel.');
		return;
	}
	if (!isLatin1(form.m_link_name.value)) {
        form.m_link_name.value = getLatin1OnlyString(form.m_link_name.value);
		alert('The text that your visitors will click has special characters that can\'t be used on a site. The characters have been removed. If the remaining text is acceptable, click the Done button again.');
		return;
	}	
	
	if (!isNotExt(form.m_link_url.value)) {
		alert('The email address has special characters that can\'t be used on an address. ');
		return;
	}	

	cmd = '/servlet/SiteBuilderServlet';
	cmd += '?Command=InsertObject';
	cmd += '&Type=Link';	
	cmd += '&attLinkType=M';
	cmd += '&Contents=' + escape(form.m_link_name.value);
	cmd += '&attHRef=' + escape(MailToCheck(form.m_link_url.value));
	cmd += BuildLinkCmd(form);

	if ((Get_Cookie('debug') * 1) > 0) DebugMsg(cmd);
	top.location.href = cmd;
	
	Delete_Cookie('coords', '/', '');	
}

function UpdateMailLink(form)
{
	if (Get_Cookie('coords') == '') {
		alert('No object to update. This problem could occur if you are using your browsers navigation buttons, back and forward. Select the Cancel button to continue.');
	}
	else {
	
		if (StripSpaces(form.m_link_name.value) == '') {
			alert('You are attempting to add an empty email link. Please enter text for your email link or select cancel.');
			return;
		}	
    	if (StripSpaces(form.m_link_url.value) == '') {
    		alert('You are attempting to add an empty email link. Please enter email address or select cancel.');
    		return;
    	}
    	if (!isLatin1(form.m_link_name.value)) {
            form.m_link_name.value = getLatin1OnlyString(form.m_link_name.value);
    		alert('The text that your visitors will click has special characters that can\'t be used on a site. The characters have been removed. If the remaining text is acceptable, click the Done button again.');
    		return;
    	}	
    	if (!isNotExt(form.m_link_url.value)) {
    		alert('The email address has special characters that can\'t be used on an address. ');
    		return;
    	}	
	
		cmd = '/servlet/SiteBuilderServlet';
		cmd += '?Command=SetObjectContents';
		cmd += '&Type=Link';	
		cmd += '&LinkType=M';
		cmd += '&Contents=' + escape(form.m_link_name.value);	
		cmd += '&attHRef=' + escape(MailCheck(form.m_link_url.value));		
		cmd += BuildLinkCmd(form);		

		if ((Get_Cookie('debug') * 1) > 0) DebugMsg(cmd);		
		top.location.href = cmd;
	}

	Delete_Cookie('coords', '/', '');	
}

function AddPageLink(form)
{
	var bTest = true;
	var iIdx = 0;
	
	while (bTest) {
		if (form.page_id[iIdx]) {
			if (form.page_id[iIdx].checked == true) {
				page_id = form.page_id[iIdx].value;
				break;
			}
		}
		else {
			bTest = false;
		}
		iIdx++;		
	}

	if (!bTest) {
		alert('You are attempting to add a page link without selecting a page. Please click one of the radio buttons next to the page titles or click the Cancel icon below.');
		return;
	}

	cmd = '/servlet/SiteBuilderServlet';
	cmd += '?Command=InsertObject';
	cmd += '&Type=Link';	
	cmd += '&attLinkType=P';
	cmd += '&Contents=' + page_id;
	cmd += BuildLinkCmd(form);

	if ((Get_Cookie('debug') * 1) > 0) DebugMsg(cmd);
	top.location.href = cmd;
	
	Delete_Cookie('coords', '/', '');	
}

function UpdatePageLink(form)
{
	var bTest = true;
	var iIdx = 0;
	
	if (Get_Cookie('coords') == '') {
		alert('No object to update. This problem could occur if you are using your browsers navigation buttons, back and forward. Select the Cancel button to continue.');
	}
	else {
		while (bTest) {
			if (form.page_id[iIdx]) {
				if (form.page_id[iIdx].checked == true) {
					page_id = form.page_id[iIdx].value;
					break;
				}
			}
			else {
				bTest = false;
			}
			iIdx++;		
		}
	
		if (!bTest) {
			alert('You are attempting to add a page link without selecting a page. Please click one of the radio buttons next to the page titles or click the Cancel icon below.');
			return;
		}
	
		cmd = '/servlet/SiteBuilderServlet';
		cmd += '?Command=SetObjectContents';
		cmd += '&Type=Link';	
		cmd += '&LinkType=P';
		cmd += '&Contents=' + page_id;
		cmd += BuildLinkCmd(form);		

		if ((Get_Cookie('debug') * 1) > 0) DebugMsg(cmd);		
		top.location.href = cmd;
	}

	Delete_Cookie('coords', '/', '');	
}

function AddGem()
{
	top.location.href = '/trellix/sitebuilder/f_edit_page.html';
}

function InsertAnnotPict()
{
	desc = this.main.desc.value;
	imgref = this.main.image.value;
	comment = this.main.comment.value;
	annot = this.main.caption.value;
	title = this.main.title.value;

	top.location.href = '/servlet/SiteBuilderServlet?Command=InsertAnnotPict&Desc=' + desc + '&ImgRef=' + imgref + '&Comment=' + comment + '&Annot=' + annot + '&Title=' + title + '&Coords=' + Get_Cookie('coords') + '&sUrl=/trellix/sitebuilder/f_edit_page.html&fUrl=/trellix/sitebuilder/f_edit_page.html';
}
function AddImage(form)
{
   var command = '?Command=InsertObject';
   StoreImage(form, command);

}

function UpdateImage(form)
{
   var command = '?Command=SetObjectContents';
   StoreImage(form, command);

}
function StoreImage(form, command)
{
	if (Get_Cookie('coords') == '') {
		alert('No object to update. This problem could occur if you are using your browsers navigation buttons, back and forward. Select the Cancel button to continue.');
		return;
	}
	if (!isLatin1(form.AltText.value)) {
        form.AltText.value = getLatin1OnlyString(form.AltText.value);
        alert('Your chosen ALT text has special characters that can\'t be used on site. The characters have been removed. If the remaining text is acceptable, click the Done button again.');
        return;
	} 
	
	with (form) {
		if (!isInteger(v_space.value) || !isInteger(h_space.value)) {
			alert('The "Top and bottom space" and "Left and right space" values must be integers.');
			return;
		}
	}

	with (form) {
		cmd = '/trellix/sitebuilder/update_image.jsp';
		cmd += command;
		cmd += '&Type=Img';
		cmd += '&Contents=' + escape(content.value);
		cmd += '&attAltText=' + escape(AltText.value);	

		
		if ((link_url.value.length > 0) && (link_url.value != 'http://') &&
			(link_url.value != 'https://') && (link_url.value != 'ftp://')) {			
			cmd += '&attHRef=' + escape(link_url.value);
			cmd += '&attTarget=' + link_target[link_target.selectedIndex].value;
		}
		else {
			cmd += '&attHRef=';
			cmd += '&attTarget=';
		}			
		

		imgAlignVal = "";
		if (align[0].checked) imgAlignVal = "Left";
		if (align[4].checked) imgAlignVal = "Right";
		cmd += '&attImgAlign=' + imgAlignVal;
		

		alignVal = "";
		if (align[1].checked) alignVal = "L";
		if (align[2].checked) alignVal = "C";		
		if (align[3].checked) alignVal = "R";
		cmd += '&attAlign=' + alignVal;	
       
		var widthVal = "";
		for (i=0; i < 6; i++) {
			if (width[i].checked) {
				widthVal = width[i].value;
			}
		}
			
		cmd += '&attWidth=' + widthVal;
        cmd += '&PageNum=' + Get_Cookie('page_num');
		cmd += '&Coords=' + Get_Cookie('coords');
		cmd += '&attImgType=' + imgType.value; 
		cmd += '&attVSpace=' + v_space.value;	
		cmd += '&attHSpace=' + h_space.value;			
		cmd += '&sUrl=/trellix/sitebuilder/f_edit_page.html';
		cmd += '&fUrl=/trellix/sitebuilder/f_edit_page.html'; 
		cmd += '&imgSize=' + imgSize.value;	// a, i, t, s, etc.
		cmd += '&phrogId=' + phrogId.value;

	} // end with form  
	
	if ((Get_Cookie('debug') * 1) > 0) DebugMsg(cmd);		

	top.location.href = cmd;

	Delete_Cookie('coords', '/', '');	
}

function SwitchPicture(picName, form, imgType)
{
	if (Get_Cookie('coords') == '') {
		alert('No object to update. This problem could occur if you are using your browsers navigation buttons, back and forward. Select the Cancel button to continue.');
	}
	else {
		cmd = '/servlet/SiteBuilderServlet';
		cmd += '?Command=SetObjectContents';
		cmd += '&Type=Img';
		cmd += '&Contents=' + picName;
		
		if (form) {
			cmd += '&attAltText=' + escape(form.AltText.value);		
		}
		
		cmd += '&PageNum=' + Get_Cookie('page_num');
		cmd += '&Coords=' + Get_Cookie('coords');
		cmd += '&attImgType=' + imgType;
		cmd += '&sUrl=/trellix/sitebuilder/f_edit_page.html';
		cmd += '&fUrl=/trellix/sitebuilder/f_edit_page.html';		
		
		if ((Get_Cookie('debug') * 1) > 0) DebugMsg(cmd);
		
		top.location.href = cmd;
	}

	Delete_Cookie('coords', '/', '');	
}

function AddSound(sName, sFile)
{
	sTag = '<embed src="/trellix/sitebuilder/layout/sounds/' + sName + '" autostart="false" width="145" height="70">';
	
	cmd = '/servlet/SiteBuilderServlet';
	cmd += '?Command=InsertPassThruGem';
	cmd += '&ID=' + '0';
	cmd += '&PassThruHTML=' + escape(sTag);
	cmd += '&PageNum=' + Get_Cookie('page_num');
	cmd += '&Coords=' + Get_Cookie('coords');
	cmd += '&sUrl=/trellix/sitebuilder/f_edit_page.html';
	cmd += '&fUrl=/trellix/sitebuilder/f_edit_page.html';		

	if ((Get_Cookie('debug') * 1) > 0) DebugMsg(cmd);
	
	top.location.href = cmd;
	
	Delete_Cookie('coords', '/', '');	
}

function SetTemplate(sName, sDefaultDesign)
{
	Set_Main_Cookie('XMLFile', sName, '', '/', '');
	Set_Main_Cookie('design', sDefaultDesign, '', '/', '');
	
	top.location.href = 'f_site_name.html';
}

function GetCoords(form)
{
	var bTest = true;
	var iIdx = 0;
	var coords = '';

	while (bTest) {
		if (form.coord[iIdx]) {
			if (form.coord[iIdx].checked == true) {
				if (coords.length > 0) coords = coords + ",";
				coords = coords + form.coord[iIdx].value;
			}
		}
		else {
			bTest = false;
		}
		iIdx++;		
	}
	
	if ((Get_Cookie('debug') * 1) > 2) DebugMsg(coords);		
	
	return coords;
}

function Publish(form, sites, index)
{
	publishLoc = StripSpaces(form.dir_name.value);

	if (publishLoc == "") {  // empty name is not valid
		alert('You did not provide a directory name. You must provide a directory name in order to publish this site.');
		return;
	}	
	if (!isNotExt(publishLoc)) {  // name contains some extended characters
		alert('Your chosen name has special characters that can\'t be used to name a directory. You must use a different name.');
		return;
	} 
	if (!isValidURLDirectoryName(publishLoc)){ // name is not a valid directory name
		alert('Your chosen name has a problem. You can use characters a-z, 0-9 and underscore. Hyphen and period could be used in the middle.');
		return;
	}
	if (!isNameAllLowercase(publishLoc)){  // name should be all in lowercase
		alert('You cannot use uppercase characters on the directory name. You can use characters a-z, 0-9 and underscore. Hyphen and period could be used in the middle.');
		return;
	}
	
	if (isSiteExist(sites, publishLoc, index)) {  // directory name should be unique.
		alert('You have already published a different web site with that directory name. You must use a different name.');
		return;
	}
	
	cmd = '/servlet/SiteBuilderServlet';
	cmd += '?Command=PublishSite';
	cmd += '&SiteDir=' + publishLoc;
	cmd += '&sResource=/trellix/sitebuilder/publish_success.jsp';
	cmd += '&fResource=/trellix/sitebuilder/f_error.jsp';	
	
	if ((Get_Cookie('debug') * 1) > 0) DebugMsg(cmd);	
	
	document.location.href = cmd;
}

function Republish()
{
	top.location.href = 'f_publish.html';
}

function Map(load)
{
	(Get_Cookie('map') == "1") ? Set_Cookie('map', '0', '', '/', '') : Set_Cookie('map', '1', '', '/', '');
	top.location.href = load;
}

function Help(load, wait)
{
	if (wait) {
		if (Get_Cookie('wait') == '1') {
			return;
		}
		
		Set_Cookie('wait', '1', '', '/', '');
	}

	(Get_Cookie('help') == '1') ? Set_Cookie('help', '0', '', '/', '') : Set_Cookie('help', '1', '', '/', '');
	
	if (load == '' || !load) {
		if (Get_Cookie('mode').indexOf('.') == -1) {
			load = '/trellix/sitebuilder/f_' + Get_Cookie('mode') + '.html';
		}
		else {
			load = '/trellix/sitebuilder/' + Get_Cookie('mode');
		}		
	}

	top.location.href = load;
}

function Tips(load)
{
	if (Get_Cookie('help') == '0') {
		Set_Cookie('help', '1', '', '/', '');
	}
	else {
		return;
	}
	
	if (load == '' || !load) {
		load = '/trellix/sitebuilder/f_' + Get_Cookie('mode') + '.html';
	}

	top.location.href = load;
}

function SaveTemplate(name)
{
	cmd = '/servlet/SiteBuilderServlet?Command=SaveTemplate&FileName=' + escape(name) + '&sUrl=/trellix/sitebuilder/f_site_organizer.html&fUrl=/trellix/sitebuilder/f_site_organizer.html';
	top.location.href = cmd;
}

function ImportSite(name)
{
	Set_Cookie('page_num', '1', '', '/', '');

	sUrl = '/servlet/SiteBuilderServlet?Command=OpenSite';
	sUrl += '&FileName=' + escape(name) + '/site.xml';
	sUrl += '&sUrl=/trellix/sitebuilder/f_edit_page.html';
	sUrl += '&fUrl=/trellix/sitebuilder/f_edit_page.html';

	cmd = '';
	cmd += '?SourceDir=' + escape(name);
	cmd += '&sUrl=' + escape(sUrl);
	cmd += '&fUrl=/trellix/sitebuilder/error.html';

	top.location.href = cmd;
}

function OpenSite(name)
{
	Set_Cookie('page_num', '1', '', '/', '');

	cmd = '/servlet/SiteBuilderServlet?Command=OpenSite';
	cmd += '&FileName=' + escape(name) + '/site.xml';
	cmd += '&sUrl=/trellix/sitebuilder/f_edit_page.html';
	cmd += '&fUrl=/trellix/sitebuilder/f_edit_page.html';
	
	top.location.href = cmd;
}

function Login(user)
{
	Set_Cookie('user', user, '', '/', '');
	top.location.href = '/servlet/SiteBuilderServlet?Command=Logon&sUrl=/trellix/sitebuilder/start.jsp&fUrl=/trellix/sitebuilder/f_error.jsp&passphrase=1&partnerid=generic&userid=101&uid='+user;
}

function OpenFaq(detail)
{
    var url = 'http://support.trellix.com/sc/default.asp?partner=10';
    if (detail && detail != '')
    {
        // detail is the category number, section should be 0 if you specify detail.
        // if you need to open a specific doc, then use OpenFaqDoc() function
	    url += '&section=0&detail=' + detail;            
    }
    else
    {
        url += '&section=1';
    }
    OpenTlxWin(url);
}

function OpenFaqDoc(docid)
{
    var url = 'http://support.trellix.com/sc/default.asp?partner=10';
    if (docid && docid != '')
    {
        // section should be 5 if you specify doc_id.
	    url += '&section=5&doc_id=' + docid;
    }
    else
    {
        url += '&section=1';
    }
    OpenTlxWin(url);
}

function OpenTlxWin(varURL)
{
var w = 468;
var h = 490;
 
var xloc = (screen.width - w) / 2;
var yloc = (screen.height - h) / 2;
 
var settings="width="+w+",height="+h+",innerwidth="+w+",innerheight="+h+",left="+xloc+",top="+yloc +",resizable=no"
var SupportCentralWin = window.open(varURL,"SupportCentralWin",settings);
}

function OpenNewWin(loc, wd, ht, winname)
{
    var xloc = (screen.width - wd) / 2;
    var yloc = (screen.height - ht) / 2;
    if (winname == null || winname == '')
        winname = 'popUp';
    var winHelp = window.open(loc, winname,'width='+wd+',height='+ht+'innerwidth='+wd+',innerheight='+ht+',left='+xloc+',top='+yloc+',resizeable=no');
    if (!winHelp.focus()) {
        winHelp.focus();
    }	
}

function AddPageOrg()
{
	cmd = '/servlet/SiteBuilderServlet?Command=AddPage';
	cmd += '&CopyLayout=1';
	cmd += '&BlankXMLFile=blank_page.xml';	
	cmd += '&sUrl=/trellix/sitebuilder/f_site_organizer.html';
	cmd += '&fUrl=/trellix/sitebuilder/f_site_organizer.html';		

	if ((Get_Cookie('debug') * 1) > 0) DebugMsg(cmd);	
	
	top.location.href = cmd;
}

function UnpublishSite(bStarterSite, siteName )
{
	if(bStarterSite){
		alert('You have selected to unpublish your Starter Site.  The next published site in your list will automatically be designated your new Starter Site.  Your Starter Site will allow you to use a shortened URL for accessing that site.  Example: http://partnerurl/username.');
	}

	cmd = '/servlet/SiteBuilderServlet?Command=UnpublishSite';
	cmd += '&XMLFile=' + siteName + '/site.xml';
	cmd += '&sUrl=/trellix/sitebuilder/advanced_options.jsp';
	cmd += '&fUrl=/trellix/sitebuilder/advanced_options.jsp';	
	
	if ((Get_Cookie('debug') * 1) > 0) DebugMsg(cmd);	
	
	top.refreshSponsorships('action');
	window.location.href = cmd; 	
}

function DeleteSite(siteName)
{
	cmd = '/servlet/SiteBuilderServlet?Command=DeleteSite';
	cmd += '&XMLFile=' + siteName + '/site.xml';
	cmd += '&sUrl=/trellix/sitebuilder/advanced_options.jsp';
	cmd += '&fUrl=/trellix/sitebuilder/advanced_options.jsp';	
	
	if ((Get_Cookie('debug') * 1) > 0) DebugMsg(cmd);	
	
	top.refreshSponsorships('action');
	window.location.href = cmd;
}

function MakeDefaultSite(siteName)
{
	cmd = '/servlet/SiteBuilderServlet?Command=MakeDefaultSite';
	cmd += '&XMLFile=' + siteName + '/site.xml';
	cmd += '&sUrl=/trellix/sitebuilder/advanced_options.jsp';
	cmd += '&fUrl=/trellix/sitebuilder/advanced_options.jsp';	
	
	if ((Get_Cookie('debug') * 1) > 0) DebugMsg(cmd);	
	
	top.refreshSponsorships('action');
	window.location.href = cmd;
}

function RaiseTipsWindow(varUrl)
{
	/* valid varUrls:
	 * mapQuestMap
	 * mapQuest
	 * weatherMagnet
	 * weatherViewer
	 * worldGuestbook
	 * fileDownload
	 * buildWebGem
	 * smartAgeBanner
	 * soundWebGem
	 * videoWebGem
     */
	OpenTlxWin('http://support.trellix.com/sc/webGemtips/default.asp?partner=10&varWebGem='+varUrl);
}

function EditNavBar()
{
	top.location.href = '/trellix/sitebuilder/f_site_organizer.html';
}

function submitWizard(form, paramVal)
{
        //form.Wizard.value=paramVal;
        form.action='wizard/f_' + paramVal + '.jsp';
        form.submit();
}

function PreviewSite()
{
        var href = '/servlet/SiteBuilderServlet?Command=RenderPage&PageNum=' + Get_Cookie('page_num') + '&Mode=0&RenderError=/trellix/sitebuilder/f_error.jsp';
        window.open(href,'tlx_preview','toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes');
}
