/* Funções Genéricas */

function infoorder(mid) {
 
   infoorder_upp();
 
}
  
function infoorder_upp() {
 
   var breite = 635;
   var hoehe = 550;
   
   var locale = 'pt_PT';
   // Special window size for de_DE
   if(locale="de_DE"){
     breite = 680;
     hoehe = 590;
   }
   
   
   actionUrl='http://www.smart.com/is-bin/INTERSHOP.enfinity/WFS/mpc-pt-content-Site/pt_PT/-/EUR/Smart_UppFeedback-Start;sid=TJ7z00IKF7Px0wZ3Nw9628AA403hqdwxRHknWFJMqf35CA==';
   myurl = addSidToURL(actionUrl);
  window.open(myurl,'infoorder','toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=no,copyhistory=no,titlebar=no,width='+breite+',height='+hoehe+',left='+(Math.round((screen.width-breite)/2))+',top='+(Math.round((screen.height-hoehe)/2)));

}

function smartconfigurator(mid) {
 
    w=910;
    h=710;
    country='PT';
    country=country.toUpperCase();
    language='pt';
    //ccUrl="http://www3.smart.com/CarConfigurator/ModelLine.aspx?modelcode=" + mid + "&country=" + country + "&language=" + language;
    ccUrl='http://www.smart.pt/is-bin/INTERSHOP.enfinity/WFS/mpc-pt-content-Site/pt_PT/-/EUR/Smart_CC-Model?cache=true';
    //ccUrl = addParameterToUrl(ccUrl, 'modelcode=' + mid);

    window.open(ccUrl,'smartconf','width='+w+',height='+h+',locationbar=no,toolbar=no,scrollbars=yes,left='+(Math.round((screen.width-w)/2))+',top='+(Math.round((screen.height-h)/2))+ ',toolbar=no');
     
    }
    
function addSidToURL(strURL) {
    var strSessionIDURL="/-snm-0145283564-1148444047-0000020951-0000002404-1149070607-enm-";
    var strSessionID = strSessionIDURL.substring(1);

    var y = strURL.lastIndexOf ("-enm-");

    if (y == -1) {
        var x = strURL.indexOf ("//");
        if (x != -1) {
            var strPre = strURL.substring (0, x+2);
            var strPost = strURL.substring (x+2, strURL.length);

            var i = strPost.indexOf('/');
            if (i != -1)
                return strPre + strPost.substring(0, i+1)+strSessionID+strPost.substring(i+1);
            else
                return strPre + strPost + strSessionIDURL;
        } else {
            var i = strURL.indexOf('/');
            if (i==-1)
                return strSessionID+strURL;
            else
                return strURL.substring(0, i+1)+strSessionID+strURL.substring(i+1);
        } //end else if
    } else {
        return strURL.substring(0, y+5)+strSessionID+strURL.substring(y+5);
    }
}

function addParameterToUrl(url, param)
{
  var x = url.indexOf ("?");
  var  addChar ='?';
  var newUrl = url;
  
    if (x != -1) 
  {
    addChar ='&';
    }
  newUrl= url + addChar + param;
  return newUrl;
}

/* Funções Validators */

function ValidaLocalizacaoLoja(source, arguments)
{
	var iConta;
	if (document.HtmlFormCandidatura.HtmlInputCheckBoxLocalizacao1Loja.checked) iConta=1;
	if (document.HtmlFormCandidatura.HtmlInputCheckBoxLocalizacao2Loja.checked) iConta=1;
	if (document.HtmlFormCandidatura.HtmlInputCheckBoxLocalizacao3Loja.checked) iConta=1;
	if (document.HtmlFormCandidatura.HtmlInputCheckBoxLocalizacao4Loja.checked) iConta=1;
	if (document.HtmlFormCandidatura.HtmlInputCheckBoxLocalizacao5Loja.checked) iConta=1;
	if (document.HtmlFormCandidatura.HtmlInputCheckBoxLocalizacao6Loja.checked) iConta=1;
	if (document.HtmlFormCandidatura.HtmlInputTextLocalizacaoOutraLoja.value != '') iConta=1;

	if (iConta==1) 
		arguments.IsValid=true 
	else 
		arguments.IsValid=false
}

function ValidaServicosAssociadosLoja(source, arguments)
{
	var iConta;
	if (document.HtmlFormCandidatura.HtmlInputCheckBoxServicosAssociados1Loja.checked) iConta=1;
	if (document.HtmlFormCandidatura.HtmlInputCheckBoxServicosAssociados2Loja.checked) iConta=1;
	if (document.HtmlFormCandidatura.HtmlInputCheckBoxServicosAssociados3Loja.checked) iConta=1;
	if (document.HtmlFormCandidatura.HtmlInputCheckBoxServicosAssociados4Loja.checked) iConta=1;
	if (document.HtmlFormCandidatura.HtmlInputCheckBoxServicosAssociados5Loja.checked) iConta=1;
	if (document.HtmlFormCandidatura.HtmlInputCheckBoxServicosAssociados6Loja.checked) iConta=1;
	if (document.HtmlFormCandidatura.HtmlInputCheckBoxServicosAssociados7Loja.checked) iConta=1;
	if (document.HtmlFormCandidatura.HtmlInputTextServicosAssociadosOutrosLoja.value != '') iConta=1;

	if (iConta==1) 
		arguments.IsValid=true 
	else 
		arguments.IsValid=false
}

/* Funções Validators*/

function Noticia(arg1) {
	document.__FORM.action = '/noticias/noticia.aspx';
	document.__FORM.recordId.value = arg1;
	document.__FORM.IdNoticia.value = arg1;
	
	document.__FORM.submit();
}

function Tema(arg1) {
	document.__FORM.action = '/noticias/lista.aspx';
	document.__FORM.recordId.value = arg1;
	document.__FORM.IdTemaNoticia.value = arg1;
	document.__FORM.tipo.value = 4;
	
	document.__FORM.submit();
}

function PressRelease(arg1) {
	document.__FORM.action = '/pressrelease/pressrelease.aspx';
	document.__FORM.recordId.value = arg1;
	
	document.__FORM.submit();
} 

function Emitente(arg1,arg2) {
	document.__FORM.action = '/emitentes/emitente.aspx';
	document.__FORM.recordId.value = arg1;

	if (arg2 > 0) document.__FORM.IdConcelho.value = arg2;
	
	document.__FORM.submit();
}

function EmitenteC() {
	var id = document.getElementById("ComboDistrito").value
	var arg1 = document.getElementById("ComboConcelho"+id).value;
	
	document.__FORM.action = '/emitentes/concelho.aspx';
	document.__FORM.recordId.value = arg1;

	document.__FORM.IdConcelho.value = arg1;
	document.__FORM.IdDistrito.value = id;
	
	document.__FORM.tipo.value = 7;
	
	document.__FORM.submit();	
}

function AgenteD(arg1) {
	if (arg1 != undefined && (arg1.value || arg1.value == '')) arg1 = arg1.value

	document.__FORM.action = '/agentes/distrito.aspx';
	document.__FORM.IdDistrito.value = arg1;
	document.__FORM.tipo.value = 1;

	document.__FORM.submit();
}

function AgenteC(arg1,arg2) {
	if (arg1 != undefined && (arg1.value || arg1.value == '')) arg1 = arg1.value
	if (arg2 != undefined && (arg2.value || arg2.value == '')) arg2 = arg2.value

	document.__FORM.action = '/agentes/concelho.aspx';
	document.__FORM.IdConcelho.value = arg1;
	document.__FORM.IdDistrito.value = arg2;
	document.__FORM.tipo.value = 2;

	document.__FORM.submit();
}

function AgenteF(arg1,arg2,arg3) {
	if (arg1 != undefined && (arg1.value || arg1.value == '')) arg1 = arg1.value
	if (arg2 != undefined && (arg2.value || arg2.value == '')) arg2 = arg2.value
	if (arg3 != undefined && (arg3.value || arg3.value == '')) arg3 = arg3.value

	document.__FORM.action = '/agentes/freguesia.aspx';
	document.__FORM.IdFreguesia.value = arg1;
	document.__FORM.IdConcelho.value = arg2;
	document.__FORM.IdDistrito.value = arg3;
	document.__FORM.tipo.value = 3;

	document.__FORM.submit();
}

function Agente(arg1) {
	if (arg1 != undefined && (arg1.value || arg1.value == '')) arg1 = arg1.value

	document.__FORM.action = '/agentes/agente.aspx';
	document.__FORM.IdLoja.value = arg1;
	
	document.__FORM.submit();
}

function Cadeia(arg1) {
	if (arg1 != undefined && (arg1.value || arg1.value == '')) arg1 = arg1.value

	document.__FORM.action = '/agentes/rede.aspx';
	document.__FORM.IdRetalhista.value = arg1;
	document.__FORM.tipo.value = 6;

	document.__FORM.submit();
}

function AreaActividade() {
	var oArea = document.getElementById("ComboArea");
	
	if (oArea.value > 0) {
		document.__FORM.action = '/emitentes/area.aspx';
		document.__FORM.IdAreaActividade.value = oArea.value;
		document.__FORM.tipo.value = 5;		
		
		document.__FORM.submit();	
	} else {
		alert('Seleccione a Área de Actividade!\n')
	}
}

function ListarConteudo(arg1) {
	switch (arg1)
	{
		case 1: //Noticias
			window.location='/noticias/';
			break;
		case 2: //Press Release
			window.location='/pressrelease/';
			break;
		case 3: //Newsletter
			window.location='/newsletter/';
			break;
	}
}

function DoSearch(arg1,arg2) {
	document.__FORM.action = arg1;
	document.__FORM.searchText.value = arg2;

	document.__FORM.submit();
}


function GoToPage(arg1,arg2,arg3,arg4,arg5,arg6) { 
	document.__FORM.action = arg1;
	document.__FORM.pag.value = arg2;
	document.__FORM.tipo.value = arg3;

	document.__FORM.searchText.value = arg3;

	switch (arg3)
	{
		case '1': //Agentes - Distrito
			document.__FORM.IdDistrito.value = arg4;
			break;
		case '2': //Agentes - Concelho
			document.__FORM.IdConcelho.value = arg4;
			document.__FORM.IdDistrito.value = document.getElementById("IdDistrito2").value;
			break;
		case '3': //Agentes - Freguesia
			document.__FORM.IdFreguesia.value = arg4;
			break;
		case '4': //Noticias - Lista
			document.__FORM.IdTemaNoticia.value = arg5;
			break;
		case '5': //Emitentes - AreaActividade
			document.__FORM.IdAreaActividade.value = arg4;
			break;		
		case '6': //Agentes - Rede
			document.__FORM.IdRetalhista.value = arg4;
			break;		
		case '7': //Emitentes - Concelho
			document.__FORM.recordId.value = arg4;
			document.__FORM.IdConcelho.value = arg4;
			document.__FORM.IdDistrito.value = document.getElementById("IdDistrito2").value;
			break;
	}
	
	document.__FORM.submit();
}

function EmitenteConcelho(arg1) {
	var id = document.getElementById("IdDistrito2").value

	if (arg1 != undefined && (arg1.value || arg1.value == '')) arg1 = arg1.value
	
	document.__FORM.action = '/emitentes/concelho.aspx';
	document.__FORM.recordId.value = arg1;

	document.__FORM.IdConcelho.value = arg1;
	document.__FORM.IdDistrito.value = id;
	document.__FORM.tipo.value = 7; //necessario para a navegacao
	
	document.__FORM.submit();	
}

function AgenteConcelho() {
	var id = document.getElementById("IdDistrito2").value
	var arg1 = document.getElementById("ComboConcelho").value;

	document.__FORM.action = '/agentes/concelho.aspx';
	document.__FORM.IdConcelho.value = arg1;
	document.__FORM.IdDistrito.value = id;
	document.__FORM.tipo.value = 2; //necessario para a navegacao
	
	document.__FORM.submit();	
}


// --------------------------------------------------
//  AGENTES e EMITENTES : combo Distrito/Concelho
// --------------------------------------------------

function HideAll_ShowActive(objDistrito,objDistritoValue) {
	var oDistritoTotal = objDistrito.length - 1;
	var oDistritoValue = objDistritoValue;
	
	//hide all
	for (i = 1;i <= oDistritoTotal;i++) { 
		ii = eval(objDistrito[i].value)
		document.getElementById("DivConcelho"+ii).style.display = 'none'	
	}

	//show active
	if (oDistritoValue > 0) {
		document.getElementById("DivConcelho"+oDistritoValue).style.display = ''
		
		//Freguesia
		var oDivFreguesia = document.getElementById("DivFreguesia")
		
		if (oDivFreguesia != undefined) {
			var oConcelhoValue = document.getElementById("ComboConcelho"+oDistritoValue).value

			if (oConcelhoValue > 0) { 
				oDivFreguesia.style.display='';
			} else {
				oDivFreguesia.style.display='none';
			}
		}
	}
} //end function

function MostraConcelho() {
	var oDistrito = document.getElementById("ComboDistrito");

	HideAll_ShowActive(oDistrito,oDistrito.value)
}

function VerDistrito(idx) {
	var oDistrito = document.getElementById("ComboDistrito");
	oDistrito.value=idx
	
	HideAll_ShowActive(oDistrito,idx)
}

function Agente_MostraFreguesia() {
	var oDistritoValue = document.getElementById("ComboDistrito").value;
	var oConcelhoValue = document.getElementById("ComboConcelho"+oDistritoValue).value;

	if (oConcelhoValue > 0) {
		document.__FORM.action = '/agentes/default.aspx';
		document.__FORM.IdConcelho.value = oConcelhoValue;
		document.__FORM.IdDistrito.value = oDistritoValue;
		document.__FORM.submit();
		
	} else {
		alert('Seleccione o Concelho!\n')
	}
}

function Agente_ListarDistrito() {
	var oDistritoValue = document.getElementById("ComboDistrito").value;
	
	if (oDistritoValue > 0) {
		AgenteD(oDistritoValue)
	} else {
		alert('Seleccione o Distrito!\n')
	}
}

function Agente_ListarConcelho() {
	var oDistritoValue = document.getElementById("ComboDistrito").value;
	var oConcelhoValue = document.getElementById("ComboConcelho"+oDistritoValue).value;

	if (oConcelhoValue > 0) {
		AgenteC(oConcelhoValue,oDistritoValue)
	} else {
		alert('Seleccione o Concelho!\n')
	}
}

function Agente_ListarFreguesia() {
	var oDistritoValue = document.getElementById("ComboDistrito").value;
	var oConcelhoValue = document.getElementById("ComboConcelho"+oDistritoValue).value;
	var oFreguesiaValue = document.getElementById("ComboFreguesia").value;

	if (oFreguesiaValue > 0) {
		AgenteF(oFreguesiaValue,oConcelhoValue,oDistritoValue)
	} else {
		alert('Seleccione a Freguesia!\n')
	}
}

function Emitente_NextPage() {
	var oDistrito = document.getElementById("ComboDistrito");
	var oDistritoValue = oDistrito.value;
	
	if (oDistritoValue > 0) {
		var oConcelho = document.getElementById("ComboConcelho"+oDistritoValue)
		if (oConcelho.value == "") { alert('Seleccione o Concelho!\n') } else { EmitenteC() }
	} else {
		alert('Seleccione o Distrito!\n')
	}
}

function Home_ListarDistrito() {

	Agente_ListarDistrito()
	
}

function DoSearchHomepage(arg1,arg2) {
	var id = document.getElementById("ComboDistrito").value
	var id2 = '';
	
	if (id != '') id2 = document.getElementById("ComboConcelho"+id).value;

	document.__FORM.action = arg1;
	document.__FORM.searchText.value = arg2;
	document.__FORM.IdDistrito.value = id;
	document.__FORM.IdConcelho.value = id2;

	document.__FORM.submit();
}

function GoToPage2(arg1,arg2,arg3,arg4,arg5) { 
	//Homepage - Pesquisa
	document.__FORM.action = arg1;
	document.__FORM.pag.value = arg2;

	document.__FORM.searchText.value = arg3;
	document.__FORM.IdDistrito.value = arg4;
	document.__FORM.IdConcelho.value = arg5;

	document.__FORM.submit();
}




// --------------
//  falta ver
// --------------
function Mapa() {
	window.open('/auxiliar/mapa.aspx','mapa','toolbar=no,width=400,height=400,location=no,status=no,directories=no,menubar=no,scrollbars=yes,resizable=no');
}

function RedirectMap(lnk) {
	window.opener.location = (lnk);
	window.close()
}

function Anterior() {
	history.back();
}

function Topo() {
	scrollTo();
}

function Fechar() {
	window.close();
}

function Imprimir() {
	window.print();
}

function abre(tid,n) {
	if (eval("document.all."+tid+".style.display")=="none") {
                for (i=1;i<n;i++) {
		eval("document.all.t"+i+".style.display='none'");
                }
		eval("document.all."+tid+".style.display=''");
		}
	else {
		eval("document.all."+tid+".style.display='none'");
	}	
}


function imprime(numero) {
	for (i=1;i<numero+1;i++) {
                eval("document.all.t"+i+".style.display=''");
        }
        print();
        for (i=1;i<numero+1;i++) {
                eval("document.all.t"+i+".style.display='none'");
        }

}

function homeBanner(){
	 AC_FL_RunContent(
	   'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
	   'width', '708',
	   'height', '287',
	   'src','/flash/20110509-home_melhorOficina_v2',
	   'quality', 'best',
	   'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
	   'align', 'middle',
	   'play', 'true',
	   'loop', 'false',
	   'scale', 'showall',
	   'wmode', 'transparent',
	   'devicefont', 'false',
	   'id', 'banner_pre_NovaGama_29092010',
	   'bgcolor', '#ffffff',
	   'name', 'Spot',
	   'menu', 'false',
	   'allowFullScreen', 'false',
	   'allowScriptAccess','sameDomain',
	   'movie','/flash/20110509-home_melhorOficina_v2',
	   'salign', ''
	); //end AC code
	
}
