function GetPage($webUrl, $libraryTitle, $pageName)
{
	$web = Get-SPWeb $webUrl
	#Write-Host $web.Url -ForegroundColor Green
	
	$pageList = $web.Lists[$libraryTitle]
	#Write-Host $pageList.Title -ForegroundColor Green

	$page = $pageList.Items | ? {$_.Name -eq $pageName} 
	#Write-Host $page.Url -ForegroundColor Green
	return $page
}

function GetFile($webUrl, $fileRelativeUrl)
{
	$web = Get-SPWeb $webUrl
	$file = $web.GetFile($fileRelativeUrl)
	
	return $file
}

function GetRelativePageUrlByWebUrl($fullPageUrl, $webUrl)
{
	[System.String] $relativePageUrl = $fullPageUrl.Substring($webUrl.Length+1);

	# Check if exist
	$web = Get-SPWeb $webUrl
	[Microsoft.SharePoint.SPFile] $file = $web.GetFile($relativePageUrl)
	
	if (!$file.Exists)
	{
		Write-Host $($MSG_MISSING_PAGE -f $relativePageUrl, $webUrl) -ForegroundColor Red
		Write-Host $MSG_OPERATION_TERMINATED -ForegroundColor DarkRed
		exit;
	}
	
	return $relativePageUrl;
}

function UpdateLibraryPage($listItem)
{
	$listItem.UpdateOverwriteVersion();
	if($listItem.File.CheckOutType -ne "None") 
	{
	   $listItem.File.CheckIn($MSG_SCRIPT_TITLE)
	}
	
	if($listItem.ParentList.EnableMinorVersions -eq $true -and $listItem.File.MinorVersion -ne 0)
	{
		$listItem.File.Publish($MSG_SCRIPT_TITLE)
	}

	if ($listItem.ParentList.EnableModeration)
    {
        $modInformation = $listItem.ModerationInformation
        if($modInformation.Status -ne [Microsoft.SharePoint.SPModerationStatusType]::Approved)
        {
            $listItem.File.Approve($MSG_SCRIPT_TITLE)
        }
    }	
}

function UpdateRootDefaultPage($fileItem)
{
	if($fileItem.CheckOutType -ne "None") 
	{
	   $fileItem.CheckIn($MSG_SCRIPT_TITLE)
	}
}