﻿// visa eller gom en div
/*function toggle(a){
	var e=document.getElementById(a);
	if(!e) {return true;}
	if(e.style.display=="none"){
	e.style.display="block";
	} else {
	e.style.display="none";
	}
	return true;
};*/

// jQuery Menyfunktioner
function toggle(a)
{
	var elementAction = "addElement";
	var e=document.getElementById(a);
	if(!e) {return true;}
	if(e.style.display=="none"){
		e.style.display="block";
		} else {
		e.style.display="none";
		elementAction="subElement";
	}

	var vhtml = $.ajax({
			url: "index.php?go=store:"+elementAction+"&element="+a,
	 	async: false
		});

	return true;
};

// jQuery Menyfunktioner
function loadSubLevel(div_id, p, lvl, sect, view, ppp, order)
{
	$("#"+div_id).html($.ajax(
	{
	  	url: "index.php?go=Store:"+sect+"&parent="+p+"&level="+lvl+"&view="+view+"&p="+ppp+"&o="+order,
  	  	async: false
	}
 	).responseText);
}

function toggleCatClass(div_class,sub_exist)
{
	if (sub_exist>0)
	{
		var x=document.getElementById(div_class);
		x.className=(x.className=="webbutikMenyContentStatus_inactive")?"webbutikMenyContentStatus_active":(x.className=="webbutikMenyContentStatus_active")?"webbutikMenyContentStatus_inactive":"webbutikMenyContentStatus_active";
	}
}

function toggleClass(div_class, sub_exist, class1, class2)
{
	$("#"+div_class).toggleClass(class2);
	$("#"+div_class).toggleClass(class1);
}

function toggleTopCatClass(div_class,sub_exist)
{
	if (sub_exist>0)
	{
		var x=document.getElementById(div_class);
		x.className=(x.className=="webbutikMenyKategori_inactive")?"webbutikMenyKategori_active":(x.className=="webbutikMenyKategori_active")?"webbutikMenyKategori_inactive":"webbutikMenyKategori_active";
	}
}

function toggleTR(divId, parentId, currentId)
{
	var disp = document.getElementById(divId).style;

	if (disp.display == 'none')
		disp.display = '';
	else
	{
		disp.display = 'none';

		//div_id_parent = $("#"+div_id).parent();
		//$("#isCat_"+parentId).css("background-color", "#faf0f0");

		if (parentId!=0)
			$("#isCat_"+parentId).css("background-color", "#ffee99");

		$("#listitem_"+currentId+" a").css("font-weight", "normal");
		$("#listitem_"+parentId+" a").css("font-weight", "bold");
	}
}

function toggleTRSearch(divId, parentId, currentId)
{
	var disp = document.getElementById(divId).style;

	if (disp.display == 'none')
		disp.display = '';
	else
	{
		disp.display = 'none';
		if (parentId!=0)
			$("#isSrchCat_"+parentId).css("background-color", "#ffee99");

		$("#listitem_"+currentId+" a").css("font-weight", "normal");
		$("#listitem_"+parentId+" a").css("font-weight", "bold");
	}
}

function loadSubLevelSearch(div_id, p, lvl, sect, calling_class, table, email, parentId)
{
	obj = document.getElementById(div_id);
	var div_status = 0;

	if(obj.style.display != "none")
		div_status = 0;
	else
	{
		div_status = 1;
		$(".isCatLvl_"+lvl).css("display","none");
		$("#isSrchCat_"+parentId+" .nlMinus").attr("class", "nlPlus");
		$("#isSrchCat_"+parentId+" .subChoice").css("display", "none");
	}

	if ($("#"+div_id).html() == "")
	{
		$("#"+div_id).html($.ajax(
		{
			url: "index.php",
			data: "go=AjaxPublic:"+sect+"&parent="+p+"&level="+lvl+"&calling_class="+calling_class+"&table="+table+"&email="+email,
			type: "GET",
			async: false
		}
		).responseText);
	}

	toggleClass("plusminus_"+p, "", "nlMinus", "nlPlus");
	$(".subChoiceLabel a").css("font-weight", "normal");
	$("#listitem_"+p+" a").css("font-weight", "bold");
	$(".subChoice").css("background-color", "#ffffff");
	$("#"+div_id).css("border", "1px solid #eeeeff");
	$("#"+div_id).css("background-color", "#ffee99"); /* #faf0f0 */

	if (parentId!=0)
		$("#"+div_id).css("margin-top", "5px");

	$("#"+div_id).css("margin-bottom", "5px");
	$("#"+div_id).css("padding", "5px");

	toggleTR(div_id, parentId, p);
}

function toggleSubChecksSearch(frm, id, parentId)
{
	if (frm.checked==true)
	{
		toggleClass("plusminus_"+id, "", "nlMinus", "nlPlus");

		var lvl = $(frm).attr("level");
		$(".isCatLvl_"+lvl).css("display","none");

		$("#isSrchCat_"+id).hide();
		$("#isSrchCat_"+id).html("");

		if (parentId != 0)
		{
			$("#isSrchCat_"+parentId).css("background-color", "#ffee99"); /* "#faf0f0" */
			$("#isSrchCat_"+parentId+" a").css("font-weight", "normal");
			$("#listitem_"+parentId+" a").css("font-weight", "bold");
			markParentSearch(frm);
		}

		$("#listitem_"+id+" a").css("font-weight", "normal");
	}
	else
	{
		$("#isSrchCat_"+id+" input").attr("disabled", "");
	}
}

function markParentSearch(frm)
{
	id = $(frm).attr("parent");
	$("#partial_"+id).show();
	if (id > 0)
		markParent($("#srch_cat_"+id));
}

function loadSubLevelNewsletter(div_id, p, lvl, sect, calling_class, table, email, parentId)
{
	obj = document.getElementById(div_id);
	var div_status = 0;

	if(obj.style.display != "none")
	{
		div_status = 0;
	}
	else
	{
		div_status = 1;
		$(".isCatLvl_"+lvl).css("display","none");
		$("#isCat_"+parentId+" .nlMinus").attr("class", "nlPlus");
		$("#isCat_"+parentId+" .subChoice").css("display", "none");
		/*toggleClass("plusminus_"+p, "", "nlMinus", "nlPlus");*/
	}
	/*toggleTR(div_id, parentId);*/

	if ($("#"+div_id).html() == "")
	{
		//$("#"+div_id).load("index.php?go=AjaxPublic:"+sect+"&parent="+p+"&level="+lvl+"&calling_class="+calling_class+"&table="+table+"&email="+email);

		$("#"+div_id).html($.ajax(
		{
			url: "index.php",
			data: "go=AjaxPublic:"+sect+"&parent="+p+"&level="+lvl+"&calling_class="+calling_class+"&table="+table+"&email="+email,
			type: "GET",
			async: false
		}
		).responseText);
	}

	toggleClass("plusminus_"+p, "", "nlMinus", "nlPlus");
	$(".subChoiceLabel a").css("font-weight", "normal");
	$("#listitem_"+p+" a").css("font-weight", "bold");
	$(".subChoice").css("background-color", "#ffffff");
	$("#"+div_id).css("border", "1px solid #eeeeff");
	$("#"+div_id).css("background-color", "#ffee99"); /* #faf0f0 */

	if (parentId!=0)
		$("#"+div_id).css("margin-top", "5px");

	$("#"+div_id).css("margin-bottom", "5px");
	$("#"+div_id).css("padding", "5px");

	toggleTR(div_id, parentId, p);
}

function toggleSubChecks(frm, id, parentId)
{
	if (frm.checked==true)
	{
		toggleClass("plusminus_"+id, "", "nlMinus", "nlPlus");

		var lvl = $(frm).attr("level");
		//alert(lvl);
		$(".isCatLvl_"+lvl).css("display","none");

		/*var disp = document.getElementById("isCat_"+id).style;
		  disp.display = 'none';*/

		$("#isCat_"+id).hide();
		$("#isCat_"+id).html("");

		if (parentId != 0)
		{
			$("#isCat_"+parentId).css("background-color", "#ffee99"); /* "#faf0f0" */
			$("#isCat_"+parentId+" a").css("font-weight", "normal");
			$("#listitem_"+parentId+" a").css("font-weight", "bold");
			markParent(frm);
		}

		$("#listitem_"+id+" a").css("font-weight", "normal");
	}
	else
	{
		$("#isCat_"+id+" input").attr("disabled", "");
	}
}

function markParent(frm)
{
	id = $(frm).attr("parent");
	$("#partial_"+id).show();
	if (id > 0)
		markParent($("#cat_"+id));
}

function clearForm(fname)
{
	$(':input','#'+fname)
	 .not(':button, :submit, :reset, :hidden')
	 .val('')
	 .removeAttr('checked')
	 .removeAttr('selected');
}

function buy(id, cat)
{
	$("#buy_"+id).html($.ajax(
	{
		url: "index.php",
		data: "go=AjaxPublic:buyProduct&buy="+id+"&cat="+cat,
		type: "GET",
		async: false,
  		success: function(data) {
 			$("#shoppingcart").html($.ajax(
 			{
 				url: "index.php",
 				data: "go=AjaxPublic:renderbasket",
 				type: "GET",
 				async: false
 			}
 			).responseText);
 		}
	}
	).responseText);

}
