function addFav(){
    var url = document.URL;  
    var title = "Seguros LOGO";
	
	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();
    }
    else if(document.all){
		window.external.AddFavorite(url, title);
	} else
		alert('Carregue em Ctrl e D ao mesmo tempo para adicionar aos favoritos');
}

function isSkypeInstalled() {
    try {
        /*@cc_on
        //The Microsoft way, thanks to the conditional comments only run in IE
        if (new ActiveXObject("Skype.Detection")) return true;
        @*/

        //Tested for firefox on win
        if (navigator.mimeTypes["application/x-skype"]) return true;
    }
    catch(e){}
    return false;
}


function callSkype(){
	var res = isSkypeInstalled();
	if (res==true);
		window.location ='skype:+351218546210';
}

function verifyEmail(str) {
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if (str.indexOf(at)==-1)
	   return false;
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
	   return false;
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
		return false;
	 if (str.indexOf(at,(lat+1))!=-1)
		return false;
	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
		return false;
	 if (str.indexOf(dot,(lat+2))==-1)
		return false;
	 if (str.indexOf(" ")!=-1)
		return false;
	 return true;				
}

function validateLogin() {
var isValid = true;

var obj = document.getElementById('email');
if (isValid && !verifyEmail(obj.value)) {
	isValid = false;
	alert(unescape('Introduza o email válido'));
}
obj = document.getElementById('pass');
if (isValid && obj.value=='') {
	isValid = false;
	alert('Introduza a password');
}
return isValid;
}

function validateForgot() {
var isValid = true;

var obj = document.getElementById('email');
if (isValid && !verifyEmail(obj.value)) {
	isValid = false;
	alert(unescape('Introduza o email válido'));
}
if (isValid)
	Solicitar();

return isValid;
}
	
function validateNews() {
var isValid = true;

var obj = document.getElementById('txtEmail');
if (isValid && !verifyEmail(obj.value)) {
	isValid = false;
	alert(unescape('Introduza o email válido'));
}
if (isValid)
	addNews();

return isValid;
}

function afterNews() {
var obj = document.getElementById('txtEmail');
obj.value='';
alert('Obrigado por se registar');
}

function pesquisa() {
document.location = 'CMS_Pesquisa?filtroPesquisa='+document.getElementById('filtroPesquisa').value;
}

function popitup(url) {
	var newwindow;
	newwindow=window.open(url,'Contacte_nos','toolbar=no,menubar=no,directories=no,location=no,status=no,width=500,height=450');
	if (window.focus) {newwindow.focus()}
	return false;
}

// coloca a scrollbar nas tabelas, usado para o remoting
function setScrollBar() {
	var MAXNROWS = 6;
	$('.tableScroll .table')
		.filter(function(){return ($("tbody tr",this).length > MAXNROWS);})
        .children("table")
		.fixedHeaderTable({ footer: false, cloneHeadToFoot: false, fixedColumn: false, themeClass:'generictable' });
}

// cria cells numa table de html 	
		        
function createTableData(myRow, text) {
	createTableData(myRow, text, false);
}

function createTableData(myRow, text, doNotDisplay) {
	var myCell = document.createElement("td");	
	myCell.className  = "dataCell";	
	myCell.colspan = "1";				
	myCell.innerHTML = text==null?'':text;
	if (doNotDisplay) myCell.style.display = 'none';
	myRow.appendChild(myCell);		
}

function createTableDataLink(myRow, text, link) {
	myRow.className = "dataRow even first last";	
	myRow.onmouseover = "if (window.hiOn){hiOn(this);}";
	myRow.onmouseout = "if (window.hiOff){hiOff(this);}";
	myRow.onblur = "if (window.hiOff){hiOff(this);}";	
	myRow.onfocus = "if (window.hiOn){hiOn(this);}";
		
	var myCell = document.createElement("td");	
	myCell.className  = "dataCell";	
	myCell.colspan = "1";
	myCell.innerHTML = '<a href="#" onclick="' + link + '" >' + text + '</a>';
	
	/*var myLink = document.createElement("a");	
	myLink.href = "#";	
	myLink.setAttribute("onclick", link);	
	myLink.innerHTML = text;	
	myCell.appendChild(myLink);
	*/
	myRow.appendChild(myCell);
}

function removeAllRows(id) {
	var i;
	var obj = document.getElementById(id);
	
	for(var i=obj.rows.length;i>0;i--) {
		obj.deleteRow(i-1);
	}
}
