function submitSearch(search_field)
{
	href="/search/"+search_field;
	document.location.href=href;
	return false;
}


function UpdateQty(item){

	var name_ar=item.name.split("-"); 

	itemId = name_ar[0];
	maat_sel = name_ar[1];		
	
	//newQty = item.options[item.selectedIndex].text;
	newQty = item.value;
	document.location.href = '/cart.php?action=update_item&pr_id='+itemId+'&qty='+newQty+'&maat_sel=' + maat_sel;
}


function productToCart(prId){
	var qty=document.getElementById('aantal'+prId).value;
	// read the selected maat 
	var maat_sel = document.getElementById('maat_select_'+prId).options[document.getElementById('maat_select_'+prId).selectedIndex].value;
	// read the selected colour
	var col_sel = 0;
	if(document.getElementById('colour_select_'+prId)) col_sel = document.getElementById('colour_select_'+prId).options[document.getElementById('colour_select_'+prId).selectedIndex].value;
	
	
	var stif_sel = 0;
	if(document.getElementById('stiffness_select_'+prId)) stif_sel = document.getElementById('stiffness_select_'+prId).options[document.getElementById('stiffness_select_'+prId).selectedIndex].value;
	
	
	maat_sel = maat_sel + "." + col_sel + "." + stif_sel;
	
	if (qty != 0)
		window.location.href='/cart.php?action=add_item&pr_id=' + prId + '&qty='+qty+'&maat_sel='+maat_sel;
	else
		window.location.href='/cart.php?action=add_item&pr_id=' + prId + '&qty=1&maat_sel='+maat_sel;
}


function updateCartInfo(){

	// update the number of items and total price in cart
	var cartNrItems = $.ajax({
	  url: "/includes/functions/getNrCartItems.php",
	  async: false
	}).responseText;
	
	var res = new Array();
	
	res = cartNrItems.split("#");
			
	$("#nr_cart_items").html(res[0]);
	$("#price_total_items").html(res[1]);

}


/***********************************************
* Switch Menu script- by Martial B of http://getElementById.com/
* Modified by Dynamic Drive for format & NS4/IE4 compatibility
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

/*if (document.getElementById){ //DynamicDrive.com change
document.write('<style type="text/css">\n')
document.write('.submenu{display: none;}\n')
document.write('</style>\n')
}*/

function SwitchProductMenu(obj){
	if(document.getElementById){
		var el = document.getElementById(obj);
		var ar = document.getElementById("masterdiv").getElementsByTagName("ul"); //DynamicDrive.com change
			if(el.style.display != "block"){ //DynamicDrive.com change

				el.style.display = "block";
				//el_parent = el.parentNode;
				//el_parent.style.backgroundColor = "#019ee1";
				
				// parse through the submenu blocks
				for (var i=0; i<ar.length; i++){
					if (ar[i].className=="subcat"){ //DynamicDrive.com change
						// save the state of each block in a cookie
						if(ar[i].style.display=="none") $.cookie('submenu_'+i,'none', {path: '/'});
						if(ar[i].style.display=="block") $.cookie('submenu_'+i,'block', {path: '/'});
					}  
					  //ar[i].style.display = "none";
					//el_parent = ar[i].parentNode;
					//el_parent.style.backgroundColor = "#004494";
				
				}
				//alert(el.id+el.style.display);
				//alert(el_parent.id);
			}else{
				el_parent = el.parentNode;
				//alert($.cookie('sub_click'));
				// if a submenuitem (link) is clicked dont save the state
				if("yes"!=$.cookie('sub_click')) {
						el.style.display = "none";
				}
				// parse through the submenu blocks
				for (var i=0; i<ar.length; i++){
					if (ar[i].className=="subcat"){ //DynamicDrive.com change
						// save the state of each block in a cookie
						if(ar[i].style.display=="none") $.cookie('submenu_'+i,'none', {path: '/'});
						if(ar[i].style.display=="block") $.cookie('submenu_'+i,'block', {path: '/'});
					}  
					  //ar[i].style.display = "none";
					//el_parent = ar[i].parentNode;
					//el_parent.style.backgroundColor = "#004494";
				}
				//alert(el.id+el.style.display);
				//alert(el_parent.id);				
			}
	}

}

function setSubClickFlag(){
  	// set the flag that signals if a submenuitem (submenu link) was clicked
	$.cookie('sub_click','yes', {path: '/'});
}

function setBuyButton(prId){
	// this function sets the visibility of the buy link
	// if all the select boxes for a product are used, hide the buy button placeholder img and sow the buy buttton
	
	var maat_exists = document.getElementById('maat_select_'+prId);
	var stiffness_exists = document.getElementById('stiffness_select_'+prId);
	var col_exists = document.getElementById('colour_select_'+prId);
	
	// read the selected maat
	if(maat_exists) maat_sel = document.getElementById('maat_select_'+prId).options[document.getElementById('maat_select_'+prId).selectedIndex].value;
	// read the selected colour
	if(col_exists) col_sel = document.getElementById('colour_select_'+prId).options[document.getElementById('colour_select_'+prId).selectedIndex].value;
	// read the selected colour
	if(stiffness_exists) stiffness_sel = document.getElementById('stiffness_select_'+prId).options[document.getElementById('stiffness_select_'+prId).selectedIndex].value;
	
	
	 if((maat_exists && maat_sel>0 && col_exists && col_sel>0 && stiffness_exists && stiffness_sel>0) || 
		(maat_exists && maat_sel>0 && !col_exists && !stiffness_exists) || 
		(maat_exists && maat_sel>0 && col_exists && col_sel>0 && !stiffness_exists) ||
		(maat_exists && maat_sel>0 && !col_exists && stiffness_exists && stiffness_sel>0) ||
		(!maat_exists && !col_exists && stiffness_exists && stiffness_sel>0) ||
		(!maat_exists && col_exists && col_sel>0 && stiffness_exists && stiffness_sel>0))
	{
		// show the link hide the placeholder
		document.getElementById('buy_button_disabled_'+prId).style.display='none';
		document.getElementById('buy_button_'+prId).style.display='';
	}
	else
	{
		// hide the link show the placeholder
		document.getElementById('buy_button_disabled_'+prId).style.display='';
		document.getElementById('buy_button_'+prId).style.display='none';
	  
	}
	
}
$(document).ready(function () { 
  	// cart info updater script
	updateCartInfo();
	
	// disable the buy button 
	if(document.getElementById('buy_button')) document.getElementById('buy_button').style.display='none';
  

  	// read through the menuitems and open / close them based on cookies
  	/*
	var ar = document.getElementById("masterdiv").getElementsByTagName("ul");
	for (var i=0; i<ar.length; i++){
		if (ar[i].className=="subcat"){ //DynamicDrive.com change
			if("block"==$.cookie('submenu_'+i)){ 
				//alert($.cookie('submenu_'+i)+ar[i].style.display); 
				ar[i].style.display="block";
			}
			else{
				//alert($.cookie('submenu_'+i)+ar[i].style.display+"2"); 
				ar[i].style.display="none";
			}	
		}  
	}*/
  	// this cookie is used to flag if a mainitem or a subitem was clicked...if a subitem the save of the state of a submenu isn't saved
  	// but need to reset that cookie every time when a page loads
	$.cookie('sub_click','no', {path: '/'});  
});
