		var strBlock,initColor,selectColor,blockCnt,selectedBlock,blocks=new Array(),maxLevels,toneColors=new Array(),toneSelectColors=new Array(),maxTones,kk,defW,defH,mWidth=3000,mHeight=2000;
		
		toneColors[0]="#eff7ff";		//Öāåņ ķåņīķčšīāąķķīćī įėīźą
		toneSelectColors[0]="#cfe7ff";	//Öāåņ āūäåėåķķīćī ķåņīķčšīāąķķīćī įėīźą
		toneColors[1]="#bfc7cf";		//Öāåņ ņīķčšīāąķķīćī įėīźą 1
		toneSelectColors[1]="#afb7cf";	//Öāåņ āūäåėåķķīćī ņīķčšīāąķķīćī įėīźą 1
		toneColors[2]="#a0a0a0";		//Öāåņ ņīķčšīāąķķīćī įėīźą 2
		toneSelectColors[2]="#7070a0";	//Öāåņ āūäåėåķķīćī ņīķčšīāąķķīćī įėīźą 2
		blockCnt=0;						//Ń÷åņ÷čź įėīźīā
		selectedBlock=null;				//Ņåźółčé āūäåėåķķūé įėīź
		maxLevels=4;					//Ģąźńčģąėüķīå ÷čńėī óšīāķåé ā čåšąšõčč
		maxTones=2;						//Ģąźńčģąėüķīå ÷čńėī óšīāķåé ņīķčšīāąķč˙
		kk=10;							//Źīżōōčöčåķņ ģąńųņąįą
		defW=300;
		defH=200;
		
function checkSpelling(e,obj)
{
	var str
	
	if(e)
	{
		if(e.keyCode) str=e.keyCode;
		else
		if(e.which) str=e.which;
		if (obj && str==13) 
			if (e.srcElement)
				e.srcElement.blur();
			else
			if (e.target)
				e.target.blur();
		if ( (str<48) || (str>57) ) 
		  {
			e.returnValue = false;
		  }
			else
			e.returnValue = true;
	}
}


// --------------------------------------------------------------------
// Āū÷čńėåķčå X źīīšäčķąņū īįśåźņą
// --------------------------------------------------------------------
function offsetXX( o ) { 
	if(o){
    var p = o.offsetLeft;

    while( o.offsetParent != null ) { 
        o  = o.offsetParent;
        p += o.offsetLeft;
        if ( o.id == 'main_td' )
            break;
    } 

    return p;}
	else
	 return 0;
}

// --------------------------------------------------------------------
// Āū÷čńėåķčå Y źīīšäčķąņū īįśåźņą
// --------------------------------------------------------------------
function offsetYY( o ) { 
	if(o){
    var p = o.offsetTop;

    while ( o.offsetParent != null ) { 
        o  = o.offsetParent;
        p += o.offsetTop;
        if ( o.id == 'main_td' )
            break;
    } 

    return p;}
	else
	 return 0;
}
		
///////////////////////////////////////////////////////
//  Āūāīä ńīäåšęčģīćī įėīźą
//  todo - Āūāīä ā äīźóģåķņ čėč āīēāšąņ ā āčäå ńņšīźč
///////////////////////////////////////////////////////

		function writeNewBlock(todo,width,height,parent)
		{
			var outStr,nw,nh,imgId;
			blockCnt++;
			blocks[blockCnt-1]=new Block(blockCnt,parent);
			blocks[blockCnt-1].nWidth=width;
			blocks[blockCnt-1].nHeight=height;
			outStr='<table class="table" width="100%" height="100%" border="1" cellpadding="0" cellspacing="0">';
			if(parent)
			{
				if(parent.Type)
				  {
				  	nw=width-2;
					nh=height-2;
				  }
				else
				  {
				  	nw=8;
					nh=7;
				  }
				if(parent.Type)  
					imgId=' id="img'+(blockCnt-1)+''
				else
				  	imgId=''
				idd='lab'+(blockCnt);
				//alert(idd+' '+blockCnt);
				outStr+='<tr><td class="window" bgcolor="'+toneColors[parent.Tone]+'" style="width: '+width+'; height: '+height+'" align="center" id="id'+blockCnt+'" onclick="selectBlock(event,'+blockCnt+');">';
  			  	nnw=width*10;
				nnh=height*10;
				outStr+='<img src="logi_files/'+getTypeSource(parent.Type)+'" width="'+nw+'" height="'+nh+'"'+imgId+'"></td></tr></table>';
			}
			else
			{
				idd='lab'+blockCnt;
			  outStr+='<tr><td class="window" bgcolor="'+toneColors[0]+'" style="width: '+width+'; height: '+height+'" align="center" id="id'+blockCnt+'" onclick="selectBlock(event,'+blockCnt+');">';
  			  outStr+='<img src="logi_files/x.gif" width="8" height="7"></td></tr></table>';
			}
			if (todo)
			  {
			    document.write(outStr);
				blocks[blockCnt-1].Select();
			  }
			else 
			  return outStr;
		}

///////////////////////////////////////////////////////
//  Āūāīä įėīźą ā āčäå HTML	
///////////////////////////////////////////////////////

		function getBlockHTML(size,editable,IDPref)
		{
		  var bl,outStr='',ch1,ch2,ch3,clickStr,newIDstr='',newID2str='';

	      clickStr='';
		  if(editable)
		    {
			  newIDstr='id="id'+IDPref+(parseInt(this.Ind)+1)+'"';
			  newID2str='id="img'+IDPref+(parseInt(this.Ind)+1)+'"';
		      clickStr='onclick="selectBlock(event,'+(this.Ind+1)+');"';
			}

		  if(IDPref==null) IDPref='';

		  bl=this;
		  if(!size)
		    size=1;
		  else
		    size=parseInt(size);
		  if(bl.withChilds)
		  {
		  	ch1=bl.GetChilds(0);
		  	ch2=bl.GetChilds(1);
		  	ch3=bl.GetChilds(2);
			outStr='<table class="table" border="0" cellpadding="0" cellspacing="0"><tr><td class="window" bgcolor="'+toneColors[bl.Tone]+'" style="border-width:0; width: '+bl.nWidth/size+'px; height: '+bl.nHeight/size+'px" align="center" '+newIDstr+' '+clickStr+'>';
			outStr+='<table class="table" border="0" cellpadding="0" cellspacing="0"><tr><td>';
		  	switch(bl.ChildsType)
			{
			  case 1:
				outStr+=ch1.GetHTML(size,editable,IDPref)+'</td><td>';
				outStr+=ch2.GetHTML(size,editable,IDPref)+'</td></tr></table>';
			  break;
			  case 2:
				outStr+=ch1.GetHTML(size,editable,IDPref)+'</td></tr><tr><td>';
				outStr+=ch2.GetHTML(size,editable,IDPref)+'</td></tr></table>';
			  break;
			  case 3:
				outStr+=ch1.GetHTML(size,editable,IDPref)+'</td><td>';
				outStr+=ch2.GetHTML(size,editable,IDPref)+'</td><td>';
				outStr+=ch3.GetHTML(size,editable,IDPref)+'</td></tr></table>';
			  break;
			}
		  	outStr+='</td></tr></table>';
		  }
		  else
		  {
 				if(bl.Type)
				  {
				  	nw=bl.nWidth-2;
					nh=bl.nHeight-2;
				  }
				else
				  {
				  	nw=8;
					nh=7;
				  }
			outStr='<table class="table" cellpadding="0" cellspacing="0" >';
			outStr+='<tr><td class="window" bgcolor="'+toneColors[bl.Tone]+'" style="width: '+bl.nWidth/size+'px; height: '+bl.nHeight/size+'px" align="center" '+newIDstr+' '+clickStr+'>';
		  	outStr+='<img src="logi_files/'+getTypeSource(bl.Type)+'" width="'+nw/size+'" height="'+nh/size+'" '+newID2str+' ></td></tr></table>';
		  }		
//		  alert(outStr);
		  return outStr;
		}

///////////////////////////////////////////////////////
//  Āūāīä HTML īźķą ā äīźóģåķņ
///////////////////////////////////////////////////////

		function writeWin(size,editable,IDPref)
		{
		  document.write(blocks[0].GetHTML(size,editable,IDPref));
		}

///////////////////////////////////////////////////////
//  Āūāīä įėīźą ā āčäå HTML ā ēąäąķķūé ņåć	
///////////////////////////////////////////////////////

		function writeTo(id,size,editable,IDPref)
		{
		  document.getElementById(id).innerHTML=blocks[0].GetHTML(size,editable,IDPref);
		}

///////////////////////////////////////////////////////
//  Āūäåėåķčå įėīźą (ļīäńāå÷čāąķčå)		
///////////////////////////////////////////////////////

		function selectBlock(event,block)
		{
		  if(event)
	  		  event.cancelBubble = true;
		  
		  if (selectedBlock!=null)
		    deselectBlock(selectedBlock);
		  if (block==null)
		  	{
			  selectedBlock=this;
//			  alert(this.ID);
			  if(!document.getElementById(this.ID)) return 0;
			  selectedBlock.Tag=document.getElementById(this.ID);
		  	  selectedBlock.Tag.style.backgroundColor=toneSelectColors[this.Tone];
			}
		  else
		    {
			  selectedBlock=blocks[block-1];
			  if (!document.getElementById(selectedBlock.ID)) return 0;
			  selectedBlock.Tag=document.getElementById(selectedBlock.ID);
		  	  selectedBlock.Tag.style.backgroundColor=toneSelectColors[selectedBlock.Tone];
			}
		  selectedBlock.Selected=true;
		  outSelectedInfo();
		}

///////////////////////////////////////////////////////
//  Īņģåķą āūäåėåķč˙ įėīźą
///////////////////////////////////////////////////////

		function deselectBlock(block)
		{
		  if (block==null)
		    {
			  if(!this.Tag) return 0;
		  	  this.Tag.style.backgroundColor=toneColors[this.Tone];
			  this.Selected=false;
			}
		  else
		    {
			  if(!block.Tag) return 0;
		  	  block.Tag.style.backgroundColor=toneColors[block.Tone];
			  block.Selected=false;
			}
		}
		
///////////////////////////////////////////////////////
//  Ēą÷čńņźą āńåćī ķåķóęķīćī ļīńėå óäąėåķč˙
///////////////////////////////////////////////////////

		function clearAll(prn)
		{
		  var i;
		
		  if (prn)
		  {
		    for(i=0;i<blockCnt;i++)
			  if(blocks[i])
			  {
			    if(blocks[i].Parent)
	 		    if(blocks[i].Parent==prn)
				  {
					 clearAll(blocks[i]);
				     blocks[i]=null;
				  }
			   }
			 blocks[prn.Ind].withChilds=false;
			 blocks[prn.Ind].ChildsType=null;
		  }
		}

///////////////////////////////////////////////////////
//  Óäąėåķčå āūäåėåķķīćī įėīźą
///////////////////////////////////////////////////////

		function deleteSelect()
		{
		  var imgId;
		  
		  if (selectedBlock)
		  {
		    if(selectedBlock.Parent)
			{
				selectedBlock.Parent.withChilds=false;
				clearAll(selectedBlock.Parent);
				selectedBlock.Parent.Tag.style.backgroundColor=selectColor;
				selectedBlock.Parent.Tag.style.borderWidth=1;
				imgId='img'+selectedBlock.Parent.Ind;
				
			    selectedBlock.Parent.Tag.innerHTML='<img src="logi_files/x.gif" width="8" height="7" id='+imgId+'>';
selectedBlock.Ind
				selectedBlock.Parent.Select();
			    solveAll();
				newWidth=selectedBlock.nWidth;
				newHeight=selectedBlock.nHeight;
				nw=newWidth*10;
				nh=newHeight*10;
				idd='lab'+(selectedBlock.Ind+1);
//				alert(idd);
				if (selectedBlock.Ind!=0)
					selectedBlock.Tag.innerHTML='<img src="logi_files/x.gif" width="8" height="7" id="'+imgId+'">'
				else 
					selectedBlock.Tag.innerHTML='<img src="logi_files/x.gif" width="8" height="7" id="'+imgId+'">'
			}
		  }
		  document.all["cod"].value='<TABLE class=window cellSpacing=0 cellPadding=0 border=2><TBODY><TR><TD id=main_td>'+document.getElementById("main_td").innerHTML+'</TD></TR></TBODY></TABLE>';
		}

///////////////////////////////////////////////////////
//  Čķčöčąėčēąöč˙...
///////////////////////////////////////////////////////

		function init()
		{
		  blockCnt=0;
		  document.getElementById("main_td").innerHTML=writeNewBlock(0,300,200,null);
		  blocks[0].Select();
		  solveAll();
		  document.all["cod"].value='<TABLE class=window cellSpacing=0 cellPadding=0 border=2><TBODY><TR><TD id=main_td>'+document.getElementById("main_td").innerHTML+'</TD></TR></TBODY></TABLE>';
		}
		
///////////////////////////////////////////////////////
//  Ēąļóńź šąēäåėåķč˙ āūäåėåķķīćī įėīźą āåšņčźąėüž
///////////////////////////////////////////////////////

		function divideSelectUD(nn)
		{
			if (selectedBlock!=null)
			  if(selectedBlock.Level<maxLevels)
			    {
				  if(nn)
				    {
					  if(selectedBlock.Level<maxLevels-1)
					    {
						   selectedBlock.ChildsType=3;
			               selectedBlock.DivideUD3();
	 			      	   blocks[blockCnt-1].Select();
						 }
				    }
				  else
				    {
 				   	  selectedBlock.ChildsType=1;
			          selectedBlock.DivideUD();
			      	  blocks[blockCnt-1].Select();
					}
				}
				document.all["cod"].value="<TABLE class=window cellSpacing=0 cellPadding=0 border=2><TBODY><TR><TD id=main_td>"+document.getElementById("main_td").innerHTML+"</TD></TR></TBODY></TABLE>";
		}
		
///////////////////////////////////////////////////////
//  Ēąļóńź šąēäåėåķč˙ āūäåėåķķīćī įėīźą ćīščēīķņąėüž
///////////////////////////////////////////////////////

		function divideSelectLR()
		{
			if (selectedBlock!=null)
			  if(selectedBlock.Level<maxLevels)
			    {
			      selectedBlock.ChildsType=2;
			      selectedBlock.DivideLR();
			      blocks[blockCnt-1].Select();
				}
			document.all["cod"].value='<TABLE class=window cellSpacing=0 cellPadding=0 border=2><TBODY><TR><TD id=main_td>'+document.getElementById("main_td").innerHTML+'</TD></TR></TBODY></TABLE>';
		}
		
///////////////////////////////////////////////////////
//  Ļīėó÷åķčå äī÷åšķčõ įėīźīā
///////////////////////////////////////////////////////

		function getChilds(ind)
		{
		  var bl=null,i;
		  
		  for(i=0;i<blockCnt;i++)
		    if(blocks[i])
			    if(blocks[i].Parent==this)
				  {
				    bl=blocks[i+ind];
					i=blockCnt;
				  }
		  return bl;
		}
		
///////////////////////////////////////////////////////
//  Šąēäåėåķčå āūäåėåķķīćī įėīźą āåšņčźąėüž
///////////////////////////////////////////////////////

		function divideUD()
		{
			var newWidth,newHeight,innerStr,kAdd=0;
			
		    newWidth=Math.floor(parseInt(selectedBlock.nWidth)/2);
		    newHeight=parseInt(selectedBlock.nHeight);
			if ((newWidth<<1)!=parseInt(selectedBlock.nWidth))  kAdd++;
			selectedBlock.Tag.style.borderWidth=0;
			innerStr='<table class="table" border="0" cellpadding="0" cellspacing="0"><tr><td>'
			innerStr+=writeNewBlock(false,newWidth,newHeight,selectedBlock)+'</td><td>';
			innerStr+=writeNewBlock(false,newWidth+kAdd,newHeight,selectedBlock)+'</td></tr></table>';
			selectedBlock.Tag.innerHTML=innerStr;
//			alert(''+selectedBlock.nWidth+'='+blocks[blockCnt-1].nWidth+'+'+blocks[blockCnt-2].nWidth);
			blocks[blockCnt-1].Select();
		    solveAll();
		}
		
///////////////////////////////////////////////////////
//  Šąēäåėåķčå āūäåėåķķīćī įėīźą äāóģ˙ āåšņčźąė˙ģč
///////////////////////////////////////////////////////

		function divideUD3()
		{
			var newWidth,newHeight,innerStr,kAdd=0,i;
			
		    newWidth=Math.floor(parseInt(selectedBlock.nWidth)/3);
		    newHeight=parseInt(selectedBlock.nHeight);
			for(i=0;i<2;i++)
				if ((newWidth*3+kAdd)!=parseInt(selectedBlock.nWidth))  kAdd++;
			selectedBlock.Tag.style.borderWidth=0;
			innerStr='<table class="table" border="0" cellpadding="0" cellspacing="0"><tr><td>'
			innerStr+=writeNewBlock(false,newWidth,newHeight,selectedBlock)+'</td><td>';
			innerStr+=writeNewBlock(false,newWidth+kAdd,newHeight,selectedBlock)+'</td><td>';
			innerStr+=writeNewBlock(false,newWidth,newHeight,selectedBlock)+'</td></tr></table>';
			selectedBlock.Tag.innerHTML=innerStr;
//			alert(''+selectedBlock.nWidth+'='+blocks[blockCnt-1].nWidth+'+'+blocks[blockCnt-2].nWidth+'+'+blocks[blockCnt-3].nWidth);
			blocks[blockCnt-1].Select();
		    solveAll();
		}
		
///////////////////////////////////////////////////////
//  Šąēäåėåķčå āūäåėåķķīćī įėīźą ćīščēīķņąėüž
///////////////////////////////////////////////////////

		function divideLR()
		{
			var newWidth,newHeight,innerStr,kAdd=0;
			
		    newWidth=parseInt(selectedBlock.nWidth);
		    newHeight=Math.floor(parseInt(selectedBlock.nHeight)/2);
			if ((newHeight<<1)!=parseInt(selectedBlock.nHeight)) kAdd++;
			selectedBlock.Tag.style.borderWidth=0;
			innerStr='<table class="table" border="0" cellpadding="0" cellspacing="0"><tr><td>'
			innerStr+=writeNewBlock(false,newWidth,newHeight,selectedBlock)+'</td></tr><tr><td>';
			innerStr+=writeNewBlock(false,newWidth,newHeight+kAdd,selectedBlock)+'</td></tr></table>';
			selectedBlock.Tag.innerHTML=innerStr;
//			alert(''+selectedBlock.nHeight+'='+blocks[blockCnt-1].nHeight+'+'+blocks[blockCnt-2].nHeight);
			blocks[blockCnt-1].Select();
		    solveAll();
		}
		
///////////////////////////////////////////////////////
//  Ņīķčšīāąķčå āūäåėåķķīćī įėīźą
///////////////////////////////////////////////////////

		function toneSelect()
		{
			if (selectedBlock!=null)
			  {
			    selectedBlock.DoTone();
		        solveAll();
			  }
		}
		
///////////////////////////////////////////////////////
//  Ņīķčšīāąķčå įėīźą
///////////////////////////////////////////////////////

		function doTone()
		{
		  this.Tone++;
		  if (this.Tone>maxTones-1) this.Tone=0;
		  this.Select();
		}
		
///////////////////////////////////////////////////////
//  Īļšåäåėåķčå ńīńņī˙ķč˙(ņčļą) āūäåėåķķīćī įėīźą
///////////////////////////////////////////////////////

		function setSelectType(type,mode)
		{
		  var newType;
		
		  if(mode)
		    {
				selectedBlock.Type=type;
				setSelectedInner(type);
			    solveAll();
//				alert('t='+selectedBlock.Type);
			}
		  else
		  if (selectedBlock)
		  {
		    switch((type)*10+selectedBlock.Type)
			{
			  case 0: case 1: case 2: case 3: case 4: case 5:   newType=0; break;

			  case 10: case 11: case 12: newType=1; break;
			  case 13: newType=4; break;
			  case 14: newType=3; break;
			  case 15: newType=4; break;

			  case 20: case 21: case 22: newType=2; break;
			  case 23: case 24: newType=5; break;
			  case 25: newType=3; break;

			  case 30: case 33: newType=3; break;
			  case 31: newType=4; break;
			  case 34: newType=1; break;
			  case 32: newType=5; break;
			  case 35: newType=2; break;
			}
			selectedBlock.Type=newType;
			setSelectedInner(newType);
		    solveAll();
		  }
		  document.all["cod"].value='<TABLE class=window cellSpacing=0 cellPadding=0 border=2><TBODY><TR><TD id=main_td>'+document.getElementById("main_td").innerHTML+'</TD></TR></TBODY></TABLE>';
		}
		
///////////////////////////////////////////////////////
//  Ļīėó÷åķčå čńõīäķčźą źąšņčķźč ļī ņčļó įėīźą
///////////////////////////////////////////////////////

		function getTypeSource(type)
		{
			var imgSrc;
			
			switch (type)
			{
			  case 0: default: imgSrc='x.gif';break;
			  case 1: imgSrc='left.gif'; break;
			  case 2: imgSrc='right.gif';  break;
			  case 3: imgSrc='up.gif'; break;
			  case 4: imgSrc='leftup.gif'; break;
			  case 5: imgSrc='rightup.gif'; break;
			}
			return imgSrc;
		}
		
///////////////////////////////////////////////////////
//  Ēąļčńü ā įėīź źąšņčķźč ā ńīīņāåņńņāčč ń åćī ņčļīģ
///////////////////////////////////////////////////////

		function setSelectedInner(type)
		{
		  var imgSrc,newWidth,newHeight,imgId;
		  
			imgSrc=getTypeSource(type);
			if(type)
			  {
				newWidth=selectedBlock.nWidth-2;
				newHeight=selectedBlock.nHeight-2;
				nw=(newWidth+2)*10;
				nh=(newHeight+2)*10;
			  }
			else
			  {
			    newWidth=8;
			    newHeight=7;
			  }
			imgId='img'+selectedBlock.Ind;
			idd='lab'+(selectedBlock.Ind+1);
			//alert(idd+" "+imgId);
		    if (selectedBlock.Ind!=0)
				selectedBlock.Tag.innerHTML='<img src="logi_files/'+imgSrc+'" width="'+newWidth+'" height="'+newHeight+'" id="'+imgId+'">';
			else
				selectedBlock.Tag.innerHTML='<img src="logi_files/'+imgSrc+'" width="'+newWidth+'" height="'+newHeight+'" id="'+imgId+'">'
		}

///////////////////////////////////////////////////////
//  Šąńń÷åņ ąņščįóņīā įėīźą
///////////////////////////////////////////////////////

		function solveParams()
		{
		  this.Tag=document.getElementById(this.ID);
		  if(this.Tag)
		    {
			  if(!this.nWidth && !this.nHeight)
			    {
				  this.nWidth=this.Tag.width;
				  this.nHeight=this.Tag.height;
				}
			  this.nLeft=offsetXX(this.Tag);
			  this.nTop=offsetYY(this.Tag);
			  this.Tag.style.width=this.nWidth;
			  this.Tag.style.height=this.nHeight;
			  if(this.withChilds)
				this.Tag.style.borderWidth=0;
			}
		}

///////////////////////////////////////////////////////
//  Óńņąķīāźą šąēģåšīā įėīźą
///////////////////////////////////////////////////////

		function setSize(newWidth,newHeight)
		  {
		    //alert(this.ID);
		    this.SetWidth(newWidth);
		    this.SetHeight(newHeight);
		  }

///////////////////////////////////////////////////////
//  Óńņąķīāźą ųčščķū įėīźą
///////////////////////////////////////////////////////

		function setWidth(newWidth,mode)
		{
		  var i,kAdd=0,kAdd1=0,fl=0;
		  
		  newWidth=parseInt(newWidth);
		  
		  if(!this.Parent && this.withChilds && this.nWidth!=newWidth)
		    {
			  alert("Sektora platuma izmaiņas nedrīkst ietekmēt visa loga platumu!");
			  return 1;
			}
		  
		  if(newWidth<27)
		    {
			  if(mode==2)
			    alert("Ievadītais platums samazina blakus sektora platumu līdz neatļautam lielumam! (ne mazāk kā 270mm)");
			  else
			    alert("Sektora platums nevar būt mazāks kā 270mm!");
			  return 1;
			}
		  
		  if(this.Parent && mode!=2 && mode!=1)
			    {
//		 		  alert(this.ID+' withParent mode='+mode);
			      for(i=0;i<blockCnt;i++)
				    if(blocks[i])
				      if(blocks[i].Parent==this.Parent && blocks[i]!=this)
					   {
					    switch(this.Parent.ChildsType)
						{
						  case 1:
						  		if(this.Parent.nWidth-newWidth<=0)
								  {
								    alert("Ievadītais platums pāsniedz iekšējā elementa platumu!!!");
									fl=1;
								  }
								else {
						          fl=blocks[i].SetWidth(this.Parent.nWidth-newWidth,2);
								  /*idl = this.ID.substring(2);
//								  alert(idl);
								  document.getElementById('xlab'+idl).value=newWidth*10;
								  //alert('xlab'+idl);*/
								  }
						  break;
						  case 2:
						      fl=this.Parent.SetWidth(newWidth,3);
						  	  if(!fl)
						        fl=blocks[i].SetWidth(newWidth,2);
						  break;
						  case 3:
					  	      if(blocks[i+1] && blocks[i+2])
						         if(blocks[i+1].Parent==this.Parent && blocks[i+2]==this)
							  		if(this.Parent.nWidth-blocks[i].nWidth-newWidth<=0)
									  {
									    alert("Ievadītais platums pāsniedz iekšējā elementa platumu!!!");
										fl=1;
									  }
									else
								      fl=blocks[i+1].SetWidth(this.Parent.nWidth-blocks[i].nWidth-newWidth,2);
							  if(blocks[i+1] && blocks[i+2])
						         if(blocks[i+2].Parent==this.Parent && blocks[i+1]==this)
							  		if(this.Parent.nWidth-blocks[i].nWidth-newWidth<=0)
									  {
									    alert("Ievadītais platums pāsniedz iekšējā elementa platumu!!!");
										fl=1;
									  }
									else
								     fl=blocks[i+2].SetWidth(this.Parent.nWidth-blocks[i].nWidth-newWidth,2);
							  if(blocks[i-1] && blocks[i+1])
						         if(blocks[i+1].Parent==this.Parent && blocks[i-1]==this)
							  		if(this.Parent.nWidth-blocks[i+1].nWidth-newWidth<=0)
									  {
									    alert("Ievadītais platums pāsniedz iekšējā elementa platumu!!!");
										fl=1;
									  }
									else
								     fl=blocks[i].SetWidth(this.Parent.nWidth-blocks[i+1].nWidth-newWidth,2);
						  break;
						}
						i=blockCnt;
					   }
				}

		  if(this.withChilds && !fl)		  
		    {
//		  alert(this.ID+' withChilds mode='+mode);
		      switch(this.ChildsType)
 			  {
			    case 1:
				  if (((newWidth>>1)<<1)!=newWidth)  kAdd++;
  	 		      for(i=0;i<blockCnt;i++)
				    if(blocks[i])
					  if(blocks[i].Parent==this)
					    {
					      fl=blocks[i].SetWidth(newWidth>>1,1);
						  if(!fl)
					        fl=blocks[i+1].SetWidth((newWidth>>1)+kAdd,1);
						  i=blockCnt;
						}
			    break;
			    case 2:
		 		   for(i=0;i<blockCnt;i++)
				    if(blocks[i])
					  if(blocks[i].Parent==this)
					    fl=blocks[i].SetWidth(newWidth,1);
			    break;
			    case 3:
				  var nW;
				  nW=Math.floor(newWidth/3);
				  if (nW*3!=newWidth)  kAdd++;
				  if (nW*3+kAdd!=newWidth)  kAdd1++;
  	 		      for(i=0;i<blockCnt;i++)
				    if(blocks[i])
					  if(blocks[i].Parent==this)
					    {
						  fl=blocks[i].SetWidth(nW+kAdd,1);
						  if(!fl)
						    fl=blocks[i+1].SetWidth(nW,1);
						  if(!fl)	
						    fl=blocks[i+2].SetWidth(nW+kAdd1,1);
						  i=blockCnt;
						}
			    break;
			  }
			}

		  if(!fl)
		    {
			  setImgWidth(this.Type,this.Ind,newWidth);
		      this.Tag.style.width=newWidth;
  		      this.nWidth=newWidth;
			}
		  return fl;
		}

///////////////////////////////////////////////////////
//  Óńņąķīāźą āūńīņū įėīźą
///////////////////////////////////////////////////////

		function setHeight(newHeight, mode)
		{
		  var i,kAdd=0,kAdd1=0,fl=0;
		  
		  newHeight=parseInt(newHeight);
		  
		  if(!this.Parent && this.withChilds && this.nHeight!=newHeight)
		    {
			  alert("Augstuma izmaiņas izvēlētā sektora nedrīkst iespaidot loga kopējo izmēru!");
			  return 1;
			}

		  if(newHeight<27)
		    {
			  if(mode==2)
			    alert("Ievadītais augstums samazina blakus sektora augstumu līdz neatļautam lielumam! (ne mazāk kā 270mm)");
			  else
			    alert("Sektora augstums nevar būt mazāks kā 270mm!");
			  return 1;
			}
		  
		  if(this.Parent && mode!=2 && mode!=1)
			    {
//		 		  alert(this.ID+' withParent mode='+mode);
			      for(i=0;i<blockCnt;i++)
				    if(blocks[i])
				      if(blocks[i].Parent==this.Parent && blocks[i]!=this)
					   {
					    switch(this.Parent.ChildsType)
						{
						  case 3:
						  case 1:
						      fl=this.Parent.SetHeight(newHeight,3);
						  	  if(!fl)
						        fl=blocks[i].SetHeight(newHeight,2);
						  break;
						  case 2:
						  		if(this.Parent.nHeight-newHeight<=0)
								  {
								    alert("Ievadītais augstums pāsniedz iekšējā elementa augstumu!!!");
									fl=1;
								  }
								else {
							        fl=blocks[i].SetHeight(this.Parent.nHeight-newHeight,2);
									/*idl = this.ID.substring(2);
								  	document.getElementById('ylab'+idl).value=newHeight*10;*/
								}
						  break;
						}
						i=blockCnt;
					   }
				}

		  if(this.withChilds && !fl)		  
		    {
//		  alert(this.ID+' withChilds mode='+mode);
		      switch(this.ChildsType)
 			  {
			    case 3:
			    case 1:
		 		   for(i=0;i<blockCnt;i++)
				    if(blocks[i])
					  if(blocks[i].Parent==this)
					    fl=blocks[i].SetHeight(newHeight,1);
			    break;
			    case 2:
				  if (((newHeight>>1)<<1)!=newHeight)  kAdd++;
  	 		      for(i=0;i<blockCnt;i++)
				    if(blocks[i])
					  if(blocks[i].Parent==this)
					    {
					      fl=blocks[i].SetHeight(newHeight>>1,1);
						  if(!fl)
					        fl=blocks[i+1].SetHeight((newHeight>>1)+kAdd,1);
						  i=blockCnt;
						}
			    break;
			  }
			}

		  if(!fl)
		    {
//			  alert(this.ID);
//			  alert(newHeight);
			  setImgHeight(this.Type,this.Ind,newHeight);
			  this.Tag.style.height=newHeight;
			  this.nHeight=newHeight;
//			  alert(this.Tag.style.height);
		    }
		  return fl;
		}
		
///////////////////////////////////////////////////////
//  Óńņąķīāźą ųčščķū źąšņčķźč
///////////////////////////////////////////////////////

		function setImgWidth(type,ind,w)
		{
			var el;
			
			el=document.getElementById('img'+ind);
			if(el)
				if(type)
				    el.style.width=w-2;
				else
				    el.style.width=8;
		}

///////////////////////////////////////////////////////
//  Óńņąķīāźą āūńīņū źąšņčķźč
///////////////////////////////////////////////////////

		function setImgHeight(type,ind,h)
		{
			var el;
			
			el=document.getElementById('img'+ind);
			if(el)
				if(type)
				    el.style.height=h-2;
				else
				    el.style.height=7;
		}

///////////////////////////////////////////////////////
//  Óńņąķīāźą šąēģåšīā āūäåėåķķīćī įėīźą
///////////////////////////////////////////////////////

		function setSelectSize()
		{
		  var newWidth,newHeight,sb,prn,i;
			
		  
		  if(!selectedBlock.Parent)
		    {
			  newWidth=Math.floor(parseInt(document.getElementById('widthfld').value));
			  newHeight=Math.floor(parseInt(document.getElementById('heightfld').value));
		      kk=Math.floor(newWidth/defW);
		      if(Math.floor(newHeight/kk)>defH)
		        kk=Math.floor(newHeight/defH);
			  mWidth=newWidth;
			  mHeight=newHeight;
			}
		  else
		    {
			  newWidth=Math.floor(parseInt(document.getElementById('widthfld2').value));
			  newHeight=Math.floor(parseInt(document.getElementById('heightfld2').value));
			}

	      newWidth=Math.floor(newWidth/kk);
	      newHeight=Math.floor(newHeight/kk);

		  selectedBlock.SetSize(newWidth,newHeight);
		  solveAll();
		  document.all["cod"].value='<TABLE class=window cellSpacing=0 cellPadding=0 border=2><TBODY><TR><TD id=main_td>'+document.getElementById("main_td").innerHTML+'</TD></TR></TBODY></TABLE>';
		}

///////////////////////////////////////////////////////
//  Āūāīä ąņščįóņīā įėīźą
///////////////////////////////////////////////////////

		function outSelectedInfo()
		{
		  var Width,Height,Top,Left;
		  
		  if(document.getElementById('widthfld2'))
		  {
			Width=selectedBlock.nWidth;
			Height=selectedBlock.nHeight;
			Left=offsetXX(selectedBlock.Tag);
			Top=offsetYY(selectedBlock.Tag);
			document.getElementById('widthfld2').value=Width*kk;
			document.getElementById('heightfld2').value=Height*kk;
//			document.getElementById('leftfld').value=Left;
//			document.getElementById('topfld').value=Top;
		  }
		}

///////////////////////////////////////////////////////
//  Īļčńąķčå źėąńńą Block
///////////////////////////////////////////////////////

		function Block(newID,parent)
		{
/////////////////   Ńāīéńņāą        ///////////////////
		  
		  this.Parent=parent;			//Įėīź-šīäčņåėü
		  this.Selected=false;			//Ōėąć āūäåėåķč˙
		  this.ID='id'+newID;			//Čäåķņčōčźąņīš
		  this.Ind=parseInt(newID)-1;	//Čķäåźń
		  this.Tag=null;				//Ņżć ń ńīäåšęčģūģ įėīźą
		  this.Type=0;					//Ńīńņī˙ķčå(ņčļ) įėīźą
		  this.Tone=0;					//Ņīķčšīāźą
		  this.withChilds=false;		//ßāė˙åņń˙ ėč šīäčņåėåģ äšóćčõ įėīźīā
		  this.ChildsType=null;			//Āčä šīäčņåėüńņāą
		  this.Level=1;					//Óšīāåķü ā čåšąšõčč įėīźīā
		  this.nWidth=0;
		  this.nHeight=0;
		  this.nLeft=0;
		  this.nTop=0;
			
/////////////////     Ģåņīäū        /////////////////////

		  this.Select=selectBlock;		//Āūäåėåķčå įėīźą
		  this.Deselect=selectBlock;	//Šąēāūäåėåķčå įėīźą
		  this.DivideUD=divideUD;		//Šąēäåėåķčå āåšņčźąėüž
		  this.DivideUD3=divideUD3;		//Šąēäåėåķčå äāóģ˙ āåšņčźąė˙ģč
		  this.DivideLR=divideLR;		//Šąēäåėåķčå ćīščēīķņąėüž
		  this.SolveParams=solveParams;	//Šąńń÷åņ ųčščķū, äėčķū č ņ.ä.
		  this.DoTone=doTone;			//Ņīķčšīāąķčå
		  this.SetSize=setSize;			//Óńņąķīāźą ķīāūõ šąēģåšīā
		  this.SetWidth=setWidth;		//Óńņąķīāźą ķīāīé ųčščķū
		  this.SetHeight=setHeight;		//Óńņąķīāźą ķīāūõ āūńīņū
		  this.GetChilds=getChilds;		//Ļīėó÷åķčå äī÷åšķčõ įėīźīā
		  this.GetHTML=getBlockHTML;	//Ļīėó÷åķčå HTML īņīįšąęåķč˙

/////////////////   Čķčöčąėčēąöč˙   /////////////////////

		  if(parent)
		    {
		      this.Level=parent.Level+1;
			  parent.withChilds=true;
			  this.Type=parent.Type;
			  this.Tone=parent.Tone;
			}
		}
		
		
///////////////////////////////////////////////////////
//  GetWindowCSV
///////////////////////////////////////////////////////

		function getWindowCSV()
		{
		  var outStr='';
		  
		  for(i=0;i<blockCnt;i++)
		    {
			  if(blocks[i])
			    {
			      outStr+='1;'
				}
			  else
			    outStr+='0;'
			}
		}
				
///////////////////////////////////////////////////////
//  Šąńń÷åņ č ļąšąģåņšīā āńåõ įėīźīā
///////////////////////////////////////////////////////

		function solveAllParams()
		{
			var i;
			
			for(i=0;i<blockCnt;i++)
			{
			    if(blocks[i])
				  {
				    //alert(blocks[i].ID);
				    blocks[i].SolveParams();
				  }
		    }
		}
		
///////////////////////////////////////////////////////
//  Šąńń÷åņ č āūāīä āńåõ ļąšąģåņšīā
///////////////////////////////////////////////////////

		function solveAll()
		{
			var i,value,itog=0,cnt,ind,stind;
			
		  if(selectedBlock.nWidth!=blocks[0].nWidth || selectedBlock.nHeight!=blocks[0].nHeight)
		    {
				  if(document.getElementById('widthfld2'))
				  {
					document.getElementById('widthfld2').disabled=false;
					document.getElementById('heightfld2').disabled=false;
					document.getElementById('b2').style.color='#34244F';
 				  }
				  if(document.getElementById('widthfld'))
				  {
					document.getElementById('widthfld').disabled=true;
					document.getElementById('heightfld').disabled=true;
					document.getElementById('b1').style.color='#999999';
				  }
			}
		  else
		    {
				  if(document.getElementById('widthfld2'))
				  {
					document.getElementById('widthfld2').disabled=true;
					document.getElementById('heightfld2').disabled=true;
					document.getElementById('b2').style.color='#999999';
				  }
				  if(document.getElementById('widthfld'))
				  {
					document.getElementById('widthfld').disabled=false;
					document.getElementById('heightfld').disabled=false;
					document.getElementById('b1').style.color='#34244F';
				  }
			}
			outSelectedInfo();

			
			solveAllParams();	

//			writeTo('main_td',1,true);

						
//			cnt=parseInt(document.getElementById('count').value);
//			if(isNaN(cnt)) cnt=1;
//			document.getElementById('count').value=cnt;

//			document.getElementById('winfld').value=Math.round(itog*cnt);

//			document.getElementById('itogfld').value=Math.round(itog*cnt);
		}
		
///////////////////////////////////////////////////////
//  Šąńń÷åņ äėčķū įąēū
///////////////////////////////////////////////////////

		function solveBase()
		{
			return blocks[0].nWidth;
		}
		
///////////////////////////////////////////////////////
//  Šąńń÷åņ ļåščģåņšą šąģū
///////////////////////////////////////////////////////

		function solveRama()
		{
			var ww=0,hh=0,i;
			
/*			for(i=0;i<blockCnt;i++)
			  {
			    if(blocks[i])
				 if(!blocks[i].withChilds)
				  {
				    if(blocks[i].nTop<=1) ww+=parseInt(blocks[i].nWidth);
				    if(blocks[i].nLeft<=1) hh+=parseInt(blocks[i].nHeight);
			 	  }
			  }*/
			return (blocks[0].nWidth+blocks[0].nHeight)<<1;
		}
		
///////////////////////////////////////////////////////
//  Šąńń÷åņ äėčķū čģļīńņīā
///////////////////////////////////////////////////////

		function solveImpost()
		{
			var ww=0,hh=0,i,cnt=0;
			for(i=0;i<blockCnt;i++)
			  {
			    if(blocks[i])
				 if(!blocks[i].withChilds)
				  {
				    ww+=parseInt(blocks[i].nWidth);
				    hh+=parseInt(blocks[i].nHeight);
					cnt++;
			 	  }
			  }
			cnt--;
			return ((ww+hh)-(Math.floor(parseInt(document.getElementById('ramafld').value)/kk)>>1))-(100*cnt/kk);
		}
		
///////////////////////////////////////////////////////
//  Šąńń÷åņ ńīåäčķčņåėåé čģļīńņīā
///////////////////////////////////////////////////////

		function solveSoedImpost()
		{
			var cnt=0,i;
			
			for(i=0;i<blockCnt;i++)
			  {
			    if(blocks[i])
				 if(!blocks[i].withChilds)
				    cnt++;
			  }
			return (cnt-1)<<1;
		}
		
///////////////////////////////////////////////////////
//  Šąńń÷åņ äėčķū ńņāīšīź							
///////////////////////////////////////////////////////

		function solveStvorki()
		{
			var ww=0,hh=0,i;
			
			for(i=0;i<blockCnt;i++)
			  {
			    if(blocks[i])
				 if(!blocks[i].withChilds && blocks[i].Type>0)
				  {
				    ww+=parseInt(blocks[i].nWidth)-(50/kk);
				    hh+=parseInt(blocks[i].nHeight)-(76/kk);
			 	  }
			  }
			return (ww+hh)<<1;
		}
		
///////////////////////////////////////////////////////
//  Šąńń÷åņ äėčķū ųņąļčźą ńņāīšźč
///////////////////////////////////////////////////////

		function solveShtapik()
		{
			var ww=0,hh=0,i;
			
			for(i=0;i<blockCnt;i++)
			  {
			    if(blocks[i])
				 if(!blocks[i].withChilds && blocks[i].Type)
				  {
				    ww+=parseInt(blocks[i].nWidth)-(55/kk);
				    hh+=parseInt(blocks[i].nHeight)-(80/kk);
			 	  }
			  }
			return (ww+hh)<<1;
		}
		
///////////////////////////////////////////////////////
//  Šąńń÷åņ äėčķū ųņąļčźą šąģū
///////////////////////////////////////////////////////

		function solveShtapikr()
		{
			var ww=0,hh=0,i;
			
			for(i=0;i<blockCnt;i++)
			  {
			    if(blocks[i])
				 if(!blocks[i].withChilds && !blocks[i].Type)
				  {
				    ww+=parseInt(blocks[i].nWidth)-(55/kk);
				    hh+=parseInt(blocks[i].nHeight)-(80/kk);
			 	  }
			  }
			return (ww+hh)<<1;
		}
		
///////////////////////////////////////////////////////
//  Šąńń÷åņ ōóšķčņóšū
///////////////////////////////////////////////////////

		function solveFurnitura(type)
		{
			var cnt=0,i;
			
			for(i=0;i<blockCnt;i++)
			  {
			    if(blocks[i])
				 if(!blocks[i].withChilds)
				  {
				    switch(type)
					{
					  case 1:
					    if(blocks[i].Type==1 || blocks[i].Type==2) cnt++;
					  break;
					  case 2:
					    if(blocks[i].Type==3) cnt++;
					  break;
					  case 3:
					    if(blocks[i].Type==4 || blocks[i].Type==5) cnt++;
					  break;
					}
			 	  }
			  }
			return cnt;
		}
		
///////////////////////////////////////////////////////
//  Šąńń÷åņ ļėīłąäč ńņåźėīļąźåņą
///////////////////////////////////////////////////////

		function solveSteklo(nn)
		{
			var s=0,i;
			
			for(i=0;i<blockCnt;i++)
			  {
			    if(blocks[i])
				 if(!blocks[i].withChilds && (blocks[i].Tone==nn || nn==null))
				  {
				    s+=parseInt(blocks[i].nWidth-(50/kk))*parseInt(blocks[i].nHeight-(76/kk));
			 	  }
			  }
			return s;
		}
		
///////////////////////////////////////////////////////
//  Šąńń÷åņ źīėč÷åńņāą ēąćėóųåź
///////////////////////////////////////////////////////

		function solveZaglushki()
		{
			return 2;
		}

///////////////////////////////////////////////////////
//  Šąńń÷åņ źīėč÷åńņāą ļīäźėąäīź
///////////////////////////////////////////////////////

		function solvePodkl()
		{
			return 6;
		}

///////////////////////////////////////////////////////
//  Šąńń÷åņ ńņīčģīńņč ąźńåńńóąšīā
///////////////////////////////////////////////////////

		function solveAccessories()
		{
			var i=1,sum=0,fl=1;
			for(i=1;fl;i++)
			  {
				  	if(document.getElementById('ac_full'+i))
				      sum+=parseInt(document.getElementById('ac_full'+i).value);
					else
					  fl=0;
			  }
			return sum;
		}


///////////////////////////////////////////////////////
//  GetWindowCSV
///////////////////////////////////////////////////////

		function getWindowCSV()
		{
		  var outStr;
		  
		  outStr=blockCnt.toString()+';';
		  outStr+=kk+';';
		  for(i=0;i<blockCnt;i++)
		    {
			  if(blocks[i])
			    {
			      outStr+='exist;'
				  if(blocks[i].Parent) outStr+=blocks[i].Parent.Ind+';'
				  else
				  outStr+='null;'
				  outStr+=blocks[i].Type+';'
//				  alert('type='+blocks[i].Type);
				  outStr+=blocks[i].Tone+';'
				  outStr+=blocks[i].withChilds+';'
				  outStr+=blocks[i].ChildsType+';'
				  outStr+=blocks[i].Level+';'
				  outStr+=blocks[i].nWidth+';'
				  outStr+=blocks[i].nHeight+';'
				}
			  else
			    outStr+='empty;'
			}
//		  alert(outStr);
		  return outStr;
		}
		
///////////////////////////////////////////////////////
//  setWindowByCSV
///////////////////////////////////////////////////////

		function setWindowByCSV(strCSV)
		{
		  var str,i;
		  
		  str=strCSV.split(";");
		  blockCnt=0;
		  kk=parseFloat(str[1]);
		  i=2;
//		  alert('parseInt(str[0])='+parseInt(str[0]));
		  while(blockCnt<parseInt(str[0]))
		    {
			  if(str[i]=='empty')
			    {
			      blocks[blockCnt]=null;
				  i++;
				}
			  else
			    {
					if(str[i+1]=='null')
					  {
					     blocks[blockCnt]=new Block(blockCnt+1,null);
					  }
					else
					  {
//					alert('i='+blockCnt);
//					alert('p='+parseInt(str[i+1]));
					     blocks[blockCnt]=new Block(blockCnt+1,blocks[parseInt(str[i+1])]);
					  }
				    blocks[blockCnt].Type=parseInt(str[i+2]);
				    blocks[blockCnt].Tone=parseInt(str[i+3]);
				    blocks[blockCnt].ChildsType=parseInt(str[i+5]);
				    blocks[blockCnt].Level=parseInt(str[i+6]);
					blocks[blockCnt].nWidth=parseInt(str[i+7]);
					blocks[blockCnt].nHeight=parseInt(str[i+8]);
					if(str[i+4]=='true')
				      blocks[blockCnt].withChilds=true;
					else
				      blocks[blockCnt].withChilds=false;
					i+=9;
//					if(blocks[blockCnt].Parent)
//					alert('p='+blocks[blockCnt].Parent.Ind);
				}
				blockCnt++;
			 }
		  solveAllParams();
		  blocks[blockCnt-1].Select();
		}		
		
///////////////////////////////////////////////////////
//  Ēąźąē ā źīšēčķó
///////////////////////////////////////////////////////

		function startSubmit()
		{
		  var csv,acc_cnt=1,outstr='';
		
		  csv=getWindowCSV();
		  document.getElementById('outputdata').value=csv;
		  deselectBlock(selectedBlock);
		  document.getElementById('outputhtml').value=document.getElementById('main_td').innerHTML;
		  
		  document.getElementById('outputacc').value=document.getElementById('access_tbl').innerHTML;
		  document.getElementById('allfld').value=document.getElementById('itogfld').value;

	  	  /*if(!isVisible('accsizeblock') && isVisible('windowblock'))
			{
			  document.getElementById('mwidthfld').value=mWidth;
			  document.getElementById('mheightfld').value=mHeight;

			  if(document.getElementById('fdelivery').checked)
			    document.getElementById('delivery').value=' checked';
			  else
			    document.getElementById('delivery').value='';

			  if(document.getElementById('fdemount').checked)
			    document.getElementById('demount').value=' checked';
			  else
			    document.getElementById('demount').value='';

			  if(document.getElementById('fmount').checked)
			    document.getElementById('mount').value=' checked';
			  else
			    document.getElementById('mount').value='';
			}
		  else if(isVisible('accsizeblock'))
			{
			  document.getElementById('mwidthfld').value=document.getElementById('accwidthfld').value;
			  document.getElementById('mheightfld').value=document.getElementById('accheightfld').value;
			}
		  else
		    {
			  document.getElementById('mwidthfld').value=0;
			  document.getElementById('mheightfld').value=0;
			}*/
		  
		  if(self.ifr)
		  if(self.ifr.Head)	
			  while(ifr.document.getElementById('ac_'+acc_cnt))
			  {
			  	/*if(ifr.Head.Item('acc_'+ifr.IdArray[acc_cnt]).Checked && isVisible('accblock'))
				  {
				    outstr+='<input type="Hidden" value="1" maxlength="5" name="ac_f'+acc_cnt+'">'
				    outstr+='<input type="Hidden" value="'+ifr.document.getElementById('ac_h'+acc_cnt).value+'" maxlength="5" name="ac_h'+acc_cnt+'">'
				  }
				else
				  {
				    outstr+='<input type="Hidden" value="0" maxlength="5" name="ac_f'+acc_cnt+'">'
				  }*/
				acc_cnt++;
			  }
		  document.getElementById('access_span').outerHTML=outstr;
		  document.calcform.submit();
		}
		
///////////////////////////////////////////////////////
//  Ēąźąē ķą ńåšāåš
///////////////////////////////////////////////////////

		function submitOrder(status)
		{
		  var i,el;
		
		  if(!status)
		    {
			  if(!testForm('name','ŌČĪ'))
				  return 0;
			  else
			  if(!testForm('mail','E-mail','mail'))
				  return 0;
			  else
			  if(!testForm('tel','Ņåėåōīķ','tel'))
				  return 0;
			  else
			  if(!testForm('comments','Źīģģåķņąščč'))
				  return 0;
			 }

		  document.getElementById('regscr').outerHTML="<script>document.getElementById('region').selectedIndex="+document.getElementById('region').selectedIndex+";</script>";

		  	for(i=0;el=document.getElementById('spn'+i);i++)
			    el.innerHTML='';
		  	for(i=1;el=document.getElementById('rmv'+i);i++)
			  el.innerHTML='';
		  	for(i=1;el=document.getElementById('delid'+i);i++)
			  el.innerHTML='';
			if(document.getElementById('rem_sub'))
				document.getElementById('rem_sub').innerHTML='';
			for(i=1;i<=6;i++)
			if(document.getElementById('rem_sub'+i))
				document.getElementById('rem_sub'+i).innerHTML='';
			
/*			if(document.getElementById('rem_sub1'))
				document.getElementById('rem_sub1').innerHTML='';
			if(document.getElementById('rem_sub2'))
				document.getElementById('rem_sub2').innerHTML='';
			if(document.getElementById('rem_sub3'))
				document.getElementById('rem_sub3').innerHTML='';
			if(document.getElementById('rem_sub4'))
				document.getElementById('rem_sub4').innerHTML='';*/
//		  alert(reMail.test('__asdfadsfasd.sdf__'));
//		  alert(reTel.test('1243a2314'));
		  
//		  document.getElementById('outputdata').value=csv;
//		  deselectBlock(selectedBlock);
		  document.getElementById('orderhtml').value=document.getElementById('order_c').innerHTML;
		  if(status)
			  document.getElementById('orderstatus').value='0';
		  document.orderform.submit();
		  }

function refreshAcc()
{
  if(self.ifr)
	if(self.ifr.Head)
	  {
  		ifr.Head.Paint();
		document.getElementById('ifr').style.height=offsetYY(ifr.document.getElementById('bot_img'))+10;
		self.ifr.outCheckAcc(self.ifr);
	  }
	else
	 {
	 	if(document.getElementById('access_tbl').innerHTML!="")
		  {
//		 	show_frame();
			setCheck();
		  }
	 }
}		  

///////////////////////////////////////////////////////////////////////////////////////////////
var accSizeIsShow=0;

function isVisible(objId)
{
	//alert (document.getElementById(objId).style.visibility);
	if(document.getElementById(objId).style.visibility=='visible')
	  return true;
	else
	  return false; 
}

function showObject(objId,mode)
{
  //	alert (1);
if (objId) {

	if((isVisible(objId) && !mode) || mode=='hide')
	  {
		document.getElementById(objId).style.visibility='hidden';
		document.getElementById(objId).style.position='absolute';
	  }
	else
	  {
		document.getElementById(objId).style.visibility='visible';
		document.getElementById(objId).style.position='static';
	  }
}
}

function showHelpBlock()
{
	//showObject('helpblock');
	/*if(isVisible('helpblock'))
	  document.getElementById('helpchkbox').checked=true;*/
}

function showWindowBlock()
{
	showObject('windowblock','');
	showResultBlock();
/*	if(isVisible('windowblock'))
	  {
	  	if(!document.getElementById('widthfld').disabled)
		  {
		    document.getElementById('widthfld').value=document.getElementById('accwidthfld').value;
		    document.getElementById('heightfld').value=document.getElementById('accheightfld').value;
		  }
		//showObject('accsizeblock','hide');
//		accSizeIsShow=0;
	  }
	else
	  {
	    document.getElementById('accwidthfld').value=document.getElementById('widthfld').value;
	    document.getElementById('accheightfld').value=document.getElementById('heightfld').value;
	  /*	if(accSizeIsShow && isVisible('accblock'))
		  {
			showObject('accsizeblock','show');
		  }
	  }*/
	setTimeout('solveAll();refreshAcc();',100);
}

function showAccBlock()
{
	//showObject('accblock');
	showResultBlock();
//	alert(accSizeIsShow);
	/*if(!isVisible('accblock'))
	  {
		showObject('accsizeblock','hide');
	  }
	else
	  {
	    if(accSizeIsShow && !isVisible('windowblock'))
		  showObject('accsizeblock','show');
	  }*/
	//SetHeightOfIfr();
	
	setTimeout('refreshAcc();solveAll();',100);
}

function SetHeightOfIfr()
{
	/*if(!frames[0].SetHeight)
		setTimeout('SetHeightOfIfr();',100)
	else
		frames[0].SetHeight(self);*/
}

function showResultBlock()
{
	/*if(isVisible('windowblock') /*|| isVisible('accblock'))
		showObject('resultblock','show');
	else
		showObject('resultblock','hide');
		*/
}


