// 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 switchCurrency(currency)
{
	setCookie("currency", currency, 30, '/', '', '');	
	location.reload();
	
}
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 bankPay()
{
	setCookie("basket", '', 30, '/', '', '');	
	
	$rgb('bankpayform').submit();
}
function molliePay()
{
	setCookie("basket", '', 30, '/', '', '');	
	
	$rgb('molliepayform').submit();
}
function paypalPay()
{
	setCookie("basket", '', 30, '/', '', '');	
	
	$rgb('paypalpayform').submit();
}
busy1 = false;

function pushlink(link)
{
	

	link = link.parentNode;
	
	if(link.style.paddingLeft == "50px") return;
	
	if(busy1) return;
	busy1 = true;
	t1 = new Tween(link.style,'paddingLeft',Tween.regularEaseOut,25,50,0.12,'px');
	t1.onMotionFinished = function(){ busy1 = false; };
	t1.start();
	
	t2 = new Tween(link.style,'backgroundPosition',Tween.regularEaseOut,-30,-5,0.12,'px 0');
	t2.start();
}
function poplink(link)
{	
link = link.parentNode;
	if(busy1) return;
	busy1 = true;
	t1 = new Tween(link.style,'paddingLeft',Tween.regularEaseOut,50,25,0.12,'px');
	t1.onMotionFinished = function(){ busy1 = false; };
	t1.start();
	
	t2 = new Tween(link.style,'backgroundPosition',Tween.regularEaseOut,-5,-30,0.12,'px 0');
	t2.start();
}
// 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
				{
					
					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.hetgroenelilare.be/beheer/index.php"; } } );
//  ADMIN basis

// productfiles magic
var myRequestPF = new ajaxObject( 'http://www.rgbtest.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.rgbtest.be/'+'ajax/account.php');

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

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

function Contact()
{
	myRequestContact.update($rgb('contactform'), 'POST');
}
function contact_gt()
{
	window.location = "http://www.hetgroenelilare.be/nl/contact-bedankt";
}

// search magic
function search()
{
 $rgb('searchform').submit();
}
function searchFocus(obj)
{
	if(obj.value == "typ hier uw tekst")
		obj.value =  "";
	if(obj.value == "type here")
		obj.value =  "";
}
function searchBlur(obj)
{
	if(lang == "nl")
	{
		if(obj.value == "")
			obj.value = "typ hier uw tekst";
	}
	else
	{
		if(obj.value == "")
			obj.value = "type here";
	}
	
}
var myRequestContact = new ajaxObject( 'http://www.hetgroenelilare.be/'+'ajax/contact.php');

function sendContact()
{
	myRequestContact.update($rgb("contactform") , "POST" );	
}

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

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

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

function emptyBasketShop()
{
	setCookie("basket", '', 30, '/', '', '');	
	
	window.location = "http://www.rgbtest.be/"+lang+"/shop";		
}
//  SHOP basis

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

//////////// SHOPPING CART start

var busy = Array(0,0,0,0,0,0);
var uptween = Array(null,null,null,null,null,null);
var last = -1;
function rollo(id)
{
	if(last == id)return;
	if(busy[id] == 1) return;
	busy[id] = 1;
	
	rollolo();
	
	uptween[id] = new Tween(document.getElementById('h'+id).style,'bottom',Tween.regularEaseInOut,-36,0,0.25,'px');
	uptween[id].onMotionFinished = function(){  busy[id] = 0;  };
	uptween[id].start();
		last = id;
}
function rollolo()
{
	if(last == -1) return;
	if(busy[last] == 1) 
	{
		busy[last] = 0;
		uptween[last].stop();
	}
	var temp  = parseInt( document.getElementById('h'+last).style.bottom);
	t1A = new Tween(document.getElementById('h'+last).style,'bottom',Tween.regularEaseInOut,temp,-36 ,0.45,'px');
	t1A.onMotionFinished = function(){  busy[last] = 0; };
	t1A.start();
}
																			
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(52.314674, 5.042939); 
				marker = new GMarker(point);
				GEvent.addListener(marker, "click", function() {    gotoUrl("http://maps.google.be/maps?f=q&source=s_q&hl=nl&q=Frederica+Zeijdelaarweg+23,+1382+Weesp,+Noord-Holland,+Nederland&sll=50.805935,4.432983&sspn=5.597012,16.907959&ie=UTF8&cd=1&geocode=FTJCHgMd_PJMAA&split=0&hq=&hnear=Frederica+Zeijdelaarweg+23,+1382+Weesp,+Noord-Holland,+Nederland&ll=52.314674,5.042939&spn=0.002643,0.008256&z=18") });
		
				 
			  map.addOverlay(marker);
			 // marker.openInfoWindowHtml(title);
			
	}
		 
function load() {
  if (GBrowserIsCompatible()) {
	map = new GMap2(document.getElementById("gmaps"));
	map.addControl(new GSmallZoomControl());
	geocoder = new GClientGeocoder();
	map.setCenter(new GLatLng(52.314674, 5.042939), 14);
	
	GIcon.transparent ="";
	for(var i = 1; i < adres_str.length; i++)
		showAddress( adres_str[i] , marker_str[i], i);							
  }
}

jQuery(document).ready(function() {

	for(var i =0 ; i<100; i++)
	{
		if(document.getElementById('gally_'+i) == null) break;
		
		$("a[rel=gallery_"+i+"]").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
		    return '<span id="fancybox-title-over">Foto ' +  (currentIndex + 1) + ' / ' + currentArray.length + ' ' + title + '</span>';
		}
	});
	}
	
	
	
});
