//************************************************************************************
//File:		/Gremlin/assets/scripts/multipostdlg.js
//Author:	Dell Professional Services
//Purpose:	Display functions used for saving and transfering info from the MultiPostSelect.aspx (for getting
//          multiple post properties) to the base posting
//
//*************************************************************************************

var g_MultipostSaveDlgForm;
var MULTI_POST_NONE_SELECTED_KEY = "[NONE]";

// ---- [Public] Set up default variables
function GRMLN_MultiPostOnLoadHandler() 
{	
	var strMultipostSaveDlgData;
	var pFuncWin;
	
	g_MultipostSaveDlgForm = window.document.MultipostSaveDlgForm;
}

function GRMLN_getMainPostbackFormWindow()
{
	var pTargetWin = window.top.opener;
	
	if (pTargetWin) 
	{
		// try the window itself first
		if (IsMainPostbackFormWindow(pTargetWin) == true)
		{
			return pTargetWin;
		}
		// if not found, look into the children frames
		for (i=0; i < pTargetWin.top.frames.length; i++) 
		{
			if (IsMainPostbackFormWindow(pTargetWin.top.frames[i]) == true)
			{
				return pTargetWin.top.frames[i];
			}
		}
	}

	return null;
}

function IsMainPostbackFormWindow(pWindow)
{
    if (pWindow.__CMS_PostbackForm)
    {
	    if ((pWindow.__CMS_PostbackForm.MultiPostSelectedLocations != null))
	    {
		    return true;
	    }
	}
	return false;
}

//	---- [Public] Transfer content to authoring form from MultipostSaveDlgForm so that when authoring does
//  a submit, it also has the information that is from the MultipostSaveDlgForm
function GRMLN_onOkayClick()
{
    //	Check if the information in the MultipostSaveDlgForm.aspx is valid or not.
//	var strMultipostSaveDlgData;
//	strMultipostSaveDlgData = g_MultipostSaveDlgForm.MultiPostSelectedLocations.value;
	// If data on the form is valid save it
//	if (strMultipostSaveDlgData != "")
//	{
//	    var pFuncWin = GRMLN_getMainPostbackFormWindow();
//	    if (pFuncWin) 
//	    {
//    		//move the data from the form to edit form successful
//		    pFuncWin.GRMLN_setMultiPostInfo(strMultipostSaveDlgData);
			window.close();
		    return true;
//	    }
//	    else
//	    {
//		    alert("Error: Function not found.");
//		    return false;
//	    }	
//	}
//	else
//	{
	    //No data to save
//		pFuncWin.GRMLN_setMultiPostInfo(MULTI_POST_NONE_SELECTED_KEY);
//        return true;
//	}
}

// Set MultiPost Info
// When multiposting, save this data to the form for the post back
function GRMLN_setMultiPostInfo(strLocations)
{
	__CMS_PostbackForm.MultiPostSelectedLocations.value = strLocations;
	alert("set :" + strLocations);
}

/// <summary>
///		Javascript function in repsonse to "Create New Page" Console link clicked
/// </summary>
function GRMLN_openWindowMultiPostPage( strDlgURL )
{
    //var strQString = "?sl=" + __CMS_PostbackForm.MultiPostSelectedLocations.value;
    WBC_openWindowOnFocus(strDlgURL, "MultiPostSelectForm", WBC_UseDefaultSizing(window.top));
}