function Request() {
    var src = document.location.search;
    if(src) src = src.substring(1);
    var ent = src.split('&');
    
    this.elements = [];
    for(var i=0; i<ent.length; i++) {
        if(ent[i] != '') {
        	var tmp = ent[i].split('=');
        	this.elements[tmp[0]] = unescape(tmp[1]);
        }
    }

    this.getParameter = function(name) {
        var val = this.elements[name];
        return val || null;
    }
}

/*
    Written by Jonathan Snook, http://www.snook.ca/jonathan
    Add-ons by Robert Nyman, http://www.robertnyman.com
*/

function getElementsByClassName(oElm, strTagName, strClassName){
    var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i<arrElements.length; i++){
        oElement = arrElements[i];      
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }   
    }
    return (arrReturnElements)
}

function ChangeQuantity(artcode, quantity) {
	window.location.href = 'index.php?action=dealer-change-quantity&product_code=' + artcode + '&product_quantity=' + document.getElementById(artcode).value;
}

function toggleSelected(el) {
	if(Element.hasClassName(el.id, 'selected'))
		Element.removeClassName(el.id, 'selected')
	else
		Element.addClassName(el.id, 'selected')
}

var selectedSubSub = null;

function toggleSubSub(el) {
	
	if(selectedSubSub != el && selectedSubSub != null) {
		document.getElementById(selectedSubSub).style.display = 'none';
	}
	
	if( document.getElementById(el).style.display == 'none' ) {
		document.getElementById(el).style.display = 'block';
		selectedSubSub = el;
	}
	else {
		document.getElementById(el).style.display = 'none';
		selectedSubSub = null;
	}
		
}

function fillMotorTypes(selectedType) {
	
	var motorid;

	
	if(document.forms['product-search'].motor.options[document.forms['product-search'].motor.selectedIndex].value)
		var motorid = document.forms['product-search'].motor.options[document.forms['product-search'].motor.selectedIndex].value;
	else
			motorid = 0;
	
	var request = new Request();
	
	if(motorid == 0)
		motorid = request.getParameter('motor');
	
	
	advAJAX.get({
	    //url: "../index.php",
	    parameters : { "motorBrandId": motorid , "action": "menu-ajax-request", "selected": selectedType },
	    onInitialization : function(obj) {  },
	    onSuccess : function(obj) { document.getElementById('motortypelist').innerHTML = obj.responseText;  },
	    onError : function(obj) { alert("ErrorZ: " + obj.status); }
	});
}

//Ongebruikt
function fillProdCat(level, cat, div) {

	advAJAX.get({
	    //url: "../index.php",
	    parameters : {"top" : cat, "categoryLevel" : level , "action" : "menu-ajax-request" },
	    onInitialization : function(obj) {  },
	    onSuccess : function(obj) {  document.getElementById(div).innerHTML = obj.responseText; },
	    onError : function(obj) { alert("Error: " + obj.status); }
	});

	if($('product-menu-two').style.visibility != 'visible')
		$('product-menu-two').style.visibility = 'visible';

}

var CheckboxWatcher = Class.create();

//defining the rest of the class implementation
CheckboxWatcher.prototype = {

  initialize: function(chkBox, message) {
    this.chkBox = $(chkBox);
    this.message = message;
    this.clicked = false;
    //assigning our method to the event

    this.chkBox.onmouseover = this.highLight.bindAsEventListener(this);
    this.chkBox.onmouseout = this.downLight.bindAsEventListener(this);
    this.chkBox.onclick = this.clickHighLight.bindAsEventListener(this);
  },

  highLight: function(evt) {
    Element.addClassName(this.chkBox.id, 'selected');
  },
  
  downLight: function(evt) {
    if(!this.clicked)	
    	Element.removeClassName(this.chkBox.id, 'selected');
  },
  
  clickHighLight: function(evt) {
    Element.addClassName(this.chkBox.id, 'selected');
    this.clicked = true;
  }
  
};


function confirmText(texttoshow) {

	if(!confirm(texttoshow))
		return false;
	else
		return true;
	
}

function clearOrderConfirmText(texttoshow) {

	if(!confirm(texttoshow))
		return false;
	else
		document.location = 'index.php?action=dealer-lounge-clear-order';
	
}

function clearHotlistConfirmText(texttoshow) {

	if(!confirm(texttoshow))
		return false;
	else
		document.location = 'index.php?action=hotlist-clear';
	
}

function submitForm() {
	f = document.forms['order-form'];
	
	if(f.elements['confirm'].checked) {
		f.submit();
	}
	else {
		alert('Please check the confirm field.');
	}
}

function protect(e) {
	alert("Copyright Motorcycle Storehouse B.V.");
	return false;
}

function trap() {
	if(document.images) {
		for(i=0;i<document.images.length;i++)
			document.images[i].oncontextmenu = protect;
	}
}

function AutoImageResizing(src, fixedSizeX, fixedSizeY)
{
	var width = src.width;
	var height = src.height;
	var ratio = width / height;
	if (width > fixedSizeX)
	{
		src.width = fixedSizeX;
	}
	if (height > fixedSizeY)
	{
		var sizedwidth = fixedSizeX / ratio;
		var sizedheight = fixedSizeY;
		if (height > width)
		{
			if (height > sizedwidth)
			{
				src.height = fixedSizeY;
			}
			if (sizedwidth > fixedSizeY)
			{
				src.width = src.width * ratio;
			}
			else
			{
				src.height = src.height * ratio;
			}
		}
		else
		{
			src.width = fixedSizeX;
		}
	}
}

var submitAllowed = false;
function formSubmit() { return submitAllowed; }