// GEN basis
// GEN basis
function popup(url,winName,W,H,X,Y) {
	if(W == undefined) W = 400;	//default width
	if(H == undefined) H = 300; //default height
	if(X == undefined) X = screen.width/2-W/2; //default Xpos (is now centered)
	if(Y == undefined) Y = screen.height/2-H/2; //default Ypos (is now centered)
	X = 10;
	Y = 10;
	winprops = 'height='+H+',width='+W+',top='+X+',left='+Y+',scrollbars=yes, resizable=yes';

	win = window.open(url, winName, winprops);
	if (parseInt(navigator.appVersion) >= 4) {
		win.window.focus();
	}
}

function stocks(id){
	for(var i = 1; i <5; i++)
	{
		document.getElementById('tab_'+i).style.display = 'none';
		document.getElementById('stocklink'+i).className =  '';
	}
	
	document.getElementById('tab_'+id).style.display = 'block';
	document.getElementById('stocklink'+id).className =  'active';
}
function ignoreenter(myfield,e)
		{
			var keycode;
			if (window.event) keycode = window.event.keyCode;
			else if (e) keycode = e.which;
			else return true;
			
			if (keycode == 13)
			   {
				 
				  
				   return false;
			   }
			else
				 return true;
		}
function $rgb(id)
{

	return document.getElementById(id);	
}
function hide(id)
{
		if($rgb(id) == null) return
	$rgb(id).style.display = 'none';
}
function show(id)
{
	if($rgb(id) == null) return
	
	$rgb(id).style.display = 'block';
}
function isHidden(id)
{
	if($rgb(id).style.display == 'none')
		return true;
	else
		return false;
}

function V_switch(id)
{
	if(isHidden(id))
		show(id);
	else
		hide(id);
}
function switchPaymentMethod(id)
{
	for(var i=1; i<=3 ; i++)
	{
		if( $rgb('payment_method_'+i) != null)
		hide('payment_method_'+i);
	}
	if(id != -1)
	show('payment_method_'+id);
}
function getKorting()
{
	korting = $rgb('kortingscode').value;
	if($rgb('korting_code_1') != null) $rgb('korting_code_1').value = korting;
	if($rgb('korting_code_2') != null)$rgb('korting_code_2').value = korting;
	if($rgb('korting_code_3') != null)$rgb('korting_code_3').value = korting;
	
}
var ogonepay = '';
function paypicker(val)
{
	ogonepay = val;
	if(val == '-1') return;
	
	if(val == 'overschrijving')
	{
		hide('ogonepay_id');
		show('bankpay_id');
	}else if(val == "paypal")
	{
		
	
		hide('ogonepay_id');
		hide('bankpay_id');
		show('paypalpay_id');
		$rgb('paypalpay_id').style.visibility = 'visible';
		
	}
	else{
		show('ogonepay_id');
		$rgb('ogonepay_id').style.visibility = 'visible';
		hide('paypalpay_id');
		hide('bankpay_id');
		//$('ogonepm').value = "CreditCard"
		//$('ogonebrand').value = val;
	}
	
				
	
}
function paypalPay()
{
		$rgb('form_paypal').submit();

}
function bankPay()
{
	
	setCookie("basket", '', 30, '/', '', '');	
	
	$rgb('bankpayform').submit();
}
var type = '';
function ogonePay()
{	
	//setCookie("basket", '', 30, '/', '', '');	
	
	 type = $rgb('payment_picker_select').options[$rgb('payment_picker_select').selectedIndex].value;
	
	$rgb('ogone_payment_type').value = type;	
		
	myRequestOgone.update( $rgb('checkoutform_anon'), 'POST');	
	
	
	
	
}
function submitOgoneForm()
{
	$rgb('form_ogone_'+type).submit();
}
function bankPay_tickets()
{
	var str = readDeelnemers();
	if( str == 0) return;
	setDeelnemers("bankPay()", str);	
	
	
}
function ogonePay_tickets()
{	
	var str = readDeelnemers();
	if( str == 0) return;
	setDeelnemers("ogonePay()", str);	
	
	

	
}

function addClassName(objElement, strClass, blnMayAlreadyExist){
   if ( objElement.className ){
      var arrList = objElement.className.split(' ');
      if ( blnMayAlreadyExist ){
         var strClassUpper = strClass.toUpperCase();
         for ( var i = 0; i < arrList.length; i++ ){
            if ( arrList[i].toUpperCase() == strClassUpper ){
               arrList.splice(i, 1);
               i--;
             }
           }
      }
      arrList[arrList.length] = strClass;
      objElement.className = arrList.join(' ');
   }
   else{  
      objElement.className = strClass;
      }
}

//http://www.bigbold.com/snippets/posts/show/2630
function removeClassName(objElement, strClass){
   if ( objElement.className ){
      var arrList = objElement.className.split(' ');
      var strClassUpper = strClass.toUpperCase();
      for ( var i = 0; i < arrList.length; i++ ){
         if ( arrList[i].toUpperCase() == strClassUpper ){
            arrList.splice(i, 1);
            i--;
         }
      }
      objElement.className = arrList.join(' ');
   }
}
var push_active = -1;
function push(id)
{	
	if(push_active != -1)
	{
		pop();
	}
	push_active = id;
	if( id == 21)
	{
		if($rgb('subbar').style.display != "block")
	
		
		
		$rgb('subbar').style.display = 'block';
		
	}else if( id = 50)
	{
		if($rgb('subbar2').style.display != "block")
	
		
		
		$rgb('subbar2').style.display = 'block';	
	}
	
	addClassName( $rgb('poplink'+id), "backgrounded");
}
function pop()
{
	
	removeClassName( $rgb('poplink21'), "backgrounded");
	removeClassName( $rgb('poplink50'), "backgrounded");
	
	if( push_active == 21)
	{
			$rgb('subbar').style.display = 'none';
	}else{
		$rgb('subbar2').style.display = 'none';
	}
	push_active = -1;
	
}
active_book_top5 = "small_1";
busy_top5 = false
function initTop5(id)
{
	opacityTween = new OpacityTween(document.getElementById('small_'+id),Tween.regularEaseIn, 100, 100, 0.1);
	opacityTween.start()
}
function showSmallBook(id)
{
	if(active_book_top5 != id && !busy_top5)
	{
		busy_top5 = true;
		opacityTween2 = new OpacityTween(document.getElementById(active_book_top5),Tween.regularEaseIn, 100, 40, 0.2);
		opacityTween2.start()
		opacityTween2.onMotionFinished = function(){busy_top5 = false;};
		
		opacityTween = new OpacityTween(document.getElementById(id),Tween.regularEaseIn, 40, 100, 0.2);
		opacityTween.start()
		
		new_big = id.replace("small", "big");
		old_big = active_book_top5.replace("small", "big");
		show(new_big);
		show(old_big);
		opacityTween3 = new OpacityTween(document.getElementById(new_big),Tween.regularEaseIn, 0, 100, 0.30);
		opacityTween3.start()
		opacityTween4 = new OpacityTween(document.getElementById(old_big),Tween.regularEaseIn, 100, 0, 0.30);
		opacityTween4.start()
		
		
		
		active_book_top5 = id;
		
	}
	
}
// GEN basis
// AJAX basis
	
var parsing_xml = false;
var lang = "";
function loadXMLFromText(xmlData)
{
	if (window.ActiveXObject) {
			//for IE
			xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
			xmlDoc.async="false";
			xmlDoc.loadXML(xmlData);
			return xmlDoc;
		} else if (document.implementation && document.implementation.createDocument) {
			//for Mozila
			parser=new DOMParser();
			xmlDoc=parser.parseFromString(xmlData,"text/xml");
			return xmlDoc;
		}

}
function moveto(url)
{
	window.location = url;	
}
function replacewww(text) { 
	var start = (text.indexOf("www"))-7; 
	var match = text.substr(start,7); 
	if(match != "http://" || match != "ttps://") 
	{ 
	text = text.replace("www", "http://www"); 
	} 
	
	 
	return text; 
}
function replaceURLWithHTMLLinks(text) { 
	var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig; 
	return text.replace(exp,"<a href='$1' >$1</a>"); 
}


function processXmlTwitter(response)
{
	parsing_xml =false; 
	xmlDoc=loadXMLFromText( response );
	var str = xmlDoc.getElementsByTagName("text")[0].childNodes[0].nodeValue; 
	 
	str = replacewww(str); 
	str = replaceURLWithHTMLLinks(str); 
	$rgb('twittertxt').innerHTML=  "<p>"+str+"</p>";
	show('twitter');
	
	
}
														
function processData(responseText, responseStatus)
	 { 
		
		//document.getElementById('loadingbar').style.display ='none';
		if (responseStatus==200) // succes
		{
			if(responseText == 'error')
							alert('Error updating data!'+responseText);
			else
			{
				if(parsing_xml)
					processXmlTwitter(responseText);
				else
				{
					//alert(responseText);
					eval(responseText);
				}
				
			}
		 }
		else if(responseStatus == 0)
		{
		
		}
		else 
		{ 
		   alert(responseStatus + ' -- Error Processing Request');
		}
	  }
function ajaxObject(url) {
		  var that=this;      
		   this.updating = false;
			  this.abort = function() {
					that.AJAX.onreadystatechange = function () {}
				  that.updating=false;
				  that.AJAX.abort();
				  that.AJAX=null;
				
			  }
		  this.update = function(form,postMethod) { 
			if(that.updating) that.abort();
			 that.AJAX = null;                      
			 var passData = getFormValues(form,"validate");
			 
			 
					
			if (window.XMLHttpRequest) {              
			  that.AJAX=new XMLHttpRequest();              
			} else {                                  
			  that.AJAX=new ActiveXObject("Microsoft.XMLHTTP");
			}                                             
			if (that.AJAX==null) {                             
			  return false;                               
			} else {
			
				
				  that.AJAX.onreadystatechange = function() {  
					if (that.AJAX.readyState==4) {             
					  that.updating=false;                
					  that.callback(that.AJAX.responseText,that.AJAX.status);        
					  that.AJAX=null;                                         
					} 
					}
																
			  that.updating = new Date();                              
			  if (/post/i.test(postMethod)) {
				var uri=urlCall+'?'+that.updating.getTime();
				that.AJAX.open("POST", uri, true);
				that.AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
				//that.AJAX.setRequestHeader("Content-Length", passData.length);
				that.AJAX.send(passData);
			  } else {
				var uri=urlCall+'?'+passData+'&timestamp='+(that.updating.getTime()); 
				that.AJAX.open("GET", uri, true);                             
				that.AJAX.send(null);                                         
			  }              
			  return true;                                             
			}                                                                           
		  }
		  var urlCall = url;        
		  this.callback = processData;
		  }
		  
		
	
function getFormValues(fobj,valFunc, url) 			
	{ 
	
	   var str = ""; 
	
	   var valueArr = null; 
	
	   var val = ""; 
	
	   var cmd = ""; 
	
	   for(var i = 0;i < fobj.elements.length;i++) 
	
	   { 
	
		   switch(fobj.elements[i].type) 
	
		   { 
			case "checkbox":
					var myval = fobj.elements[i].checked;
					if(myval) 
						myval = 1;
					else
						myval = 0;								   
				   str += fobj.elements[i].name + 
	
					"=" + myval + "&"; 
	
					   break; 
			  case "textarea":
				 str += fobj.elements[i].name + 
	
						 "=" + escape(fobj.elements[i].value) + "&"; 
						 break; 
		   
				case "password":
					str += fobj.elements[i].name + 
	
						 "=" + escape(fobj.elements[i].value) + "&"; 
						  break; 
				case "hidden":
					str += fobj.elements[i].name + 

					 "=" + (fobj.elements[i].value) + "&"; 
					  break; 
			   case "text": 
	
							
					str += fobj.elements[i].name + 
	
					 "=" + escape(fobj.elements[i].value) + "&"; 
	
					 break; 
	
			   case "select-one": 
	
					str += fobj.elements[i].name + 
	
					"=" + fobj.elements[i].options[fobj.elements[i].selectedIndex].value + "&"; 
	
					break; 
	
		   } 
	
	   } 
							
				
					 
					 
	   str = str.substr(0,(str.length - 1)); 
	
	   return str; 
	
	}


	
//  ADMIN basis
function addListener(element, type, expression)
{
if(window.addEventListener)	
{
 // Standard
 element.addEventListener(type, expression, false);
 return true;
 }
  else if(window.attachEvent)
   { // IE	
	element.attachEvent('on' + type, expression);	
	return true;	
}
 else return false;
}

//addListener(document, "keyup", function (e) { if (!e) { e = event; } if (e.keyCode == 27) { document.location.href = "http://www.horecabelfine.be/beheer/index.php"; } } );
//  ADMIN basis

// books magic
var busy = new Array();
var tween_array = new Array();
var nr_array = new Array();
var loaded = new Array();

function subscribe(name)
{
	
	var myRequestBooks = new ajaxObject( 'http://www.horecabelfine.be/'+'ajax/subscribe.php');
	myRequestBooks.update( $rgb('nmform'), 'POST');


}
function contact_gt()
{
	$rgb('nmform').innerHTML = "<p>Bedankt voor uw interesse!</p>";
}
function unlock(name)
{
	busy[name] = false;
}
function setControls(name, number)
{
	var total = 5;
	if(lang == "en") total = 2;
	for(var i = 1; i <=total; i++)
	{
		$rgb(name+"_"+i).className = "inactive";
	}
	$rgb(name+"_"+number).className = "active";
}
function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

// search suggester
var ss_active = false;
var myRequestSS = new ajaxObject( 'http://www.horecabelfine.be/'+'ajax/searchsuggest.php');
var last_lookup  = '';
var active_sugg = -1;
function setActiveSuggestion()
{
	var total = $rgb('ajaxsuggestions').childNodes.length;
	for( var i = 0; i < total ; i++)
		removeClassName( $rgb('result_'+i) ,'active') 
		
	addClassName(  $rgb('result_'+active_sugg) ,'active');
	
}
function  setActiveSuggestionUp( )
{
	// get sugg. count
	var total = $rgb('ajaxsuggestions').childNodes.length;
	
	if( active_sugg == -1) active_sugg = total-1;
	else if( active_sugg == 0) active_sugg = total-1;
	else
		active_sugg--;
	setActiveSuggestion();
}
function  setActiveSuggestionDown( )
{
	// get sugg. count
	var total = $rgb('ajaxsuggestions').childNodes.length;
	
	if( active_sugg == -1) active_sugg = 0;
	else if( active_sugg == total-1) active_sugg = 0;
	else
		active_sugg++;
	setActiveSuggestion();
}
function gotoActiveSuggestion()
{
	window.location = $rgb('result_'+active_sugg).href;
}
function searchenter(myfield,e)
{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	
	if (keycode == 13)
	   {
		  gotoActiveSuggestion();
		   return false;
	   }
	else
		 return true;
}
function searchSuggest( e){
var KeyID = e.keyCode;


switch(KeyID)

   {

     
      case 38:
	  if( ss_active )
	  {
		  setActiveSuggestionUp( );
		  return;
		}
      case 40:
	  if( ss_active )
	  {
          setActiveSuggestionDown( );
		 return; 
		}
     
	 
   }




	if( last_lookup == $rgb('searchbox').value) return;
	if($rgb('searchbox').value.length >= 3)
	myRequestSS.update( $rgb('searchform'), 'POST');
	//ajaxsuggestions
	last_lookup = $rgb('searchbox').value; 
	ss_active = true;
}

					
// allbooks magic
var myRequestAllBooks = new ajaxObject( 'http://www.horecabelfine.be/'+'ajax/allbooks.php');
var done = false;
function allBooks(id)
{
	if(done){ 

		if(lang == 'nl')
			alert('Alle boeken worden reeds weergegeven');
		else if (lang == 'fr')
			alert('Tous les livres sont déja affichés');
		else 
			alert('All books are already displayed');

	return;} 
	myRequestAllBooks.update( $rgb('allbooksform'), 'POST');
	done = true;

}
// productfiles magic
var myRequestPF = new ajaxObject( 'http://www.horecabelfine.be/'+'ajax/fetchfiles.php');
function fetchFiles(id)
{
	$rgb('ajax_product_id').value = id;
	myRequestPF.update( $rgb('ajax_fetchproduct_form'), 'POST');

}

// account magic
var myRequestAccount = new ajaxObject( 'http://www.horecabelfine.be/'+'ajax/account.php');

function changeInfo()
{
	myRequestAccount.update( $rgb('account_form'), 'POST');	
}

// contact magic
var myRequestContact = new ajaxObject( 'http://www.horecabelfine.be/'+'ajax/contact.php');

function Contact()
{
	myRequestContact.update($rgb('contactform'), 'POST');
}

// contact magic
var myRequestContact2 = new ajaxObject( 'http://www.horecabelfine.be/'+'ajax/newsletter.php');

function newsletter()
{
	myRequestContact2.update($rgb('contactform'), 'POST');
}
function contact_gt2()
{
	window.location = "http://www.horecabelfine.be/nl/bedankt-vooruwaanvraag";
}
function contact_gt3()
{
	window.location = "http://www.horecabelfine.be/nl/bedankt-inschrijving";
}

// search magic
function search()
{
 $rgb('searchform').submit();
}
function searchFocus(obj)
{
	if(obj.value == "Zoek...")
		obj.value =  "";
	if(obj.value == "Search...")
		obj.value =  "";
}
function searchBlur(obj)
{
	if(lang == "nl")
	{
		if(obj.value == "")
			obj.value = "Zoek...";
	}
	else
	{
		if(obj.value == "")
			obj.value = "Search...";
	}
	
}
// login magic
var myRequestLogin = new ajaxObject( 'http://www.horecabelfine.be/'+'ajax/login.php');
var myRequestPW = new ajaxObject( 'http://www.horecabelfine.be/'+'ajax/pwreset.php');

function moveToUrl(url)
{
	window.location = url;
}

function doPwReset()
{	 
 
	myRequestPW.update($rgb("pwresetform") , "POST" );	
}
///////////////////////////
///////// SHOPPING CART
///////////////////////////

function emptyBasketShop()// updated to manage abonnement information and options
{
	setCookie("basket", '', 30, '/', '', '');	
	setCookie("abonnement_bool", '', 30, '/', '', '');	
	setCookie("options_int", '', 30, '/', '', '');	
	
	window.location = "http://www.horecabelfine.be/"+lang+"/shop";		
}
//  SHOP basis

/* cart functions */
var baseurl = "http://www.horecabelfine.be/";
var stricturl = "http://www.horecabelfine.be/";

//////////// SHOPPING CART start
function setCookie( name, value, expires, path, domain, secure )
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );


if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}
function setCookie2 (name, value, lifespan, access_path) {
      
  var cookietext = name + "=" + escape(value)  
    if (lifespan != null) {  
      var today=new Date()     
      var expiredate = new Date()      
      expiredate.setTime(today.getTime() + 1000*60*60*24*lifespan)
      cookietext += "; expires=" + expiredate.toGMTString()
    }
    if (access_path != null) { 
      cookietext += "; PATH="+access_path 
    }
   document.cookie = cookietext 
   return null  
}
function get_cookie ( cookie_name )
{
  var results = document.cookie.match ( cookie_name + '=(.*?)(;|$)' );

  if ( results )
	return ( unescape ( results[1] ) );
  else
	return '';
}	

function add(new_item){ // deprecated

	var old_amount = deleteOrderReturnAmount(new_item);
	basket_string = get_cookie("basket");
	
	var p_fid = ''+( parseInt($rgb('aantal').options[$rgb('aantal').selectedIndex].value) + parseInt(old_amount));
	

	if(basket_string == '' || basket_string == null)
		basket_string = new_item + 'fff' + p_fid;
	else
		basket_string = basket_string + "xxx" + new_item + 'fff' + p_fid;
	
	setCookie("basket", basket_string, 30, '/', '', '');
	
	window.location = 'http://www.horecabelfine.be/'+lang+'/winkelwagentje';
}
function buyNowInSize()
{
	var amount= $rgb('amount').options[$rgb('amount').selectedIndex].value ;
	
	buyNow( $rgb('maat').options[$rgb('maat').selectedIndex].value , amount);
}
function SaveScrollXY() {
$rgb('ScrollXX').value = 0;
$rgb('ScrollYY').value = scrollTop();
}
function ResetScrollPosition() {
	
	init();
	
	$rgb('navbar_left').style.left = (  parseInt($rgb('content').offsetLeft )   )+"px";
	 show('navbar_left');
	 $rgb('navbar_right').style.left = (  parseInt($rgb('content').offsetLeft )   +780)+"px";
	 show('navbar_right');
	 
	 var hidx, hidy;
	hidx = 0;
	hidy = $rgb('ScrollYY').value;
		
		
	if( (window.location+"").indexOf("#") != -1)
	{
		onscrollFunc();
		return;
	}
		

	
	
	if (typeof hidx != 'undefined' && typeof hidy != 'undefined') {

		window.scrollTo(hidx, hidy);
		
	}

	
	
	
	// set fix pos.
}
window.onresize = function() { 

$rgb('navbar_left').style.left = (  parseInt($rgb('content').offsetLeft )   )+"px";
	 show('navbar_left');
	 $rgb('navbar_right').style.left = (  parseInt($rgb('content').offsetLeft )   +780)+"px";
	 show('navbar_right');

	 };

function addinstant(new_item,  amount){ // updated to manage abonnement information and options
	
	

	new_item = new_item.toString();
	
	
	
	var old_amount = deleteOrderReturnAmount(new_item);
	basket_string = get_cookie("basket");
	
	var p_fid = ''+( parseInt(amount) + parseInt(old_amount));
	

	if(basket_string == '' || basket_string == null)
	{
		basket_string = new_item + 'fff' + p_fid;
		
	}else
	{
		basket_string = basket_string + "xxx" + new_item + 'fff' + p_fid;
		
	}
	setCookie("basket", basket_string, 30, '/', '', '');
	$rgb('force_product_show').value = new_item;
	SaveScrollXY();
	$rgb('Form1').submit();
	//window.location = 'http://www.horecabelfine.be/'+lang+'/assortiment';
}

function buyNow(id)  // updated to manage abonnement information
{
	var obj = $rgb('product_'+id);
	var val = obj.value;
	deleteOrderReturnAmount(id);
	var amount = parseInt(val);
	
	if(  isNaN(amount) && amount != ""  && amount != 0 && amount != "0")
	{
		alert("Gelieve een geldig aantal in te geven.");
		return;
	}
	if(amount == 0 || amount == "0")
	{
		deleteOrderReturnAmount(id);
		SaveScrollXY();
		$rgb('Form1').submit();
		return;
	}
	
	add_str = id;
		
	addinstant(add_str, amount);
}
function confirmDeleteOrder(id)
{
	if(lang == "nl")
	{
		 if (confirm("Bent u zeker dat u dit product wilt verwijderen uit het winkelwagentje?")) {
		deleteOrder(id);
	  }
	  
	}else if(lang == "fr")
	{
		 if (confirm("Êtes-vous certain de vouloir supprimer ce produit de votre panier d'achat?")) {
		deleteOrder(id);
	  }
	}else  if(lang == "en")
	{
	if (confirm("Are you sure you want to take this book out of your shopping cart?")) {
		deleteOrder(id);
	  }
	}else  if(lang == "de")
	{
	if (confirm("Sind Sie sicher, dass Sie dieses Produkt aus Ihrem Einkaufskorb entfernen wollen?")) {
		deleteOrder(id);
	  }
	}
	
	
	
	
	
	 
	
}
function deleteOrder(id)   // updated to manage abonnement information and options
{
	// special -> only delete one amount from this item
	basketstr = get_cookie("basket");
	abonnement_bool_string = get_cookie("abonnement_bool");
	options_int_string = get_cookie("options_int");

	new_basketstr = "";
	new_abonnement_bool_string = "";
	new_options_int_string = "";
	
	if(basketstr == "")return;
	
	var myarray = basketstr.split("xxx");
	var myarray_abonnement_bool = abonnement_bool_string.split("xxx");
	var myarray_options_int = options_int_string.split("xxx");
	var found = false;

	for(var i = 0; i<myarray.length;i++)
	{
		var temparray = myarray[i].split("=");
		var tmp = temparray[0].split("fff");
		
		if(id != tmp[0] || found)
		{
			
			if(i > 0)
			{
				new_basketstr += "xxx";
				new_abonnement_bool_string += "xxx";
				new_options_int_string += "xxx";
	
			}
			
			new_basketstr += temparray[0];		
			new_abonnement_bool_string += myarray_abonnement_bool[i];	
			new_options_int_string += myarray_options_int[i];			
		}else
		{found = true;
			if(tmp[1] > 1 && 0)
			{
				if(i > 0)
				{
					new_basketstr += "xxx";
					new_abonnement_bool_string += "xxx";
					new_options_int_string += "xxx";
				}
				new_basketstr += tmp[0]+'fff'+(tmp[1]-1);	
				new_abonnement_bool_string += myarray_abonnement_bool[i];	
				new_options_int_string += myarray_options_int[i];					
			}
		
		}
	}	
	
	//alert(new_basketstr);
	setCookie("basket", new_basketstr, 30, '/', '', '');	
	
	
	
	window.location = 'http://www.horecabelfine.be/'+lang+'/winkelwagentje';
}
function emptyBasketShop()  // updated to manage abonnement information and options
{
	setCookie("basket", '', 30, '/', '', '');	
	setCookie("abonnement_bool", '', 30, '/', '', '');	
	setCookie("options_int", '', 30, '/', '', '');

	window.location = "http://www.horecabelfine.be/nl/assortiment";		
}
function deleteOrderReturnAmount(id)  // updated to manage abonnement information and options
{
	basketstr = get_cookie("basket");
	abonnement_bool_string = get_cookie("abonnement_bool");
	options_int_string = get_cookie("options_int");

	new_basketstr = "";
	new_abonnement_bool_string = "";
	new_options_int_string = "";
	
	var found_amount = 0;
		
	if(basketstr == "")
		return found_amount;
	
	var myarray = basketstr.split("xxx");
	var myarray_abonnement_bool = abonnement_bool_string.split("xxx");
	var myarray_options_int = options_int_string.split("xxx");
	
	var found = false;

	for(var i = 0; i<myarray.length;i++)
	{
		var temparray = myarray[i].split("=");
		
		var tmp = temparray[0].split("fff");
		if(id != tmp[0] || found)
		{
			
			if(i > 0)
			{
				new_basketstr += "xxx";
				new_abonnement_bool_string += "xxx";
				new_options_int_string += "xxx";
	
			}
			new_basketstr += temparray[0];			
			new_abonnement_bool_string += myarray_abonnement_bool[i];	
			new_options_int_string += myarray_options_int[i];			
		}else
		{
			found = true;
			found_amount = tmp[1];
			
			
		}
	}	
	
	
	setCookie("basket", new_basketstr, 30, '/', '', '');	
	setCookie("abonnement_bool", new_abonnement_bool_string, 30, '/', '', '');
	setCookie("options_int", new_options_int_string, 30, '/', '', '');

	return found_amount;
}


// shopping cart editor
function editAmount( id)
{	
	var old = parseInt($rgb('amount_'+id).innerHTML);
	$rgb('editdata_'+id).innerHTML = "<input onkeypress='return submitenter(this,event, "+id+")' ' type='text' id='inputdata_"+id+"' value='"+old+"'/>";
	$rgb('editlink_'+id).className = 'confirmamount';
	$rgb('editlink_'+id).href = 'javascript:confirmQuantity('+id+')';
	
	
	$rgb('inputdata_'+id).focus();
}
function entersubmitter(myfield, e, id)
{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	
	if (keycode == 13)
	   {
		buyNow(id)
		return false;
	   }
	else
		 return true;
}	


function submitenter(myfield,e, id)
{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	
	if (keycode == 13)
	   {
		confirmQuantity(id);
		return false;
	   }
	else
		 return true;
}
function IsNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }

function confirmQuantity(id, new_amount)   // updated to manage abonnement information and options
{
	var newdata = new_amount;
	if(!IsNumeric(newdata)) 
	{
		alert('Gelieve een cijfer op te geven!'); return;
	}
	
	// special -> only delete one amount from this item
	basketstr = get_cookie("basket");
	abonnement_bool_string = get_cookie("abonnement_bool");
	options_int_string	= get_cookie("options_int");

	new_basketstr = "";
	new_abonnement_bool_string = "";
	new_options_int_string = "";
	
	
	if(basketstr == "")return;
	
	var myarray = basketstr.split("xxx");
	var myarray_abonnement_bool = abonnement_bool_string.split("xxx");
	var myarray_options_int = options_int_string.split("xxx");
	
	var found = false;

	for(var i = 0; i<myarray.length;i++)
	{
		var temparray = myarray[i].split("=");
		var tmp = temparray[0].split("fff");
		
		if(id != tmp[0] || found)
		{
			
			if(i > 0)
			{
				new_basketstr += "xxx";
				new_abonnement_bool_string += "xxx";
				new_options_int_string += "xxx";
	
			}
			new_basketstr += temparray[0];	
			new_abonnement_bool_string += myarray_abonnement_bool[i];			
			new_options_int_string += myarray_options_int[i];					
		}else
		{found = true;
			if(newdata > 0)
			{
				if(i > 0)
				{
					new_basketstr += "xxx";
					new_abonnement_bool_string += "xxx";
					new_options_int_string += "xxx";
				}
				new_basketstr += tmp[0]+'fff'+( newdata );	
				new_abonnement_bool_string += myarray_abonnement_bool[i];
				new_options_int_string += myarray_options_int[i];	
			}
		
		}
	}	
	
	//alert(new_basketstr);
	setCookie("basket", new_basketstr, 30, '/', '', '');	
	setCookie("abonnement_bool", new_abonnement_bool_string, 30, '/', '', '');
	setCookie("options_int", new_options_int_string, 30, '/', '', '');

	
	
	window.location = 'http://www.horecabelfine.be/'+lang+'/winkelwagentje';

}
function changeProductAbonnementStatus(id, new_status)
{
	if(new_status == true) new_status = 1;
	else new_status = 0;
	
	basketstr = get_cookie("basket");
	abonnement_bool_string = get_cookie("abonnement_bool");
	
	
	new_abonnement_bool_string = "";
	
		
		
	var myarray = basketstr.split("xxx");
	var myarray_abonnement_bool = abonnement_bool_string.split("xxx");
	
		
	for(var i = 0; i<myarray.length;i++)
	{
		var temparray = myarray[i].split("=");
		
		var tmp = temparray[0].split("fff");
		if(i > 0)
		{
			
			new_abonnement_bool_string += "xxx";
			

		}
			
		if(id != tmp[0] )
		{
			
			
			
			new_abonnement_bool_string += myarray_abonnement_bool[i];	
				
		}else
		{
			
			new_abonnement_bool_string += new_status;	
			
		}
	}	
	
	
	setCookie("abonnement_bool", new_abonnement_bool_string, 30, '/', '', '');
	
	
	
	window.location = 'http://www.horecabelfine.be/'+lang+'/winkelwagentje';
}
function changeProductOption(id, new_option_value)
{
	basketstr = get_cookie("basket");
	abonnement_bool_string = get_cookie("abonnement_bool");
	options_int_string = get_cookie("options_int");

	
	new_options_int_string = "";
	var myarray = basketstr.split("xxx");
	
	var myarray_options_int = options_int_string.split("xxx");
	
	

	for(var i = 0; i<myarray.length;i++)
	{
		var temparray = myarray[i].split("=");
		
		var tmp = temparray[0].split("fff");
		if(i > 0)
			{
				new_options_int_string += "xxx";
	
			}
		if(id != tmp[0] )
		{
			
			
			
			new_options_int_string += myarray_options_int[i];			
		}else
		{
			new_options_int_string += new_option_value;		
			
		}
	}	
	
	
	setCookie("options_int", new_options_int_string, 30, '/', '', '');

	
	
	window.location = 'http://www.horecabelfine.be/'+lang+'/winkelwagentje';
}
///////////////////////////
///////// SHOPPING CART
///////////////////////////

function goToCheckout(logged_in, amount)
{
		if( editing_basket) return;
		if(amount < 12)
		{
			alert('U kan geen bestelling plaatsen onder de 12 dozen. Gelieve uw bestelling aan te vullen.');
			return;
		}	

		if(amount%12 != 0)
		{
			alert('U kan enkel bestellingen plaatsen die een veelvoud zijn van 12. Gelieve uw bestelling te wijzigen.');
			return;
		}		
		/*
		if(logged_in)
		{
			if( $rgb('shipping_method').options[$rgb('shipping_method').selectedIndex].value == -1)
			{
				alert('Gelieve eerst een verzendingsmethode te kiezen.');
				return;
			}
		
		
			$rgb('shippingform').submit();			
		}
		else*/
			window.location = 'http://www.horecabelfine.be/nl/checkout';
	
}
function update_shipping_option()
{
	var sec = $rgb('shipping_option');
	var value = sec.options[sec.selectedIndex].value;
	if(value == -1) return;
	var price = parseFloat(sec.options[sec.selectedIndex].className);
	
	var normale_prijs = parseFloat( $rgb('normale_prijs').innerHTML );
	$rgb('verzending_amount').innerHTML = price;
	$rgb('totaal_amount').innerHTML = price + normale_prijs;


}
//  SHOP basis

// REGFORM basis
function goRegisterForm(bool)
{
	if(bool == 1 ) show('company_form'); else hide('company_form');	
}
function goRegisterForm2(bool)
{
	if(!bool)hide('facturatie_adres_form');else show('facturatie_adres_form');

}
var myRequestRegister = new ajaxObject( 'http://www.horecabelfine.be/'+'ajax/registreren.php');
function suggestValue(id, value)
{
	//if( document.getElementById(id).value == "")
		document.getElementById(id).value = value;
	
	//$('taxcode').className = " text ";
}
function register()
{
	
	myRequestRegister.update( $rgb('register_ajax_form'), 'POST');	
}
function checkEmail(email) {

var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (!filter.test(email)) {


return false;
}
}



var myRequestVAT = new ajaxObject( 'http://www.horecabelfine.be/'+'ajax/vat.php');
var lookup_done = false;
function suggestData(type)
{
	if( lookup_done) return;
	
	$rgb('lookup_type').value = type;
	
	if(type == 1)
	{
		if( checkEmail( $rgb('email').value) == false)return;
		document.getElementById('email').className = ' text activity';
	}else{
		if($rgb('vat').value.length < 10)return;
		document.getElementById('vat').className = ' text activity';
	}
	
	
	myRequestVAT.update( $rgb('checkoutform_anon'), 'POST');	
}


function setCheckbox(id, val)
{
	if(val == "1")
		$rgb(id).checked = true
	else
		$rgb(id).checked = false;
			
}

function addressCheckbox( val)
{
	if( val == "1" )
	{
		$rgb('invoice_address_different').checked = false;
	}else
	{
		$rgb('invoice_address_different').checked = true;
		
		show("invoicing_address");
	}

}



function gotoUrl(mylink)
						{
							window.location = mylink;
						}			
																				
function showAddress(address, title, id) {
							 // if (geocoder) {
							//	geocoder.getLatLng(
							//	  address,
							//	  function(point) {
							//		if (!point) {
							//		  alert(address + " not found");
							//		} else {
									 // map.setCenter(point, 13);
										var point = new GLatLng( 51.088026,4.006692); //Ottergemsesteenweg @
										marker = new GMarker(point);
										GEvent.addListener(marker, "click", function() {    gotoUrl('http://maps.google.be/maps?q=chocdecor&hl=en&ll=51.058876,3.868904&spn=0.186654,0.528374&sll=51.024364,3.731232&sspn=0.011999,0.033023&vpsrc=0&t=m&z=12') });
								
	http://maps.google.be/maps?q=chocdecor&hl=en&ll=51.088026,4.006692&spn=0.001457,0.004128&sll=51.024364,3.731232&sspn=0.011999,0.033023&vpsrc=6&t=m&hq=chocdecor&z=19									 
									  map.addOverlay(marker);
									 // marker.openInfoWindowHtml(title);
							}
		 
function load() {
  if (GBrowserIsCompatible()) {
	map = new GMap2(document.getElementById("gmaps"));
	map.setUIToDefault();
	map.setCenter(new GLatLng( 51.088052,4.006733), 8);
	geocoder = new GClientGeocoder();
	
	GIcon.transparent ="";
	for(var i = 1; i < adres_str.length; i++)
	{
		showAddress( adres_str[i] , marker_str[i], i);	
	}
		//						
  }
}

function showOmschrijving()
{
	if($rgb('links')!= null) {hide('links'); removeClassName( $rgb('thirdh2') ,'active');}
	show('omschrijving');
	hide('tech');
	
	addClassName( $rgb('firsth2') ,'active');
	removeClassName( $rgb('secondh2') ,'active');
}
function showTech()
{
	if($rgb('links')!= null) {hide('links'); removeClassName( $rgb('thirdh2') ,'active');}
	hide('omschrijving');
	show('tech');
	
	removeClassName( $rgb('firsth2') ,'active');
	addClassName( $rgb('secondh2') ,'active');
}
function showLinks()
{
	hide('omschrijving');
	hide('tech');
	show('links');
	
	removeClassName( $rgb('firsth2') ,'active');
	removeClassName( $rgb('secondh2') ,'active');
	
	addClassName( $rgb('thirdh2') ,'active');
}

function showPricehelp()
{
	 $rgb('product_price_helper_fix').innerHTML  =  $rgb('pricehelp').innerHTML;
	 show('product_price_helper_fix');
}	
function hidePricehelp()
{

	hide('product_price_helper_fix');
}


var point = 0;
var max = 5;
var w = 598;
var offset = -12;
var busy = false;
var home_counter=  0;
var pause = false;
function pauser()
{
	
	clearTimeout(timer_home);
	
	$rgb('tools_left').innerHTML = "<a href='javascript:playr()' class='play'></a>";
}
function playr()
{
	
	
	clearTimeout(timer_home);
	recoil();
		
	$rgb('tools_left').innerHTML = "<a href='javascript:pauser()' class='pause'></a>";
}

function recoil(){

	if( home_counter +1 == max)
	{
		goTo(home_counter+1, true)
		timer_home = setTimeout('recoil()', 6500);
	}else
	{
		goTo(home_counter+1)
		timer_home = setTimeout('recoil()', 6500);
	}
	
	
}
function setGoTime()
{

	timer_home = setTimeout('recoil()', 6500);
}

function left()
{
	if(busy==true) return;
	if(point == 0) return;
	
	var new_point = point-1;
	var old_point = point;
	t1 = new Tween(document.getElementById('mediashifter').style,'left',Tween.regularEaseOut,offset-old_point*w, offset-new_point*w  ,0.35,'px');
	t1.onMotionFinished = function(){busy = false;};
		
	t1.start()
	
	busy = true;
	point--;
}
function goTo(count, resetpointer)
{
	if(home_counter == count)return;
	if(busy==true) return;
	
	
	
	var new_point = count;
	var old_point = home_counter;
	

	
	t1 = new Tween(document.getElementById('mediashifter').style,'left',Tween.regularEaseInOut,-old_point*w, -new_point*w  ,1,'px');
	
	if (resetpointer != null)
	{
		t1.onMotionFinished = function(){ busy = false; document.getElementById('mediashifter').style.left = "0px"; home_counter = 0; };
	
	}else
	{
		t1.onMotionFinished = function(){ busy = false;};
	
	}	
		
	t1.start()
	
	busy = true;
	
	home_counter= count;
	
	for(var i = 0 ; i < max; i++)
	{
		removeClassName( $rgb('toolt'+i) , "active");
		
		
	
	}
	
	if (resetpointer != null)
	{
		addClassName( $rgb('toolt0')  , "active");
	}else
	{
		addClassName( $rgb('toolt'+count)  , "active");
	}
	
	
}
function goToAndPause(count)
{
	if(home_counter == count)return;
	if(busy==true) return;
	
	
	var new_point = count;
	var old_point = home_counter;
	
	t1 = new Tween(document.getElementById('mediashifter').style,'left',Tween.regularEaseInOut,-old_point*w, -new_point*w  ,1,'px');
	t1.onMotionFinished = function(){pauser(); busy = false;};
		
	t1.start()
	
	busy = true;
	
	home_counter= count;
	
	for(var i = 0 ; i < max; i++)
	{
		removeClassName( $rgb('toolt'+i) , "active");
		
		
	
	}
	addClassName( $rgb('toolt'+count)  , "active");
	
}
function right()
{
	if(busy==true) return;
	if(point >= max-5) return;
	
	var new_point = point+1;
	var old_point = point;
	t1 = new Tween(document.getElementById('mediashifter').style,'left',Tween.regularEaseOut,offset -old_point*w, offset-new_point*w  ,0.35,'px');
	t1.onMotionFinished = function(){busy = false;};
	
	t1.start()
	
	busy = true;
	point++;
}
function goNav(id)
{
	$rgb('nav_'+(id+1)).className = 'active';
}


jQuery(document).ready(function() {

	
	$("a.fancybox").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'none'
	});
	

});

var s1;var s2;
function scrollTop()
{
	var ScrollTop = document.body.scrollTop;
 
	if (ScrollTop == 0)
	{
		if (window.pageYOffset)
			ScrollTop = window.pageYOffset;
		else
			ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
	}	
	return ScrollTop;
}
window.onscroll = function(e)
{
	onscrollFunc();
}
function onscrollFunc()
{
	if( !ready) return;
	var y = scrollTop();
	y = parseInt(y);
	
	var dest = y;
	if( y >= 200)	
		dest = 0;
		
	if( y < 200)
		dest = (200-y);
	
	if(s1 != null) s1.stop();
	if(s2 != null) s2.stop();
	
	
	$rgb('navbar_left').style.top = dest+"px";
	$rgb('navbar_right').style.top = dest+"px";
	
	/*
	s1 = new Tween($rgb('navbar_left').style,'marginTop',Tween.regularEaseOut, parseInt($rgb('navbar_left').style.marginTop)  ,dest  ,0.15,'px');
	s1.start()
	
	s2 = new Tween($rgb('navbar_right').style,'marginTop',Tween.regularEaseOut, parseInt($rgb('navbar_right').style.marginTop)  ,dest  ,0.15,'px');
	s2.start()
	
	*/
}

var sfeerbeeld_busy = false;
var sfeerbeeld;
var oldgame = 2;
var old_filename;
function showSfeerBeeld(id, filename)
{	
	if(filename == old_filename ) return;
	if( filename == "") return;
	if( sfeerbeeld_busy ) return;
	sfeerbeeld_busy = true;
	
	hide('navbar_rest');
	sfeerbeeld = null;
	sfeerbeeld = new Image;
	
	
	sfeerbeeld.src = 'http://www.rgbcdn.be/8/'+filename+'';
	
	if( sfeerbeeld.complete)
	{
			$rgb('navbar_left').style.backgroundImage = "none";
			var newgame = 2;
				if(oldgame == 2)
					newgame = 1;
					
				old_filename = filename;
				
				show('sfeerbeeld'+newgame);
				$rgb('sfeerbeeld'+newgame).innerHTML ='<div class="h">'+$rgb('tekst_'+id).innerHTML+'</div><img style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(); background:none\9;" alt="" src="http://www.rgbcdn.be/8/'+filename+'"/>';
				
				
				var o1 = opacityTween = new OpacityTween($rgb('sfeerbeeld'+newgame) ,Tween.regularEaseInOut, 0, 100, 0.5);
				o1 .start()
				
				var o2 = opacityTween = new OpacityTween( $rgb('sfeerbeeld'+oldgame) ,Tween.regularEaseInOut, 100, 0, 0.5);
				o2.start()
				o2.onMotionFinished = function(){sfeerbeeld_busy = false;};
			
				
				oldgame = newgame ;
				
			
	}else
	{
		sfeerbeeld.onload = function (e)
		{
			$rgb('navbar_left').style.backgroundImage = "none";
		
			var newgame = 2;
			if(oldgame == 2)
				newgame = 1;
				
			old_filename = filename;
			
			show('sfeerbeeld'+newgame);
			$rgb('sfeerbeeld'+newgame).innerHTML ='<div class="h">'+$rgb('tekst_'+id).innerHTML+'</div><img style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(); background:none\9;" alt="" src="http://www.rgbcdn.be/8/'+filename+'"/>';
			
			
			var o1 = opacityTween = new OpacityTween($rgb('sfeerbeeld'+newgame) ,Tween.regularEaseInOut, 0, 100, 0.5);
			o1 .start()
			
			var o2 = opacityTween = new OpacityTween( $rgb('sfeerbeeld'+oldgame) ,Tween.regularEaseInOut, 100, 0, 0.5);
			o2.start()
			o2.onMotionFinished = function(){sfeerbeeld_busy = false;};
		
			
			oldgame = newgame ;
			
			
		}
	}
}

function changeAmount(e,newvalue, prod_id, go)
	{
		e.cancelBubble = true;
		if (e.stopPropagation) e.stopPropagation();
		var keycode;
		if (window.event) keycode = window.event.keyCode;
		else if (e) keycode = e.which;
		else return true;
		
		if (keycode == 13 || go == 1)
		   {
				
				confirmQuantity(prod_id, newvalue) 
				
			   return false;
		   }
		else
			 return true;
	}
	var editing_basket = false;
	function getReadyToSave(item)
	{
		$rgb('refresh_'+item).style.visibility='visible';
		editing_basket = true;
		$rgb('vlgstapbtn').innerHTML = "Wijzigingen opslaan";
	}
function resetPicker()
{
	$rgb('payment_picker_select').selectedIndex = 0;
}	
var myRequestOgone = new ajaxObject( 'http://www.horecabelfine.be/'+'ajax/getOgoneCheckout.php');

function goOgone(payment_type)
{
	$rgb('ogone_payment_type').value = payment_type;	
		
	myRequestOgone.update( $rgb('checkoutform_anon'), 'POST');	
}
var ready = false;
function init(){
 ready = true;

}

function setInputValue(prod_id, value)
{
	if( $rgb('product_'+prod_id) != null)
	$rgb('product_'+prod_id).value = value;

}

