function get_state_value()
{
	var pars = "city="+$F("city")+"&state="+$F("state");
	return pars;
}

function set_action_choose_account_type_address(customers_type, address_type)
{
	
	var shipping_company_details_page = $("company_details");
	var shipping_person_details_page = $("person_details");
	
	if(customers_type == 1)
	{
		shipping_company_details_page.style.display = 'none';
		shipping_person_details_page.style.display = 'block';			
	}
	else
	{			
		shipping_company_details_page.style.display = 'block';
		shipping_person_details_page.style.display = 'none';			
		
	}
	
	
}

//================================================================================================================================
//================================================================================================================================

function Ajax_Updater(url, pars, div_to_update)
{	
	pars+="&div_to_update="+div_to_update;
	
	var myAjax = new Ajax.Request( url,

										{
											
										  method: 'post',
										  parameters: pars,
										  onComplete: Ajax_Updater_FromServer
										  
										}

							);
}

function Ajax_Updater_FromServer(originalRequest)
{
	Try.these(
			function () {				
				
				var jsonObject = eval('(' + originalRequest.responseText + ')');				
			
				
				var div_to_update = jsonObject['div_to_update'];
				var content_div = jsonObject['content_div'];						
			
				$(div_to_update).innerHTML = content_div;
			
				
			}//function ()			
			
			
	);	
}

//================================================================================================================================
//================================================================================================================================


//================================================================================================================================
//FUNCTIONS ADDRESS  BOOK, CREATE NEW ACCOUNT
//================================================================================================================================

function set_action_choose_country()
{
	var country = $F("country");
	
	var url = dir_value+"ajax.php";
	var pars = "action_list=get_states&country="+country;	
	
	var myAjax = new Ajax.Updater("div_input_state_content" , url, { method: 'post',  parameters: pars });	
		
}

//================================================================================================================================
//================================================================================================================================


//================================================================================================================================
//function set action add accesories to cart
//================================================================================================================================

function set_action_add_accesorii_to_cart(key)
{
	var qty = $F("qty_"+key);
	var products_id = $F("products_id_"+key);
	var url = $F("action_link");
	
	var pars = "products_id="+products_id+"&qty="+qty+"&action_list=add_products_accesories_to_cart&key="+key;
	
		
	
	var myAjax = new Ajax.Request( url,

											{
												
											  method: 'post',
											  parameters: pars,
											  onComplete: set_action_add_accesorii_to_cart_from_server
											  
											}

								);
	
	
	
}


function set_action_add_accesorii_to_cart_from_server(originalRequest)
{
	Try.these(
		function () 
		{				
				
			var jsonObject = eval('(' + originalRequest.responseText + ')');				
			
				
			var action_result = jsonObject['action_result'];
			
			switch(action_result)
			{
				case "add_products_accesories_to_cart_ok":
				
					key = jsonObject['key'];				
					var div_alert_page = $("div_alert_error_"+key);
					
					//alert(key);
					
					div_alert_page.style.display = 'block';
					div_alert_page.innerHTML = jsonObject['alert_msg'];
					
					var shopping_cart_products_totals_page = $("shopping_cart_products_totals");
					var shopping_cart_total_page = $("shopping_cart_total");
					
								
					shopping_cart_products_totals_page.innerHTML = jsonObject['cart_products'];
					shopping_cart_total_page.innerHTML = jsonObject['cart_total'];
					
					
				break;
				
				case "add_products_accesories_to_cart_not_ok":		
					
					
				break;
			}
			
				
		}//function ()			
			
			
	);

	
}

//================================================================================================================================
//================================================================================================================================

function check_submit_search_form(field_name)
{
	
	var ok = true;
	
	if(field_name)
	{
		var keywords = $F(field_name);	
	}
	else
	{
		var keywords = document.quick_find.keywords.value;	
	}
	
	if(keywords.length<2)
	{
		if(language == "english")
		{
			alert("Please enter the search word.");	
		}
		else		
		{
			alert("Va rugam sa introduceti cuvantul de cautare.");
		}
		ok = false;
	}
	
	return ok;
}


function close_box_add_in_cart()
{
	hideBox('overlay_main_page', 'div_content_effect_add_in_cart');
}

//========================================================================================================================================
//BEGIN functions for the homepage main banner
//========================================================================================================================================
var divs = new Array("container","container1", "container2", "container3", "container4", "container5");
var divs2 = new Array();
var currentDiv = 0;
// homepage main banner
//check which divs contain a commercial
function checkDivs() {
	for(i=0;i<divs.length;i++)
	{
		//alert(document.getElementById(divs[i]).childNodes.length);
		if (navigator.appName == 'Microsoft Internet Explorer')
		{
			if(document.getElementById(divs[i]))
			{
				if (document.getElementById(divs[i]).childNodes.length == 5)
				{
					divs2[divs2.length] = divs[i];
				}
			}
		}
		else
		{
			if(document.getElementById(divs[i]))
			{
				if (document.getElementById(divs[i]).childNodes.length == 8)
				{
					//alert("aici");
					divs2[divs2.length] = divs[i];
				}
			}
		}
	}
	spitOutLinks();

}

// homepage main banner
//spit out the links according to the number of active ones
function spitOutLinks()
{
	var content_divs = '';

	for (i=0;i<divs2.length;i++)
	{
		//document.write(' <li class="inverted"><a href="javascript: void(0);" id="link' + i + '" onclick="javascript: selectedShow(\'' + i + '\');">test1</a></li><li class="spacer"></li>');
		
		content_divs += ' <li class="inverted"><a href="javascript: void(0);" id="link' + i + '" onclick="javascript: selectedShow(\'' + i + '\');">test1</a></li><li class="spacer"></li>';

		//
		if(i*1 == 2)	
		{
			//alert("aici");
			//document.write('</ul></div><div class="float_left" style="font-size:5px;width:5px;float:left">&nbsp;</div><div id="tab-optiuni" class="float_left" style="float:left"><ul>');

			content_divs += '</ul></div><div class="float_left" style="font-size:5px;width:5px;float:left">&nbsp;</div><div id="tab-optiuni" class="float_left" style="float:left"><ul>';
		}
	}

	document.write(content_divs);
	first();
}

// homepage main banner
//get the alternate text from the image and print out
function first() {
	for (i=0;i<divs2.length;i++) {

		if (document.getElementById(divs2[i])) {
			if (navigator.appName == 'Microsoft Internet Explorer') {
				var el = document.getElementById(divs2[i]).childNodes[2].childNodes[0].alt;
			}
			else {
				var el = document.getElementById(divs2[i]).childNodes[3].childNodes[0].alt;
			}
			var els = el.substring(0,16);
			document.getElementById('link'+i).innerHTML = els+"...";
		}
	}

	if (document.getElementById(divs2[0])) {
		document.getElementById(divs2[0]).style.display = 'block';
		document.getElementById("link0").className = 'selectatz';
	}

	timer = window.setInterval("cycle()",13000);
	cycle();
}

// homepage main banner
function cycle() {
	if(divs2.length==0) {
		return;
	}
	if (currentDiv == '') {
		currentDiv = 0;
	}

	if (currentDiv == divs2.length) {
		currentDiv = 0
	}

	for (i=0;i<divs2.length;i++) {
		if (document.getElementById(divs[i])) {
			document.getElementById(divs[i]).style.display = 'none';
			document.getElementById('link'+i).className = '';
		}
	}
	try{
	if (document.getElementById(divs[currentDiv])) {
		document.getElementById(divs[currentDiv]).style.display = 'block';
		try {
			document.getElementById('link'+currentDiv).className = 'selectatz';
		} catch(err) {
			//error processing stripped
		}
	}} catch(err) {
		//error processing stripped
	}
	currentDiv++
}

// homepage main banner
function selectedShow(id) {

	window.clearInterval(timer);

	for (i=0;i<divs2.length;i++) {
		if (document.getElementById(divs[i])) {
			document.getElementById(divs[i]).style.display = 'none';
			document.getElementById('link'+i).className = '';
		}
	}
	if (document.getElementById(divs[id])) {
		document.getElementById(divs[id]).style.display = 'block';
		document.getElementById('link'+id).className = 'selectatz';
	}
}

//========================================================================================================================================
// END functions for the homepage main banner
//========================================================================================================================================



//========================================================================================================================================
//FUNCTION TELL A FRIEND
//========================================================================================================================================
function set_action_tell_a_friend()
{
	var tell_name = $F("tell_name");
	var tell_email = $F("tell_email");
	var friend_email = $F("friend_email");
	var friend_name = $F("friend_name");
	
	var tell_comments = $F("tell_comments");
	
	var tell_a_friend_err_div_page = $("tell_a_friend_err_div");
	
	var products_id = $F("products_id");
	
	var ok = true;
	
	text_error = "";
	
	if(tell_name.length<3)
	{
		if(language == "english")	
		{
			text_error+="Please enter your name.<br>";
		}
		else
		{
			text_error+="Va rugam sa va introduceti numele.<br>";
		}
		
		ok = false;		
	}
	
	if(!validate_email(tell_email))
	{
		if(language == "english")
		{
			text_error+="Please enter your email.<br>";
		}
		else
		{
			text_error+="Va rugam sa va introduceti emailul.<br>";
		}
		ok = false;		
	}
	
	if(friend_name.length<2)
	{
		if(language == "english")
		{
			text_error+="Please enter your friend name.<br>";
		}
		else
		{
			text_error+="Va rugam sa introduceti numele prietenului.";
		}
		ok = false;	
	}
	
	
	if(!validate_email(friend_email))
	{
		if(language == "english")
		{
			text_error+="Please enter your friend email.<br>";
		}
		else
		{
			text_error+="Va rugam sa introduceti emailul prietenului.<br>";
		}
		ok = false;		
	}
	
	
	if(ok)
	{
		tell_a_friend_err_div_page.innerHTML = "";
		
		var url = dir_value+"ajax.php";
		var pars = "action_list=tell_a_friend&tell_name="+tell_name+"&tell_email="+tell_email+"&tell_comments="+tell_comments+"&products_id="+products_id+"&friend_email="+friend_email+"&friend_name="+friend_name;
		
		var myAjax = new Ajax.Request( url,

											{
												
											  method: 'post',
											  parameters: pars,
											  onComplete: set_action_tell_a_friend_from_server
											  
											}

								);
								
								
		
		
	}
	else
	{
		tell_a_friend_err_div_page.innerHTML = text_error;
	}
	
	
}

function set_action_tell_a_friend_from_server(originalRequest)
{
	Try.these(
			function () {				
				
			var jsonObject = eval('(' + originalRequest.responseText + ')');				
			
				
			var action_result = jsonObject['action_result'];
			
			switch(action_result)
			{
				case "tell_a_friend_ok":
					 $("tell_comments").value="";					 
					 $("tell_a_friend_alert_div").innerHTML = jsonObject['alert_msg'];
					 setTimeout("hideBox('overlay_main_page', 'tell_a_friend_details')", 1500);
				break;
				
				case "tell_a_friend_not_ok":
				
					$("tell_a_friend_err_div").innerHTML = jsonObject['err_msg'];
					
				break;
			}
			
				
			}//function ()			
			
			
	);	
	
}

//========================================================================================================================================
//========================================================================================================================================

//========================================================================================================================================
//PRODUCTS COMPARATIONS
//========================================================================================================================================
function add_product_to_comparation()
{
	var url = dir_value+"ajax.php";	
	var nr_products_per_page = $F("nr_products_per_page");
	
	
	
	var nr_products_comparation = $F("nr_products_comparation");
	var categories_id = $F("categories_id");
	
	//alert(nr_products_comparation);
	
	var nr_new_selected = 0;
	var pars = "action_list=add_products_to_compare&categories_id="+categories_id;
	
	
	
	for(var i=0; i<nr_products_per_page; i++)
	{
		var compare = $("compare_"+i);
		if(compare.checked == true)		
		{
			var products_id = $F("products_id_"+i);						
			pars += "&products_id_"+nr_new_selected+"="+products_id;
			
			nr_new_selected++;
			
		}
		
	}
	
	pars += "&nr_new_selected="+nr_new_selected;
	
	
	
	var nr_total_products = ((nr_products_comparation*1)+(nr_new_selected*1));
	if( nr_total_products < 2 )
	{
		if(language == "english")
		{
			alert("Please select more than one product.");
		}
		else
		{
			alert("Va rog sa adaugati mai mult de un produs.");
		}
	}
	else
	{	
		
		var myAjax = new Ajax.Request( url,

											{
												
											  method: 'post',
											  parameters: pars,
											  onComplete: add_product_to_comparation_from_server
											  
											}

								);
										
	}
	

}

function add_product_to_comparation_from_server(originalRequest)
{
	Try.these(
			function () {				
				
			var jsonObject = eval('(' + originalRequest.responseText + ')');				
			
				
			var action_result = jsonObject['action_result'];
			var nr_total_products = jsonObject['nr_total_products'];
			var categories_id = jsonObject['categories_id'];
			
						
			parent.window.document.getElementById("nr_products_comparation").value = nr_total_products;
			
			switch(action_result)
			{
				case "add_products_to_compare_ok":
					 //var categories_id = $F("categories_id");
					 //window.open ("products_comparation.php?categories_id="+categories_id, "Products","width=900,height=700, scrollbars=1"); 
					 
					 var iframe_location = "products_comparation.php?categories_id="+categories_id;					 
					 parent.window.compare_products_iframe.location = iframe_location;
					 
					 if($("box_compare_products").style.display == "none")
					 {
					 	showBox('overlay_main_page', 'box_compare_products');
					 }
					 
				break;
				
				case "add_products_to_compare_not_ok":
					if(language == "english")
					{
						alert("Please select more than one product.");
					}
					else
					{
						alert("Va rog sa adaugati mai mult de un produs.");
					}
				break;
			}
			
				
			}//function ()			
			
			
	);	
	
}

function set_action_remove_product_from_compare(products_id, categories_id)
{
	var url = dir_value+"ajax.php";
	var pars = "action_list=remove_product_from_comparation&products_id="+products_id+"&categories_id="+categories_id;
	
	var myAjax = new Ajax.Request( url,

											{
												
											  method: 'post',
											  parameters: pars,
											  onComplete: set_action_remove_product_from_compare_from_server
											  
											}

								);
	
}

function set_action_go_to_product_from_overlay(products_url)
{
	//alert(products_url);
	parent.window.location = products_url;
	parent.window.hideBox('overlay_main_page', 'box_compare_products');
	
}

function set_action_remove_product_from_compare_from_server(originalRequest)
{
	Try.these(
			function () {				
				
			var jsonObject = eval('(' + originalRequest.responseText + ')');							
				
			var action_result = jsonObject['action_result'];
			var categories_id = jsonObject['categories_id'];	
			
			var nr_left_products = jsonObject['nr_left_products'];
			
			switch(action_result)
			{
				case "remove_product_from_comparation_ok":
					 
					 //window.open ("products_comparation.php?categories_id="+categories_id, "Products","width=900,height=700, scrollbars=1"); 					 
					 //alert(nr_left_products);
					 if(nr_left_products == 0)
					 {
					 	parent.window.hideBox('overlay_main_page', 'box_compare_products');
					 }
					 else
					 {
					 	var iframe_location = "products_comparation.php?categories_id="+categories_id;				 
					 	parent.window.compare_products_iframe.location = iframe_location;
					 }
					 
					// showBox('overlay_main_page', 'box_compare_products');
					 
				break;
				
				case "remove_product_from_comparation_not_ok":
					
				break;
			}
			
				
			}//function ()						
			
	);	
	
}


function add_product_single_product_to_comparation(categories_id)
{
	
	var products_id_var = $F("other_products_id");
	
	var pars = "action_list=add_products_to_compare&categories_id="+categories_id+"&products_id_0="+products_id_var+"&nr_new_selected=1";	
	var url = dir_value+"ajax.php";
	
	
		
	var myAjax = new Ajax.Request( url,

											{
												
											  method: 'post',
											  parameters: pars,
											  onComplete: add_product_to_comparation_from_server
											  
											}

								);		
}

//========================================================================================================================================
//========================================================================================================================================

//========================================================================================================================================
//========================================================================================================================================
function set_action_top_searches(keyword_searched)
{
	document.quick_find.keywords.value = keyword_searched;
	document.quick_find.submit();
	
	return false;
}
//========================================================================================================================================
//========================================================================================================================================

function update_selected_image(image_selected, products_id)
{
	var url = dir_value+"ajax.php";
	var pars = "action_list=update_selected_image&image_selected="+image_selected+"&products_id="+products_id;
	
	//var myAjax = new Ajax.Updater("product_images_content_div" , url, { method: 'post',  parameters: pars });	
	
	Ajax_Updater(url, pars, "product_images_content_div");
	
	
}



function update_project_selected_image(image_selected)
{
	var url = dir_value+"ajax.php";
	var pars = "action_list=update_project_selected_image&image_selected="+image_selected;
	
	//var myAjax = new Ajax.Updater("div_project_images" , url, { method: 'post',  parameters: pars });	
	
	Ajax_Updater(url, pars, "div_project_images");
}

function update_selected_project(projects_id)
{
	
	var selected_projects_id = $F("selected_projects_id");
	
	$("a_project_"+selected_projects_id).style.backgroundColor = "#ffffff";
	$("a_project_"+projects_id).style.backgroundColor = "#efefef";
	
	$("selected_projects_id").value = projects_id;
	
	
	var url = dir_value+"ajax.php";
	var pars = "action_list=update_project_selected&projects_id="+projects_id;
	
	//var myAjax = new Ajax.Updater("div_content_selected_portfolio" , url, { method: 'post',  parameters: pars });	
	
	Ajax_Updater(url, pars, "div_content_selected_portfolio");
	
	
	
}


function set_action_submit_review()
{
	var ok = true;
	
	var add_review_err_div_page = $("add_review_err_div");
	var reviews_text = $F("reviews_text");		
	var rating = document.cart_quantity.rating;
	var customer_id = $F("review_customer_id");
	var language_id = $F("language_id");
	var products_id = $F("products_id");
	var customers_name = $F("customers_name");
	
	
	
	
	text_error = "";
	
	/*
	if(customer_id == 0)
	{
		ok = false;
		if(language == "english")
		{
			text_error+="Please login in order to add your review.<br>";
		}
		else
		{
			text_error+="Va rog sa va logati pentru a adauga un review.<br>";
		}
		
	}
	*/
	
	if(customers_name.length < 3)
	{
		ok = false;
		if(language == "english")
		{
			text_error+="Please enter your name.<br>";
		}
		else
		{
			text_error+="Va rog sa va introduceti numele dvs.<br>";
		}	
	}
	
	if(reviews_text.length < 10)
	{
		ok = false;
		if(language == "english")
		{
			text_error+="Your review needs to have min 10 characters.<br>";
		}
		else
		{
			text_error+="Comentariul dvs trebuie sa aibe minim 10 caractere.<br>";
		}
	}
	
	var check_rating = false;
	var radio_value = 0;
	for(var i=0; i<rating.length; i++)
	{
		if(rating[i].checked == true)
		{
			check_rating = true;
			radio_value = rating[i].value;
			break;
		}
	}
	
	if(check_rating == false)
	{
		ok = false;
		if(language == "english")
		{
			text_error+="Please choose rating for this product";
		}
		else
		{
			text_error+="Va rog sa votati acest produs.";
		}
		
	}
	
	if(ok)
	{
		add_review_err_div_page.innerHTML = "";
		var url = dir_value+'ajax.php';
		var pars = "action_list=add_review&reviews_text="+reviews_text+"&rating="+radio_value+"&customer_id="+customer_id+"&products_id="+products_id+"&language_id="+language_id+"&customers_name="+customers_name;

		var myAjax = new Ajax.Request( url,

											{
												
											  method: 'post',
											  parameters: pars,
											  onComplete: set_action_submit_review_from_server
											  
											}

								);
								
									
	}
	else
	{
		add_review_err_div_page.innerHTML = text_error;
	}
	
	
}

function set_action_submit_review_from_server(originalRequest)
{
	Try.these(
			function () {				
				
			var jsonObject = eval('(' + originalRequest.responseText + ')');				
			
				
			var action_result = jsonObject['action_result'];
			
			switch(action_result)
			{
				case "add_review_ok":
				
					$("reviews_text").value="";
					$("customers_name").value="";
					var rating = document.cart_quantity.rating;
					for(var i=0; i<rating.length;i++)					
					{
						rating[i].checked = false;
					}
					
				
					var products_id_var = jsonObject['products_id'];	

					/*
								
					var url = "ajax.php";		
					
					var pars = "action_list=update_reviews&products_id="+products_id_var;	
					var myAjax = new Ajax.Updater("product_reviews_content_div" , url, { method: 'post',  parameters: pars });
					
					var pars = "action_list=update_reviews_total&products_id="+products_id_var;	
					var myAjax = new Ajax.Updater("content_reviews_total_top" , url, { method: 'post',  parameters: pars });
					
					*/
					
					var add_review_err_div_page = $("add_review_err_div");
					add_review_err_div_page.style.color = "blue";
					if(language == "english")
					{
						add_review_err_div_page.innerHTML = "Your review was added. It will be approved by our web adminstrator."
					}
					else
					{
						add_review_err_div_page.innerHTML = "Comentariul dvs. a fost adaugat. Va fi in curand aprobat de administratorul site-ului."
					}
					
					
					
				break;
				
				case "add_review_ok_not_ok":
				break;
			}
			
				
			}//function ()			
			
			
	);	
}

function set_action_vote_review(reviews_id, vote_atitude)
{
	
	var url = dir_value+'ajax.php';
	var pars = "action_list=vote_for_review&reviews_id="+reviews_id+"&vote_atitude="+vote_atitude;
		
	var myAjax = new Ajax.Request( url,

											{
												
											  method: 'post',
											  parameters: pars,
											  onComplete: set_action_vote_review_from_server
											  
											}

								);
								
}

function set_action_vote_review_from_server(originalRequest)
{
	Try.these(
			function ()
			{				
				
				var jsonObject = eval('(' + originalRequest.responseText + ')');				
			
			
				var reviews_id = jsonObject["reviews_id"];	
				var reviews_votes = jsonObject["reviews_votes"];
				var reviews_votes_for = jsonObject["reviews_votes_for"];			
			
				if( (reviews_id > 0) && (reviews_votes_for > 0))
				{
					if(language == "english")
					{
						$("review_totals_"+reviews_id).innerHTML = reviews_votes_for+" out of "+reviews_votes+" found usefull this review.";		
					}
					else
					{
						$("review_totals_"+reviews_id).innerHTML = reviews_votes_for+" din "+reviews_votes+" au gasit util acest comentariu.";		
					}
				}
			
				
			}//function ()			
			
			
	);	
		
}

//===========================================================================================================================================
//===========================================================================================================================================



function set_action_choose_state()
{
	var country = document.getElementById("country").value;
	
	var url = dir_value+"ajax.php";
	var pars = "action_list=get_states&country="+country;
	
	var state = document.getElementById("state");		
	
	state.options[0] = new Option("Loading...", "0");
	state.selectedIndex = 0;
	state.disabled = true;
	
	var myAjax = new Ajax.Request( url,

											{ method: 'get',
											  parameters: pars,
											  onComplete: set_action_choose_state_from_server
											}

										 );			
	
	
}

function set_action_choose_state_from_server(originalRequest)
{
	var xml = originalRequest.responseXML;//we have the xml object
	
	var respNode = xml.getElementsByTagName("response")[0];		
	var items = respNode.getElementsByTagName("item");
	
	var state = $("state");
	
	state.options[0] = new Option("Choose", "0");
	state.options.length  = 1;

	if(items.length > 0)
	{

		for (var i=0; i<items.length; i++)
		{
		  if (items[i].getElementsByTagName("name")[0].firstChild==null)
		  {
			  //city_id.options[i] = new Option("","");
		  }
		  else
		  {
			   var name = items[i].getElementsByTagName("name")[0].firstChild.nodeValue;
			   var value = items[i].getElementsByTagName("value")[0].firstChild.nodeValue;		   

			   state.options[i+1] = new Option(name, value);
		   }
		}
		
	}
	else
	{
		//state.options[1] = new Option("--Other City--", "-1");
		//state.options.length  = 2;
	}

	
	state.disabled = false;	
}


function set_class_general(element_obj,new_class_name)
{
	element_obj.setAttribute("class", new_class_name);
	element_obj.setAttribute("className", new_class_name);
}


function set_action_subcat(div_id, link_location, action)
{
	var div_cat_object = $(div_id);
	
	switch(action)
	{
		case "over":
		set_class_general(div_cat_object,'menu_top_sub_cat_over');
		break;
		
		case "out":
		set_class_general(div_cat_object,'menu_top_sub_cat_out');
		break;
		
		case "click":
		window.location = link_location;
		break;
	}
}


function show_more_products(type, af_1, af_2, tpl_path)
{
	
	var limit_new_products = $F("limit_"+type+"_products");		
	var nr_new_products = $F("nr_"+type+"_products");
	var limit = (limit_new_products*1)+1;			
	var a_new_show_more_page = $("a_"+type+"_show_more");
		
	var span_container = $("arrow_"+type);
	

	if(a_new_show_more_page.innerHTML==af_1)
	{
		for(i=limit; i<=nr_new_products;i++)	
		{
			$("products_"+type+"_"+i).style.display = "block";
		}
		a_new_show_more_page.innerHTML = af_2;
		span_container.innerHTML = '<img src="'+tpl_path+'img/arrows/arrow_grey_up.gif">';		

	}
	else
	{
		for(i=limit; i<=nr_new_products;i++)	
		{
			$("products_"+type+"_"+i).style.display = "none";
		}
		a_new_show_more_page.innerHTML = af_1;
		span_container.innerHTML = '<img src="'+tpl_path+'img/arrows/arrow_grey_down.gif">';
		
	}
	
}

function set_action_add_to_cart_list(order)
{
	var products_id = $F("products_id_"+order);
	var products_qty = $F("products_qty_"+order);
		
	document.cart_quantity.products_id.value = products_id;
	document.cart_quantity.products_qty.value	= products_qty;
	
	document.cart_quantity.submit();
	return false;
}


function set_filter_values_more(filter_id, nr_values, nr_values_af, text_more, text_less)
{
	var a_more_obj = $(filter_id+"_view_more");
	nr_values_af = nr_values_af*1;
	nr_values = nr_values*1;
	if(a_more_obj.innerHTML == text_more)
	{		
		for(i=nr_values_af; i<nr_values; i++)
		{			
			$(filter_id+"_"+i).style.display = "block";
		}
		a_more_obj.innerHTML = text_less;
	}
	else
	{
		for(var i=nr_values_af; i<nr_values; i++)
		{
			$(filter_id+"_"+i).style.display = "none";
		}
		a_more_obj.innerHTML = text_more;
	}
}



function set_action_reset_filter(field_id)
{
	var frm = document.dropdown_filter;
	
	var field_form = eval('document.dropdown_filter.'+field_id);
	field_form.value = 0;
	
	frm.submit();
	return false;
}

function set_action_reset_filter_all(categories_name_url)
{
	var frm = document.dropdown_filter;
	frm.action = categories_name_url		
	frm.reset_all.value = 0;		
	frm.submit();
	return false;
}



function set_action_filter_mouse(div_id, action_mouse, id_field, value_field)
{
	var div_id_object = document.getElementById(div_id);
	
	var frm = document.dropdown_filter;
	
	switch(action_mouse)
	{
		case "over":
		set_class_general(div_id_object,'filter_over');
		break;
		
		case "out":
		set_class_general(div_id_object,'filter_out');
		break;
		
		case "click":
		
		   /*	
			var field_form = eval('document.dropdown_filter.'+id_field);
			field_form.value = value_field;
			frm.submit();
			return false;
			*/
		   
		   frm.action = value_field;
		   frm.submit();
		   return false;
			
		break;
	}
	
	
}

function set_active_tab(new_selected_tab)
{
    var last_selected_tab = last_tab;
    
    var last_selected_tab_obj = $("tab_"+last_selected_tab);
    
    //alert(last_selected_tab_obj.childNodes[0]);
    
    var available_children = last_selected_tab_obj.getElementsByTagName("td");
    
    set_class_general(available_children[0],"tnsleft");
    set_class_general(available_children[1],"tnsline");
    set_class_general(available_children[2],"tnsright");
    
   $("tab_content_"+last_selected_tab).style.display="none";
   $("tab_content_"+new_selected_tab).style.display="block";
    
    var new_selected_tab_obj = $("tab_"+new_selected_tab);
    
    var available_children = new_selected_tab_obj.getElementsByTagName("td");
    
    set_class_general(available_children[0],"tsleft");
    set_class_general(available_children[1],"tsline");
    set_class_general(available_children[2],"tsright");
    
    last_tab = new_selected_tab;
    
    return false;
    
}


delay = 105;

i = 0;
do_not_hide = "";
menu_array = Array();



// ----- Popup Control ---------------------------------------------------------

function at_display(x)
{
  win = window.open();
  for (var i in x) win.document.write(i+' = '+x[i]+'<br>');
}

// ----- Show Aux -----

function at_show_aux(parent, child, width_left)
{
  var p = document.getElementById(parent);
  var c = document.getElementById(child);

  var top  = (c["at_position"] == "y") ? p.offsetHeight : 0;
  var left = (c["at_position"] == "x") ? p.offsetWidth - 217 : 0;

  for (; p; p = p.offsetParent)
  {
    top  += p.offsetTop;
    left += p.offsetLeft;
  }

  c.style.position   = "absolute";
  c.style.top        = top +'px';
  c.style.left       = left+'px';
  c.style.visibility = "visible";
}

// ----- Show -----
i = 0;
function at_show()
{//if you go over a menu, you show all it's children.
//if the menu you are over is a subchild, you should also show it's grandfather.
  p = document.getElementById(this["at_parent"]);
  set_class_general(p,'menu_top_main_cat_over');
  c = document.getElementById(this["at_child" ]);
  i++;
  at_show_aux(p.id, c.id, 1);

/*
  if (p.id == "menu_subcat_1_name_3" || p.id == "menu_cat_1_names" || p.id == "menu_subcat_1_3	")
  {
    at_show_aux("menu_cat_1", "menu_cat_1_names");
	do_not_hide = "menu_cat_1_names";
	document.getElementById("debug").innerHTML += i+"|it should also show menu_cat"+"<br>";

	main_cat = document.getElementById("menu_cat_1");
	  clearTimeout(main_cat["at_timeout"]);
  }
  else
  {
	do_not_hide = "";
  }
*/
//  document.getElementById("debug").innerHTML += "<tr><td>"+this.id+":"+"at_show</td><td>:"+i+"|</td><td>"+c["at_position"] +"|</td><td>parent:"+p.id+"|</td><td>child:"+c.id+"</td><br>";

//  document.getElementById("debug").innerHTML += i+"|"+"at_show:"+"|"+this.id+":"+c["at_position"] +"|parent:"+p.id+"|child:"+c.id+"<br>";

  clearTimeout(c["at_timeout"]);
}

// ----- Show Grandson -----

function at_show_grandson()
{//if you go over a menu, you show all it's children.
//if the menu you are over is a subchild, you should also show it's grandfather.
  p = document.getElementById(this["at_parent"]);
  c = document.getElementById(this["at_child" ]);

  g1 = document.getElementById(this["at_grandparent1"]);
  g2 = document.getElementById(this["at_grandparent2"]);

  at_show_aux(g1.id, g2.id, 150);

  clearTimeout(g2["at_timeout"]);

  at_show_aux(p.id, c.id, 150);

i++;
// document.getElementById("debug").innerHTML += i+"|"+"at_show_grandson:"+"|"+this.id+":"+c["at_position"] +"|grandparent1:"+g1.id+"|grandparent2:"+g2.id+"|parent:"+p.id+"|child:"+c.id+"<br>";


  clearTimeout(c["at_timeout"]);
}

// ----- Hide -----

function at_hide()
{//if you get out of a menu, you close all it's children
	i++;
	p = document.getElementById(this["at_parent"]);
	set_class_general(p,'menu_top_main_cat_out');
	
	c = document.getElementById(this["at_child"]);

	c["at_timeout"] = setTimeout("document.getElementById('"+c.id+"').style.visibility = 'hidden'", delay);

  
//  document.getElementById("debug").innerHTML += i+"|"+"at_hide:"+"|"+this.id+":"+c["at_position"]+"|parent:"+p.id+"|child:"+c.id+"<br>";

}

// ----- Hide Grandson -----
function at_hide_grandson()
{//if you get out of a menu, you close all it's children
  c = document.getElementById(this["at_child"]);
  p = document.getElementById(this["at_grandparent2"]);

  c["at_timeout"] = setTimeout("document.getElementById('"+c.id+"').style.visibility = 'hidden'", delay);
  p["at_timeout"] = setTimeout("document.getElementById('"+p.id+"').style.visibility = 'hidden'", delay);
}

// ----- Click -----

function at_click()
{
  p = document.getElementById(this["at_parent"]);
  c = document.getElementById(this["at_child" ]);

  if (c.style.visibility != "visible") at_show_aux(p.id, c.id, "1");
  else c.style.visibility = "hidden";

  return false;
}

// ----- Attach -----

// PARAMETERS:
// parent   - id of visible html element
// child    - id of invisible html element that will be dropdowned
// showtype - "click" = you should click the parent to show/hide the child
//            "hover" = you should place the mouse over the parent to show
//                      the child
// position - "x" = the child is displayed to the right of the parent
//            "y" = the child is displayed below the parent
// cursor   - Omit to use default cursor or check any CSS manual for possible
//            values of this field

function at_attach(parent, child, showtype, position, cursor)
{
  p = document.getElementById(parent);
  c = document.getElementById(child);

  p["at_parent"]     = p.id;
  c["at_parent"]     = p.id;
  p["at_child"]      = c.id;
  c["at_child"]      = c.id;
  p["at_position"]   = position;
  c["at_position"]   = position;

  c.style.position   = "absolute";
  c.style.visibility = "hidden";

  if (cursor != undefined) p.style.cursor = cursor;

  switch (showtype)
  {

    case "hover":
      p.onmouseover = at_show;
      p.onmouseout  = at_hide;
      c.onmouseover = at_show;
      c.onmouseout  = at_hide;
      break;
  }
}

function at_attach_sub(grand_parent1, grand_parent2, parent, child, showtype, position, cursor)
{
  p = document.getElementById(parent);
  c = document.getElementById(child);

  p["at_grandparent1"]     = grand_parent1;
  p["at_grandparent2"]     = grand_parent2;
  c["at_grandparent1"]     = grand_parent1;
  c["at_grandparent2"]     = grand_parent2;
  
  p["at_parent"]     = p.id;
  c["at_parent"]     = p.id;

  p["at_child"]      = c.id;
  c["at_child"]      = c.id;
  p["at_position"]   = position;
  c["at_position"]   = position;

  c.style.position   = "absolute";
  c.style.visibility = "hidden";

  if (cursor != undefined) p.style.cursor = cursor;

  switch (showtype)
  {

    case "hover":
      p.onmouseover = at_show;
      p.onmouseout  = at_hide;
      c.onmouseover = at_show_grandson;
      c.onmouseout  = at_hide_grandson;
      break;
  }
}