var d$ = document;
function e$(id){return e$$(d$,id)}
function e$$(e,id){return e.getElementById(id)||null}
function v$(id){return d$.getElementById(id).value}
function t$(e,t){return e.getElementsByTagName(t)}
function a$(e,a){try{return typeof e=='object'?e.getAttribute(a):e$(e).getAttribute(a)}catch(err){}return 0}
function a$$(e,a,v){e.setAttribute(a+(a=='class'&&ua$('ie 7')?'Name':''),v)}
function new$(e,o){var x=d$.createElement(e);if(o)for(k in o)a$$(x,k,o[k]);return x}
function sh$(e,v){typeof e=='object'?e.style.display=v:e$(e).style.display=v}
function s$(e){sh$(e,'block')}
function h$(e){sh$(e,'none')}
function ua$(t){return navigator.userAgent.toLowerCase().indexOf(t)>-1}
function ce$(p,t,v){var e=d$.createElement(t);v=v||'';if(null==e.canHaveChildren||e.canHaveChildren)e.appendChild(d$.createTextNode(v));else e.text=v;p.appendChild(e);return e}
function rand$(a,b){var r=Math.random();if(typeof a=="undefined")return r;if(typeof b=="undefined"){b=a;a=0}return a+Math.floor(r*(b-a+1))}
function event$(e){return(e&&e.target)||(event&&event.srcElement)}
function nextsibling$(e){do{e=e.nextSibling}while(e&&e.nodeType!=1);return e}
function addclass$(o,c){var re=new RegExp("(^|\\s)"+c+"(\\s|$)","g");if(re.test(o.className))return;o.className=(o.className+" "+c).replace(/\s+/g," ").replace(/(^ | $)/g, "")}
function removeclass$(o,c){var re=new RegExp("(^|\\s)"+c+"(\\s|$)","g");o.className=o.className.replace(re, "$1").replace(/\s+/g, " ").replace(/(^ | $)/g, "")}
function addOption$(selectObj,text,value,isSelected){if(selectObj!=null&&selectObj.options!=null)selectObj.options[selectObj.options.length]=new Option(text,value,false,isSelected)}
function in_array$(v,a,s){var k='',ss=!!s;if(ss)for(k in a){if(a[k]===v)return true}else for(k in a)if(a[k]==v)return true;return false;}
function email$(s){return s.match(/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/)}

function get_radio_value(o)
{ for(var i=0,n=o.length;i<n;i++)if(o[i].checked)return o[i].value;
  return null;
}

function add_event(e, event, f){if(e.attachEvent)e.attachEvent("on"+event,f);else if(e.addEventListener)e.addEventListener(event,f,true);else e["on"+event]=f}
function remove_event(e, event, f){if(e.detachEvent)e.detachEvent("on"+event,f);else if(e.removeEventListener)e.removeEventListener(event,f,true);else e["on"+event]=null}

function sajax_init_object()
{ if(window.XMLHttpRequest)return new XMLHttpRequest();
  else
  { if(window.ActiveXObject)
    { if(ua$("msie 5"))return new ActiveXObject("Microsoft.XMLHTTP");
      else return new ActiveXObject("MSXML2.XMLHTTP");
    }
    else return null;
  }
}

function sajax_do_call(args) 
{ var i, x, n;
  var uri = "index.php";
  var post_data;  
 
  post_data=[];
  for(i=0;i<args.length-1;i++)post_data.push('args[]='+encodeURIComponent(args[i]));
  post_data = post_data.join('&');
  x=sajax_init_object();
  if(x==null)
  { return false;
  } 
  else
  { x.open("POST", uri, true);
    x.setRequestHeader("Method", "POST "+uri+" HTTP/1.1");
    x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    x.onreadystatechange=function()
    { if(x.readyState!=4)return;
      var data = x.responseText;
      try 
      { var callback = args[args.length-1];
	callback(data, false);
      } 
      catch(e){}
    }
  }  
  x.send(post_data);
  delete x;
  return true;
}

function sajax(){sajax_do_call(sajax.arguments)}

function setcookie$(name,value,days)
{ if(days)
  { var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = '; expires='+date.toGMTString();
  }
  else var expires = '';

  document.cookie = name+'='+value+expires+'; path=/';
}

function getcookie$(name)
{ var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i<ca.length;i++)
  { var c = ca[i];
    while(c.charAt(0)==' ')c=c.substring(1,c.length);
    if(c.indexOf(nameEQ)==0)return c.substring(nameEQ.length,c.length);
  }
  return null;
}

function delcookie$(name)
{ setcookie$(name,"",-1);
}

function bindReady(handler)
{ var called = false
  
  function ready()
  { if(called)return;
    called = true;
    handler()
  }

  if(document.addEventListener)
  { document.addEventListener("DOMContentLoaded", function(){document.removeEventListener("DOMContentLoaded", arguments.callee, false);ready()}, false)
  }
  else if(document.attachEvent)
  { if(document.documentElement.doScroll&&window==window.top)
    { function tryScroll()
      { if(called)return;
        try
        { document.documentElement.doScroll("left");
          ready()
        }
        catch(e)
        { setTimeout(tryScroll, 18)
        }
      }
      tryScroll()
    }
    
    document.attachEvent("onreadystatechange", function()
    { if(document.readyState==="complete")
      { document.detachEvent("onreadystatechange", arguments.callee);
        ready()
      }
    })
  }

  if(window.addEventListener){window.addEventListener('load', ready, false);}
  else if(window.attachEvent)window.attachEvent('onload', ready);
}

var readyList = [];
function onready$(handler)
{ if(!readyList.length)
  { bindReady(function(){for(var i=0;i<readyList.length;i++)readyList[i]()})
  }
  readyList.push(handler)
}


function onResizeWindow(){var h=d$.documentElement.clientHeight,hh=ua$('ie 7')?e$('content-wrap').offsetHeight:e$('content-wrap').clientHeight,x=e$('vspace'),dh=h-hh-256-1;x.style.height=(dh>0?dh:0)+'px'}

var slider;
function initSys()
{ if(e$('gspoiler-news')){new gspoiler$('gspoiler-news',{h3:'div'})}
  new img$();
  onResizeWindow();
  setInterval(onResizeWindow,250);
}
add_event(window,"load",initSys);
onready$(onResizeWindow);
onready$(map_europe);
onready$(function(){if(e$('up')){var dh=(window.innerHeight||d$.documentElement.clientHeight),ch=d$.body.clientHeight,h=ch/dh;if(h>1.75)s$('up')}});

/*============================================*/
function gspoiler$(id,o)
{ var sender=this;
  this.ul=e$(id),this.id=id,this.li=[],this.v={interval:20,k:-1,h3:'h3',id_prefix:'vmi',f:0},this.n=0;

  this.init=function(o)
  { for(s in o)this.v[s]=o[s];
    for(var i=0,j=0,li=t$(this.ul,'li'),n=li.length;i<n;i++)
    { if(li[i].parentNode==this.ul&&(h3=t$(li[i],this.v.h3)[0])&&h3.nextSibling!=null&&(x=nextsibling$(h3))&&(id=this.v.id_prefix+j++))
      { h3.onclick=function(){sender.pr(parseInt(a$(this,'id_spoiler').substr(sender.v.id_prefix.length)))}
        a$$(h3,'id_spoiler',id);a$$(x,'id',id);this.li.push(li[i]);
      }
    }
    this.n=this.li.length;
    if(!this.n)return;
    if(k=a$(this.ul,'open'))this.v.k=parseInt(k);
    if(this.v.k>=0)this.pr(this.v.k);
  }
  this.pr=function(k)
  { for(var i=0;i<this.n;i++)
    { spoiler$(this.v.id_prefix+i,{d:k==i?1:0});
      if(this.v.f)this.v.f(e$(this.v.id_prefix+i),k==i?1:0);
    }
  }
  this.init(o||{});
}

function spoiler$(e,o)
{ var e = typeof e=='object'?e:e$(e);
  if(!e)return;
  s$(e);
  var h=e.style.height,sh;e.style.height='auto';sh=e.offsetHeight;e.style.height=h;
  var oh=e.offsetHeight; sh=sh=='auto'?0:parseInt(sh);
  o=o||{};
  if(oh==0||oh>=sh)
  { var c=oh, r=typeof o.d=='undefined'?(oh<sh?sh:0):(o.d?sh:0);
    var t = setInterval(function() 
    { var n=Math.ceil((c*1.5+r*0.5)*0.5);
      if(n==c)n=r;
      c=n;
      e.style.height=c<sh?c+'px':'';
      if(c==r)
      { clearInterval(t);
        if(!c)h$(e);
        if(o.onsuccess)o.onsuccess();
      }
    }, 25);
  }
  return false;
}

var map={};
function map_europe()
{ if(!e$('map'))return;
  var svg = new Raphael('map',595,385);
  for(var x in europe_svg)
  { var path=europe_svg[x];
    if(path.length)
    { var z=svg.path(path);
      z.attr({"stroke-width":"0.5px", "stroke":"#7baede", "fill":x=='Kazahstan'?"#ffffff":"#9d1d50", "fill-opacity":0.01});
      z.country=x;
      z.toBack();
      
      var st=svg.set();
      st.push(z);
      map[x]=st;
      
      map[x].hover(
        function()
        { map_europe_hover(this,1);
          e$('brand').innerHTML='';
          onResizeWindow()
        },
        function()
        { if(e$('tcountry-'+this.country))
          { var e=this;
            this.timer=setInterval(function(){map_europe_hover(e,0)},100);
          }
          else map_europe_hover(this,0);
        }
      );
    }
  }
}

function map_europe_hover(o,d)
{ clearInterval(o.timer);
  if(d)
  { o.animate({'fill-opacity':1},100);
    o.attr({'cursor':'pointer', 'stroke-width':'0.5px', 'stroke':'#7baede'});
    if(e$('tcountry-'+o.country))s$('tcountry-'+o.country);
    if(b=country_brand[o.country])
    { for(var i=0,n=b.length;i<n;i++)
      { if(x=e$('brand'+b[i])){addclass$(x,'s');a$$(x,'country',o.country)}
      }
    }
  }
  else
  { o.animate({'fill-opacity':0.01},100);
    o.attr({'cursor':'pointer', 'stroke-width':'0.5px', 'stroke':'#7baede'});
    if(e$('tcountry-'+o.country))h$('tcountry-'+o.country);
    if(b=country_brand[o.country])
    { for(var i=0,n=b.length;i<n;i++)
      { if((x=e$('brand'+b[i]))&&a$(x,'country')==o.country){removeclass$(e$('brand'+b[i]),'s');a$$(x,'country','')}
      }
    }
  }
}

function brand_hover(o,d)
{ var c=e$('x'+o.id).innerHTML;
  if(c.length)
  { if(x=e$('i'+o.id))
    { if(d)e$('brand').innerHTML=x.innerHTML;else e$('brand').innerHTML='';
    }
    onResizeWindow();
    c=jQuery.parseJSON(c);
    for(var i=0,n=c.length;i<n;i++)
    { var x=c[i];
      map[x].animate({'fill-opacity':(d?1:0.01)},100);
      if(d)s$('tcountry-'+x);else h$('tcountry-'+x);
    }
  }
}



function img$(o)
{ var sender=this;
  this.wnd=null,this.x={},this.arrow={width:38,height:48},this.current={g:'',k:''}

  this.init=function(o)
  { this.v={tag:'img',rel:'gallery',array:[],bclose:1};
    for(s in o)this.v[s]=o[s];
    if(!this.v.array.length)
    { for(var i=0,k=0,j=0,a=t$(d$,this.v.tag),n=a.length;i<n;i++)
      { if((z=a$(a[i],'rel'))&&(z=z.match('^'+this.v.rel+'\\[([a-zA-Z0-9]+)\\]|'+this.v.rel+'$')))
        { if(!(z=z[1]))z='single'+j++;
          if(!this.x[z])this.x[z]=[];
          k=this.x[z].length;
          this.x[z].push({src:a$(a[i],'href'),title:a$(a[i],'title'),g:z,k:k});
          a[i].k=k;a[i].g=z;
          add_event(a[i],"click",this.showimg);
        }
      }
      this.wnd=new wnd$({show:0});
    }
    else
    { var z='dynamic';this.x[z]=[];
      for(var i=0,a=this.v.array,n=a.length;i<n;i++){this.x[z].push({src:a[i].src,title:a[i].title,g:z,k:i})}
      this.wnd=new wnd$({show:0});sender.show(sender.x[z][0])
    }
  }
  this.showimg=function(e){var img=event$(e);sender.show(sender.x[img.g][img.k])}
  this.move=function(d){var k=sender.current.k+d,g=sender.current.g,n=sender.x[g].length;if(k+1>n)k=0;else if(k<0)k=n-1;sender.show(sender.x[g][k])}
  this.show=function(o)
  { if(sender.current.g=='')sender.wnd.show({html:'',bclose:sender.v.bclose,onclose:function(){sender.hide()},tpl:'empty'});else sender.wnd.fill('');
    var g=o.g,k=parseInt(o.k),x=new$('div',{'class':'wnd_gallery'}),img_box=new$('div'),img_prev=new$('img',{'src':'images/wnd-left.gif','class':'arrow'}),img_next=new$('img',{'src':'images/wnd-right.gif','class':'arrow'}),title=new$('div',{'class':'wnd_title'});
    add_event(img_next,"click",function(){sender.move(1)});add_event(img_prev,"click",function(){sender.move(-1)});
    var i=new Image();i.className='wnd_img';
    i.onload=function(){img_box.style.width=i.width+'px';img_box.style.height=i.height+'px';img_prev.style.marginTop=img_next.style.marginTop=Math.round((i.height/2-sender.arrow.height/2))+'px';img_next.style.marginLeft=i.width-sender.arrow.width+'px';sender.wnd.fill(x)}
    i.src=sender.x[g][k].src;
    sender.current.g=g;sender.current.k=k;
    img_box.appendChild(i);if(sender.x[g].length>1){img_box.appendChild(img_prev);img_box.appendChild(img_next)}x.appendChild(img_box);
    if((t=sender.x[g][k].title)&&t.length){title.innerHTML=t;x.appendChild(title)}
  }
  this.hide=function(){sender.current={g:'',k:''}}
  this.init(o||{});
}


function fade$(e,v)
{ e = typeof e=='object'?e:e$(e);clearInterval(e.si);v=v||{};
  e.v={k:1,o:100,onsuccess:0,timer:18,x:0.18};
  for(s in v)e.v[s]=v[s];
  if(e.v.k)s$(e);
  e.v.o=e.v.k?e.v.o:0;e.k=e.v.k||-1;e.alpha=e.style.opacity?parseFloat(e.style.opacity)*100:0;e.si=setInterval(function(){e.tween()},e.v.timer);
  e.tween=function()
  { if(Math.abs(e.alpha-e.v.o)<2){clearInterval(e.si);if(!e.v.k)h$(e);if(e.v.onsuccess)e.v.onsuccess()}
    else{var d=Math.round((e.v.o-e.alpha)*e.v.x),dd=Math.abs(d),value=Math.round(e.alpha+d)+((dd<2?2:1)*e.k);e.style.opacity=value/100;e.style.filter='alpha(opacity='+value+')';e.alpha=value}
  }
}


function wnd$(o)
{ var sender=this;
  this.v,this.m,this.b,this.c,this.bclose,this.bg,this.id,this.timer;
  if(typeof wnd$.zIndex=='undefined')wnd$.zIndex=10000;

  this.show=function(o)
  { this.v={opacity:70,fixed:0,topsplit:2,height:0,width:0,sajax:0,html_id:0,html:0,bg:0,tpl:'default',mask:1,show:1,onclose:null,onsajax:null,w:84,h:84,bclose:0};
    for(s in o)this.v[s]=o[s];
    if(!this.v.show)return;
    this.id=rand$(1,9999);
    this.m=new$('div',{'id':'mask'+this.id,'class':'wnd_mask'});this.m.style.zIndex=wnd$.zIndex++;
    this.b=new$('div',{'id':'inner'+this.id,'class':'wnd_inner'});this.b.style.zIndex=wnd$.zIndex++;
    this.c=new$('div',{'class':'wnd_content'});this.c.style.zIndex=wnd$.zIndex++;
    this.bg=new$('div',{'class':'wnd_preload_bg'});this.bg.style.zIndex=wnd$.zIndex++;
    this.bclose=new$('div',{'class':'wnd_close'});this.bclose.style.zIndex=wnd$.zIndex++;
    d$.body.appendChild(this.m);
    d$.body.appendChild(this.b);
    this.b.appendChild(this.c);
    this.b.appendChild(this.bg);
    this.b.appendChild(this.bclose);
    if(this.v.bg)this.b.style.background=this.v.bg;
    if(this.v.bclose)s$(this.bclose);
    if(this.v.html)this.fill(this.v.html);
    else if(this.v.html_id)this.fill(e$(this.v.html_id).innerHTML);
    
    if(this.v.mask)fade$(this.m.id,{o:this.v.opacity});
    fade$(this.b.id);

    add_event(this.m,"click",function(){sender.hide()});
    add_event(this.bclose,"click",function(){sender.hide()});
    add_event(window,"resize",function(){sender.mask()});
    
    if(this.v.sajax)this.sajax(this.v.sajax)
  }
  this.hide=function(){if(this.v.onclose)this.v.onclose();fade$(this.m,{k:0,onsuccess:function(){sender.m.innerHTML=''}});fade$(this.b,{k:0,onsuccess:function(){sender.b.innerHTML=''}})}
  this.fill=function(r){s$(this.bg);this.c.innerHTML=this.tpl[this.v.tpl];if(typeof r=='object'){this.c.firstChild.appendChild(r)}else{this.c.firstChild.innerHTML=r};h$(this.c);sender.mask()}
  this.mask=function(){this.m.style.height=this.total(1)+'px'; this.b.style.width=this.v.w+'px'; this.b.style.height=this.v.h+'px';this.update_bg();fade$(this.c,{k:0,onsuccess:function(){sender.size()}})}
  this.onsajax=function(r){if(this.v.onsajax)this.v.onsajax(this,r);else this.fill(r)}
  this.sajax=function(a)
  { this.fill(this.tpl.sajax_preload);
    var p=[];for(var i=0;i<a.length;i++)p.push('args[]='+encodeURIComponent(a[i]));p=p.join('&');
    var x=sajax_init_object();
    if(x==null)return false;
    else
    { x.wnd=this;
      x.open("POST", "index.php", true);x.setRequestHeader("Method", "POST index.php HTTP/1.1");x.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
      x.onreadystatechange=function(){if(x.readyState!=4)return;x.wnd.onsajax(x.responseText)}
    }  
    x.send(p);
    delete x;
    return true;
  }
  this.pos=function()
  { var t;
    if(typeof this.v.top!='undefined'){t=this.v.top}else{t=(this.height()/this.v.topsplit)-(this.b.offsetHeight/2); t=t<20?20:t}
    if(!this.v.fixed&&!this.v.top){t+=this.top()}
    this.b.style.top=t+'px'; 
    this.b.style.left=typeof this.v.left!='undefined'?this.v.left+'px':(this.width()/2)-(this.b.offsetWidth/2)+'px'
  }
  this.top=function(){return d$.documentElement.scrollTop||d$.body.scrollTop}
  this.width=function(){return self.innerWidth||d$.documentElement.clientWidth||d$.body.clientWidth}
  this.height=function(){return self.innerHeight||d$.documentElement.clientHeight||d$.body.clientHeight}
  this.total=function(d){var b=d$.body,e=d$.documentElement;return d?Math.max(Math.max(b.scrollHeight,e.scrollHeight),Math.max(b.clientHeight,e.clientHeight)):Math.max(e.clientWidth,b.scrollWidth)}
  this.tpl={'default':'<div class="wnd_default"></div>','preload':'<div class="wnd_preload"></div>','sajax_preload':'<div class="wnd_sajax_preload"></div>','empty':'<div></div>'}
  this.size=function()
  { clearInterval(this.timer);s$(this.c);
    this.c.style.width=this.v.width?this.v.width+'px':'auto';
    this.c.style.height=this.v.height?this.v.height+'px':'auto';
    var w=this.c.offsetWidth,wd=w>parseInt(this.b.style.width)?1:-1,h=this.c.offsetHeight,hd=h>parseInt(this.b.style.height)?1:-1;
    h$(this.c);sender.timer=setInterval(function(){sender.ts(w,wd,h,hd)},20)
  }
  this.ts=function(w,wd,h,hd)
  { var cw=parseInt(this.b.style.width), ch=parseInt(this.b.style.height);
    if(cw==w&&ch==h){clearInterval(this.timer);this.v.w=w;this.v.h=h;this.timer=setInterval(function(){sender.show_content()},50)}
    if(cw!=w){this.b.style.width=(w-Math.floor(Math.abs(w-cw)*.6)*wd)+'px'}
    if(ch!=h){this.b.style.height=(h-Math.floor(Math.abs(h-ch)*.6)*hd)+'px'}
    this.update_bg();
    this.pos()
  }
  this.update_bg=function(){var x=this.b.style;this.bg.style.width=parseInt(x.width)-4+'px';this.bg.style.height=parseInt(x.height)-4+'px'}
  this.show_content=function(){clearInterval(this.timer);fade$(this.c);this.b.className='wnd_inner';h$(this.bg)}
  this.show(o||{});
}


function calendar$(ids,o)
{ var sender=this;
  this.input=e$(ids.input);if(!ids.block)ids.block='ico_'+ids.input;this.id_block=ids.block;this.ico;this.visible=0;

  if(typeof calendar$.idx=='undefined')
  { calendar$.idx=[];
    //add_event(window,"scroll",function(){calendar$.hideAll()});
    calendar$.lang=
      calendar_local!='undefined'
      ?calendar_local
      :{'months':['January','February','March','April','May','June','July','August','September','October','November','December'],
       'weekdays':['Su','Mo','Tu','We','Th','Fr','Sa'],
       'prevY':'Previous Year',
       'nextY':'Next Year',
       'prevM':'Previous Month',
       'nextM':'Next Month',
       'invalidDay':'Invalid day of month value: "#n_day#".\nAllowed range for selected month is 01 - #d_numdays#.',
       'invalidMonth':'Invalid month value: "#n_month#".\nAllowed range is 01-12.',
       'invalidYear':'Invalid date: "#s_date#".\nAccepted format is dd.mm.yyyy.'
      }
  }
  calendar$.idx.push(sender);
  this.index=calendar$.idx.length-1;

  this.init=function(o)
  { this.v={'yearscroll':1,'weekstart':1,'centyear':70,'imgpath':'images/calendar/'};
    for(s in o)this.v[s]=o[s];
    this.ico=ce$(e$(this.id_block),'img');
    this.ico.src=this.v.imgpath+'cal.gif';
    this.ico.className='tcalIcon';

    add_event(this.ico,"click",function(){sender.visible?sender.hide():sender.show()});
  }
  this.show=function()
  { this.e_div = ce$(d$.body,'div');
    this.e_div.className = 'tcal';

    this.e_shade = ce$(d$.body,'div');
    this.e_shade.className = 'tcalShade';

    this.hideAll();

    if(!this.update())return;

    this.e_div.style.visibility = 'visible';
    this.e_shade.style.visibility = 'visible';

    this.ico.src = this.v.imgpath+'no_cal.gif';
    this.ico.title = 'Close Calendar';
    this.visible = 1;
  }
  this.hide=function(n_date)
  { if(n_date)this.input.value=this.generDate(new Date(n_date));
    if(!this.visible)return;
    if(this.e_shade)this.e_shade.style.visibility='hidden';
    this.e_div.style.visibility = 'hidden';
    this.ico.src = this.v.imgpath+'cal.gif';
    this.ico.title = 'Open Calendar';
    this.visible = false;
  }
  this.update=function(d_date)
  { var d_today = this.resetTime(new Date());
    var d_selected = this.input.value==''?d_today:this.parseDate(this.input.value);
    if(!d_date)d_date=d_selected;
    else if(typeof(d_date)=='number')d_date=this.resetTime(new Date(d_date));
    else if(typeof(d_date)=='string')this.parseDate(d_date);

    if(!d_date)return false;

    var d_firstday = new Date(d_date);
    d_firstday.setDate(1);
    d_firstday.setDate(1-(7+d_firstday.getDay()-this.v.weekstart)%7);

    var a_class, s_html = '<table class="ctrl"><tbody><tr>'
		+ (this.v.yearscroll?'<td'+this.relDate(d_date,-1,'y')+' title="'+calendar$.lang.prevY+'"><img src="'+this.v.imgpath+'prev_year.gif" /></td>':'')
		+ '<td'+this.relDate(d_date, -1)+' title="'+calendar$.lang.prevM+'"><img src="'+this.v.imgpath+'prev_mon.gif" /></td><th>'
		+ calendar$.lang.months[d_date.getMonth()]+' '+ d_date.getFullYear()
			+'</th><td'+this.relDate(d_date, 1)+' title="'+calendar$.lang.nextM+'"><img src="'+this.v.imgpath+'next_mon.gif" /></td>'
		+ (this.v.yearscroll?'<td'+this.relDate(d_date, 1, 'y')+' title="'+calendar$.lang.nextY+'"><img src="'+this.v.imgpath+'next_year.gif" /></td></td>':'')
		+ '</tr></tbody></table><table><tbody><tr>';


    for(var i=0;i<7;i++)s_html+='<th>'+calendar$.lang.weekdays[(this.v.weekstart+i)%7]+'</th>';
    s_html+='</tr>' ;

    var n_date, n_month, d_current = new Date(d_firstday);
    while(d_current.getMonth()==d_date.getMonth()||d_current.getMonth()==d_firstday.getMonth())
    { s_html +='<tr>';
      for(var n_wday=0;n_wday<7;n_wday++)
      { a_class = [];
        n_date = d_current.getDate();
        n_month = d_current.getMonth();
        if(d_current.getMonth()!=d_date.getMonth())a_class[a_class.length] = 'othermonth';
        if(d_current.getDay()==0||d_current.getDay()==6)a_class[a_class.length] = 'weekend';
        if(d_current.valueOf()==d_today.valueOf())a_class[a_class.length] = 'today';
        if(d_current.valueOf()==d_selected.valueOf())a_class[a_class.length] = 'selected';
        s_html+='<td onclick="calendar$.idx[\''+this.index+'\'].hide('+d_current.valueOf()+')"'+(a_class.length?' class="'+a_class.join(' ')+'">':'>')+n_date+'</td>'

        d_current.setDate(++n_date);
        while(d_current.getDate()!= n_date&&d_current.getMonth()==n_month)
        { d_current.setHours(d_current.getHours + 1);
          d_current = f_tcalResetTime(d_current);
        }
      }
      s_html +='</tr>';
    }
    s_html +='</tbody></table>';
	
    this.e_div.innerHTML = s_html;

    var n_width  = this.e_div.offsetWidth;
    var n_height = this.e_div.offsetHeight;
    var n_top  = this.getPosition(this.ico,'Top')+this.ico.offsetHeight;
    var n_left = this.getPosition(this.ico,'Left')-n_width+ this.ico.offsetWidth;
    if(n_left<0)n_left=0;

    this.e_div.style.left = n_left+'px';
    this.e_div.style.top  = n_top+'px';

    this.e_shade.style.width = (n_width+8)+'px';
    this.e_shade.style.left = (n_left-1)+'px';
    this.e_shade.style.top = (n_top-1)+'px';
    this.e_shade.innerHTML = '<table><tbody><tr><td rowspan="2" width="6"><img src="'+this.v.imgpath+'pixel.gif"></td><td rowspan="2"><img src="'+this.v.imgpath+'pixel.gif"></td><td width="7" height="7"><img src="'+this.v.imgpath+'shade_tr.png"></td></tr><tr><td background="'+this.v.imgpath+'shade_mr.png" height="'+(n_height-7)+'"><img src="' + this.v.imgpath+'pixel.gif"></td></tr><tr><td><img src="'+this.v.imgpath+'shade_bl.png"></td><td background="'+this.v.imgpath+'shade_bm.png" height="7" align="left"><img src="'+this.v.imgpath+'pixel.gif"></td><td><img src="'+this.v.imgpath+'shade_br.png"></td></tr><tbody></table>';
    return true;
  }
  this.parseDate=function(s_date)
  { var re_date = /^\s*(\d{1,2})\.(\d{1,2})\.(\d{2,4})\s*$/;
    if(!re_date.exec(s_date))return alert(calendar$.lang.invalidYear.replace('#s_date#',s_date));
    var n_day = Number(RegExp.$1),
    n_month = Number(RegExp.$2),
    n_year = Number(RegExp.$3);
    if(n_year<100)n_year+=(n_year<this.v.centyear?2000:1900);
    if(n_month<1||n_month>12)return alert(calendar$.lang.invalidMonth.replace('#n_month#',n_month));
    var d_numdays = new Date(n_year, n_month, 0);
    if(n_day>d_numdays.getDate())return alert(calendar$.lang.invalidDay.replace('#n_day#',n_day).replace('#d_numdays#',d_numdays.getDate()));
    return new Date (n_year, n_month - 1, n_day);
  }
  this.resetTime=function(d_date){d_date.setHours(0);d_date.setMinutes(0);d_date.setSeconds(0);d_date.setMilliseconds(0);return d_date}
  this.hideAll=function(){for(var i=0,n=calendar$.idx.length;i<n;i++)calendar$.idx[i].hide()}
  this.generDate=function(d_date){return ((d_date.getDate()<10?'0':'')+d_date.getDate()+'.'+(d_date.getMonth()<9?'0':'')+(d_date.getMonth()+1)+'.'+d_date.getFullYear())}
  this.relDate=function(d_date, d_diff, s_units)
  { var s_units = (s_units=='y'?'FullYear':'Month');
    var d_result = new Date(d_date);
    d_result['set' + s_units](d_date['get'+s_units]()+d_diff);
    if(d_result.getDate()!= d_date.getDate())d_result.setDate(0);
    return ' onclick="calendar$.idx[\''+this.index+'\'].update('+d_result.valueOf()+')"';
  }
  this.getPosition=function(e_elemRef, s_coord)
  { var n_pos=0,n_offset,e_elem=e_elemRef;
    while(e_elem)
    { n_offset = e_elem["offset" + s_coord];
      n_pos += n_offset;
      e_elem = e_elem.offsetParent;
    }
    e_elem = e_elemRef;
    while(e_elem!=document.body)
    { n_offset = e_elem["scroll" + s_coord];
      if(n_offset&&e_elem.style.overflow=='scroll')n_pos-=n_offset;
      e_elem = e_elem.parentNode;
    }
    return n_pos;
  }

  this.init(o||{});
}

/* form validator */
var MSGTIMER = 20;
var MSGSPEED = 5;
var MSGOFFSET = 3;
var MSGHIDE = 3;

function inlineMsg(target,string,autohide) {
  var msg;
  var msgcontent;
  if(!document.getElementById('tt2msg')) {
    msg = document.createElement('div');
    msg.id = 'tt2msg';
    msgcontent = document.createElement('div');
    msgcontent.id = 'msgcontent';
    document.body.appendChild(msg);
    msg.appendChild(msgcontent);
    msg.style.filter = 'alpha(opacity=0)';
    msg.style.opacity = 0;
    msg.alpha = 0;
  } else {
    msg = document.getElementById('tt2msg');
    msgcontent = document.getElementById('msgcontent');
  }
  msgcontent.innerHTML = string;
  msg.style.display = 'block';
  var msgheight = msg.offsetHeight;
  var targetdiv = document.getElementById(target);
  targetdiv.focus();
  var targetheight = targetdiv.offsetHeight;
  var targetwidth = targetdiv.offsetWidth;
  var topposition = topPosition(targetdiv) - ((msgheight - targetheight) / 2);
  var leftposition = leftPosition(targetdiv) + targetwidth + MSGOFFSET;
  msg.style.top = topposition + 'px';
  msg.style.left = leftposition + 'px';
  clearInterval(msg.timer);
  msg.timer = setInterval("fadeMsg(1)", MSGTIMER);
  if(!autohide) {
    autohide = MSGHIDE;  
  }
  window.setTimeout("hideMsg()", (autohide * 1000));
}

function hideMsg(msg) {
  var msg = document.getElementById('tt2msg');
  if(!msg.timer) {
    msg.timer = setInterval("fadeMsg(0)", MSGTIMER);
  }
}

function fadeMsg(flag) {
  if(flag == null) {
    flag = 1;
  }
  var msg = document.getElementById('tt2msg');
  var value;
  if(flag == 1) {
    value = msg.alpha + MSGSPEED;
  } else {
    value = msg.alpha - MSGSPEED;
  }
  msg.alpha = value;
  msg.style.opacity = (value / 100);
  msg.style.filter = 'alpha(opacity=' + value + ')';
  if(value >= 99) {
    clearInterval(msg.timer);
    msg.timer = null;
  } else if(value <= 1) {
    msg.style.display = "none";
    clearInterval(msg.timer);
  }
}

function leftPosition(target) {
  var left = 0;
  if(target.offsetParent) {
    while(1) {
      left += target.offsetLeft;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.x) {
    left += target.x;
  }
  return left;
}

function topPosition(target) {
  var top = 0;
  if(target.offsetParent) {
    while(1) {
      top += target.offsetTop;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.y) {
    top += target.y;
  }
  return top;
}
/* end form validator */

