// JavaScript Document
//+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
function ajax(pagina, elem, valor, opcao, carregar, tempo, pagina2){
	if(carregar){
		$("#"+elem).html('<font class="ftcarregando">Carregando...</font><img src="imagem/ampulheta.gif" width="16" height="16" align="absmiddle"/>');	
	}
	switch(opcao){
		case(0):
			el = elem;
		break;
		case(1):
			organizarAlert(pagina2,true);
			ajax(pagina, 'msg', valor, 0, false, '', '');
			setTimeout("ocultarLayer('alert','"+pagina2+"')",tempo);
		break;
	}
	if(opcao == 0){
		$.ajax({
			type: "POST",
			url : pagina,
			data: valor,
			success: function(retorno){
				if(el != ''){
					$("#"+el).html(retorno);	
				}
			}
		});
	}
}
//+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
// url_encode version 1.0 
function url_encode(str) { 
	if(str == undefined){
		str = '';	
	}
	var hex_chars = "0123456789ABCDEF"; 
	var noEncode = /^([a-zA-Z0-9\_\-\.])$/; 
	var n, strCode, hex1, hex2, strEncode = ""; 
	
	for(n = 0; n < str.length; n++) { 
		if (noEncode.test(str.charAt(n))) { 
			strEncode += str.charAt(n); 
		} else { 
		strCode = str.charCodeAt(n); 
		hex1 = hex_chars.charAt(Math.floor(strCode / 16)); 
		hex2 = hex_chars.charAt(strCode % 16); 
		strEncode += "%" + (hex1 + hex2); 
		} 
	} 
	return strEncode; 
 } 
//=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
 // 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 { 
				 strDecode += str.charAt(n); 
			} 
	  } 

	  return strDecode; 
 } 
//=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=