var act = ''
var browser     = '';
if (navigator.appName.indexOf('Microsoft') != -1)
browser = 'IE'
else if (navigator.appName.indexOf('Netscape') != -1)
browser = 'Netscape'
else browser = 'IE';
var image=new Array()
var homeLink_1=new Array()
var homeLink_2=new Array()
var homeLink_3=new Array()
var num=0
var num1=0
var num2=0
var num3=0
var timeDelay
var timeDelay1
var timeDelay2
var timeDelay3
var imagePreload=new Array()
var imagePreload1=new Array()
var imagePreload2=new Array()
var imagePreload3=new Array()
var show1=0
var show2=0
var show3 = 0
for (i=0;i<image.length;i++)
{
	imagePreload[i]=new Image()
	imagePreload[i].src=image[i]
}
for (j=0;j<homeLink_2.length;j++)
{
	imagePreload2[j]=new Image()
	imagePreload2[j].src=homeLink_2[j]
}
for (m=0;m<homeLink_3.length;j++)
{
	imagePreload3[m]=new Image()
	imagePreload3[m].src=homeLink_2[m]
}
for (k=0;k<homeLink_1.length;k++)
{
	imagePreload1[k]=new Image()
	imagePreload1[k].src=homeLink_1[k]
}
function rec_pass(){
		var f_usrn
		var f_email
		var f_nif
		if(document.forms.form1['f_usrn'].value) f_usrn = document.forms.form1['f_usrn'].value
		if(document.forms.form1['f_email'].value) f_email = document.forms.form1['f_email'].value
		if(document.forms.form1['f_nif'].value) f_nif = document.forms.form1['f_nif'].value
	if (f_usrn || f_email || f_nif) {
		//strLocation = 'http://' + home + 'rec_password.php?X=1'
		strLocation = 'rec.php?X=1'
		if(f_usrn) strLocation += '&USRN='+f_usrn
		if(f_email) strLocation += '&EMAIL='+f_email
		if(f_nif) strLocation += '&NIF='+f_nif
 		window.open(strLocation, '_self', "fullscreen=yes, menubar=no, toolbar=no", false)

	} else {
		alert ('Tem de preencher pelo menos um dos campos')
		return;
	}
}

function home_link(imgID)
{
	var imgSrc = document.forms.login[imgID].src
	var str = imgSrc.substr(imgSrc.lastIndexOf("/")+1, imgSrc.lastIndexOf(".")-imgSrc.lastIndexOf("/")-1)
	if(str== 'revolta')  popMicroSite('microsite/eventos.php?area=revolta')
	if(str== 'cliente') popCartao()
	if(str== 'noticias') popNoticias()
	if(str== 'promocao') popPromocao()
	if(str== 'eventos') popMicroSite('microsite/eventos.php?area=eventos')
	if(str== 'cozinheiro') popMicroSite('microsite/eventos.php?area=jovem')
	if(str== 'congresso') popMicroSite('microsite/eventos.php?area=cnc')
	if(str== 'escolas') popMicroSite('microsite/eventos.php?area=escolas')
	if(str== 'open') popMicroSite('microsite/eventos.php?area=open')
	if(str== 'haccp')  popMicroSite('microsite/haccp.php')
	if(str== 'destaque_hp1') window.open('img/destaque.pdf') 
	if(str== 'destaque_hp2') window.open('img/destaque.pdf') 
	else if(str == 'contarecheio') popMicroSite('microsite/value.php?area=contarecheio')
}
function popPromocao () {
        strLocation = 'img/promocao.pdf'
        window.open(strLocation,'Promocao', 'height=500, width=400, status=no, toolbar=no,menubar=no,location=no, resizable=no, top=120, left=300, scrollbars=no');
}
function popRevolta(){
	//strLocation = 'http://' + home + '/popCond.html'
	strLocation = 'popRevolta.html'
	window.open(strLocation,'popRevolta','height=500, width=400, status=no, toolbar=no,menubar=no,location=no, resizable=no, top=120, left=300, scrollbars=no');
}

function popRevoltaIns() {
	strLocation = 'http://www.e-gosto.com/eventos/form.asp?idEvento=12'
	window.open(strLocation,'popRevolta','height=600, width=500, status=no, toolbar=no,menubar=no,location=no, resizable=no, top=120, left=300, scrollbars=no');
	resizeTo(460,595)
}
function popNoticias(){
	//strLocation = 'http://' + home + '/popCond.html'
	strLocation = 'popNoticias.html'
	window.open(strLocation,'popNoticias','height=500, width=400, status=no, toolbar=no,menubar=no,location=no, resizable=no, top=120, left=300, scrollbars=no');
}
function image_effects()
{    
	document.images.slide.filters.revealTrans.Transition=23 // we can change between 1 and 23
	document.images.slide.filters.revealTrans.apply()
	document.images.slide.filters.revealTrans.play()
}
function image_effects1()
{    
	document.images.homeLink1.filters.revealTrans.Transition=23// we can change between 1 and 23
	document.images.homeLink1.filters.revealTrans.apply()
	document.images.homeLink1.filters.revealTrans.play()	
}
function image_effects2()
{    
	document.images.homeLink2.filters.revealTrans.Transition=23 // we can change between 1 and 23
	document.images.homeLink2.filters.revealTrans.apply()
	document.images.homeLink2.filters.revealTrans.play()	
}
function image_effects3()
{    
	document.images.homeLink3.filters.revealTrans.Transition=23 // we can change between 1 and 23
	document.images.homeLink3.filters.revealTrans.apply()
	document.images.homeLink3.filters.revealTrans.play()	
}
function slideshow()
{ 
    /*if (num<image.length)
     {
       num++
       if (num==image.length) 
       num=0
       if(browser=="IE") image_effects()
       timeDelay=setTimeout("slideshow()",5000) 
       document.images.slide.src=image[num]   
     }  */
	 if (show1 == 0) {
		slideshow1()
		show1=1
	 }
	 if (show2 == 0) {
		slideshow2()
		show2=1
	 }
	 if (show3 == 0) {
		 slideshow3()
		 show3=1
	 }
}
function slideshow1()
{ 
	if (num1<homeLink_1.length)
     {
       num1++
       if (num1==homeLink_1.length) 
       num1=0
       if(browser=="IE") image_effects1()
       timeDelay1=setTimeout("slideshow1()",5000) 
       document.images.homeLink1.src=homeLink_1[num1]
     }
}
function slideshow2()
{ 
	if (num2<homeLink_2.length)
     {
       num2++
       if (num2==homeLink_2.length) 
       num2=0
       if(browser=="IE") image_effects2()
       timeDelay2=setTimeout("slideshow2()",5000) 
       document.images.homeLink2.src=homeLink_2[num2]
     }
}
function slideshow3()
{ 
	if (num3<homeLink_3.length)
     {
       num3++
       if (num3==homeLink_3.length) 
       num3=0
       if(browser=="IE") image_effects3()
       timeDelay3=setTimeout("slideshow3()",5000) 
       document.images.homeLink3.src=homeLink_3[num3]
     }
}
function frompop2reg(){
	strLocation = "reg.php"
	window.opener.location.href=strLocation
	self.close()
}
function frompop2rec(){
	strLocation = "rec.php"
	window.opener.location.href=strLocation
	self.close()
}
function pop_login(){
	strLocation = 'pop_login.php'
	window.open(strLocation,'login','height=200, width=200, status=no, titlebar=no, toolbar=no,menubar=no,location=no, resizable=no, top=300, left=300');
	return false
}
function changeSec(loja, sec) {
	if (loja == 'braga') var secs = new Array('talho','peixaria', 'frutaselegumes', 'padaria', 'garrafeira', 'congelados', 'gourmet', 'centroformacao');
	else if(loja== 'tavira') var secs = new Array('talho','peixaria', 'frutaselegumes', 'congelados', 'garrafeira');
	for (i=0; i < secs.length; i++) {
		document.getElementById(secs[i]).style.display = 'none';
		document.getElementById('im_'+secs[i]).src = 'images/'+secs[i]+'.gif';
	}
	document.getElementById('im_'+sec).src = 'images/'+sec+'2.gif';	
	//document.getElementById('im_'+sec).style.cursor = 'none';
	document.getElementById(sec).style.display = 'block';
}
function changeWine(zone) {
	var zones = new Array('douro', 'dao', 'estremadura', 'setubal', 'alentejo');
	for (i=0; i < zones.length; i++) {
		document.getElementById(zones[i]).style.display = 'none';
		document.getElementById('im_'+zones[i]).src = 'images/'+zones[i]+'.gif';
	}
	document.getElementById('im_'+zone).src = 'images/'+zone+'2.gif';	
	document.getElementById(zone).style.display = 'block';
}
function changeMenu(mnu) {
	var mnus = new Array('A1', 'A2', 'A3', 'A4', 'A5', 'A6');
	for (i=0; i < mnus.length; i++) {
		if(mnu != mnus[i]) document.getElementById(mnus[i]).style.display = 'none';
	}
	var style1 = document.getElementById(mnu).style;
	if(style1.display == 'none' ) style1.display = 'block';
	else style1.display = 'none';
//	document.getElementById(mnu).style.display = 'block';
}
function changeDiv(div) {
	var tDiv = div.substr(0, 4)
	var dMax = 0;
	if(tDiv == 'good') dMax = 13;
	if(tDiv == 'how_') dMax = 12;
	if (dMax > 0) for (i=1;i<=dMax;i++)
	{
		if (div != tDiv+i) {
			document.getElementById(tDiv+i).style.display = 'none';
			if(tDiv!='how_' || (tDiv=='how_' && i>4))document.getElementById('im_'+tDiv+i).src = "images/arrow_down.jpg"
		}
	}
	if (document.getElementById)
	{
		var style2 = document.getElementById(div).style;
		if(style2.display == 'none' ) {
			style2.display = 'block';
			document.getElementById('im_'+div).src = "images/arrow_up.jpg"
		}
		else {
			style2.display = 'none';
			document.getElementById('im_'+div).src = "images/arrow_down.jpg"
		}
	}
	else if (document.all)
	{
	// this is the way old msie versions work
		var style2 = document.all[div].style;
		style2.display = style2.display? "":"block";
	}
	else if (document.layers)
	{
	// this is the way nn4 works
		var style2 = document.layers[div].style;
		style2.display = style2.display? "":"block";
	}
}

function popCond(){
	//strLocation = 'http://' + home + '/popCond.html'
	strLocation = 'popCond.html'
	window.open(strLocation,'popCond','height=520, width=420, status=no, toolbar=no,menubar=no,location=no, resizable=no, top=120, left=300, scrollbars=no');
}
function popCartao(){
	//strLocation = 'http://' + home + '/popCond.html'
	strLocation = 'popCartao.html'
	window.open(strLocation,'popCartao','height=570, width=420, status=no, toolbar=no,menubar=no,location=no, resizable=no, top=120, left=300, scrollbars=no');
}
function pop5razoes(){
	//strLocation = 'http://' + home + '/pop5razoes.html'
	strLocation = 'pop5razoes.html'
	window.open(strLocation,'_blank','height=495, width=325, status=no, toolbar=no,menubar=no,location=no, resizable=no, top=100, left=300');
}

function popMicroSite(loc){
	var newwindow=window.open(loc,'microsite','height=650, width=670, status=no, toolbar=no,menubar=no,location=no, resizable=no, top=40, left=180, scrollbars=yes');
	if(window.focus)newwindow.focus()
	return false;
}

function popMundial(loc, h, w){
	var newwindow=window.open(loc,'mundial','height='+ h +', width='+ w + ', status=yes, toolbar=no,menubar=no,location=yes, resizable=yes, top=40, left=180');
	if(window.focus)newwindow.focus()
	return false;
}

function popPrasa(loc){
	
	var imgPrasaSrc = document.forms.login['slide'].src
	var strPrasa = imgPrasaSrc.substr(imgPrasaSrc.lastIndexOf("/")+1, imgPrasaSrc.lastIndexOf(".")-imgPrasaSrc.lastIndexOf("/")-1)
	if(strPrasa== 'destaque-d')  loc='prasa/auto.php'
//	if(str== 'cliente') popCartao()
//	if(str== 'noticias') popNoticias()
//	else if(str == 'contarecheio') popMicroSite('microsite/value.php?area=contarecheio')

var newwindow=window.open(loc,'prasa','height=700, width=670, status=no, toolbar=no,menubar=no,location=no, resizable=yes, top=2, left=180, scrollbars=yes');
	if(window.focus)newwindow.focus()
	return false;
}
function popCom(){
        strLocation = 'img/JM_Comunicado_03Julho2009.pdf'
        window.open(strLocation,'Promocao', 'height=500, width=400, status=no, toolbar=no,menubar=no,location=no, resizable=no, top=120, left=300, scrollbars=no');

}
function goTo(dest) {
	switch(dest) {
		case 'home':
			//strLocation = 'http://' + home + 'index.php'
			strLocation = 'index.php'
		break;
	}
	if (strLocation) window.open(strLocation, '_self', "fullscreen=yes, menubar=no, toolbar=no", false)
	act = dest	
}

function form1_Validator(theForm)
{
	if (act != '') return (false)
	//theForm = document.getElementById(form_name).
  if (theForm.nif.value == "")
  {
    alert("Por favor introduza um valor no campo \"Contribuinte\" .");
    theForm.nif.focus();
    return (false);
  }

  if (theForm.nif.value.length < 9)
  {
    alert("Por favor introduza 9 digitos no campo  \"Contribuinte\" .");
    theForm.nif.focus();
    return (false);
  }

  if (theForm.nif.value.length > 9)
  {
    alert("Por favor introduza 9 digitos no campo  \"Contribuinte\" .");
    theForm.nif.focus();
    return (false);
  }

  var checkOK = "0123456789-,.";
  var checkStr = theForm.nif.value;
  var allValid = true;
  var decPoints = 0;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    if (ch == ",")
    {
      allNum += ".";
      decPoints++;
    }
    else if (ch != ".")
      allNum += ch;
  }
  if (!allValid)
  {
    alert("Por favor introduza apenas numeros no campo \"Contribuinte\".");
    theForm.nif.focus();
    return (false);
  }

  if (decPoints > 1)
  {
    alert("Por favor introduza um numero valido no campo \"Contribuinte\"");
    theForm.nif.focus();
    return (false);
  }

  if (theForm.nome.value == "")
  {
    alert("Por favor introduza um valor no campo \"Nome\".");
    theForm.nome.focus();
    return (false);
  }

  if (theForm.nome.value.length > 50)
  {
    alert("Por favor introduza no maximo 50 caracteres no campo \"Nome\"");
    theForm.nome.focus();
    return (false);
  }
/*

      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Por favor introduza apenas letras, numeros e espaços no campo \"Nome\".");
    theForm.nome.focus();
    return (false);
  }
*/
/*
  if (theForm.email.value == "")
  {
    alert("Por favor introduza um valor no campo \"Email\".");
    theForm.email.focus();
    return (false);
  }


      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
*/
  if (!allValid)
  {
    alert("Por favor introduza apenas letras, numeros e \"@\" no campo \"Email\".");
    theForm.email.focus();
    return false;
  }

  if (theForm.telefone.value == "")
  {
    alert("Por favor introduza um valor no campo \"Telefone\".");
    theForm.telefone.focus();
    return (false);
  }

  if (theForm.telefone.value.length < 9)
  {
    alert("Por favor introduza 9 digitos no campo \"Telefone\".");
    theForm.telefone.focus();
    return (false);
  }

  if (theForm.telefone.value.length > 9)
  {
    alert("Por favor introduza 9 digitos no campo \"Telefone\".");
    theForm.telefone.focus();
    return (false);
  }

  var checkOK = "0123456789-,._";
  var checkStr = theForm.telefone.value;
  var allValid = true;
  var decPoints = 0;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    if (ch == ",")
    {
      allNum += ".";
      decPoints++;
    }
    else if (ch != ".")
      allNum += ch;
  }
  if (!allValid)
  {
    alert("Por favor introduza apenas numeros no campo \"Telefone\".");
    theForm.telefone.focus();
    return (false);
  }

  if (decPoints > 1)
  {
    alert("POr favor introduza um numero valido no campo \"Telefone\".");
    theForm.telefone.focus();
    return (false);
  }
  
  return (true);
}

