// JavaScript Document
// Por DigitMídia - Mídia Digital & Design - www.digitmidia.com.br

function modal(action,divTarget, html, title){

	switch (action) {
		case 'show':
				var el = new Element('div', {'id':divTarget});
				el.setProperties({'class':'bodyOverlay'});

				var elContent 	= new Element('div', {'id':divTarget+'Content'}).injectInside(el);
				var elBar 	= new Element('div', {'id':divTarget+'Bar'});
				var elBody 		= new Element('div', {'id':divTarget+'Body'});
				
				if(title != ''){
					elBar.setHTML('<span>'+title+'</span><a href=javascript:modal(\'hide\',\''+divTarget+'\');><span>x</span> fechar</a>')
				}
				
				elBar.setProperties({'class':'bodyOverlayBar'});
				elBody.setProperties({'class':'bodyOverlayBody'});

				elContent.appendChild(elBar);
				elContent.appendChild(elBody);
				elBody.setHTML(html);
				elContent.setProperties({'class':'bodyOverlayContent'});
				
				$E('body').appendChild(el);
			break;
		case 'hide':
				$E('body').removeChild($(divTarget));
			break;
		default:
			return false;
			break;
	}		
}
function ajaxCall(url, campo, loadShow){
	new Ajax(url, {
		method: 'get',
		evalScripts: true,
		update: $(campo)
	}).request();
}

function ajaxForm(formId, target, loadShow){
	$(formId).send({
			update: $(target),
			evalScripts:true
			});
	if(loadShow == true){
		$(target).innerHTML = 'Por Favor Aguarde...';
	}
	return false;
}

function divShow(target,tipo){
	$(target).style.display = tipo;
}
function curriculoEnviar( formId,target ){
	ajaxForm( formId,target,true );
	divShow( target, 'block' );
	divShow( formId, 'none' );
	window.setTimeout( "divShow( '"+target+"','none')", 3000);
	window.setTimeout( "divShow( '"+formId+"','block')", 3000);
}

/*  OPTIONS */

function loaderOrientador(target,filter,type){
	jSonOptions(target,"/vetorOrientador.php?filtro="+filter+"&type="+type);
}
function jSonOptions(target,targetUrl){
	var url = targetUrl;
	var jSonRequest = new Json.Remote(url,{
									  onRequest:function(){
										elements = $(target).empty();
										elOption = new Element("option",{
																"value": ""
															 });
										elOption.appendText("Aguarde...");
										elOption.injectInside($(target));
										$(target).setProperty("disabled","disabled");
									  },
									  onComplete: function(jsonObj){
										addOptions(target,jsonObj.opts);
										$(target).removeProperty("disabled");
									  },
									  onFailure: function(){
										 clearElement(target);
									  }
									  }).send();
}
function addOptions(target,opt){
	var options = opt;
	clearElement($(target));
	options.each(function(campo){
						  elOption = new Element("option",{
												 	"value": campo.id
												 });
						  elOption.appendText(campo.descricao);
						  elOption.injectInside($(target));
						  })
}
function clearElement(target){
	elements = $(target).empty();
	elOption = new Element("option",{
							"value": ""
						 });
	elOption.appendText("TODAS");
	elOption.injectInside($(target));
	$(target).setProperty("disabled","disabled");
}

function abreJanela(url,name,extra){
	w = window.open(url,name,extra);
	w.focus();
}
/* END OPTIONS */