﻿function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0; a && i<a.length && (x=a[i]) && x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i, j=0, x, a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0; i < (a.length-2); i+=3)
   if ((x=MM_findObj(a[i]))!=null) {document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

var selectedDiv;
var divHeight;

function changeMap(id) {
	var images = Array("", "1.png", "2.png", "3.png", "4.png", "5.png", "6.png", "7.png", "8.png", "9.png", "10.png", "11.png", "12.png", "13.png", "14.png", "15.png", "16.png", "17.png", "18.png", "19.png", "20.png");
	var names = Array("", "Viana do Castelo", "Braga", "Porto", "Vila Real", "Bragança", "Aveiro", "Viseu", "Guarda", "Coimbra", "Castelo Branco", "Leiria", "Santarém", "Portalegre", "Lisboa", "Setúbal", "Évora", "Beja", "Faro", "Açores", "Madeira");
	var image_path = 'images/agents/';
	selectedDiv = 'section' + id;
	//divHeight = document.getElementById(selectedDiv).clientHeight;
	
	document.mapa.src = image_path + images[id];
	document.getElementById('districtName').innerHTML = names[id];
}

function restoreMap(id) {
	document.mapa.src = 'images/agents/map_portugal.jpg';
	document.getElementById('districtName').innerHTML = '';
}

function showScrollerDivs() {
/*
	if (divHeight>585) {
		document.getElementById('scrollerDivs').style.display = 'block';
	} else {
		document.getElementById('scrollerDivs').style.display = 'none';
	}
*/
}

var Timer;
function ScrollTop(){
alert(1);
  Timer = setInterval("document.getElementById('agentes').scrollTop -= 2", 15);
}

function ScrollDown(){
  Timer = setInterval("document.getElementById('agentes').scrollTop += 2", 15);
alert(2);
}

function go2(url){
	window.location.href=url;
}

function checkEmail(inputvalue){	
    var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
    if(pattern.test(inputvalue)){         
		return true;   
    }else{   
		return false;
    }
}

function registMag(){
	if (document.magazine.subscribe_email.value == ''){
		alert("Preencha o Email!");
	} else {	
		var check = checkEmail(document.magazine.subscribe_email.value);

		if (check) {
			window.document.magazine.mode.value = 'i';
			window.document.magazine.action = 'magazine.asp';
			window.document.magazine.submit();
		} else {
			alert("Email Inválido!");
		}
	}
}

function resendMag(){
	if (document.magazine.subscribe_email.value == ''){
		alert("Preencha o Email!");
	} else {	
		var check = checkEmail(document.magazine.subscribe_email.value);

		if (check) {
			window.document.magazine.mode.value = 'r';
			window.document.magazine.action = 'magazine.asp';
			window.document.magazine.submit();
		} else {
			alert("Email Inválido!");
		}
	}
}

function cancelMag(){
	if (document.magazine.subscribe_email.value == ''){
		alert("Preencha o Email!");
	} else {	
		var check = checkEmail(document.magazine.subscribe_email.value);

		if (check) {
			window.document.magazine.mode.value = 'c';
			window.document.magazine.action = 'magazine.asp';
			window.document.magazine.submit();
		} else {
			alert("Email Inválido!");
		}
	}
}


function selectAgentsDistrito(id) {
    document.agents.fk_distrito_id.value = id;
    /*
    if (document.agents.fk_distrito_id.value == '') {
        document.getElementById('error').innerHTML = 'Escolha o distrito no mapa por favor!';
    } else {
        document.getElementById('error').innerHTML = '';
    }
    */
    getAgents();
}

function selectAgentsBrands(id) {
    //alert(id);
    document.getElementById('fk_section_id').value = id;
    /*
    if (document.agents.fk_section_id.value == '') {
        document.getElementById('error').innerHTML = 'Escolha a marca por favor!';
    } else {
        document.getElementById('error').innerHTML = '';
    }
    */
    getAgents();    
}

function getAgents() {
    //if ((document.agents.fk_section_id.value != '') & (document.agents.fk_distrito_id.value != '')) {
    if (document.agents.fk_distrito_id.value != '') {
        window.document.agents.submit();
    }
}