//Validation downloads
$(document).ready(function() { 
	
	$("a.submitDownloads").click(function()
		{
			if (!isCheckedById("download"))
			{
				alert ("Please select at least one download");
				return false;
			}
			/*				
			else if (!isCheckedById("event"))
			{
				alert ("Please select at least one event");
				return false;
			}
			*/
			else
			{
				$(this).parents("form").submit(); //submit the form
			}
		});
		
		function isCheckedById(id)
		{
			var checked = $("input[id="+id+"]:checked").length;
			//alert(checked);
			if (checked == 0)
			{
				return false;
			}
			else
			{
				return true;
			}
		}
});

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_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_nbGroup(event, grpName) { //v6.0
	
    var i,img,nbArr,args=MM_nbGroup.arguments;
    if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
		
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {	
	document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
      
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {		
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up;}
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}

function CheckValueOnBlur(field, value) {
	if (!field.value) {
		field.value = value;
	}
}	
			
function CheckValueOnFocus(field, value) {
	if (field.value) {
		if (field.value == value) {
			field.value='';
	    }
	}
}

//create onDomReady Event
window.onDomReady = DomReady;

//Setup the event
function DomReady(fn)
{
	//W3C
	if(document.addEventListener)
	{
		document.addEventListener("DOMContentLoaded", fn, false);
	}
	//IE
	else
	{
		document.onreadystatechange = function(){ readyState(fn); }
	}
}

//IE execute function
function readyState(fn)
{
	//dom is ready for interaction
	if(document.readyState == "interactive" || document.readyState == "complete")
	{
		fn();
	}
}

function gup(name) 
{
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var tmpURL = window.location.href;
	var results = regex.exec( tmpURL );
	if( results == null )
		return "";
	else
		return results[1];
}

//FAQ page
function setFilter(){
	var selectedFilter = gup('Filter1');
	var x=document.getElementById('categoryFilter');
	
	for (i = 0; i < x.length; i++)
	{
		if(x.options[i].value == selectedFilter){
			document.getElementById('categoryFilter').selectedIndex = i;
		}

	}
}

/****************************************************/

$(document).ready(function() { 
	layoutFix();
	topMenuReplace();
});

function layoutFix(){

	//$('div.masterStepsLine div.finished:last').addClass('noBgr');
    //$('.tabStepContent .bodyContent div.ProductItem:nth-child(7n)').addClass('lastInLine');
    $('.subMenuMarker img').parent().addClass('greenItem').next().addClass('greenItem');
}

function topMenuReplace() {
    var html;
   /* alert(html +"AAA");
        html = $('#menu1item0').detach();
        alert(html +"AAA");
        $('td#menu1item1').after(html);*/
}

// JavaScript Document

$(document).ready(function(){
	accordionLogic();
	btnFix();
	brandsBox();
	setListStyles();
})


function accordionLogic(){
	$('.accordion div.accTitle').click(
	  function() {		
		if($(this).parent().hasClass('active'))
			$(this).parent().removeClass('active');
		else
			$(this).parent().addClass('active');
	  });		
}

function  btnFix(){
	$('a.btn').wrap('<span class="btnHolder"></span>');
}

function doNothing(){
}

function setLeftMenuClass(){
	if (document.getElementById('maintable')){
		document.getElementById('maintable').className = 'maintable leftWideContent';
	}
}

function setRightMenuClass(){
	if (document.getElementById('maintable')){
		document.getElementById('maintable').className = 'maintable mainWide';
	}
}

function brandsBox(){
	var activeIndex;
	$('.brandsBox0').prepend('<div class="tabLine"></div>');
	$('.brandsBox0 ul li .tabItem').each( function(){
		$('.brandsBox0 .tabLine').append($(this).detach());
	});
	
	$('.brandsBox0 .tabLine .tabItem').click( function(){
		activeIndex = $(this).index();
		setBrandBox(activeIndex);
	});
	
	$('.brandsBox1').prepend('<div class="tabLine"></div>');
	$('.brandsBox1 ul li .tabItem').each( function(){
		$('.brandsBox1 .tabLine').append($(this).detach());
	});
	
	$('.brandsBox1 .tabLine .tabItem').click( function(){
		activeIndex = $(this).index();
		setBrandBox(activeIndex);
	});
	
	$('.brandsBoxAmg').prepend('<div class="tabLine"></div>');
	$('.brandsBoxAmg ul li .tabItem').each( function(){
		$('.brandsBoxAmg .tabLine').append($(this).detach());
	});
	
	$('.brandsBoxAmg .tabLine .tabItem').click( function(){
		activeIndex = $(this).index();
		setBrandBox(activeIndex);
	});
}	

function setBrandBox(activeIndex){
	var oldActiveIndex = activeIndex;
	$('.brandsBox0 .tabLine .tabItem').removeClass('active');
	$('.brandsBox0 ul li.active').removeClass('active');
	activeIndex = activeIndex +1;
	$('.brandsBox0 ul li:nth-child(' + activeIndex + ')').addClass('active');
	$('.brandsBox0 .tabLine .tabItem:nth-child(' + activeIndex + ')').addClass('active');
	
	activeIndex = oldActiveIndex;
	$('.brandsBox1 .tabLine .tabItem').removeClass('active');
	$('.brandsBox1 ul li.active').removeClass('active');
	activeIndex = activeIndex +1;
	$('.brandsBox1 ul li:nth-child(' + activeIndex + ')').addClass('active');
	$('.brandsBox1 .tabLine .tabItem:nth-child(' + activeIndex + ')').addClass('active');
	
	activeIndex = oldActiveIndex;
	$('.brandsBoxAmg .tabLine .tabItem').removeClass('active');
	$('.brandsBoxAmg ul li.active').removeClass('active');
	activeIndex = activeIndex +1;
	$('.brandsBoxAmg ul li:nth-child(' + activeIndex + ')').addClass('active');
	$('.brandsBoxAmg .tabLine .tabItem:nth-child(' + activeIndex + ')').addClass('active');
}


	

function setListStyles(){
	
	$('.content ol li').wrapInner('<span class="orderedlistItem"></span>');
	$('.content ul').className = 'dashList';
	$('.customcontenttable ul').className = 'dashList';
}



var timeout = 5000;
                // JavaScript Document
// http://jquery.malsup.com/cycle/int2.html
// read http://ejohn.org/blog/how-javascript-timers-work/ for more info about the timings issue.
// also read this http://forum.jquery.com/topic/jquery-cycle-plugin-creating-a-realtime-status-progress-bar
var pause = 0;
var images = new Array();
var stack = new Array();


$(document).ready(function() {
    SetLayout();

    //TNTW-53732 preload images
    if (images != null && images.length > 0) {
        AddToStack(0);
    }

    $('#slideshow').cycle({
        fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
        next: '#carrousel_next',
        timeout: timeout,
        prev: '#carrousel_previous',
        pause: 1,
        before: onBefore,
        after: onAfter,
        continuous: 0
    });

    $('#carrousel_pauzeButton').click(function() {
        $('.slideshow').cycle('toggle');
    });
    
     //Set heigth
    $('.carouselControls').css('height', $('.slideshow').height());

});


function SetLayout() {
    var elementCount = $("#slideshow > div").size();

    //hide slide buttons
    if (elementCount == 1) {
        $('#carrousel_buttons').css('display', 'none');
    }    
   
}

function onBefore(curr, next, opts) {
    if (opts.addSlide) // <-- important!
        while (stack.length)
        opts.addSlide(stack.shift());
 }

function onAfter(curr, next, opts) {
}

function UpdateProgressBar(options) {
    $("#carrousel_progressBar").stop();
    if (pause == 0) {
        $("#carrousel_progressBar").css('width', 0);
    }
}

function AddToStack(imageNr) {

    if (imageNr < images.length) {
        var img = new Image();

        img.src = images[imageNr].src;
        $(img).bind('load', function() {
            stack.push(AddImage(images[imageNr]));
            AddToStack(imageNr + 1);
        });
    }
}

function AddImage(image) {

    if (image.href != null && image.href != "") {
        return "<div><a href='"+ image.href +"' target='"+ image.target +"' title='"+ image.text +"'><img src=\"" + image.src + "\" alt='"+ image.title +"' style=\"border-width:0px;\"\></a>";
    }else
    {
        return "<div><img src=\"" + image.src + "\" alt='" + image.text + "' title='" + image.text + "' style=\"border-width:0px;\"\></div>";
    }
}
