function ShowLOG(PALERT)
{
   var txW=PALERT;
   if(debug==1)
   {
     alert(txW);
   }

}

function removeSpaces(s)
{
	var allSpacesRe = "/\s+/g";
	return s.replace(allSpacesRe, "");
}

function getParameter ( queryString, parameterName )
{
  var parameterName = parameterName + "=";
  if ( queryString && queryString.length>0)
  {
    begin = queryString.indexOf ( parameterName );
    
	if ( begin != -1 )
	  {
          begin += parameterName.length;
          end = queryString.indexOf ( "&" , begin );
            if ( end == -1 )
		    {
              end = queryString.length
            }
         return unescape ( queryString.substring ( begin, end ) );
      }
    return "null";
  }
}




function HDNOW()
{
    alert("77777777777");
}


function FillTreeMozilla(PARAM)
{
	var TreeRoot=PARAM;
	ShowLOG('Дерево: '+PARAM);
	d.add(0,-1,PARAM);
	
	var incMain=0;
	var incSubLevel=0;
	var m=0;
	var p=0;
	var n=0;
	var MainIndexTree=0;
	var LV2=0;
	
	var MainList = document.getElementById(DefaultULList);
  	for(var i in MainList.childNodes)
  	{
  		var x = MainList.childNodes[i];
  		if(x.innerText)
		{
			if(!x.getElementsByTagName("ul")[0])
			{
				incMain++;
				d.add(n+1,0,x.innerText,x.firstChild.href);
				TreeIndexMain[MainIndexTree]=x.firstChild.href;
				//alert(x.firstChild.href);
                                
                if(!x.firstChild.href)
				{
					TreeIndexMain[20000]=MainIndexTree;
				}
				
				MainIndexTree++;
				p=n+1;
				
			}
			if(x.tagName == "UL")
			{
				//alert("Дочерних узлов: "+x.childNodes.length);
				incSubLevel=0;
				
				for(var w=0;w<x.childNodes.length;w++)
				{
					var SubLevel=x.childNodes[w];
					if(SubLevel.tagName == "LI")
					{
						//alert(x.childNodes[w].innerText+': '+(p+incSubLevel+1)+'.'+(p)+'');
						d.add((p+incSubLevel+1),p,x.childNodes[w].innerText,x.childNodes[w].firstChild.href);
						if(!x.childNodes[w].firstChild.href)
						{
							//alert(x.childNodes[w].innerText);
							TreeIndexMain[20000]=MainIndexTree-1;
							alert(LV2+1);
							Cat2Index[20000]=LV2+1;
							LV2++;
						}
						//TreeIndexMain[(p+incSubLevel+1)]=x.childNodes[w].firstChild.href;
						//m=incMain+incSubLevel;
						n=p+incSubLevel+1;
						
						incSubLevel++;
						
					}
					if(SubLevel.tagName == "UL")
					{
							var iii=0;
							for(var u=0;u<SubLevel.childNodes.length;u++)
							{
								var SubLevelLast=SubLevel.childNodes[u];
								if(SubLevelLast.tagName == "LI")
								{
									//SubLevelLast.firstChild.href;
									//TreeIndexMain[(p+incSubLevel)]=SubLevelLast.firstChild.href;
									iii++;									
								}
							
							}
						
					
					}			
					
					
					
					
					
				}
				
			}
			
			
		}
		
		
		
	}
	
	
}


function FillTreeMozillaFX(Tree_root)
{
	d.add(0,-1,Tree_root);
	
	var incMain=0;
	var incSubLevel=0;
	var m=0;
	var p=0;
	var n=0;
	var MainIndexTree=0;
	var MainList = document.getElementById(DefaultULList);
  	for(var i in MainList.childNodes)
  	{
  		var x = MainList.childNodes[i];
  		if(x.textContent)
		{
			if(x.tagName == "LI")
			{
				//alert(x.textContent+' '+x.firstChild.href);
				d.add(n+1,0,x.textContent,x.firstChild.href);
				
                                if(!x.firstChild.href)
				{
				    TreeIndexMain[20000]=MainIndexTree;
				}

                                TreeIndexMain[MainIndexTree]=n+1;
                                MainIndexTree++;
				p=n+1;
			}
			if(x.tagName == "UL")
			{
				for(var j=0;j<x.childNodes.length;j++)
				{
					var SubLevel=x.childNodes[j];
					if(SubLevel.tagName == "LI")
					{
						//alert(SubLevel.textContent+' '+SubLevel.firstChild.href);
						d.add((p+incSubLevel+1),p,SubLevel.textContent,SubLevel.firstChild.href);
						n=p+incSubLevel+1;
						incSubLevel++;
					}
				}
			}
			
			
		}
		
		
		
	}
	
	
}



function HideCalalog(BR_type)
{
	var BR=BR_type;
	if(BR=='IE')
	{
		var BlockElem = document.getElementById("mytree2");
		BlockElem.style.display = 'none';
	}
	if(BR=='Opera')
	{
		var BlockElem = document.getElementById("mytree2");
		BlockElem.style.display = 'none';
		
	}
		
}


function HideDiv()
{
	if(window.location.pathname=='/catalog/' || window.location.pathname=='/catalog/index.php' || window.location.pathname=='/catalog/basket.php' || window.location.pathname=='/catalog/detail.php' || window.location.pathname=='/catalog/index2.php' || window.location.pathname=='/catalog/draw.php' || window.location.pathname=='/personal/' || window.location.pathname=='/catalog/compare.php')
	{
		document.getElementById("TD1").innerText='';
		document.getElementById("TD2").innerText='';
		document.getElementById("TD3").innerText='';
		
		document.getElementById("DV1").style.display='none';
		document.getElementById("bg_prokrutka").style.display='none';
		
		document.getElementById("sideLeft").innerText='';
		document.getElementById("sideLeft").style.width=0+'px';
				
		document.getElementById("sideRight").style.width=0+'px';
		document.getElementById("sideRight").style.marginLeft=0+'px';
		document.getElementById("content").style.paddingLeft=0+'px';
		document.getElementById("centerContent_main").style.width=1000+'px';
		
		
	}
}




function HideDivNew()
{
	if(window.location.pathname=='/catalog/' || window.location.pathname=='/catalog/index.php' || window.location.pathname=='/catalog/basket.php' || window.location.pathname=='/catalog/detail.php' || window.location.pathname=='/catalog/draw.php' || window.location.pathname=='/personal/' || window.location.pathname=='/catalog/compare.php')
	{
		document.getElementById("TD1").textContent=" ";
		document.getElementById("TD2").textContent=" ";
		document.getElementById("TD3").textContent=" ";
		
		document.getElementById("DV1").style.display='none';
		document.getElementById("bg_prokrutka").style.display='none';
		
		document.getElementById("sideLeft").textContent=" ";
		document.getElementById("sideLeft").style.width=0+'px';
		
		
		document.getElementById("sideRight").style.width=0+'px';
		document.getElementById("sideRight").style.marginLeft=0+'px';
		document.getElementById("content").style.paddingLeft=0+'px';
		document.getElementById("centerContent_main").style.width=1000+'px';
		
	}
}

function CheckBrowser()
{
	var uaVers='null';
	if (window.navigator.userAgent.indexOf ("MSIE") >= 0)
	{
		ua = 'Explorer';
		uaVers=ua+' '+window.navigator.userAgent.substr(window.navigator.userAgent.indexOf("MSIE")+5,3);
	}
	if (window.navigator.userAgent.indexOf ("Opera") >= 0)
	{
		ua = 'Opera';
		uaVers=ua+' '+window.navigator.userAgent.substr(window.navigator.userAgent.indexOf("Opera")+6,4);
	}
	
	if (window.navigator.userAgent.indexOf ("Chrome") >= 0)
	{
ua = 'Chrome';
uaVers=ua+' '+window.navigator.userAgent.substr(window.navigator.userAgent.indexOf("Chrome")+6,8)+' ('+ window.navigator.userAgent.substr(8,3)+')';
	}
	
	if (window.navigator.userAgent.indexOf ("Firefox") >= 0)
	{
ua = 'Firefox';
uaVers=ua+' '+window.navigator.userAgent.substr(window.navigator.userAgent.indexOf("Firefox")+6,8)+' ('+ window.navigator.userAgent.substr(8,3)+')';
	}
	
	
	return uaVers;
	
}


function PutMainCategoryNew(CIDP,Bparam)
{
	var Br_type=Bparam;
	var CID=CIDP;
	if(Br_type == 'NOT_IE')
	{
		var incMain=0;
		var cbMain=document.getElementById(CID);
		var MainList=document.getElementById(DefaultULList);
		cbMain.options.length = 0;
		var INNER="";
		
		cbMain.options.length+=1;
		cbMain[incMain].text = ' ';
		cbMain.options[incMain].value = 0;

		for(var i in MainList.childNodes)
		{
			var x = MainList.childNodes[i];
			
			if(CheckBrowser().indexOf ("Firefox") >= 0)
			{
				//INNER=x.textContent;
				INNER=x.innerText;
			}
			else
			{
				INNER=x.innerText;
			}
			if(INNER)
			{
				if(!x.getElementsByTagName('ul')[0])
				{
					CatMainIndex[incMain]=x.firstChild.href;
					cbMain.options.length+=1;
					cbMain[incMain+1].text = INNER;
					cbMain.options[incMain+1].value = i;
					incMain++;
				}
			
			}
		}
	}
  
}



function PutMainCategoryFIREFOX(CIDP,Bparam)
{
	var Br_type=Bparam;
	var CID=CIDP;
	
	var incMain=0;
	var cbMain=document.getElementById(CID);
	var MainList=document.getElementById(DefaultULList);
	cbMain.options.length = 0;
	var INNER="";

	for(var i in MainList.childNodes)
	{
		var x = MainList.childNodes[i];
  		if(x.textContent)
		{
			if(x.tagName == "LI")
			{
				//alert(x.textContent+' '+x.firstChild.href);
				CatMainIndex[incMain]=x.firstChild.href;
				//alert('индекс: '+incMain+', значение: '+x.firstChild.href)
                                cbMain.options.length+=1;
				cbMain[incMain].text = x.textContent;
				cbMain.options[incMain].value = i;
				incMain++;
				
			}
		}
	}
	
  
}














function GetView()
{
	var res="null";
	if(CheckBrowser().indexOf ("Explorer") >= 0)
	{
		res="IE";
	}
	else
	{
		res="NOT_IE";
	}
	return res;
}  


function ReloadPage(P1,P2,P3)
{
   var IndexP=P2;
   var PAR3=P3;
   ShowLOG('Параметры запуска [ReloadPage]:'+Cat2Index[IndexP]);
   
   if(PAR3==1)
   { 
        if(CheckBrowser().indexOf ("Firefox") >= 0)
	{
           if(CatMainIndex[IndexP]!='null' && CatMainIndex[IndexP]!='undefined')
           {
                var adress=CatMainIndex[IndexP];
                if(CatMainIndex[IndexP])
		{
		   window.location=(''+CatMainIndex[IndexP]+''); 
		}
           }

        }
       else
       {
       
			if(CatMainIndex[IndexP]!='null' && CatMainIndex[IndexP]!='undefined')
			{
				var adress=CatMainIndex[IndexP];
				if(CatMainIndex[IndexP])
				{
					window.location=(''+CatMainIndex[IndexP]+''); 
				}
			}
       
	   }

   }     
     
     if(PAR3==2)
     {
         if(TreeIndexSecondMain[IndexP]!='null' && TreeIndexSecondMain[IndexP]!='undefined' && TreeIndexSecondMain[IndexP]!='selected')
         {
             var adress=TreeIndexSecondMain[IndexP];
	     if(TreeIndexSecondMain[IndexP])
	     {
		   window.location=(''+TreeIndexSecondMain[IndexP]+''); 
	     }
         }

     }

	
} 


function SetMainCategoryNew(CIDP,BrTypeP)
{
	var Br_type=BrTypeP;
	var CID=CIDP;
	var Combobox_main=document.getElementById(CID);
		
	if(Br_type == 'NOT_IE' )
	{
		ShowLOG('Параметры запуска [SetMainCategoryNew]'+CID+','+BrTypeP);
		var IdNEW=TreeIndexMain[20000];
		IdNEW+=1;
		//alert('Главная категория: '+IdNEW+'');
		Combobox_main.selectedIndex =IdNEW;
	}
	
}

function FillComboBox_mozilla(Parent_combobox_ID,ComboBox_ID)
{
	var cbMainParent = document.getElementById(Parent_combobox_ID);
	var cbMain = document.getElementById(ComboBox_ID);
	
	if(cbMain.options.length>=1)
		{
			cbMain.options.length = 0;
		}
		
	if (cbMainParent != -1)
	{
		
		var nm=cbMainParent.options[cbMainParent.selectedIndex].text;
		
		if(FindCategory_mozilla(nm)[0]!="null")
		{
			var mass = new Array();
			mass=FindCategory_mozilla(nm);
			cbMain.options.length=mass.length;
			
			cbMain[0].text = ' ';
			cbMain.options[0].value = 0;
			
			for(var i=0;i<=mass.length-1;i++)
			{
				cbMain[i+1].text = mass[i];
				cbMain.options[i+1].value = i;
			}
		}
		else
		{
			for(var j=0;j<=cbMain.options.length-1;j++)
			{
				cbMain[i].text = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
				cbMain.options[i].value = 0;
				
				
			}
			
		}
	}
}


function FindCategory_mozilla(Name_Category)
{
	var isTrue="1";
	var queryString = window.top.location.search.substring(1);
	var qid="null";
	if(queryString)
	{
		qid=getParameter (queryString,DefaultSectionID);
	}
	
	var res = new Array();
	res[0]="null";
	
	var incMain=0;
	var incSubLevel=0;
	var m=0;
	var p=0;
	var n=0;
	
	var INNER="";
	
	var MainList = document.getElementById(DefaultULList);
  	for(var i in MainList.childNodes)
  	{
  		var x = MainList.childNodes[i];
  		
		if(CheckBrowser().indexOf ("Firefox") >= 0)
			{
				INNER=x.innerText;
			}
		else
			{
				INNER=x.innerText;
			}
		
		
		if(INNER)
		{
			if(!x.getElementsByTagName("ul")[0])
			{
				if(removeSpaces(INNER) == removeSpaces(Name_Category))
				{
					isTrue="0";
				}
				else
				{
					isTrue="1";
				}
				incMain++;
				
			}
			if(x.tagName == "UL")
			{
				//alert("Дочерних узлов: "+x.childNodes.length);
				incSubLevel=0;
				
				for(var w=0;w<x.childNodes.length;w++)
				{
					var SubLevel=x.childNodes[w];
					if(SubLevel.tagName == "LI")
					{
						if(isTrue=="0")
						{
							if(getParameter (x.childNodes[w].firstChild.href,DefaultSectionID)==qid)
							{
								Cat2Index[incSubLevel]="selected";
							}
							else
							{
								Cat2Index[incSubLevel]=x.childNodes[w].firstChild.href;
							}
							
							if(CheckBrowser().indexOf ("Firefox") >= 0)
							{
								res[incSubLevel]=x.childNodes[w].textContent;
                                                                TreeIndexSecondMain[incSubLevel]=x.childNodes[w].firstChild.href;
							}
							else
							{
								res[incSubLevel]=x.childNodes[w].innerText;
                                                                TreeIndexSecondMain[incSubLevel]=x.childNodes[w].firstChild.href; 
							}
							
							//alert(''+incSubLevel+''+x.childNodes[w].innerText);
						}
						//res[incSubLevel]=x.childNodes[w].innerText;
						//incSubLevel++;
						
						
						//alert(x.childNodes[w].innerText+': '+(p+incSubLevel+1)+'.'+(p)+'');
						//d.add((p+incSubLevel+1),p,x.childNodes[w].innerText,x.childNodes[w].firstChild.href);
						//m=incMain+incSubLevel;
						incSubLevel++;
						
					}
					
					if(SubLevel.tagName == "UL")
					{
							var iii=0;
							for(var u=0;u<SubLevel.childNodes.length;u++)
							{
								var SubLevelLast=SubLevel.childNodes[u];
								if(SubLevelLast.tagName == "LI")
								{
										if(getParameter (SubLevelLast.firstChild.href,DefaultSectionID) == qid)
										{
											//alert(SubLevelLast.firstChild.href);
											Cat2Index[incSubLevel-1]="selected";
										}
										iii++;									
								}
							}
					
					}
					
				}
				
				//alert(x.childNodes[1].innerText);
				//alert(x.childNodes[1].firstChild.href);
			}
			
			
		}
		
		
		
	}
	
	return res;
}


function SetSecondCategory(CID2_P,index)
{
	var CID2_P;
	var Combobox_second=document.getElementById(CID2_P);
	var queryString = window.top.location.search.substring(1);
	var qid=getParameter (queryString,DefaultSectionID);
	if(qid!="null")
	{
		Combobox_second.selectedIndex =Cat2Index[20000];
	}
}

function defPosition(event) {
    var x = y = 0;
    if (document.attachEvent != null) { // Internet Explorer & Opera
        x = window.event.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
        y = window.event.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
    } else if (!document.attachEvent && document.addEventListener) { // Gecko
        x = event.clientX + window.scrollX;
        y = event.clientY + window.scrollY;
    } else {
        // Do nothing
    }
    return {x:x, y:y};
}

function Show_img(imgN)
{
  var imgNew="/images/copco/catalog/"+imgN+".jpg";
  var lMouse=defPosition(event).x            
  var TMouse=defPosition(event).y

  document.getElementById('PreviewImg').src=imgNew;
  document.getElementById('ImageBox').style.left=lMouse;
  document.getElementById('ImageBox').style.top=TMouse;
  document.getElementById('ImageBox').style.visibility = 'visible';
}

function Hide_img()
{
	document.getElementById('ImageBox').style.visibility = 'hidden';
}



 
