﻿// JScript File
function ajaxContentAds(adURL)
  {
  var xmlHttp;
  var val;
  
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      try
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      catch (e)
        {
        alert("Your browser does not support AJAX!");
        return false;
        }
      }
    }
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState==4)
        {
       
        document.getElementById("rightContentSubImageText").innerHTML = xmlHttp.responseText;
        }
      }
    xmlHttp.open("GET",adURL,true);
    xmlHttp.send(null);
    return false;
  }
  function ajaxSearchAds(adURL, adId)
  {
  var xmlHttp;
  var val;
  
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      try
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      catch (e)
        {
        alert("Your browser does not support AJAX!");
        return false;
        }
      }
    }
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState==4)
        {
       
        document.getElementById(adId).innerHTML = xmlHttp.responseText;
        }
      }
    xmlHttp.open("GET",adURL,true);
    xmlHttp.send(null);
    return false;
  }
  var currentLgThumb = 1;
  var prev = "";
  var oldLg = 1;
  var count = 1;
  var x = 1;
  var position = 1;
  var thumb1position = "";
  var img1 = 1;
  var img2 = 2;
  var img3 = 3;
  var img4 = 4;
  var img5 = 5;
  var img6 = 6;
  var img7 = 7;
  var img8 = 8;
  var img9 = 9;
  function showLargeThumbnail(img,sender) {
    //reset the default image values from the function if the original image no longer is in that field
    if (sender == "bikeSmallImageTop" && img2 != 2) {
        img = img2;
    }
    if (sender == "bikeSmallImageBottom" && img3 != 3) {
        img = img3;
    }
    if (sender == "Row1Left" && img4 != 4) {
        img = img4;
    }
    if (sender == "Row1Middle" && img5 != 5) {
        img = img5;
    }
    if (sender == "Row1Right" && img6 != 6) {
        img = img6;
    }
    if (sender == "Row2Left" && img7 != 7) {
        img = img7;
    }
    if (sender == "Row2Middle" && img8 != 8) {
        img = img8;
    }
    if (sender == "Row2Right" && img9 != 9) {
        img = img9;
    }
    //set the placeholder values so we know where each image is in the proper place
    switch (sender) {
        case "bikeSmallImageTop":
            img2 = currentLgThumb;
            break;
        case "bikeSmallImageBottom":
            img3 = currentLgThumb;
            break;
        case "Row1Left":
            img4 = currentLgThumb;
            break;    
        case "Row1Middle":
            img5 = currentLgThumb;
            break;
        case "Row1Right":
            img6 = currentLgThumb;
            break;
        case "Row2Left":
            img7 = currentLgThumb;
            break;
        case "Row2Middle":
            img8 = currentLgThumb;
            break;
        case "Row2Right":
            img9 = currentLgThumb;
            break;
    }
    if (prev == sender && count == 1) { //if the user clicks on the same image we just want the two to swap
        img = oldLg;
        count += 1;
        document.getElementById(sender).src = "Images/Image" + currentLgThumb + "ThumbSm.jpg";
        document.getElementById('bikeLargeImage').src = "Images/Image" + img + "ThumbLg.jpg";
        document.getElementById('bikeLargeImageLink').href = "Images/Image" + img + ".jpg";
    }
    else { //if the user clicks on a new image
        oldLg = currentLgThumb;
        count = 1;
        document.getElementById(sender).src = "Images/Image" + currentLgThumb + "ThumbSm.jpg";
        document.getElementById('bikeLargeImage').src = "Images/Image" + img + "ThumbLg.jpg";
        document.getElementById('bikeLargeImageLink').href = "Images/Image" + img + ".jpg";
    }
    currentLgThumb = img;
    prev = sender;
    x += 1;
  }
  function showLargeThumbnailPreview(img,sender,path) {
    //reset the default image values from the function if the original image no longer is in that field
    if (sender == "bikeSmallImageTop" && img2 != 2) {
        img = img2;
    }
    if (sender == "bikeSmallImageBottom" && img3 != 3) {
        img = img3;
    }
    if (sender == "Row1Left" && img4 != 4) {
        img = img4;
    }
    if (sender == "Row1Middle" && img5 != 5) {
        img = img5;
    }
    if (sender == "Row1Right" && img6 != 6) {
        img = img6;
    }
    if (sender == "Row2Left" && img7 != 7) {
        img = img7;
    }
    if (sender == "Row2Middle" && img8 != 8) {
        img = img8;
    }
    if (sender == "Row2Right" && img9 != 9) {
        img = img9;
    }
    //set the placeholder values so we know where each image is in the proper place
    switch (sender) {
        case "bikeSmallImageTop":
            img2 = currentLgThumb;
            break;
        case "bikeSmallImageBottom":
            img3 = currentLgThumb;
            break;
        case "Row1Left":
            img4 = currentLgThumb;
            break;    
        case "Row1Middle":
            img5 = currentLgThumb;
            break;
        case "Row1Right":
            img6 = currentLgThumb;
            break;
        case "Row2Left":
            img7 = currentLgThumb;
            break;
        case "Row2Middle":
            img8 = currentLgThumb;
            break;
        case "Row2Right":
            img9 = currentLgThumb;
            break;
    }
    if (prev == sender && count == 1) { //if the user clicks on the same image we just want the two to swap
        img = oldLg;
        count += 1;
        document.getElementById(sender).src = path + "Images/Image" + currentLgThumb + "ThumbSm.jpg";
        document.getElementById('bikeLargeImage').src = path + "Images/Image" + img + "ThumbLg.jpg";
        document.getElementById('bikeLargeImageLink').href = path + "Images/Image" + img + ".jpg";
    }
    else { //if the user clicks on a new image
        oldLg = currentLgThumb;
        count = 1;
        document.getElementById(sender).src = path + "Images/Image" + currentLgThumb + "ThumbSm.jpg";
        document.getElementById('bikeLargeImage').src = path + "Images/Image" + img + "ThumbLg.jpg";
        document.getElementById('bikeLargeImageLink').href = path + "Images/Image" + img + ".jpg";
    }
    currentLgThumb = img;
    prev = sender;
    x += 1;
  }
  function startFade(id) {
        var funcall = "opacity('" + id + "', 100, 0, 1000)";
        setTimeout(funcall, 1000);
    }
    function opacity(id, opacStart, opacEnd, millisec) {
        //speed for each frame
        var speed = Math.round(millisec / 100);
        var timer = 0;

        //determine the direction for the blending, if start and end are the same nothing happens
        if(opacStart > opacEnd) {
            for(i = opacStart; i >= opacEnd; i--) {
                setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
                timer++;
            }
        } else if(opacStart < opacEnd) {
            for(i = opacStart; i <= opacEnd; i++)
                {
                setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
                timer++;
            }
        }
        //document.getElementById(id).style.display = "none";
    } 
    //change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object = "filter:alpha(opacity=" + opacity + ");";
    if (opacity == 0) {
        document.getElementById(id).style.display = "none";
    }
}
        
        function createSearch() {
            var strQS = "?type=search"
            if (document.getElementById('ddrYEar').options[document.getElementById('ddrYEar').selectedIndex].text != "") {
                strQS += "&mYear=" + document.getElementById('ddrYEar').options[document.getElementById('ddrYEar').selectedIndex].text;
            }
            if (document.getElementById('ddrManufacturer').options[document.getElementById('ddrManufacturer').selectedIndex].text != "") {
                strQS += "&mManufacturer=" + document.getElementById('ddrManufacturer').options[document.getElementById('ddrManufacturer').selectedIndex].value;
            }
            if (document.getElementById('keywordsTextbox').value != "") {
                strQS += "&mKeywords=" + document.getElementById('keywordsTextbox').value;
            } 
            if (document.getElementById('zipCodeTextbox').value != "") {
                strQS += "&mZipCode=" + document.getElementById('zipCodeTextbox').value;
            }
            if (document.getElementById('ddrRadius').options[document.getElementById('ddrRadius').selectedIndex].text != "") {
                strQS += "&mRadius=" + document.getElementById('ddrRadius').options[document.getElementById('ddrRadius').selectedIndex].value;
            }
            window.location = "/Search/Search.aspx" + strQS;
        }