//Moo.ToolsEx, Moo extended. Copyright (c) 2007-2008 TryFirst, P. de Bondt, <http://TryFirst.nl>,
Element.extend(
{
	hide: function() 
	{
		return this.setStyle('display', 'none');
	},
	
	show: function() 
	{
		return this.setStyle('display', '');
	}
});

// Tabs
var mootabs = new Class({
 
		initialize: function(element, options) {
			this.options = Object.extend({
				width:				300,
				height:				200,
				changeTransition:	Fx.Transitions.bounceOut
			}, options || {});
 
			this.el = $(element);
			this.id = element;
			this.tabPanels = $$('#' + this.id + ' ul.mootabs_title');
			this.tabPanel = this.tabPanels[0];
 
			this.el.setStyle('width', this.options.width );
 
			$$('#' + this.id + ' div.mootabs_panel').each(function(panel) {
				panel.setStyles({
					height: this.options.height ,
					width: this.options.width 
				});
			}.bind(this));
 
			this.tabs = $$('#' + this.id + ' ul li a');		
 
			this.tabs.each(function(tab) {
 
				var linkName = tab.getProperty('href').split('#')[1];
				tab.setProperty('rel', linkName );
				tab.href = 'javascript:void(0);';
 
				tab.addEvent('click', function() {
					this.activate(tab);
				}.bind(this));
			}.bind(this));
		},
 
		activate: function(tab) {
 
			var linkName = tab.getProperty('rel');
			this.tabs.each(function(tab) {
				tab.removeClass('active');
				tab.getParent().removeClass('active');
			});
 
			tab.addClass('active');		
 			tab.getParent().addClass('active');
			
			$$('#' + this.id + ' div.mootabs_panel').each(function(panel) {
				panel.removeClass('active');
			});		
 
			$(linkName).addClass('active');
		}		
	});
	
// Alternate row table
function alternate(id){ 
   if (id==null) return;
   var rows = $$('#'+id +' tr');   
   if (rows==null) return;
   for(i = 0; i < rows.length; i++)
     ((i % 2)==0) ? rows[i].className += " even" : rows[i].className += " odd"; 
}
// === Toggle + /- Header blocks in content (H3)
function toggleBlockEx( iH )
	{
	if (iH.className=="plus")
		{	//--Expand now
			iH.className="minus";
			iH.nextSibling.style.display="block";
		} else {
			//--Collapse
			iH.className="plus";
			iH.nextSibling.style.display="none";
		}
	}
// = Obfuscate email address
function gem( mu, md)
	{ var ma; ma= mu+ '@'+ md;
	document.write('<a href="mailto:' + ma + '">' + ma + '</a>'); 
	}
function MM_openBrWindow(theURL,winName) { //v2.0
	var stile = "top=10, left=10, width=800, height=600, status=no, menubar=no, toolbar=no scrollbar=no";
	window.open(theURL,winName,stile);
}
function MM_jumpMenu(targ,selObj,restore){ //v3.0
	eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	if (restore) selObj.selectedIndex=0;
}

// Check on keydown, and respond to enter and tab 
// goto next field, or submit
function ValidateKey( iEvent )
	{
	try {
		var evt = new Event(iEvent); 
		if ((evt.key=='enter') || (evt.code==9))
			{
			switch (evt.target.id)
				{
				case 'Email':
					document.getElementById('Password').focus();
					return false;
					break;
				case 'Password':
					ValidateSubmitLogin();
					return false;
					break;
				}
			}
		} catch(e) {}
	return true;
	}

function ValidateSubmitLogin(e)
	{
	var oForm = e;
	if (e) {
		//--Find form
		while (oForm.nodeName.toUpperCase() != "FORM") {
			oForm = oForm.parentNode;
		}
	} else
		oForm = document.forms[1];

	var iValid = new Validation(oForm, {onSubmit : false, useAlert : true});
 	Validation.add('validate-password',{ 
		errorMsg: 'Uw wachtwoord moet langer zijn dan 3 tekens en niet password,123 of abc.', 
		test: function(element){ 
		debugger
			return ((element.getValue().length >= 3) || (element.getValue()=='123') || (element.getValue()=='abc'));
			},
		minLength: 3,
		maxLength: 12
		}); 
	var bResult = iValid.validate();
	if (bResult==false) return false;	
	//--Validate
	oForm.submit();
	return true;
	}
function Logout() 
	{
	Cookie.set("USER_ID","xx",{path : "/", duration : false});
	Cookie.set("CART_ID","xx",{path : "/", duration : false});
	Cookie.remove("USER_ID");
	Cookie.remove("CART_ID");
	window.location.reload();
	return false;
	}	
	
function ResponseFromCart(e)
	{
	try {
	iReturn = Json.evaluate(e);
	if (iReturn.mode=="1")
		{
		$('info_'+iReturn.productid).innerHTML="Product is toegevoegd!";
		$('cartdisp').innerHTML=iReturn.description;
		} else if(iReturn.mode=="99") {
		window.location.href = iReturn.description;
		} else 	{
		$('info_'+iReturn.productid).innerHTML=iReturn.description;
		$('cartdisp').innerText=iReturn.description;
		}
	} catch(e) {}
	}
	
function AddToCart(el, sUserID, sCartID, sProdID, eCount)
	{
	el.style.display='none';
	$('Info_'+sProdID).setStyle('display','block');
	$('Info_'+sProdID).innerHTML="Product wordt toegevoegd...";

	sCount = eCount.value;

	var myAjax = new Ajax('process?open&' + 'a=5&UserID='+sUserID+'&CartID='+sCartID+'&Count='+sCount+'&ProductID='+sProdID+'&ReturnID=Info_'+sProdID, {'method':'get','onComplete':ResponseFromCart });
	myAjax.request();
	return false;
	}
	
function ResponseReload( sResult)
	{
	location.reload(true);	
	}
function RemoveArt(el,sCartID,sProductID)
	{
	el.style.display='none';
	var iAjax = new Ajax('process?open&a=15&CartID='+sCartID+'&productID='+sProductID, {method: 'get', onComplete: ResponseReload});
	iAjax.request();	
	}
function RemoveAll(el,sCartID)
	{
	el.style.display='none';
	$('infoRemoveAll').setStyle('display','block');	
	$('infoRemoveAll').innerHTML="Legen...";
	var iAjax = new Ajax('process?open&a=9&CartID='+sCartID, {method: 'get', onComplete: ResponseReload});
	iAjax.request();	
	}

function ResponseOrder()	
	{
	//--Send to order
	window.location.href=g_sOrderURL;
	}	
function Order(el, sOrderURL)
	{
	el.style.display='none';
	$('infoOrder').setStyle('display','block');
	$('infoOrder').innerHTML="Update...";
	$('CART').send({onComplete:ResponseOrder});		
	}

function SubmitAll()
	{
	$('CART').send({onComplete:ResponseReload});
	return false;
	}
function UpdateAll(el,sCartID)
	{
	el.style.display='none';
	$('infoUpdateAll').setStyle('display','block');	
	$('infoUpdateAll').innerHTML="Update...";
	$('CART').send({onComplete:ResponseReload});		
	}
	
	
//Bug in IE 6 prevents correct hover menu, so add some jscript handlers to do the job
sfHover = function() {
	var sfEls = $$(".submenu");
	if (sfEls==null) return;
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() { 
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}

	}
	
//resize the tab panel	
   function ResizePanels() { 
	var sfEls = $$(".navigation2"); 
	if (sfEls==null) return;
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].style.height = (window.getHeight()
			-$$(".adminlogo").getCoordinates()[0].height
			-$$(".admintitle").getCoordinates()[0].height
			-$$(".admininfo").getCoordinates()[0].height
			-6) + 'px'; 
		}
	var sfEls = $$(".interfaceframes"); 
		if (sfEls==null) return;
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].style.height = (window.getHeight()-6) + 'px'; 
			}		
	var sfEls = $$(".contentframe .content"); 
		if (sfEls==null) return;
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].style.height = (window.getHeight()
				-$$(".contentframe .header").getCoordinates()[0].height
				-16 ) + 'px'; 
			sfEls[i].style.width = (window.getWidth() - 25) + 'px';
			}		
    }

function Shop_Search_KeyDown(evt, sLang) 
	{
	evt = (evt) ? evt : event;
	var charCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);
	if (charCode == 13 || charCode == 3)
		{
		Shop_Search( document.getElementById('SearchText').value, sLang  );
		return false;
		}
	return true;
	}

function Shop_Search( sSearch, sLang )
	{
	//open search form
	if (sLang==null)
		sLang="nl";
	if (sSearch != "" )
		window.top.location = "Shop_Search?open&search=" + sSearch
	}		
		
function ShowOnChecked( el, elShow )
	{
	if ( (el.checked==true) && (el.value=='1'))
		$(elShow).setStyle('display','block');
	else
		$(elShow).setStyle('display','none');
	}
function CheckboxValue( sName )
	{
	var asEl = $$('input[name='+sName+']');
	var sValue='';
	asEl.each(function(el){
			if (el.getProperty('checked') == true){
				sValue= el.getProperty('value');				
			}
		});	
	return sValue;
	}		
		
// === Rezize the panels correctly and Add IE6 menu fix===
window.addEvent('domready', function(){
	ResizePanels(); });
window.onresize = ResizePanels; 
