	var mapDiv = null;
	var resultsDiv = null;
	var resultsIFrame = null;
	var layoutDiv = null;
    var controlDiv = null;
    var toolbarDiv = null;
    var embedBut = null; var shareBut = null; var saveBut = null;
    var waitDiv = null;
//    var CurrentLangPHP = (Cookie.get('LanguagePHP')) ? Cookie.get('LanguagePHP') : GetSystemParam('CurrentLang'); 
 
	
	function InitLayout()
	{
		var currType = Cookie.get('lType');
		if (currType == null) 
		{
			currType = 'v35x65';
			Cookie.set('lType', currType, 365);
		}
	 CreateLayout(currType);

        }
	
	function CreateLayout(lType) {
		try
		{
	  		var currType = Cookie.get('lType');
	  		mapDiv = $('SearchMap');
	  		if (!mapDiv) mapDiv = Builder.node('div',{ 'id' : 'SearchMap' } );
	  		resultsDiv = $('SearchResults');
	  		if (!resultsDiv) resultsDiv = Builder.node('div',{ 'id' : 'SearchResults' } );
 		        controlDiv = $('controlDiv');
		        if (!controlDiv) controlDiv = 
	        	    Builder.node('div',
		            { 'id' : 'ControlDiv' },
		            [Builder.node
	        	    ('div',{ 'id' : 'waitDiv','className':'waiting'})
		           ]);
			toolbarDiv =$('toolbarDiv');
			if (!toolbarDiv) toolbarDiv =  Builder.node
	            	('div',{ 'id' : 'toolbarDiv' });
	                waitDiv = $('waitDiv');
		        if (!waitDiv) waitDiv = 
			Builder.node('div',{ 'id' : 'waitDiv' });    
	            
			mapTitleDiv = $('MapTitle');
			if (!mapTitleDiv) mapTitleDiv = 
			Builder.node('span',{ 'id' : 'MapTitle' });
	                	  		
	  		layoutDiv = $('LayoutDiv');
 			layoutDiv.className = lType;
 	  		if (layoutDiv) 
	  		{
//				var tdSearchMapStyle = 'min-height: 376px;';	// minimal map size
				var tdSearchMapStyle = 'min-height: 100px;';	// minimal map size
				var tblLeftStyle = 'height: 100%;';

	  			var code = '';
	  			useIFrames = false;
	  			code += '<div class="lpanel" id="tblLeft" style="' + tblLeftStyle + '; width:35%;">';                         
	  			code += '<div id="tdTitle"></div>';
	  			code += '<div id="SearchMap" style="' + tdSearchMapStyle + 'height: 100%;"></div>';
				code += '<img style="_width:320px; height:1px; visibility:hidden;">';
	  			code += '</div>';
	  			code += '<div class="rpanel" id="SearchResults" style="width:65%;"></div>';
	  			layoutDiv.innerHTML = code;
		                $('tblLeft').appendChild(controlDiv);
	  			$('tblLeft').appendChild(toolbarDiv);

 	                //---------------Заголовок карты----------------------
                		$('tdTitle').appendChild(mapTitleDiv);
	                //-----------------------------------------------------
 		  		if (!$("embed_span")){this.AddToToolbar("embed",$('toolbarDiv'));}
		  		if (!$("share_span")){this.AddToToolbar("share",$('toolbarDiv'));}
		  		//if (!$("saveit_span")){this.AddToToolbar("saveit",$('toolbarDiv'));}

				adjustSizes();
		  	}
		  	else
		  	{
		  		alert('No layout div');
		  	}
		}
		catch (ex)
		{
			alert(ex.toString());
		}  		
	}

	function AddToToolbar(button,toolbarDiv,alt)
	{
	try
	{ 
	   var el =  Builder.node('a', { 'id':button+'_span','className':button+"_Act_"+GetSystemParam('CurrentLang'),'href':'javascript:void(0);','title':Langs[GetSystemParam('CurrentLang')][button+"_but"] });               
	   toolbarDiv.appendChild(el);
				
	}catch(e){}			
	}			
	
	function LayoutChange(e) 
	{
		var lType = e.id.replace(/viewType[_]/,'');
		if (Cookie.get('lType')!=lType)
		{
		Cookie.set('lType', lType, 365);
		CreateLayout(lType, 'WorkTr');
		if (QMap.currentRequest.replace(/\s+$/, '')!=''){location.href = MainDomain+"/main/?request="+QMap.currentRequest;}else{location.href = MainDomain+"/main/";}
		Element.setStyle($(mapDiv), {'display':'none'});
		Element.setStyle($(horDiv), {'display':'none'});
		}
		//QMap.Resize();
	}



