//SUGGEST skriptas
var xmlHttp
var segm

function showHint(str, segm)
{
if (segm=='1'){
spn='txtHint';
frme='frm'
len='10'
}
else if (segm=='2'){
spn='txtHint2';
frme='frm2'
len='10'
}
else if (segm=='3'){
spn='txtHint';
frme='frm'
len='7'
}
else if (segm=='4'){
spn='txtHint2';
frme='frm2'
len='7'
}
var url="/bilietai/gethint";
document.getElementById("x").value="";
document.getElementById("segm").value=segm;
if (str.length>=3)
  {
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
url=url+"?q="+str;
url=url+"&len="+len;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
else
{ 
  document.getElementById(spn).innerHTML="";
  document.getElementById(frme).style.visibility="hidden"
  return;
  }
} 

function stateChanged()
{ 
if (xmlHttp.readyState==4)
{ 
if (xmlHttp.responseText != "")
{
document.getElementById(spn).innerHTML=xmlHttp.responseText;
aukst = document.getElementById("pasiul").rows.length
if (aukst>1 && aukst<3){
document.getElementById(frme).style.height="70px"
}
//else if(aukst>2 && aukst<=5){
//document.getElementById(frme).style.height="50px"
//}
//else if(aukst==6){
//document.getElementById(frme).style.height="200px"
//}
else if (aukst>=3 && aukst<=9){
document.getElementById(frme).style.height="110px"
}
else if(aukst>9){
document.getElementById(frme).style.height="310px"
}
if (aukst>1){
document.getElementById(frme).style.visibility="visible"
}
else{
document.getElementById(frme).style.visibility="hidden"
}
}
else {
document.getElementById(spn).innerHTML="";
document.getElementById(frme).style.visibility="hidden"
}
}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

function istrinti(segm){
if (segm=='1'){
pav="is"
hnt="txtHint"
frme="frm"
kodas="iata1"
}
else if (segm=='2'){
pav="i"
hnt="txtHint2"
frme="frm2"
kodas="iata2"
}
if (document.getElementById("x").value=="")
{
document.getElementById(pav).value=""
document.getElementById(kodas).value=""
document.getElementById(hnt).innerHTML="";
document.getElementById(frme).style.visibility="hidden"
}
}

function laikyti(){
document.getElementById("x").value="a";
}

function paleisti(){
document.getElementById("x").value="";
}

function iata(id, val){
segm = document.getElementById("segm").value
if (segm=='1' || segm=='3'){
pav="is"
hnt="txtHint"
frme="frm"
iat="iata1"
}
else if (segm=='2' || segm=='4'){
pav="i"
hnt="txtHint2"
frme="frm2"
iat="iata2"
}
document.getElementById(pav).value=val;
document.getElementById(hnt).innerHTML="";
document.getElementById(frme).style.visibility="hidden"
document.getElementById(iat).value=id

document.getElementById("x").value="";
}

function ivesti(nr)
{
if (nr==1)
{
document.getElementById("isvblokas").innerHTML="<a href='javascript:salys(1)'>Visi oro uostai</a>"
document.getElementById("is").style.visibility="visible"
document.getElementById("is").value=""
document.getElementById("iata1").value=""
document.getElementById("isdrop").style.visibility="hidden"
}
else
{
document.getElementById("atvblokas").innerHTML="<a href='javascript:salys(2)'>Visi oro uostai</a>"
document.getElementById("i").style.visibility="visible"
document.getElementById("i").value=""
document.getElementById("iata2").value=""
document.getElementById("idrop").style.visibility="hidden"
}
}

function ivestisali(nr)
{
if (nr==1)
{
val = document.getElementById("isdrop").value
document.getElementById("iata1").value=val
}
else
{
val = document.getElementById("idrop").value
document.getElementById("iata2").value=val
}
}

function changeContent(value)
{
if (value == '1'){
document.getElementById('kalendorius2').style.visibility="hidden"
document.getElementById('prm').value = '1'
}
else {
document.getElementById('kalendorius2').style.visibility="visible"
document.getElementById('prm').value = '2'
}
}
/////////////////////////////////////////////////////////////////////////////////////////IESKOTI IR REZULTATAI

function rezultataiSENAS(is, i, isvmenmetai, isvdiena, suaug, jaun, sen, vaik, kud, grizmenmetai, grizdiena, oneway, isis, ii, klase, psl, sesija)
{
var url="/bilietai/pirmas?";
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
url=url+"pirmyn="+oneway+"&departure="+is+"&arrive="+i+"&menmetaical1="+isvmenmetai+"&dienacal1="+isvdiena+"&menmetaical2="+grizmenmetai+"&dienacal2="+grizdiena+"&klase="+klase+"&suaug="+suaug+"&jaun="+jaun+"&sen="+sen+"&vaik="+vaik+"&kud="+kud+"&isis="+isis+"&ii="+ii+"&psl="+psl+"&sesija="+sesija

xmlHttp.onreadystatechange=pakeitimas
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function pakeitimasSENAS()
{ 
if (xmlHttp.readyState==4)
{
if (xmlHttp.responseText != "")
{
document.getElementById("viskas").innerHTML=xmlHttp.responseText;
uzpildymasview()
}
}
}

function rezultatai(is, i, isvmenmetai, isvdiena, suaug, jaun, sen, vaik, kud, grizmenmetai, grizdiena, oneway, isis, ii, klase, psl, sesija, refer)
{
var url="/bilietai/pirmas?";
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
url=url+"pirmyn="+oneway+"&departure="+is+"&arrive="+i+"&menmetaical1="+isvmenmetai+"&dienacal1="+isvdiena+"&menmetaical2="+grizmenmetai+"&dienacal2="+grizdiena+"&klase="+klase+"&suaug="+suaug+"&jaun="+jaun+"&sen="+sen+"&vaik="+vaik+"&kud="+kud+"&isis="+isis+"&ii="+ii+"&psl="+psl+"&sesija="+sesija+"&ref="+refer
url=url+"&sid="+Math.random();

xmlHttp.onreadystatechange=pakeitimas
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function pakeitimas()
{ 
if (xmlHttp.readyState==4)
{
if (xmlHttp.responseText != "")
{
ats = xmlHttp.responseText
ats2 = ats.split("/")
//document.write(ats)
if (ats2[0] == "OK")
{
ses=ats2[1]
document.getElementById("sesija").value = ses
document.getElementById("isis").value = ats2[2]
document.getElementById("ii").value = ats2[3]
forma.submit()
}
else
{
//document.write(ats)
document.getElementById("errA").value = ats2[0]
document.getElementById("errB").value = ats
//document.getElementById("errB").value = ats2[1]
forma.action="/bilietai/error"
forma.submit()
}
}
}
}

function uzpildymasview()
{
isvmenmetai = document.getElementById("menmetaical1A").value
suaug = document.getElementById("suaugA").value
jaun = document.getElementById("jaunA").value
sen = document.getElementById("senA").value
vaik = document.getElementById("vaikA").value
kud = document.getElementById("kudA").value
ow = document.getElementById("prm").value

if (isvmenmetai != "")
{
document.getElementById("menmetaical1").value = isvmenmetai
document.getElementById("suaug").value = suaug
document.getElementById("jaun").value = jaun
document.getElementById("sen").value = sen
document.getElementById("vaik").value = vaik
document.getElementById("kud").value = kud

if (ow == "2")
{
grizmenmetai = document.getElementById("menmetaical2A").value
document.getElementById("menmetaical2").value = grizmenmetai
}
else
{
document.getElementById("ow").checked = true
document.getElementById('kalendorius2').style.visibility="hidden"
}
}
}

////////////////////////////////////////////////////////////////////////////////////////////SALYS

function showHintB()
{

xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="/bilietai/salys";

xmlHttp.onreadystatechange=stateChangedB
xmlHttp.open("GET",url,true);
xmlHttp.send(null);


} 

function stateChangedB()
{ 
if (xmlHttp.readyState==4)
{ 
if (xmlHttp.responseText != "")
{

document.getElementById("spn2").style.visibility="visible";
}
}
}

function salys(miestas)
{
if (miestas==1)
{
k = "<iframe class='framas' src='/bilietai/salys?miestas=is' id='spn2' width='400' height='250' frameborder='0' scrolling='auto' onblur='noframe()'></iframe>"
}
else
{
k = "<iframe class='framas' src='/bilietai/salys?miestas=i' id='spn2' width='400' height='250' frameborder='0' scrolling='auto' onblur='noframe()'></iframe>"
}
document.getElementById("framas").innerHTML = k
document.getElementById("spn2").focus()
}

function noframe()
{
window.parent.document.getElementById("framas").innerHTML = ""
}

function miestasset(miestas, iata, cityname, countryname, airportname)
{
//window.parent.document.getElementById("is").value = cityname+", "+countryname+", ("+iata+")"
if (airportname!=undefined)
{
window.parent.document.getElementById(miestas).value = cityname+", "+airportname+", "+countryname+" ("+iata+")"
document.write("yes")
}
else
{
window.parent.document.getElementById(miestas).value = cityname+", "+countryname+" ("+iata+")"
document.write("yes2")
}
if (miestas=="is")
{
window.parent.document.getElementById("iata1").value = iata
}
else if (miestas=="i")
{
window.parent.document.getElementById("iata2").value = iata
}
window.parent.document.getElementById("framas").innerHTML = ""
}
////////////////////////////////////////////////////////////////////////////////////////////VALIDATE
function validatepradzia()
{
var is
var i
is = document.getElementById("iata1").value
i = document.getElementById("iata2").value
isvmenmetai = document.getElementById("menmetaical1").value
isvdiena = document.getElementById("dienacal1").value
suaugs = document.getElementById("suaug")
suaugs = suaugs.options[suaugs.selectedIndex].text
jaun = document.getElementById("jaun")
jaun = jaun.options[jaun.selectedIndex].text
sen = document.getElementById("sen")
sen = sen.options[sen.selectedIndex].text
vaik = document.getElementById("vaik")
vaik = vaik.options[vaik.selectedIndex].text
kud = document.getElementById("kud")
kud = kud.options[kud.selectedIndex].text
submitOK="true"
today = new Date()
isvdate = new Date()
isvmetai = isvmenmetai.slice(-4)

if (document.getElementById("xmenmetaical1") != undefined)
{
document.getElementById("xmenmetaical1").value = isvmenmetai
document.getElementById("xdienacal1").value = isvdiena
}

if (isvmenmetai.length ==7)
{
isvmen = isvmenmetai.slice(0,2)-1
}
else
{
isvmen = isvmenmetai.slice(0,1)-1
}
isvdate.setFullYear(isvmetai,isvmen,isvdiena)

if (document.getElementById("prm").value==2)
{
oneway = "no"
grizmenmetai = document.getElementById("menmetaical2").value
grizdiena = document.getElementById("dienacal2").value
grizdate = new Date()
grizmetai = grizmenmetai.slice(-4)

if (document.getElementById("xmenmetaical2") != undefined)
{
document.getElementById("xmenmetaical2").value = grizmenmetai
document.getElementById("xdienacal2").value = grizdiena
}

if (grizmenmetai.length ==7)
{
grizmen = grizmenmetai.slice(0,2)-1
}
else
{
grizmen = grizmenmetai.slice(0,1)-1
}
grizdate.setFullYear(grizmetai,grizmen,grizdiena)
}
else
{
oneway = "yes"
}

if (suaugs==0 && jaun==0 && sen==0)
{
dideli = 1
}
else
{
dideli = 0
}

if (is == "")
{
alert("Įrašykite arba pasirinkite miestą iš kurio skrisite!")
submitOK="false"
}
else if (i == "")
{
alert("Įrašykite arba pasirinkite miestą į kurį skrisite!")
submitOK="false"
}
else if (today>=isvdate)
{
alert("Išvykimo data negali būti šiandien arba ankstesnė, negu šiandien. Pataisykite datą!")
submitOK="false"
}
else if (oneway=="no" && today>=grizdate)
{
alert("Grįžimo data negali būti šiandien arba ankstesnė, negu šiandien. Pataisykite datą!")
submitOK="false"
}
else if (oneway=="no" && grizdate<isvdate)
{
alert("Grįžimo data negali būti ankstesnė už išvykimo datą. Pataisykite datas!")
submitOK="false"
}
else if (dideli==1 && vaik>0)
{
alert("Vaikams skristi be suaugusiųjų nėra galimybės užsakyti bilieto internetu. Prašome skambinti tel. +370 (5) 2460516!")
submitOK="false"
}
else if (dideli==1 && kud>0)
{
alert("Kūdikiai skristi be suaugusiųjų negali. Prašome pataisyti keleivių skaičių!")
submitOK="false"
}
else if (dideli==1 && kud==0 && vaik==0)
{
alert("Jūs nepasirinkote nė vieno keleivio. Prašome pataisyti!")
submitOK="false"
}

if (submitOK=="true")
 {
document.getElementById("forma").submit()
//forma.submit()
 }
}
///////////////////////////////////////////////////////////////////////////////VALIDATE REZULTATU PSL
function validateresult(fff, trip)
{
/*var x=document.getElementById(form).getElementsByTagName("input");
var l = x.length-2
var ch = 0
for (var i=0;i<l;i++)
{
if (x[i].checked==true)
{
ch++
}
}
if (trip==2 && ch != 2)
{
alert("Pasirinkite skrydį pirmyn ir skrydį atgal!")
}
else if (trip !=2 && ch !=1)
{
alert("Pasirinkite skrydį!")
}
else
{*/
//s = document.getElementById(form)
//aaa=document.getElementsByName(fff)[0].name
//document.write(aaa)
document.forms.formm.submit()
//}
}
////////////////////////////////////////////////////////////////////////////////////////DUOMENYS PSL
function pristat(val)
{
kodas = val.substring(0,3)
if (kodas=="ETK" || kodas=="HFP")
{
document.getElementById("prist").style.visibility = "hidden"
}
else
{
document.getElementById("prist").style.visibility = "visible"
}
}

function tikr()
{
formok="yes"
zmones=document.getElementById("kelduom").getElementsByTagName("table")
gmdata = document.getElementsByName("gmdat")
//kreipinys=kreipinys[0].getElementsByTagName("input")
//document.write(kreipinys[0].getElementsByTagName("input")[0].checked)
l=zmones.length
for (var i=0;i<l;i++){
n=zmones[i].getElementsByTagName("input")
s=zmones[i].getElementsByTagName("select")
k=i+1
if (n[0].checked==false && n[1].checked==false)
{
alert("Pasirinkite kreipinį keleiviui Nr."+k+"!")
formok="no"
break
}
if (n[2].value==""||n[2].value==null)
{
alert("Įrašykite vardą keleiviui Nr."+k+"!")
formok="no"
break
}
if (n[3].value==""||n[3].value==null)
{
alert("Įrašykite pavardę keleiviui Nr."+k+"!")
formok="no"
break
}
if (n.length>6)
{
if (n[6].value.length !=10)
{
alert("Teisingai įrašykite gimimo datą!")
formok="no"
break
}
else
{
menuo=n[6].value.substr(5,2)
diena=n[6].value.substr(8)
if ((diena<1)||(menuo=="01" && diena>31)||(menuo=="02" && diena>29)||(menuo=="03" && diena>31)||(menuo=="04" && diena>30)||(menuo=="05" && diena>31)||(menuo=="06" && diena>30)||(menuo=="07" && diena>31)||(menuo=="08" && diena>31)||(menuo=="09" && diena>30)||(menuo=="10" && diena>31)||(menuo=="11" && diena>30)||(menuo=="12" && diena>31))
{
alert("Teisingai įrašykite gimimo datą!")
formok="no"
break
}
}
if (s.length>3)
{
if (s[3].value !="" && n[7].value =="")
{
alert("Įrašykite dažno keleivio kortelės numerį keleiviui Nr."+k+"!")
formok="no"
break
}
}
}
else
{
if (s[1].value != "" && n[4].value == "")
{
alert("Įrašykite dažno keleivio kortelės numerį keleiviui Nr."+k+"!")
formok="no"
break
}
}
}
if (formok=="yes")
{
tel = document.getElementById("telefonas").value
eml = document.getElementById("email")
apos=eml.value.indexOf("@")
dotpos=eml.value.lastIndexOf(".")
siuntimas=document.getElementById('siunt').getElementsByTagName("input")
q=siuntimas.length
pazymeta="no"
for (var i=0;i<q;i++){
if (siuntimas[i].checked==true)
{
pazymeta="yes"
}
}
if (tel==null || tel=="")
{
alert("Įrašykite kontaktinį telefono numerį!")
formok="no"
}
else if (apos<1||dotpos-apos<2) 
{
alert("Teisingai įrašykite elektroninio pašto adresą!")
formok="no"
}
else if (pazymeta=="no")
{
alert("Pasirinkite bilieto pristatymo būdą!")
formok="no"
}
else if (document.getElementById("prist").style.visibility=="visible")
{
gavejas=document.getElementById("gavejas").value
adresas=document.getElementById("adr").value
miestas=document.getElementById("miestas").value
zip=document.getElementById("zip").value
if (gavejas==null || gavejas=="")
{
alert("Įrašykite gavėjo vardą, pavardę arba pavadinimą!")
formok="no"
}
else if (adresas==null || adresas=="")
{
alert("Įrašykite bilieto pristatymo adresą!")
formok="no"
}
else if (miestas==null || miestas=="")
{
alert("Įrašykite bilieto pristatymo miestą!")
formok="no"
}
else if (zip==null || zip=="")
{
alert("Įrašykite bilieto pristatymo pašto kodą!")
formok="no"
}
}
}
if (formok=="yes")
{
forma.submit()
}
}

function gimdata(laukas)
{
metai=document.getElementById(laukas+"gimmetai").value
menuo=document.getElementById(laukas+"gimmenuo").value
diena=document.getElementById(laukas+"gimdiena").value
if (diena.length==1)
{
diena="0"+diena
}

document.getElementById(laukas+"gimdata").value=metai+"-"+menuo+"-"+diena
}
///////////////////////////////////////////////////////////////////////////////////////////APMOKEJIMAS PSL
function kortele(val, kaina)
{
kaina = Number(kaina)
tdk = document.getElementById("krtl")
if (val=="CCN")
{
tdk.style.visibility = "visible"
tdk.style.position = "relative"
apt = Math.round(kaina/100*3)
}
else if (val=="BTR")
{
tdk.style.visibility = "hidden"
tdk.style.position = "absolute"
apt = 10
}
else
{
tdk.style.visibility = "hidden"
tdk.style.position = "absolute"
apt = 0
}
suapt = kaina+apt
document.getElementById("aptmok").innerHTML = apt+" Lt"
document.getElementById("isviso").innerHTML = "<b>"+suapt+" Lt</b>"
document.getElementById("suma").value = suapt
document.getElementById("aptarnavimomok").value = apt
}

function apmvalid()
{
formok="yes"
chk = document.getElementsByName("apmokejimas")
q = chk.length
pazymeta = ""
kort = document.getElementById("krtl").style.visibility
for (var i=0;i<q;i++)
{
if (chk[i].checked==true)
{
pazymeta = "yes"
}
}
if (pazymeta == "")
{
alert("Pasirinkite apmokėjimo būdą!")
formok = "no"
}
else if (kort=="visible" && document.getElementById("pavarde").value=="")
{
alert("Įrašykite kortelės turėtojo vardą ir pavardę!")
formok = "no"
}
else if (kort=="visible" && document.getElementById("nr").value=="")
{
alert("Įrašykite kortelės numerį!")
formok = "no"
}
else if (kort=="visible" && document.getElementById("pavarde").value=="")
{
alert("Įrašykite kortelės turėtojo vardą ir pavardę!")
formok = "no"
}
else if (kort=="visible" && document.getElementById("cvv").value=="")
{
alert("Įrašykite kortelės CVV kodą!")
formok = "no"
}
else if (kort=="visible" && document.getElementById("adresas").value=="")
{
alert("Įrašykite kortelės turėtojo adresą!")
formok = "no"
}
else if (kort=="visible" && document.getElementById("miestas").value=="")
{
alert("Įrašykite kortelės turėtojo adreso miestą!")
formok = "no"
}
else if (kort=="visible" && document.getElementById("zip").value=="")
{
alert("Įrašykite kortelės turėtojo pašto kodą!")
formok = "no"
}
if (formok=="yes")
{
forma.submit()
}
}

/////////////////////////////////////////////////////////////////////////////////////////+/-2 d. KAINU KALENDORIUS
var sesija
var ow
var datpirmynarr
var datatgalarr
var pdat=0
var adat=0

function savkainos()
{

ow = document.getElementById("prm").value
menmetaipirmyn = document.getElementById("menmetaical1A").value
menmetaipirmyn = menmetaipirmyn.split("/")
dienapirmyn = document.getElementById("dienacal1").value
datpirmyn = new Date()
datpirmyn.setFullYear(menmetaipirmyn[1], menmetaipirmyn[0]-1,dienapirmyn)
datpirmynarr = new Array()
datpirmynarr[0] = new Date(datpirmyn)
datpirmynarr[0]=datpirmynarr[0].setDate(datpirmynarr[0].getDate()-2)
datpirmynarr[1] = new Date(datpirmyn)
datpirmynarr[1]=datpirmynarr[1].setDate(datpirmynarr[1].getDate()-1)
datpirmynarr[2] = new Date(datpirmyn)
datpirmynarr[2] = datpirmyn
datpirmynarr[3] = new Date(datpirmyn)
datpirmynarr[3]=datpirmynarr[3].setDate(datpirmynarr[3].getDate()+1)
datpirmynarr[4] = new Date(datpirmyn)
datpirmynarr[4]=datpirmynarr[4].setDate(datpirmynarr[4].getDate()+2)
var i=0
var dpirmyn = ""
isvdiena = new Array()
for (i=0;i<5;i++)
{
y= new Date(datpirmynarr[i])
y=y.getFullYear()
m=new Date(datpirmynarr[i])
m=m.getMonth()+1
d=new Date(datpirmynarr[i])
d=d.getDate()
isvdiena[i] = d
datpirmynarr[i] = y+"-"+m+"-"+d
}

suaug = Number(document.getElementById("suaugA").value)
jaun = Number(document.getElementById("jaunA").value)
sen = Number(document.getElementById("senA").value)
vaik = Number(document.getElementById("vaikA").value)
iataA = document.getElementById("iata1").value
iataB = document.getElementById("iata2").value
klase = document.getElementById("klaseA").value
keleiviai = suaug+jaun+sen+vaik

eilutes = document.getElementById("kalendor").getElementsByTagName("td")
var z=9
for (i=0;i<=4;i++)
{
eilutes[z].innerHTML = isvdiena[i]+" d."
z=z+6
}

if (ow == "2")
{
menmetaiatgal = document.getElementById("menmetaical2A").value
menmetaiatgal = menmetaiatgal.split("/")
dienaatgal = document.getElementById("dienacal2").value
datatgal = new Date()
datatgal.setFullYear(menmetaiatgal[1], menmetaiatgal[0]-1, dienaatgal)
datatgalarr = new Array()
datatgalarr[0] = new Date(datatgal)
datatgalarr[0]=datatgalarr[0].setDate(datatgalarr[0].getDate()-2)
datatgalarr[1] = new Date(datatgal)
datatgalarr[1]=datatgalarr[1].setDate(datatgalarr[1].getDate()-1)
datatgalarr[2] = new Date(datatgal)
datatgalarr[2] = datatgal
datatgalarr[3] = new Date(datatgal)
datatgalarr[3]=datatgalarr[3].setDate(datatgalarr[3].getDate()+1)
datatgalarr[4] = new Date(datatgal)
datatgalarr[4]=datatgalarr[4].setDate(datatgalarr[4].getDate()+2)

var i=0
var datgal=""
atvdiena = new Array()
for (i=0;i<5;i++)
{
y= new Date(datatgalarr[i])
y=y.getFullYear()
m=new Date(datatgalarr[i])
m=m.getMonth()+1
d=new Date(datatgalarr[i])
d=d.getDate()
atvdiena[i] = d
datatgalarr[i] = y+"-"+m+"-"+d
}

var i=3
for (i=3;i<=7;i++)
{
eilutes[i].innerHTML = atvdiena[i-3]+" d."
}
uzkl = "/bilietai/savkainos?departure="+iataA+"&arrive="+iataB+"&dpirmyn="+datpirmynarr[0]+"&datgal="+datatgalarr[0]+"&suaug="+keleiviai+"&klase="+klase+"&pirmyn="+ow+"&uzklausa=10&sesija=0"

}
else
{
var i=3
for (i=3;i<=7;i++)
{
eilutes[i].innerHTML = "X"
}
uzkl = "/bilietai/savkainos?departure="+iataA+"&arrive="+iataB+"&dpirmyn="+datpirmynarr[0]+"&datgal=&suaug="+keleiviai+"&klase="+klase+"&pirmyn="+ow+"&uzklausa=10&sesija=0"
}
uzkl=uzkl+"&sid="+Math.random();
eilutes[10].innerHTML = "<img src='/images/indicator.gif' alt='Ieškome kainos...'>"
savkainosxml(uzkl)
//frmfrm = "<iframe class='framas' src='/bilietai/savkainos?departure="+iataA+"&arrive="+iataB+"&dpirmyn="+dpirmyn+"&datgal="+datgal+"&suaug="+keleiviai+"&klase="+klase+"&pirmyn="+ow+"' id='spn2' width='400' height='250' frameborder='0' scrolling='auto'></iframe>"
//document.getElementById("bilsav").innerHTML=frmfrm
//uzkl = "/bilietai/savkainos?departure="+iataA+"&arrive="+iataB+"&dpirmyn="+datpirmynarr[0]+"&datgal="+datatgalarr[0]+"&suaug="+keleiviai+"&klase="+klase+"&pirmyn="+ow+"&uzklausa=1&sesija=0"
//savkainosxml(uzkl)


}

function savkainostesti(prm, atg, uzkl, krypt)
{
if (atg=="X")
{
uzkl = "/bilietai/savkainos?dpirmyn="+prm+"&datgal=&uzklausa="+uzkl+"&sesija="+sesija+"&pirmyn="+ow
uzkl=uzkl+"&sid="+Math.random();
}
else
{
if (krypt==1)
{
uzkl = "/bilietai/savkainos?dpirmyn=&datgal="+atg+"&uzklausa="+uzkl+"&sesija="+sesija+"&pirmyn="+ow
uzkl=uzkl+"&sid="+Math.random();
}
else
{
uzkl = "/bilietai/savkainos?dpirmyn="+prm+"&datgal="+atg+"&uzklausa="+uzkl+"&sesija="+sesija+"&pirmyn="+ow
uzkl=uzkl+"&sid="+Math.random();
}
}
//document.write(prm)
//document.write(atg)
savkainosxml(uzkl)
}

function savkainosxml(uzkl)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 

xmlHttp.onreadystatechange=function()
	{
	x=0
	if (xmlHttp.readyState==4)
	{
	if (xmlHttp.responseText != "")
	{
	x = xmlHttp.responseText;
	eilutes = document.getElementById("kalendor").getElementsByTagName("td")
	x = x.split("/")
	sesija = x[1]
	lang = Number(x[2])
	kain = x[0]
	if (kain != "-")
	{
	eilutes[lang].innerHTML = "<a href='javascript:iskalendoriaus("+pdat+","+adat+")'>"+kain+"</a>"
	}
	else
	{
	eilutes[lang].innerHTML = "X"
	}
	if (ow==1)
	{
	pdat = Number(pdat)+1
	uzkl = lang+6
	if (lang>=34)
	{
	return
	}
	else
	{
	eilutes[uzkl].innerHTML = "<img src='/images/indicator.gif' alt='Ieškome kainos...'>"
	savkainostesti(datpirmynarr[pdat], "X", uzkl)
	}
	}
	else
	{
	if (lang>=10 && lang<=13)
	{
	uzkl = lang+1
	pdat = 0
	adat = lang-9
	krypt = 1
	}
	else if (lang==14)
	{
	uzkl = lang+2
	pdat = 1
	adat = lang-14
	krypt = 2
	}
	else if (lang>=15 && lang<=19)
	{
	uzkl = lang+1
	pdat = 1
	adat = lang-15
	krypt = 1
	}
	else if (lang==20)
	{
	uzkl = lang+2
	pdat = 2
	adat = lang-20
	krypt = 2
	}
	else if (lang>=21 && lang<=25)
	{
	uzkl = lang+1
	pdat = 2
	adat = lang-21
	krypt = 1
	}
	else if (lang==26)
	{
	uzkl = lang+2
	pdat = 3
	adat = lang-26
	krypt = 2
	}
	else if (lang>=27 && lang<=31)
	{
	uzkl = lang+1
	pdat = 3
	adat = lang-27
	krypt = 1
	}
	else if (lang==32)
	{
	uzkl = lang+2
	pdat = 4
	adat = lang-32
	krypt = 2
	}
	else if (lang>=34 && lang<=37)
	{
	uzkl = lang+1
	pdat = 4
	adat = lang-33
	krypt = 1
	}
	else
	{
	return
	}
	eilutes[uzkl].innerHTML = "<img src='/images/indicator.gif' alt='Ieškome kainos...'>"
	savkainostesti(datpirmynarr[pdat], datatgalarr[adat], uzkl, krypt)
	}
	}
	}
	}
xmlHttp.open("GET",uzkl,true);
xmlHttp.send(null);

}

function iskalendoriaus (pdat, adat)
{
if(ow==2)
{
atgal = datatgalarr[adat].split("-")
mmatg = atgal[1]+"/"+atgal[0]
document.getElementById("menmetaical2A").value = mmatg
document.getElementById("dienacal2A").value = atgal[2]
}
pirmyn = datpirmynarr[pdat].split("-")
mmpirm = pirmyn[1]+"/"+pirmyn[0]

document.getElementById("sesijaA").value = ""
document.getElementById("pslA").value = 1
document.getElementById("menmetaical1A").value = mmpirm
document.getElementById("dienacal1A").value = pirmyn[2]

ktpsl.submit()
}
////////////////////////////////////////////////////////////////////////////////////////////RUSIUOTI REZULTATAI
var rusiav
var krypt
var pirmumas

function rusiavimas(sesija, rus, kryptis, prm, ref)
{
rusiav = rus
krypt = kryptis
pirmumas = prm
document.getElementById("bilietaiviewrez").innerHTML="<table class='rezultatai' width='100%'><tr><td style='text-align: center;'><h3><b>Rūšiuojame rezultatus...</b></h3><br>Truputį palaukite.<br><img src='/images/progresas.gif' ></td></tr></table>"
var url="/bilietai/spausdintirez?sesija="+sesija+"&rus="+rus+"&ref="+ref;
url=url+"&sid="+Math.random();

xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
xmlHttp.onreadystatechange=rusiavimaskeisti
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function rusiavimaskeisti()
{ 
if (xmlHttp.readyState==4)
{ 
if (xmlHttp.responseText != "")
{
document.getElementById("bilietaiviewrez").innerHTML=xmlHttp.responseText;
kiekps = document.getElementById("kiekpas").value
document.getElementById("kiek").innerHTML=kiekps
if (pirmumas==1)
{
document.getElementById("irankiai").style.visibility="visible"
//savkainos() //+-2 d. kalendoriaus ijungimas. Atjungta. Jei reikia ijungti, atstatyti
}
if (rusiav==1)
{
document.getElementById("rus1").style.visibility="hidden"
document.getElementById("rus1").style.position="absolute"
document.getElementById("rus2").style.visibility="visible"
document.getElementById("rus2").style.position="relative"
document.getElementById("rus3").style.visibility="visible"
document.getElementById("rus3").style.position="relative"
document.getElementById("rus4").style.visibility="visible"
document.getElementById("rus4").style.position="relative"
}
else if (rusiav==2)
{
document.getElementById("rus1").style.visibility="visible"
document.getElementById("rus1").style.position="relative"
document.getElementById("rus2").style.visibility="hidden"
document.getElementById("rus2").style.position="absolute"
document.getElementById("rus3").style.visibility="visible"
document.getElementById("rus3").style.position="relative"
document.getElementById("rus4").style.visibility="visible"
document.getElementById("rus4").style.position="relative"
}
else if (rusiav==3)
{
document.getElementById("rus1").style.visibility="visible"
document.getElementById("rus1").style.position="relative"
document.getElementById("rus2").style.visibility="visible"
document.getElementById("rus2").style.position="relative"
document.getElementById("rus3").style.visibility="hidden"
document.getElementById("rus3").style.position="absolute"
document.getElementById("rus4").style.visibility="visible"
document.getElementById("rus4").style.position="relative"
}
else if (rusiav==4)
{
document.getElementById("rus1").style.visibility="visible"
document.getElementById("rus1").style.position="relative"
document.getElementById("rus2").style.visibility="visible"
document.getElementById("rus2").style.position="relative"
document.getElementById("rus3").style.visibility="visible"
document.getElementById("rus3").style.position="relative"
document.getElementById("rus4").style.visibility="hidden"
document.getElementById("rus4").style.position="absolute"
}
if (krypt==1)
{
document.getElementById("rus3").style.visibility="hidden"
document.getElementById("rus3").style.position="absolute"
}
}
}
}
function kiekpasiulymu ()
{
document.getElementById("kiek").innerHTML=kiek
}

////////////////////////////////////////////////////////////////////////////////////////////REZULTATU PSL
function uzpildyti(is,i,menmetaipirmyn,dienapirmyn,menmetaiatgal,dienaatgal,suaug,jaun,sen,vaik,kud,iataA,iataB,klase,ow)
{
document.getElementById("is").value = is
document.getElementById("i").value = i
document.getElementById("menmetaical1").value = menmetaipirmyn
document.getElementById("dienacal1").value = dienapirmyn
document.getElementById("suaug").value = suaug
document.getElementById("jaun").value = jaun
document.getElementById("sen").value = sen
document.getElementById("vaik").value = vaik
document.getElementById("kud").value = kud
document.getElementById("iata1").value = iataA
document.getElementById("iata2").value = iataB
document.getElementById("klase").value = klase
if (ow == "2")
{
document.getElementById("menmetaical2").value = menmetaiatgal
document.getElementById("dienacal2").value = dienaatgal
}
else
{
document.getElementById("ow").checked = true
document.getElementById('kalendorius2').style.visibility="hidden"
}
}


////////////////////////////////////////////////////////////////////////////////////////////KALENDORIUS

/*****************************************************************************
Copyright (C) 2006  Nick Baicoianu

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*****************************************************************************/
//constructor for the main Epoch class (ENGLISH VERSION)
function Epoch(name,mode,targetelement,multiselect,offset)
{
	this.state = 0;
	this.name = name;
	this.curDate = new Date();
	var dd=this.curDate.getDate()
	dd=dd+offset
	this.curDate.setDate(dd)
	this.mode = mode;
	this.selectMultiple = (multiselect == true); //'false' is not true or not set at all
	
	//the various calendar variables
	//this.selectedDate = this.curDate;
	this.selectedDates = new Array();
	this.calendar;
	this.calHeading;
	this.calCells;
	this.rows;
	this.cols;
	this.cells = new Array();
	
	//The controls
	this.monthSelect;
	this.yearSelect;
	
	//standard initializations
	this.mousein = false;
	this.calConfig();
	this.setDays();
	this.displayYear = this.displayYearInitial;
	this.displayMonth = this.displayMonthInitial;
	
	this.createCalendar(); //create the calendar DOM element and its children, and their related objects
	
	if(this.mode == 'popup' && targetelement && targetelement.type == 'text') //if the target element has been set to be an input text box
	{
		this.tgt = targetelement;
		this.calendar.style.position = 'absolute';
		this.topOffset = this.tgt.offsetHeight; // the vertical distance (in pixels) to display the calendar from the Top of its input element
		this.leftOffset = 0; 					// the horizontal distance (in pixels) to display the calendar from the Left of its input element
		this.calendar.style.top = this.getTop(targetelement) + this.topOffset + 'px';
		this.calendar.style.left = this.getLeft(targetelement) + this.leftOffset + 'px';
		document.body.appendChild(this.calendar);
		this.tgt.calendar = this;
		this.tgt.onfocus = function () {this.calendar.show();}; //the calendar will popup when the input element is focused
		this.tgt.onblur = function () {if(!this.calendar.mousein){this.calendar.hide();}}; //the calendar will popup when the input element is focused
	}
	else
	{
		this.container = targetelement;
		this.container.appendChild(this.calendar);
	}
	
	this.state = 2; //0: initializing, 1: redrawing, 2: finished!
	this.visible ? this.show() : this.hide();
}
//-----------------------------------------------------------------------------
Epoch.prototype.calConfig = function () //PRIVATE: initialize calendar variables
{
	//this.mode = 'flat'; //can be 'flat' or 'popup'
	this.displayYearInitial = this.curDate.getFullYear(); //the initial year to display on load
	this.displayMonthInitial = this.curDate.getMonth(); //the initial month to display on load (0-11)
	this.rangeYearLower = 2005;
	this.rangeYearUpper = 2037;
	this.minDate = new Date(2005,0,1);
	this.maxDate = new Date(2037,0,1);
	this.startDay = 1; // the day the week will 'start' on: 0(Sun) to 6(Sat)
	this.showWeeks = false; //whether the week numbers will be shown
	this.selCurMonthOnly = false; //allow user to only select dates in the currently displayed month
	this.clearSelectedOnChange = true; //whether to clear all selected dates when changing months
	
	//flat mode-only settings:
	//this.selectMultiple = true; //whether the user can select multiple dates (flat mode only)

	switch(this.mode) //set the variables based on the calendar mode
	{
		case 'popup': //popup options
			this.visible = false;
			break;
		case 'flat':
			this.visible = true;
			
			break;
	}
	this.setLang();
};
//-----------------------------------------------------------------------------
Epoch.prototype.setLang = function()  //all language settings for Epoch are made here.  Check Date.dateFormat() for the Date object's language settings
{
	this.daylist = new Array('S','Pr','A','T','K','P','Š','S','Pr','A','T','K','P','Š'); /*<lang:en>*/
	this.months_sh = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
	this.monthup_title = 'Go to the next month';
	this.monthdn_title = 'Go to the previous month';
	this.clearbtn_caption = 'Clear';
	this.clearbtn_title = 'Clears any dates selected on the calendar';
	this.maxrange_caption = 'This is the maximum range';
};
//-----------------------------------------------------------------------------
Epoch.prototype.getTop = function (element) //PRIVATE: returns the absolute Top value of element, in pixels
{
    var oNode = element;
    var iTop = 0;
    
    while(oNode.tagName != 'BODY') {
        iTop += oNode.offsetTop;
        oNode = oNode.offsetParent;
    }
    
    return iTop;
};
//-----------------------------------------------------------------------------
Epoch.prototype.getLeft = function (element) //PRIVATE: returns the absolute Left value of element, in pixels
{
    var oNode = element;
    var iLeft = 0;
    
    while(oNode.tagName != 'BODY') {
        iLeft += oNode.offsetLeft;
        oNode = oNode.offsetParent;        
    }
    
    return iLeft;
};
//-----------------------------------------------------------------------------
Epoch.prototype.show = function () //PUBLIC: displays the calendar
{
	this.calendar.style.display = 'block';
	this.visible = true;
};
//-----------------------------------------------------------------------------
Epoch.prototype.hide = function () //PUBLIC: Hides the calendar
{
	this.calendar.style.display = 'none';
	this.visible = false;
};
//-----------------------------------------------------------------------------
Epoch.prototype.toggle = function () //PUBLIC: Toggles (shows/hides) the calendar depending on its current state
{
	if(this.visible) {
		this.hide();
	}
	else {
		this.show();
	}
};
//-----------------------------------------------------------------------------
Epoch.prototype.setDays = function ()  //PRIVATE: initializes the standard Gregorian Calendar parameters
{
	this.daynames = new Array();
	var j=0;
	for(var i=this.startDay; i< this.startDay + 7;i++) {
		this.daynames[j++] = this.daylist[i];
	}
		
	this.monthDayCount = new Array(31,((this.curDate.getFullYear() - 2000) % 4 ? 28 : 29),31,30,31,30,31,31,30,31,30,31);
};
//-----------------------------------------------------------------------------
Epoch.prototype.setClass = function (element,className) //PRIVATE: sets the CSS class of the element, W3C & IE
{
	element.setAttribute('class',className);
	element.setAttribute('className',className); //<iehack>
};
//-----------------------------------------------------------------------------
Epoch.prototype.createCalendar = function ()  //PRIVATE: creates the full DOM implementation of the calendar
{
	var tbody, tr, td;
	this.calendar = document.createElement('table');
	this.calendar.setAttribute('id',this.name+'_calendar');
	this.setClass(this.calendar,'calendar');
	//to prevent IE from selecting text when clicking on the calendar
	this.calendar.onselectstart = function() {return false;};
	this.calendar.ondrag = function() {return false;};
	tbody = document.createElement('tbody');
	
	//create the Main Calendar Heading
	tr = document.createElement('tr');
	td = document.createElement('td');
	td.appendChild(this.createMainHeading());
	tr.appendChild(td);
	tbody.appendChild(tr);
	
	//create the calendar Day Heading
	tr = document.createElement('tr');
	td = document.createElement('td');
	td.appendChild(this.createDayHeading());
	tr.appendChild(td);
	tbody.appendChild(tr);

	//create the calendar Day Cells
	tr = document.createElement('tr');
	td = document.createElement('td');
	td.setAttribute('id',this.name+'_cell_td');
	this.calCellContainer = td;	//used as a handle for manipulating the calendar cells as a whole
	td.appendChild(this.createCalCells());
	tr.appendChild(td);
	tbody.appendChild(tr);
	
	//create the calendar footer
	//tr = document.createElement('tr');
	//td = document.createElement('td');
	//td.appendChild(this.createFooter());
	//tr.appendChild(td);
	//tbody.appendChild(tr);
	
	//add the tbody element to the main calendar table
	this.calendar.appendChild(tbody);

	//and add the onmouseover events to the calendar table
	this.calendar.owner = this;
	this.calendar.onmouseover = function() {this.owner.mousein = true;};
	this.calendar.onmouseout = function() {this.owner.mousein = false;};
};
//-----------------------------------------------------------------------------
Epoch.prototype.createMainHeading = function () //PRIVATE: Creates the primary calendar heading, with months & years
{
	//create the containing <div> element
	var container = document.createElement('div');
	container.setAttribute('id',this.name+'_mainheading');
	this.setClass(container,'mainheading');
	//create the child elements and other variables
	this.monthSelect = document.createElement('select');
	this.yearSelect = document.createElement('input');
	var monthDn = document.createElement('input'), monthUp = document.createElement('input');
	var opt, i;
	//fill the month select box
	
	var menesiai=new Array("sausio","vasario","kovo","balandžio","gegužės","birželio","liepos","rugpjūčio","rugsėjo","spalio","lapkričio","gruodžio");
	var data = new Date();
	//var diena=data.getDate()
	var menuo = data.getMonth()+1
	//diena=diena+14
	//data.setDate(diena)
	diena = this.curDate.getDate()
	var metai = data.getFullYear()
	var men=this.curDate.getMonth()+1
	var m=menuo
	var y=metai
	
	for(i=0;i<12;i++)
	{
		var val=m+'/'+y
		opt = document.createElement('option');
		opt.setAttribute('value',val);
		if(m==men) {
			opt.setAttribute('selected','selected');
		}
		var menmet=y+' '+menesiai[m-1]
		opt.appendChild(document.createTextNode(menmet));
		//opt.appendChild(document.createTextNode(this.months_sh[i]));
		this.monthSelect.appendChild(opt);
		if (m==12) {
			m = 1
			y++
			}
		else m++
		
	}
	n = this.name
	this.monthSelect.name = "menmetai"+n
	this.yearSelect.name = "diena"+n
	this.monthSelect.id = "menmetai"+n
	this.yearSelect.id = "diena"+n
	this.yearSelect.value = diena
	this.yearSelect.size = 2
	this.yearSelect.setAttribute('readOnly', true);
	//and fill the year select box
	/*for(i=this.rangeYearLower;i<=this.rangeYearUpper;i++)
	{
		opt = document.createElement('option');
		opt.setAttribute('value',i);
		if(this.state == 0 && this.displayYear == i) {
			opt.setAttribute('selected','selected');
		}
		opt.appendChild(document.createTextNode(i));
		this.yearSelect.appendChild(opt);		
	}*/
	//add the appropriate children for the month buttons
	monthUp.setAttribute('type','button');
	monthUp.setAttribute('value','>');
	monthUp.setAttribute('title',this.monthup_title);
	monthDn.setAttribute('type','button');
	monthDn.setAttribute('value','<');
	monthDn.setAttribute('title',this.monthdn_title);
	this.monthSelect.owner = this.yearSelect.owner = monthUp.owner = monthDn.owner = this;  //hack to allow us to access this calendar in the events (<fix>??)
	
	//assign the event handlers for the controls
	monthUp.onmouseup = function () {this.owner.nextMonth();};
	monthDn.onmouseup = function () {this.owner.prevMonth();};
	this.monthSelect.onchange = function() {
		var dataval = this.value.split("/")
		//this.owner.displayMonth = this.value; 
		this.owner.displayMonth = dataval[0]-1;
		this.owner.displayYear = dataval[1]
		this.owner.displayDay = this.owner.yearSelect.value; 
		//this.owner.displayYear = this.owner.yearSelect.value; 
		this.owner.goToMonth(this.owner.displayYear,this.owner.displayMonth,this.owner.displayDay);
	};
	this.yearSelect.onchange = function() {
		this.owner.displayMonth = this.owner.monthSelect.value;
		this.owner.displayYear = this.value; 
		this.owner.goToMonth(this.owner.displayYear,this.owner.displayMonth);
	};
	
	//and finally add the elements to the containing div
	//container.appendChild(monthDn);
	container.appendChild(this.monthSelect);
	container.appendChild(this.yearSelect);
	//container.appendChild(monthUp);
	return container;
};
//-----------------------------------------------------------------------------
Epoch.prototype.createFooter = function () //PRIVATE: creates the footer of the calendar - goes under the calendar cells
{
	var container = document.createElement('div');
	var clearSelected = document.createElement('input');
	clearSelected.setAttribute('type','button');
	clearSelected.setAttribute('value',this.clearbtn_caption);
	clearSelected.setAttribute('title',this.clearbtn_title);
	clearSelected.owner = this;
	clearSelected.onclick = function() { this.owner.resetSelections(false);};
	container.appendChild(clearSelected);
	return container;
};
//-----------------------------------------------------------------------------
Epoch.prototype.resetSelections = function (returnToDefaultMonth)  //PRIVATE: reset the calendar's selection variables to defaults
{
	this.selectedDates = new Array();
	this.rows = new Array(false,false,false,false,false,false,false);
	this.cols = new Array(false,false,false,false,false,false,false);
	if(this.tgt)  //if there is a target element, clear it too
	{
		this.tgt.value = '';
		if(this.mode == 'popup') {//hide the calendar if in popup mode
			this.hide();
		}
	}
		
	if(returnToDefaultMonth == true) {
		this.goToMonth(this.displayYearInitial,this.displayMonthInitial);
	}
	else {
		this.reDraw();
	}
};
//-----------------------------------------------------------------------------
Epoch.prototype.createDayHeading = function ()  //PRIVATE: creates the heading containing the day names
{
	//create the table element
	this.calHeading = document.createElement('table');
	this.calHeading.setAttribute('id',this.name+'_caldayheading');
	this.setClass(this.calHeading,'caldayheading');
	var tbody,tr,td;
	tbody = document.createElement('tbody');
	tr = document.createElement('tr');
	this.cols = new Array(false,false,false,false,false,false,false);
	
	//if we're showing the week headings, create an empty <td> for filler
	if(this.showWeeks)
	{
		td = document.createElement('td');
		td.setAttribute('class','wkhead');
		td.setAttribute('className','wkhead'); //<iehack>
		tr.appendChild(td);
	}
	//populate the day titles
	for(var dow=0;dow<7;dow++)
	{
		td = document.createElement('td');
		td.appendChild(document.createTextNode(this.daynames[dow]));
		if(this.selectMultiple) { //if selectMultiple is true, assign the cell a CalHeading Object to handle all events
			td.headObj = new CalHeading(this,td,(dow + this.startDay < 7 ? dow + this.startDay : dow + this.startDay - 7));
		}
		tr.appendChild(td);
	}
	tbody.appendChild(tr);
	this.calHeading.appendChild(tbody);
	return this.calHeading;	
};
//-----------------------------------------------------------------------------
Epoch.prototype.createCalCells = function ()  //PRIVATE: creates the table containing the calendar day cells
{
	this.rows = new Array(false,false,false,false,false,false);
	this.cells = new Array();
	var row = -1, totalCells = (this.showWeeks ? 48 : 42);
	var beginDate = new Date(this.displayYear,this.displayMonth,1);
	var endDate = new Date(this.displayYear,this.displayMonth,this.monthDayCount[this.displayMonth]);
	var sdt = new Date(beginDate);
	sdt.setDate(sdt.getDate() + (this.startDay - beginDate.getDay()) - (this.startDay - beginDate.getDay() > 0 ? 7 : 0) );
	//create the table element
	this.calCells = document.createElement('table');
	this.calCells.setAttribute('id',this.name+'_calcells');
	this.setClass(this.calCells,'calcells');
	var tbody,tr,td;
	tbody = document.createElement('tbody');
	for(var i=0;i<totalCells;i++)
	{
		if(this.showWeeks) //if we are showing the week headings
		{
			if(i % 8 == 0)
			{
				row++;
				tr = document.createElement('tr');
				td = document.createElement('td');
				if(this.selectMultiple) { //if selectMultiple is enabled, create the associated weekObj objects
					td.weekObj = new WeekHeading(this,td,sdt.getWeek(),row)
				}
				else //otherwise just set the class of the td for consistent look
				{
					td.setAttribute('class','wkhead');
					td.setAttribute('className','wkhead'); //<iehack>
				}
				td.appendChild(document.createTextNode(sdt.getWeek()));			
				tr.appendChild(td);
				i++;
			}
		}
		else if(i % 7 == 0) //otherwise, new row every 7 cells
		{
			row++;
			tr = document.createElement('tr');
		}
		//create the day cells
		td = document.createElement('td');
		td.appendChild(document.createTextNode(sdt.getDate()));// +' ' +sdt.getUeDay()));
		var cell = new CalCell(this,td,sdt,row);
		this.cells.push(cell);
		td.cellObj = cell;
		sdt.setDate(sdt.getDate() + 1); //increment the date
		tr.appendChild(td);
		tbody.appendChild(tr);
	}
	this.calCells.appendChild(tbody);
	this.reDraw();
	return this.calCells;
};
//-----------------------------------------------------------------------------
Epoch.prototype.reDraw = function () //PRIVATE: reapplies all the CSS classes for the calendar cells, usually called after chaning their state
{
	this.state = 1;
	var i,j;
	for(i=0;i<this.cells.length;i++) {
		this.cells[i].selected = false;
	}
	for(i=0;i<this.cells.length;i++)
	{
		for(j=0;j<this.selectedDates.length;j++) { //if the cell's date is in the selectedDates array, set its selected property to true
			if(this.cells[i].date.getUeDay() == this.selectedDates[j].getUeDay() ) {
				this.cells[i].selected = true;
			}
		}

		this.cells[i].setClass();
	}
	//alert(this.selectedDates);
	this.state = 2;
};
//-----------------------------------------------------------------------------
Epoch.prototype.deleteCells = function () //PRIVATE: removes the calendar cells from the DOM (does not delete the cell objects associated with them
{
	this.calCellContainer.removeChild(this.calCellContainer.firstChild); //get a handle on the cell table (optional - for less indirection)
	this.cells = new Array(); //reset the cells array
};
//-----------------------------------------------------------------------------
Epoch.prototype.goToMonth = function (year,month,day) //PUBLIC: sets the calendar to display the requested month/year
{
	this.monthSelect.value = (month+1)+'/'+year
	this.displayMonth = Number(month);
	this.yearSelect.value = day;
	this.displayYear = year
	this.deleteCells();
	this.calCellContainer.appendChild(this.createCalCells());
	};
//-----------------------------------------------------------------------------
Epoch.prototype.nextMonth = function () //PUBLIC: go to the next month.  if the month is december, go to january of the next year
{
	
	//increment the month/year values, provided they're within the min/max ranges
	if(this.monthSelect.value < 11) {
		this.monthSelect.value++;
	}
	else
	{
		if(this.yearSelect.value < this.rangeYearUpper)
		{
			this.monthSelect.value = 0;
			this.yearSelect.value++;
		}
		else {
			alert(this.maxrange_caption);
		}
	}
	//assign the currently displaying month/year values
	this.displayMonth = this.monthSelect.value;
	this.displayYear = this.yearSelect.value;
	
	//and refresh the calendar for the new month/year
	this.deleteCells();
	this.calCellContainer.appendChild(this.createCalCells());
};
//-----------------------------------------------------------------------------
Epoch.prototype.prevMonth = function () //PUBLIC: go to the previous month.  if the month is january, go to december of the previous year
{
	//increment the month/year values, provided they're within the min/max ranges
	if(this.monthSelect.value > 0)
		this.monthSelect.value--;
	else
	{
		if(this.yearSelect.value > this.rangeYearLower)
		{
			this.monthSelect.value = 11;
			this.yearSelect.value--;
		}
		else {
			alert(this.maxrange_caption);
		}
	}
	
	//assign the currently displaying month/year values
	this.displayMonth = this.monthSelect.value;
	this.displayYear = this.yearSelect.value;
	
	//and refresh the calendar for the new month/year
	this.deleteCells();
	this.calCellContainer.appendChild(this.createCalCells());
};
//-----------------------------------------------------------------------------
Epoch.prototype.addZero = function (vNumber) //PRIVATE: pads a 2 digit number with a leading zero
{
	return ((vNumber < 10) ? '0' : '') + vNumber;
};
//-----------------------------------------------------------------------------
Epoch.prototype.addDates = function (dates,redraw)  //PUBLIC: adds the array "dates" to the calendars selectedDates array (no duplicate dates) and redraws the calendar
{
	var j,in_sd;
	for(var i=0;i<dates.length;i++)
	{	
		in_sd = false;
		for(j=0;j<this.selectedDates.length;j++)
		{
			if(dates[i].getUeDay() == this.selectedDates[j].getUeDay())
			{
				in_sd = true;
				break;
			}
		}
		if(!in_sd) { //if the date isn't already in the array, add it!
			this.selectedDates.push(dates[i]);
		}
	}
	if(redraw != false) {//redraw  the calendar if "redraw" is false or undefined
		this.reDraw();
	}
};
//-----------------------------------------------------------------------------
Epoch.prototype.removeDates = function (dates,redraw)  //PUBLIC: adds the dates to the calendars selectedDates array and redraws the calendar
{
	var j;
	for(var i=0;i<dates.length;i++)
	{
		for(j=0;j<this.selectedDates.length;j++)
		{
			if(dates[i].getUeDay() == this.selectedDates[j].getUeDay()) { //search for the dates in the selectedDates array, removing them if the dates match
				this.selectedDates.splice(j,1);
			}
		}
	}
	if(redraw != false) { //redraw  the calendar if "redraw" is false or undefined
		this.reDraw();
	}
};
//-----------------------------------------------------------------------------
Epoch.prototype.outputDate = function (vDate, vFormat) //PUBLIC: outputs a date in the appropriate format (DEPRECATED)
{
	var vDay			= this.addZero(vDate.getDate()); 
	var vMonth			= this.addZero(vDate.getMonth() + 1); 
	var vYearLong		= this.addZero(vDate.getFullYear()); 
	var vYearShort		= this.addZero(vDate.getFullYear().toString().substring(3,4)); 
	var vYear			= (vFormat.indexOf('yyyy') > -1 ? vYearLong : vYearShort);
	var vHour			= this.addZero(vDate.getHours()); 
	var vMinute			= this.addZero(vDate.getMinutes()); 
	var vSecond			= this.addZero(vDate.getSeconds()); 
	return vFormat.replace(/dd/g, vDay).replace(/mm/g, vMonth).replace(/y{1,4}/g, vYear).replace(/hh/g, vHour).replace(/nn/g, vMinute).replace(/ss/g, vSecond);
};
//-----------------------------------------------------------------------------
Epoch.prototype.updatePos = function (target) //PUBLIC: moves the calendar's position to target's location (popup mode only)
{
	this.calendar.style.top = this.getTop(target) + this.topOffset + 'px'
	this.calendar.style.left = this.getLeft(target) + this.leftOffset + 'px'
}
//-----------------------------------------------------------------------------

/*****************************************************************************/
function CalHeading(owner,tableCell,dow)
{
	this.owner = owner;
	this.tableCell = tableCell;
	this.dayOfWeek = dow;
	
	//the event handlers
	this.tableCell.onclick = this.onclick;
}
//-----------------------------------------------------------------------------
CalHeading.prototype.onclick = function ()
{
	//reduce indirection:
	var owner = this.headObj.owner;
	var sdates = owner.selectedDates;
	var cells = owner.cells;
	
	owner.cols[this.headObj.dayOfWeek] = !owner.cols[this.headObj.dayOfWeek];
	for(var i=0;i<cells.length;i++) //cycle through all the cells in the calendar, selecting all cells with the same dayOfWeek as this heading
	{
		if(cells[i].dayOfWeek == this.headObj.dayOfWeek && (!owner.selCurMonthOnly || cells[i].date.getMonth() == owner.displayMonth && cells[i].date.getFullYear() == owner.displayYear)) //if the cell's DoW matches, with other conditions
		{
			if(owner.cols[this.headObj.dayOfWeek]) 		//if selecting, add the cell's date to the selectedDates array
			{
				if(owner.selectedDates.arrayIndex(cells[i].date) == -1) { //if the date isn't already in the array
					sdates.push(cells[i].date);
				}
			}
			else										//otherwise, remove it
			{
				for(var j=0;j<sdates.length;j++) 
				{
					if(cells[i].dayOfWeek == sdates[j].getDay())
					{
						sdates.splice(j,1);	//remove dates that are within the displaying month/year that have the same day of week as the day cell
						break;
					}
				}
			}
			cells[i].selected = owner.cols[this.headObj.dayOfWeek];
		}
	}
	owner.reDraw();
};
/*****************************************************************************/
function WeekHeading(owner,tableCell,week,row)
{
	this.owner = owner;
	this.tableCell = tableCell;
	this.week = week;
	this.tableRow = row;
	this.tableCell.setAttribute('class','wkhead');
	this.tableCell.setAttribute('className','wkhead'); //<iehack>
	//the event handlers
	this.tableCell.onclick = this.onclick;
}
//-----------------------------------------------------------------------------
WeekHeading.prototype.onclick = function ()
{
	//reduce indirection:
	var owner = this.weekObj.owner;
	var cells = owner.cells;
	var sdates = owner.selectedDates;
	var i,j;
	owner.rows[this.weekObj.tableRow] = !owner.rows[this.weekObj.tableRow];
	for(i=0;i<cells.length;i++)
	{
		if(cells[i].tableRow == this.weekObj.tableRow)
		{
			if(owner.rows[this.weekObj.tableRow] && (!owner.selCurMonthOnly || cells[i].date.getMonth() == owner.displayMonth && cells[i].date.getFullYear() == owner.displayYear)) //match all cells in the current row, with option to restrict to current month only
			{
				if(owner.selectedDates.arrayIndex(cells[i].date) == -1) {//if the date isn't already in the array
					sdates.push(cells[i].date);
				}
			}
			else										//otherwise, remove it
			{
				for(j=0;j<sdates.length;j++)
				{
					if(sdates[j].getTime() == cells[i].date.getTime())  //this.weekObj.tableRow && sdates[j].getMonth() == owner.displayMonth && sdates[j].getFullYear() == owner.displayYear)
					{
						sdates.splice(j,1);	//remove dates that are within the displaying month/year that have the same day of week as the day cell
						break;
					}
				}
			}
		}
	}
	owner.reDraw();
};
/*****************************************************************************/
//-----------------------------------------------------------------------------
function CalCell(owner,tableCell,dateObj,row)
{
	this.owner = owner;		//used primarily for event handling
	this.tableCell = tableCell; 			//the link to this cell object's table cell in the DOM
	this.cellClass;			//the CSS class of the cell
	this.selected = false;	//whether the cell is selected (and is therefore stored in the owner's selectedDates array)
	this.date = new Date(dateObj);
	this.dayOfWeek = this.date.getDay();
	this.week = this.date.getWeek();
	this.tableRow = row;
	
	//assign the event handlers for the table cell element
	this.tableCell.onclick = this.onclick;
	this.tableCell.onmouseover = this.onmouseover;
	this.tableCell.onmouseout = this.onmouseout;
	
	//and set the CSS class of the table cell
	this.setClass();
}
//-----------------------------------------------------------------------------
CalCell.prototype.onmouseover = function () //replicate CSS :hover effect for non-supporting browsers <iehack>
{
	this.setAttribute('class',this.cellClass + ' hover');
	this.setAttribute('className',this.cellClass + ' hover');
};
//-----------------------------------------------------------------------------
CalCell.prototype.onmouseout = function () //replicate CSS :hover effect for non-supporting browsers <iehack>
{
	this.cellObj.setClass();
};
//-----------------------------------------------------------------------------
CalCell.prototype.onclick = function () 
{
	//reduce indirection:
	var cell = this.cellObj;
	var owner = cell.owner;
	if(!owner.selCurMonthOnly || cell.date.getMonth() == owner.displayMonth && cell.date.getFullYear() == owner.displayYear)
	{
		if(owner.selectMultiple == true)  //if we can select multiple cells simultaneously, add the currently selected cell's date to the selectedDates array
		{
			if(!cell.selected) //if this cell has been selected
			{
				if(owner.selectedDates.arrayIndex(cell.date) == -1) {
					owner.selectedDates.push(cell.date);
				}
			}
			else		
			{
				var tmp = owner.selectedDates; // to reduce indirection
				//if the cell has been deselected, remove it from the owner calendar's selectedDates array
				for(var i=0;i<tmp.length;i++)
				{
					if(tmp[i].getUeDay() == cell.date.getUeDay()) {
						tmp.splice(i,1);
					}
				}
			}
		}
		else //if we can only select one cell at a time
		{
			owner.selectedDates = new Array(cell.date);
			if(owner.tgt) //if there is a target element to place the value in, do so
			{
				owner.tgt.value = owner.selectedDates[0].dateFormat();
				if(owner.mode == 'popup') {
					owner.hide();
				}
			}
		}
		//owner.selectedDates = 11;//TTTTT
		owner.reDraw(); //redraw the calendar cell styles to reflect the changes
		var a = new Date(owner.selectedDates[0])
		var dd = a.getDate()
		var mm = a.getMonth()
		var yy = a.getFullYear()
		//document.write(dd)
		owner.goToMonth(yy,mm,dd)
	}
};
//-----------------------------------------------------------------------------
CalCell.prototype.setClass = function ()  //private: sets the CSS class of the cell based on the specified criteria
{
	if(this.selected) {
		this.cellClass = 'cell_selected';
	}
	else if(this.owner.displayMonth != this.date.getMonth() ) {
		this.cellClass = 'notmnth';	
	}
	else if(this.date.getDay() > 0 && this.date.getDay() < 6) {
		this.cellClass = 'wkday';
	}
	else {
		this.cellClass = 'wkend';
	}
	
	if(this.date.getFullYear() == this.owner.curDate.getFullYear() && this.date.getMonth() == this.owner.curDate.getMonth() && this.date.getDate() == this.owner.curDate.getDate()) {
		this.cellClass = this.cellClass + ' curdate';
	}

	this.tableCell.setAttribute('class',this.cellClass);
	this.tableCell.setAttribute('className',this.cellClass); //<iehack>
};
/*****************************************************************************/
Date.prototype.getDayOfYear = function () //returns the day of the year for this date
{
	return parseInt((this.getTime() - new Date(this.getFullYear(),0,1).getTime())/86400000 + 1);
};
//-----------------------------------------------------------------------------
Date.prototype.getWeek = function () //returns the day of the year for this date
{
	return parseInt((this.getTime() - new Date(this.getFullYear(),0,1).getTime())/604800000 + 1);
};
/*function getISOWeek()
{
	var newYear = new Date(this.getFullYear(),0,1);
	var modDay = newYear.getDay();
	if (modDay == 0) modDay=6; else modDay--;
	
	var daynum = ((Date.UTC(this.getFullYear(),this.getMonth(),this.getDate(),0,0,0) - Date.UTC(this.getFullYear()),0,1,0,0,0)) /1000/60/60/24) + 1;
	
	if (modDay < 4 ) {
	    var weeknum = Math.floor((daynum+modDay-1)/7)+1;
	}
	else {
	    var weeknum = Math.floor((daynum+modDay-1)/7);
	    if (weeknum == 0) {
	        year--;
	        var prevNewYear = new Date(this.getFullYear(),0,1);
	        var prevmodDay = prevNewYear.getDay();
	        if (prevmodDay == 0) prevmodDay = 6; else prevmodDay--;
	        if (prevmodDay < 4) weeknum = 53; else weeknum = 52;
	    }
	}
	
	return + weeknum;
}*/
//-----------------------------------------------------------------------------
Date.prototype.getUeDay = function () //returns the number of DAYS since the UNIX Epoch - good for comparing the date portion
{
	return parseInt(Math.floor((this.getTime() - this.getTimezoneOffset() * 60000)/86400000)); //must take into account the local timezone
};
//-----------------------------------------------------------------------------
Date.prototype.dateFormat = function(format)
{
	if(!format) { // the default date format to use - can be customized to the current locale
		format = 'm/d/Y';
	}
	LZ = function(x) {return(x < 0 || x > 9 ? '' : '0') + x};
	var MONTH_NAMES = new Array('January','February','March','April','May','June','July','August','September','October','November','December','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
	var DAY_NAMES = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sun','Mon','Tue','Wed','Thu','Fri','Sat');
	format = format + "";
	var result="";
	var i_format=0;
	var c="";
	var token="";
	var y=this.getFullYear().toString();
	var M=this.getMonth()+1;
	var d=this.getDate();
	var E=this.getDay();
	var H=this.getHours();
	var m=this.getMinutes();
	var s=this.getSeconds();
	var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,HH,H,KK,K,kk,k;
	// Convert real this parts into formatted versions
	var value = new Object();
	//if (y.length < 4) {y=''+(y-0+1900);}
	value['Y'] = y.toString();
	value['y'] = y.substring(2);
	value['n'] = M;
	value['m'] = LZ(M);
	value['F'] = MONTH_NAMES[M-1];
	value['M'] = MONTH_NAMES[M+11];
	value['j'] = d;
	value['d'] = LZ(d);
	value['D'] = DAY_NAMES[E+7];
	value['l'] = DAY_NAMES[E];
	value['G'] = H;
	value['H'] = LZ(H);
	if (H==0) {value['g']=12;}
	else if (H>12){value['g']=H-12;}
	else {value['g']=H;}
	value['h']=LZ(value['g']);
	if (H > 11) {value['a']='pm'; value['A'] = 'PM';}
	else { value['a']='am'; value['A'] = 'AM';}
	value['i']=LZ(m);
	value['s']=LZ(s);
	//construct the result string
	while (i_format < format.length) {
		c=format.charAt(i_format);
		token="";
		while ((format.charAt(i_format)==c) && (i_format < format.length)) {
			token += format.charAt(i_format++);
			}
		if (value[token] != null) { result=result + value[token]; }
		else { result=result + token; }
		}
	return result;
};
/*****************************************************************************/
Array.prototype.arrayIndex = function(searchVal,startIndex) //similar to array.indexOf() - created to fix IE deficiencies
{
	startIndex = (startIndex != null ? startIndex : 0); //default startIndex to 0, if not set
	for(var i=startIndex;i<this.length;i++)
	{
		if(searchVal == this[i]) {
			return i;
		}
	}
	return -1;
};
/*****************************************************************************/
	//////IFRAMEui KELIONEMS/////////
function framesize(dydis)
{
	parent.parent.document.getElementById("the_iframe").style.height = dydis
	//a = parent.parent.document.getElementById("the_iframe").style.height
	//alert(a)
}
