function  addToCart(prod_id){


	var company_id = $('company_id').value ;
		ajax_request("/"+webfolder+"ajax.server.php", "ajax=1&id="+pageID+"&action=addtocart&module=shopping_cart&prod_id="+prod_id+"&pQuantity=1&company_id="+company_id, onaddToCart);

}
function showProductDescription(){
	$('description-selected').className = " sel ";
	$('shipment-selected').className = "";
	$('payment-selected').className = "";
	$('questions-selected').className = "";
	var product_id = $('productId').value ;
	ajax_request("/"+webfolder+"ajax.server.php", "ajax=1&id="+pageID+"&action=showProductDescription&module=products&prod_id="+product_id, onloadAdditionalProductInfo);

}
function showProductPayment(){
	$('description-selected').className = "";
	$('shipment-selected').className = "";
	$('payment-selected').className = " sel ";
	$('questions-selected').className = "";
	var product_id = $('productId').value ;
	ajax_request("/"+webfolder+"ajax.server.php", "ajax=1&id="+pageID+"&action=showProductPayment&module=products&prod_id="+product_id, onloadAdditionalProductInfo);

}
function showProductShipment(){
	$('description-selected').className = "";
	$('shipment-selected').className = " sel ";
	$('payment-selected').className = "";
	$('questions-selected').className = "";
	var product_id = $('productId').value ;
	ajax_request("/"+webfolder+"ajax.server.php", "ajax=1&id="+pageID+"&action=showProductShipment&module=products&prod_id="+product_id, onloadAdditionalProductInfo);

}
function showProductContactForm(){
	$('description-selected').className = "";
	$('shipment-selected').className = "";
	$('payment-selected').className = "";
	$('questions-selected').className = " sel ";
	var product_id = $('productId').value ;
	ajax_request("/"+webfolder+"ajax.server.php", "ajax=1&id="+pageID+"&action=showProductContactForm&module=products&prod_id="+product_id, onloadAdditionalProductInfo);

}
function sendMessageToCompany(){

		var comp_id = $('company_id').value ;
		var name = $('contactform-name').value ;
		var email = $('contactform-email').value ;
		var phone = $('contactform-phone').value ;
		var text = $('contactform-text').value ;
		//alert("&name="+phone+"&email="+email+"&phone="+phone+"&text="+text+"&product_id="+product_id+"&");
		ajax_request("/"+webfolder+"ajax.server.php", "ajax=1&id="+pageID+"&action=sendMessageToCompany&module=products&name="+phone+"&email="+email+"&phone="+phone+"&text="+text+"&product_id="+product_id+"&comp_id="+comp_id, onSendMessageToCompany);


}



function changeProductSubCategories (parent_cat_id){

		for (var i=0; i<Categories.length; i++)
		{
			$('parent_'+Categories[i]).className = "";
		}

	$('parent_'+parent_cat_id).className = " sel ";



	ajax_request("/"+webfolder+"ajax.server.php", "ajax=1&id="+pageID+"&action=changeSubCategories&module=products&parent_cat_id="+parent_cat_id, onChangeSubCategories);
	loadProductListByParentCategoryId(1,parent_cat_id);
}
function changeSaleSubCategories (parent_cat_id){

		for (var i=0; i<Categories.length; i++)
		{
			$('parent_'+Categories[i]).className = "";
		}

	$('parent_'+parent_cat_id).className = " sel ";

	loadSalesListByParentCategoryId(1,parent_cat_id);

	ajax_request("/"+webfolder+"ajax.server.php", "ajax=1&id="+pageID+"&action=changeSaleSubCategories&module=products&parent_cat_id="+parent_cat_id, onChangeSubCategories);
}
function changeSpecialSubCategories (parent_cat_id){

		for (var i=0; i<Categories.length; i++)
		{
			$('parent_'+Categories[i]).className = "";
		}

	$('parent_'+parent_cat_id).className = " sel ";
	loadSpecialListByParentCategoryId(1,parent_cat_id);
	ajax_request("/"+webfolder+"ajax.server.php", "ajax=1&id="+pageID+"&action=changeSpecialSubCategories&module=products&parent_cat_id="+parent_cat_id, onChangeSubCategories);
}
function loadProductList(qPage,cat_id) {

	if(cat_id)
	{
		elements=document.getElementsByClassName("sub_cat");
		for(j = 0; j < elements.length; j++){
			   elements[j].className = "sub_cat";
		}

		$('sub_cat_'+cat_id).className += " sel";
	}

	ajax_request("/"+webfolder+"ajax.server.php", "ajax=1&id="+pageID+"&action=loadProductList&module=products&qPage="+qPage+"&cat_id="+cat_id, onloadProductList);
}
function loadSalesList(qPage,cat_id) {

	if(cat_id)
	{
		elements=document.getElementsByClassName("sub_cat");
		for(j = 0; j < elements.length; j++){
			   elements[j].className = "sub_cat";
		}

		$('sub_cat_'+cat_id).className += " sel";
	}

	ajax_request("/"+webfolder+"ajax.server.php", "ajax=1&id="+pageID+"&action=loadSalestList&module=products&qPage="+qPage+"&cat_id="+cat_id, onloadProductList);
}
function loadSpecialList(qPage,cat_id) {
	if(cat_id)
	{
		elements=document.getElementsByClassName("sub_cat");
		for(j = 0; j < elements.length; j++){
			   elements[j].className = "sub_cat";
		}

		$('sub_cat_'+cat_id).className += " sel";
	}

	ajax_request("/"+webfolder+"ajax.server.php", "ajax=1&id="+pageID+"&action=loadSpecialList&module=products&qPage="+qPage+"&cat_id="+cat_id, onloadProductList);
}

function loadProductListByParentCategoryId(qPage,parent_category_id) {


	ajax_request("/"+webfolder+"ajax.server.php", "ajax=1&id="+pageID+"&action=loadProductList&module=products&qPage="+qPage+"&parent_category_id="+parent_category_id+"&cat_id=0", onloadProductList);
}
function loadSalesListByParentCategoryId(qPage,parent_category_id) {


	ajax_request("/"+webfolder+"ajax.server.php", "ajax=1&id="+pageID+"&action=loadSalestList&module=products&qPage="+qPage+"&parent_category_id="+parent_category_id+"&cat_id=0", onloadProductList);
}
function loadSpecialListByParentCategoryId(qPage,parent_category_id) {


	ajax_request("/"+webfolder+"ajax.server.php", "ajax=1&id="+pageID+"&action=loadSpecialList&module=products&qPage="+qPage+"&parent_category_id="+parent_category_id+"&cat_id=0", onloadProductList);
}
function showNextProduct(cat_id,prod_id) {

	product_id = prod_id;

	ajax_request("/"+webfolder+"ajax.server.php", "ajax=1&id="+pageID+"&action=showNextProduct&module=products&cat_id="+cat_id+"&prod_id="+prod_id, showProduct);

}


function showPreviousProduct(cat_id,prod_id) {


	product_id = prod_id;

	ajax_request("/"+webfolder+"ajax.server.php", "ajax=1&id="+pageID+"&action=showPreviousProduct&module=products&cat_id="+cat_id+"&prod_id="+prod_id, showProduct);
}

function showProduct(resp, respone_array){

			respone_array = evalJson(resp.responseText);
	$('description-selected').className = " sel ";
	$('shipment-selected').className = "";
	$('payment-selected').className = "";
	$('questions-selected').className = "";

	$('company_info').innerHTML = respone_array["company_info"];
	$('product_header_switches').innerHTML = respone_array["header_switches"];
	$('prod_stat').innerHTML = respone_array["prod_stat"];
	$('product-description').innerHTML = respone_array["description"];
	//loadProductDiamensions();
	loadProductPrices();


}


function onloadAdditionalProductInfo(resp, respone_array) {

	respone_array = evalJson(resp.responseText);

	$('product-description').innerHTML = respone_array["additional_info_html"];

}
function onSendMessageToCompany(resp, respone_array){

		respone_array = evalJson(resp.responseText);
	if(respone_array["msg_sent"] == 1 )
	{
		$('product-description').innerHTML = respone_array["response_msg"];
	}
	else
	{
		$('msg_response').innerHTML = respone_array["response_msg"];
	}

}
function onloadProductList(resp, respone_array) {

	respone_array = evalJson(resp.responseText);

	$('product_table').innerHTML = respone_array["product_list"];
	$('page_switch').innerHTML = respone_array["switch_html"];
}


function loadProductDiamensions() {

	var color = $('bp-color').value;

	ajax_request("/"+webfolder+"ajax.server.php", "ajax=1&id="+pageID+"&action=getDiamensions&module=products&color="+color+"&product_id="+product_id, onloadProductDiamensions);
}


function onloadProductDiamensions(resp, respone_array) {

	respone_array = evalJson(resp.responseText);
	var diamensions = $('diamensions');
	diamensions.innerHTML = respone_array["diamension_menu"];
	loadProductPrices();
}

function loadProductPrices() {
		var param_id = $('bp-size').value;

	ajax_request("/"+webfolder+"ajax.server.php", "ajax=1&id="+pageID+"&action=getPrices&module=products&param_id="+param_id, onloadProductPrices);
}
function onChangeSubCategories(resp, respone_array) {

	respone_array = evalJson(resp.responseText);


	$('list').innerHTML = respone_array;

}
function onloadProductPrices(resp, respone_array) {

	respone_array = evalJson(resp.responseText);
	//$('price-shop').innerHTML = respone_array["shop_price"];

	if (respone_array["sale_price"])
	{
		showPortalAndShopPrice(respone_array["price"],respone_array["shop_price"]);
		$('is-sale').style.display = "inline";
		$('price-old').innerHTML = respone_array["price"];
		$('price-sale').innerHTML = respone_array["sale_price"];
		$('price-label').style.display = "none";
		//$('price-label').innerHTML = "";
	}
	else
	{
		showPortalAndShopPrice(respone_array["price"],respone_array["shop_price"]);
		$('price-old').innerHTML = "";
		$('price-sale').innerHTML = "";
		$('is-sale').style.display = "none";
	}
}

function showPortalAndShopPrice(PortalPrice,ShopPrice)
{
		if((!PortalPrice)&&(!ShopPrice))
		{
			$('buy-product-price').innerHTML = respone_array["msg_no_price"];
		}
		else
		{
			if(!PortalPrice)
			{
				$('price-label').style.display = "none";
			}
			else
			{
			 	$('price-label').style.display = "inline";
			 	$('price').innerHTML = PortalPrice;
			}
			if(!ShopPrice)
			{
				$('price-shop-label').style.display = "none";
			}
			else
			{
			 	$('price-shop-label').style.display = "inline";
			 	$('price-shop').innerHTML = ShopPrice;
			}


		}
}