
var gsCatParentSTR = "";
var gsCatCookie = ExtractCookieEx("WEB",'category');

function InsertCookieEx(strName, strKey, strValue){
	var strKeysValues = ExtractCookie(strName, strKey);
	var sTmp = '';
	var sDelimiter = '';
	aKeyValue = new Array();
	aOneKeyValue = new Array();
	if ((strKeysValues=="none")||(strKeysValues=="")) {
		document.cookie = strName + "=" + strKey + "=" + strValue + "; path=\/";
	} else if (("&"+strKeysValues.toLowerCase()).indexOf("&"+strKey.toLowerCase()+"=")==-1) {
		document.cookie = strName + "=" + strKeysValues + "&" + strKey + "=" + strValue + "; path=\/";
	} else {
		aKeyValue = strKeysValues.split("&");
		for (var i = 0; i<aKeyValue.length; i++) {
			aOneKeyValue = aKeyValue[i].split("=");
			if (aOneKeyValue[0].toLowerCase()==strKey.toLowerCase()) aOneKeyValue[1] = strValue;
			sTmp += sDelimiter + aOneKeyValue[0] + "=" + aOneKeyValue[1];
			sDelimiter = "&";
		}
		document.cookie = strName + "=" + sTmp + "; path=\/";
	}
}

function InsCoo(intId){
	InsertCookieEx("WEB","category",intId);
}
function checkParent(src, dest) {
	while (src!=null) {
		if (src.tagName == dest) return src;
			src = src.parentElement;
        }
	return null;
}
/*
function outlineCat() {

	var open = event.srcElement;
	var el = checkParent(open, "TD");
	if (null!=el) {
		for (var pos=0; pos<el.children.length; pos++) {
			if (el.children[pos].tagName=="TABLE") {
				if (el.children[pos].style.display=="block") {
					el.children[0].className = "";
				}else{
					el.children[0].className = "";
				}
				break;
			}
		}
	    if (pos==el.children.length) return;
	} else return;
	el = el.children[pos];
        
	if ("TABLE"==el.tagName) {
		if (el.style.display=="block") {
			el.style.display = "";
		} else {
			el.style.display = "block";
		}
	}
	event.cancelBubble = true;

}
*/
function CatA(pkCat, sNameCat,bBold,nChildren,nLevel,nCatSelect,nParentCat,sSeoUrl) {
	var bSelected = (pkCat == nCatCurrent);
      
      


        if (pkCat == nCatSelect){
      	   return "<b><font style='color:red;'><a href='" + sSeoUrl + "'  onclick=\'InsCoo(\"" + gsCatParentSTR + "x" + pkCat + "a\"); \'>" + sNameCat + "</a></b>";
           }
         else {
   	       return "<a "+((nLevel==1)?"":" style='font-weight:normal;'")+"  href='" + sSeoUrl + "' onclick=\'InsCoo(\"" + gsCatParentSTR + "x" + pkCat + "a\"); \'>" + (bSelected?"":"") + sNameCat + "</a>";
        	}    

}

gnCatLevel = 1;

// CatSame
function CS(pkCat,nChildren,sNameCat,nLevel,nCatSelect,nCaPa,sSeoUrl) {
	var i = gsCatParentSTR.lastIndexOf("x");
	var nParentCat = gsCatParentSTR.substr(i+1,gsCatParentSTR.length - i - 2);
        var sBG;
        var sBgRoot;
        //alert(gnCatLevel+' '+sNameCat);


        if (gnCatLevel == 2 ){
        	document.write(
        		"<TR><TD id='x" + pkCat + "a' valign=top style='padding-left:10px;font-weight:normal;height:15px;'>" +
        		"<img style='vertical-align:middle;' src='/img/" + ((nChildren > 0) ? ((gsCatCookie.indexOf("x" + pkCat + "a")==-1) ? "li_dotyellow" : "li_dotyellow") : "li_dotyellow") + ".gif'>&nbsp;" +
        		CatA(pkCat, sNameCat,"0",nChildren,nLevel,nCatSelect,nParentCat,sSeoUrl) +
        		((nChildren > 0) ? "" :	"</TD></TR>")
        	);
        } else {
         if (gnCatLevel == 3 ){
               	document.write(
        		"<TR><TD id='x" + pkCat + "a' valign=top style='font-weight:normal;padding-left:20px;height:15px;' class='ThirdLevel'>" +
        		"<img style='vertical-align:middle;' src='/img/" + ((nChildren > 0) ? ((gsCatCookie.indexOf("x" + pkCat + "a")==-1) ? "dot_orange" : "dot_orange") : "dot_orange") + ".gif'>&nbsp;" +
        		CatA(pkCat, sNameCat,"1",nChildren,nLevel,nCatSelect,nParentCat,sSeoUrl) +
        		((nChildren > 0) ? "" :	"</TD></TR>")
        	);
         } else {
        	document.write(
                		"<TR><TD " + sBgRoot + " " + sBG + " id='x" + pkCat + "a' valign=top style='font-weight:bold;height:15px;'>" +
                		"<img style='vertical-align:middle;' src='/img/catTree/" + ((nChildren > 0) ? ((gsCatCookie.indexOf("x" + pkCat + "a")==-1) ? "empty" : "empty") : "empty") + ".gif'>&nbsp;" +
                		CatA(pkCat, sNameCat,"1",nChildren,nLevel,nCatSelect,nParentCat,sSeoUrl) +
                		((nChildren > 0) ? "" :	"</TD></TR>")
                	);
         }
        }
}
// CatLower
function CL(pkCat, nParentCat, nChildren, nRowSpan, sNameCat,nLevel,nCatSelect,nCaPa,sSeoUrl) {
        gnCatLevel += 1;
        var sBG;

	gsCatParentSTR = gsCatParentSTR + "x" + nParentCat + "a";
          
      //if (2470 == pkCat) {alert(gnCatLevel);}
        if (gnCatLevel == 2 ){
        
          textik="<TABLE width='195' style='background-color:#EBE4D6;border-top:2px solid white;" + (((gsCatCookie.indexOf(nParentCat)==-1))?" display:none; ":"") + "'  cellpadding='0' cellspacing='0'>" +
        		"<TR>" +
        		"<TD style='padding-left:10px;' id='x" + pkCat + "a' valign=top style='font-weight:normal;height:15px;'><img style='vertical-align:middle;' src='/img/" + ((nChildren > 0) ? ((gsCatCookie.indexOf("x" + pkCat + "a")==-1) ? "li_dotyellow" : "li_dotyellow") : "li_dotyellow") + ".gif'>&nbsp;" +
        		CatA(pkCat, sNameCat,"0",nChildren,nLevel,nCatSelect,nParentCat,sSeoUrl)
        
          //alert(textik);
        	document.write(textik);
        	
        } else {
                document.write(
                		"<TABLE width='195' border='0' cellpadding='0' cellspacing='0'" + (((gsCatCookie.indexOf(nParentCat)==-1))?"":" style='display:block;'") + ">" +
                		"<TR>" +
                		"<TD " + sBG + " class='ThirdLevel' id='x" + pkCat + "a' valign=top style='height:15px;'><img style='vertical-align:middle;' src='/img/" + ((nChildren > 0) ? ((gsCatCookie.indexOf("x" + pkCat + "a")==-1) ? "dot_orange" : "dot_orange") : "dot_orange") + ".gif'>&nbsp;" +
                		CatA(pkCat, sNameCat,"0",nChildren,nLevel,nCatSelect,nParentCat,sSeoUrl)
                	);
        }
}
// CatEnd
function CE() {
        gnCatLevel -= 1;
	var i = gsCatParentSTR.lastIndexOf("x");
	gsCatParentSTR = gsCatParentSTR.substr(0,i);
	document.write("</TD></TR></TABLE>");
}
// CatHigher
function CH(pkCat, nChildren, sNameCat,nLevel,nCatSelect,nCaPa,sSeoUrl) {
        var sBG;
        var sBgRoot;

        if (gnCatLevel == 2 ){
                document.write(
        		"</TD></TR>" +
        		"<TR><TD style='padding-left:10px;font-weight:normal;height:15px;' id='x" + pkCat + "a' ><img style='vertical-align:middle;' src='/img/" + ((nChildren > 0) ? ((gsCatCookie.indexOf("x" + pkCat + "a")==-1) ? "li_dotyellow" : "li_dotyellow") : "li_dotyellow") + ".gif'>&nbsp;" +
        		CatA(pkCat, sNameCat,"1",nChildren,nLevel,nCatSelect,0,sSeoUrl)
        	);
        }else{
                document.write(
                		"</TD></TR>" +
                		"<TR><TD " + sBG + " id='x" + pkCat + "a' style='font-weight:bold;height:15px;'><img style='vertical-align:middle;' src='/img/catTree/" + ((nChildren > 0) ? ((gsCatCookie.indexOf("x" + pkCat + "a")==-1) ? "empty" : "empty") : "empty") + ".gif'>&nbsp;" +
                		CatA(pkCat, sNameCat,"1",nChildren,nLevel,nCatSelect,0,sSeoUrl)
                	);
        }
}


function ExtractCookieEx(strName, strKey) {
	var strKeysValues = ExtractCookie(strName, strKey);
	if ((strKeysValues=="none")||(strKeysValues=="")) return "none";
	aKeyValue = new Array();
	aOneKeyValue = new Array();
	aKeyValue = strKeysValues.split("&");
	for (var i = 0; i<aKeyValue.length; i++) {
		aOneKeyValue = aKeyValue[i].split("=");
		if (aOneKeyValue[0].toLowerCase()==strKey.toLowerCase()) return aOneKeyValue[1];
	}
	return "none";
}
function ExtractCookie(strName) {
	var iIndex;
	var cookieList=document.cookie.split("; ");
	for (var i=0; i < cookieList.length; i++){
		iIndex = cookieList[i].toLowerCase().indexOf(strName.toLowerCase()+'=');
		if (iIndex==0)
			return (cookieList[i].substring(strName.length+1,cookieList[i].length));
	}
	return "none";
}
