function favoritos (descricao){
  if (document.all) {
    window.external.AddFavorite('http://' +document.domain, descricao);
  }
}

function homepage (site){
        document.body.style.behavior='url(#default#homepage)';
        document.body.setHomePage('http://'+document.domain);
}

// alteracao combos
function CarregaCombo(nomeform,campo,subcampo) {
	remove_tudo(nomeform,subcampo);
	document.all.sframe.src="pesquisa_auto_carrega_modelo.php?nomeform="+nomeform+"&subcampo="+subcampo+"&dropdown_sub1="+campo.value;
}
function adiciona(valor,texto,nomeform,subcampo) {
	linha = document.createElement("OPTION");
	linha.text=texto;
	linha.value=valor;
	document.forms[nomeform].elements[subcampo].add(linha);
}
function remove_tudo(nomeform,subcampo) {
	//Apagando o subc
	var tam = document.forms[nomeform].elements[subcampo].length;
	while( tam > 0 ) { 
		document.forms[nomeform].elements[subcampo].remove(tam-1); 
		tam--;
	}
}

//preload image
function preloadImage(imgUrl) {
	preload = new Image();
    preload.src = imgUrl;
}
//swap image
function swap(target, imgUrl) {
    document[target].src = imgUrl;
}


// TEXTAREA COUNTER //

function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else 
countfield.value = maxlimit - field.value.length;
}


//----------------------------------------------------------------------------------------------------------
//See http://www.blakems.com/archives/000087.html for more info.

//expandCollapse
function expandCollapse() {
	for (var i=0; i<expandCollapse.arguments.length; i++) {
		if (document.getElementById(expandCollapse.arguments[i])){
			var element = document.getElementById(expandCollapse.arguments[i]);
			element.style.display = (element.style.display == "none") ? "block" : "none";
		}
	}
}

function ShowLayer(id) {
	if (document.getElementById(id)){
  		document.getElementById(id).style.display = "block"; 
	}
}

function HideLayer(id) {
 	if (document.getElementById(id)){
  		document.getElementById(id).style.display = "none"; 
	}
}

//Hide Timer
var timerID;

function HideTimedLayer(id)
{  
    clearTimeout(timerID);
    document.getElementById(id).style.display = "none";
}

function timedLayer(id)
{
  setTimeout("HideTimedLayer(\"" + id + "\")", 5000); //5000= 5 seconds
}
//----------------------------------------------------------------------------------------------------------



// do_focus & do_blur
function do_focus(obj,str){
	if(obj.value == str)
		obj.value='';
}
function do_blur(obj,str){
	if(obj.value==''){
		obj.value = str;
	}
}
function do_focus_pass(obj){
        var field = do_focus_pass.arguments.length>1?do_focus_pass.arguments[1]:'pass';
	obj.style.display='none';
	obj.form.elements[field].style.display='';
	obj.form.elements[field].focus();
}
function do_blur_pass(obj,str){
	if(obj.value==''){
		obj.style.display='none';
		obj.form.mask.style.display='';
		obj.form.mask.value = str;
	}
}

