// VALIDATORS

function CheckValidatorsGroup(groupID)
{
    Page_ClientValidate();
    
    var controlsAlreadyValidated = new Array();
    for (var i = 0; i < Page_Validators.length; i++) {
        var control = document.getElementById(Page_Validators[i].controltovalidate);
    
        if(!controlsAlreadyValidated.contains(control)){
            if(Page_Validators[i].validationGroup == groupID)
            {
                ChangeControlStyle(control,Page_Validators[i].isvalid);
            }
            if(!Page_Validators[i].isvalid)
            {
		        controlsAlreadyValidated.include(control);
	        }
        }
    }
}

function ChangeControlStyle(control, isvalid)
{
    if(!isvalid)
	{
	    control.style.borderColor = isvalid ? "" : "#FF0000";
	    if($('PreencheErro'))
	    {
			$('PreencheErro').setStyle('display','block');
	    }
    }
    else{
        var control = document.getElementById(control.id);
	    control.style.borderColor = "";
    }
}

/* EMBED - used by TinyMCE */

function writeFlash(p) {
	writeEmbed(
		'D27CDB6E-AE6D-11cf-96B8-444553540000',
		'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0',
		'application/x-shockwave-flash',
		p
	);
}

function writeShockWave(p) {
	writeEmbed(
	'166B1BCA-3F9C-11CF-8075-444553540000',
	'http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=8,5,1,0',
	'application/x-director',
		p
	);
}

function writeQuickTime(p) {
	writeEmbed(
		'02BF25D5-8C17-4B23-BC80-D3488ABDDC6B',
		'http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0',
		'video/quicktime',
		p
	);
}

function writeRealMedia(p) {
	writeEmbed(
		'CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA',
		'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0',
		'audio/x-pn-realaudio-plugin',
		p
	);
}

function writeWindowsMedia(p) {
	p.url = p.src;
	writeEmbed(
		'6BF52A52-394A-11D3-B153-00C04F79FAA6',
		'http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701',
		'application/x-mplayer2',
		p
	);
}

function writeEmbed(cls, cb, mt, p) {
	var h = '', n;

	h += '<object classid="clsid:' + cls + '" codebase="' + cb + '"';
	h += typeof(p.id) != "undefined" ? 'id="' + p.id + '"' : '';
	h += typeof(p.name) != "undefined" ? 'name="' + p.name + '"' : '';
	h += typeof(p.width) != "undefined" ? 'width="' + p.width + '"' : '';
	h += typeof(p.height) != "undefined" ? 'height="' + p.height + '"' : '';
	h += typeof(p.align) != "undefined" ? 'align="' + p.align + '"' : '';
	h += '>';

	for (n in p)
		h += '<param name="' + n + '" value="' + p[n] + '">';

	h += '<embed type="' + mt + '"';

	for (n in p)
		h += n + '="' + p[n] + '" ';

	h += '></embed></object>';

	document.write(h);
}


/* end EMBED - used by TinyMCE */

// CLEAR DEFAULTS
function clearDefault(el) {
	if (el.defaultValue==el.value){ el.value = ""; }
}

function restoreDefault(el) {
	if (el.value == ""){ el.value = el.defaultValue; }
}

function initClearDefaults(){
	$$('input.cleardefault').each(function(el, i){
		el.addEvent("focus",function(event){
			clearDefault(el);
		});
		el.addEvent("blur",function(event){
			restoreDefault(el);
		});
	});
}
//end CLEAR DEFAULTS

//FIX Hover IE6
function fixIE6Hover(selector, cssClass){
	if (Browser.Engine.trident4) {
		$$(selector).each(function(el){
			el.addEvents({
				'mouseenter':function(){
					el.toggleClass(cssClass);
				},
				'mouseleave':function(){
					el.toggleClass(cssClass);
				}
			});	
		});
	}
}

// Destaques homepages
window.addEvent('domready', function() {
	
	initClearDefaults();
	
	if($('destaqueFundo')){
		$('destaqueFundo').set('morph',{duration: 500, transition: Fx.Transitions.Sine.easeInOut});								  
		$('destaqueFundo').setStyle('opacity','0');
	}

	$$('.destaqueConteudo').each(function(el){
		el.set('morph',{duration: 500, transition: Fx.Transitions.Sine.easeInOut});								  
		el.setStyle('opacity','0');
	
	});	

	$$('.destaqueItemDetalhe a').each(function(element){
		
		element.addEvent("click",function(event){
			event.stop();									 	
		
			var destaqueItem = element.get("href").split("#")[1];	

			if($(destaqueItem)){			
				$(destaqueItem).morph({								
					'opacity': 1
				});

				$('destaqueFundo').morph({				
					'opacity': 0.7
				});
			}
			
		});

	});	

	$$('.fecharDestaque').each(function(element){						   
										
		element.addEvent("click",function(event){
			event.stop();									 	
			
			var itemFechar = element.get("rel");

			$(itemFechar).morph({
				'opacity': 0
			});

							
			$('destaqueFundo').morph({
				'opacity': 0
			});
		});	
	});
	
	
	
	fixIE6Hover('.destaqueItem a','over');
	
//	/* LOAD PRINT BUTTON  */
//	$$('.print').each(function(el,i){
//		new Element('a',{
//			'href'  :'#',
//			'title' :'Imprimir',
//			'text'  :'Imprimir',
//			'class' :'iconPrint',
//			'events': {
//				'click': function(){window.print();}
//			}
//		}).inject(el);
//	});
	
});