function alterForm(value, campoId, action){
	if( value > 0 ){
		var field = document.getElementById(campoId);
		setLocaleNull(field);
	
		var xmlhttp = ajax();
	
		xmlhttp.open("GET", "funcoesLocais.php?id="+value+"&action="+action);
	
	        xmlhttp.onreadystatechange=function() {
	                if (xmlhttp.readyState == 4) {
	                        var conteudo = url_decode(xmlhttp.responseText);
	                        var conteudoArray = conteudo.split(";");
				if (conteudoArray.length > 1) {
	                                for(i = 0; i < conteudoArray.length; i++) {
	                                        var conteudoArrayTemp = conteudoArray[i].split("|");
						field.options[i] = new Option(conteudoArrayTemp[1], conteudoArrayTemp[0], false, false);
	                                }
	                        }
	                }
	        }
	        xmlhttp.send(null)
	}
	else{
		var field = document.getElementById(campoId);
                setLocaleNull(field);
	}
}

function setLocaleNull(selectForm)
{
        var qtdeformLocale = selectForm.length;
        if( qtdeformLocale > 0 )
        {
                while (qtdeformLocale != 0)
                {//exclui elementos antigos
                        selectForm.options[0] = null;
                        qtdeformLocale = selectForm.length;
                }
        }
}

// url_decode version 1.0
function url_decode(str) {
        var n, strCode, strDecode = "";

        for (n = 0; n < str.length; n++) {
                if (str.charAt(n) == "%") {
                        strCode = str.charAt(n + 1) + str.charAt(n + 2);
                        strDecode += String.fromCharCode(parseInt(strCode, 16));
                        n += 2;
                } else if (str.charAt(n) == "+") {
                        strCode = str.charAt(n);
                        strDecode += " ";
                } else {
                        strDecode += str.charAt(n);
                }
        }
        return strDecode;
}

function ajax(){
        try{
                xmlhttp = new XMLHttpRequest();
        }
        catch(ee){
                try{
                        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
                }
                catch(e){
                        try{
                                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                        }
                        catch(E){
                                xmlhttp = false;
                        }
                }
        }
        return xmlhttp;
}

function alteraInclusao(plano){
        var plano_id;
        var perfil_id;
        var ppd;
        switch(plano){
                case "Pro":
                        plano_id = 1;
                        perfil_id = 1;
                        ppd = 0;
                break;
                case "Est":
                        plano_id=2;
                        perfil_id=3;
                        ppd = 0;
                break;
                case "Ope":
                        plano_id=7;
                        perfil_id=9;
                        ppd = 0;
                break;
                case "ppd":
                        plano_id = 9;
                        perfil_id = 1;
                        ppd = 1;
                break;
        }
        document.getElementById("plano_id_inc").value= plano_id;
        document.getElementById("perfil_id_inc").value= perfil_id;
        document.getElementById("ppd_id_inc").value= ppd;
}
