// 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)
{
		
	$rgb(id).style.display = 'none';
}
function show(id)
{
		
	$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{
		show('ogonepay_id');
		$rgb('ogonepay_id').style.visibility = 'visible';
		hide('bankpay_id');
		//$('ogonepm').value = "CreditCard"
		//$('ogonebrand').value = val;
	}
	
				
	
}
function bankPay()
{
	
	setCookie("basket", '', 30, '/', '', '');	
	
	$rgb('bankpayform').submit();
}
function ogonePay()
{	
	//setCookie("basket", '', 30, '/', '', '');	
	
	$rgb('form_ogone_'+ogonepay).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 == null) return;
   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{
		if( $rgb('subbar2') != null)$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.winewise.be/beheer/index.php"; } } );
//  ADMIN basis

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;
}


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

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

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

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

var myRequestnewsletter = new ajaxObject( 'http://www.winewise.be/'+'ajax/newsletter.php');
function newsletter()
{
	myRequestnewsletter.update($rgb('newsletterform'), 'POST');
}

var myRequestJoinCourse = new ajaxObject( 'http://www.winewise.be/'+'ajax/joincourse.php');
function subscribeToCourse()
{
	myRequestJoinCourse.update($rgb('subscribe_course_form'), 'POST');
}

var myRequestJoinBaseCourse = new ajaxObject( 'http://www.winewise.be/'+'ajax/joinbasecourse.php');
function baseCourse()
{
	myRequestJoinBaseCourse.update($rgb('subscribe_course_form'), 'POST');
}


function newsletter_gt()
{
	window.location = "http://www.winewise.be/"+lang+"/newsletter-bedankt";

}
function contact_gt()
{
	window.location = "http://www.winewise.be/"+lang+"/contact-bedankt";
}
function join_gt()
{
	window.location = "http://www.winewise.be/"+lang+"/inschrijving-bedankt";
}


// login magic
var myRequestLogin = new ajaxObject( 'http://www.winewise.be/'+'ajax/login.php');
var myRequestPW = new ajaxObject( 'http://www.winewise.be/'+'ajax/pwreset.php');

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

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

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;
   }


// 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.winewise.be/'+'ajax/registreren.php');

function register()
{
	
	myRequestRegister.update( $rgb('register_ajax_form'), 'POST');	
}


function gotoUrl(mylink)
						{
							window.location = mylink;
						}			
																				

function tab(id)
{
	for(var i = 0; i <= 10;i++)
	{	
		if( $rgb('tab'+i) == null)break;
		
		$rgb('tab'+i).className = "";
		hide('tabcontent'+i);
	}
	
	$rgb('tab'+id).className = "active";
	show('tabcontent'+id);
	
}
function confirmJoin(url)
{
	if(lang == "nl")
	{
		if(confirm("Weet u zeker dat u zich wilt inschrijven voor dit examen?"))
			window.location = url;
	}else if(lang == "en")
	{
		if(confirm("Are you sure you wish to sign up for this examn?"))
			window.location = url;
	}

}
function suggestValue(id, value)
{
	//if( document.getElementById(id).value == "")
		document.getElementById(id).value = value;
	
	//$('taxcode').className = " text ";
}
function toggleC()
{
	obj = $rgb('company_form');
	if(obj.style.display == "block")
		obj.style.display = "none";
	else
		obj.style.display ="block";
}

var myRequestVAT = new ajaxObject( 'http://www.winewise.be/'+'ajax/vat.php');

function suggestData(type)
{
	
	if($rgb('btw').value.length < 10)return;
	
	document.getElementById('btw').className = ' text activity';
	
	
	myRequestVAT.update( $rgb('subscribe_course_form'), 'POST');	
}


var timer =null;

timer = setTimeout("zoner()", 10000);
var cur = 0;
function zoner()
{
	
	if( cur == 0)
	{
		opacityTween = new OpacityTween(document.getElementById('img1'),Tween.regularEaseOut, 100, 0, 2);
		opacityTween.start()	
		opacityTween2 = new OpacityTween(document.getElementById('img2'),Tween.regularEaseOut, 0, 100, 2);
		opacityTween2.start()	
		document.getElementById('img2').style.zIndex = 4;
		document.getElementById('img1').style.zIndex = 3;
		
		
	}else
	{
		opacityTween = new OpacityTween(document.getElementById('img2'),Tween.regularEaseOut, 100, 0, 2);
		opacityTween.start()	
		opacityTween2 = new OpacityTween(document.getElementById('img1'),Tween.regularEaseOut, 0, 100, 2);
		opacityTween2.start()	
		document.getElementById('img1').style.zIndex = 4;
		document.getElementById('img2').style.zIndex = 3;
		
	}
	

	
	if( cur == 0 ) 
		cur = 1;
	else
		cur = 0;
		
	timer = setTimeout("zoner()", 10000);
}


function uitschrijven(cid, id)
{
	window.location = "http://www.winewise.be/"+lang+"/examen-join?course_id="+cid+"&leave_exam="+id;
}



