// 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 $(id)
{
	return document.getElementById(id);	
}
function hide(id)
{
	$(id).style.display = 'none';
}
function show(id)
{
	
	$(id).style.display = 'block';

}
function isHidden(id)
{
	if($(id).style.display == 'none')
		return true;
	else
		return false;
}
function V_switch(id)
{
	if(isHidden(id))
		show(id);
	else
		hide(id);
}
// GEN basis
// AJAX basis
		
														
													
function processData(responseText, responseStatus)
 { 
	
	//document.getElementById('loadingbar').style.display ='none';
	if (responseStatus==200) // succes
	{
		if(responseText == 'error')
						alert('Error updating data!'+responseText);
		else
		{
			
			eval(responseText);
			if( $('loading_myrgb') != null ) hide('loading_myrgb');
		}
	 }
	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; 

}

function doSignup()
{
	myRequest3.update($('registerform') , "POST" );		
}
function doDroomfeest()
{
	myRequest4.update($('droomfeestform') , "POST" );		
}

function doRegister()
{
		myRequest2.update($('registerform') , "POST" );		
}
function doPwReset()
{
		myRequestPW.update($('pwresetform') , "POST" );		
}
function submitNM()
{
		myRequestNM.update( $('nmform'), 'POST');	
}
function donateNow()
{
		myRequestDonate.update( $('donateform'), 'POST');	
}


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

//  AJAX basis

//  MYRGB 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.myrgb.be"; } } );
//  MYRGB basis

var current_open = "";
var subnav_bools = null;
var currently_moving = false;
var tween_started = -1;
function showSubNav(id)
{
	var d = new Date();
	if(id == "" && currently_moving ) return; //ignore
	
	
	if(current_open == id) return;
	var i = 1;
	for(i = 1; i<=9; i++)
	{
		if(subnav_bools[i-1])
			hide("subnav_"+i);
	}	
	if(id != "") 
	{
		if($(id) != null)
		{
			show(id);
			current_open = id;
			currently_moving = true;
			
			tween_started = d.getTime();
			t1A = new Tween( $(id).style,'height',Tween.regularEaseOut,0,31,0.35,'px');
			t1A.onMotionFinished = function(){ currently_moving=false; };
			t1A.start();		
		}
	}else
	{
		current_open = "";	
	}
}

//  SHOP basis

/* cart functions */
var baseurl = "http://www.makeawish.be/";
var stricturl = "http://www.makeawish.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 get_cookie ( cookie_name )
{
  var results = document.cookie.match ( cookie_name + '=(.*?)(;|$)' );

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

function add(new_item){
	
	var old_amount = deleteOrderReturnAmount(new_item);
	basket_string = get_cookie("basket");
	
	var p_fid = ''+( parseInt($('aantal').options[$('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.makeawish.be/winkelmandje';
}
function confirmDeleteOrder(id)
{

	
	  if (confirm("Bent u zeker dat u dit product wilt verwijderen uit het winkelmandje?")) {
		deleteOrder(id);
	  }
	
}
function deleteOrder(id)
{
	basketstr = get_cookie("basket");
	new_basketstr = "";
	
	if(basketstr == "")return;
	
	var myarray = basketstr.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_basketstr += temparray[0];			
		}else
		{found = true;}
	}	
	
	//alert(new_basketstr);
	setCookie("basket", new_basketstr, 30, '/', '', '');	
	
	
	
	window.location = 'http://www.makeawish.be/winkelmandje';
}
function emptyBasketShop()
{
	setCookie("basket", '', 30, '/', '', '');	
	
	window.location = "http://www.makeawish.be/shop";		
}
function deleteOrderReturnAmount(id)
{
	basketstr = get_cookie("basket");
	
	new_basketstr = "";
	var found_amount = 0;
		if(basketstr == "")return found_amount;
	
	var myarray = basketstr.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_basketstr += temparray[0];			
		}else
		{
			found = true;
			found_amount = tmp[1];
			
			
		}
	}	
	
	
	setCookie("basket", new_basketstr, 30, '/', '', '');	
	
	return found_amount;
}


//  SHOP basis


