// Desenvolvido por Istrata Comunicação

gE = function(alvo) {
	var e;
	e = document.getElementById(alvo);
	return e;
}
gEs = function(alvo) {
	var e;
	e = document.getElementsByTagName(alvo);
	return e;
}

// Insere flash sem borda
function swf(url, w, h, bg, vars, id) {
	
	if(bg) {
		ie_bg = '<param name="bgcolor" value="'+ bg +'" />';
		ff_bg = 'bgcolor="'+ bg +'"';			
	}else {
		ie_bg = '<param name="wmode" value="transparent" />';
		ff_bg = 'wmode="transparent"';
	}
	
	if(vars) {
		ie_vars = '<param name="flashvars" value="'+ vars +'" />';
		ff_vars = 'flashvars="'+ vars +'"';			
	}else {
		ie_vars =
		ff_vars = '';
	}
	
	cd_flash  = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
	cd_flash += 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" ';
	cd_flash += 'width="' + w + '" ';
	cd_flash += 'height="'+ h + '" ';
	cd_flash += 'id="'+ id +'" ';
	cd_flash += 'name="'+ id +'">';
	cd_flash += '<param name="movie" value="' + url + '" />';
	cd_flash += '<param name="menu" value="false" />';
	cd_flash += '<param name="quality" value="high" />';
	cd_flash += '<param name="salign" value="tl" />';
	cd_flash += '<param name="scale" value="noscale" />';
	cd_flash += ie_bg;
	cd_flash += ie_vars;
	cd_flash += '<embed src="' + url + '" type="application/x-shockwave-flash" ';
	cd_flash += 'pluginspage="http://www.macromedia.com/go/getflashplayer" ';
	cd_flash += 'menu="false" quality="high" salign="tl" scale="noscale" ';
	cd_flash += 'width="' + w + '" ';
	cd_flash += 'height="'+ h + '" ';
	cd_flash += 'id="'+ id +'" ';
	cd_flash += ff_bg;
	cd_flash += ff_vars;
	cd_flash += '></embed>';
	cd_flash += '</object>';
	
	document.write(cd_flash);
	
}

// Chama func quando o HTML já foi todo carregado
function DOMReady(func){
	if(!(document.body==null)){
		func();
	}else{
		var func_rep = func;
		setTimeout(function(){ DOMReady(func_rep) }, 100);
	}
}

// Aplica eventos à objetos
addEvent = function(objs, evento, func, params) {
	for(i=0; i<objs.length; i++) {
		obj = objs[i];
		if(obj) {
			funcOld = obj[evento];
			obj[evento] = function() {
				if(funcOld) { funcOld(); }
				if(params) {
					return func(params);
				}else {
					return func();
				}
			}
		}
	}
}

limpaCampo = function(alvo) {
	if(alvo.value == alvo.defaultValue){
		alvo.value = "";
	}
}

// Aplica mascara aos campos e seta o maxlength
aplMask = function(args) {
	cp = args[0];
	mask = args[1];
	
	txt = cp.value;
	ids  = [];
	chrs = [];
	
	cp.maxLength = mask.length;
	
	// coloca # no texto do campo para deixar as duas Strings com o msm tamanho
	while(txt.length < mask.length) {
		txt = '#'+ txt;
	}
	
	// verifica os caracteres da mascara
	for(i=0; i<mask.length; i++) {
		lt = mask.charAt(i);

		if(lt != '#') {
			ids.push(i);
			chrs.push(lt);
		}
	}	
	
	// limpa caracteres exclusivos da mascara
	for(i=0; i<chrs.length; i++) {
		while(txt.indexOf(chrs[i]) != -1) {
			txt = txt.replace(chrs[i], '');
		}
	}
	
	// aplica a máscara
	for(i=0; i<ids.length; i++) {
		txt_a = txt.slice(0, ids[i]);
		txt_b = txt.slice(ids[i], txt.length);
		txt = txt_a + chrs[i] +txt_b;
	}
	
	// limpa os # postos para igualar os tamanhos
	while(txt.indexOf('#') != -1) {
		txt = txt.replace('#', '');
	}
	
	(txt.length > chrs.length) ? cp.value = txt : cp.value = '';
	
}


// fecha pop-up
fechaPopFlash = function() {
    document.getElementById('pop-up').style.display = 'none';
    return false;
}
