function fullyear(checkyear){
if (checkyear.length==0 || checkyear.length==2){
showshort=false;
if (checkyear.length==2){
showshort=true;
showyear=checkyear;}
currdate = new Date();
checkyear=""+currdate.getFullYear();
if (showshort==true){
showyearnew=checkyear.substring(2,4);
if(showyearnew>50)
addyear=1;
else
addyear=0;
if(showyear-30>0)
checkyear=Number(checkyear.substring(0,2)-1)+addyear+""+showyear;
else
checkyear=Number(checkyear.substring(0,2))+addyear+""+showyear;}}
return checkyear;}
function formcheckdate (formname, fieldname, date_format, onlycheck){
if (!checkinit)
formcheckinit();
if (typeof(date_format)=="undefined") date_format="d.m.Y";
if (typeof(onlycheck)=="undefined") onlycheck=false;
if (document.forms[formname].elements[fieldname])
checkdate = document.forms[formname].elements[fieldname].value;
if (checkdate>""){
datevalid=true;
cut_list="./, ";
date_list="dmY";
date_cut_first=0; date_cut_second=0; date_cut_first_pos=0; date_cut_second_pos=0;
for (i=0;i<cut_list.length;i++){
if (date_cut_first<=0) date_cut_first=date_format.indexOf(cut_list.charAt(i));
if (date_cut_first_pos<=0) date_cut_first_pos=checkdate.indexOf(cut_list.charAt(i));
if (date_cut_second<=0) date_cut_second=date_format.lastIndexOf(cut_list.charAt(i));
if (date_cut_second_pos<=0) date_cut_second_pos=checkdate.lastIndexOf(cut_list.charAt(i));}
date_cut_first_char = date_format.substr(date_cut_first,1);
date_cut_second_char = date_format.substr(date_cut_second,1);
datepart=new Array();
datepos=new Array();
for (counter=0; counter<3; counter++){
switch(counter){
case 0:
date_currpart=date_format.substr(0,date_cut_first);
date_currvalue=checkdate.substr(0,date_cut_first_pos);
break;
case 1:
date_currpart=date_format.substr(date_cut_first+1,date_cut_second-date_cut_first-1);
date_currvalue=checkdate.substr(date_cut_first_pos+1,date_cut_second_pos-date_cut_first_pos-1);
break;
case 2:
date_currpart=date_format.substr(date_cut_second+1,date_format.length-date_cut_second-1);
date_currvalue=checkdate.substr(date_cut_second_pos+1,checkdate.length-date_cut_second_pos-1);
break;}
switch(date_currpart){
case "d":
case "D":
date_partname="day";
break;
case "m":
case "M":
date_partname="month";
break;
case "y":
case "Y":
date_partname="year";
break;}
datepart[date_partname]=new Array();
datepart[date_partname]["pos"]=counter;
datepart[date_partname]["format"]=date_currpart;
datepart[date_partname]["value"]=date_currvalue;
datepos[counter]=date_partname;}
datelast=checkdate;
currdate = new Date();
checkmonth=datepart["month"]["value"];
if ((checkmonth<1) || (checkmonth>12) || (checkmonth==null) || (checkmonth=="")){
checkmonth = currdate.getMonth();
datevalid=false;}
else
checkmonth=checkmonth-1;
checkday=datepart["day"]["value"];
if (checkday.substring(0,1)=="0") checkday=checkday.substring(1,2);
if ((checkday<1) || (checkday>31) || (checkday==null) || (checkday=="")){
checkday = currdate.getDate();
datevalid=false;}
checkyear=datepart["year"]["value"];
checkyear=fullyear(checkyear);
if (checkyear.length!=4)
datevalid=false;
if (datevalid==true){
if (onlycheck==false){
if (checkday.length==1)
checkday="0"+checkday;
checkmonth=Number(checkmonth)+1+"";
if (checkmonth.length==1)
checkmonth="0"+checkmonth;
datepart["day"]["corrected"]=checkday;
datepart["month"]["corrected"]=checkmonth;
datepart["year"]["corrected"]=checkyear;
datereturn=datepart[datepos[0]]["corrected"]+date_cut_first_char+datepart[datepos[1]]["corrected"]+date_cut_second_char+datepart[datepos[2]]["corrected"];
if (datereturn!=datelast)
document.forms[formname].elements[fieldname].value=datereturn;}
swapimage(fieldname+"image", "image_valid");}
else{
if (onlycheck==false){
if (checkdate!="")
document.forms[formname].elements[fieldname].value="";}
swapimage(fieldname+"image", "image_invalid");}}
else{
if (onlycheck==false)
document.forms[formname].elements[fieldname].value="";
swapimage(fieldname+"image", "image_invalid");}}
function formchecktime (formname, fieldname, time_format, onlycheck){
if (!checkinit)
formcheckinit();
if (typeof(time_format)=="undefined") time_format="H:i:s";
if (typeof(onlycheck)=="undefined") onlycheck=false;
if (document.forms[formname].elements[fieldname])
checktime = document.forms[formname].elements[fieldname].value;
if (checktime>""){
if(checktime.substr(checktime.length-1,1)!=":" && checktime.indexOf(":")==checktime.lastIndexOf(":"))
checktime+=":";
timevalid=true;
cut_list=":- ";
time_list="His";
time_cut_first=0; time_cut_second=0; time_cut_first_pos=0; time_cut_second_pos=0;
for (i=0;i<cut_list.length;i++){
if (time_cut_first<=0) time_cut_first=time_format.indexOf(cut_list.charAt(i));
if (time_cut_first_pos<=0) time_cut_first_pos=checktime.indexOf(cut_list.charAt(i));
if (time_cut_second<=0) time_cut_second=time_format.lastIndexOf(cut_list.charAt(i));
if (time_cut_second_pos<=0) time_cut_second_pos=checktime.lastIndexOf(cut_list.charAt(i));}
time_cut_first_char = time_format.substr(time_cut_first,1);
time_cut_second_char = time_format.substr(time_cut_second,1);
timepart=new Array();
timepos=new Array();
for (counter=0; counter<3; counter++){
switch(counter){
case 0:
time_currpart=time_format.substr(0,time_cut_first);
time_currvalue=checktime.substr(0,time_cut_first_pos);
break;
case 1:
time_currpart=time_format.substr(time_cut_first+1,time_cut_second-time_cut_first-1);
time_currvalue=checktime.substr(time_cut_first_pos+1,time_cut_second_pos-time_cut_first_pos-1);
break;
case 2:
time_currpart=time_format.substr(time_cut_second+1,time_format.length-time_cut_second-1);
time_currvalue=checktime.substr(time_cut_second_pos+1,checktime.length-time_cut_second_pos-1);
break;}
switch(time_currpart){
case "h":
case "H":
time_partname="hour";
break;
case "i":
case "I":
time_partname="minute";
break;
case "s":
case "S":
time_partname="second";
break;}
timepart[time_partname]=new Array();
timepart[time_partname]["pos"]=counter;
timepart[time_partname]["format"]=time_currpart;
timepart[time_partname]["value"]=time_currvalue;
timepos[counter]=time_partname;}
timelast=checktime;
checkhour=timepart["hour"]["value"];
if (checkhour.substring(0,1)=="0" && checkhour.length>1) checkhour=checkhour.substring(1,2);
if ((checkhour<0) || (checkhour>23) || (checkhour==null) || (checkhour==""))
timevalid=false;
checkminute=timepart["minute"]["value"];
if (checkminute.substring(0,1)=="0" && checkminute.length>1) checkminute=checkminute.substring(1,2);
if (checkminute=="")
checkminute="0";
else{
if ((checkminute<0) || (checkminute>59) || (checkminute==null) || (checkminute==""))
timevalid=false;}
checksecond=timepart["second"]["value"];
if (checksecond.substring(0,1)=="0" && checksecond.length>1) checksecond=checksecond.substring(1,2);
if (checksecond=="")
checksecond="0";
else{
if ((checksecond<0) || (checksecond>59) || (checksecond==null))
timevalid=false;}
if (timevalid==true){
if (onlycheck==false){
if (checkhour.length==1)
checkhour="0"+checkhour;
if (checkminute.length==1)
checkminute="0"+checkminute;
if (checksecond.length==1)
checksecond="0"+checksecond;
timepart["hour"]["corrected"]=checkhour;
timepart["minute"]["corrected"]=checkminute;
timepart["second"]["corrected"]=checksecond;
timereturn=timepart[timepos[0]]["corrected"]+time_cut_first_char+timepart[timepos[1]]["corrected"]+time_cut_second_char+timepart[timepos[2]]["corrected"];
if (timereturn!=timelast)
document.forms[formname].elements[fieldname].value=timereturn;}
swapimage(fieldname+"image", "image_valid");}
else{
if (onlycheck==false){
if (checktime!="")
document.forms[formname].elements[fieldname].value="";}
swapimage(fieldname+"image", "image_invalid");}}
else{
if (onlycheck==false)
document.forms[formname].elements[fieldname].value="";
swapimage(fieldname+"image", "image_invalid");}}
function formcheckdateformat(formname,fieldname,datepart,charcount,numbermin,numbermax,nullbefore){
checkvalue=document.forms[formname].elements[fieldname+"_seivalues["+datepart+"]"].value;
if (checkvalue>"" && Number(checkvalue)==checkvalue){
checkvalue=Number(checkvalue);
numbervalid=true;
if (numbermin!=null){
if (checkvalue<numbermin)
checkvalue=numbermin;}
if (numbermax!=null){
if (checkvalue>numbermax)
checkvalue=numbermax;}
if (checkvalue.length>charcount)
checkvalue=numbermax;
if (nullbefore==true){
checkvalue=""+checkvalue;
for (counter=0; counter<(charcount-checkvalue.length); counter++)
checkvalue="0"+checkvalue;}}
else
numbervalid=false;
document.forms[formname].elements[fieldname+"_seivalues["+datepart+"]"].value=checkvalue;
if (numbervalid==true)
swapimage(fieldname+"image", "image_valid");
else
swapimage(fieldname+"image", "image_invalid");
if (numbervalid==true){
if (datepart=="y"){
curryear=document.forms[formname].elements[fieldname+"_seivalues[y]"].value;
if (curryear.length==1)
curryear="0"+curryear;
document.forms[formname].elements[fieldname+"_seivalues[y]"].value=curryear;}
if (datepart=="Y"){
curryear=document.forms[formname].elements[fieldname+"_seivalues[Y]"].value;
if (curryear.length==1)
curryear="0"+curryear;
curryear=fullyear(curryear);
document.forms[formname].elements[fieldname+"_seivalues[Y]"].value=curryear;}
if (datepart=="H" || datepart=="G"){
if (typeof(document.forms[formname].elements[fieldname+"_seivalues[i]"])=="object"){
if (document.forms[formname].elements[fieldname+"_seivalues[i]"].value==""){
document.forms[formname].elements[fieldname+"_seivalues[i]"].value="00";}}
if (typeof(document.forms[formname].elements[fieldname+"_seivalues[s]"])=="object"){
if (document.forms[formname].elements[fieldname+"_seivalues[s]"].value==""){
document.forms[formname].elements[fieldname+"_seivalues[s]"].value="00";}}}
if (datepart=="d" || datepart=="j"){
nextyear=false;
if (typeof(document.forms[formname].elements[fieldname+"_seivalues[n]"])=="object"){
if (document.forms[formname].elements[fieldname+"_seivalues[n]"].value==""){
currdate = new Date();
currmonth = currdate.getMonth()+1;
currday = currdate.getDate();
if (currday>Number(checkvalue)){
if (currmonth<12)
currmonth++;
else{
currmonth=1;
nextyear=true;}}
document.forms[formname].elements[fieldname+"_seivalues[n]"].value=currmonth;}}
if (typeof(document.forms[formname].elements[fieldname+"_seivalues[m]"])=="object"){
if (document.forms[formname].elements[fieldname+"_seivalues[m]"].value==""){
currdate = new Date();
currmonth = currdate.getMonth()+1;
currday = currdate.getDate();
if (currday>Number(checkvalue)){
if (currmonth<12)
currmonth++;
else{
currmonth=1;
nextyear=true;}}
currmonth=""+currmonth;
if (currmonth.length==1)
currmonth="0"+currmonth;
document.forms[formname].elements[fieldname+"_seivalues[m]"].value=currmonth;}}
if (typeof(document.forms[formname].elements[fieldname+"_seivalues[y]"])=="object"){
if (document.forms[formname].elements[fieldname+"_seivalues[y]"].value==""){
currdate = new Date();
curryear = currdate.getFullYear();
if (nextyear==true)
curryear++;
document.forms[formname].elements[fieldname+"_seivalues[y]"].value=curryear;}}
if (typeof(document.forms[formname].elements[fieldname+"_seivalues[Y]"])=="object"){
if (document.forms[formname].elements[fieldname+"_seivalues[Y]"].value==""){
currdate = new Date();
curryear = currdate.getFullYear();
if (nextyear==true)
curryear++;
document.forms[formname].elements[fieldname+"_seivalues[Y]"].value=curryear;}}}}
dateformat=document.forms[formname].elements[fieldname+"_seivalues[format]"].value;
datevalue="";
for (counter=0; counter<dateformat.length; counter++){
currchar = dateformat.substr(counter,1);
switch(currchar){
case "Y":
case "y":
case "n":
case "m":
case "j":
case "d":
case "G":
case "H":
case "i":
case "s":
if (typeof(document.forms[formname].elements[fieldname+"_seivalues["+currchar+"]"])!="undefined")
datevalue+=document.forms[formname].elements[fieldname+"_seivalues["+currchar+"]"].value;
break;
default:
datevalue+=currchar;
break;}}
document.forms[formname].elements[fieldname].value = datevalue;
sei_fieldchange(formname, fieldname);}
function formeditdateformat(formname,fieldname,datepart,pointer,charcount,numbermin,numbermax,nullbefore){
var isNN = (navigator.appName.indexOf('Netscape')!=-1);
var keyCode = (isNN) ? pointer.which : pointer.keyCode;
switch(keyCode){
case 27:
currfield=document.forms[formname].elements[fieldname+"_seivalues["+datepart+"]"];
var index = -1, i = 0, found = false; firstfield=0;
while (i < document.forms[formname].length && index == -1){
if (document.forms[formname][i].name.substr(0,fieldname.length)==fieldname && document.forms[formname][i].name!=fieldname+"_seivalues[format]"){
if (firstfield==0)
firstfield=i;
document.forms[formname][i].value="";}
i++;}
if (firstfield>0)
sei_element_focus(formname, firstfield);
break;
case 35:
case 36:
currfield=document.forms[formname].elements[fieldname+"_seivalues["+datepart+"]"];
var index = -1, i = 0, found = false;
while (i < document.forms[formname].length && index == -1){
if (document.forms[formname][i] == currfield)
index = i;
else
i++;}
addindex=0;
found=true;
if (keyCode==35){
while(found==true){
addindex++;
if(typeof(document.forms[formname][index+addindex])=="object"){
if (document.forms[formname][index+addindex].name.substr(0,fieldname.length)!=fieldname || document.forms[formname][index+addindex].name==fieldname+"_seivalues[format]"){
found=false;
addindex--;}}}}
if (keyCode==36){
while(found==true){
addindex--;
if(typeof(document.forms[formname][index+addindex])=="object"){
if (document.forms[formname][index+addindex].name.substr(0,fieldname.length)!=fieldname || document.forms[formname][index+addindex].name==fieldname+"_seivalues[format]"){
found=false;
addindex++;}}}}
if(typeof(document.forms[formname][index+addindex])=="object"){
if (document.forms[formname][index+addindex].type!="hidden"){
newfieldname=document.forms[formname][index+addindex].name;
sei_element_focus(formname, newfieldname);
return false;}
else
return true;}
else
return true;
break;
case 38:
checkvalue=document.forms[formname].elements[fieldname+"_seivalues["+datepart+"]"].value;
if (Number(checkvalue)==checkvalue || checkvalue==""){
if (checkvalue==""){
currdate= new Date();
switch(datepart){
case "H": case "G": checkvalue=currdate.getHours(); break;
case "i": checkvalue=currdate.getMinutes(); break;
case "s": checkvalue=currdate.getSeconds(); break;
case "d": case "j": checkvalue=currdate.getDate(); break;
case "m": case "n": checkvalue=currdate.getMonth()+1; break;
case "Y": checkvalue=currdate.getFullYear(); break;
case "y": checkvalue=currdate.getFullYear(); checkvalue=checkvalue+""; checkvalue=checkvalue.substring(2,4); break;
default: checkvalue++; break;}}
else
checkvalue++;
if (checkvalue>numbermax)
checkvalue=numbermin;
document.forms[formname].elements[fieldname+"_seivalues["+datepart+"]"].value=checkvalue;
formcheckdateformat(formname,fieldname,datepart,charcount,numbermin,numbermax,nullbefore);
sei_element_focus(formname, fieldname+"_seivalues["+datepart+"]");}
break;
case 40:
checkvalue=document.forms[formname].elements[fieldname+"_seivalues["+datepart+"]"].value;
if (Number(checkvalue)==checkvalue || checkvalue==""){
if (checkvalue==""){
currdate= new Date();
switch(datepart){
case "H": case "G": checkvalue=currdate.getHours(); break;
case "i": checkvalue=currdate.getMinutes(); break;
case "s": checkvalue=currdate.getSeconds(); break;
case "d": case "j": checkvalue=currdate.getDate(); break;
case "m": case "n": checkvalue=currdate.getMonth()+1; break;
case "Y": checkvalue=currdate.getFullYear(); break;
case "y": checkvalue=currdate.getFullYear(); checkvalue=checkvalue+""; checkvalue=checkvalue.substring(2,4); break;
default: checkvalue++; break;}}
else
checkvalue--;
if (checkvalue<numbermin)
checkvalue=numbermax;
document.forms[formname].elements[fieldname+"_seivalues["+datepart+"]"].value=checkvalue;
formcheckdateformat(formname,fieldname,datepart,charcount,numbermin,numbermax,nullbefore);
sei_element_focus(formname, fieldname+"_seivalues["+datepart+"]");}
break;
case 9:
case 55:
if (!pointer.shiftKey)
return true;
case 32:
case 109:
case 111:
case 188:
case 189:
case 190:
currfield=document.forms[formname].elements[fieldname+"_seivalues["+datepart+"]"];
var index = -1, i = 0, found = false;
while (i < document.forms[formname].length && index == -1){
if (document.forms[formname][i] == currfield)
index = i;
else
i++;}
if (keyCode==9 && pointer.shiftKey)
addindex=-1;
else
addindex=1;
if(typeof(document.forms[formname][index+addindex])=="object"){
if (document.forms[formname][index+addindex].type!="hidden"){
document.forms[formname][index+addindex].focus();
return false;}
else
return true;}
else
return true;
break;}}
