function verifyExtension( value )
{
	var bValid = false;
	var extensions = ['jpg','gif','png'];
	var extension  = value.substr( value.length - 3 , value.length );
	
	for( i in extensions )
	{
		if( extensions[i] == extension.toLowerCase() )
			return true;
	}
	
	document.getElementById( "FileFile" ).value = "";
	alert( "Arquivo com formato inválido!" );
}

function showHidden()
{
// 	alert(arguments.length);
	for ( var i = 0; i < arguments.length; i++ ) 
	{
    	var sState = document.getElementById( arguments[i] ).style.display;
		if( sState == 'none' )
			document.getElementById( arguments[i] ).style.display = '';
		else
			document.getElementById( arguments[i] ).style.display = 'none';
    }
}

var Dom = YAHOO.util.Dom;
var YEvent = YAHOO.util.Event;
var DDM = YAHOO.util.DragDropMgr;
var tar = [];


DDApp = {
    init: function() {

        var targets = Dom.getElementsByClassName( "area" );
        for ( i=0; i < targets.length ; i++ ) 
        {
            tar.push( new YAHOO.util.DDTarget( targets[i].id ) );
        }
		
		var dragglebles = Dom.getElementsByClassName( "drag" );
        for ( i=0; i < dragglebles.length ; i++ ) 
        {
	        new DDList( dragglebles[i].id );
        }
    }
};


DDList = function( id , sGroup , config ) {

   DDList.superclass.constructor.call( this , id , sGroup , config );

    var el = this.getDragEl();
    Dom.setStyle(el, "opacity", 0.67); // The proxy is slightly transparent

    this.goingUp = false;
    this.lastY = 0;
};

YAHOO.extend(DDList, YAHOO.util.DDProxy, {

    startDrag: function( x , y ) 
    {
        // make the proxy look like the source element
        var dragEl = this.getDragEl();
        var clickEl = this.getEl();
        
        for( i=0; i < tar.length; i++ )
        {
        	var b = new YAHOO.util.ColorAnim( tar[i].getEl() , { backgroundColor: { to: "#6d5f52" } } , 0.3 );
	        b.animate();
        }
        
        Dom.setStyle(clickEl, "visibility", "hidden");

        dragEl.innerHTML = clickEl.innerHTML;

//		Dom.setStyle( dragEl , "width" , "150px" );
//		Dom.setStyle( dragEl , "height" , "90px" );
		Dom.setStyle( dragEl , "overflow" , "hidden" );
        Dom.setStyle( dragEl , "border" , "2px solid gray" );
    },

    endDrag: function( e ) 
    {
        var srcEl = this.getEl();
        var proxy = this.getDragEl();

        Dom.setStyle( proxy , "visibility" , "" );
        var a = new YAHOO.util.Motion( 
            proxy, { 
                points: { 
                    to: Dom.getXY( srcEl )
                }
            }, 
            0.2, 
            YAHOO.util.Easing.easeOut 
        )
        
        var b = {};
        for( i=0; i < tar.length; i++ )
        {
	        b = new YAHOO.util.ColorAnim( tar[i].getEl() , { backgroundColor: { to: "#5A4B41" } } , 0.3 );
	        b.animate();
        }
        
        b.onComplete.subscribe( function(){
        	for( i=0; i < tar.length; i++ )
	        {
	       		Dom.setStyle( tar[i].getEl() , "backgroundColor" , "transparent" );
	       	}
	    });
	    
        var proxyid = proxy.id;
        var thisid = this.id;

        a.onComplete.subscribe( function(){
            Dom.setStyle( proxyid , "visibility" , "hidden" );
            Dom.setStyle( thisid , "visibility", "" );
        });
        a.animate();
    },
    
    onDragDrop: function( e , id ) 
    {
        // If there is one drop interaction, the li was dropped either on the list,
        // or it was dropped on the current location of the source element.
        if (DDM.interactionInfo.drop.length === 1) {

            // The position of the cursor at the time of the drop (YAHOO.util.Point)
            var pt = DDM.interactionInfo.point; 

            // The region occupied by the source element at the time of the drop
            var region = DDM.interactionInfo.sourceRegion; 

            // Check to see if we are over the source element's location.  We will
            // append to the bottom of the list once we are sure it was a drop in
            // the negative space (the area of the list without any list items)
            if (!region.intersect(pt)) {
                
                var destEl = Dom.get(id);
                var destDD = DDM.getDDById(id);
                
                if ( destEl.nodeName.toLowerCase() == "ul" ) 
        		{
	                var p = destEl.firstChild.parentNode;
	                p.insertBefore(this.getEl(), destEl.firstChild)
                
               		DDM.refreshCache();
               	}
            }
        }
    },
    

    onDrag: function( e ) 
    {
        // Keep track of the direction of the drag for use during onDragOver
        var y = YEvent.getPageY( e );

        if( y < this.lastY ){
            this.goingUp = true;
        }
        else if( y > this.lastY ){
            this.goingUp = false;
        }

        this.lastY = y;
    },

    onDragOver: function( e , id ) 
    {
        var srcEl = this.getEl();
        var destEl = Dom.get( id );

        if ( destEl.nodeName.toLowerCase() == "li" ) 
        {
            var p = destEl.parentNode;

            if (this.goingUp) {
                p.insertBefore(srcEl, destEl); // insert above
            } else {
                p.insertBefore(srcEl, destEl.nextSibling); // insert below
            }

            DDM.refreshCache();
        }
    }
});

var saveCategory;