// JavaScript Document




function janela_frame(titulo, url) 
{
	document.getElementById('janela_frame_texto').innerHTML = titulo;
	document.getElementById('janela_iframe').src = url;
	$('#janela_frame').jqmShow();
}



function janela_frame_x() 
{
	document.getElementById('janela_iframe').src = '/design/pixel.gif';
	$('#janela_frame').jqmHide();
}




$(document).ready(function(){ 
						   







// Post comentario
$("#frm_helpdesk_chat_post").submit(function () 
{ 
	var comentario = $.trim($("#helpdesk_nova_msg").val().replace(/<\/?[^>]+>/gi, ''));
	
	if (comentario != '')
	{
		var htmlStr = $('#frm_comentario').html(); //bckup
		
		$('#frm_comentario').html('<img src="/loading.gif"  style="margin-top:8px;" />'); //loading
		
		
		$.get("/helpdesk/api/index.php", { conteudo: $("#idconteudo").val(), comentario: comentario },  function(data)
			{
				if (data != '') 
				{ 
					alert(data);
					$('#frm_comentario').html(htmlStr);
				} else 
				{
					$.get("/helpdesk/api/index.php", { conteudo: $("#idconteudo").val(), devolve_comentarios: 1 },  function(data)
						{
							document.getElementById('com_existentes').innerHTML = data;
							$('#frm_comentario').html(htmlStr);
							$('#comentario').val('');
						});
				}
			});
	} else 	alert('pff escreva a sua mensagem');
	return false;
});	












//$('#dialog').jqm();				   
$('#janela_frame').jqm();							   
						   
$("ul.sf-menu").supersubs({ 
	minWidth:    22,   // minimum width of sub-menus in em units 
	maxWidth:    37,   // maximum width of sub-menus in em units 
	extraWidth:  1     // extra width can ensure lines don't sometimes turn over 
					   // due to slight rounding differences and font-family 
}).superfish({ 
	a_nimation: {height:'show'},   // slide-down effect without fade-in 
	delay:     1110               // 1.2 second delay on mouseout 
}); 


		
$('#marcas-vertical').cycle({ 
    //fx:     'scrollVert', 
    prev:   '#prev2', 
    next:   '#next2', 
	speed:  'fast', 
    timeout: 2000
	
});		
		
		
$('#marcas-hor').cycle({ 
    //fx:     'scrollVert', 
    prev:   '#prev2', 
    next:   '#next2', 
	speed:  'fast', 
    timeout: 2000
	
});				

$('#banners_esq_cima').cycle({ 
	fx:     'growX',
	speed:  'slow', 
    timeout: 3500
});	








$('#home_banners') 
.before('<div id="nav">') 
.cycle({ 
    fx:     'fade', 
    speed:  'fast', 
    timeout: 2000,
	pause:1,
    pager:  '#home_banners_nav' 
});










		
		
    }); 
	
	
	
	
	
	

function foca(id)
{
	document.getElementById(id).focus();
	document.getElementById(id).select();	
}

function saka_valor(id)
{
	return document.getElementById(id).value;
}

function numerico_entre_len(id, minimo, maximo)
{
	valor = document.getElementById(id).value;
	if (valor.length > maximo) return false;
	else if (valor.length < minimo) return false;
	else return true;
}

function valida_mail(id)
{
	if (document.getElementById(id).value.search(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/) == -1) return false; else return true;
}

function trim(str)
{
	s = str.replace(/^(\s)*/, '');
	s = s.replace(/(\s)*$/, '');
	return s;
}

function ifchecked(id)
{
	if (document.getElementById(id).checked == true ) return true; else return false;
}

function valida_null(id)
{
	if (document.getElementById(id).value != '' && document.getElementById(id).value != 'HR-NULL' && document.getElementById(id).value != 'HR-NULL-CHAR' && document.getElementById(id).value != null) return true; else return false;
}

function mostrar_obj(id) 
{
	var objecto;		
	objecto = document.getElementById(id);
	if (objecto) 
	{
		objecto.style.position     = "relative";
		objecto.style.overflow     = "visible";
		objecto.style.visibility   = "visible";
		objecto.style.display      = "";		
	}
}   
	
function esconder_obj(id) 
{
	var objecto;		
				
	objecto = document.getElementById(id);	
	if (objecto) 
	{
		objecto.style.position     = "absolute";
		objecto.style.overflow     = "hidden";
		objecto.style.visibility   = "hidden";
		objecto.style.display      = "none";
	}
}   		
	
	

function valida_frm_mini()
{
if (valida_mail('utilizador_mini') == false) { foca('utilizador_mini'); alert('Introduza um e-mail válido.');  return false; }
else if (numerico_entre_len('password_mini',5,100) == false)  { foca('password_mini'); alert('A password está errada.'); return false; }
}



function valida_frm_registo()
{
if (valida_mail('email') == false) { foca('email'); alert('Introduza um e-mail válido.');  return false; }
if (numerico_entre_len('password1',5,100) == false) { foca('password1'); alert('Introduza uma password. Deverá ter no mínimo 5 caracteres.');  return false; }
if (numerico_entre_len('password2',5,100) == false) { foca('password2'); alert('Para confirmaçao, repita a password que introduziu anteriormente.');  return false; }
if (saka_valor('password1') !=  saka_valor('password2'))  { foca('password2'); alert('As passwords nao correspondem.');  return false; }

if (numerico_entre_len('nome',5,100) == false) { foca('nome'); alert('Introduza o nome da empresa.');  return false; }
if (numerico_entre_len('morada',7,200) == false) { foca('morada'); alert('Introduza uma morada correcta.');  return false; }
if (numerico_entre_len('localidade',2,30) == false) { foca('localidade'); alert('Introduza uma localidade.');  return false; }
if (numerico_entre_len('cp',4,10) == false) { foca('cp'); alert('Introduza um código postal válido.');  return false; }

if (numerico_entre_len('nc',9,11) == false) { foca('nc'); alert('Introduza um NIF válido.');  return false; }
if (numerico_entre_len('telefone',9,30) == false) { foca('telefone'); alert('Introduza um contacto telefónico válido.');  return false; }



}	