var edit_loaded = false;
var newContent=null;
//--- ÃÂ¸ÃÂ· ÃÂÃÂ°ÃÂ¹ÃÂ»ÃÂ° win.js

var win_SelectedItem;
var win_SelectedX, win_SelectedY;
var win_aMouseX,   win_aMouseY;
var win_checkMove = 0;
//---
var win_old_onmousemove=null;
var win_old_onmouseup  =null;
//---
function win_getPageSize()
  {
   /*if(navigator.appName=="Microsoft Internet Explorer")
     {
      var doc_element=document.documentElement;
      return([(doc_element.clientWidth ? doc_element.scrollWidth : document.body.scrollWidth), 
              (doc_element.clientWidth ? doc_element.scrollHeight: document.body.scrollHeight)]);
     }
   else
      return([document.body.clientWidth, document.body.clientHeight]);*/
   //if(window.opera)
   //  return [document.documentElement.scrollWidth, document.documentElement.scrollHeight];
   //alert("!!!");
   return [document.body.scrollWidth, document.body.scrollHeight]
   
  }
function win_getViewPage()
  {
   if(navigator.appName=="Microsoft Internet Explorer")
     {
      return([document.documentElement.clientWidth, document.documentElement.clientHeight]);     
     }
   else
      return([document.body.clientWidth, document.body.clientHeight]);
   
  }
function win_show(event)
  {
   var obj_content=document.getElementById('login_form');
   var obj_bkg    =document.getElementById('login_background');
   if(!obj_content || !obj_bkg) return;
   //---
   var pagesize=win_getPageSize();
   var style   =obj_bkg.style;
   //---
   style.width  =pagesize[0]+'px';
   style.height =pagesize[1]+'px';
   style.display="block";
   //---
   style=null;
   //---
   window_CentralWindow(obj_content,400,160);
   obj_content.style.display="block";
   //---
   win_show_bar(event);
  }

function win_hide()
  {
   var obj_content=document.getElementById('login_form');
   var obj_bkg    =document.getElementById('login_background');
   if(!obj_content || !obj_bkg) return;
   //---
   obj_content.style.display="none";
   obj_bkg.style.display="none";
  }

function win_resize(event)
  {
   var obj_bkg=document.getElementById('login_background');
   if(!obj_bkg) return;
   //---
   if(obj_bkg.style.display=="block") win_show(event);
  }

function win_down(event)
  {
   if(!event) event=window.event;
   //---
   win_SelectedItem=document.getElementById("login_form");
   //---
   win_SelectedX=parseInt(win_SelectedItem.style.left);
   win_SelectedY=parseInt(win_SelectedItem.style.top);
   //---
   win_aMouseX  = event.clientX;
   win_aMouseY  = event.clientY;
   win_checkMove= 1;
   //---
   win_old_onmousemove=document.onmousemove;
   win_old_onmouseup  =document.onmouseup;
   //---
   document.onmousemove=win_drag;
   document.onmouseup  =function(event){win_checkMove=0;};
  }

function win_drag(event)
  {
   if(win_checkMove!=1) return false;
   //---
   if(!event) event=window.event;
   //---
   win_SelectedItem.style.left=win_SelectedX+(event.clientX-win_aMouseX);
   win_SelectedItem.style.top =win_SelectedY+(event.clientY-win_aMouseY);
   //---
   return false;
  }

function win_drop(event)
  {
   document.onmousemove=win_old_onmousemove;
   document.onmouseup  =win_old_onmouseup;
   //---
   win_old_onmousemove=null;
   win_old_onmouseup  =null;
  }

function win_show_bar(event) 
  {
   coord = win_getViewPage();
   MouseX = coord[0]/2 - 200 - document.body.scrollLeft;
   MouseY = coord[1]/2 - 180 - document.body.scrollTop;
   //---
   obj = document.getElementById("login_form");
   if(!obj) return;
   //---
   obj.style.top =MouseY ;
   obj.style.left=MouseX;
   //---
   obj.style.visibility = "visible";
  }

function win_hide_bar() 
  {
   document.getElementById("login_form").style.visibility="hidden";
   win_hide();
  }

function win_show_opac(real) 
  {
   var obj=document.getElementById("login_form");
   if(!obj) return;
   //---
   obj.style.filter ="alpha(opacity="+(real==0 ? 100 : 75)+")";
   obj.style.opacity=(real==0 ? 1 : 0.75);
  }

function win_info_tips(obj,job) 
  {
   var oName =obj.cells[0].firstChild;
   //---
   if(obj) obj.style.backgroundColor=(job ? '#ECF4F6':'#FBFBFB'); 
   //---
   if(!oName) return;
   //---
   oName.style.display=(job ? 'block': 'none');
   oName.style.width  =(obj.offsetWidth-45)+"px";
  }
  
//--- ÃÂ¸ÃÂ· ÃÂÃÂ°ÃÂ¹ÃÂ»ÃÂ° tabs.js ÃÂÃÂ¿ÃÂÃÂ°ÃÂ²ÃÂ»ÃÂµÃÂ½ÃÂ¸ÃÂµ ÃÂ²ÃÂºÃÂ»ÃÂ°ÃÂ´ÃÂºÃÂ°ÃÂ¼ÃÂ¸  

var tabs_current='';
var tabs;

function SetTabs(tabssite)
  {
   tabs=tabssite;
  }

function TabsActivate(id)
  {
   var obj_tab;
   var obj_a;
   TabsShow(tabs_current,true);
   //---
   tabs_current=id;
   TabsShow(id);

   for(var i=0; i<tabs.length;i++ )
     {
      obj_tab =document.getElementById("tab_page_"+tabs[i]);
      obj_a   =document.getElementById("a_page_"+tabs[i-1]);
      if((obj_tab.className=='dialog_tab_select_wrong' || obj_tab.className=='dialog_tab_select' ))
        {
         if(obj_a)
            obj_a.className="divnotright";
        }      
      else
        {
         if(obj_a)
           { 
            obj_a.className="divright";
           }
        }    
     }
   
  }

function TabsShow(id,hide)
  {
   var obj_page=document.getElementById(id);
   var obj_tab =document.getElementById('tab_'+id);
   //---
   if(!obj_page || !obj_tab) return;
   //---
   var class_name='dialog_tab';
   //---
   var class_select='dialog_tab_select';
   if(hide)
     {
      var is_wrong=false;
      eval('try{is_wrong='+id+'_info;}catch(e){}');
      //---
      if(is_wrong==1) class_name='dialog_tab_wrong';
      
     }
   else
     {
      var is_wrong=false;
      if(obj_tab.className=='dialog_tab_wrong')
         class_select='dialog_tab_select_wrong';
      
     }  
   //---
   obj_page.style.display=(hide ? 'none'     : 'block');
   obj_tab.className     =(hide ? class_name : class_select);
  }

//--- news.js 

function quote(id,frame)
  {
   try
     {
      if(frame==true)
        {
         //if(! edit_loaded) show_editor(id);
         var d = window.frames[0].document;
        }
      else
        {
         document.CommentEdit.id.value=0;
        }
      //---
      var obj_content=document.getElementById('content'+id);
      var obj_author =document.getElementById('author_info_'+id);
      //----
      if(!obj_content || !obj_author) return;
      //----
      var d_content = obj_content.cloneNode(true);
      var o = d_content.firstChild, k;
      while(o)
        {
         k = o.nextSibling;
         if(o.nodeName == 'DIV' && o.className == 'fquote')
           d_content.removeChild(o);
         o = k;
        }
      //--- ÑÐ±Ð¸Ð²Ð°ÐµÐ¼ ÐºÐ°ÑÑÐ¸Ð½Ð¸Ðº
      o = d_content.getElementsByTagName('IMG');
      for(k=o.length-1;k>=0;--k)
        o[k].parentNode.removeChild(o[k]);
      //--- ÑÐ±Ð¸Ð²Ð°ÐµÐ¼ PRE ÑÐºÐ¸
      o = d_content.getElementsByTagName('PRE');
      for(k=o.length-1;k>=0;--k)
        o[k].parentNode.removeChild(o[k]);
      //---
      var content_str='<strong><span style="color:#42639C;"'+(obj_author.title ? ' title="'+obj_author.title+'"' : '')+'>'+obj_author.innerHTML+'</span> wrote:</strong> <br /> '+d_content.innerHTML;
      //---
      set_content('<div class="fquote">'+content_str+"</div>\n<p><br></p>",true,false,frame);
      //---
      if(frame==true)
        {
         if(window.frames[0].Gimel.isMSIE) window.frames[0].Gimel.SetFocus('content');
         window.frames[0].Gimel.ScrollToCursor('content');
        }
      else
        {
         if(Gimel.isMSIE)  Gimel.SetFocus('content');
         Gimel.ScrollToCursor('content');
         
        }
      //----
      edit_set_state();
      if(frame) d.CommentEdit.id.value=0;
     }
     catch(e){}
  }

function edit(id,frame)
  {
   if(frame==true)
     {
      //--- если редактор не загружен загружаем и выходим
      if(! edit_loaded)
        {
         show_editor(id);
         return;
        }
      //---
      var d = window.frames[0].document;
      d.CommentEdit.id.value=id;
      var cmd_new =d.getElementById('comment_new_cmd');
      var cmd_save=d.getElementById('comment_save_cmd');
     }
   else
     {
      var cmd_new    =document.getElementById('comment_new_cmd');
      var cmd_save   =document.getElementById('comment_save_cmd');
      document.CommentEdit.id.value=id;
     }
   //---
   var obj_content=document.getElementById('content'+id);
   //---
   if(!obj_content || !cmd_new || !cmd_save) return;
   //---
   cmd_new.style.display ='none';
   cmd_save.style.display='block';
   //--- set content
   if(obj_content)
     {
      set_content(obj_content.innerHTML,true,true,frame);
     }
  }

function edit_cancel()
  {
   var cmd_new    =document.getElementById('comment_new_cmd');
   var cmd_save   =document.getElementById('comment_save_cmd');
   //----
   if(!cmd_new || !cmd_save) return;
   //----
   document.CommentEdit.id.value=0;
   //----
   cmd_save.style.display='none';
   cmd_new.style.display ='block';
  if(window.Gimel)
     {
      set_content('',false,true);
     }
   //----
   edit_set_state();
  }

function edit_set_state(state)
  {
   var is_draft   =document.getElementById('draft_state');
   var ctrl_editor=document.getElementById('editor_ctrl');
   var ctrl_title =document.getElementById('editor_title');
   //----
   if(!ctrl_editor || !ctrl_title || !is_draft) return;
   //----
   if(!state || state=='')
     {
      if(parseInt(is_draft.value)>0)
        {
         ctrl_editor.checked   =true;
         ctrl_editor.disabled  =true;
         ctrl_title.style.color="#aaaaaa";
        }
      else
        {
         ctrl_editor.checked   =false;
         ctrl_editor.disabled  =false;
         ctrl_title.style.color="#626363";
        }
     }
   else
     {
      ctrl_editor.checked   =(parseInt(state)<=0);
      ctrl_editor.disabled  =false;
      ctrl_title.style.color="#626363";
     }
  }

function ShowCommentFrame(action,event,title)
  {
   var action_frame =document.getElementById('action_frame');
   var action_title =document.getElementById('action_title');
   var action_button=document.getElementById('action_button');
   //----
   if(!action_frame || !action_title || !action_button) return;
   //----
   action_title.innerHTML='&nbsp;&nbsp;'+title;
   //----
   document.ActionForm.reset();
   document.ActionForm.action=action;
   action_button.name        =event;
   //----
   action_frame.style.left=screen.availWidth/2 -parseInt(action_frame.style.width)/2;
   action_frame.style.top =screen.availHeight/2-parseInt(action_frame.style.height)/2-50;
   //----
   action_frame.style.visibility='visible';
   document.ActionForm.comment.focus();
  }

function HideCommentFrame()
  {
   var action_frame=document.getElementById('action_frame');
   //----
   if(!action_frame) return;
   //----
   action_frame.style.visibility='hidden';
  }

function set_content(str,clear_object,is_replace,frame)
  {
   var startPos=0;
   var endPos  =0;
   var valuePos=0;
   var url     ='';
   var content_str='';
   //---
   if((startPos=str.indexOf('<!--movie:'))>=0)
     {
      //---
      do
        {
         content_str+=str.substring(endPos,startPos);
         //---
         valuePos=str.indexOf('-->',startPos);
         if(valuePos<0) break;
         //---
         if(!clear_object) content_str+='<img src="http://www.mql4.com/editor/i/0.gif" id="movie:'+str.substring(startPos+10,valuePos)+'" class="player" height="251" width="305">';
         //---
         endPos=str.indexOf('<!--/movie',startPos);
         if(endPos<0) break;
         //---
         endPos+=13;
        }
      while((startPos=str.indexOf('<!--movie:',endPos))>=0);
      //---
      if(endPos>=0) content_str+=str.substring(endPos,str.length);
     }
   else
     {
      content_str=str;
     }
   //--- проверяем редактор в фрайме
   if(frame==true)
     {
      //--- если редактор даже не загружался загрузим его
      if(!edit_loaded)
        {
         newContent=content_str;
         show_editor(0);
        }
      //---
      if(is_replace) window.frames[0].Gimel.SetContent('content',content_str, true,true,true);
      else           window.frames[0].Gimel.InsertContent('content',content_str, true,false,true);
     }
   else
     {
      if(is_replace) Gimel.SetContent('content',content_str, true,true,true);
      else           Gimel.InsertContent('content',content_str, true,false,true);
     }
  }
  
//--- ÃÂ¸ÃÂ· validator.js ÃÂÃÂÃÂ¾ÃÂ²ÃÂµÃÂÃÂºÃÂ° ÃÂ²ÃÂÃÂ¾ÃÂ´ÃÂ½ÃÂÃÂ ÃÂ´ÃÂ°ÃÂ½ÃÂ½ÃÂÃÂ ÃÂ½ÃÂ° ÃÂ¿ÃÂÃÂ°ÃÂ²ÃÂ¸ÃÂ»ÃÂÃÂ½ÃÂ¾ÃÂµ ÃÂ·ÃÂ°ÃÂ¿ÃÂ¾ÃÂ»ÃÂ½ÃÂµÃÂ½ÃÂ¸ÃÂµ

//----
function validator(list)
  {
   if(!list || list.length<=0) return(false);
   //----
   var text_obj=null,item_obj=null;
   var ret=true,tmp=false,id='';
   //----
   for(key in list)
     {
      item_obj=document.getElementById(key);
      text_obj=document.getElementById(key+"_text");
      //----
      if(item_obj)
        {
         tmp=false;
         //----
         try{ eval("tmp=validator_"+list[key]+"(item_obj,text_obj);"); }catch(e){}
        }
      //----
      if(ret && !tmp) ret=false;
     }
   //----
   return(ret);
  }
//----
function validator_text(item_obj,text_obj)
  {
   //----
   if(item_obj.value=='')
     {
      if(text_obj) text_obj.className='error';
      //----
      try{ item_obj.focus(); } catch(e){}
      //----
      return false;
     }
   else
      if(text_obj) text_obj.className='';
   //----
   return true;
  }
//----
function validator_select(item_obj,text_obj)
  {
   //----
   if(item_obj.selectedIndex<=0 || item_obj.value<=0)
     {
      if(text_obj) text_obj.className='error';
      //----
      try{ item_obj.focus(); }catch(e){}
      //----
      return false;
     }
   else
      if(text_obj) text_obj.className='';
   //----
   return true;
  }
//----
function validator_new_password(item_obj,text_obj)
  {
   if(item_obj.value.length>0 && !validator_password(item_obj,text_obj))
     {
      if(text_obj) text_obj.className='error';
      //----
      try{ item_obj.focus(); } catch(e){}
      //----
      return false;
     }
   else
      if(text_obj) text_obj.className='';
   //----
   return true;
  }
//----
function validator_password(item_obj,text_obj)
  {
   //----
   if(item_obj.value.length<6
      || item_obj.value.toLowerCase()==item_obj.value
      || item_obj.value.toUpperCase()==item_obj.value
      || !(/[\d]{1,}/.test(item_obj.value)))
     {
      if(text_obj) text_obj.className='error';
      //----
      try{ item_obj.focus(); } catch(e){}
      //----
      return false;
     }
   else
      if(text_obj) text_obj.className='';
   //----
   return true;
  }
//----
function validator_simple_newpassword(item_obj,text_obj)
  {
   if(item_obj.value.length>0 && !validator_simple_password(item_obj,text_obj))
     {
      if(text_obj) text_obj.className='error';
      //----
      try{ item_obj.focus(); } catch(e){}
      //----
      return false;
     }
   else
      if(text_obj) text_obj.className='';
   //----
   return true;
  }
//----
function validator_simple_password(item_obj,text_obj)
  {
   if(item_obj.value.length<4)
     {
      if(text_obj) text_obj.className='error';
      //----
      try{ item_obj.focus(); } catch(e){}
      //----
      return false;
     }
   else
      if(text_obj) text_obj.className='';
   //----
   return true;
  }
//----
function validator_confirm_password(item_obj,text_obj)
  {
   var confirm_obj=document.getElementById(item_obj.id+'_confirm');
   //----
   if(!confirm_obj || (item_obj.value.length>0 && item_obj.value!=confirm_obj.value))
     {
      if(text_obj) text_obj.className='error';
      //----
      try{ item_obj.focus(); } catch(e){}
      //----
      return false;
     }
   else
      if(text_obj) text_obj.className='';
   //----
   return true;
  }
//----
function validator_email(item_obj,text_obj)
  {
   if(!(/^[0-9a-zA-Z]([-_.0-9a-zA-Z])*@[0-9a-zA-Z]([-_.0-9a-zA-Z])*\.[a-zA-Z]{2,4}$/.test(item_obj.value)))
     {
      if(text_obj) text_obj.className='error';
      //----
      try{ item_obj.focus(); } catch(e){}
      //----
      return false;
     }
   else
      if(text_obj) text_obj.className='';
   //----
   return true;
  }
//----
function validator_login(item_obj,text_obj)
  {
   if(item_obj.value.length<3 || item_obj.value.length>15
      || /[^0-9a-zA-Z\-\._]/.test(item_obj.value))
     {
      if(text_obj) text_obj.className='error';
      //----
      try{ item_obj.focus(); } catch(e){}
      //----
      return false;
     }
   else
      if(text_obj) text_obj.className='';
   //----
   return true;
  }
//----
function validator_minus_digit(item_obj,text_obj)
  {
   //----
   if(parseFloat(item_obj.value)>=0)
     {
      if(text_obj) text_obj.className='error';
      //----
      try{ item_obj.focus(); } catch(e){}
      //----
      return false;
     }
   else
      if(text_obj) text_obj.className='';
   //----
   return true;
  }
//----
function validator_plus_digit(item_obj,text_obj)
  {
   //----
   if(parseFloat(item_obj.value)<0)
     {
      if(text_obj) text_obj.className='error';
      //----
      try{ item_obj.focus(); } catch(e){}
      //----
      return false;
     }
   else
      if(text_obj) text_obj.className='';
   //----
   return true;
  }
//--- Ð¿ÑÐ¾Ð²ÐµÑÐºÐ° Ð½Ð° Ð¿ÑÐ°Ð²Ð¸Ð»ÑÐ½ÑÐµ ÑÐ¸Ð¼Ð²Ð¾Ð»Ñ Ð¸Ð¼ÐµÐ½Ð¸ ÑÐ°Ð¹Ð»Ð°, Ð½Ðµ ÐºÐ°ÑÐ°Ð»Ð¾Ð³Ð°
function validator_filename(item_obj,text_obj)
  {
   var fileName = extractFileName(item_obj.value);
   //---
   if(/[^0-9a-z\-\._\s]/i.test(fileName))
     {
      if(text_obj) text_obj.className='error';
      //----
      try{ item_obj.focus(); } catch(e){}
      //----
      return false;
     }
   else
      if(text_obj) text_obj.className='';
   //----
   return true;
  }  
//--- Ð¸Ð¼Ñ ÑÐ°Ð¹Ð»Ð° Ð¸Ð· Ð¿ÑÑÐ¸
function extractFileName(path) {
    path=path.replace("/","\\");
    var blankPos = path.lastIndexOf("\\");
    return path.substr(blankPos + 1);
}
//--- для новостей, показываем редактор при клике

function show_editor(id)
  {
   if(! edit_loaded)
     {
      var w;
      if(w = document.getElementById('coments'))
        {
         w.src = edit_url+newsID+'/'+pageID+'/'+id;
         w.style.display = '';
         edit_loaded = true;
        }
     }
  }

function editorLoaded()
  {
   if( newContent != null )
     {
      window.frames[0].Gimel.SetContent('content',newContent,true);
      newContent = null;
     }
   //----
   window.frames[0].Gimel.SetFocus('content');
  }
//--- показываем стейтмен в профайле пользователя.
function showStatement(url)
  {
   var statement=document.getElementById('istatementFrame');
   var a_href  =document.getElementById('a_statement');
   //---
   if(statement)
     {
      statement.src=url;
      statement.style.visibility = "visible";
      statement.style.display ='block';
      //---
      a_href.style.display    = 'none';
      a_href.style.visibility = "hidden";
     }
  }

function window_CentralWindow(id, width, height)
{     
 var win=id;
 //---
 var arrayPageSizes = window_getPageSize();
 var arrayPageScrolls = window_getPageScroll();
 //---
 var boxTop = arrayPageScrolls[1] + ((arrayPageSizes[3] - height) / 2);
 var boxLeft = ((arrayPageSizes[0] - width) / 2);
 //---
 win.style.top = (boxTop < 0) ? "0px" : boxTop + "px";
 win.style.left = (boxLeft < 0) ? "0px" : boxLeft + "px";
 win=null;
}
//---
function window_getPageScroll()
{
 var yScroll;
 if (self.pageYOffset)
   {
    yScroll = self.pageYOffset;
   }
 else if (document.documentElement && document.documentElement.scrollTop)
   {
   yScroll = document.documentElement.scrollTop;
   }
 else if (document.body)
   {
    yScroll = document.body.scrollTop;
   }
 //---
 arrayPageScroll = new Array('',yScroll) 
 return arrayPageScroll;
}
//---
function window_getPageSize(){

var xScroll, yScroll;

if (window.innerHeight && window.scrollMaxY)
  {
   xScroll = document.body.scrollWidth;
   yScroll = window.innerHeight + window.scrollMaxY;
  }
else if (document.body.scrollHeight > document.body.offsetHeight)
  {
   xScroll = document.body.scrollWidth;
   yScroll = document.body.scrollHeight;
  }
else
  {
   xScroll = document.body.offsetWidth;
   yScroll = document.body.offsetHeight;
  }
//---
var windowWidth, windowHeight;
if (self.innerHeight)
  { 
   windowWidth = self.innerWidth;
   windowHeight = self.innerHeight;
  }
else if (document.documentElement && document.documentElement.clientHeight)
  {
   windowWidth = document.documentElement.clientWidth;
   windowHeight = document.documentElement.clientHeight;
  }
else if (document.body)
  {
   windowWidth = document.body.clientWidth;
   windowHeight = document.body.clientHeight;
  }
//---
if(yScroll < windowHeight)
  {
   pageHeight = windowHeight;
  }
else
  { 
   pageHeight = yScroll;
  }
//---
if(xScroll < windowWidth)
  {
   pageWidth = windowWidth;
  }
else
  {
   pageWidth = xScroll;
  }
//---
arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
return arrayPageSize;
}
