//************************************************************************************
//File:		/NR/System/WBC/PopUp/Cross-Browser/PageOperation/AuthoringMode/PageAuthoring.js
//Author:	Microsoft Corporation.
//Purpose:	Display functions used for saving and transfering info from the NewPageSaveDlg.asp(for getting
//          page properties) to NewPageSave.asp.  Entry pt is Authoring Form when Save button is pressed. 
//			Exit pt is when NewPageSave.asp for saving the page information.
//
//*************************************************************************************

var g_NewPageSaveDlgForm;

// ---- [Public] Set up default variables
function WBC_onLoadHandler() 
{	
	g_NewPageSaveDlgForm = window.document.NC_NewPageSaveDlgForm;
}

//	---- [Public] Transfer content to authoring form from NewPageSaveDlg so that when authoring does
//  a submit, it also has the information that is from the NewPageSaveDlg
function WBC_onOkayClick(bContinueAuthoring)
{
	
	// If data on the NewPageSaveDlg is valid
	if (WBC_ValidateData())
	{
		//move the name and display name from the display name form to edit form successful
		if (WBC_transferFormContent())
		{
			 
			//now get the WBC_doSubmitForm function from the authoring form and do a submit 
			var pFuncWin = WBC_getFuncWin("WBC_savePosting", window.top.opener);
			if (pFuncWin)
			{ 	 
				if (bContinueAuthoring == true)
				{
					//2nd parameter means new page
					pFuncWin.WBC_savePosting(IDS_ACTION_SAVE, true);
				}
				else
				{
					//2nd parameter means new page
					pFuncWin.WBC_savePosting(IDS_ACTION_SAVEANDEXIT, true);
				}	
			}
			else 
			{   
				alert(IDS_FUNCTION_NOT_FOUND);
				return false;
			}
			
			window.close();
			return true;
		}
	}
	return false;
}

//	---- [Public] Check if the informatin in the NewPageSaveDlg.asp is valid or not.
function WBC_ValidateData()
{	 
	var strNewPageSaveDlgName;
	strNewPageSaveDlgName = g_NewPageSaveDlgForm.NC_intxtName;
	if (!WBC_verifyInputName(strNewPageSaveDlgName))
	{
		alert(IDS_INVALID_NAME)
		return false;
	}	
	return true;
}

//	---- [Public] Transfer content from NewPageSaveDlg to the authoring form
function WBC_transferFormContent()
{
	
	// look for main authoring form 
	var pFuncWin = WBC_getFuncWin("WBC_setNewPageInfo", window.top.opener);
	
	if (pFuncWin) 
	{	
		pFuncWin.WBC_setNewPageInfo(g_NewPageSaveDlgForm.NC_intxtName.value, g_NewPageSaveDlgForm.NC_intxtDisplayName.value);
		return true;
	}
	else
	{
		alert(IDS_FUNCTION_NOT_FOUND);
		return false;
	}
	
	 
}



