var win= null;
function ShowWindow(mypage,myname,w,h,scroll){
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  var settings  ='height='+h+',';
      settings +='width='+w+',';
      settings +='top='+wint+',';
      settings +='left='+winl+',';
      settings +='scrollbars='+scroll+',';
      settings +='resizable=yes,';
	  settings +='status=yes';
  win=window.open(mypage,myname,settings);
  if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}
		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_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_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;
		  } }
		}

		//encrypt email
		function goForth(c,n,d) {
		c += ' ';
		var length = c.length;
		var number = 0;
		var bar = 0;
		var answer = '';
		for(var i = 0; i < length; i++) {
		number = 0;
		bar = 0;
		while(c.charCodeAt(i) != 32) {
		number = number * 10;
		number = number + c.charCodeAt(i)-48;
		i++;
		}
		answer += String.fromCharCode(decrypt(number,n,d));
		}
		// Updated security feature
		parent.location = 'm'+'a'+'i'+'l'+'t'+'o'+':'+answer;
		}
		
		function showText(c,n,d) {
		c += ' ';
		var length = c.length;
		var number = 0;
		var bar = 0;
		var answer = '';
		for(var i = 0; i < length; i++) {
		number = 0;
		bar = 0;
		while(c.charCodeAt(i) != 32) {
		number = number * 10;
		number = number + c.charCodeAt(i)-48;
		i++;
		}
		document.write('&');
		document.write('#');
		document.write(decrypt(number,n,d));
		}
		}
		
		function decrypt(c,n,d) {
		// Split exponents up
		if (d % 2== 0) {
		bar = 1;
		for(var i = 1; i <= d/2; i++) {
		foo = (c*c) % n;
		bar = (foo*bar) % n;
		}
		} else {
		bar = c;
		for(var i = 1; i <= d/2; i++) {
		foo = (c*c) % n;
		bar = (foo*bar) % n;
		}
		}
		return bar;
		}


		function imposeMaxLength(Object, MaxLen)
		{
  			return (Object.value.length <= MaxLen);
		}


		function verify(){
    			msg = "Weet u het zeker?";
    			return confirm(msg);
		}

		function noenter() {
  			return !(window.event && window.event.keyCode == 13); 
		}

		function querySt(ji) {
			hu = window.location.search.substring(1);
			gy = hu.split("&");
			for (i=0;i<gy.length;i++) {
				ft = gy[i].split("=");
				if (ft[0] == ji) {
					return ft[1];
				}
			}
		}

		function ScrollMenu() {

			if(querySt("scrollpos") != "") {
				scrollpos = querySt("scrollpos");

				div1.scrollTop = scrollpos;

				//alert(scrollpos);

			}
		}

		function SetDivPosition() {
        		var intY = document.getElementById("divMain").scrollTop;
        		//document.title = intY;
        		document.cookie = "yPos=!~" + intY + "~!";
      		}


		function loadCat(sortid,merkid,mainid,subid) {	
					
				    merkid = merkid.replace('%20',' ');
				    merkid = merkid.replace('%20',' ');

				    $("a").css("cursor", "wait");  
				    
				    $("td#tdCatMenu").load("/AudioBizz/assets/common/themes/live/CatMenuServer.aspx?SortID="+sortid+"&MerkID="+escape(merkid)+"&MainID="+mainid+"&SubID="+escape(subid)+"&SubSubID=0", function() { 
					$("a").css("cursor", "auto"); 
				    });
		  

			 	    $("div#divMainContent").load("/AudioBizz/assets/common/themes/live/CatOverviewServer.aspx?SortID="+sortid+"&MerkID="+escape(merkid)+"&MainID="+mainid+"&SubID="+escape(subid), function() {
				      	$("a").css("cursor", "auto");
			    	    });


				    if(sortid == 1 && merkid == '' && mainid == '' && subid == '') {
					   var strnav = escape("<a href='#' class='navLink'>Sorteer op merk</a>");
    					   loadNav(strnav);

					   divMain.scrollTop = 0;
				           div1.scrollTop = 0;

				    }
				    else if(sortid == 2 && merkid == '' && mainid == '' && subid == '') {
					   var strnav = escape("<a href='#' class='navLink'>Sorteer op categorie</a>");
    					   loadNav(strnav);
				           
					   divMain.scrollTop = 0;
				           div1.scrollTop = 0;
				    }
				    else {
					
				    	$.get("/AudioBizz/assets/common/themes/live/NavigationCatServer.aspx?SortID="+sortid+"&MerkID="+escape(merkid)+"&MainID="+mainid+"&SubID="+escape(subid)+"&SubSubID=0", function(response) {
					    	$("div#divNav").html(response).show();
				    	});

					divMain.scrollTop = 0;
				    }
								 
				    
		};

		function ClearCatMenu(sortid,merkid,mainid,subid) {	

				    merkid = merkid.replace('%20',' ');    
				    
				    $.get("/AudioBizz/assets/common/themes/live/CatMenuServer.aspx?SortID="+sortid+"&MerkID="+escape(merkid)+"&MainID="+mainid+"&SubID="+escape(subid)+"&SubSubID=0", function(response) {
					    $("div#divCatMenu").html(response).show();
				    });

				    
		};

		function loadLogo(brandid) {	    
				    
			            //$.get("/AudioBizz/assets/common/themes/live/BrandLogoServer.aspx?BrandID="+escape(brandid), function(response) {
					//    $("div#divLogo").html(response).show();
				    //});
		};

		function loadNav(nav) {	    
				    
			            $.get("/AudioBizz/assets/common/themes/live/NavigationServer.aspx?nav="+escape(nav), function(response) {
					    $("div#divNav").html(response).show();
				    });
		};

		function offsetPosition(element) {
			var offsetLeft = 0, offsetTop = 0;
			do {
				offsetLeft += element.offsetLeft;
				offsetTop  += element.offsetTop;
			} while (element = element.offsetParent);
			return [offsetLeft, offsetTop];
		}	
		
		function loadsearchresults(keywords) {	

			divSearchResults.style.left = offsetPosition(keywords)[0];

    			if ((keywords.value == null) || (keywords.value == "")) {
        			divSearchResults.style.display = "none";
    			}
    			else {
				$.get("/AudioBizz/assets/common/themes/live/JSearchResultsServer.aspx?KeyWords="+escape(keywords.value), function(response) {
					$("div#divSearchResults").html(response).show();
				});

    				divSearchResults.style.display = "inline";
				divSearchResults.style.visiblity = "visible";
    			}
				    
		};

		function hidesearchresults() {	

        		divSearchResults.style.display = "none";
				    
		};

		function setScrollbars() {
			document.getElementById("divMain").style.height=document.body.offsetHeight - (62)+"px";
			document.getElementById("div1").style.height=document.body.offsetHeight - (62)+"px";
		};

		function handleKeyUp(e) 
		{
  // get the event
  e = (!e) ? window.event : e;
  // get the event's target
  target = (!e.target) ? e.srcElement : e.target;
  if (target.nodeType == 3) 
    target = target.parentNode;
  // get the character code of the pressed button
  code = (e.charCode) ? e.charCode :
       ((e.keyCode) ? e.keyCode :
       ((e.which) ? e.which : 0));
  // check to see if the event was keyup
  if (e.type == "keyup") 
  {    
    isKeyUpDownPressed =false; 
    // check to see we if are interested in the current character
    if ((code < 13 && code != 8) || 
        (code >=14 && code < 32) || 
        (code >= 33 && code <= 46 && code != 38 && code != 40) || 
        (code >= 112 && code <= 123)) 
    {
      // simply ignore non-interesting characters
    }
    else
    /* if Enter is pressed we jump to the PHP help page of the current 
       function */
    init = 0;
    if(code == 13)
    {
      // check to see if any function is currently selected
      if(position>0)
      {
				document.getElementById('txtSearch').value	=	document.getElementById("a" + position).name + rubbish;
        location.href = document.getElementById("a" + position).href;
      }        
    }        
    else
    // if the down arrow is pressed we go to the next suggestion
      if(code == 40)
      {                   
        newTR=document.getElementById("tr"+(++position));
        oldTR=document.getElementById("tr"+(--position));
        // deselect the old selected suggestion   
        if(position>=0 && position<suggestions-1)
          oldTR.className = "";
 
        // select the new suggestion and update the keyword
        if(position < suggestions - 1)
        {
          newTR.className = "highlightrow";
          updateKeywordValue(newTR);
          position++;         
        }     
        e.cancelBubble = true;
        e.returnValue = false;
        isKeyUpDownPressed = true;        
        // scroll down if the current window is no longer valid
        if(position > maxVisiblePosition)
        {   
          oScroll = document.getElementById("scroll");
          oScroll.scrollTop += 18;
          maxVisiblePosition += 1;
          minVisiblePosition += 1;
        }
      }
      else
      // if the up arrow is pressed we go to the previous suggestion
      if(code == 38)
      {       
        newTR=document.getElementById("tr"+(--position));
        oldTR=document.getElementById("tr"+(++position));
        // deselect the old selected position
        if(position>=0 && position <= suggestions - 1)
        {       
          oldTR.className = "";
        }
        // select the new suggestion and update the keyword
        if(position > 0)
        {
          newTR.className = "highlightrow";
          updateKeywordValue(newTR);
          position--;
          // scroll up if the current window is no longer valid
          if(position<minVisiblePosition)
          {
            oScroll = document.getElementById("scroll");
            oScroll.scrollTop -= 18;
            maxVisiblePosition -= 1;
            minVisiblePosition -= 1;
          }   
        }     
        else
          if(position == 0)
            position--;
        e.cancelBubble = true;
        e.returnValue = false;
        isKeyUpDownPressed = true;  
      }     
  }
		}

		var brandid = "";
		var mainid = "";
		var subid = "";
		var subsubid = "";
		var sortid = "1";
		
		if(querySt("brandid") != "")
			brandid = querySt("brandid");

		if(querySt("maincatid") != "")
			mainid = querySt("maincatid");

		if(querySt("subcatid") != "")
			subid = querySt("subcatid");

		if(querySt("subsubcatid") != "")
			subsubid = querySt("subsubcatid");

		if(querySt("sortid") != "")
			sortid = querySt("sortid");

		if(brandid != '') loadLogo(brandid);

		if(sortid == 2) {
			brandid = mainid;
			mainid = subid;
			subid = querySt("subsubcatid");
		}
	
		
		 $(document).ready(function() {

			//Load menu
			//$.get("/AudioBizz/assets/common/themes/live/CatMenuServer.aspx?SortID="+sortid+"&MerkID="+brandid+"&MainID="+mainid+"&SubID="+subid+"&SubSubID="+subsubid, function(response) {
			//	$("td#tdCatMenu").html(response).show();
			//});

			$.ajax({
  				url: "/AudioBizz/assets/common/themes/live/CatMenuServer.aspx?SortID="+sortid+"&MerkID="+brandid+"&MainID="+mainid+"&SubID="+subid+"&SubSubID="+subsubid,
  				success: function(response){
    				$("td#tdCatMenu").html(response);
  				}
			});

			//End Load menu


			$("a[rel^='lightbox']").prettyPhoto({
			animationSpeed: 'normal', /* fast/slow/normal */
			padding: 40, /* padding for each side of the picture */
			opacity: 0.35, /* Value betwee 0 and 1 */
			showTitle: false, /* true/false */
			allowresize: true, /* true/false */
			counter_separator_label: ' van ', /* The separator for the gallery counter 1 "of" 2 */
			theme: 'light_rounded' /* light_rounded / dark_rounded / light_square / dark_square */
			});


			$('div#divRemember').qtip({ content: 'Wilt u uw inloggegevens bewaren om sneller te kunnen inloggen? Klik dan op het selectievakje naast het slot', position: 'bottom', nudge_top:1})
			/*
			$('div#divmerk1').qtip({content:'Audio & Much More', position:'bottom',nudge_top:0});
			$('div#divmerk2').qtip({content:'Professional Audio', position:'bottom',nudge_top:0});
			$('div#divmerk3').qtip({content:'Installation Audio', position:'bottom',nudge_top:0});
			$('div#divmerk4').qtip({content:'Accessoires', position:'bottom',nudge_top:0});
			$('div#divmerk5').qtip({content:'Flightcases', position:'bottom',nudge_top:0});
			$('div#divmerk6').qtip({content:'Hardware & Stands', position:'bottom',nudge_top:0});
			$('div#divmerk7').qtip({content:'Cables & Connectors', position:'bottom',nudge_top:0});
			$('div#divmerk8').qtip({content:'Racks & Stands', position:'bottom',nudge_top:0});
			$('div#divmerk9').qtip({content:'Cable crossovers', position:'bottom',nudge_top:0});
			$('div#divmerk10').qtip({content:'VideoSystems & Interfaces', position:'bottom',nudge_top:0});
			$('div#divmerk11').qtip({content:'Professional Speakers', position:'bottom',nudge_top:0});
			$('div#divmerk12').qtip({content:'Mixers & Speakers', position:'bottom',nudge_top:0});
			$('div#divmerk13').qtip({content:'Audio Tools', position:'bottom',nudge_top:0});
			$('div#divmerk14').qtip({content:'Connectors', position:'bottom',nudge_top:0});
			$('div#divmerk15').qtip({content:'Cable & Connectors', position:'bottom',nudge_top:0});
			$('div#divmerk16').qtip({content:'Digital Audio Systems', position:'bottom',nudge_top:0});
			*/
			

			setScrollbars();
		

			//setTimeout("ScrollMenu()",1000);
		
		});

		$.ajax({
  			url: "/AudioBizz/assets/common/themes/live/CatMenuServer.aspx?SortID="+sortid+"&MerkID="+brandid+"&MainID="+mainid+"&SubID="+subid+"&SubSubID="+subsubid,
  			success: function(response){
    			$("td#tdCatMenu").html(response);
  			}
		});

		window.onresize = setScrollbars;

