/* Functions ==================================================================================== */

/* copyHeight */
function copyHeight(objParam){
	var mHeight = $(objParam).eq(0).height();
	for(i=0; i<$(objParam).length; i++){
		if(mHeight < $(objParam).eq(i).height()){
			mHeight = $(objParam).eq(i).height();
		}
	}
	$(objParam).height(mHeight+'px');
}

/* carregaOn */
function carregaOn(obj,retorno){
	if(window.location.href.indexOf(obj) != -1){
		$(retorno).addClass('on');
	}
}

/* mudaImagem */
function mudaImagem(objPai,obj,txt){
	$('#box_img h5').text(txt);
	$(objPai).attr('src','/club/img/img_cartao'+ obj +'.png');	
}

/* reloadComment */
function reloadComment(obj, retorno, label){
	$('#' + retorno + ' .span_destaque').hide();
	
	if(label != undefined){
		$('#' + retorno).append('<span class="span_destaque"><h5>' + label + '</h5></span>');
	}

	changeSelect(obj, retorno);
}

/* changeSelect */
function changeSelect(obj,retorno){
	if(obj == 0){
		$('#' + retorno + ' .sel').removeClass('txt_aux_on');
		$('#' + retorno + ' .sel').addClass('txt_aux_off');
		$('#' + retorno + ' .txt_aux').addClass('txt_aux_on');
		$('#' + retorno + ' .sel option').attr('selected','selected');
		$('#' + retorno + ' .txt_aux').focus();
	}else{
		$('#' + retorno + ' .txt_aux').removeClass('txt_aux_on');
		$('#' + retorno + ' .txt_aux').addClass('txt_aux_off');
		$('#' + retorno + ' .sel').removeClass('txt_aux_off');
		$('#' + retorno + ' .sel').addClass('txt_aux_on');
	}
}


/* pop up */
function openPop(url,name, string){
	window.open(url, name, string);
}

function validateOutros(){
	for(var i = 1; i <= $('.sel').length; i++){
		if($('#linha0' + i + ' select').val() == 0 && $('#linha0' + i + ' select').val() != '' && $('input[@name=txt0' + i + 'aux]').val() == ''){
			alert('Você deve preencher o campo ' + $('#linha0' + i + ' select option:selected').text().substr(0, $('#linha0' + i + ' select option:selected').text().length - 2));
			$('input[@name=txt0' + i + 'aux]').focus();
			return false;
		}
	}
}

function visualizar(f, w, h){
	DFsbm = false;

	validateOutros();

	if (!DFckForm(f, true)) return false;
	
	f.preview.value = 'true';

	$('#frmStep02Natal').attr("target","popView");
	$('#frmStep02Natal').attr("action","/club/convite");
	popView = window.open('','popView','scrollbars=auto,resize=no,status=yes,width='+ w +',height='+ h +',top=150,left=150');
	$('#frmStep02Natal').submit();
}

function validateForm(f, t){
	f.action = 'criar_convite_step03.jsp';
	f.target = '';
	DFsbm = false;

	validateOutros();
	
	if (!DFckForm(f, t)) return false;
	
	f.preview.value = 'false';
}

$(function(){
	$('#txt_horas').keyup(function(){
		if($('#txt_horas').val() > 12){
			$(this).val(12);
		}
	})
	
	$('#txt_minutos').keyup(function(){
		if($('#txt_horas').val() == 12 && $(this).val() > 59){
			$(this).val(59);
		}
	})

	//$('#txt_minutos').val()
})



/* mudarProduto */
function mudaProduto(objId){
	$('.bullets_produtos li a').removeClass();
	$('.bullets_produtos li #' + objId).addClass('on');

	$('.box_produtos h3').removeClass();
	$('.box_produtos h3').addClass('tit_' + objId);

	$('.box_produtos .bt_ver_novamente').attr('id', objId);

	var so = new SWFObject("/club/swf/" + objId + ".swf", "obj_flash", "118", "118", "8");
	so.useExpressInstall("/club/swf/expressinstall.swf");
	so.addParam("wmode", "transparent");
	so.addParam("scale", "noscale");
	so.write("box_flash");	

	if(objId == 'tacas'){
		$('.box_produtos .txt').html('O Freezer tem um suporte para colocar suas taças. Perfeito para acompanhar suas bebidas geladas.');
	}else if(objId == 'bar'){
		$('.box_produtos .txt').html('Você programa o painel digital e ele avisa quando suas bebidas estão no ponto para beber.');
	}else if(objId == 'dispenser'){
		$('.box_produtos .txt').html('É só apertar o botão e pegar na porta da geladeira mesmo.<br /> A única coisa que você vai ter que abrir é a sua latinha.');
	}
}
