﻿﻿QuinturaInviteEmbedIt= Class.create();
QuinturaInviteEmbedIt.prototype = {
divId : null,
bodyDivId : null,
PreviewDivId : null,
PreviewFrameId : null,
EmbedText : null,FlashText : null,FlashVersion:null,
newEmbedText : null,
request:null,
mapWidth:null,
mapHeight:null,
px:null,
show_r:null,
show_s:null,
partnerId:null,
partnerTopic:null,
ServerURL:null,
//partner_s:null,
//quintura_s:null,

initialize: function()
        {
       
        this.ServerURL = null;
        this.FlashVersion = false;
        this.EmbedText = '<div style="height:MAXHEIGHT;width:MAXWIDTH;background-color:white;"><script type="text/javascript" language="javascript" src="SERVERURL/light/?PartnerId=PARTNERID&PartnerTopic=PARTNERTOPIC&request=CURRREQUEST&ViewType=embed_it&show_sform=SHOWSFORM&show_result=SHOWREZULT"></script></div>';
        this.FlashText = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" '+
        'codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0"'+ 
        'width="MAXWIDTH" height="MAXHEIGHT" id="QuinturaFlash" align="middle">'+
        '<param name="allowScriptAccess" value="sameDomain" />'+
        '<param name="movie" value="SERVERURL/flash/quintura.swf?refresh=0&firstRequest=CURRREQUEST&engine=SERVERURL&partnerId=PARTNERID&partnerTopic=PARTNERTOPIC&lang=CURRLANG" />'+
        '<param name="quality" value="high" />'+
        '<param name="bgcolor" value="#ffffff" />'+
        '<param name="firstRequest" value="CURRREQUEST" />'+
        '<param name="lang" value="CURRLANG" />'+
        '<param name="engine" value="SERVERURL"/>'+
        '<param name="refresh" value="0" />'+
        '<param name="partnerId" value="PARTNERID"/>'+
        '<param name="partnerTopic" value="PARTNERTOPIC" />'+
        '<embed src="SERVERURL/flash/quintura.swf?refresh=0&firstRequest=CURRREQUEST&partnerId=PARTNERID&partnerTopic=PARTNERTOPIC&engine=SERVERURL&lang=CURRLANG" quality="high" bgcolor="#ffffff" width="MAXWIDTH" height="MAXHEIGHT" '+
        'name="QuinturaFlash" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" '+
        'pluginspage="http://www.macromedia.com/go/getflashplayer" />'+
        '</object>';
       //this.EmbedText = ServerURL+'/light_2.asp?PartnerId=PARTNERID&PartnerTopic=PARTNERTOPIC&request=CURRREQUEST&ViewType=embed_it&show_sform=SHOWSFORM&show_result=SHOWREZULT';
       
       // try
        {
        this.request=" ";
        this.mapWidth=EmbedMapParam['default_with_result']['width'];
        this.mapHeight=EmbedMapParam['default_with_result']['height'];
        this.px = "px";
        this.show_r=true;
        this.show_s=true;
        
        this.bodyDivId = $('EmbedItDiv1');
     	this.divId = 'EmbedIt1';
     	this.newEmbedText ='';
     	this.PreviewDivId =$('PreviewDiv');
     	this.PreviewFrameId =$('PreviewFrame');
     	if(!this.bodyDivId){this.bodyDivId = this.divId }
		
		{
		
			var Btn_div =  $('Btn_div1');
			if (!Btn_div)
			{
			  Btn_div = Builder.node('div', 
				{ 
				
					'id' : 'Btn_div1','name':'Btn_div1'
					
				}
				
				
				
				);
				$(this.bodyDivId).appendChild(Btn_div);
			   
			}
		
		
			
			var previewBut = $('previewBut');
			if (!previewBut) 
			{
				previewBut = Builder.node('input', 
				{ 
					'type' : 'button',
					'id' : 'previewBut',
					'value' : Langs[CurrentLang]['preview_but_embed'],
					//'value' : 'Preview',
					'class'	: 'submit_btn'
				});
				Btn_div.appendChild(previewBut);
			}
			Event.observe(previewBut, 'click', this.Preview.bindAsEventListener(this));
			
		    
			
			//---------------------------------------------				
			//var DescriptionBlockDiv =$('DescriptionBlockDiv1');
			//if (!DescriptionBlockDiv){DescriptionBlockDiv = Builder.node('div', { 'id' : 'DescriptionBlockDiv1' },Langs[CurrentLang]['embedit_desc'])};
			//$(this.bodyDivId).insertBefore(DescriptionBlockDiv, Btn_div);
			//---------------------------------------------
			
				
			var EmbedTextBlockDiv =$('EmbedTextBlockDiv1');
			if (!EmbedTextBlockDiv){EmbedTextBlockDiv = Builder.node('div', { 'id' : 'EmbedTextBlockDiv1' })};
			$(this.bodyDivId).insertBefore(EmbedTextBlockDiv, Btn_div);
			//---------------------------------------------
			Builder.node('div', { 'id' : 'request_title' }, 'Type your query: ');//Настройки карты
			
			var EmbedRequest =$('EmbedRequest1');
			if (!EmbedRequest)
			{
		    EmbedRequest = Builder.node('div',
			{
				'id' : 'RequestDiv'
			},
		    [
		    Builder.node('span', { 'id' : 'request_title' }, 'Type your query: '),
		    Builder.node('input',
			{
				'id' : 'EmbedRequest1',
				'type' : 'text',
				'name' : 'EmbedRequest',
				'value' :this.request
			})]);
			EmbedTextBlockDiv.appendChild(EmbedRequest);
			}
			
			var EmbedTextBlock =$('EmbedTextBlock1');
			if (!EmbedTextBlock)
			{
		    EmbedTextBlock = Builder.node('textarea',
			{
				'id' : 'EmbedTextBlock1',
				'name' : 'EmbedTextBlock1',
				'rows':4,
				'wrap':'soft'		
			});
			
			EmbedTextBlockDiv.appendChild(EmbedTextBlock);
			
			
			//-------------------------------------------
			var ParamBlockDiv =$('ParamBlockDiv1');
			if (!ParamBlockDiv){
			ParamBlockDiv = Builder.node('div', { 'id' : 'ParamBlockDiv1' })
			$(this.bodyDivId).insertBefore(ParamBlockDiv, Btn_div);
			};
			//-------------------------------------------
			var ShowResultDiv = $('ShowResultDiv1');
			if (!ShowResultDiv)
			{
			var ShowResultDiv = Builder.node('div',
			{
				'id' : 'ShowResultDiv1'
			},
			[
			//
			//Builder.node('hr', { 'id' : 'show_sform_title' }),
			Builder.node('div', { 'id' : 'show_result_title1' }, Langs[CurrentLang]['map_settings_titile']),//Настройки карты
			Builder.node('input', 
			{
				'id' : 'show_result_box1',
				'type' : 'checkbox',
				'checked' :true
				
			}),
			
			Builder.node('span', { 'id' : 'show_result_desc1' }, Langs[CurrentLang]['show_result_desc'])
			]);
			//$(this.bodyDivId).insertBefore(ShowResultDiv, Btn_div);
			ParamBlockDiv.appendChild(ShowResultDiv);
			
			}
			Event.observe($('show_result_box1'), 'click', this.ChangeEmbedText.bindAsEventListener(this));
			
			//-------------------------------------------
			
			var ShowSearchDiv = $('ShowSearchDiv1');
			if (!ShowSearchDiv)
			{
			var ShowSearchDiv = Builder.node('div',
			{
				'id' : 'ShowSearchDiv1'
			},
			[
			//Builder.node('hr', { 'id' : 'show_sform_title' }),
			Builder.node('input', 
			{
				'id' : 'show_sform_box1',
				'type' : 'checkbox',
				'checked' :true
				
			}),
			
			Builder.node('span', { 'id' : 'show_sform_desc1' }, Langs[CurrentLang]['show_sform_desc'])
			]);
			//$(this.bodyDivId).insertBefore(ShowSearchDiv, Btn_div);
			ParamBlockDiv.appendChild(ShowSearchDiv);
			
			}
			Event.observe($('show_sform_box1'), 'click', this.ChangeEmbedText.bindAsEventListener(this));
			
			//-------------------------------------------
			var ShowExactDimentions = $('ShowExactDimentions1');
			if (!ShowExactDimentions)
			{
			var ShowExactDimentions = Builder.node('div',
			{
				'id' : 'ShowExactDimentions1'
			},
			[
			//Builder.node('hr', { 'id' : 'show_sform_title' }),
			Builder.node('input', 
			{
				'id' : 'show_exec_dim_box1',
				'type' : 'radio',
				'name' : 'DefDimentions',
				'value' :'0'
				
			}),
			
			Builder.node('span', { 'id' : 'show_exec_dim1' }, Langs[CurrentLang]['show_exec_dim'])
			]);
			//$(this.bodyDivId).insertBefore(ShowExactDimentions, Btn_div);
			ParamBlockDiv.appendChild(ShowExactDimentions);
			}
			Event.observe($('show_exec_dim_box1'), 'click', this.ChangeEmbedText.bindAsEventListener(this));
			//-------------------------------------------
			//-------------------------------------------
			var ShowExactDimentions2 = $('ShowExactDimentions2');
			if (!ShowExactDimentions2)
			{
			var ShowExactDimentions2 = Builder.node('div',
			{
				'id' : 'ShowExactDimentions2'
			},
			[
			//Builder.node('hr', { 'id' : 'show_sform_title' }),
			Builder.node('input', 
			{
				'id' : 'show_exec_dim_box2',
				'type' : 'radio',
				'name' : 'DefDimentions',
				'value' :'1'
				
			}),
			
			Builder.node('span', { 'id' : 'show_exec_dim2' }, Langs[CurrentLang]['show_exec_dim'])
			]);
			//$(this.bodyDivId).insertBefore(ShowExactDimentions, Btn_div);
			ParamBlockDiv.appendChild(ShowExactDimentions);
			}
			Event.observe($('show_exec_dim_box2'), 'click', this.ChangeEmbedText.bindAsEventListener(this));
			//-------------------------------------------
			// Переключение по партнерам
			try
			{
			        if ($('select_cloud_site'))
			        {
			        //alert(Add_Partner+Add_Topic);
			        
			        Event.observe($('partner_URL'), 'click', this.ChangeEmbedText.bindAsEventListener(this));
			        Event.observe($('quintura_URL'), 'click', this.ChangeEmbedText.bindAsEventListener(this));
			        
			        AddSearchEngine({'PartnerId':GetPreviewSettingsParam('PartnerId'),'PartnerTopic':GetPreviewSettingsParam('PartnerTopic')});
			        AddSearchEngine({'PartnerId':GetOptionalPartnerID("PartnerId"),'PartnerTopic':GetOptionalPartnerTopic("PartnerTopic")});
			        
			        
			        //try {$('partner_URL_label').innerHTML = MapHeaders[SearchEngines[CurrentEngine]]}catch(ex){}
			        
			        }
			
			}catch(ex){}
			//Переключение по  Скриптам
			try
			{
			        if ($('js_code')&&$('flash_code'))
			        {
			        //alert(Add_Partner+Add_Topic);
			        
			        Event.observe($('js_code'), 'click', this.ChangeEmbedText.bindAsEventListener(this));
			        Event.observe($('flash_code'), 'click', this.ChangeEmbedText.bindAsEventListener(this));
			        
			       			        
			        
			        }
			
			}catch(ex){}
			
			//-------------------------------------------
			var DefDimentionsDiv = $('DefDimentionsDiv1');
			if (!DefDimentionsDiv)
			{
			var DefDimentionsDiv = Builder.node('div',
			{
				'id' : 'DefDimentionsDiv1'
			},
			[
			Builder.node('div', { 'id' : 'wfield_div1' },
			
			[
			Builder.node('span', { 'id' : 'wfield_title1' }, Langs[CurrentLang]['wfield_title']),
			Builder.node('input', 
			{
				'id' : 'show_wfield1',
				'type' : 'text',
				'value' : this.mapWidth
			})]),
			[
			
			Builder.node('div', { 'id' : 'hfield_div1' },
			[
			Builder.node('span', { 'id' : 'hfield_title1' }, Langs[CurrentLang]['hfield_title']),
			Builder.node('input', 
			{
				'id' : 'show_hfield1',
				'type' : 'text',
				'value' : this.mapHeight
			
			})])],
			Builder.node('div', { 'id' : 'dimentions_desc1' }, Langs[CurrentLang]['dimentions_desc'])
			]);
			$(this.bodyDivId).insertBefore(DefDimentionsDiv, Btn_div);
			}
			try{
			Event.observe($('show_hfield1'), 'change', this.ChangeEmbedText.bindAsEventListener(this));
			Event.observe($('show_wfield1'), 'change', this.ChangeEmbedText.bindAsEventListener(this));
			Event.observe($('EmbedRequest1'), 'change', this.ChangeEmbedText.bindAsEventListener(this));
			Event.observe($('if_want'), 'click', this.ToogleForm.bindAsEventListener(this));
			}catch(ex){}
			}
			}
		
		
		}
		//catch (e){}
		},
		
DisableSize : function ()
{
   Element.setStyle($('show_wfield1'),{backgroundColor:'#d6d6d6',color:'#d6d6d6'});
   Element.setStyle($('show_hfield1'),{backgroundColor:'#d6d6d6',color:'#d6d6d6'});
   $('show_wfield1').disabled=true;
   $('show_hfield1').disabled=true;
   $('show_hfield1').className="";
},

EnableSize : function ()
{

   Element.setStyle($('show_wfield1'),{backgroundColor:'#FFFFFF',color:'#000000'});
   Element.setStyle($('show_hfield1'),{backgroundColor:'#FFFFFF',color:'#000000'});
   $('show_wfield1').disabled=false;
   $('show_hfield1').disabled=false;
  

},

DisableParam :function ()
{
        
       $('show_result_box1').disabled=true;
       $('show_sform_box1').disabled=true;
      $('show_exec_dim_box1').disabled=true;
     //  $('show_exec_dim_box2').disabled=true;
      if ($('show_exec_dim_box1').checked){$('show_exec_dim_box2').checked=true;}
        
},

EnableParam :function ()
{
        
        $('show_result_box1').disabled=false;
        $('show_sform_box1').disabled=false;
        $('show_exec_dim_box1').disabled=false;
       //  $('show_exec_dim_box2').disabled=false;
        
},
	
ChangeEmbedText : function()
{   
   // var  
   
   
   this.px ="px";
   this.mapWidth = $('show_wfield1').value;  
   this.mapHeight = $('show_hfield1').value;
   
   /// Flash and JavaScript
   if ($('js_code').checked)
   {var q = this.EmbedText;this.FlashVersion = false;}
   else
   {var q = this.FlashText;this.FlashVersion = true;}
   
    
     
   this.show_s= $('show_sform_box1').checked;if (this.show_s?showform='1':showform='0') ;
   this.show_r = $('show_result_box1').checked;if (this.show_r?showrezult='1':showrezult='0') ;
   var showexecdim = $('show_exec_dim_box1').checked;if (showexecdim?showexecdim='1':showexecdim='0') ;
   
   
   if (showexecdim == '1') {
   this.mapWidth=100;this.mapHeight=100;this.px ="%";
   this.DisableSize();
   }
   else
   {
   this.EnableSize();
   if (!isFinite((this.mapWidth))||(this.mapWidth)<EmbedMapParam['min']['width']) //если не число, то ставим значение по умолчанию
   {
   if (showrezult=='1') 
     {this.mapWidth=EmbedMapParam['default_with_result']['width'];$('show_wfield1').value = this.mapWidth;}
   else
     {this.mapWidth=EmbedMapParam['default']['width'];$('show_wfield1').value = this.mapWidth;}}
   
   if (!isFinite((this.mapHeight))||(this.mapHeight)<EmbedMapParam['min']['height']) //если не число, то ставим значение по умолчанию
   {
   if (showrezult=='1')
     {this.mapHeight=EmbedMapParam['default_with_result']['height'];$('show_hfield1').value = this.mapHeight;}
   else
     {this.mapHeight=EmbedMapParam['default']['height'];$('show_hfield1').value = this.mapHeight;}
   }
   }
   
   /////////////////////////////////
   if ($('flash_code').checked){this.DisableParam();this.px='';this.EnableSize();}else {this.EnableParam();if(showexecdim != '1'){this.EnableSize();}}
   
   
   //-------------------------------------------------------------------------------
   try{this.ServerURL =UrlForEmbedServer}catch(ex)
   {this.ServerURL =MainDomain}
   //=================================================
   try
   {
     if ($('partner_URL').checked){

         SetSearchEngine(1);
         
         this.partnerId = GetOptionalPartnerID('PartnerId'); 
         this.partnerTopic = GetOptionalPartnerTopic('PartnerTopic'); //Settings for partner site
         
         }
     if ($('quintura_URL').checked){
         
         this.partnerId = GetPreviewSettingsParam('PartnerId'); 
         this.partnerTopic  = GetPreviewSettingsParam('PartnerTopic');//Settings for service site
         
         SetSearchEngine(0);
         
         if (GetPreviewSettingsParam('UrlForEmbedServer')) {this.ServerURL  = GetPreviewSettingsParam('UrlForEmbedServer');
         }
         }     
   }
   catch (ex)
   {
     this.partnerId = GetPreviewSettingsParam('PartnerId'); 
     this.partnerTopic  = GetPreviewSettingsParam('PartnerTopic');
     
   }
  if (GetPreviewSettingsParam('UrlForEmbedServer')) {this.ServerURL  = GetPreviewSettingsParam('UrlForEmbedServer');}
  //--------------------------------------------------------------------------------
   
   this.request = $('EmbedRequest1').value;
   var req = encodeURIComponent(this.request);
   
   var q = q.replace(/MAXHEIGHT/g, this.mapHeight+this.px ).replace(/SERVERURL/g, this.ServerURL  ).replace(/MAXWIDTH/g, this.mapWidth+this.px ).replace(/SHOWSFORM/, showform).replace(/SHOWREZULT/, showrezult).replace(/CURRREQUEST/g, req).replace(/PARTNERID/g, this.partnerId).replace(/PARTNERTOPIC/g, this.partnerTopic ).replace(/CURRLANG/g, CurrentLang);
   
	var EmbedTextBlock = $('EmbedTextBlock1');
	
   
     	EmbedTextBlock.value=q;
	    this.newEmbedText=q;
	
	//EmbedTextBlock.select();
	
	//this.Preview(req,maxwidth,maxheight,showrezult,showform);
},	
Preview: function()
{
if (this.FlashVersion)
{
        
        Element.setStyle($('EmbedFlashPreview'),{'display':'block'});
        if (this.mapWidth=="100"){this.mapWidth=EmbedMapParam['default_with_result']['width'];}
        if (this.mapHeight=="100"){this.mapHeight=EmbedMapParam['default_with_result']['height'];}
             
           
        
        
              Element.setStyle($('EmbedFlashPreview'),{'width':this.mapWidth});
              Element.setStyle($('EmbedFlashPreview'),{'height':this.mapHeight});
              Element.setStyle($('EmbedMapPreview'),{'display':'none'});
        //Вставка Flash
         var so = new SWFObject(this.ServerURL+"/flash/quintura.swf?engine="+this.ServerURL +"&partnerId="+this.partnerId+"&partnerTopic="+this.partnerTopic+"&lang="+CurrentLang+"&firstRequest="+encodeURIComponent(this.request)+"","mymovie",this.mapWidth,this.mapHeight,"7","#FFFFFF");
                      so.addParam("engine", this.ServerURL );
                      so.addParam("lang", CurrentLang );
                      so.addParam("partnerId", this.partnerId );
                      so.addParam("partnerTopic", this.partnerTopic );
                      so.addParam("firstRequest", encodeURIComponent(this.request));
                      so.write("EmbedFlashPreview");
                  

}
else
{

        if (this.show_r){var show_r='block';}else{var show_r='none';}
        if (this.show_s){var  show_s='block';}else{var show_s='none';}
        
        Element.setStyle($('EmbedMapPreview'),{'display':'block'});
        Element.setStyle($('EmbedFlashPreview'),{'display':'none'});
        
        Element.setStyle($('EmbedMapPreview'),{'width':this.mapWidth+this.px });
        Element.setStyle($('EmbedMapPreview'),{'height':this.mapHeight+this.px });
        Element.setStyle($('result_td'),{'display':show_r});
        Element.setStyle($('qform_td'),{'display':show_s});
        
       
        QSearchForm.SetRequestString(this.request);
      
        Display.SendRequest(true);
   }     

},	
ToogleForm: function()
{  
  var FormDiv = $('IWANT');
  if (FormDiv)
  {
    if (FormDiv.style.display == 'none')
    {
    FormDiv.style.display = 'block';
    try
        {
           $('send_mail_but').focus(); 
           $('fname').focus();
        }
        catch(ex){}
    }
    else
    {
    FormDiv.style.display = 'none';
    }
  } 
},
Toogle: function()
  { 
 
  {
	
	    var body = document.getElementsByTagName('body').item(0);
	    var currMapName = '';
	  	if ($(this.divId).style.display == 'none') 
	  	
	  	   {  
            
	  	    var EmbedTextBlock = $('EmbedTextBlock');               
	  	    this.ChangeEmbedText();
			 
	  		$(this.divId).style.display = 'block';
	  		EmbedTextBlock.select();
	  		
	  			  		
	  	    }
	  	 else
		 {
		    
		    $(this.divId).style.display = 'none';
		    
		
		    
		    }
		
		}
    }
		
			  
}