
$().ready(function() {
  $('#dialog').jqm();
  $('#dialog').jqmShow();
});

$().ready(function() {
  $('#dialog2').jqm();
  $('#dialog2').jqmShow();
});

function toggleMe(a){
	  var e=document.getElementById(a);
	  if(!e)return true;
	  if(e.style.display=="none"){
	    e.style.display="block";
	  } else {
	    e.style.display="none";
	  }
	  return true;
}

function toggleMeVisible(a){
	  var e=document.getElementById(a);
	  if(!e)return true;
	  if(e.style.visibility=="hidden"){
		    e.style.visibility="visible";
	  } else {
	    e.style.visibility="hidden";
	  }
	  return true;
}

function changeClass(a,b,c){
	var e=document.getElementById(a);
	  if(!e)return true;
	  
	  if(e.className== b){
	    e.className=c;
	  } else {
	    e.className=b;
	  }
	  return true;
}

function toggleMeOn(a){
	  var e=document.getElementById(a);
	  if(!e)return true;
	  if(e.style.display=="none"){
	    e.style.display="block"
	  }
	  return true;
}

function toggleMeOff(a){
	  var e=document.getElementById(a);
	  if(!e)return true;
	  if(e.style.display=="block"){
	    e.style.display="none"
	  }
	  return true;
}


function showSubnav(a){
	  var e=document.getElementById(a);


	    e.style.display="block"

	  return true;
}
function hideSubnav(a){
	  var e=document.getElementById(a);


	    e.style.display="none"

	  return true;
}

function reload() {

	document.location.href="#connection";
	document.location.reload();
}

function showCountryInfo() { //used in content.html
	//var CountryID;
	//var CountryInputdID;
	//var CountryLink;
	CountryID = document.getElementById("countryInfo").value;
	CountryInputdID = "countryUrl"+CountryID;
	//alert(CountryInputdID);
	try
	{
		CountryLink = document.getElementById(CountryInputdID).value;
		window.open(CountryLink);
	}
	catch(err)
	{
		alert ('Bitte wählen Sie ein anderes Land');
	}
}

function noop()	{
}


function scroll( updown,productID,movePixel ) {

		var position=0;
		movePixel = parseInt(movePixel);
		position = parseInt(document.getElementById('productScrollValueCurrent'+productID).value);
		positionMax = parseInt(document.getElementById('productScrollValueMax'+productID).value);
		//alert(position+' '+positionMax+' '+updown);
		if ( updown == 'left' && position<0){
			 position = position +movePixel;
		}
		else if ( updown == 'right' && -position<(positionMax-3)*movePixel){
			position = position -movePixel;
		}
		if (position<0){
			document.getElementById('productScrollButtonLeft'+productID).style.display="block";
		}
		else{
			document.getElementById('productScrollButtonLeft'+productID).style.display="none";
		}
		if (-position==(positionMax-3)*movePixel){
			document.getElementById('productScrollButtonRight'+productID).style.display="none";
		}
		else {
			document.getElementById('productScrollButtonRight'+productID).style.display="block";
		}
		document.getElementById(productID).style.marginLeft = position+"px";
		document.getElementById('productScrollValueCurrent'+productID).value =position;
}



function setCheckbox(name) {
	document.getElementById(name).checked = true;
}

function slideDiv(divID, LinkGroupID) {
			
	var openDIV = '';
	
	if (LinkGroupID==1)
	{
		
		changeClass(divID+'_button',"square_grey_w250_down center_block","square_grey_w250_up center_block");
		changeClass(divID+'_preview',"filter_preview","filter_preview_selected");
		
		var div1 = document.getElementById('filterCompanies');
		var div2 = document.getElementById('filterPOS');
		var div3 = document.getElementById('filterBrands');
		//var div4 = document.getElementById('categoryShowrooms');
		
		if (div1.style.display == 'block') {$(document.getElementById('filterCompanies')).slideUp("slow"); openDIV= 'filterCompanies';}
		if (div2.style.display == 'block') {$(document.getElementById('filterPOS')).slideUp("slow"); openDIV= 'filterPOS';}
		if (div3.style.display == 'block') {$(document.getElementById('filterBrands')).slideUp("slow"); openDIV= 'filterBrands';}
		//if (div4.style.display == 'block') {$(document.getElementById('categoryShowrooms')).slideUp("slow"); openDIV= 'categoryShowrooms';}
	}
	else
	{
		var div1 = document.getElementById('homeCategories');
		var div2 = document.getElementById('key_account');
		var div3 = document.getElementById('showrooms');
		if (div1.style.display == 'block') {$(document.getElementById('homeCategories')).slideUp("slow"); openDIV= 'homeCategories';}
		if (div2.style.display == 'block') {$(document.getElementById('key_account')).slideUp("slow"); openDIV= 'key_account';}
		if (div3.style.display == 'block') {$(document.getElementById('showrooms')).slideUp("slow"); openDIV= 'showrooms';}
	}
	if (openDIV != divID) {
		$(document.getElementById(divID)).slideDown("slow");
		if (LinkGroupID==1){
			changeClass(openDIV+'_button',"square_grey_w250_down center_block","square_grey_w250_up center_block");
			changeClass(openDIV+'_preview',"filter_preview","filter_preview_selected");
		}
	}
}
		

function slideDivUpDown(divID) {
	if (document.getElementById(divID).style.display == 'block') {$(document.getElementById(divID)).slideUp("slow"); }
	else {$(document.getElementById(divID)).slideDown("slow"); }
}

function loadHtmlContent(divID,htmlTitle) {
	 $(document).ready(function(){

		jQuery.get( "/_files/templates/clients/mynetfair/"+htmlTitle, function(d){$('#'+divID).html(d);} )
	});

}
					
function loadHtmlContentFromPhp(divID,phpTitle, typeID) {
	if(divID == '') //Only call a php file (don't display the html results in the div divID)
	{
		jQuery.get( "/_include/"+phpTitle );
	}
	else if( typeID == 1) //display with picture wait during loading
	{
		alert($(document.getElementById(divID)).offsetHeight);
		loadWaiting(divID);
		$(document).ready(function(){
			jQuery.get( "/_include/"+phpTitle, function(d){$('#'+divID).html(d); loadStopWaiting(divID);} )
		});	
		loadWaiting(divID);
	}
	else //run the php file phpTitle and display the html result in the div divID
	{
		loadWaiting(divID);
		$(document).ready(function(){
			jQuery.get( "/_include/"+phpTitle, function(d){$('#'+divID).html(d);} )
		});
	}
}

function changeValue(divID, SearchboxText) {
    if (document.getElementById(divID).value == SearchboxText) {
        document.getElementById(divID).value = "";
    } else if (document.getElementById(divID).value == "") {
        document.getElementById(divID).value = SearchboxText;
    }
}	
				
				
function scrollAnimation(sender)		
{		
	(function($) {
		$(function() { //on DOM ready
			$("#scroller").simplyScroll({
				autoMode: 'loop'
			});
		});
	})(jQuery);		
}		

//Display waiting picture during charging div
function loadWaiting(divID)
{
	(function($){
		$.fn.waiting = function(options) {
			var settings = $.extend({
				css: {'opacity':'0.6','background-color':'#00AEEF'},
				imgsrc: "/_files/templates/clients/mynetfair/images/new/loader.gif"
			},options);
			var offset = this.offset();
			var height = this.offsetHeight;
			var width = this.width();
			var id = this[0].id;
			var newid = id + "waiting";
			this[0].waitid = newid;
			var div = $("<div />").css({'position':'absolute','top':offset.top,'left':offset.left,'height':height,'width':width}).css(settings.css)
			.attr('id',newid).appendTo("body");
			var img = $("<img />").attr("src",settings.imgsrc);
			var imgheight = '32px';
			var imgwidth = img.width();
			var top = ((300/2)-(32/2));
			img.css({'position':'absolute','top':top,'left':((width/2)-(imgwidth/2)),'z-index':3000});
			img.appendTo(div);
			return this;
		}
	})(jQuery);
	$(document.getElementById(divID)).waiting({imgsrc:"/_files/templates/clients/mynetfair/images/new/loader.gif"});
}

//Stop displaying waiting picture during charging div
function loadStopWaiting(divID)
{
	(function($){
		$.fn.stopWaiting = function() {
			var waitid = this[0].waitid;
			$("#"+waitid).remove();
			return this;
		}

	})(jQuery);
	$(document.getElementById(divID)).stopWaiting();
}