function get(id) {
	return document.getElementById(id);	
}

function changeContent(id,text) {
	get(id).innerHTML=text;
}

function validateSignUp(){
	d=document.cadastro;
	
	if (d.nome.value=="" || d.password.value=="" || d.tmsg.value=="") {
		alert("Por favor, preencha todos os campos!");
		return false;
	} else {
		m1 = d.tmail.value.indexOf("@");
        m2 = d.tmail.value.indexOf(".");
        m3 = d.tmail.value.length;
        if (!(m1 >= 3 && m2 >= 6 && m3 >= 9)) {
        	alert ("Email inválido!");
            d.tmail.focus();
            return false;
        }
	}
	
return true;
}

var newwindow = '';

function popitup(url,h,w) {
	if (!newwindow.closed && newwindow.location) {
		newwindow.location.href = url;
	}
	else {

		d = Math.round(Math.random()*500);

		newwindow=window.open(url,d,'height='+h+',width='+w);

		x = Math.round(screen.width/2) - (w/2);
		y = Math.round(screen.height/2) - (h/2);

		newwindow.moveTo(x,y);

		if (!newwindow.opener) newwindow.opener = self;
	}
	if (window.focus) {newwindow.focus()}
}

function classificados(query) {
	if (!newwindow.closed && newwindow.location) {
		newwindow.location.href = url;
	}
	else {

		d = Math.round(Math.random()*500);

		newwindow=window.open('classificados.php'+query,d,'height=500,width=620,scrollbars=yes');

		x = Math.round(screen.width/2) - (620/2);
		y = Math.round(screen.height/2) - (500/2);

		newwindow.moveTo(x,y);

		if (!newwindow.opener) newwindow.opener = self;
	}
	if (window.focus) {newwindow.focus()}
}

/* chamadas */

var ll = 1;
var x = -1;
var active = false;
var interval = 0;
var cInterval = 0;
var last = '?';


function spell(n) {

	s = chamadas[n];

	if (s && (ll <= s.length)) {

		active = true;

		k = s.substring(0,ll);
		k += (ll < s.length) ? "_" : "";
		ll++;

		lnk = '<a href="'+links[n]+'">'+k+'</a>'

		changeContent('chamada',lnk);

	}

	if (s!=null && ll > s.length) {
		active = false;
		cInterval = setInterval('chamadasTimer()',4500);
		clearInterval(interval);
	}

}

function chamadasTimer() {

	al = chamadas.length-1;

	if (!active) {

		x = randomize(al);

		last += "%"+x+"?";

		ll=0;

	}

	interval = setInterval('spell(x)',50);
	clearInterval(cInterval);

}

function randomize(num) {

	r = Math.floor(Math.random()*num);
	full = true;
	c = 0;

	while (c <= num) {

		if (last.indexOf("%"+c+"?") == -1) {
			full = false;
			c++;
		}

		if (last.indexOf('%'+c+'?') >= 0) {
			break;
		}

	}

	last = full ? '?' : last;

	while (last.indexOf('%'+r+'?') >= 0) {
		r = Math.floor(Math.random()*num);
	}

	return r;

}

function getChamadas() {

	chamadasTimer();

}

function changeAlbumContent(oi) {

	get('id-imagem').src = album[oi][imagem];
	get('id-imagem').alt = album[oi][titulo];


	get('id-resumo').innerHTML = album[oi][resumo];
	get('id-url').href = "javascript:opener.location='"+album[oi][url]+"'; window.close();";

	if (album[oi][url]=='empty') get('id-url').style.visibility = 'hidden'; else get('id-url').style.visibility = 'visible';

	get('credito').innerHTML = album[oi][credito];

}

function addfav() {

	var title=document.title;
	var url=this.location.href;

	if ( document.all && window.external ) window.external.AddFavorite( url, title);

	else if(window.sidebar) window.sidebar.addPanel(title, url,"");

	else if( window.opera && window.print ) {
		var mbm = document.createElement('a');
		mbm.setAttribute('rel','sidebar');
		mbm.setAttribute('href',url);
		mbm.setAttribute('title',title);
		mbm.click();
	}

}
