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 printpage() {
	if (window.print) {
		window.print();
	} else {
		alert('U kunt deze pagina printen in het menu bestand - afdrukken.');
	}
}		

		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 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&ThemeID=live", 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)+"&ThemeID=live", function() {
				      	$("a").css("cursor", "auto");
			});


			if(sortid == 1 && merkid == '' && mainid == '' && subid == '') {
					   var strnav = escape("<a href='#' class='navLink'>Sorteer op merk</a>");
    					   loadNav(strnav);		   

			}
			else if(sortid == 2 && merkid == '' && mainid == '' && subid == '') {
					   var strnav = escape("<a href='#' class='navLink'>Sorteer op categorie</a>");
    					   loadNav(strnav);
				           
					   
			}
			else {
					
				$.get("/AudioBizz/assets/common/themes/live/NavigationCatServer.aspx?SortID="+sortid+"&MerkID="+escape(merkid)+"&MainID="+mainid+"&SubID="+escape(subid)+"&SubSubID=0", function(response) {
					    	$("span#divNav").html(response).show();
				});

					
			}
			
			scroll(0,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&ThemeID=live", function(response) {
					    $("td#tdCatMenu").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) {
					    $("span#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 == "")) {
        			document.getElementById('divSearchResults').style.display = "none";
    			}
    			else {
				$.get("/AudioBizz/assets/common/themes/live/JSearchResultsServer.aspx?KeyWords="+escape(keywords.value), function(response) {
					$("div#divSearchResults").html(response).show();
				});

    				document.getElementById('divSearchResults').style.display = "inline";
    			}
				    
		};

		function hidesearchresults() {	

        		document.getElementById('divSearchResults').style.display = "none";
				    
		};

		function ShowDivAccount() {	

			document.getElementById('divAccount').style.display = "inline";

			document.getElementById('divKlantenService').style.display = "none";
    					    
		};

		function ShowDivKlantenService() {	

    			document.getElementById('divKlantenService').style.display = "inline";
			
			document.getElementById('divAccount').style.display = "none";
    					    
		};

		function CloseDivs()
		{
				
			document.getElementById('divAccount').style.display = "none";
			
			document.getElementById('divKlantenService').style.display = "none";        				
    				
		}

		function ShowDiv(divID)
		{
			if(document.getElementById(divID).style.display=='none')
				document.getElementById(divID).style.display='block';
			else
				document.getElementById(divID).style.display='none';
		}

		function HideDiv(divID)
		{
			document.getElementById(divID).style.display='none';
		}


		function popupMovie() {
		
			var hpos = ((document.body.clientWidth-640)/2);
			var vpos = ((document.body.clientHeight-360)/2);
			var win=dhtmlwindow.open('frmMovie', 'iframe', 'http://www.youtube.com/embed/soJvzydn-aM?rel=0&autoplay=1', 'Audiobizz Movie', 'width=640px,height=360px,left='+hpos+'px,top=100px,resize=0,scrolling=0','recal');
		}

		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 timer;
        	var speed = 7;

        	function scrollIt(id,dir)
        	{
            		var divObj = document.getElementById(id);

            		if (dir == 1)
            		{
                		divObj.scrollLeft -= speed;
                		timer = setTimeout('scrollIt("'+id+'",1)',1);
            		}
            		else if (dir == 2)
            		{
                		divObj.scrollLeft += speed;
                		timer = setTimeout('scrollIt("'+id+'",2)',1);
            		}
        	}

        	function stopScroll()
        	{
            		if (timer)
                		clearTimeout(timer);
        	}

		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+"&ThemeID=live", 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+"&ThemeID=live",
  				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})
			
			*/


			if(querySt("sale") == "1")
				loadCat('1','Sale','','');

		});

