/**
 * @author Petuhov Dmitriy
 * @copyright 2007 MetaQuotes Software Corp.
 */
var img_close = document.createElement('img');
img_close.src = '/i/closebox_close.gif';

window.DialogWindow =
{
 
 layer   : null,
 content : null,
 caption : null,
 back    : null,
 
 state      : false,
 dx         : 0,
 dy         : 0,
 maxwidth   : 0,
 maxheight  : 0,

 setBackSize : function ()
   {
   // s = DialogWindow.back.style).width = document.documentElement.scrollWidth+'px';
    var s;
    (s = DialogWindow.back.style).width = '100%';
    //alert(document.documentElement.scrollHeight+'/'+document.documentElement.clientWidth);
    s.height = document.documentElement.scrollHeight+'px';
    
   },
 
 show : function (title, html,  width, height)
   {
       
   html=html.replace(/id="PREFIX/g, 'id="'); 
   html=html.replace(/id=PREFIX/g, 'id=');

    
    function setSize()
      {
       var s;
       (s = DialogWindow.layer.style).width = width + 'px';
       s.height = height + 'px';
       (s = DialogWindow.content.style).width = width - ((! window.MSIE5)?4:0) + 'px';
       s.height = height - 40 - ((! window.MSIE5)?4:0) +'px';
      }


    function makeWindow()
      {
       var back = (DialogWindow.back = document.createElement('div'));
       back.className = 'window-disabler';
       back.innerHTML = '&nbsp;';
       document.body.appendChild(back);
       //---
       var layer = (DialogWindow.layer = document.createElement('div'));
       layer.className = 'window-dialog';
       //---
       var caption = (DialogWindow.caption = document.createElement('div'));
       caption.className = 'window-caption';
       caption.innerHTML = '<span style="font-size:1px;">&nbsp;</span>';
       layer.appendChild(caption);
       //---
       var a         = document.createElement('span');
       a.innerHTML   = title;
       caption.insertBefore(a,caption.lastChild);
       //---
       a.onclick = function (e)
                     {
                      if(! e) e = window.event;
                      //---
                      if(e.stopPropagation)
                        e.stopPropagation();
                      else
                        e.cancelBubble = true;
                      return false;
                     }
       //---
       img_close.onclick = DialogWindow.close;
       caption.insertBefore(img_close,caption.lastChild);
       //---
       var content = (DialogWindow.content = document.createElement('div'));
       content.className = 'window-content';
       layer.appendChild(content);
       //---
       document.body.appendChild(layer);
       //---
       if(window.opera)
         {
          caption.onmousedown = DialogWindow.down;
          document.addEventListener('mouseup',DialogWindow.up,true);
          caption.addEventListener('mouseup',DialogWindow.up,true);
          back.onmousemove = DialogWindow.move;
          layer.addEventListener('mousemove',DialogWindow.move,true);
          window.addEventListener('resize',DialogWindow.setBackSize,true);
         }
       else if(document.addEventListener)
         {
          document.addEventListener('mouseup',DialogWindow.up,true);
          caption.addEventListener('mouseup',DialogWindow.up,true);
          back.addEventListener('mousemove',DialogWindow.move,true);
          layer.addEventListener('mousemove',DialogWindow.move,true);
          caption.addEventListener('mousedown',DialogWindow.down,true);
          window.addEventListener('resize',DialogWindow.setBackSize,true);
         }
       else
         {
          document.attachEvent('onmouseup',DialogWindow.up);
          caption.attachEvent('onmouseup',DialogWindow.up);
          back.attachEvent('onmousemove',DialogWindow.move);
          layer.attachEvent('onmousemove',DialogWindow.move);
          caption.attachEvent('onmousedown',DialogWindow.down);
          window.onresize = DialogWindow.setBackSize;
         }
      };
    if(! DialogWindow.layer)
      makeWindow();
    //---
    this.setBackSize();
    setSize();
    
    DialogWindow.content.innerHTML = html;
    
    DialogWindow.dx = DialogWindow.dy = 0;
    
    var y,x;
    if(! window.MSIE)
      {
       y = Math.ceil((document.documentElement.clientHeight / 2) - (height / 2));
       x = Math.ceil((document.documentElement.clientWidth / 2) - (width / 2));
       //y = Math.ceil((window.innerHeight / 2) - (height / 2));
       //x = Math.ceil((window.innerWidth / 2) - (width / 2));
      }
    else if(! window.MSIE5)
      {
       y = Math.ceil((document.documentElement.clientHeight / 2) - (height / 2));
       x = Math.ceil((document.documentElement.clientWidth / 2) - (width / 2));
      }
    else
      {
       y = Math.ceil((document.documentElement.scrollHeight / 2) - (height / 2));
       x = Math.ceil((document.documentElement.scrollWidth / 2) - (width / 2));
      }
    
    y+=document.documentElement.scrollTop;
    x+=document.documentElement.scrollLeft;
    DialogWindow.setPos(x,y);
    
    DialogWindow.back.style.display    = 'block';
    DialogWindow.layer.style.display   = 'block';
    DialogWindow.maxwidth              = document.documentElement.clientWidth-width;
    DialogWindow.maxheight             = document.documentElement.scrollHeight-height;
    if ($('forum_user_login') && $('forum_user_login').value=='') {$('forum_user_login').focus();}
    if ($('forum_user_login') && $('forum_user_login').value!='') {$('forum_user_password').focus();}
   },
   
  setPos : function (x,y)
    {
     if (DialogWindow.maxwidth){
      df5=DialogWindow.dx-28;
      df6=DialogWindow.dy-28;
      if (x>DialogWindow.maxwidth+df5  || x<DialogWindow.dx ) x=null;
      if (y>DialogWindow.maxheight+df6 || y<DialogWindow.dy ) y=null;
     }
     var s;
     s = DialogWindow.layer.style;
     if (x) s.left = x - DialogWindow.dx +'px';
     if (y) s.top = y - DialogWindow.dy +'px';
    },
   
  move : function (e)
    {
     if(! DialogWindow.state)
       return;
     //---
     if(!e) e = window.event;
     //---
     DialogWindow.setPos(e.clientX,e.clientY);
     //---
     if(e.stopPropagation)
       e.stopPropagation();
     else
       e.cancelBubble = true;
    },
  up   : function ()
    {
     DialogWindow.state = false;
    },
  down : function (e)
    {
     if(! e) e = window.event;
     //---
     DialogWindow.state = true;
     //---
     var s;
     DialogWindow.dx = e.clientX - parseInt((s = DialogWindow.layer.style).left);
     DialogWindow.dy = e.clientY - parseInt(s.top);
     //---
     if(e.stopPropagation)
       e.stopPropagation();
     else
       e.cancelBubble = true;
     //---
     return false;
    },
  close : function ()
    {
     DialogWindow.back.style.display   = 'none';
     DialogWindow.layer.style.display  = 'none';
    }
}//---
var win_ban_SelectedItem;
var win_ban_SelectedX, win_ban_SelectedY;
var win_ban_aMouseX,   win_ban_aMouseY;
var win_ban_checkMove = 0;
//---


function win_ban_show(event,ip,cookie,user_id,user_name,lng)
  {
   obj = document.getElementById("edit_div");
   if(!obj) return;
   //---
   var scroll=getPageScroll();
   var arrayPageSize    = getPageSize();
   var arrayPageScroll  = getPageScroll();
   //---
   //alert("pagesize:\n"+arrayPageSize+"\n\nPageScroll\n"+arrayPageScroll);
   var boxTop           = arrayPageScroll[1] + ((arrayPageSize[3] - 175) / 2);
   var boxLeft          = ((arrayPageSize[0] - 537) / 2);
   //---
   //alert(boxLeft+'-'+boxTop);
   obj.style.top =(boxTop < 0) ? "0px" : boxTop + "px";
   obj.style.left=(boxLeft < 0) ? "0px" : boxLeft + "px";
   //---
   obj.style.display="block";
   var edit_ip    =document.getElementById("ip_address");
   var edit_cookie=document.getElementById("cookie");
   var comment    =document.getElementById("comment");
   var user       =document.getElementById("user_id");
   if(edit_ip)    edit_ip.value=ip;
   if(edit_cookie)edit_cookie.value=cookie;
   if(comment)    
      if(lng=='ru')      comment.value="Бан пользователя: "+user_name;
      else if(lng=='cn') comment.value="Ban user: "+user_name;
      else               comment.value="Ban user: "+user_name;
   if(user)       user.value=user_id;
   //obj.style.visibility = "visible";
  }
//---  
function win_ban_drag(event)
  {
   if(win_ban_checkMove!=1) return false;
   //---
   if(!event) event=window.event;
   //---
   win_ban_SelectedItem.style.left=win_ban_SelectedX+(event.clientX-win_ban_aMouseX)+"px";
   win_ban_SelectedItem.style.top =win_ban_SelectedY+(event.clientY-win_ban_aMouseY)+"px";
   //---
   return false;
  }
//---
function win_ban_drop(event)
  {
   document.onmousemove=win_old_ban_onmousemove;
   document.onmouseup  =win_old_ban_onmouseup;
   //---
   win_old_ban_onmousemove=null;
   win_old_ban_onmouseup  =null;
  }
//---
function win_hide() 
  {
   var obj=document.getElementById("edit_div");
   if(!obj) return;
   obj.style.display="none";
  }
//---
function win_ban_down(event)
  {
   if(!event) event=window.event;
   //---
   win_ban_SelectedItem=document.getElementById("edit_div");
   //---
   win_ban_SelectedX=parseInt(win_ban_SelectedItem.style.left);
   win_ban_SelectedY=parseInt(win_ban_SelectedItem.style.top);
   //---
   win_ban_aMouseX  = event.clientX;
   win_ban_aMouseY  = event.clientY;
   win_ban_checkMove= 1;
   //---
   win_old_ban_onmousemove=document.onmousemove;
   win_old_ban_onmouseup  =document.onmouseup;
   //---
   document.onmousemove=win_ban_drag;
   document.onmouseup  =function(event){win_ban_checkMove=0;};
  }
//---
function form_validator_ban(frm)
  {
   if(!frm) return(false);
   //----
   var is_error=false;
   //----
   var obj=document.getElementById("ip_address");
   if(obj.value!='' && /[0-9]{1,3}\.[0-9]{1,3}\.([0-9]{1,3}|\*)\.([0-9]{1,3}|\*)/.test(obj.value)==false)
     {
      alert("");
      return(false);
     }
   //----
   return(true);
  }
  
  
function 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 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;
}
  function edit(id)
  {
   var type=((""+id).substr(0,1)=='_' ? 0 : 1);
   //---
   if(type==0) real_id=parseInt(id.substr(1,id.length));
   else        real_id=parseInt(id);
   //---
   var src_id     =document.getElementById('id_message');
   var src_subject=document.getElementById('subject_message');
   var src_content=document.getElementById('content'+id);
   var src_simple =document.getElementById('simple_message');
   //---
   var edit_id       =document.getElementById('edit_id');
   var edit_parent_id=document.getElementById('edit_parent_id');
   //---
   var obj_subject   =document.getElementById('edit_subject');
   var obj_simple    =document.getElementById('edit_simple');
   //---
   var data_subject      =document.getElementById('subject');
   var data_file         =document.getElementById('edit_file');
   var data_subject_title=document.getElementById('subject');
   var data_simple       =document.getElementById('simple');
   //---
   var cmd_cnew =document.getElementById('edit_cnew_cmd');
   var cmd_csave=document.getElementById('edit_csave_cmd');
   var cmd_new  =document.getElementById('edit_new_cmd');
   var cmd_save =document.getElementById('edit_save_cmd');
   //---
   var admin_date_create      =document.getElementById('admin_date_create');
   var admin_date_modify      =document.getElementById('admin_date_modify');
   var admin_label_date_modify=document.getElementById('admin_label_date_modify');
   var admin_not_modify       =document.getElementById('admin_not_modify');
   var admin_label_not_modify =document.getElementById('admin_label_not_modify');
   //---
   var obj_date    =document.getElementById('date_'+id);
   var obj_author  =document.getElementById('author_info_'+id);
   var admin_author=document.getElementById('admin_author');
   //--- set id
   if(edit_id && src_id) { edit_id.value=real_id; }
   //--- set subject
   if(src_subject && obj_subject && data_subject)
     {
      if(type==0) { data_subject.value=src_subject.value; obj_subject.style.display="block"; }
      else        { data_subject.value='';                obj_subject.style.display="none";  }
     }
   //--- set content
   if(src_content && window.Gimel)
     {
      set_content(src_content.innerHTML,false,true);
     }
   //--- set file
   if(data_file) try { data_file.value=''; }catch(e){}
   //--- set simple
   if(src_simple && obj_simple && data_simple)
     {
      if(type==0) { data_simple.checked=(src_simple.value==0); obj_simple.style.display="block"; }
      else        { data_simple.checked=false;                 obj_simple.style.display="none";  }
     }
   //--- set cmd
   if(cmd_cnew && cmd_csave)
     {
      if(type==0) { cmd_cnew.style.display='none'; cmd_csave.style.display='none';  }
      else        { cmd_cnew.style.display='none'; cmd_csave.style.display='block'; }
     }
   //---
   if(cmd_new && cmd_save)
     {
      if(type==0) { cmd_new.style.display='none'; cmd_save.style.display='block';  }
      else        { cmd_new.style.display='none'; cmd_save.style.display='none'; }
     }
   //---
   var date_list=null;
   //---
   if(obj_date && obj_date.innerHTML) date_list=obj_date.innerHTML.split('|');
   //---
   if(admin_date_create) admin_date_create.value=(date_list[0]!=null ? date_list[0] : '');
   //---
   if(admin_date_modify)
     {
      admin_date_modify.style.display=(type==0 ? 'block' : 'none');
      //---
      admin_date_modify.value=(type==0 && date_list[1]!=null ? date_list[1] : '');
     }
   //---
   if(admin_label_date_modify) admin_label_date_modify.style.display=(type==0 ? 'block' : 'none');
   //---
   if(admin_not_modify)
     {
      admin_not_modify.style.display='none';
      //---
      admin_not_modify.checked=false;
     }
   //---
   if(admin_label_not_modify)     admin_label_not_modify.style.display ='none';
   if(admin_author && obj_author) admin_author.value=obj_author.innerHTML;
  }

function edit_cancel()
  {
   var src_id=document.getElementById('id_message');
   //---
   var edit_id       =document.getElementById('edit_id');
   //---
   var obj_subject=document.getElementById('edit_subject');
   var obj_simple =document.getElementById('edit_simple');
   //---
   var data_subject      =document.getElementById('subject');
   var data_file         =document.getElementById('edit_file');
   var data_subject_title=document.getElementById('subject');
   var data_simple       =document.getElementById('simple');
   //---
   var cmd_cnew =document.getElementById('edit_cnew_cmd');
   var cmd_csave=document.getElementById('edit_csave_cmd');
   var cmd_new  =document.getElementById('edit_new_cmd');
   var cmd_save =document.getElementById('edit_save_cmd');
   //---
   var admin_date_create      =document.getElementById('admin_date_create');
   var admin_date_modify      =document.getElementById('admin_date_modify');
   var admin_label_date_modify=document.getElementById('admin_label_date_modify');
   var admin_not_modify       =document.getElementById('admin_not_modify');
   var admin_label_not_modify =document.getElementById('admin_label_not_modify');
   var admin_author           =document.getElementById('admin_author');
   //---
   if(edit_id)                     { edit_id.value=0;                                                }
   if(obj_subject && data_subject) { data_subject.value='';obj_subject.style.display="none";         }
   if(window.Gimel)                Gimel.SetContent(Gimel.isGecko ? '<br>' : '');
   if(data_file)                   try { data_file.value=''; }catch(e){}
   if(obj_simple && data_simple)   { data_simple.checked=false; obj_simple.style.display="none";     }
   if(cmd_cnew && cmd_csave)       { cmd_cnew.style.display='block'; cmd_csave.style.display='none'; }
   if(cmd_new && cmd_save)         { cmd_new.style.display='none';   cmd_save.style.display='none';  }
   //---
   if(admin_date_create)           { admin_date_create.value='';                                                    }
   if(admin_date_modify)           { admin_date_modify.style.display      ='none';  admin_date_modify.value='';     }
   if(admin_label_date_modify)     { admin_label_date_modify.style.display='none';                                  }
   if(admin_not_modify)            { admin_not_modify.style.display       ='block'; admin_not_modify.checked=false; }
   if(admin_label_not_modify)      { admin_label_not_modify.style.display ='block';                                 }
   if(admin_author)                { admin_author.value='';                                                         }
  }

function quote_forum(id)
  {
   var cmd_csave=document.getElementById('edit_csave_cmd');
   var cmd_save =document.getElementById('edit_save_cmd');
   var is_clear =false;
   //---
   if(!cmd_save || !cmd_csave || cmd_save.style.display=='block' || cmd_csave.style.display=='block') edit_cancel();
   //---
   var obj_content=document.getElementById('content'+id);
   var obj_author =document.getElementById('author_info_'+id);
   //---
   if(!obj_content || !obj_author) return;
   //---
   var content='<strong><span style="color:#42639C;"'+(obj_author.title ? ' title="'+obj_author.title+'"' : '')+'>'+obj_author.innerHTML+'</span> :</strong><br /> '+obj_content.innerHTML;
   //---
   set_content('<div class="fquote">'+content+"</div>\n<p><br></p>",true,false);
   //---
   if(Gimel.isMSIE)  Gimel.SetFocus('content');
   Gimel.ScrollToCursor('content');
  }
//---
function set_content(str,clear_object,is_replace)
  {
   var startPos=0;
   var endPos  =0;
   var valuePos=0;
   var url     ='';
   //---
   if((startPos=str.indexOf('<!--movie:'))>=0)
     {
      var content  ='';
      var movie_str='';
      var pos      =0;
      //---
      do
        {
         content+=str.substring(endPos,startPos);
         //---
         valuePos=str.indexOf('-->',startPos);
         if(valuePos<0) break;
         //---
         endPos=str.indexOf('<!--/movie',startPos);
         if(endPos<0) break;
         //---
         var width =251;
         var height=305;
         //--- get width and height
         movie_str    =str.substr(valuePos+3,endPos);
         movie_str_len=movie_str.length;
         //---
         if((pos=movie_str.indexOf('width="'))>=0)
            width=parseInt(movie_str.substring(pos+7,movie_str_len));
         //---
         if((pos=movie_str.indexOf('height="'))>=0)
            height=parseInt(movie_str.substring(pos+8,movie_str_len));
         //---
         if(!clear_object) content+='<img src="/i/0.gif" id="movie:'+str.substring(startPos+10,valuePos)+'" class="player" width="'+width+'" height="'+height+'">';
         //---
         endPos+=13;
        }
      while((startPos=str.indexOf('<!--movie:',endPos))>=0);
      //---
      if(endPos>=0) content+=str.substring(endPos,str.length);
     }
   else
     {
      content=str;
     }
   //---
   if(is_replace) Gimel.SetContent('content_forum',content, true, true);
   else           {Gimel.InsertContent('content_forum',content, true);}
  }
//---
function getAbsPosition(n)
  {
   var p = {absLeft : 0, absTop : 0};
   //---
   while(n)
     {
      p.absLeft+=n.offsetLeft;
      p.absTop +=n.offsetTop;
      //---
      n = n.offsetParent;
     }
   //---
   return p;
  }
//---
function show_similar(obj,line_count,not_hide)
  {
   if(!obj) return;
   var div_obj=obj.nextSibling;
   if(!div_obj) return;
   //---
   var is_show=(div_obj.style.display!='none');
   //---
   if(!is_show)
     {
      var rep=getAbsPosition(obj);
      //---
      div_obj.style.left=(rep.absLeft-16-(430-obj.offsetWidth))+"px";
      div_obj.style.top =(rep.absTop-(16+line_count*16))+"px";
     }
   //---
   div_obj.style.display=(is_show && !not_hide ? 'none' : 'block');
   obj.style.fontWeight =(is_show && !not_hide ? 'normal' : 'bold');
  }
//---
//----
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 $(id){
   return document.getElementById(id);
}

function AjaxPost(url, params, container){
   http.open("POST", url, true);
   http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   http.setRequestHeader("Content-length", params.length);
   http.setRequestHeader("Connection", "close");
   //---
   http.onreadystatechange = function() {
      // && http.status == 200
      if(http.readyState == 4 && container=='sendproc') 
         {
          //alert(http.responseText);
          if(http.responseText=='success')
            {
             $('container2').style.display='block';
             $('container1').style.display='none';
            }
          else
            {
             $('send_process').style.color='red';
             $('send_process').style.fontWeight='bold';
             $('send_process').innerHTML='';
            }
         }
   }
   http.send(params);
}


function MenuOver(id){
    menu=$(id);
    menu.style.backgroundColor='#D1EBFF';  
    menu=null;
}

function MenuOut(id){
    menu=$(id);
    menu.style.backgroundColor='#FFFFFF'; 
    menu=null;
}

function ShowMenu(){
    var menu=$('lang_menu');
    menu.style.display='block';
    menu=null;
}

function HideMenu(){
    var menu=$('lang_menu');
    menu.style.display='none';
    menu=null;
}

function ChangeMenu(){
    var menu=$('lang_menu');
    menu.style.display=='block' ? HideMenu() : ShowMenu();
    menu.blur();
    menu=null;
}

function ComboBoxOver(){
    var langbox=$('lang');
    langbox.style.borderColor='#9FD8FF';
    langbox=null;
}

function ComboBoxOut(){
    var menu=$('lang_menu');
    if (menu.style.display=='block') 
        {
         menu=null; return false;
        }
    var langbox=$('lang');
    langbox.style.borderColor='#C4E6FF';
    langbox=null;
    menu=null;
}

var product   = 0; // Mobile, CE, Palm
var payment   = 1; // Share-It, WM, RuPay

function ClickTerminal(n)
   {
    product = n;
    generateUrl();
   }

function ClickPayment(n)
   {
    payment = n;
    generateUrl();
   }

function CreateWMForm()
   {
    var wmz_purse ='Z392041188281';
    var wmr_purse ='R632240114525';
    var wmz_amount=45;
    var wmr_amount=1200;
    var mypurse   ='';
    var myamount  =0;
    var myemail   =$('frm2_email').value;
    var myname    =$('frm2_name').value+' '+$('frm2_lastname').value;
    var p         = new Array(300038603, 186801, 177647);
    var d         = new Array('4 Mobile', 'CE', 'for Palm');
    var is_err    =false;
    // сначала все проверяем
    if(!(/^[0-9a-zA-Z]([-_.0-9a-zA-Z])*@[0-9a-zA-Z]([-_.0-9a-zA-Z])*\.[a-zA-Z]{2,4}$/.test(myemail))) 
      {$('frm2_email_label').style.color='red'; is_err=true;}
    else 
      $('frm2_email_label').style.color='black';
    //---
    if(myname==' ')
      {$('frm2_name_label').style.color='red'; is_err=true;}
    else 
      $('frm2_name_label').style.color='black';
    //---
    if(is_err) return false;    
    //---
    // Смотрим, на какой кошелек пользователь делает оплату
    if ($('radiobwmz').checked) {mypurse=wmz_purse; myamount=wmz_amount;}
    else {mypurse=wmr_purse; myamount=wmr_amount;}
    //---
    var html = 
    '<input type="hidden" name="LMI_PAYMENT_AMOUNT" value = "'+myamount+'" />'+
    '<input type="hidden" name="LMI_PAYMENT_DESC"   value = "MetaTrader 4 Mobile Registration Key" />'+
    '<input type="hidden" name="LMI_PAYMENT_NO"     value = "'+p[product]+'" />'+
    '<input type="hidden" name="LMI_PAYEE_PURSE"    value = "'+mypurse+'" />'+
    '<input type="hidden" name="LMI_SIM_MODE"       value = "0" />'+
    '<input type="hidden" name="FIELD_EMAIL"        value = "'+myemail+'" /> '+
    '<input type="hidden" name="FIELD_NAME"         value = "'+myname+'" /> '+
    '<input type="hidden" name="FIELD_LANG"         value = "'+mylang+'" /> '+
    '<input type="hidden" name="FIELD_AMOUNT"       value = "'+myamount+'" /> '+
    '<input type="hidden" name="order_id"           value = "'+p[product]+'" />'+
    '<input type="hidden" name="sum"                value = "5" />';
    $('pl').innerHTML = html;
    return true;
   }

function generateUrl()
  {
   if (product == null || payment == null) return;
   var o = document.getElementById('pform');
   // Share-It
   if (payment == 0)
      {
                              lnum     =1;
       if (mylang=='de')      lnum     =2;
       else if (mylang=='es') lnum     ='4';
       else if (mylang=='ru') lnum     ='12';       
       o.action                        ='http://www.shareit.com/product.html?cart=1&productid=300038603&languageid='+lnum;
       if ($('button_buy'))
         {
          $('button_buy').style.display   ='block';
          $('button_next').style.display  ='none';
         }
      }
   else
   // WebMoney 
   if (payment == 1)
      {
       mylang=='ru' ? o.action ='https://merchant.webmoney.ru/lmi/payment.asp' : o.action ='https://merchant.wmtransfer.com/lmi/payment.asp';
       $('button_buy').style.display   ='none';
       $('button_next').style.display  ='block';       
      }
   else
   // RUPAY
   if (payment == 2)
      {
       var p      = new Array(4444, 7777, 3333);
       var d      = new Array('4 Mobile', 'CE', 'for Palm');
       o.action   ='https://rbkmoney.ru/acceptpurchase.aspx';
       var html   =
       '<input type="hidden" name="eshopId" value="4604">'+
       '<input type="hidden" name="recipientAmount" value="1200.00">'+
       '<input type="hidden" name="serviceName" value="MetaTrader 4 Registration Key">'+
       '<input type="hidden" value="RUR" name="recipientCurrency"/>'+
       '<input type="hidden" name="order_id" value="'+p[product]+'">';
       $('pl').innerHTML               = html;
       $('button_buy').style.display   ='block';
       $('button_next').style.display  ='none';
      }
   }

function wizard(to)
   {
    var cnt=$('wizard_cnt');
    to=='next' ? cnt.value++ : cnt.value--;
    n=cnt.value;
    //---
    if (n==0)
       {
        $('frm1').style.display       ='block';
        $('frm2').style.display       ='none';
        $('wizard_cnt').value         =n;
        $('button_back').style.display='none';
        $('button_next').style.display='block';
        $('button_buy').style.display ='none';      
       }
    else if (n==1)
      {
       // var payment in selection wizard form (Webmoney(1), RuPay(2), ShareIt(0))
       if(payment==1) {$('frm2_wm').style.display='block'; $('frm2_rbk').style.display='none';}
       if(payment==2) {$('pform').submit(); cnt.value--; return false;}
       if(payment==0) {$('pform').submit(); cnt.value--; return false;}
       //---
       $('frm1').style.display       ='none';
       $('frm2').style.display       ='block';
       $('frm3').style.display       ='none';
       $('button_back').style.display='block';
       $('button_buy').style.display ='block';
       $('button_next').style.display='none';
       $('frm2_error').style.display ='none';
      }
    else if (n==2)
      {
       // webmoney
       if (payment==1) 
           if(CreateWMForm()) {$('pform').submit();} else {cnt.value--; n=cnt.value; return false;}
       //---
       DialogWindow.close();
      }
}
function checkForm() 
   {
    var sendproc           =$('send_process');
    var container1         ='container1';
    var fal                =0;
    var err_text           ='';
    //---
    sendproc.style.display ='block';
    sendproc.style.color   ='red';
    sendproc.style.fontWeight='bold';
    //---
    if(document.getElementById('frm_name').value == "" ) {
       fal++;
       err_text='';
       $('t_frm_name').style.color='red';
    }
    else 
      {
       $('t_frm_name').style.color='black';
      }
    //---
    if(document.getElementById('frm_company').value == "" ) {
       fal++;
       $('t_frm_company').style.color='red';
       err_text='';
    }    
    else 
      {
       $('t_frm_company').style.color='black';
      }
    //---
    if(document.getElementById('frm_country').value == "" ) {
       fal++;
       err_text='';
       $('t_frm_country').style.color='red';
    }
    else 
      {
       $('t_frm_country').style.color='black';
      }
    //---
    if(document.getElementById('frm_email').value == "" ) {
       fal++;
       err_text='';
       $('t_frm_email').style.color='red';
    }
    else 
      {
       $('t_frm_email').style.color='black';
      }
    //---
    var dd=document.getElementById('frm_email').value;
    if(!(/^[0-9a-zA-Z]([-_.0-9a-zA-Z])*@[0-9a-zA-Z]([-_.0-9a-zA-Z])*\.[a-zA-Z]{2,4}$/.test(dd))) {
       fal++;
       err_text='';
       $('t_frm_email').style.color='red';
    }
    else 
      {
       $('t_frm_email').style.color='black';
      }
    //---
    if(document.getElementById('frm_phone').value == "" || document.getElementById('frm_phone').value=='+1 123 12345678') {
       fal++;
       err_text='';
       $('t_frm_phone').style.color='red';
    }
    else 
      {
       $('t_frm_phone').style.color='black';
      }
    //---
    if(document.getElementById('frm_text').value == "" ) {
       fal++;
       err_text='';
       $('t_frm_text').style.color='red';
    }
    else 
      {
       $('t_frm_text').style.color='black';
      }
    //---
    if (fal==1) {sendproc.innerHTML=err_text; return false;} 
    if (fal>1)  {sendproc.innerHTML=''; return false;}
    //---
    sendproc.innerHTML        ="<img src='/i/load2.gif' alt='' style='position: relative; top: 3px;' />  &nbsp;";    
    sendproc.style.color      ='black';
    sendproc.style.fontWeight ='normal';
    //---
    AjaxPost
      (
       "/brokers", 
       "lib=mailsend&email="+$('frm_email').value+"&name="+encodeURI($('frm_name').value)+"&address="+encodeURI($('frm_country').value)+"&company="+encodeURI($('frm_company').value)+"&phone="+encodeURI($('frm_phone').value)+"&text="+encodeURI($('frm_text').value),
       "sendproc"
      );
    //---
    return true;
   }

   var loadcountry   =0;
   var countrylist   ="";
   var arrcountry    =new Array();
   var list2         =new Array();
   var mylang;       
   //---
	function LoadCountryesAjaxPost(url, params)
	  {
	   http.open("POST", url, true);
	   http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   http.setRequestHeader("Content-length", params.length);
	   http.setRequestHeader("Connection", "close");
	   //---
	   http.onreadystatechange = function() {
	      if(http.readyState == 4 ) 
	         {
	          countrylist    =http.responseText;
		       var mylist     =$('frm_country');
		       arrcountry     =countrylist.split("\r\n");
		       //alert(arrcountry);
		       //---
		       //mylist.options[0]=null;
		       //mylist.options[0]=null;
		       //---
		       if (arrcountry.length<2) loadcountry=1; 
		       for (i=0; i<arrcountry.length; i++)
		         {
		          if (arrcountry[i]=="") continue;
		          list2=arrcountry[i].split(":");
		          //---
		          if (document.createElement)
		            {
		             var newlist   = document.createElement("OPTION");
		             newlist.text  = list2[1];
		             newlist.value = list2[1];
		             (mylist.options.add) ? mylist.options.add(newlist) : mylist.add(newlist, null);
		             }
		          else
		            {
		             mylist.options[i] = new Option(list2[1], list2[1], false, false);
		            }
		         }
	         }
	   }
	   http.send(params);
	  }
	//---   
   function LoadCountryes(lang)
      {
       if (loadcountry==1) return false;
       //---
       LoadCountryesAjaxPost("/brokers", "lib=loadcountry&lang="+lang);
      }
   //---
var http=false;
/*@cc_on @*/

/*@if (@_jscript_version >= 5)
try {
  http = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
  try {
    http = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (e2) {
    http = false;
  }
}
@end @*/
if (!http && typeof XMLHttpRequest != 'undefined') {http = new XMLHttpRequest();}

var tabs_current='';

function TabsActivate(id)
  {
   TabsShow(tabs_current,true);
   //----
   tabs_current=id;
   TabsShow(id);
  }

function TabsShow(id,hide)
  {
   var obj_page=document.getElementById(id);
   var obj_tab =document.getElementById('tab_'+id);
   //----
   if(!obj_page || !obj_tab) return;
   //----
   obj_page.style.display=(hide ? 'none'       : 'block');
   obj_tab.className     =(hide ? 'dialog_tab' : 'dialog_tab_select');
  }//----
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;
  }
