function ExecuteState(actionFile, idElementDest, state, params){
	aux ='';
	if(state && state.length > 0)
		aux += '&state='+state;
	if(params && params.length > 0)
		aux += '&'+params;
	fnAjaxSendHtml(actionFile, aux , '_ExecuteState' ,' , "'+idElementDest+'"');	
}

function _ExecuteState(retorno , idElementDest){
	$j(idElementDest).innerHTML = retorno;
	setScriptAjax(retorno, $j(idElementDest));
}

function ExecuteStateReturnFunction(actionFile, funcaoJsRetorno, state  , params){
	aux ='';
	if(state && state.length > 0)
		aux += '&state='+state;
	if(params && params.length > 0)
		aux += '&'+params;
	fnAjaxSend(actionFile,'&'+aux,funcaoJsRetorno,'');
}

function FormSubmitAjaxArray(formId, actionFile, funcaoJsRetorno, param){
	formSereliazed = getCampoSerialized(formId);
	fnAjaxSend(actionFile,formSereliazed,funcaoJsRetorno," ,'"+param+"'");
}


function FormSubmitAjax(formId, actionFile, funcaoJsRetorno, idElementDest){
	fnAjaxSendHtml(actionFile, getCampoSerialized(formId) ,funcaoJsRetorno,' , "'+idElementDest+'"');
}

function FormSubmitAjaxReturnToDiv(formId , actionFile , idElementDest){
	FormSubmitAjax(formId , actionFile , "_FormSubmitAjax" , idElementDest)
}

function _FormSubmitAjax(retorno , idElementDest){
	if(idElementDest.length > 0 && $j(idElementDest))
		$j(idElementDest).innerHTML = retorno;
	else
		$j('divPrincipal').innerHTML = retorno;
}

// function submitFormPaginacao(idForm, numPagina){
// 	if($j('hidenPagina')){
// 		$j('hidenPagina').value = numPagina; 
// 	}
// 	
// 	if($j(idForm)){
// 		$j(idForm).submit();
// 	}
// }

function getCampoSerialized(formId){
	inputs = $(formId).getInputs();
	
	for(var x=0; x < inputs.length; x++){
		validaFckCampo(inputs[x].id);
	}
	return '&'+$(formId).serialize();
}

function validaFckCampo(id){
	if($j(id+"___Config")){
		if(typeof(FCKeditorAPI) != 'undefined' && typeof(FCKeditorAPI) != 'unknown' ){
			if(FCKeditorAPI.GetInstance(id).EditMode == 1 || FCKeditorAPI.GetInstance(id).EditMode == 1 ){
				alert("Para enviar as informações HTML, desabilite os botões 'Código Fonte' na barra de ferramentas dos editores.");
				return false;
			}else{
				$j(id).value=setEntidadeHTML(1, FCKeditorAPI.GetInstance(id).GetXHTML(true));
			}
		}
	}
}

function setEntidadeHTML(tipconversao, texto){
    var eHTML1 = new Array("&Aacute;","&Eacute;","&Iacute;","&Oacute;","&Uacute;","&Agrave;","&Egrave;","&Igrave;","&Ograve;","&Ugrave;","&Atilde;","&Otilde;","&Acirc;","&Ecirc;","&Icirc;","&Ocirc;","&Ucirc;","&aacute;","&eacute;","&iacute;","&oacute;","&uacute;","&agrave;","&egrave;","&igrave;","&ograve;","&ugrave;","&atilde;","&otilde;","&acirc;","&ecirc;","&icirc;","&ocirc;","&ucirc;","&ccedil;","&Ccedil;","&amp;","&nbsp;","&lt;","&gt;","&deg;","&ordf;");
    var eHTML2 = new Array("Á","É","Í","Ó","Ú","À","È","Ì","Ò","Ù","Ã","Õ","Â","Ê","Î","Ô","Û","á","é","í","ó","ú","à","è","ì","ò","ù","ã","õ","â","ê","î","ô","û","ç","Ç","&","&nbsp;","<",">","º","ª");

    for(i=0; i< eHTML1.length; i++){
        switch(tipconversao){
            case 1:
                charFind = eHTML1[i];
                charReplace = eHTML2[i];
                break;
            case 2:
                charFind = eHTML2[i];
                charReplace = eHTML1[i];
                break;
            default:
                alert('Você não definiu o tipo da conversão na função setEntidadeHTML.');
                return false;
                break;
        }
        texto = texto.replace(eval('/'+charFind+'/g'), charReplace);
    }

    return texto;
}

//função para obrigar preenchimento ou seleção de campo
function obrigatorio(ids,titulos) {
	var id,titulo,i,tipo
	var exp_valida_email = /^[\w-]+(\.[\w-]+)*@(([\w-]{2,63}\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/
	
	id = ids.split("|");
	titulo = titulos.split("|");
	
	for (i=0;i < id.length;i++) {
		tipo = $j(id[i]).type;
		if(!$j(id[i]).value || $j(id[i]).value.trim() == ""){
			tipo = $j(id[i]).type;
				if (tipo == "select-one"){
				alert("O campo "+titulo[i]+" deve ser selecionado");
			}else{
				if((tipo == "text") || (tipo == "textarea") || (tipo == "password")){
					alert("O campo "+titulo[i]+" deve ser preenchido");
				}
			}
			
			$j(id[i]).focus();
			return false;
		}else if($j(id[i]).name.search(/email/i) >= 0){
			if(exp_valida_email.test($j(id[i]).value) == false){
				alert("Por favor, digite um "+titulo[i]+" valido.");
				
				$j(id[i]).focus();
				return(false);
			}
		}
	}
	return true;
}

function obrigatorioV2(ids,titulos, elementId) {
	var id,titulo,i,tipo
	var exp_valida_email = /^[\w-]+(\.[\w-]+)*@(([\w-]{2,63}\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/
	
	id = ids.split("|");
	titulo = titulos.split("|");
	msg = '';
	var  apenasEmail = true;
	for (i=0;i < id.length;i++) {
		tipo = $(id[i]).type;
		
		if(!$(id[i]).value || $(id[i]).value.trim() == ""){
			apenasEmail = false;
			tipo = $(id[i]).type;
			if (tipo == "select-one"){
				msg += "O campo "+titulo[i]+" deve ser selecionado"+"<br />";
			}else{
				if((tipo == "text") || (tipo == "textarea") || (tipo == "password")){
					msg += "O campo "+titulo[i]+" deve ser preenchido"+"<br />";
				}
			}
		}else if($(id[i]).name.search(/email/i) >= 0){
			if(exp_valida_email.test($(id[i]).value) == false){
				msg += "Por favor, digite um "+titulo[i]+" valido."+"<br />";
			}
		}
	}
	if (msg != "") {
		if (titulos == '') {
			if (!apenasEmail) {
				msg = "Os campos marcados com <strong>*</strong> são de preenchimento obrigatórios.";
			}
			else {
				msg = "O campo <strong>email</strong> está preenchido incorretamente.";
			}
		}
		elementId = (elementId == null) ? 'msgRetorno' : elementId;
		document.getElementById(elementId).className = 'wbp_msg_error';
		document.getElementById(elementId).innerHTML = msg;
		document.getElementById(elementId).style.display = '';
		return false;
	} else {
		return true;
	}
}

function SwitchMenu(obj,name){
	if(document.getElementById){
	var el = document.getElementById(obj);
	var ar = document.getElementById(name).getElementsByTagName("span"); //DynamicDrive.com change
		if(el.style.display != "block"){ //DynamicDrive.com change
			for (var i=0; i<ar.length; i++){
				if (ar[i].className=="submenu") //DynamicDrive.com change
				ar[i].style.display = "none";
			}
			el.style.display = "block";
		}else{
			el.style.display = "none";
		}
	}
}

function selecionaTodos(elementName , seleciona){
	campo_box = document.getElementsByName(elementName);
	for(var x=0; x < campo_box.length; x++){
		campo_box[x].checked = seleciona;
	}
}

function carregar_calendario(entrada,botao) {
    Calendar.setup(
    {
	inputField : entrada, // ID of the input field
	ifFormat : "%d/%m/%Y", // the date format
	button : botao // ID of the button
	}
    );
}

function orderField(campo, execFunction){
	if($j('order')){
		if($j('order').value == campo){
			$j('order').value = campo + " desc";
		}else{
			$j('order').value = campo;
		}
	}
	
	submitFormPaginacao();
}

// Metodo para abrir popUP
var win = null;
function NewWindow(mypage,myname,w,h,scroll,toolbar,statubar){
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	
	settings = 'height='+h+',width='+w+',scrollbars='+scroll+',resizable,toolbar,status'
	win = window.open(mypage,myname,settings)
}

/**
* Adiciona mï¿½todo lpad() ï¿½ classe String.
* Preenche a String ï¿½ esquerda com o caractere fornecido,
* atï¿½ que ela atinja o tamanho especificado.
*/
String.prototype.lpad = function(pSize, pCharPad)
{
	var str = this;
	var dif = pSize - str.length;
	var ch = String(pCharPad).charAt(0);
	for (; dif>0; dif--) str = ch + str;
	return (str);
} //String.lpad


/**
 * Adiciona metodo trim() ï¿½ classe String.
 * Elimina brancos no inï¿½cio e fim da String.
 */
String.prototype.trim = function()
{
	return this.replace(/^\s*/, "").replace(/\s*$/, "");
} //String.trim


function printr( input, _indent ) {
	// Recuo
	
	var indent = ( typeof( _indent ) == 'string' ) ? _indent + '    ' : '    '
	var parent_indent = ( typeof( _indent ) == 'string' ) ? _indent : '';
	
	var output = '';
	
	// Tipo de Elemento do Array
	
	switch( typeof( input ) )
	{
	case 'string':
		output        =    "'" + input + "'\n";
	break;
	
	case 'number':
		output        =    input + "\n";
	break;
		
	case 'boolean':
		output        =    ( input ? 'true' : 'false' ) + "\n";
	break;
	
	case 'object':
		output        =    ( ( input.reverse ) ? 'Array' : 'Object' ) + "\n";
	
		output       +=    parent_indent + "(\n";
	
		for( var i in input )
		{
		output +=    indent + '[' + i + '] => ' + printr( input[ i ], indent );
		}
	
		output       +=    parent_indent + ")\n"
	break;
	}

	
	
	return output;
}

function getVarPHP(varPHP) {
	if(varPHP)
		return JSON.parse(varPHP);
}

function print_r(variavel){
	alert(printr(variavel));
}

function str_replace(search, replace, subject) {
    var f = search, r = replace, s = subject;
    var ra = r instanceof Array, sa = s instanceof Array, f = [].concat(f), r = [].concat(r), i = (s = [].concat(s)).length;
 
    while (j = 0, i--) {
        if (s[i]) {
            while (s[i] = (s[i]+'').split(f[j]).join(ra ? r[j] || "" : r[0]), ++j in f){};
        }
    };
 
    return sa ? s : s[0];
}



var popupStatus;
function togglePopupWBP(url, width, height, _bgClose, _bgColor){
	if(popupStatus==0 || typeof(popupStatus)=='undefined'){
		popupStatus = 1;
		tb_show("BUSCA DE CURRICULOS",url+"&height=370&width=500&TB_iframe=true");
	} else {

		popupStatus = 0;
		tb_remove();
	}

}


