var popup=0;
var popup2=0;
var DOC_ROOT = "/"; /*sempre deve ter / no final /*/

function AbrirJanela(szURL, intWidth, intHeight, szWinName) {
   window.open(szURL, szWinName, "position=center, toolbar=no,location=no,directories=no,status=no,width=" + intWidth + ",height=" + intHeight + "menubar=no,scrollbars=no,resizable=no");
}


function newWindow(newURL,left,top,width,height) {
	popup = window.open(newURL,'popup','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbar=1,resizable=0,copyhistory=0,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

function newWindow2(newURL,left,top,width,height)
{
	popup = window.open(newURL,'popup2','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=no,copyhistory=no,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}


// file: pagequery_api.js
// javascript query string parsing utils
// pass location.search to the constructor: var page = new PageQuery(location.search)
// get values like: var myValue = page.getValue("param1") etc.
// djohnson@ibsys.com {{djohnson}}
// you may use this file as you wish but please keep this header with it thanks
 function PageQuery(q) {
	if(q.length > 1) this.q = q.substring(1, q.length);
	else this.q = null;
	this.keyValuePairs = new Array();
	if(q) {
		// Turn <plus> back to <space>
		// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
		this.q = this.q.replace(/\+/g, ' ')
		this.q = unescape(this.q);

		for(var i=0; i < this.q.split("&").length; i++) {
			this.keyValuePairs[i] = this.q.split("&")[i];
		}
	}
	this.getKeyValuePairs = function() { return this.keyValuePairs; }
	this.getValue = function(s) {
		for(var j=0; j < this.keyValuePairs.length; j++) {
			if(this.keyValuePairs[j].split("=")[0] == s)
				return this.keyValuePairs[j].split("=")[1];
		}
		return "";
	}
	this.getParameters = function() {
		var a = new Array(this.getLength());
		for(var j=0; j < this.keyValuePairs.length; j++) {
			a[j] = this.keyValuePairs[j].split("=")[0];
		}
		return a;
	}
	this.getLength = function() { return this.keyValuePairs.length; }	
}

// adicionar ao bookmark
function addBookmark( url, title ) {
	if (window.external)
		external.AddFavorite( url, title )
	else
		alert("O seu browser não suporta esta função!");
}

function valida_procura(sForm) {
	var box = document.getElementById('fp');
	//alert(box);
	var bcpbox = document.getElementById('bcp');
	if (box.value.length == 0) {
		alert("O Campo Procura nao pode ser vazio!");
		boxsForm.c.focus();
		return false;
	}
	if (box.value.length < 2) {
		alert("O Campo procura deve ter pelo menos 2 caracteres !");
		box.focus();
		return false;
	}
	bcpbox.value = box.value;
	return true;
}

// setupDefaults();
function textCounter(field, maxlimit) {
	if (field.value.length > maxlimit) { /* if too long...trim it! */ 
		field.value = field.value.substring(0, maxlimit); 
		/* otherwise, update 'characters left' counter */ 
	}
	else {
		obj_spn1 = document.getElementById('spn1');
		html_output = " " + (maxlimit - field.value.length) + " ";
		obj_spn1.innerHTML = html_output;
	}
}

function verificaSite(url)
{
//	alert(url.value);
	enviaPage('includes/verifica_site.asp', 'GET', 'true', 'verificasite','url='+url.value)
}

function gerawidgets(id_categoria, formato)
{
	var formatovalue = "";
	
	for(var i=0; i<formato.length; i++)
	{
		if (formato[i].checked) formatovalue = formato[i].value;
	}

	enviaPage('includes/gera_widgets_inc.asp', 'GET', 'true', 'codigowidgets','id_categoria='+id_categoria.value+'&formato='+formatovalue)
}

function enviaPage(url, metodo, modo, tagId, parametros)
{
    goAjax( url+"?"+parametros , metodo, modo , tagId); 
}


function goAjax(url, metodo, modo, tagRetorno, parametros) 
{
    document.getElementById(tagRetorno).innerHTML='<div align="center" class="carregando"><img src="../imagens/carregando.gif"><br /><br />carregando...</div>'
	if (document.getElementById) 
	{ //Verifica se o Browser suporta DHTML.	
		try {             
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");         
		} 
		catch (e) 
		{              
			try {                 
					xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (E) {
				xmlhttp = false;
			}
		}
		
		if  (!xmlhttp && typeof  XMLHttpRequest != 'undefined' ) 
		{ 
			try  {
				xmlhttp = new  XMLHttpRequest();
			} 
			catch  (e) {
				xmlhttp = false ;
			}         
		}	
		if (xmlhttp) 
		{
            if(metodo == "GET") {
                xmlhttp.open("GET", url, modo);
            } else {        
                xmlhttp.open("POST", url, modo);
                xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1");
                xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
                xmlhttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
                xmlhttp.setRequestHeader("Pragma", "no-cache");
            }    
            
            xmlhttp.onreadystatechange = function() {
                if(xmlhttp.readyState == 4) {
                    retorno=xmlhttp.responseText
                    document.getElementById(tagRetorno).innerHTML=retorno
                }
            }
            if(metodo == "GET") {
                xmlhttp.send(null);
            } else {        
                xmlhttp.send(parametros);
            }
		}
	}
}

function Trim(str){
	return str.replace(/^\s+|\s+$/g,"");
}


// se outro site quer usar a busca, não conseguirá
if (top.location != location) window.open(location.href);
