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')||ua$('ie 6'))?'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 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 addOption$(selectObj,text,value,isSelected){if(selectObj!=null&&selectObj.options!=null)selectObj.options[selectObj.options.length]=new Option(text,value,false,isSelected)}

function add_event(element, event_name, func)
{ if(element.attachEvent)element.attachEvent("on" + event_name, func);
  else if(element.addEventListener)element.addEventListener(event_name, func, true);
  else element["on" + event_name] = func;
}

function remove_event(element, event_name, func)
{ if(element.detachEvent)element.detachEvent("on" + event_name, func);
  else if(element.removeEventListener)element.removeEventListener(event_name, func, true);
  else element["on" + event_name] = 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)}



var wnd, slider;
function initSys()
{ if(e$('slider'))
  { slider = new hslider$('slider',{cv:4,auto:1});
    add_event(e$('slider-left'),'click',function(){slider.move(-1)});
    add_event(e$('slider-right'),'click',function(){slider.move(1)});
  }
}
add_event(window,"load",initSys);

/*============================================*/
function add2cart()
{ var k=get_current_item(), p=[];
  for(var i=0;i<params_m;i++)p.push(items[k][i+9]);
  var i=v$('quantity');if(!i){i=1;e$('quantity').value=1}
  if(items[k][7])sajax('order','x_add2cart',e$('name-product').innerHTML,i,items[k][1],items[k][0],items[k][2],items[k][6],p.join('<br />'),productId,function(r){r=r.split('@');e$('cart').innerHTML=r[0];location.href='/order?ext=back-to-shop';/*wnd=new wnd$({html:r[1],onclose:function(){location.href='/order?ext=back-to-shop'}})*/})
}

function del_product(pid)
{ sajax('order','x_del_product',pid,function(r){r=r.split('@');if(r[2]>0){e$('cart').innerHTML=r[0];e$('order-products').innerHTML=r[1]}else{e$('cart').innerHTML=r[3];location.reload()/*wnd=new wnd$({html:r[4],onclose:function(){location.reload()}})*/}})
}

function uop()
{ var p=[],v=[],e=e$('fop').elements;
  for(var i=0,n=e.length;i<n;i++)
  { v.push(e[i].value==''?'':e[i].value);
    p.push(a$(e[i],'pid'));
  }
  sajax('order','x_update_products',p.join(','),v.join(','),function(r){r=r.split('@');e$('cart').innerHTML=r[0];e$('order-products').innerHTML=r[1]})
}

function update_params()
{ if(params_m)
  { var l=9,v,vv=null,s=[],c={},k=0;
    for(var i=0,n=items.length;i<n;i++)c[items[i][0]]=i;
    images_k = 0;
    for(var j=0;j<params_m;j++)
    { s[j] = [];
      v = v$('param'+j);
      while(e$('param'+j).options.length>0)e$('param'+j).options.remove(0);
      s$('param'+j);
      for(g in c)
      { var i = c[g];
        if(items[i][l+j]!=''&&((j&&items[i][l+j-1]==vv&&!in_array$(items[i][l+j],s[j])) || (!j&&!in_array$(items[i][l+j],s[j]))))
        { s[j].push(items[i][l+j]);
        }
        if(!in_array$(items[i][l+j],s[j]))delete(c[g]);
      }
      s[j].sort();
      for(var i in s[j])addOption$(e$('param'+j), s[j][i], s[j][i], s[j][i]==v);
      if(!e$('param'+j).options.length)h$('param'+j);
      vv=!in_array$(v,s[j])?s[j][0]:v;
    }
    
    k = get_current_item();
    
    var x = items[k];
    e$('art_no').innerHTML = x[1];
    e$('oldPrice').innerHTML = Math.ceil(parseFloat(x[3])*eu).toFixed(2)+' '+grn+' / '+x[3]+' &euro;';
    e$('newPrice').innerHTML = e$('itemPrice').innerHTML = ' '+Math.ceil(parseFloat(x[2])*eu).toFixed(2)+' '+grn+' / '+x[2]+' &euro;';
    e$('savedAmount').innerHTML = ' '+Math.ceil(parseFloat(x[5])*eu).toFixed(2)+' '+grn;
    e$('savedPercentage').innerHTML = x[4];
    if(parseFloat(x[5])>0){h$('defaultPriceArea');s$('reducedPriceArea')}else{s$('defaultPriceArea');h$('reducedPriceArea')}
    if(x[7])
    { s$('itemAvailable');
      e$('itemAvailable').innerHTML = x[8];
      h$('itemNotAvailable');
      e$('quantity').disabled = false;
    }
    else
    { h$('itemAvailable');
      s$('itemNotAvailable');
      e$('itemNotAvailable').innerHTML = x[8];
      e$('quantity').disabled = true;
    }

    update_item_img();
    navigateImage('');

    var p=e$('param0'), o=p.options;
    for(var i=0,n=o.length;i<n;i++)
    { if(z=e$('colorthumbimage'+i)){if(i==p.selectedIndex)z.className='current';else z.className=''}
    }
  }
}

function get_current_item()
{ for(var i=0,n=items.length,l=9;i<n;i++)
  { if(params_m==3&&items[i][l+0]==v$('param0')&&items[i][l+1]==v$('param1')&&items[i][l+2]==v$('param2'))return i;
    if(params_m==2&&items[i][l+0]==v$('param0')&&items[i][l+1]==v$('param1'))return i;
    if(params_m==1&&items[i][l+0]==v$('param0'))return i;
  }
  return 0;
}

function update_item_img()
{ var k = get_current_item();
  if(items[k][6]!=items[items_k][6])
  { update_img(items[k][6],items[items_k][6]);
    items_k = k;
  }
}

function update_img(i,j)
{ e$('itemImgBg').style.display='block';
  e$('itemImg').style.opacity=0;
  e$('itemImg').style.filter='alpha(opacity=0)';
  e$('itemImg').src=otto_img+i;
  fade$(e$('itemImgBg'),{k:0,onsuccess:function(){e$('itemImgBg').src=otto_img+j;e$('itemImgBg').style.opacity=1;e$('itemImgBg').style.filter='alpha(opacity=100)';}});
  fade$(e$('itemImg'),{k:1});
}

function setColor(v)
{ var x=e$('param0'),o=x.options;
  for(var i=0,n=o.length;i<n;i++)if(o[i].value==v)x.selectedIndex=i;
  update_params();
}

function navigateImage(d)
{ var code=items[get_current_item()][0], l=0, ki=images_k;
  if(images[code]&&(l=images[code].length)&&l>1)
  { if(d=='backward'){images_k--;if(images_k<0)images_k=l-1}
    if(d=='forward'){images_k++;if(images_k>=l)images_k=0}
    s$('navi');
    e$('navitext').innerHTML='&nbsp; Фото '+(images_k+1)+' из '+l+' &nbsp;';
    if(ki!=images_k)update_img(images[code][images_k],images[code][ki]);
  }
  else h$('navi');
}


function upoc()
{ var p=0;
  for(i=0,x=t$(e$('c'),'input'),n=x.length;i<n;i++)
  { if(x[i].type=='checkbox'&&x[i].checked)p+=parseFloat(a$(x[i],'price'));
  }
  e$('price').innerHTML = p.toFixed(2)+' грн.';
}


function hslider$(id,o)
{ var sender=this;
  this.ul=e$(id),this.id=id,this.li=[],this.v={cv:4,pt:0,auto:0,interval:4000},this.k=0,this.w;

  this.init=function(o)
  { for(s in o)this.v[s]=o[s];
    for(var i=0,j=1,li=t$(this.ul,'li'),n=li.length;i<n;i++)
    { if(li[i].parentNode==this.ul)
      { this.li.push(li[i]);
        this.li[this.li.length-1].idx=a$(li[i],'idx');
        if(this.v.pt&&a$(li[i],'idx')==this.v.k+1){this.v.k=j-1;this.v.pt=0}
        j++;
      }
    }
    this.w=this.li[0].offsetWidth;this.width=this.w*this.li.length;
    this.ul.style.width=this.width+'px';
    this.ul.style.left='0px';
    sender.ul.parentNode.style.height=this.li[0].offsetHeight+'px';
    if(this.v.k>this.li.length||this.v.k<0)this.v.k=0;
    this.pos(this.v.k||0);if(this.v.auto)this.v.auto=setInterval(function(){sender.move(1)},this.v.interval)
  }
  this.move=function(d){var n=this.k+d,i=d==1?n==this.li.length?0:n:n<0?this.li.length-1:n;this.pos(i)}
  this.pos=function(p)
  { n=this.li.length-this.v.cv;if(p>n)p=0;
    
    clearInterval(this.ul.ai);clearInterval(this.ul.si);
    var o=parseInt(this.ul.style.left),t=p*this.w,d=t>Math.abs(o)?1:-1;t=t*-1;this.k=p;
    this.ul.si=setInterval(function(){sender.slide(t,d)},20)
  }
  this.slide=function(t,d)
  { var o=parseInt(sender.ul.style.left),hh=sender.li[sender.k].offsetHeight,h=parseInt(sender.ul.parentNode.style.height)||0;
    if(o==t){clearInterval(sender.ul.si);sender.ul.parentNode.style.height=hh+'px'}
    else{sender.ul.style.left=o-Math.ceil(Math.abs(t-o)*.15)*d+'px';sender.ul.parentNode.style.height=h-Math.ceil((h-hh)*.15)+'px'}
  }
  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:15,x:0.05};
  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(this.alpha==this.v.o){clearInterval(this.si);if(!this.v.k)h$(this);if(this.v.onsuccess)this.v.onsuccess()}
    else{var value=(Math.round(this.alpha+((this.v.o-this.alpha)*this.v.x))+(1*this.k));this.style.opacity=value/100;this.style.filter='alpha(opacity='+value+')';this.alpha=value}
  }
}

function wnd$(o)
{ var sender=this;
  this.v,this.m,this.b,this.c,this.id,this.timer;
  if(typeof wnd$.zIndex=='undefined')wnd$.zIndex=10000;

  this.show=function(o)
  { this.v={opacity:70,fixed:1,topsplit:2,height:0,width:0,sajax:0,html_id:0,html:0,bg:0,tpl:'default',show:1,onclose:null,w:84,h:84};
    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++;
    d$.body.appendChild(this.m);
    d$.body.appendChild(this.b);
    this.b.appendChild(this.c);
    if(this.v.bg)this.b.style.background=this.v.bg;

    if(this.v.html)this.fill(this.v.html);
    else if(this.v.html_id)this.fill(e$(this.v.html_id).innerHTML);
    
    fade$(this.m.id,{o:this.v.opacity});
    fade$(this.b.id);

    add_event(this.m,"click",function(){sender.hide()});
    add_event(window,"resize",function(){sender.mask()});
    
    if(this.v.sajax)this.sajax(this.v.sajax)
  }
  this.hide=function(){fade$(this.m.id,{k:0,onsuccess:function(){sender.m.innerHTML=''}});fade$(this.b.id,{k:0,onsuccess:function(){sender.b.innerHTML=''}});if(this.v.onclose)this.v.onclose()}
  this.fill=function(r){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);this.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.b.className='wnd_inner wnd_preload_bg';fade$(this.c,{k:0,onsuccess:function(){sender.size()}})}
  this.sajax=function(a)
  { this.fill(this.tpl.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.fill(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></div>','preload':'<div class="wnd_preload"></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.pos()
  }
  this.show_content=function(){clearInterval(this.timer);fade$(this.c);this.b.className='wnd_inner'}
  this.show(o||{});
}


function calendar$(ids,o)
{ var sender=this;
  this.input=e$(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=
      {'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 */

