	// Define constants
var GN_ARRAY_MONTH_NAME = new Array ("Jan", "Fev", "Mar", "Abr", "Mai", "Jun", "Jul", "Ago", "Set", "Out", "Nov", "Dez");

function RemoveQueryString2(strUrl, strParamName)
{
    var retVal;
    
    // have to impose it on both noraml querystring and the UrlEncoded
    // Url which is in the NRORIGINALURL value
    retVal = RemoveQueryStringWithDelimiters2(strUrl, strParamName, '?', '&', '=');
    
    return retVal;
}

function RemoveQueryStringWithDelimiters2(strUrl, strParamName, cQuestionMark, cAmpersand, cEquals)
{
    var twoPartUrl = strUrl.split(cQuestionMark);
    
    if (twoPartUrl.length > 1)
    {
        // a[1] got to be the querystring part of the Url
        var queryStrings = twoPartUrl[1].split(cAmpersand);
        
        // loop through queryStrings array and look for strParamName
        for (var i = 0; i < queryStrings.length; i++)
        {
            if (queryStrings[i].indexOf(strParamName + cEquals) >= 0)
            {
                // found! Set the item to be blank so it won't
                // be added back in later during Url re-construction
                queryStrings[i] = "";
            }
        }
        
        // reconstruct Url using modified queryStrings array
        var retVal = twoPartUrl[0];  // base Url part
        var prefixQuestionMark = true;
        var prefixAmpersand = false;
        for (var i = 0; i < queryStrings.length; i++)
        {
            if (queryStrings[i] != "")  // non-empty means should be added back in
            {
                // add '?' if this is the first querystring param
                if (prefixQuestionMark)
                {
                    retVal += cQuestionMark;
                    prefixQuestionMark = false; // never add '?' again
                }
                
                // see if last param told us to add '&'
                if (prefixAmpersand)
                {
                    retVal += cAmpersand;
                    prefixAmpersand = false;
                }
                
                retVal += queryStrings[i];
                prefixAmpersand = true; // next time prefix '&'
            }
        }
        
        return retVal;
    }
    else
    {
        return strUrl;
    } 
}

function AppendQueryString2(strBaseUrl, strQueryParam, strQueryValue)
{
    if (strBaseUrl.indexOf(strQueryParam + "=") >= 0)
    { 
        return strBaseUrl;
    }
    else
    {
        var chSeparator = '&';
                
        if (strBaseUrl.indexOf('?') < 0 )
        {
            chSeparator = '?';
        }
        
        return strBaseUrl + chSeparator + strQueryParam + '=' + strQueryValue;               
    }
}

function UpdateFrameInPublishedMode2()
{
	window.location.href = GetUrlModePublished2( window.location.href );
}

function UpdateSiblingFramesInPublishedMode2(NewTopUrl)
{
	for (i=0; i < window.top.frames.length; i++) 
	{
		if (window.top.frames[i] != window)
		{
			// refresh it with Published mode URL
			window.top.frames[i].location.href = GetUrlModePublished2( window.top.frames[i].location.href );
		}
	}
	
	//parent.location.href = NewTopUrl;
	window.location.href = GetUrlModePublished2( window.location.href );
}

function UpdateFrameInUnpublishedMode2()
{
	window.location.href = GetUrlModeUnpublished2( window.location.href );
}

/// <summary>
/// Javascript function to update all sibling frames to Unpublished
/// mode after "Switch To Edit Site" has been clicked. This is done
/// in case the action is in a framed site.
/// </summary>
function UpdateSiblingFramesInUnpublishedMode2(NewTopUrl)
{
	for (i=0; i < window.top.frames.length; i++) 
	{
		if (window.top.frames[i] != window)
		{
			// refresh it with Unpublished mode URL
			window.top.frames[i].location.href = GetUrlModeUnpublished2( window.top.frames[i].location.href );
		}
	}

	//parent.location.href = NewTopUrl;
	window.location.href = GetUrlModeUnpublished2( window.location.href );
}

function GetUrlModePublished2( strUrl )
{
	if (strUrl.indexOf("NRMODE=") > 0)
	{
		strUrl = strUrl.replace(/NRMODE=Unpublished/, "NRMODE=Published");
		strUrl = strUrl.replace(/NRMODE%3dUnpublished/, "NRMODE%3dPublished");
		strUrl = strUrl.replace(/NRMODE=Update/, "NRMODE=Published");
		strUrl = strUrl.replace(/NRMODE%3dUpdate/, "NRMODE%3dPublished");
	}
	else
	{
		strUrl = AppendQueryString2( strUrl, "NRMODE", "Published" );
	}

    // need to get rid of WBCMODE and wbc_purpose in query string
	strUrl = RemoveQueryString2( strUrl, "WBCMODE");
	strUrl = RemoveQueryString2( strUrl, "wbc_purpose");
	return strUrl;
}

/// <summary>
/// Javascript function to return a Url in Unpublished mode, based
/// on the passed in URL. 
/// </summary>
function GetUrlModeUnpublished2( strUrl )
{
	if (strUrl.indexOf("NRMODE=") > 0)
	{
		strUrl = strUrl.replace(/NRMODE=Published/, "NRMODE=Unpublished");
		strUrl = strUrl.replace(/NRMODE%3dPublished/, "NRMODE%3dUnpublished");
		strUrl = strUrl.replace(/NRMODE=Update/, "NRMODE=Unpublished");
		strUrl = strUrl.replace(/NRMODE%3dUpdate/, "NRMODE%3dUnpublished");
	}
	else
	{
		strUrl = AppendQueryString2( strUrl, "NRMODE", "Unpublished" );
	}

    // need to append WBCMODE and wbc_purpose querystring parameters
    // for PresentationUnpublished mode.
	strUrl = AppendQueryString2( strUrl, "WBCMODE", "PresentationUnpublished" );
	strUrl = AppendQueryString2( strUrl, "wbc_purpose", "Basic" );
	return strUrl;
}

function CMS_openWindowPageProperties2( strDlgURL )
{
	WBC_openWindowOnFocus(strDlgURL, "WBC_winPagePropsDlg", IDS_WIN_PAGEPROPS_FEATURES);
}

function DoSwitchToPublished()
{
	var fmeContents = window.top.frames["ContentsFrame"];
	fmeContents.SwitchToPublished();
}

function DoSwitchToUnpublished()
{
	var fmeContents = window.top.frames["ContentsFrame"];
	fmeContents.SwitchToUnpublished();
}

//	Write date in local time
function GN_writeUTC2Local(strDate)
{
	var pDate = new Date(strDate);
	GN_writeDate(GN_convertUTC2Local(pDate));
}

//	Write date using document.write()
function GN_writeDate(pDate) 
{
	document.write( GN_formatDateToString( pDate, false ) );
}

//	Convert GMT time to local time
function GN_convertUTC2Local(pDateUTC)
{
	return new Date(pDateUTC.getTime() - pDateUTC.getTimezoneOffset() * 60 * 1000);
}	

//	Return a date string in the "DD MMM YYYY, hh:mm:ss am/pm" or 24 hour "DD MMM YYYY, hh:mm:ss" format
function GN_formatDateToString( pDate, bAmPm )
{
	if (bAmPm)
	{
		var nHours =  pDate.getHours();
		var strAmPm;
		if (nHours == 0) {
			nHours = 12;
			strAmPm = "am";
		} else if (nHours == 12) {
			strAmPm = "pm";
		} else if (nHours > 12) {
			nHours = nHours - 12;
			strAmPm = "pm";
		} else {
			strAmPm = "am";
		}

		return ( GN_addLeadingZero(pDate.getDate()) + " " + GN_ARRAY_MONTH_NAME[pDate.getMonth()] + " " + GN_fixJavaScriptYear(pDate.getFullYear()) + ", " + GN_addLeadingZero(nHours) + ":" + GN_addLeadingZero(pDate.getMinutes()) + ":" + GN_addLeadingZero(pDate.getSeconds()) + " " + strAmPm );
	}
	else
	{
		return ( GN_addLeadingZero(pDate.getDate()) + " " + GN_ARRAY_MONTH_NAME[pDate.getMonth()] + " " + GN_fixJavaScriptYear(pDate.getFullYear()) + " " + GN_addLeadingZero(pDate.getHours()) + ":" + GN_addLeadingZero(pDate.getMinutes()) + ":" + GN_addLeadingZero(pDate.getSeconds()));
	}
}

// Add leading zero to number less than 10
function GN_addLeadingZero(nNum)
{
	if (nNum < 10) 
	{
		return "0" + nNum;
	}
	else 
	{
		return nNum;
	}
}

// Returns correct year for any year after 1000
function GN_fixJavaScriptYear( nYear )
{
	if (nYear < 1000) 
	{
		return nYear + 1900;
	}
	else 
	{
		return nYear;
	}
}

//	Convert GMT time to local time
function GN_convertUTC2Local(pDateUTC)
{
	return new Date(pDateUTC.getTime() - pDateUTC.getTimezoneOffset() * 60 * 1000);
}	

function ShowUtcDate( strdata )
	{
		//alert(strdata)
		
		var arrData = strdata.split( '-');
		//alert(" DATA DE ENTRADA:" + strdata.getDate() + "-" + strdata.getMonth() + 1 + "-" + strdata.getFullYear())
		//var pDate = new Date(strdata);
		if(arrData.length > 5){
			//
			var pDate = new Date(arrData[2],arrData[1] - 1,arrData[0], arrData[3], arrData[4],arrData[5]);		
			//alert(" DATA DE SAIDA:" + pDate.getDate() + "-" + pDate.getMonth()  + "-" + pDate.getFullYear())
						
			return GN_formatDateToString(GN_convertUTC2Local(pDate), false)			
		}
		return strdata;
	}

