﻿/* Ford Concessionários */

/* Area's Page ID's */
var Pages = [];
// new Array("Search", "Advanced Search", "Used Vehicles", "Compare Products", "Product Sheet" , "Test Drive", "Product Catalogue")
// new Array("Pesquisa", "Pesquisa Detalhada", "Veiculos usados", "Comparar Veiculos", "Ficha de Veiculo" , "Faça um Test Drive", "Lista de Veiculos", "Grupo eCom")
Pages[1] = new Array ("1", "1", "1", "1", "1", "1", "1", "GROUP00"); //Pagina Intro para evitar erros Javascript
Pages[3] = new Array ("32", "1517", "1515", "1518", "1516", "25", "1519", "GROUP1"); //Stand exemplo
Pages[4] = new Array ("67", "46", "44", "47", "45", "60", "48", "GROUP23"); //Stand Bretescar
Pages[5] = new Array ("92", "71", "69", "72", "70", "85", "73", "GROUP37"); //Stand Louresford
Pages[6] = new Array ("117", "96", "94", "97", "95", "110", "98", "GROUP13"); //Stand BRM Automoveis
Pages[7] = new Array ("142", "121", "119", "122", "120", "135", "123", "GROUP12"); //Stand Auto Rabal
Pages[8] = new Array ("167", "146", "144", "147", "145", "160", "148", "GROUP17"); //Stand M.Coutinho Nordeste
Pages[9] = new Array ("192", "171", "169", "172", "170", "185", "173", "GROUP4"); //Stand Auto Sueco Coimbra
Pages[10] = new Array ("217", "196", "194", "197", "195", "210", "198", "GROUP26"); //Stand Garagem Lopes
Pages[11] = new Array ("242", "221", "219", "222", "220", "235", "223", "GROUP24"); //Stand Egifor
Pages[12] = new Array ("267", "246", "244", "247", "245", "260", "248", "GROUP27"); //Stand Lizdrive
Pages[13] = new Array ("292", "271", "269", "272", "270", "285", "273", "GROUP15"); //Stand Hermotor
Pages[14] = new Array ("317", "296", "294", "297", "295", "310", "298", "GROUP18"); //Stand M.Coutinho Porto
Pages[15] = new Array ("342", "321", "319", "322", "320", "335", "323", "GROUP14"); //Stand Daro
Pages[16] = new Array ("367", "346", "344", "347", "345", "360", "348", "GROUP9"); //Stand CAM Porto
Pages[17] = new Array ("392", "371", "369", "372", "370", "385", "373", "GROUP19"); //Stand Rodam
Pages[18] = new Array ("417", "396", "394", "397", "395", "410", "398", "GROUP16"); //Stand Intermotor
Pages[19] = new Array ("442", "421", "419", "422", "420", "435", "423", "GROUP21"); //Stand Auto Garagem
Pages[20] = new Array ("467", "446", "444", "447", "445", "460", "448", "GROUP2"); //Stand M.Coutinho Litoral
Pages[21] = new Array ("492", "471", "469", "472", "470", "485", "473", "GROUP39"); //Stand Tecniauto
Pages[22] = new Array ("517", "496", "494", "497", "495", "510", "498", "GROUP30"); //Stand CAM Lisboa
Pages[23] = new Array ("542", "521", "519", "522", "520", "535", "523", "GROUP41"); //Stand Carfor
Pages[24] = new Array ("567", "546", "544", "547", "545", "560", "548", "GROUP40"); //Stand Expofor
Pages[25] = new Array ("592", "571", "569", "572", "570", "585", "573", "GROUP38"); //Stand Moderno
Pages[26] = new Array ("617", "596", "594", "597", "595", "610", "598", "GROUP32"); //Stand Forpalmela
Pages[27] = new Array ("642", "621", "619", "622", "620", "635", "623", "GROUP8"); //Stand Motortejo
Pages[28] = new Array ("667", "646", "644", "647", "645", "660", "648", "GROUP10"); //Stand Nivelfor
Pages[29] = new Array ("692", "671", "669", "672", "670", "685", "673", "GROUP11"); //Stand Abrancar
Pages[30] = new Array ("717", "696", "694", "697", "695", "710", "698", "GROUP34"); //Stand Maxicar
Pages[31] = new Array ("742", "721", "719", "722", "720", "735", "723", "GROUP31"); //Stand Fiaal
Pages[32] = new Array ("767", "746", "744", "747", "745", "760", "748", "GROUP33"); //Stand Forportil
Pages[33] = new Array ("792", "771", "769", "772", "770", "785", "773", "GROUP5"); //Stand Madeira Auto-car
Pages[34] = new Array ("817", "796", "794", "797", "795", "810", "798", "GROUP29"); //Stand RPF II
Pages[35] = new Array ("842", "821", "819", "822", "820", "835", "823", "GROUP3"); //Stand Auto Ilha Verde
Pages[36] = new Array ("867", "846", "844", "847", "845", "860", "848", "GROUP42"); //Stand Ford Lusitana
Pages[37] = new Array ("867", "846", "844", "847", "845", "860", "848", "GROUP42"); //Viaturas comerciais

// Portuguese Districts
var Districts = [];
Districts[0] = new Array ("Aveiro", "1465", "1490");
Districts[1] = new Array ("Beja", "1483", "1497");
Districts[2] = new Array ("Braga", "1466", "1491");
Districts[3] = new Array ("Bragança", "1467", "1499");
Districts[4] = new Array ("Castelo Branco", "1484", "1507");
Districts[5] = new Array ("Coimbra", "1468", "1500");
Districts[6] = new Array ("Évora", "1469", "1492");
Districts[7] = new Array ("Faro", "1471", "1493");
Districts[8] = new Array ("Guarda", "1485", "1498");
Districts[9] = new Array ("Leiria", "1473", "1495");
Districts[10] = new Array ("Lisboa", "1474", "1496");
Districts[11] = new Array ("Porto", "1477", "1501");
Districts[12] = new Array ("Santarém", "1478", "1502");
Districts[13] = new Array ("Setúbal", "1479", "1503");
Districts[14] = new Array ("Viana do Castelo", "1480", "1504");
Districts[15] = new Array ("Vila Real", "1481", "1505");
Districts[16] = new Array ("Viseu", "1482", "1506");
Districts[17] = new Array ("Reg. Aut. dos Açores", "1464", "1489");
Districts[18] = new Array ("Reg. Aut. da Madeira", "1472", "1494");


/* Support Menu Mouse Over */
function SwapImage (id, imageSrc) {
  document.getElementById(id).src = imageSrc;
}

/* QuickSearch default text */
function CheckInput(DefaultInputText) {
  if ($('#QuickSearch_q').val() == DefaultInputText) {
    $('#QuickSearch_q').css({'color':'#000000'});
    $('#QuickSearch_q').val('');
  }
}

function CheckInput2(DefaultInputText) {
  if ($('#QuickSearch_q').val() == "" || $('#QuickSearch_q').val() == DefaultInputText) {
    $('#QuickSearch_q').css({'color':'#636363'});
    $('#QuickSearch_q').val(DefaultInputText);
  }
}

/* Vehicle Pictures */
function ZoomPicture(picturePath) {
  if (picturePath != "" && picturePath.substr(1,5) != "Admin") {
    document.getElementById('ProductZoomImage').innerHTML = '<img src="/admin/public/getimage.aspx?&amp;Image=' + picturePath + '&amp;Width=275&amp;Height=205" alt="" \/>';
  }
}

/* Vehicle Comparitions */
function CheckCheckboxes(ProdID) {
  activatedCheckBox = '#VehicleCompare' + ProdID;
  if (!$(activatedCheckBox).attr('checked')) {
    if ($('#ProductCompare1').val() == ProdID) {
      $('#ProductCompare1').val("");
    }
    else if ($('#ProductCompare2').val() == ProdID) {
      $('#ProductCompare2').val("");
    }
  }
  else {
    if ($('#ProductCompare1').val() != "" && $('#ProductCompare2').val() != "") {
      $(activatedCheckBox).attr('checked', false);
      alert("Só pode comparar 2 veículos de cada vez");
    }
    else {
      if ($('#ProductCompare1').val() == "") {
        $('#ProductCompare1').val(ProdID);
      }
      else if ($('#ProductCompare2').val() == "") {
        $('#ProductCompare2').val(ProdID);
      }
    }
  }
}

function CompareSubmit(areaID) {
  if ($('#ProductCompare1').val() == "" || $('#ProductCompare2').val() == "") {
    alert("Tem de seleccionar dois produtos para haver comparação");
  }
  else {
    document.ProductListForm.action = 'Default.aspx?ID=' + Pages[areaID][3] + '&compareproducts=' + $('#ProductCompare1').val().toUpperCase() + ',' + $('#ProductCompare2').val().toUpperCase();
    document.ProductListForm.submit();
  }
}

function VehicleComparistionURL() {
  URL = 'eComSearch=1';
  return URL;
}

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];}
}

function getURLParam(strParamName){
  var strReturn = "";
  var strHref = window.location.href;
  if ( strHref.indexOf("?") > -1 ){
    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
    var aQueryString = strQueryString.split("&");
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
      if (aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ) {
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
    }
  }
  return unescape(strReturn);
}