$.fn.imageLoad = function(fn){
    this.load(fn);
    this.each( function() {
        if ( this.complete && this.naturalWidth !== 0 ) {
            $(this).trigger('load');
        }
    });
}


$(document).ready(function () {
    //this code is executed when the page's onload event fires

    // header menu

    $('#header-menu>li').eq(0).addClass('first');
    $('#header-menu>li').eq(1).addClass('second');

    if ($('#products-menu').size() > 0) {
        var top_item = $('#header-menu>li').eq(0);
        top_item.addClass('products');

        top_item.append('<span class="border">&nbsp;</span>');

        var w = top_item.outerWidth() - 2;

        if ($.browser.msie) {
            w += 1;
        }

        $('.border', top_item).css('width', w + 'px');
        $('.border', top_item).css('display', 'block');


        if ($('#products-menu li ul li').size() > 0) {
            $('.border', top_item).css('background-color', '#1F4C9D');
        }
    }

    if ($('#header-menu li.current ul').size() > 0) {
        $('#header-menu').height(77);

        $('#header-menu li.current ul').css('display', 'block');

        var w = 0;

        $('#header-menu li.current ul li').each(function (index, item) {
            var lw = $('a', item).outerWidth() + 1;
            $(item).width(lw);
            w += lw;
        });

        $('#header-menu li.current ul').width(w);

        var top_item = $('#header-menu li.current');

        top_item.append('<span class="border">&nbsp;</span>');

        var w_i = top_item.outerWidth() - 1;

        $('.border', top_item).css('width', w_i + 'px');
        $('.border', top_item).css('display', 'block');

        var pos_x = top_item.offset().left - $('#header-menu').offset().left;

        var margin_x = (w - w_i) / 2;
        
        if (pos_x + w_i/2 - w/2 <= 0) {
          margin_x = pos_x;
        } else if (pos_x + w_i/2 + w/2 >= 900) {
          margin_x = w/2 - 4;
          if($.browser.msie) {
            margin_x += 12;
          }
        }

        $('#header-menu li.current ul').css('margin-left', -margin_x + 'px');
    }


    // fix teasers height

    // $('#contents .teaser').css('border-top', '1px solid red');

    var vbox = $('#contents .vbox');
    var vbox_left, vbox_right;

    if (vbox.size() == 3) {
        $('#contents .vbox').each(function (index, item) {
            if (index == 1) {
                vbox_left = item;
            } else if (index == 2) {
                vbox_right = item;
                return false;
            }
        });

        var teasers_left = $('.teaser', vbox_left);
        var teasers_right = $('.teaser', vbox_right);

        var len = Math.min(teasers_left.size(), teasers_right.size());

        var diff;
        for (var i = 0; i < len; i++) {
            diff = $(teasers_left[i]).outerHeight() - $(teasers_right[i]).outerHeight();
            if (diff > 0) {
                $(teasers_right[i]).css('margin-bottom', (parseInt($(teasers_right[i]).css('margin-bottom').replace('px', '')) + diff) + 'px');
            } else if (diff < 0) {
                $(teasers_left[i]).css('margin-bottom', (parseInt($(teasers_left[i]).css('margin-bottom').replace('px', '')) - diff) + 'px');
            }
        }
    }

    // product gallery

    $('#page-contents.products .gallery .slides li img').imageLoad(function (e) {
        var img = $(e.target);
        if (img.height() < 206) {
            img.css('margin-top', (206 - img.height()) / 2 + 'px');
        }
    });

    $('#page-contents.products .gallery .slides').cycle({
        fx: 'fade',
        pager: '#page-contents.products .gallery .thumbs',
        pagerAnchorBuilder: function (idx, slide) {
            return '#page-contents.products .gallery .thumbs li:eq(' + idx + ') a';
        }
    });

    $('#page-contents.products .gallery .slides').cycle('pause');

    // product tables
    var max_height
    var cols;
    var pad;
    $('.specifications .table-row').each(function (index, item) {
        max_height = 0;
        cols = $('.table-col', item);

        cols.each(function (index, item) {
            if ($(item).height() > max_height) {
                max_height = $(item).height();
            }
        });

        cols.each(function (index, item) {
            if ($(item).height() < max_height) {
                pad = (max_height - $(item).height()) / 2;
                $(item).css('padding-top', pad + 'px');
                $(item).css('padding-bottom', pad + 'px');
            }
        });
    });



    // fix footer columns height

    var left = $('#footer-left-col');
    var middle = $('#footer-middle-col');
    var right = $('#footer-right-col');
    var f_height = Math.max(left.height(), middle.height(), right.height());
    left.height(f_height);
    middle.height(f_height);
    right.height(f_height);

    // world map buttons
 // world map buttons
    if ($('#dealer-locator-button').parent().hasClass('selected')) {
        document.getElementById('currentTabAux').value = 'dealer-locator-button';
        $('#tabs .wrap .selected-tab .selected-tab-inner').html($('#dealer-locator-button').parent().html());
        $('#tabs .wrap .selected-tab').css('width', ($('#dealer-locator-button').parent().outerWidth() + 14) + 'px');
        $('#tabs .wrap .selected-tab').css('left', ($('#dealer-locator-button').parent().position().left - 7) + 'px');
        $('#tabs .wrap .selected-tab').css('display', 'block');
    }
    if ($('#worldmap-button').parent().hasClass('selected')) {
        document.getElementById('currentTabAux').value = 'worldmap-button';
        $('#tabs .wrap .selected-tab .selected-tab-inner').html($('#worldmap-button').parent().html());
        $('#tabs .wrap .selected-tab').css('width', ($('#worldmap-button').parent().outerWidth() + 14) + 'px');
        $('#tabs .wrap .selected-tab').css('left', ($('#worldmap-button').parent().position().left - 7) + 'px');
        $('#tabs .wrap .selected-tab').css('display', 'block');
    }

    $('#tabs a').click(function () {
	if ($(this).attr('id') != document.getElementById('currentTabAux').value) {
            document.getElementById('currentTabAux').value = $(this).attr('id');
            if ($(this).parent().hasClass('selected')) {
                $('#tabs .title').removeClass('selected');
                $('#tabs .wrap .selected-tab').css('display', 'none');
            } else {
                if ($(this).parent() != null && $(this).parent().position() != null) {
                    $('#tabs .title').removeClass('selected');
                    $(this).parent().addClass('selected');
                    $('#tabs .title').removeClass('selected');
                    $('#tabs .wrap .selected-tab .selected-tab-inner').html($(this).parent().html());
                    $('#tabs .wrap .selected-tab').css('width', ($(this).parent().outerWidth() + 14) + 'px');
                    if ($(this).parent() != null && $(this).parent().position() != null && $(this).parent().position().left != null) { $('#tabs .wrap .selected-tab').css('left', ($(this).parent().position().left - 7) + 'px'); }
                    $('#tabs .wrap .selected-tab').css('display', 'block');
                }
            }

        }
        return false;
    });
    /*$(".dealer-locator-button").click(function () {
        if ($.browser.msie) {
            $('#dealer-locator-content').height(600);
        }
        if (document.getElementById("active").value == "0") {
            if (google.loader.ClientLocation != null) {

                var yourLocation = google.loader.ClientLocation.latitude + '%2C'
                                    + google.loader.ClientLocation.longitude;
            }
            var url = '/sitecore%20modules/dealerlocator/alto/Function.ExcelDealerLocator.Google.aspx'; //?location=' + yourLocation;
            document.getElementById("homepage-map-canvas").innerHTML = '<iframe src="' + url + '" scrolling="no" width="100%" height="935" border="0" frameborder="0"  id="dealer_iframe" ></iframe>';
            document.getElementById("active").value = "1";


            $('#homepage-map-canvas iframe').load(function () {
                $('#dealer-locator-content').slideToggle();
                $('#homepage-map-canvas iframe').unbind('load');
            });
        }
        else {
            $(".homepage-map-canvas").innerHTML = "";
            document.getElementById("active").value = "0";
            $('#dealer-locator-content').slideToggle();
        }


    });
*/
   /* $(".worldmap-button").click(function () {
      
	 if ($.browser.msie) {
            $('#worldmap-content').height(430);
        }
	  if (document.getElementById("active").value == "0") {
          
            var url = '/Global/Footer/GoogleDealerLocator.aspx'; //?location=' + yourLocation;
            document.getElementById("homepage-map-canvas").innerHTML = '<iframe src="' + url + '" scrolling="no" width="100%" height="900" border="0" frameborder="0"  id="dealer_iframe" ></iframe>';
            document.getElementById("active").value = "1";


            $('#homepage-map-canvas iframe').load(function () {
                $('#worldmap-content').slideToggle();
                $('#homepage-map-canvas iframe').unbind('load');
            });
        }
        else {
		    //document.getElementById("worldmap-content").style.height="0px";
            $(".homepage-map-canvas").innerHTML = "";
            document.getElementById("active").value = "0";
            $('#worldmap-content').slideToggle();
        }
    });
    
    */
    var uid = 0;
    var max_in_list = 10;
    var line_height = 18;
    var scroll_lines = 5;
    $('.boxBody3 .countryList').each(function(index, item) {
      if($('li', item).size() > max_in_list) {
      
        var scrolling = false;
      
        var item_id = 'country-int-id-' + uid;
        uid++;
        
        $(item).attr('id', item_id);
        
        var fix_links = function(e) {
          var ul_id = $(e.currentTarget).attr('id').replace('a-', '').replace('b-', '');
          var a = $('#a-' + ul_id);
          var b = $('#b-' + ul_id);
          var top = $('#' + ul_id).css('margin-top').replace('px', '') * 1;
          
          if(top < 0) {
            b.removeClass('disabled');
          } else {
            b.addClass('disabled');
          }
          
          if(top > (Math.round($('#' + ul_id).outerHeight() / 18) - max_in_list) * -line_height) {
            a.removeClass('disabled');
          } else {
            a.addClass('disabled');
          }
        }
        
        var more = $('<div class="boxBody3"></div>');
        var more_a = $('<a id="a-' + item_id + '" href="#" class="more">&nbsp;</a>');
        more.append(more_a);
        
        var scroll_line_more = function(scroll, ul_id) {
          var top = $('#' + ul_id).css('margin-top').replace('px', '') - scroll;
          
          if(top > (Math.round($('#' + ul_id).outerHeight() / 18) - max_in_list) * -line_height) {
            return line_height;
          }
          
          return 0;
        }
        
        more_a.click(function(e) {
          if(scrolling) {
            return false;
          }
          
          var scroll = 0;
          var ul_id = $(e.currentTarget).attr('id').replace('a-', '');
          
          for(var i = 0; i < scroll_lines; i++) {
            scroll += scroll_line_more(scroll, ul_id);
          }
          
          scrolling = true;
          $('#' + ul_id).animate({'margin-top': '-=' + scroll}, 500, function() {
            fix_links(e);
            scrolling = false;
          });
          
          fix_links(e);
          
          return false;
        });
        
        var less = $('<div class="boxBody3"></div>');
        var less_a = $('<a id="b-' + item_id + '" href="#" class="less disabled">&nbsp;</a>');
        less.append(less_a);
        
        var scroll_line_less = function(scroll, ul_id) {
          var top = $('#' + ul_id).css('margin-top').replace('px', '') * 1 + scroll;
                   
          if(top < 0) {
            return line_height;
          }
          
          return 0;
        }
        
        less_a.click(function(e) {
          if(scrolling) {
            return false;
          }
          
          var scroll = 0;
          var ul_id = $(e.currentTarget).attr('id').replace('b-', '');
          
          for(var i = 0; i < scroll_lines; i++) {
            scroll += scroll_line_less(scroll, ul_id);
          }
          
          scrolling = true;
          $('#' + ul_id).animate({'margin-top': '+=' + scroll}, 500, function() {
            fix_links(e);
            scrolling = false;
          });
          
          return false;
        });
        
        $(item).parent().after(more);
        $(item).parent().before(less);
      }
    });

    $('.clear-field').clearField();
});

function ShowDealer() {
 
    if ($.browser.msie) {
        $('#tab-content').height(600);
    }
   // alert('dealer al=' + document.getElementById("active-left").value + "  " + document.getElementById('currentTab').value + " ar= " + document.getElementById("active-right").value);
    if (document.getElementById("active-left").value == "0" ) {
        if (google.loader.ClientLocation != null) {

            var yourLocation = google.loader.ClientLocation.latitude + '%2C'
        + google.loader.ClientLocation.longitude;
        }
        var url = '/sitecore%20modules/dealerlocator/alto/Function.ExcelDealerLocator.Google.aspx'; //?location=' + yourLocation;
        document.getElementById("homepage-map-canvas").innerHTML = '<iframe src="' + url + '" scrolling="no" width="100%" height="935" border="0" frameborder="0"  id="dealer_iframe" ></iframe>';
      
      //  $("dealer-locator-button").parent().addClass('selected');
      //  alert(document.getElementById('currentTab').value != 'dealer-locator-button');
        if (document.getElementById("active-right").value=="0") {
            $('#homepage-map-canvas iframe').load(function () {
                $('#tab-content').slideToggle();
                $('#homepage-map-canvas iframe').unbind('load');
            });
        }
        document.getElementById("active-left").value = "1";
        document.getElementById("active-right").value = "0";
        document.getElementById('currentTab').value = 'dealer-locator-button'
    }
    else {
       // alet('else');
        $(".homepage-map-canvas").innerHTML = "";
        document.getElementById("active-left").value = "0";
       
            $('#tab-content').slideToggle();
        
       // document.getElementById('currentTab').value = 'dealer-locator-button'
     //   if ($("dealer-locator-button").parent().hasClass('selected')) {
     //       $("dealer-locator-button").parent().removeClass('selected');
    //        $('#tabs .wrap .selected-tab').css('display', 'none');
   //     }
    }
   
    return false;
};

function ShowWorldMap() {

   /* var h = 0;
   if ($('#tab-content').height() == 0) {
        h = 430;
    }
    $('#tab-content').animate(
        {
            height: h
        }, 200
        );*/
    if ($.browser.msie) {
        $('#tab-content').height(430);
    }
   // alert('world ar=' + document.getElementById("active-right").value + "  " + document.getElementById('currentTab').value+" al= " + document.getElementById("active-left").value);
    if (document.getElementById("active-right").value == "0") {
        var url = '/Global/Footer/Tabs/CountrySelector.aspx'; //?location=' + yourLocation;
        document.getElementById("homepage-map-canvas").innerHTML = '<iframe src="' + url + '" scrolling="no" width="100%" height="900" border="0" frameborder="0"  id="dealer_iframe" ></iframe>';
       
        //document.getElementById("worldmap-content").style.height="600px";
        if (document.getElementById("active-left").value == "0") {
            $('#homepage-map-canvas iframe').load(function () {
                $('#tab-content').slideToggle();
                $('#homepage-map-canvas iframe').unbind('load');
            });
        }
        document.getElementById("active-right").value = "1";
        document.getElementById("active-left").value = "0";
        document.getElementById('currentTab').value = 'worldmap-button';
    }
    else {
       
        //document.getElementById("worldmap-content").style.height="0px";
        $(".homepage-map-canvas").innerHTML = "";
        document.getElementById("active-right").value = "0";
        $('#tab-content').slideToggle();
       // if ($(this).parent().hasClass('selected')) {
       ////     $('#tabs .title').removeClass('selected');
       //     $('#tabs .wrap .selected-tab').css('display', 'none');
     //   }
    }
   
    return false;
};
var cuid = 0;
function fixCountryDiv(id) {
  var MAX_HEIGHT = 194;
  var SCROLL_HEIGHT = 93;
  
  var div = document.getElementById(id);
  var contents = $('.contents', div);
  
  if(contents.hasClass('fixed')) {
    return;
  }
  
  contents.addClass('fixed');
  
  if(contents.size() == 1) {
    var inner = $('.inner', contents);
    
    if(inner.outerHeight() > MAX_HEIGHT) {
      inner
        .css('position', 'absolute')
        .css('top', 0);
      
      contents.height(MAX_HEIGHT);
      
      var item_id = 'country-div-' + cuid;
      cuid++;
      
      inner.attr('id', item_id);
      
      var more = $('<div class="boxBody3"></div>');
      var more_a = $('<a id="sm-' + item_id + '" href="#" class="more">&nbsp;</a>');
      more.append(more_a);
      
      var less = $('<div class="boxBody3"></div>');
      var less_a = $('<a id="sl-' + item_id + '" href="#" class="less">&nbsp;</a>');
      less.append(less_a);
      
      var scrolling = false;
      
      more_a.click(function(e) {
        if(scrolling) {
          return false;
        }
        
        var inner_id = $(e.currentTarget).attr('id').replace('sm-', '');
        
        if($('#' + inner_id).css('top').replace('px', '') * -1 + MAX_HEIGHT < $('#' + inner_id).outerHeight()) {
          scrolling = true;
          $('#' + inner_id).animate({'top': '-=' + SCROLL_HEIGHT}, 500, function() {
            fixCountryLinks(inner_id);
            scrolling = false;
          });
        }
        
        return false;
      });
      
      less_a.click(function(e) {
        if(scrolling) {
          return false;
        }
        
        var inner_id = $(e.currentTarget).attr('id').replace('sl-', '');
        
        if($('#' + inner_id).css('top').replace('px', '') * -1 > 0) {
          scrolling = true;
          $('#' + inner_id).animate({'top': '+=' + SCROLL_HEIGHT}, 500, function() {
            fixCountryLinks(inner_id);
            scrolling = false;
          });
        }
        
        return false;
      });
      
      less_a.addClass('disabled');
            
      var fixCountryLinks = function(inner_id) {
        var more_a = $('#sm-' + inner_id);
        var less_a = $('#sl-' + inner_id);
        
        if($('#' + inner_id).css('top').replace('px', '') * -1 + MAX_HEIGHT < $('#' + inner_id).outerHeight()) {
          more_a.removeClass('disabled');
        } else {          
          more_a.addClass('disabled');
        }
        
        if($('#' + inner_id).css('top').replace('px', '') * -1 > 0) {
          less_a.removeClass('disabled');
        } else {
          less_a.addClass('disabled');
        }
      }
      
      contents.after(more);
      contents.before(less);
    }
  }
}
  
function checkEnter(e,caller) //e is event object passed from function invocation
{
	var characterCode //literal character code will be stored in this variable

	if(e && e.which)
	{ //if which property of event object is supported (NN4)
		e = e
		characterCode = e.which //character code is contained in NN4's which property
	}
	else
	{
		e = event
		characterCode = e.keyCode //character code is contained in IE's keyCode property
	}

	if(characterCode == 13)//if generated character code is equal to ascii 13 (if enter key)
	{ 
		document.getElementById(caller).onclick();
		return false
	}
	else
	{
		return true
	}
}

function postSearchIdleSurf(searchStr,site){
if(searchStr != ""){
    if(document.forms[0].__VIEWSTATE){
	    document.forms[0].__VIEWSTATE.enabled = false;

	}
	
	document.mainform.searchMain.value = searchStr;
	document.mainform.method="post";
	//document.mainform.action="/functions/search2.aspx?search="+searchStr+"&site="+site;
	document.mainform.action="/search.aspx?q="+encodeURI(searchStr);//+"&site="+site;
	document.mainform.submit();
}
else{
	return false
}
}

function GoToMYNilfisk() {
    document.mainform.target.value = 'http://my.nilfisk-Alto.com/nilfisk-alto.asp';
    document.mainform.submit();
}


/*
Cookies for countrySelector
*/

var expDays = 100;
var exp = new Date();
exp.setTime(exp.getTime() + (expDays * 24 * 60 * 60 * 1000));

function getCookieVal(offset) {
    var endstr = document.cookie.indexOf(";", offset);
    if (endstr == -1)
        endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie(name) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg)
            return getCookieVal(j);
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break;
    }
    return null;
}
function SetCookie(name, value) {
    var argv = SetCookie.arguments;
    var argc = SetCookie.arguments.length;
    var expires = (argc > 2) ? argv[2] : null;
    var path = (argc > 3) ? argv[3] : null;
    var domain = (argc > 4) ? argv[4] : null;
    var secure = (argc > 5) ? argv[5] : false;
    document.cookie = name + "=" + escape(value) +
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
	((path == null) ? "" : ("; path=" + path)) +
	((domain == null) ? "" : ("; domain=" + domain)) +
	((secure == true) ? "; secure" : "");

}

function DeleteCookie(name) {
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval = GetCookie(name);
    document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

function productFinderStep(obj) {
    if (mainform.productfinderurl != null) {
        mainform.productfinderurl.value = obj.value;
    }
    mainform.productfindersubmit.disabled = "";
}


var hide = true;

function showhide(obj, lyr) {
    hideall();
    var obj = document.getElementById(obj);
    var lyr2 = document.getElementById(lyr + 'Countries').id;

    var elContinent = document.getElementById(lyr).style;
    var elCountries = document.getElementById(lyr2).style;
    
    
    if (elContinent.display == '' || elContinent.display == 'none') {
        elContinent.display = 'block';
        elCountries.display = 'block';
        setLyr(obj, lyr);
        setLyr2(obj, lyr2);

        if (GetCookie('brandDivId') != null) {
            if (document.getElementById(GetCookie('brandDivId')) != null) {
                document.getElementById(GetCookie('brandDivId')).style.display = 'none';
            }
        }
    }
}

function placeContinent(newX, newY, lyr) {
    /*
    Africa
    Asia
    AustraliaOcenia
    Europe
    MiddleEast
    NorthAmerica
    SouthAmerica
    */

    var x = new getObj(lyr);
    if (lyr == "Africa") {
        x.style.top = newY + 113 + 'px';
        x.style.left = newX + 284 + 'px';
    }
    else if (lyr == "Asia") {
        x.style.top = newY + 17 + 'px';
        x.style.left = newX + 417 + 'px';
    }
    else if (lyr == "AustraliaOcenia") {
        x.style.top = newY + 181 + 'px';
        x.style.left = newX + 523 + 'px';
    }
    else if (lyr == "Europe") {
        x.style.top = newY + 19 + 'px';
        x.style.left = newX + 266 + 'px';
    }
    else if (lyr == "MiddleEast") {
        x.style.top = newY + 92 + 'px';
        x.style.left = newX + 369 + 'px';
    }
    else if (lyr == "NorthAmerica") {
        x.style.top = newY + 0 + 'px';
        x.style.left = (newX -7) + 'px';
    }
    else if (lyr == "SouthAmerica") {
        x.style.top = newY + 158 + 'px';
        x.style.left = newX + 154 + 'px';
    }
    else {
        x.style.top = newY + 'px';
        x.style.left = newX + 'px';
    }
}

function setLyr(obj, lyr) {
    var newX = findPosX(obj);
    var newY = findPosY(obj);
    //if (lyr == 'testP') newY -= 50;
    var x = new getObj(lyr);

    placeContinent(newX, newY, lyr);
    //	x.style.top = newY + 'px';
    //	x.style.left = newX + 'px';
}

function setLyr2(obj, lyr) {
    var newX = findPosX(obj);
    var newY = findPosY(obj);
    var x = new getObj(lyr);
    var x = new getObj(lyr);
    if (lyr == "AfricaCountries") {
        x.style.top = newY + 110 + 'px';
        x.style.left = newX + 410 + 'px';
    }
    else if (lyr == "AsiaCountries") {
        x.style.top = newY + 90 + 'px';
        x.style.left = newX + 260 + 'px';
    }
    else if (lyr == "AustraliaOceniaCountries") {
        x.style.top = newY + 150 + 'px';
        x.style.left = newX + 330 + 'px';
    }
    else if (lyr == "EuropeCountries") {
        x.style.top = newY -7 + 'px';
        x.style.left = newX + 430 + 'px';
    }
    else if (lyr == "MiddleEastCountries") {
        x.style.top = newY + 50 + 'px';
        x.style.left = newX + 467 + 'px';
    }
    else if (lyr == "NorthAmericaCountries") {
        x.style.top = newY + 60 + 'px';
        x.style.left = newX + 220 + 'px';
    }
    else if (lyr == "SouthAmericaCountries") {
        x.style.top = newY + 110 + 'px';
        x.style.left = newX + 230 + 'px';
    }
    else {
        x.style.top = newY + 'px';
        x.style.left = newX + 'px';
    }
}

function findPosX(obj) {
  return 10;
}

function findPosY(obj) {
    return marginTop = 20;
}


function getObj(name) {
    if (document.getElementById) {
        this.obj = document.getElementById(name);
        this.style = document.getElementById(name).style;
    }
    else if (document.all) {
        this.obj = document.all[name];
        this.style = document.all[name].style;
    }
    else if (document.layers) {
        if (document.layers[name]) {
            this.obj = document.layers[name];
            this.style = document.layers[name];
        }
        else {
            this.obj = document.layers.testP.layers[name];
            this.style = document.layers.testP.layers[name];
        }
    }
}

function hideall() {
    document.getElementById('Africa').style.display = 'none';
    document.getElementById('Asia').style.display = 'none';
    document.getElementById('AustraliaOcenia').style.display = 'none';
    document.getElementById('Europe').style.display = 'none';
    document.getElementById('MiddleEast').style.display = 'none';
    document.getElementById('NorthAmerica').style.display = 'none';
    document.getElementById('SouthAmerica').style.display = 'none';
    document.getElementById('AfricaCountries').style.display = 'none';
    document.getElementById('AsiaCountries').style.display = 'none';
    document.getElementById('AustraliaOceniaCountries').style.display = 'none';
    document.getElementById('EuropeCountries').style.display = 'none';
    document.getElementById('MiddleEastCountries').style.display = 'none';
    document.getElementById('NorthAmericaCountries').style.display = 'none';
    document.getElementById('SouthAmericaCountries').style.display = 'none';
}





jQuery(document).ready(function () {
  $('.countrySelectorAlto').mouseleave(function(e) {
    hideall();
  });
  
    //$(".countryInfoText").mouseover(function () { $("#Africa, #Asia, #AustraliaOcenia, #Europe, #MiddleEast, #NorthAmerica, #SouthAmerica, #AfricaCountries, #AustraliaOceniaCountries, #EuropeCountries, #MiddleEastCountries, #NorthAmericaCountries, #SouthAmericaCountries").css({ display: "none" }) })
});


function gotoURL(pUrl, indexNum) {
    if (pUrl != '') {
        url = new String(pUrl);
        window.location.href = url;
    }
}

/*Product comparator*/

function checkAndCompare(itm) {



    if (document.forms[0].comparator) {
        var max = document.forms[0].comparator_th.length;
        var totalChecked = 0;
        var areaWidth = 440;

        // loop through checkboxes
        for (var idx = 0; idx < max; idx++) {

            document.forms[0].comparator_th[idx].disabled = false;
            document.getElementById("label" + document.forms[0].comparator[idx].value).style.color = "Black";

            // count actives
           
            for (var j = 0; j < document.getElementById("specifications").childNodes.length; j++) {
                var tdID = document.getElementById("col-" + document.forms[0].comparator_th[idx].value + "-" + (j + 1) + "-" + (idx + 1));
                //alert("col-" + document.forms[0].comparator[idx].value + "-" + (j + 1) + "-" + (idx + 1)+"  "+document.getElementById("col-" + document.forms[0].comparator[idx].value + "-" + (j + 1) + "-" + (idx + 1)));
                if (tdID != null) {
                    if (eval("document.forms[0].comparator_th[" + idx + "].checked") == true) {
                        if (j == 0) { totalChecked += 1; }
                        if (document.all) { tdID.style.display = "block"; }
                        else { tdID.style.display = "table-cell"; }
                    }
                    else { tdID.style.display = "none"; }
                }
            }
        }
        if (totalChecked > 2) {
            disableUnChecked();
        }

    }
}

function disableUnChecked() {
    var max = document.forms[0].comparator.length;

    for (var idx = 0; idx < max; idx++) {
        if (eval("document.forms[0].comparator_th[" + idx + "].checked") != true ) {
            document.forms[0].comparator_th[idx].disabled = true;
            document.getElementById("label" + document.forms[0].comparator_th[idx].value).style.color = "Gray";
        }

    }

}

String.prototype.startsWith = function(str)
{return (this.match("^"+str)==str)}

function accessoriesModelClick(pcs) {
    if (document.getElementById("radio" + pcs).checked) {
        var max = document.forms[0].comparator.length;
        for (var idx = 0; idx < max; idx++) {
		
            document.forms[0].comparator[idx].checked = false;
			
        }
        document.getElementById("radio" + pcs).checked = true;
    
    var div = document.getElementById("accDiv" + pcs);
    var label = document.getElementById("label" + pcs)

    var previousPcs = document.getElementById("selectedPcs").value
    document.getElementById("selectedPcs").value = pcs;

    var previousDiv = document.getElementById("accDiv" + previousPcs);
    var previousLabel = document.getElementById("label" + previousPcs)
    //alert(div.id);


    div.style.display = "block";
    previousDiv.style.display = "none";
    //previousLabel.id="removeBold";
    //label.="markBold";
}
else {
    document.getElementById("radio" + pcs).checked = true;
}
}


/*search*/
function doSearch() {

    document.forms[0].__VIEWSTATE.disabled = true;
    document.forms[0].quickSearchBtn.disabled = true;
    document.forms[0].btnG.disabled = true;
    document.mainform.method = "get";


    var q = '?q=';
    if (qBox != null) {
        q += encodeURI(qBox.value);
    }
    var url = '';

    // check if it's advanced search or not
    var el = document.getElementById("advancedSearch");
    var display = el.style.display;

    // simple search
    if (display == "none") {
        // the query words
        var qBox = document.getElementById('q');

        if (qBox != null) {
            q += encodeURI(qBox.value);
        }

        url += q;
        // HACK, dont show files in normal search
        //url += '&as_filetype=pdf&as_filetype=doc&as_filetype=ps&as_filetype=ppt&as_filetype=xls&as_filetype=rtf'

        document.location = url;
        return;
    }

    // advanced search takes search words from as_q
    var as_q = document.getElementById('as_q');

    q += encodeURI(as_q.value);
    url += q;

    // exact words
    var as_epq = document.getElementById('as_epq');
    if (as_epq != null && as_epq.value != '') {
        url += '&as_epq=' + encodeURI(as_epq.value);
    }

    // one of the words at least
    var as_oq = document.getElementById('as_oq');
    if (as_oq != null && as_oq.value != '') {
        url += '&as_oq=' + encodeURI(as_oq.value);

    }
    // and without the words
    var as_eq = document.getElementById('as_eq');
    if (as_eq != null && as_eq.value != '') {
        url += '&as_eq=' + encodeURI(as_eq.value);
    }
    // filetype filtering
    var as_ft = document.getElementById('as_ft');
    if (as_ft != null && as_ft.value != '') {
        url += '&as_ft=' + encodeURI(as_ft.value);
    }

    var as_filetype = document.getElementById('as_filetype');
    if (as_filetype != null && as_filetype.value != '') {
        url += '&as_filetype=' + encodeURI(as_filetype.value);
    }


    // the number of results in page
    var num = document.getElementById('num');
    if (num != null) {
        url += '&num=' + num.value;
    }


    document.location = url;

    //    document.mainform.submit();
}


function changeTab(idshow,idhide) {
    if (document.getElementById(idhide) != null) {
        document.getElementById(idhide).style.display = 'none';
    }
    if (document.getElementById(idshow) != null) {
        document.getElementById(idshow).style.display = 'inline';
    }
}

 $('#homepage-map-canvas iframe').load(function () {
$('#worldmap-content').slideToggle();
$('#homepage-map-canvas iframe').unbind('load');
});


