
var root='http://www.networkbay.ro/';


//** Tab Content script v2.0- © Dynamic Drive DHTML code library (http://www.dynamicdrive.com)
//** Updated Oct 7th, 07 to version 2.0. Contains numerous improvements:
//   -Added Auto Mode: Script auto rotates the tabs based on an interval, until a tab is explicitly selected
//   -Ability to expand/contract arbitrary DIVs on the page as the tabbed content is expanded/ contracted
//   -Ability to dynamically select a tab either based on its position within its peers, or its ID attribute (give the target tab one 1st)
//   -Ability to set where the CSS classname "selected" get assigned- either to the target tab's link ("A"), or its parent container
//** Updated Feb 18th, 08 to version 2.1: Adds a "tabinstance.cycleit(dir)" method to cycle forward or backward between tabs dynamically
//** Updated April 8th, 08 to version 2.2: Adds support for expanding a tab using a URL parameter (ie: http://mysite.com/tabcontent.htm?tabinterfaceid=0) 

////NO NEED TO EDIT BELOW////////////////////////

function ddtabcontent(tabinterfaceid){
	this.tabinterfaceid=tabinterfaceid //ID of Tab Menu main container
	this.tabs=document.getElementById(tabinterfaceid).getElementsByTagName("a") //Get all tab links within container
	this.enabletabpersistence=false;
	this.hottabspositions=[] //Array to store position of tabs that have a "rel" attr defined, relative to all tab links, within container
	this.currentTabIndex=0 //Index of currently selected hot tab (tab with sub content) within hottabspositions[] array
	this.subcontentids=[] //Array to store ids of the sub contents ("rel" attr values)
	this.revcontentids=[] //Array to store ids of arbitrary contents to expand/contact as well ("rev" attr values)
	this.selectedClassTarget="link" //keyword to indicate which target element to assign "selected" CSS class ("linkparent" or "link")
}

ddtabcontent.getCookie=function(Name){ 
	var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
	if (document.cookie.match(re)) //if cookie found
		return document.cookie.match(re)[0].split("=")[1] //return its value
	return ""
}

ddtabcontent.setCookie=function(name, value){
	document.cookie = name+"="+value+";path=/" //cookie value is domain wide (path=/)
}

ddtabcontent.prototype={

	expandit:function(tabid_or_position){ //PUBLIC function to select a tab either by its ID or position(int) within its peers
		this.cancelautorun() //stop auto cycling of tabs (if running)
		var tabref=""
		try{
			if (typeof tabid_or_position=="string" && document.getElementById(tabid_or_position).getAttribute("rel")) //if specified tab contains "rel" attr
				tabref=document.getElementById(tabid_or_position)
			else if (parseInt(tabid_or_position)!=NaN && this.tabs[tabid_or_position].getAttribute("rel")) //if specified tab contains "rel" attr
				tabref=this.tabs[tabid_or_position]
		}
		catch(err){alert("Invalid Tab ID or position entered!")}
		if (tabref!="") //if a valid tab is found based on function parameter
			this.expandtab(tabref) //expand this tab
	},

	cycleit:function(dir, autorun){ //PUBLIC function to move foward or backwards through each hot tab (tabinstance.cycleit('foward/back') )
		if (dir=="next"){
			var currentTabIndex=(this.currentTabIndex<this.hottabspositions.length-1)? this.currentTabIndex+1 : 0
		}
		else if (dir=="prev"){
			var currentTabIndex=(this.currentTabIndex>0)? this.currentTabIndex-1 : this.hottabspositions.length-1
		}
		if (typeof autorun=="undefined") //if cycleit() is being called by user, versus autorun() function
			this.cancelautorun() //stop auto cycling of tabs (if running)
		this.expandtab(this.tabs[this.hottabspositions[currentTabIndex]])
	},

	setpersist:function(bool){ //PUBLIC function to toggle persistence feature
			//this.enabletabpersistence=bool
			this.enabletabpersistence=0
	},

	setselectedClassTarget:function(objstr){ //PUBLIC function to set which target element to assign "selected" CSS class ("linkparent" or "link")
		this.selectedClassTarget=objstr || "link"
	},

	getselectedClassTarget:function(tabref){ //Returns target element to assign "selected" CSS class to
		return (this.selectedClassTarget==("linkparent".toLowerCase()))? tabref.parentNode : tabref
	},

	urlparamselect:function(tabinterfaceid){
		var result=window.location.search.match(new RegExp(tabinterfaceid+"=(\\d+)", "i")) //check for "?tabinterfaceid=2" in URL
		return (result==null)? null : parseInt(RegExp.$1) //returns null or index, where index (int) is the selected tab's index
	},

	expandtab:function(tabref){
		var subcontentid=tabref.getAttribute("rel") //Get id of subcontent to expand
		//Get "rev" attr as a string of IDs in the format ",john,george,trey,etc," to easily search through
		var associatedrevids=(tabref.getAttribute("rev"))? ","+tabref.getAttribute("rev").replace(/\s+/, "")+"," : ""
		this.expandsubcontent(subcontentid)
		this.expandrevcontent(associatedrevids)
		for (var i=0; i<this.tabs.length; i++){ //Loop through all tabs, and assign only the selected tab the CSS class "selected"
			this.getselectedClassTarget(this.tabs[i]).className=(this.tabs[i].getAttribute("rel")==subcontentid)? "selected" : ""
		}
		
		toggle_product_page_up(subcontentid);
		
		if (this.enabletabpersistence) //if persistence enabled, save selected tab position(int) relative to its peers
			ddtabcontent.setCookie(this.tabinterfaceid, tabref.tabposition)
		this.setcurrenttabindex(tabref.tabposition) //remember position of selected tab within hottabspositions[] array
	},

	expandsubcontent:function(subcontentid){
		for (var i=0; i<this.subcontentids.length; i++){
			var subcontent=document.getElementById(this.subcontentids[i]) //cache current subcontent obj (in for loop)
			subcontent.style.display=(subcontent.id==subcontentid)? "block" : "none" //"show" or hide sub content based on matching id attr value
		}
	},

	expandrevcontent:function(associatedrevids){
		var allrevids=this.revcontentids
		for (var i=0; i<allrevids.length; i++){ //Loop through rev attributes for all tabs in this tab interface
			//if any values stored within associatedrevids matches one within allrevids, expand that DIV, otherwise, contract it
			document.getElementById(allrevids[i]).style.display=(associatedrevids.indexOf(","+allrevids[i]+",")!=-1)? "block" : "none"
		}
	},

	setcurrenttabindex:function(tabposition){ //store current position of tab (within hottabspositions[] array)
		for (var i=0; i<this.hottabspositions.length; i++){
			if (tabposition==this.hottabspositions[i]){
				this.currentTabIndex=i
				break
			}
		}
	},

	autorun:function(){ //function to auto cycle through and select tabs based on a set interval
		this.cycleit('next', true)
	},

	cancelautorun:function(){
		if (typeof this.autoruntimer!="undefined")
			clearInterval(this.autoruntimer)
	},

	init:function(automodeperiod){
		var persistedtab=ddtabcontent.getCookie(this.tabinterfaceid) //get position of persisted tab (applicable if persistence is enabled)
		var selectedtab=-1 //Currently selected tab index (-1 meaning none)
		var selectedtabfromurl=this.urlparamselect(this.tabinterfaceid) //returns null or index from: tabcontent.htm?tabinterfaceid=index
		this.automodeperiod=automodeperiod || 0
		for (var i=0; i<this.tabs.length; i++){
			this.tabs[i].tabposition=i //remember position of tab relative to its peers
			if (this.tabs[i].getAttribute("rel")){
				var tabinstance=this
				this.hottabspositions[this.hottabspositions.length]=i //store position of "hot" tab ("rel" attr defined) relative to its peers
				this.subcontentids[this.subcontentids.length]=this.tabs[i].getAttribute("rel") //store id of sub content ("rel" attr value)
				this.tabs[i].onclick=function(){
					tabinstance.expandtab(this)
					tabinstance.cancelautorun() //stop auto cycling of tabs (if running)
					return false
				}
				if (this.tabs[i].getAttribute("rev")){ //if "rev" attr defined, store each value within "rev" as an array element
					this.revcontentids=this.revcontentids.concat(this.tabs[i].getAttribute("rev").split(/\s*,\s*/))
				}
				
				if (selectedtabfromurl==i || this.enabletabpersistence && selectedtab==-1 && parseInt(persistedtab)==i || !this.enabletabpersistence && selectedtab==-1 && this.getselectedClassTarget(this.tabs[i]).className=="selected"){
					selectedtab=i //Selected tab index, if found
				}
			}
		} //END for loop
		if (selectedtab!=-1) //if a valid default selected tab index is found
			this.expandtab(this.tabs[selectedtab]) //expand selected tab (either from URL parameter, persistent feature, or class="selected" class)
		else //if no valid default selected index found
			this.expandtab(this.tabs[this.hottabspositions[0]]) //Just select first tab that contains a "rel" attr
		if (parseInt(this.automodeperiod)>500 && this.hottabspositions.length>1){
			this.autoruntimer=setInterval(function(){tabinstance.autorun()}, this.automodeperiod)
		}
	} //END int() function

} //END Prototype assignment





// ===================================================================
// Author: Matt Kruse <matt@mattkruse.com>
// WWW: http://www.mattkruse.com/
//
// NOTICE: You may use this code for any purpose, commercial or
// private, without any further permission from the author. You may
// remove this notice from your final code if you wish, however it is
// appreciated by the author if at least my web site address is kept.
//
// You may *NOT* re-distribute this code in any way except through its
// use. That means, you can include it in your product, or your web
// site, or any other form where the code is actually being used. You
// may not put the plain javascript up on your site for download or
// include it in your javascript libraries for download. 
// If you wish to share this code with others, please just point them
// to the URL instead.
// Please DO NOT link directly to my .js files from your site. Copy
// the files to your server and use them there. Thank you.
// ===================================================================

// HISTORY
// ------------------------------------------------------------------
// December 9, 2003: Added script to the Javascript Toolbox
// December 10, 2003: Added the preProcessTrees variable to allow user
//      to turn off automatic conversion of UL's onLoad
// March 1, 2004: Changed it so if a <li> has a class already attached
//      to it, that class won't be erased when initialized. This allows
//      you to set the state of the tree when painting the page simply
//      by setting some <li>'s class name as being "liOpen" (see example)
/*
This code is inspired by and extended from Stuart Langridge's aqlist code:
		http://www.kryogenix.org/code/browser/aqlists/
		Stuart Langridge, November 2002
		sil@kryogenix.org
		Inspired by Aaron's labels.js (http://youngpup.net/demos/labels/) 
		and Dave Lindquist's menuDropDown.js (http://www.gazingus.org/dhtml/?id=109)
*/

// Automatically attach a listener to the window onload, to convert the trees
addEvent(window,"load",convertTrees);

// Utility function to add an event listener
function addEvent(o,e,f){
	if (o.addEventListener){ o.addEventListener(e,f,true); return true; }
	else if (o.attachEvent){ return o.attachEvent("on"+e,f); }
	else { return false; }
}

// utility function to set a global variable if it is not already set
function setDefault(name,val) {
	if (typeof(window[name])=="undefined" || window[name]==null) {
		window[name]=val;
	}
}

// Full expands a tree with a given ID
function expandTree(treeId) {
	var ul = document.getElementById(treeId);
	if (ul == null) { return false; }
	expandCollapseList(ul,nodeOpenClass);
}

// Fully collapses a tree with a given ID
function collapseTree(treeId) {
	var ul = document.getElementById(treeId);
	if (ul == null) { return false; }
	expandCollapseList(ul,nodeClosedClass);
}

// Expands enough nodes to expose an LI with a given ID
function expandToItem(treeId,itemId) {
	var ul = document.getElementById(treeId);
	if (ul == null) { return false; }
	var ret = expandCollapseList(ul,nodeOpenClass,itemId);
	if (ret) {
		var o = document.getElementById(itemId);
		if (o.scrollIntoView) {
			o.scrollIntoView(false);
		}
	}
}

// Performs 3 functions:
// a) Expand all nodes
// b) Collapse all nodes
// c) Expand all nodes to reach a certain ID
function expandCollapseList(ul,cName,itemId) {
	if (!ul.childNodes || ul.childNodes.length==0) { return false; }
	// Iterate LIs
	for (var itemi=0;itemi<ul.childNodes.length;itemi++) {
		var item = ul.childNodes[itemi];
		if (itemId!=null && item.id==itemId) { return true; }
		if (item.nodeName == "LI") {
			// Iterate things in this LI
			var subLists = false;
			for (var sitemi=0;sitemi<item.childNodes.length;sitemi++) {
				var sitem = item.childNodes[sitemi];
				if (sitem.nodeName=="UL") {
					subLists = true;
					var ret = expandCollapseList(sitem,cName,itemId);
					if (itemId!=null && ret) {
						item.className=cName;
						return true;
					}
				}
			}
			if (subLists && itemId==null) {
				item.className = cName;
			}
		}
	}
}

// Search the document for UL elements with the correct CLASS name, then process them
function convertTrees() {
	setDefault("treeClass","mktree");
	setDefault("nodeClosedClass","liClosed");
	setDefault("nodeOpenClass","liOpen");
	setDefault("nodeBulletClass","liBullet");
	setDefault("nodeLinkClass","bullet");
	setDefault("preProcessTrees",true);
	if (preProcessTrees) {
		if (!document.createElement) { return; } // Without createElement, we can't do anything
		uls = document.getElementsByTagName("ul");
		for (var uli=0;uli<uls.length;uli++) {
			var ul=uls[uli];
			if (ul.nodeName=="UL" && ul.className==treeClass) {
				processList(ul);
			}
		}
	}
}

// Process a UL tag and all its children, to convert to a tree
function processList(ul) {
	if (!ul.childNodes || ul.childNodes.length==0) { return; }
	// Iterate LIs
	for (var itemi=0;itemi<ul.childNodes.length;itemi++) {
		var item = ul.childNodes[itemi];
		if (item.nodeName == "LI") {
			// Iterate things in this LI
			var subLists = false;
			for (var sitemi=0;sitemi<item.childNodes.length;sitemi++) {
				var sitem = item.childNodes[sitemi];
				if (sitem.nodeName=="UL") {
					subLists = true;
					processList(sitem);
				}
			}
			var s= document.createElement("SPAN");
			var t= '\u00A0'; // &nbsp;
			s.className = nodeLinkClass;
			if (subLists) {
				// This LI has UL's in it, so it's a +/- node
				if (item.className==null || item.className=="") {
					item.className = nodeClosedClass;
				}
				// If it's just text, make the text work as the link also
				if (item.firstChild.nodeName=="#text") {
					t = t+item.firstChild.nodeValue;
					item.removeChild(item.firstChild);
				}
				s.onclick = function () {
					this.parentNode.className = (this.parentNode.className==nodeOpenClass) ? nodeClosedClass : nodeOpenClass;
					return false;
				}
			}
			else {
				// No sublists, so it's just a bullet node
				item.className = nodeBulletClass;
				s.onclick = function () { return false; }
			}
			s.appendChild(document.createTextNode(t));
			item.insertBefore(s,item.firstChild);
		}
	}
}


// when the page loads, transform all product images into draggable items
// and allow them to be dropped on the cart

window.onload = function() {	
	// bind a progress indicator to all Ajax calls
	startAjax();
}

function startAjax()
{
	Ajax.Responders.register({
	  // when an Ajax request is started, show the indicator
		onCreate: function() {
		if (Ajax.activeRequestCount > 0)
		  Element.show($("indicator"));
	  },
		// when an Ajax request is finished, hide the indicator
		onComplete: function() {
		if (Ajax.activeRequestCount == 0)
		  Element.hide($("indicator"));
	  }
	});
}

// add item to cart
function addToCart(cid)
{
	var ptype=document.getElementsByName("price_type");
	
	for(var i=0;i<ptype.length;i++)
	{
		if (ptype[i].checked)
		{
			cid = cid + ptype[i].value;
			break;
		}
	}

	new Ajax.Request(root + "cart_server.php?action=addToCart", {
		parameters: "cid=" + cid,
		onSuccess: function(resp) {
			var cartUpdate = eval('(' + resp.responseText + ')');
			var isNew = cartUpdate['cartItemDetails'][0].isNew;
			// if this item is new in the cart, inject it inside, otherwise update the qty and subtotal
			if (isNew == 1)
			{
				var newItem = '<div id="cartItem_' + cid + '" style="display:none" class="row">';
				newItem += '<div class="cell1" id="cartItemQty_' + cid + '" valign="top">1</div>';
				newItem += '<div class="cell2"><a href="' + root + cartUpdate['cartItemDetails'][0].slug +'/" class="cart_link">' + cartUpdate['cartItemDetails'][0].title + '</a></div>';
				newItem += '<div class="cell3" id="cartItemPrice_' + cid + '">' + cartUpdate['cartItemDetails'][0].newPrice + ' </div>';
				newItem += '<div class="cell4"><a href="' + root + 'cart_server.php?action=removeFromCart&cid=' + cid + '" onclick="return removeFromCart(\'' + cid + '\')" title="Sterge din cos">';
				newItem += '<img src="' + root + '/images/x.gif" alt="x" /></a></div><div class="clear"></div></div>';
				
				if ($("cartIsEmpty"))
					Element.hide($("cartIsEmpty"));
				new Insertion.Bottom("cartItems", newItem);	
				
				Effect.Appear("cartItem_" + cid, { duration: 0.5 });
				Element.update($("cartTotalAmount"), "Total: " + cartUpdate['cartItemDetails'][0].total);
				//new Effect.Highlight("cartTotalAmount", {startcolor:'#999999', endcolor:'#FFFFFF', restorecolor:'#FFFFFF'});
			}
			// so, the item already existed in the cart, therefore update its quantity and subtotal
			else
			{
				Element.update($("cartItemQty_" + cid), cartUpdate['cartItemDetails'][0].newQty);
				Element.update($("cartItemPrice_" + cid), cartUpdate['cartItemDetails'][0].newPrice);
				Element.update($("cartTotalAmount"), "Total: " + cartUpdate['cartItemDetails'][0].total);
				//new Effect.Highlight("cartTotalAmount", {startcolor:'#999999', endcolor:'#FFFFFF', restorecolor:'#FFFFFF'});
				//new Effect.Highlight("cartItemPrice_" + id, {startcolor:'#999999', endcolor:'#FFFFFF', restorecolor:'#FFFFFF'});
				//new Effect.Highlight("cartItemQty_" + id, {startcolor:'#999999', endcolor:'#FFFFFF', restorecolor:'#FFFFFF'});
			}
		}
	});
	return false;
}

// remove an item from the cart
function removeFromCart(cid)
{
	Effect.Fade("cartItem_" + cid);
	new Ajax.Request(root + "cart_server.php?action=removeFromCart", {
		parameters: "cid=" + cid,
		onSuccess: function(resp) {
			var total = resp.responseText;
			if (total == 0)
			{
				// update the cart's total amount and contents
				Element.update($("cartItems"), '<div id="cartIsEmpty">Cosul este gol.</div>');
				Element.update($("cartTotalAmount"), "Total: 0 RON");
				//new Effect.Highlight("cartIsEmpty", {startcolor:'#999999', endcolor:'#FFFFFF', restorecolor:'#FFFFFF'});
			}
			else
			{
				// update the cart's total amount
				Element.update($("cartTotalAmount"), "Total: " + total);
			}
			//new Effect.Highlight("cartTotalAmount", {startcolor:'#999999', endcolor:'#FFFFFF', restorecolor:'#FFFFFF'});
		}
	});
	return false;
}

// empty the cart
function emptyCart()
{
	new Ajax.Request(root + "cart_server.php?action=emptyCart", {
		onSuccess: function(resp) {
			if (resp.responseText == 1)
			{
				// update the cart's total amount and contents
				Element.update($("cartItems"), '<div id="cartIsEmpty">Cosul este gol.</div>');
				Element.update($("cartTotalAmount"), "Total: 0 RON");
				//new Effect.Highlight("cartIsEmpty", {startcolor:'#999999', endcolor:'#777777', restorecolor:'#777777'});
				//new Effect.Highlight("cartTotalAmount", {startcolor:'#999999', endcolor:'#777777', restorecolor:'#777777'});
			}
		}
	});
	return false;
}


function validate_comment_form()
{
	errmsg = '';
	focusfield = '';
	
	name = document.getElementById('name').value;
	
	if (name=='')
	{
		errmsg += "You must enter your name first.\n";
		if (focusfield=='') focusfield = 'name';
	}
	
	comment = document.getElementById('comment').value;
	
	if (comment=='')
	{
		errmsg += "You must enter a comment first.\n";
		if (focusfield=='') focusfield = 'comment';
	}
	
	if (errmsg!='')
	{
		alert(errmsg);
		document.getElementById(focusfield).focus();
		
		return false;
	}
}

function validate_contact_form()
{
	errmsg = '';
	focusfield = '';
	
	name = document.getElementById('name').value;
	
	if (name=='')
	{
		errmsg += "You must enter your name first.\n";
		if (focusfield=='') focusfield = 'name';
	}
	
	email = document.getElementById('email').value;
	
	if (email=='')
	{
		errmsg += "You must enter your e-mail first.\n";
		if (focusfield=='') focusfield = 'email';
	}
	else
	{
		if (! ( (email.indexOf(".") > 2) && (email.indexOf("@") > 0) ) )
		{
			errmsg += "E-mail address is not valid.\n";
			if (focusfield=='') focusfield = 'email';
		}
	}
	
	mesaj = document.getElementById('mesaj').value;
	
	if (mesaj=='')
	{
		errmsg += "You must enter a message first.\n";
		if (focusfield=='') focusfield = 'mesaj';
	}
	
	if (errmsg!='')
	{
		alert(errmsg);
		document.getElementById(focusfield).focus();
		
		return false;
	}
	
	return true;
}

function form_submit (myform)
{
	theform = document.getElementById(myform);
	theform.submit();
}

function toggle_product_page_up (n)
{
	prod_up_div = document.getElementById('product_page_up');
	prod_up_gal_div = document.getElementById('product_page_up_galerie');
	
	if (n=='galerie')
	{
		prod_up_div.style.display = 'none';
		prod_up_gal_div.style.display = 'block';
	}
	else
	{
		prod_up_div.style.display = 'block';
		prod_up_gal_div.style.display = 'none';
	}
	
	return false;
}

function showfull (img)
{
	imgcontainer = document.getElementById('imgfull');
	
	imgcontainer.src = img;
	
	return false;
}



function open_submenu (id, me)
{
	el = document.getElementById('submenu' + id);
	
	if (!el)
	{
		return false;
	}
	
	if (el.className=='menu_show')
	{
		el.className='menu_hide';
	}
	else
	{
		el.className='menu_show';
	}
	
	if (me.className=='anchor_open')
	{
		me.className='anchor_closed';
	}
	else
	{
		me.className='anchor_open';
	}		
	
}


function applyfilters (pag, rval)
{
	var filters = document.getElementsByName("filter");
	
	filter_string = '';
	
	for (i=0; i<filters.length; i++)
	{
		filter_string = filter_string + filters[i].id + '=' + filters[i].value + ',';
	}
	
	products_div = document.getElementById('products');
	var cat_id1 = document.getElementById('cat_id').value;
	
	var ord1 = document.getElementById('ordprice').value;
	
	ppag1 = document.getElementById('ppag').value;
	
	new Ajax.Request(root + "./?page=ajax_filters&lang=en", {
		parameters: "&cat=" + cat_id1 + "&filters=" + filter_string+ "&pag=" + pag + "&ppag=" + ppag1 + "&pord=" + ord1,
		onSuccess: function(resp) {
			products_div.innerHTML = resp.responseText;
		}
	});
	
	return rval;
}


function applysearchfilters (pag, rval)
{
	products_div = document.getElementById('products');
	var q1 = document.getElementById('qq').value;
	
	ppag1 = document.getElementById('ppag').value;
	
	var ord1 = document.getElementById('ordprice').value;
	
	new Ajax.Request(root + "./?page=ajax_search_filters&lang=en", {
		parameters: "&pag=" + pag + "&q=" + escape(q1) + "&pord=" + ord1 + "&ppag=" + ppag1,
		onSuccess: function(resp) {
			products_div.innerHTML = resp.responseText;
		}
	});
	
	return rval;
}

function applyppag (ppagx)
{
	var filters = document.getElementsByName("filter");
	
	filter_string = '';
	
	for (i=0; i<filters.length; i++)
	{
		filter_string = filter_string + filters[i].id + '=' + filters[i].value + ',';
	}
	
	products_div = document.getElementById('products');
	dppag = document.getElementById('ppag');
	var cat_id1 = document.getElementById('cat_id').value;

	var ord1 = document.getElementById('ordprice').value;
	
	dppag.value = ppagx;
	
	new Ajax.Request(root + "./?page=ajax_filters&lang=en", {
		parameters: "&cat=" + cat_id1 + "&filters=" + filter_string+ "&pag=1&ppag=" + ppagx + "&pord=" + ord1,
		onSuccess: function(resp) {
			products_div.innerHTML = resp.responseText;
		}
	});
}


function applysearchppag (ppagx)
{
	
	products_div = document.getElementById('products');
	dppag = document.getElementById('ppag');
	var q1 = document.getElementById('qq').value;

	var ord1 = document.getElementById('ordprice').value;
	
	dppag.value = ppagx;
	
	new Ajax.Request(root + "./?page=ajax_search_filters&lang=en", {
		parameters: "&q=" + q1 + "&pag=1&ppag=" + ppagx + "&pord=" + ord1,
		onSuccess: function(resp) {
			products_div.innerHTML = resp.responseText;
		}
	});
}



function ordprice ()
{
	var filters = document.getElementsByName("filter");
	
	filter_string = '';
	
	for (i=0; i<filters.length; i++)
	{
		filter_string = filter_string + filters[i].id + '=' + filters[i].value + ',';
	}
	
	products_div = document.getElementById('products');
	ppag1 = document.getElementById('ppag').value;
	var cat_id1 = document.getElementById('cat_id').value;
	
	var ordprice1 = document.getElementById('ordprice').value;
	
	if (ordprice1==1)
	{
		ordprice1 = 0;
	}
	else
	{		
		ordprice1 = 1;
	}
	
	 document.getElementById('ordprice').value = ordprice1;
	
	new Ajax.Request(root + "./?page=ajax_filters&lang=en", {
		parameters: "&cat=" + cat_id1 + "&filters=" + filter_string+ "&pag=1&ppag=" + ppag1 + "&ord=" + ordprice1,
		onSuccess: function(resp) {
			products_div.innerHTML = resp.responseText;
		}
	});
}

function applyord ()
{
	var filters = document.getElementsByName("filter");
	
	filter_string = '';
	
	for (i=0; i<filters.length; i++)
	{
		filter_string = filter_string + filters[i].id + '=' + filters[i].value + ',';
	}
	
	products_div = document.getElementById('products');
	ppag1 = document.getElementById('ppag').value;
	var cat_id1 = document.getElementById('cat_id').value;
	
	var ord1 = document.getElementById('ord').value;
	
	 document.getElementById('ordprice').value = ord1;
	
	
	new Ajax.Request(root + "./?page=ajax_filters&lang=en", {
		parameters: "&cat=" + cat_id1 + "&filters=" + filter_string+ "&pag=1&ppag=" + ppag1 + "&pord=" + ord1,
		onSuccess: function(resp) {
			products_div.innerHTML = resp.responseText;
		}
	});
}


function applysearchord ()
{
	products_div = document.getElementById('products');
	ppag1 = document.getElementById('ppag').value;
	var q1 = document.getElementById('qq').value;
	
	var ord1 = document.getElementById('ord').value;
	
	document.getElementById('ordprice').value = ord1;
	
	
	new Ajax.Request(root + "./?page=ajax_search_filters&lang=en", {
		parameters: "&q=" + q1 + "&pag=1&ppag=" + ppag1 + "&pord=" + ord1,
		onSuccess: function(resp) {
			products_div.innerHTML = resp.responseText;
		}
	});
}





function seltab (id, n)
{
	prod_up_div = document.getElementById('product_page_up');
	prod_up_gal_div = document.getElementById('product_page_up_galerie');
	
	if (id==5)
	{
		prod_up_div.style.display = 'none';
		prod_up_gal_div.style.display = 'block';
	}
	else
	{
		prod_up_div.style.display = 'block';
		prod_up_gal_div.style.display = 'none';
	}
	
	
	
	for (i=1; i<=n; i++)
	{
		
		tab = document.getElementById("tab" + i);
		
		if (tab)
		{
			
			tabcontent = document.getElementById("tab" + i + "-content");
	
			if (id == i)
			{
				tab.className = "tab-selected";
				tabcontent.className = "tab-content-display";
			}
			else
			{
				tab.className = "tab";
				tabcontent.className = "tab-content-hide";
			}
		}
	}
	
	return false;
}

function default_seltab ()
{
	dhref = location.href;
		
	var anchorMatch = /#tab([0-9]+)/i,match;
		
	match=anchorMatch.exec(dhref);
	
	if (match && match[1])
	{
		seltab(match[1]);
	}
}


function opencompat(id)
{
	
	thisdiv = document.getElementById('compat' + id);
	zalink = document.getElementById('compatlink' + id);
	
	if (thisdiv.style.display == 'block')
	{
		thisdiv.style.display = 'none';
		zalink.innerHTML = '[+]';
	}
	else
	{
		thisdiv.style.display = 'block';
		zalink.innerHTML = '[-]';
	}
	
	
	
	return false;
}

function popup_open ( url, w, h, namepop )
{
	if (!w) w=400; 
	if (!h) h=400; 
	if (!namepop) namepop="Popup";
  	win = window.open( url, namepop, 'scrollbars=yes, status=no, toolbar=no,menubar=yes,titlebar=yes,resizable=yes, dependent=1, z-lock=1, width='+w+',height='+h );
 	
	if ( !win )
	{
		alert('It appears that pop-up blockers are enabled on your computer, which may prevent\nsome components from functioning properly. Please temporarily disable any\npop-up blockers.\n\nTo disable the Windows XP pop-up blocker, from the Tools menu in Internet Explorer,\nselect Pop-up Blocker, then Turn Off Pop-up Blocker. To disable other pop-up blockers\nthat are part of a search engine or toolbar, right-click on a toolbar in Internet Explorer\nand click to deselect all toolbars except Standard Buttons, Address Bar, and Links.');
	}	
	else
	{		
		win.moveTo( screen.width/2-w/2, screen.height/2-h/2);
		win.focus();
	}
}

//////////////////////////

if (mobile == undefined) var mobile = {};

var documentBody = $(document.body);

mobile.BrowserCheck = {};
//test for IE6
mobile.BrowserCheck.IE6 = (function(){
	var isIE6 = ((navigator.appName == "Internet Explorer") || navigator.appVersion.indexOf("MSIE") !=-1) && (parseInt(navigator.appVersion) >= 6);

	if (isIE6)
		return true;
	else
		return false;
})();


mobile.InfoIconsManager = Class.create({
	
	_DISPLAY_INFO_BOX_DELAY: 200,	// ms to keep pointer over icon to open box.
	
	_currentInfoIconElement: null,
	_infoBoxElement: null,
	_closeInfoBoxHandlerPrebound: null,
	_mouseoverTimeout: null,

	/**
	 * Constructor. Attaches all event Handlers. 
	 * @param {String} infoIconClassName The CSS class name for info icon links.
	 */
	initialize: function(infoIconClassName) {
		var infoIcons = $$("." + infoIconClassName);
		infoIcons.invoke("observe", "mouseover", this._startDisplayInfoBox.bindAsEventListener(this));
		infoIcons.invoke("observe", "mouseout", this._stopDisplayInfoBox.bind(this));
		infoIcons.invoke("observe", "click", (function(event) {
			Event.findElement(event, 'a').blur();
			event.stop();
		}).bindAsEventListener());
		if (mobile.BrowserCheck.IE6) {
			 document.style = [];
			this._helper = new mobile.IE6Hover();
		}
	},
	
	/**
	 * Handler starting display of info box, will be bound to mouseover event.
	 * Will start a timeout which can be cancelled by a mouseout event, to prevent flickering
	 * if info boxes when moving the pointer across an info icon.
	 * Will call {@link #_displayInfoBox} when timeout is complete.
	 * @param {Object} event
	 */
	_startDisplayInfoBox: function(event) {
		this._stopDisplayInfoBox();
		// Prototype 1.6.0.3 event bug workaround:
		//    In IE we explicitly have to clone the event element.
		//    FF ist just fine with a reference.
		//    See MRO-1.
		var theEvent = Prototype.Browser.IE ? Object.clone(event) : event;
		this._mouseoverTimeout = setTimeout(this._displayInfoBox.bind(this, theEvent), this._DISPLAY_INFO_BOX_DELAY);
	},
	
	/**
	 * Handler stopping a running mouseover timeout.
	 * To be bound to mouseout events.
	 */
	_stopDisplayInfoBox: function() {
		if (this._mouseoverTimeout) {
			clearTimeout(this._mouseoverTimeout);
			this._mouseoverTimeout = null;
		}
	},
	
	/**
	 * Displays an info box belonging to a given info icon element.
	 * Retrieves info box contents, positions the box above the icon and
	 * chooses the proper box alignment depending on viewport position.
	 * @param {Object} event
	 */
	_displayInfoBox: function(event) {
		var element = Event.findElement(event, 'a');
		// console.log("_displayInfoBox %o", element);
		
		var box = this._getInfoBox();
		if (this._currentInfoIconElement != element) {
			var content = this._getInfoBoxContent(element);
			this._updateInfoBoxContent(content);
			this._updateInfoBoxTitle(element.getAttribute('title'));
			this._currentInfoIconElement = element;
			// this._setInfoBoxPosition(element);
		}
		if (mobile.BrowserCheck.IE6) {
			element.insert({after: this._getInfoBox()});
		}
		this._setInfoBoxAlignment(element);
		box.show();
		if (mobile.BrowserCheck.IE6) {
			this._helper.showBackgroundFrame(this._getInfoBox());
		}
	},
	
	/**
	 * Closes (hides) a currently open info box.
	 * To be bound to a mouseleave event.
	 * @param {Object} event
	 * @param {Object} element
	 */
	_closeInfoBoxHandler: function(event, element) {
		// Includes a "mouseleave" emulation for FF:
		if (Prototype.Browser.IE || (event.relatedTarget != event.currentTarget && !event.relatedTarget.childOf(event.currentTarget))) {
			element.hide();
			if (mobile.BrowserCheck.IE6) {
				this._helper.hideBackgroundFrame(this._getInfoBox());
			}
			event.stop();
		}
	},
	
	/**
	 * Getter for info box element. Element will be created ({@link #_createInfoBoxElement})
	 * and attached to DOM if it doesn't exist so far.
	 * @return The info box element. 
	 */
	_getInfoBox: function() {
		if (!this._infoBoxElement) {
			this._infoBoxElement = this._createInfoBoxElement();
		}
		return this._infoBoxElement;
	},
	
	/**
	 * Creates the info box HTML element with all substructures and attaches it to the DOM.
	 * Will also initialize the mouseleave event listening for closing the info box.
	 * @return The info box element.
	 */
	_createInfoBoxElement: function() {
		var documentBody = $(document.body);
		// console.log("_createInfoBoxElement");
		var element = new Element('div', {className: 'infoBoxWrapper'});
		element.innerHTML = "<div class='shadow'></div><div class='infoBox'><div class='infoIcon'></div><h4>Info</h4><a href='#' class='close'>[x]</a><div class='content'></div></div>";
		documentBody.insert({bottom: element});
		element.observe(Prototype.Browser.IE ? "mouseleave" : "mouseout", this._closeInfoBoxHandler.bindAsEventListener(this, element));
		element.down('.close').observe("click", (function(event) {
			element.hide();
			event.findElement('a').blur();
			event.stop();
		}).bindAsEventListener());
		return element;
	},
	
	_updateInfoBoxContent: function(contentHTML) {
		// console.log("_updateInfoBoxContent %o", contentHTML);
		this._getInfoBox().down('.content').update(contentHTML);
	},
	
	_updateInfoBoxTitle: function(title) {
		this._getInfoBox().down('h4').update(title);
	},
	
	_getInfoBoxContent: function(linkElement) {
		// the info element content will be contained in a .infoBoxContent div right after the link.
		var contentWrapper = linkElement.next('.infoBoxContent') || linkElement.up().next('.infoBoxContent');
		if (contentWrapper) {
			// console.log("found info content %o", contentWrapper.innerHTML);
			return contentWrapper.innerHTML;		
		}
	},
	
	/**
	 * Positions the info box element above an info icon.
	 * Does not do any alignment and seems to fail sometimes in IE6, therefore deprecated.
	 * @deprecated
	 * @see #_setInfoBoxAlignment
	 * @param {Object} linkElement
	 */
	_setInfoBoxPosition: function(linkElement) {
		this._getInfoBox().clonePosition(linkElement.down('img'), {
			setWidth: false,
			setHeight: false,
			offsetLeft: -11,
			offsetTop: -11
		});
	},
	
	/**
	 * Positions the info box element above an info icon and determines whether the
	 * info box should be aligned on top, bottom, left or right side.
	 * The code is a bit verbose but should make the calculation easier to understand, I hope.
	 * In IE6 the alignment won't be 
	 */ 
	_setInfoBoxAlignment: function(linkElement) {
		
		var box = this._getInfoBox();
		var element = linkElement.down('img');
		
		var viewportDimensions = document.viewport.getDimensions();
		var viewportOffset = element.viewportOffset();
		var elementOffset = element.cumulativeOffset();
		var boxDimensions = box.getDimensions();
		
		var paddingDistance = 10;
		var hasSpaceBelow = (viewportDimensions.height - viewportOffset.top - boxDimensions.height > paddingDistance);
		var hasSpaceAbove = (viewportOffset.top - boxDimensions.height > paddingDistance);
		var hasSpaceRight = (viewportDimensions.width - viewportOffset.left - boxDimensions.width > paddingDistance);
		var hasSpaceLeft = (viewportOffset.left - boxDimensions.width > paddingDistance);
		
		var boxElement = box.down('.infoBox');
		// console.log("Box has enough space below %o, above %o, left %o, right %o", hasSpaceBelow, hasSpaceAbove, hasSpaceLeft, hasSpaceRight);
		if (!hasSpaceBelow && hasSpaceAbove) {
			box.setStyle({top: (elementOffset.top - boxDimensions.height + 2 * paddingDistance + 1) + "px"});
			boxElement.addClassName("bottom");
		} else {
			box.setStyle({top: (elementOffset.top - paddingDistance - 1) + "px"});
			boxElement.removeClassName("bottom");
		}
		if (!hasSpaceRight && hasSpaceLeft) {
			box.setStyle({left: (elementOffset.left - boxDimensions.width + 2 * paddingDistance + 1) + "px"});
			boxElement.addClassName("right");
		} else {
			box.setStyle({left: (elementOffset.left - paddingDistance - 1) + "px"});
			boxElement.removeClassName("right");			
		}	
	}
});

function validate_cere_form()
{
	errmsg = '';
	focusfield = '';
	
	name = document.getElementById('cere_name').value;
	
	if (name=='')
	{
		errmsg += "You must fill in the name first.\n";
		if (focusfield=='') focusfield = 'cere_name';
	}
	
	email = document.getElementById('cere_email').value;
	
	if (email=='')
	{
		errmsg += "The e-mail address must be filled in.\n";
		if (focusfield=='') focusfield = 'cere_email';
	}
	
	comment = document.getElementById('cere_comment').value;
	
	if (comment=='')
	{
		errmsg += "You must enter a comment first.\n";
		if (focusfield=='') focusfield = 'cere_comment';
	}
	
	if (errmsg!='')
	{
		alert(errmsg);
		document.getElementById(focusfield).focus();
		
		return false;
	}
	else
	{
		cere_id1 = document.getElementById('cere_id').value;
		cere_name1 = document.getElementById('cere_name').value;
		cere_email1 = document.getElementById('cere_email').value;
		cere_tel1 = document.getElementById('cere_tel').value;
		cere_comment1 = document.getElementById('cere_comment').value;
		cere_captcha1 = document.getElementById('cere_captcha').value;
		
		document.getElementById('cere_msg_error').innerHTML = '';
		
		new Ajax.Request(root + "./?page=cere_info", {
			parameters: "&id=" + cere_id1 + "&cere_name=" + cere_name1 + "&cere_email=" + cere_email1 + "&cere_tel=" + cere_tel1 + "&cere_comment=" + cere_comment1 + "&cere_captcha=" + cere_captcha1,
			onSuccess: function(resp) {
			
				if (resp.responseText.indexOf("\"errormsg\"")== -1)
				{		
					tab6 = document.getElementById('tab6-content');	
					tab6.innerHTML = resp.responseText;
				}
				else
				{
					tab6 = document.getElementById('cere_msg_error');	
					tab6.innerHTML = resp.responseText;
				}
			}
		});
		
		return false;
	}
	
	return true;
}

Element.observe(window, "load", function() {
	new mobile.InfoIconsManager('infoIconLink');
})


function show_menu_slide (id, mya)
{
     	
	if ($j("#menu_ul"+id).is(":hidden")) {
		$j("#menu_ul"+id).slideDown("fast");
		
		mya.className = "menu_ul_a_level0_open";
		
	} else {
		$j("#menu_ul"+id).slideUp("fast");
		
		mya.className = "menu_ul_a_level0_closed";
	}
	
	return false;
}