var mouseeY;
var mouseeX;
var iii = 5;
var xxd;
var abbbc=0;
var yyd;
moz_lay='idnumer';
var mas = new Array();
calcz=null;
var valentins=1;
laukums=null;
datums=new Date();





function movein3(which,html){
which.style.background='#E2E3E7'
}
function moveout3(which, html){
which.style.background='#FFFFFF'
}


function movein4(which,html){
which.style.background='#C6CBCF'
}
function moveout4(which, html){
which.style.background='#F2F3ED'
}

function movein5(which,html){
which.style.background='#C6CBCF'
}
function moveout5(which, html){
which.style.background='#E8E8E8'
}


function movein4ot(which,html){
which.style.background='#C6CBCF'
}
function moveout4ot(which, html){
which.style.background='#F2F3ED'
}

function widd(o) {
    if (document.layers) return o.clip.width;
    return o.offsetWidth;
}

function heighh(o) {
    if (document.layers) return o.clip.height;
    return o.offsetHeight;
}

function OT_inside(o,x,y,dx1,dy1,dx2,dy2) {
   var l=xxd;
   var t=yyd;
   if (valentins==1 && abbbc!=1) {
            return ((x-(dx1?dx1:0)>=l)&&(y-(dy1?dy1:0)>=t)&&(x-(dx2?dx2:0)<l+widd(o))&&(y-(dy2?dy2:0)<t+heighh(o)));
   }

   else {
        return true;
   }

}


function getel(a,b,c) {
    mas[0]=document.getElementById(a);
}

function OT_move(o,x,y) {
//x=100; y=100;
    if (document.layers)
        o.moveToAbsolute(x,y);
    else if (o.style.left&&(!o.style.pixelLeft)) {
        o.style.left=x+'px';
        o.style.top=y+'px';
    } else {
        o.style.pixelLeft=x;
        o.style.pixelTop=y;
    }
}

function get_date(a,b,c,d,e,f) {

    xxd=e;
    yyd=f;
        getel(b,c,d);
    var o=(document.getElementById?document.getElementById(moz_lay):(document.all?document.all[moz_lay]:document[moz_lay]));
    var n=(calcz==null);
    if (laukums&&(a==laukums)) return false;
    if (!n) {
        if (document.layers)
            calcz.visibility='hide';
        else
            calcz.style.visibility='hidden';
    }
    calcz=o;
    laukums=a;
    var d;
    if (a.name=='inDate') {
        datums=new Date();
        d=new Date();
        d.setDate(d.getDate()+14);
    } else if (a.name=='departureDate') {
        datums=new Date();
        d=new Date();
        d.setDate(d.getDate()+14);
    } else {
        d=new Date(datums.getFullYear(),datums.getMonth(),datums.getDate());
        d.setDate(d.getDate());
    }
    OT_render(d.getMonth()+1,d.getFullYear());
    OT_move(o,e,f);
    if (document.layers)
        o.visibility='show';
    else
        o.style.visibility='visible';
    if (n) {
        if (document.layers)
            document.captureEvents(Event.MOUSEDOWN);
        else
            document.onmousedown=cfff;
    }
}

function cfff(e) {
    if (calcz==null) return;
    var x=(document.all?event.clientX+document.body.scrollLeft:e.pageX);
    var y=(document.all?event.clientY+document.body.scrollTop:e.pageY);
    if (!(OT_inside(laukums,x,y,0,0,4,0)||OT_inside(calcz,x,y))) {OT_close(); }//
}

function cal_settings(y,m,d) {

    if (calcz==null) return;
   // alert(document.all["T1"]);
    if (m < 10) m = '0' + m;
    if (d < 10) d = '0' + d;
    mas[0].value=y+'-'+m+'-'+d;
    OT_close();
}

function OT_close2() {

    if (parent.document.layers)
        parent.calcz.visibility='hide';
    else {
        if (parent.calcz)
        parent.calcz.style.visibility='hidden';
    }
    if (parent.calcz) {
        if (parent.document.layers)
            parent.document.releaseEvents(Event.MOUSEDOWN);
        else
            parent.document.onmousedown=null;
    }
    parent.calcz=null;
    parent.laukums=null;
    parent.abbbc=1;
}

function setHeader(_head) {
     document.getElementById('head_id').innerHTML = _head;

}


function setBold(_head) {
     i = 0;
     while (document.getElementById('curentmenu' + i)) {
         document.getElementById('curentmenu' + i).style.fontWeight = 'normal';
         i++;
     }

     _head.style.fontWeight = 'bold';
}

function OT_close() {

    if (document.layers)
        calcz.visibility='hide';
    else
        calcz.style.visibility='hidden';
    if (calcz!=null) {
        if (document.layers)
            document.releaseEvents(Event.MOUSEDOWN);
        else
            document.onmousedown=null;
    }
    calcz=null;
    laukums=null;
    abbbc=1;
}

function OT_render(month,year) {

    if (calcz==null) return;
    var t_y=datums.getFullYear();
    var t_m=datums.getMonth()+1;
    var t_d=datums.getDate();
    var d=new Date(year,month-1,1);
    var max=(month==2?28+((year%4==0)&&((year%100!=0)||(year%400==0))?1:0):30+(month<8?1-((month-1)%2):(month-1)%2));
    var html='<table border=0 class="topmenu" cellpadding=0 cellspacing=0 bgcolor="#A0A3AA" style=" z-index:10"><tr><td><table border=0 cellpadding=3 cellspacing=1 width=150><tr bgcolor="#EBF3FE">\
    <td colspan="7" class="topmenu33"><table border=0 cellpadding=0 cellspacing=0 width=150><tr>\
    <td width="10px"><a href="javascript:void(0)" onclick="OT_render('+(month>1?month-1:12)+',' +(month>1?year:year-1)+')"><img src="images/a_left.gif" width=8 height=8 border=0></a></td>\
    <td valign="top" align="center" height="1" color="#3E4663" width="130px"><span style="font-family: verdana" color="#3E4663" class="topmenu22">&nbsp;&nbsp;';
    html+=menesis[month-1]+' '+year+'&nbsp;&nbsp;</span></td>\
    <td width="10px" align="right"><a href="javascript:void(0)" onclick="OT_render('+(month<12?month+1:1)+','+(month<12?year:year+1)+')"><img src="images/a_right.gif" width=8 height=8 border=0></a></td> \
    </tr></table></td>\
    </tr><tr bgcolor="#C6CBCF">';
    html+='<td align=center class="topmenu33" style="color:3E4663">P</td>\
    <td align=center class="topmenu33" style="color:3E4663">O.</td>\
    <td align=center class="topmenu33" style="color:3E4663">T.</td>\
    <td align=center class="topmenu33" style="color:3E4663">C.</td>\
    <td align=center class="topmenu33" style="color:3E4663">P.</td>\
    <td align=center class="topmenu33" style="color:FF0000">S.</td>\
    <td align=center class="topmenu33" style="color:FF0000">Sv.</td></tr>';
    var offset=d.getDay();
    var count=1,i,a;
    for (i=1;i<=max;i++) {

        if (count==1) html+='<tr bgcolor=white>';
        if ((i==1)&&(offset>1)) {
            //alert(offset);

            html+='<td colspan='+(offset-1)+' bgcolor="#FFFFFF" class="topmenu22">&nbsp;</td>';
            count=offset;
        }
        else if ((i==1)&&(offset==0)) {
            //alert(offset);
            if (offset <=  0) offset = 7;

            html+='<td colspan='+(offset-1)+' bgcolor="#FFFFFF" class="topmenu22">&nbsp;</td>';
            count=offset;
        }
if (month==mmz && year==yyz && i==ddz) {
 html+='<td align=center onmouseover="movein4(this)" onmouseout="movein4(this)" style="background-color: #C6CBCF;"><font face="arial,helvetica" size=1><a class="ipt3" ';
  if (count>5)
{
html+=' style="color:#FF0000" ';
        }
 html+=' href="javascript:cal_settings('+year+','+month+','+i+')" onclick="">'+i+'</a></font></td>';
         }
else {
html+='<td align=center onmouseover="movein3(this)" onmouseout="moveout3(this)" style=""><font face="arial,helvetica" size=1><a class="ipt3"  ';
  if (count>5)
{
html+=' style="color:#FF0000" ';
        }
 html+='  href="javascript:cal_settings('+year+','+month+','+i+')" onclick="">'+i+'</a></font></td>';    }
        if ((i==max)&&(count<7)) {
            html+='<td colspan='+(7-count)+' bgcolor="#FFFFFF" class="topmenu22">&nbsp;</td>';
            count=7;
        }
        count++;
        if (count>7) {
            count=1;
            html+='</tr>';
        }
    }
    html+='</table></td></tr></table>';
    if (document.layers) {
        calcz.document.open('text/html');
        calcz.document.write(html);
        calcz.document.close();
    } else
        calcz.innerHTML=html;

}


var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;
var tempX = 0;
var tempY = 0;
function getMouseXY(e) {
if (IE) { // grab the x-y pos.s if browser is IE
tempX = event.clientX + document.documentElement.scrollLeft;
tempY = event.clientY + document.documentElement.scrollTop;
}
else {  // grab the x-y pos.s if browser is NS
tempX = e.pageX;
tempY = e.pageY;
}
if (tempX < 0){tempX = 0;}
if (tempY < 0){tempY = 0;}
mouseeX = tempX;
mouseeY = tempY;
//window.status=mouseeX+" "+mouseeY;
return true;
}
