var errorMessage = "A operação não pode ser realizada. Por favor tente novamente.\nCaso o erro persita, contate o administrador do sistema."
var openedGuide = 0

function setCookie( name, value , expires )
{
	c = name + "=" + escape(value) 
    if( ! expires )
	{
		var today = new Date();
		var dateExpire = new Date( today.getTime() + ( 30 * 1000 * 60 * 60 * 24 ) )
		c += ';expires=' + dateExpire.toGMTString()
	}
	
	document.cookie= c
}

function getCookie( name )
{
	if ( document.cookie.length > 0 )
	{
   		start=document.cookie.indexOf( name + "=" )
  		if ( start!=-1 )
   		{	 
    		start += ( name.length + 1 ) 
			strC = document.cookie.substring( start , document.cookie.length )
			end = strC.indexOf(";")
    	
			if ( end == -1 ) 
				end = document.cookie.length
		
			return unescape(strC.substring( 0 , end ))
		} 
	}
	return null
}

function formatValue( field , format )  
{

	/* Função para formatar um campo no formato definido pelo programador Leandro F Pinto
		
	*****************      Como usar      *************************
	
	chame a função no evento onkeypress do campo exemplo - ( onKeyPress='return formatValue( this , '99/99/9999' )' )
	
	*/

		var strVerify = ""
		var retorno = false
		var key = event.keyCode;
		var keychar = String.fromCharCode( key );
	
		for( x=0; x < format.length ; x++)
		{
			if( isNaN( format.charAt( x ) ) )
			{
				strVerify += x + "|" + format.charAt( x ) + "|"
			}
		}
	
	if( ! isNaN( keychar ) )
	  {
	  		retorno = true
			var strValue = field.value
						
	  		if( strValue.length < format.length )
			{
	  			strVerify = strVerify.split("|")
		
				for( x=0; x < ( strVerify.length - 1 ) ; x += 1)
				{
					tam = strValue.length + ""	
						if( tam == strVerify[x] )
						{
							strValue += strVerify[x+1]
							field.value = strValue
							break
						}
				}
			}
			else
				retorno = false
	  }
	  
	  return retorno
}

function replaceAll( str , strSearch , strNew )
{
	var i = str.indexOf( strSearch );
	
	while( i > -1 )
	{
		str = str.replace( strSearch , strNew );
		i = str.indexOf( strSearch , i + strNew.length + 1);
	}
	
	return str;
}

function showGuide( guideId, c )
{

	if( guideId == null )
		return
	
	if( openedGuide != guideId )
	{
		document.getElementById( 'guide_' + openedGuide ).className = "closedPanel"
		document.getElementById( 'panel_' + openedGuide ).style.display = "none"
	}
	
	document.getElementById( 'guide_' + guideId ).className = "openedPanel"
	document.getElementById( 'panel_' + guideId ).style.display = "block"
	
	openedGuide = guideId
	
	setCookie( c , guideId, true )
	
}

