/**
	BALLROOM - SITE (BALLROOM) v: 0.1
	Developer(s):
		+ Fernando Basilio (fernando.basilio@rede106.com)
*/


// validação
function checkEmail(obj) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test($(obj).val())) return true;
}

function checkBlank(obj){
	if ($(obj).val() != '') return true;
}

function checkNaN(obj){
	if (isNaN($(obj).val()) == true) return true;
}

// VALIDAR FORMULARIO DE CONTATO
function validaContato(){
	var vNome		= $(".txt_nome");
	var vEmail		= $(".txt_email");
	var vMotivo		= $(".txt_assunto");
	var vMensagem	= $(".txt_mensagem");
	if(!checkBlank($(vNome)) == true){
		alert('Insira um Nome.');
		return false;
	}else if(!checkBlank($(vEmail)) == true){
		alert('Insira um E-mail.');
		return false;
	}else if(!checkEmail($(vEmail)) == true){
		alert("Insira um E-mail valido.")
		return false;
	}else if(!checkBlank($(vMotivo)) == true){
		alert('Insira um Assunto.');
		return false;
	}else if(!checkBlank($(vMensagem)) == true){
		alert('Insira uma Mensagem.');
		return false;
	}else{
		return true;
	}
}


// copyHeight
function copyHeight(obj){
	hMax = $(obj).eq(0).height();
	for (i=0; i<$(obj).length; i++){
		if(hMax < $(obj).eq(i).height()){
			hMax = $(obj).eq(i).height();
		}
	}
	$(obj).height(hMax);
}


// centralizeElement
function centralizeElement(obj){
	var obj = obj;
	if ($("body").height() > $(obj).height()) {
		$(obj).css({top: '50%', marginTop: -($(obj).height()/2) + 'px'});
	}else {
		$(obj).css({marginTop: '0px', top: '0px'});
	}
	if ($("body").width() > $(obj).width()) {
		$(obj).css({left: '50%', marginLeft: -($(obj).width()/2) + 'px'});
	}else {
		$(obj).css({marginLeft: '0px', left: '0px'});
	}
}


// Return GET params
function returnParam(url,paramName){
	for(var qs = url.split("&"), i=0; i < qs.length; i++)
		if(qs[i].indexOf(paramName)>=0)
			return qs[i].split("=")[1];
	return false;
}


// Flash Calls
function openLink(url) {
	if(!url.match('http')) {
		switch(url) {
			case "example": window.location = 'http://www.example.com.br/'; break;
			case "exampl2": doSomething(); return true; break;
			default: return false;
		}
	}else
		window.location = url;
	return true;
}



// Popup handler
function openPopup(u,n,w,h,o,c) {
	var l = t = 18;
	if (c) {
		l = (screen.availWidth-w) / 2;
		t = (screen.availHeight-h) / 2;
	}
	p=window.open(u,'pop_'+n,'left='+l+',top='+t+',width='+w+',height='+h+''+((o)?','+o:''));
}

function comunicadoPop(url){
	openPopup(url,'Comunicado',415,350,'scrollbars=1',true);
}
