function gravarPrefs(caminho, host){
	Sortable.destroy('coluna_esq');
	Sortable.destroy('coluna_dir');
	document.getElementById("ctlogin_btsalvarpref").innerHTML = "<h1 id='msg_conf' class='font10px left normal fntpadrao_link_login' style='margin-top:3px;'>Salvando suas configurações, aguarde...</h1>";
	var strUserPref = elementos(1);
  var url = "gravar_preferencias.php?prefs="+strUserPref;
  ajaxHTML_gravarPrefs(caminho, url);
};
function iniciarPrefs(caminho, aux, host){
	if (aux != "1"){
	  document.getElementById("ctlogin_btsalvarpref").innerHTML = "<img name=\"btsalvarpref\" id=\"idbtsalvarpref\" class=\"pointer\" src=\""+caminho+"btsalvarpref.gif\" onclick=\"gravarPrefs('"+caminho+"', '"+host+"');\" />";
	}  
};
fila=[]
ifila=0
function ajaxHTML_gravarPrefs(caminho, url){
    fila[fila.length]=[caminho,url];
    if((ifila+1)==fila.length){
	    setTimeout("ajaxRun_gravarPrefs()",1100);
    }
};

function ajaxRun_gravarPrefs(){
	if (window.XMLHttpRequest) {
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
		}
		}else if(window.ActiveXObject){
			try {
				http_request = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch(e){
				try {
					http_request = new ActiveXObject("Microsoft.XMLHTTP");
				}catch (e){}
			}
		}
		http_request.open("GET",fila[ifila][1],true);
		http_request.onreadystatechange=function() {
		if (http_request.readyState==4){
			retorno = unescape(http_request.responseText.replace(/\+/g," "));
			if (retorno == "true"){
				document.getElementById("ctlogin_btsalvarpref").innerHTML = "<h1 id='msg_conf' class='font10px left normal fntpadrao_link_login' style='margin-top:3px;'>Configurações salvas com sucesso!</h1>";
				setTimeout("Effect.Fade('msg_conf');",1100);
				
				if(document.getElementById("layout_sel").value != document.getElementById("layout_antigo").value && document.getElementById("layout_antigo").value !== '') {
					window.location.reload();
				}
			}	
			else{
				document.getElementById("ctlogin_btsalvarpref").innerHTML = "<h1 id='msg_conf' class='font10px left normal fntpadrao_link_login' style='margin-top:3px;'>Ocorreu um erro, tente novamente!</h1>";
				setTimeout("Effect.Fade('msg_conf');",1100);
			}	
			// <![CDATA[
			Sortable.create("coluna_esq",{dropOnEmpty:true,tag:'div', containment:["coluna_esq","coluna_dir"], handle:'topobloco', overlap:'vertical', constraint: false, ghosting: true, 
			onUpdate:function(){
				iniciarPrefs("./temas/katatudo/imagens/", "", document.getElementById('form_host').value);
				tiraEspaco();
			}, 
			onChange:function(){
				criaEspaco('coluna_dir');
			}});
			Sortable.create("coluna_dir",{dropOnEmpty:true,tag:'div',containment:["coluna_dir","coluna_esq"], handle:'topobloco', overlap:'vertical',constraint: false, ghosting: true, 
			onUpdate:function(){
				iniciarPrefs("./temas/katatudo/imagens/", "", document.getElementById('form_host').value);
				tiraEspaco();
			}, 
			onChange:function(){
				criaEspaco('coluna_esq');
			}
			});
			// ]]>
			ifila++;
			if(ifila<fila.length){
				setTimeout("ajaxRun()",30);
			}	
		}
	}
	http_request.send(null)
};
