
// **********   Abarth.Master FUNCTIONS   **********
function CloseForms()
{
  var contactusform = document.getElementById('ContactUs');
  var testdriveform = document.getElementById('TestDrive');
  var newsletterform = document.getElementById('NewsLetter');
  if (contactusform != null)
    contactusform.style.display = 'none';
  if (testdriveform != null)
    testdriveform.style.display = 'none';
  if (newsletterform != null)
    newsletterform.style.display = 'none';
}

function CloseAllPanel()
{
  var panels = document.getElementsByTagName('div');

  for (var i=0; i<panels.length; i++)
    if (panels[i].className == 'ButtonSeeDriversClose' || panels[i].className == 'PanelSeeDrivers')
      panels[i].style.display = "none";
}

function ShowParentForm()
{
  if (parent != null && parent.document != null)
  {
    var divid = null;
    if (location.href.indexOf('ContactUs') > -1)
        divid = 'ContactUs';
    else if (location.href.indexOf('TestDrive') > -1)
        divid = 'TestDrive';
    else if (location.href.indexOf('NewsLetter') > -1)
        divid = 'NewsLetter';

    if (divid != null)
    {
        var div = parent.document.getElementById(divid);
        if (div != null)
        {
            div.style.top = 0;
            div.style.display = 'block';
        }
    }
  }
}

function ApplySifr()
{
    if(typeof sIFR == "function"){
      var RelUrl = GetSiteCollectionUrl();
      sIFR.replaceElement(named({sSelector:"h1", sFlashSrc:RelUrl+"/Style%20Library/swf/sifr_heavy_noBg.swf",            sColor:"#FFFFFF", sLinkColor:"#FFFFFF", sHoverColor:"#CCCCCC", sBgColor:"#FFFFFF", nPaddingTop:0, nPaddingRight:0, nPaddingBottom:0, nPaddingLeft:0, sFlashVars:"textalign=left&offsetLeft=0&offsetTop=0", sWmode:"transparent"}));
      sIFR.replaceElement(named({sSelector:"h2", sFlashSrc:RelUrl+"/Style%20Library/swf/sifr_heavy_noBg.swf",      sColor:"#FFFFFF", sLinkColor:"#FFFFFF", sHoverColor:"#CCCCCC", sBgColor:"#141414", nPaddingTop:0, nPaddingRight:0, nPaddingBottom:0, nPaddingLeft:0, sFlashVars:"textalign=left&offsetLeft=0&offsetTop=0", sWmode:"transparent"}));
      sIFR.replaceElement(named({sSelector:"h3", sFlashSrc:RelUrl+"/Style%20Library/swf/sifr.swf",            sColor:"#e21502", sLinkColor:"#e21502", sHoverColor:"#e21502", sBgColor:"#141414", nPaddingTop:0, nPaddingRight:0, nPaddingBottom:0, nPaddingLeft:0, sFlashVars:"textalign=left&offsetLeft=0&offsetTop=0", sWmode:"transparent"}));
      sIFR.replaceElement(named({sSelector:"h4", sFlashSrc:RelUrl+"/Style%20Library/swf/sifr_heavy.swf",      sColor:"#e21502", sLinkColor:"#e21502", sHoverColor:"#e21502", sBgColor:"#141414", nPaddingTop:0, nPaddingRight:0, nPaddingBottom:0, nPaddingLeft:0, sFlashVars:"textalign=left&offsetLeft=0&offsetTop=0", sWmode:"transparent"}));
      sIFR.replaceElement(named({sSelector:"h5", sFlashSrc:RelUrl+"/Style%20Library/swf/sifr_heavy_noBg.swf", sColor:"#e21502", sLinkColor:"#e21502", sHoverColor:"#e21502", sBgColor:"#FFFFFF", nPaddingTop:0, nPaddingRight:0, nPaddingBottom:0, nPaddingLeft:0, sFlashVars:"textalign=left&offsetLeft=0&offsetTop=0", sWmode:"transparent"}));
      sIFR.replaceElement(named({sSelector:"h6", sFlashSrc:RelUrl+"/Style%20Library/swf/sifr_heavy_noBg.swf", sColor:"#e21502", sLinkColor:"#e21502", sHoverColor:"#e21502", sBgColor:"#FFFFFF", nPaddingTop:0, nPaddingRight:0, nPaddingBottom:0, nPaddingLeft:0, sFlashVars:"textalign=left&offsetLeft=0&offsetTop=0", sWmode:"transparent"}));
      //sIFR.replaceElement(named({sSelector:"#mainTitle", sFlashSrc:RelUrl+"/Style%20Library/swf/sifr_heavy_noBg.swf", sColor:"#e21502", sLinkColor:"#e21502", sHoverColor:"#e21502", sBgColor:"#FFFFFF", nPaddingTop:0, nPaddingRight:0, nPaddingBottom:0, nPaddingLeft:0, sFlashVars:"textalign=left&offsetLeft=0&offsetTop=0", sWmode:"transparent"}));
      //sIFR.replaceElement(named({sSelector:"#subTitle", sFlashSrc:RelUrl+"/Style%20Library/swf/sifr_heavy_noBg.swf",  sColor:"#e21502", sLinkColor:"#e21502", sHoverColor:"#e21502", sBgColor:"#FFFFFF", nPaddingTop:0, nPaddingRight:0, nPaddingBottom:0, nPaddingLeft:0, sFlashVars:"textalign=left&offsetLeft=0&offsetTop=0", sWmode:"transparent"}));
    }
}
function ApplyBlogSifr()
{
    if(typeof sIFR == "function"){
      var RelUrl = GetSiteCollectionUrl();
      sIFR.replaceElement(named({sSelector:"h1", sFlashSrc:RelUrl+"/Style%20Library/swf/sifr.swf",            sColor:"#FFFFFF", sLinkColor:"#FFFFFF", sHoverColor:"#CCCCCC", sBgColor:"#FFFFFF", nPaddingTop:0, nPaddingRight:0, nPaddingBottom:0, nPaddingLeft:0, sFlashVars:"textalign=left&offsetLeft=0&offsetTop=0", sWmode:"transparent"}));
      sIFR.replaceElement(named({sSelector:"h2", sFlashSrc:RelUrl+"/Style%20Library/swf/sifr_heavy.swf",      sColor:"#FFFFFF", sLinkColor:"#FFFFFF", sHoverColor:"#CCCCCC", sBgColor:"#141414", nPaddingTop:0, nPaddingRight:0, nPaddingBottom:0, nPaddingLeft:0, sFlashVars:"textalign=left&offsetLeft=0&offsetTop=0", sWmode:"transparent"}));
      sIFR.replaceElement(named({sSelector:"h5", sFlashSrc:RelUrl+"/Style%20Library/swf/sifr_heavy_noBg.swf", sColor:"#e21502", sLinkColor:"#e21502", sHoverColor:"#e21502", sBgColor:"#FFFFFF", nPaddingTop:0, nPaddingRight:0, nPaddingBottom:0, nPaddingLeft:0, sFlashVars:"textalign=left&offsetLeft=0&offsetTop=0", sWmode:"transparent"}));
      sIFR.replaceElement(named({sSelector:"h6", sFlashSrc:RelUrl+"/Style%20Library/swf/sifr_heavy_noBg.swf", sColor:"#e21502", sLinkColor:"#e21502", sHoverColor:"#e21502", sBgColor:"#FFFFFF", nPaddingTop:0, nPaddingRight:0, nPaddingBottom:0, nPaddingLeft:0, sFlashVars:"textalign=left&offsetLeft=0&offsetTop=0", sWmode:"transparent"}));
      //sIFR.replaceElement(named({sSelector:"#mainTitle", sFlashSrc:RelUrl+"/Style%20Library/swf/sifr_heavy_noBg.swf", sColor:"#e21502", sLinkColor:"#e21502", sHoverColor:"#e21502", sBgColor:"#FFFFFF", nPaddingTop:0, nPaddingRight:0, nPaddingBottom:0, nPaddingLeft:0, sFlashVars:"textalign=left&offsetLeft=0&offsetTop=0", sWmode:"transparent"}));
      //sIFR.replaceElement(named({sSelector:"#subTitle", sFlashSrc:RelUrl+"/Style%20Library/swf/sifr_heavy_noBg.swf",  sColor:"#e21502", sLinkColor:"#e21502", sHoverColor:"#e21502", sBgColor:"#FFFFFF", nPaddingTop:0, nPaddingRight:0, nPaddingBottom:0, nPaddingLeft:0, sFlashVars:"textalign=left&offsetLeft=0&offsetTop=0", sWmode:"transparent"}));
    }
}
// *****************************************************


// **********   PodWrapperWebPart FUNCTIONS   **********
var oldValue = null;
function UpdatePositions(tableid, dropdownid)
{
    var table = document.getElementById(tableid);
    var ddlClicked = document.getElementById(dropdownid);
    var dropdowns = table.getElementsByTagName('select');

    if (oldValue == null || table == null || ddlClicked == null)
        return;

    var newValue = ddlClicked.value;
    var ascending = (oldValue < newValue);
    //alert('old: ' + oldValue + '_new: ' + newValue + '_delta: ' + delta + '_ddls: ' + dropdowns.length);

    for (var i=0; i<dropdowns.length; i++)
    {
        if (dropdowns[i].id != dropdownid)
        {
            //alert('before: ' + dropdowns[i].value);
            if (ascending && dropdowns[i].value >= oldValue && dropdowns[i].value <= newValue)
            {
                dropdowns[i].selectedIndex = (dropdowns[i].selectedIndex - 1);
            }
            else if (!ascending && (dropdowns[i].value >= newValue && dropdowns[i].value <= oldValue))
            {
                dropdowns[i].selectedIndex = (dropdowns[i].selectedIndex + 1);
            }
            //alert('after: ' + dropdowns[i].value);
        }
    }
}
// *****************************************************


// **********   Teams FUNCTIONS   **********
function GestPanel(PanelID)
{
  if(document.getElementById(PanelID).style.display == "none")
    document.getElementById(PanelID).style.display = "block";
  else
    CloseAllPanel();
}

function DrivFillPanel(panelid, drivpanelid)
{
  // In IE, getElementById is case insensitive;
  // in Firefox, is case SENSITIVE
  drivpanelid = drivpanelid.toUpperCase();
  //alert(drivpanelid);

  var panel = document.getElementById(panelid);
  var drivpanel = document.getElementById(drivpanelid);

  if (panel != null && drivpanel != null)
  {
    if (panel.innerHTML == '')
      panel.innerHTML = drivpanel.innerHTML;
  }
}
// *****************************************************


// **********   Forms FUNCTIONS   **********
function OpenPopup(url, params)
{
  window.open(url,null,params);
}

function CloseForm(divid)
{
  var div = document.getElementById(divid);
  if (div != null)
      div.style.display = 'none';
}

function SetBG(tagid, imageName)
{
    var tag = document.getElementById(tagid);
    if (tag != null)
        tag.style.background = 'url(' + GetSiteCollectionUrl() + '/SiteCollectionImages/' + imageName + ') repeat-x';
}

function SetBlogImageUrl(tagid)
{
    var tag = document.getElementById(tagid);
    if (tag != null)
        tag.style.background = 'url(' + GetCMSSiteUrl() + '/PublishingImages/blog_preview_image.jpg) repeat-x';
}

function GetSiteCollectionUrl()
{
    var cmsUrl = GetCMSSiteUrl();
    return cmsUrl.substr(0, cmsUrl.toLowerCase().indexOf('/cms', 0));
}

function GetCMSSiteUrl()
{
    //alert(window.location.pathname);
    var parts = window.location.pathname.split('/');
    //alert(parts.length);
    var cmsSiteUrl = '';

    for (var i=0; i<parts.length; i++)
    {
        if (parts[i].length > 0)
        {
            cmsSiteUrl += '/' + parts[i];
            if (parts[i].toLowerCase().indexOf('cms') == 0)
                break;
        }
    }

    //alert(cmsSiteUrl);
    return cmsSiteUrl;
}

function ToggleForm(divid)
{
  var div = document.getElementById(divid);
  if (div != null)
  {
    if (div.style.display == null || div.style.display == '' || div.style.display == 'none')
    {
        // reload jsp form
        var frameId = divid + 'Frame';
        var formUrl = GetCMSSiteUrl();
        if (divid == 'ContactUs')
//            formUrl += '/Pages/ContactUs.html';
			formUrl = '../../ContactUs.html';
        else if (divid == 'TestDrive')
//            formUrl += '/Pages/TestDrive.aspx';
            formUrl = '../../TestDrive.html';
        else if (divid == 'NewsLetter')
//            formUrl += '/Pages/NewsLetter.aspx';
            formUrl = '../../NewsLetter.html';

        var sendFrame = GetFrame(document, frameId);
        if (sendFrame != null && formUrl != null)
        {
            //alert(sendFrame.location.href);
            //if (sendFrame.location.href == null || sendFrame.location.href == '' || sendFrame.location.href == 'about:blank')
//			alert(formUrl);
                sendFrame.location.href = formUrl;
            //else
            //    sendFrame.location.reload(true);
        }

        //div.style.display = 'block';
    }
    else
    {
        div.style.display = 'none';
    }
  }
}

function GetFrame(doc, frameId)
{
    if (doc == null || frameId == null)
        return null;
    else if (doc.frames != null)
        return doc.frames[frameId];
    else
        return doc.getElementById(frameId).contentWindow;
}
// *****************************************************


// **********   Rollup Images FUNCTIONS   **********
function DrivMOver(imgid)
{
  var img = document.getElementById(imgid);
  if (img != null)
    img.src = img.src.replace('Off.','On.').replace('off.','on.').replace('Click.','On.').replace('click.','on.');
}

function DrivMOut(imgid)
{
  var img = document.getElementById(imgid);
  if (img != null)
    img.src = img.src.replace('On.','Off.').replace('on.','off.').replace('Click.','Off.').replace('click.','off.');
}

function DrivMClick(imgid)
{
  var img = document.getElementById(imgid);
  if (img != null)
    img.src = img.src.replace('On.','Click.').replace('on.','click.');
}
// *****************************************************


// **********   CheckBox Client-Validation FUNCTION   **********
function ValChk(chkid, chkValId)
{
    var chk = document.getElementById(chkid);
    if (chk != null)
    {
        var chkVal = document.getElementById(chkValId);
        if (chkVal != null)
            chkVal.style.display = (chk.checked ? 'none' : 'block');

        return chk.checked;
    }
    return true;
}
// *****************************************************
