function toggleDiv(id,flagit) {
  if (flagit=="1"){
    if (document.layers) document.layers[''+id+''].visibility = "show"
    else if (document.all) document.all[''+id+''].style.visibility = "visible"
    else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "visible"
  }
  else
  if (flagit=="0"){
    if (document.layers) document.layers[''+id+''].visibility = "hide"
    else if (document.all) document.all[''+id+''].style.visibility = "hidden"
    else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "hidden"
  }
}

/********************************** NEWSLETTER SUBSCRIPTION ***********************************/
function subscribe() {
  var join_field = jQuery("input#j_email").val();
  var sub_url;
  if(jQuery("input[@name=signup][@checked]").val() == 'off') {
    sub_url = '/select.php?select_id=newsletter_subscribe&act=unsubscribe&email='+join_field;
  } else {
    sub_url = '/select.php?select_id=newsletter_subscribe&act=subscribe&email='+join_field;
  }
  jQuery("form#newsletterform").load(sub_url);
}


function paging(page) {
  if (jQuery("#pagin_numbers_news").is('*') ){
    razd = "_news";
  }else if (jQuery("#pagin_numbers").is('*')) {
    razd = '';
  }
  var last_page = GetPages(2,razd);
  var current_page = parseInt(GetPages(0,razd));
  var sub_url;
  if (razd == "_news") {
    dvid = 'news_page';
    sub_url = "/select.php?select_id=news&pg=" + current_page;
  }else{
    dvid = 'cars_list';
    sub_url = "/select.php?select_id=cars&pg=" + current_page;
  }
  if (page == 'first') {
    current_page = 1;
  } else if (page == 'prev') {
    current_page-- ;
  } else if (page == 'next') {
    current_page++;
  } else if (page == 'last') {
    current_page = last_page;
  }
  //	alert(sub_url);
  jQuery.get(sub_url, function(html) {
    jQuery("div#"+dvid).html(html);
    SetPages(current_page,last_page,razd);
  });
}
function GetPages(n,razd) {
  if (jQuery('#pagin_numbers'+razd)) {
    gp_content = jQuery('#pagin_numbers'+razd).html().split(' ');
    return gp_content[n];
  }
}
jQuery(document).ready(
function initPages() {
  var razd;
  var suburl;
  if (jQuery("#pagin_numbers_news").is('*') ){
    razd = '_news';
    suburl = "/select.php?select_id=news&max=1";
  }else if (jQuery("#pagin_numbers").is('*')) {
    razd = '';
    suburl = "/select.php?select_id=cars&max=1";
  }
  if (jQuery('#pagin_numbers'+razd).html()) {
    var gp_content = jQuery('#pagin_numbers'+razd).html().split(' ');
    if (gp_content[0] > 0 && gp_content[2] > 0) {

    } else {
      jQuery.get(suburl, function(txt) {
        SetPages(1,txt,razd);
      }) ;
    }
  }
}
);
jQuery(document).ready(
function () {
  LoadPromo();
  LoadPromoSecond();
});
function LoadPromo() {
  jQuery.ajax({
    type: "GET",
    url: "/select.php",
    data: "select_id=showroom",
    beforeSend: function() {
      jQuery("div#fadecontainer").fadeOut();
      //			jQuery("div#showroom").html('<div class="loading"><img src="/images/loading_1.gif" /></div>');
    },
    success: function(msg){
      jQuery("div#showroom").html(msg);
      jQuery("div#fadecontainer").fadeIn();
      setTimeout('LoadPromo()',20000);
    }
  });
}
function LoadPromoSecond() {
  jQuery.ajax({
    type: "GET",
    url: "/select.php",
    data: "select_id=showroom_second_had",
    beforeSend: function() {
      jQuery("div#fade_second_hand_image").fadeOut();
      //			jQuery("div#showroom").html('<div class="loading"><img src="/images/loading_1.gif" /></div>');
    },
    success: function(msg){
      jQuery("div#h_second").html(msg);
      jQuery("div#fade_second_hand_image").fadeIn();
      setTimeout('LoadPromoSecond()',20000);
    }
  });
}
function SetPages(a,b,razd) {
  if (jQuery('#pagin_numbers'+razd)) {
    jQuery('#pagin_numbers'+razd).html(a + ' / ' + b);
  }
  if (a <= 1) {
    jQuery("#left_2").css({display:"none"});
    jQuery('#left_1').css({display:"none"});
  } else if (a > 1) {
    jQuery('#left_2').css({display:"inline"});
    jQuery('#left_1').css({display:"inline"});
  }
  if (a >= b) {
    jQuery('#right_2').css({display:"none"});
    jQuery('#right_1').css({display:"none"});
  } else if (a < b) {
    jQuery('#right_2').css({display:"inline"});
    jQuery('#right_1').css({display:"inline"});
  }
}
function carshow(brand) {
  sub_url = "/select.php?select_id=cars&brand=" + brand;
  //	alert(sub_url);
  jQuery.get(sub_url, function(html) {
    if (jQuery("div#cars_list").html()) {
      jQuery("div#cars_list").html(html);
      jQuery.get("/select.php?select_id=cars&max=1", function(txt) {
        SetPages(1,txt,'');
      }) ;
    }
  });
}
function orderBy(opro) {
  sub_url = "/select.php?select_id=cars&pg=1&order="+opro;
  //	alert(sub_url);
  var cur_class = jQuery("#ord_"+opro).attr("class");
  jQuery.get(sub_url, function(html) {
    jQuery("div#cars_list").html(html);
    jQuery.get("/select.php?select_id=cars&max=1", function(txt) {
      SetPages(1,txt,'');
    }) ;

    if (cur_class == "sortUp") {
      cur_class = "sortDown";
    } else {
      cur_class = "sortUp";
    }
    jQuery("#used_cars_listing th").each(function (index) {
      if (index > 0)
      jQuery(this).removeClass();
    });
    jQuery("#ord_"+opro).addClass(cur_class);
  });
}

navHover = function() {
  var lis =
  document.getElementById("main-menu").getElementsByTagName("LI");
  for (var i=0; i<lis.length; i++) {
    lis[i].onmouseover=function() {
      this.className+=" iehover";
    }
    lis[i].onmouseout=function() {
      this.className=this.className.replace(new RegExp(" iehover\\b"),
      "");
    }
  }
}
if (window.attachEvent) window.attachEvent("onload", navHover);