// JavaScript Document

function $(objID){
	return document.getElementById(objID);
}

function $$(objID){
	return document.getElementById(objID).style;
}

function posX(val){
	return (screen.width-val)/2;
}

function posY(val){
	return ((screen.height-val)/2)-20;
}

function getQueryString(val) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == val) {
      return pair[1];
    }
  } 
  //alert('Query ' + val + ' not found');
}

function exFlash(swf, width, height, wmode){
	((wmode==undefined||wmode=='')?wmode='opaque':wmode='transparent');
	swfBox= '';
	swfBox+='<object type=\"application/x-shockwave-flash\" data=\"'+swf+'.swf\" width=\"'+width+'\" height=\"'+height+'\">';
	swfBox+='<param name=\"movie\" value=\"'+swf+'.swf\" />';
	swfBox+='<param name=\"quality\" value=\"high\" />';
	swfBox+='<param name=\"wmode\" value=\"'+wmode+'\" />';
	swfBox+='</object>';
	document.write(swfBox);
}

var waitMessage = '';
waitMessage += '<div align=\"center\"><img src=\"/imagens/loading.gif\"></div>';

function fcCarregaCidade(strUrl, objEstado) {
	var url = strUrl;
	var str = 'id_tb_estado=' + objEstado.value;
	var trgt = 'lyLoadCidade';

	document.getElementById(trgt).innerHTML='aguarde...';
	xmlHttp=GetXmlHttpObject(trgt)
	xmlHttp.open('post',url, true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.setRequestHeader('Content-length', str.length);
	xmlHttp.send(urlEncode(str));
}

function ajaxPost(url,str,trgt){	
	document.getElementById(trgt).innerHTML=waitMessage;
	xmlHttp=GetXmlHttpObject(trgt)
	xmlHttp.open('post',url, true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.setRequestHeader('Content-length', str.length);
	xmlHttp.send(urlEncode(str));
} 

function ajaxGet(url,trgt){
	document.getElementById(trgt).innerHTML=waitMessage;
	xmlHttp=GetXmlHttpObject(trgt)		
	xmlHttp.open('get',url, true);
	xmlHttp.send(null);
}

function GetXmlHttpObject(trgt){
	var objXmlHttp=null;
	if (navigator.userAgent.indexOf("MSIE")>=0){ 
		var strName="Msxml2.XMLHTTP";
		if (navigator.appVersion.indexOf("MSIE 5.5")>=0){
			strName="Microsoft.XMLHTTP";
		}
		try{ 
			objXmlHttp=new ActiveXObject(strName);
			objXmlHttp.onReadyStateChange=function(){
				if (xmlHttp.readyState==4||xmlHttp.readyState=="complete"){ 
					document.getElementById(trgt).innerHTML=xmlHttp.responseText;
				}
			}
			return objXmlHttp;
		}catch(e){ 
			alert("Error. Scripting for ActiveX might be disabled");
			return;
		} 
	}
	else{
		objXmlHttp=new XMLHttpRequest();
		objXmlHttp.onload=function(){
			if (xmlHttp.readyState==4||xmlHttp.readyState=="complete"){ 
				document.getElementById(trgt).innerHTML=xmlHttp.responseText;
			}
		}
		objXmlHttp.onerror=function(){
			if (xmlHttp.readyState==4||xmlHttp.readyState=="complete"){ 
				document.getElementById(trgt).innerHTML=xmlHttp.responseText;
			}
		}
		return objXmlHttp;
	}
}

function urlEncode(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;
}

function tmp(){
	alert('Desculpe\nainda não implementado');
}
