// Email address must be of form a@b.c
function isEmail (s){
	if (isEmpty(s)){return true;}
    	// is s whitespace?
    	if (isWhitespace(s)){return true;}

    	// there must be >= 1 character before @, so we
    	// start looking at character position 1
    	// (i.e. second character)
    	var i = 1;
    	var sLength = s.length;

    	// look for @
    	while ((i < sLength) && (s.charAt(i) != "@"))
    	{ i++
    	}

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}
// fim da funcao isEmail

function isWhitespace (s)
{
    var whitespace = " \t\n\r";
    var i;

    // Is s empty?
    if (isEmpty(s)){return true;}

    // Search through characters one by one
    for (i = 0; i < s.length; i++)
    {
        // Check that current character isn't whitespace.
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
} // fim da funcao Whitespace

// Check whether string s is empty.
function isEmpty(s){
	return ((s == null) || (s.length == 0))
}





// adicionar aos favoritos

function addFav(){
    var url      = "http://www.papelar.pt/";
    var title    = "Papelar";
    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);}
}
function bookmark(url, sitename)
{
  ns="Utilizadores Netscape e FireFox, devem clicar CTRL+D para adicionar este site aos favoritos."
  if ((navigator.appName=='Microsoft Internet Explorer') &&
    (parseInt(navigator.appVersion)>=4))
  {
    window.external.AddFavorite(url, sitename);
  }
  else if (navigator.appName=='Netscape')
  {
    alert(ns);
  }
}


// mostra esconde div
function controldiv(id) {
    var aElm=document.getElementsByTagName('div');
    for(var i=0; i<aElm.length; i++) {
        if(aElm[i].className=='show') {
    	    aElm[i].className='hide';
        }
    }
    document.getElementById(id).className='show';
}


function closedialogerror(){
    document.getElementById('erro').style.display='none';

}
function trocaimg(img){
    document.getElementById('imagem_destaque').src=img;
}

function check_pesquisa(){
    var text = document.forms["pesquisa"];
    if(text.texto.value=="" || text.texto.value=="texto a pesquisar"){
        document.getElementById('pagina')="pagina_transparente";
        document.getElementById('msg').value="Deve inserir o texto a pesquisar";
        document.getElementById('erro').style.display='block';
		return false;
    }
}
function check_contacto(){
    var text = document.forms["contacto"];
    if(text.nome.value==""){
        alert("Nome é um campo obrigatório");
        text.nome.focus();
        return;
    }
    if(text.email.value==""){
        alert("Email é um campo obrigatório");
        text.email.focus();
        return;
    }
    if(text.assunto.value==""){
        alert("Assunto é um campo obrigatório");
        text.assunto.focus();
        return;
    }
    if(text.mensagem.value==""){
        alert("Mensagem é um campo obrigatório");
        text.mensagem.focus();
        return;
    }
    text.submit();
}
function change_foto(id1,src1,img1){
    document.getElementById(id1).src=src1+img1;


 }

function change_foto2(id1,src1,img1,id2,src2){
    document.getElementById(id2).src=src2+getName(document.getElementById(id1).src);
    document.getElementById(id1).src=src1+img1;


 }
 function getName(s) {
//var d = s.lastIndexOf('.');
var d = s.length;
return s.substring(s.lastIndexOf('/') + 1, d < 0 ? s.length : d);
}
function addbookmark()
{
bookmarkurl="http://www.papelar.pt/"
bookmarktitle="Papelar"
if (document.all)
window.external.AddFavorite(bookmarkurl,bookmarktitle)
}

// altera o type de um input
function changeInputType(oldObject, oType) {
  var newObject = document.createElement('input');
  newObject.type = oType;
  if(oldObject.size) newObject.size = oldObject.size;
  //if(oldObject.value) newObject.value = oldObject.value;
  if(oldObject.name) newObject.name = oldObject.name;
  if(oldObject.id) newObject.id = oldObject.id;
  if(oldObject.className) newObject.className = oldObject.className;
  if(oldObject.style.width) newObject.style.width = oldObject.style.width;
  oldObject.parentNode.replaceChild(newObject,oldObject);
  newObject.focus();
  return newObject;
}
function opendiv(id1,id2,file, width, height){
    document.getElementById(id2).src="../../galeria/newsletter/img/"+file;
    document.getElementById(id1).style.width=width;
    document.getElementById(id1).style.height=height;
    document.getElementById(id1).style.display='block';


}
function closediv(id){
    document.getElementById(id).style.display='none';

}


function popup(url)
{
 params  = 'width='+screen.width;
 params += ', height='+screen.height;
 params += ', top=0, left=0'
 params += ', fullscreen=no';
 params += ', menubar=yes';
 params += ', scrollbars=auto';

 newwin=window.open(url,'Vinografia', params);
 if (window.focus) {newwin.focus()}
 return false;
}



