/* JSTime - A Utility to get Server time i JavaScript Written By Helge Damsholt - May, 2003*/var count,ServerDateTime,Dp,Mp,Yp,Hp,Mip,Sp;TimeObjects = new Array();function SetJavaTime(y,mo,d,h,mi,s,Format){ServerDateTime=new Date(y,mo-1,d,h,mi,s);count=ServerDateTime.getSeconds()-1;}function AddServerTime(AddObj){AddIt = true;if (TimeObjects.length==0){TimeObjects[0]=AddObj;return true;}else{for(i=0;i<TimeObjects.length;i++){if(AddObj==TimeObjects[i])AddIt = false;}if(AddIt){TimeObjects[i]=AddObj;return true;}}}function isDate(Inn){InnStr = new String(Inn);if(InnStr.indexOf('Daylight')!=-1||InnStr.indexOf('UTC')!=-1){return true}else{return false}}function FormatDate(Inn,FormatStr,DateArray,MonthArray){var Tmp = "",Mnd=-1;Out = new String(FormatStr); if(isDate(Inn)){if(DateArray) Tmp = DateArray[Inn.getDay()];rExp=/DAY/;Out=Out.replace(rExp,Tmp); if(MonthArray.length-1!=-1){ Tmp=Inn.getDate(); /*Tmp=(Inn.getDate()<10)?"0"+Inn.getDate():Inn.getDate();*/ rExp=/DD/;Out=Out.replace(rExp,Tmp); Tmp=MonthArray[Inn.getMonth()]; rExp=/MO/; Out=Out.replace(rExp,Tmp); }else{ Tmp=(Inn.getDate()<10)?"0"+Inn.getDate():Inn.getDate(); rExp=/DD/; Out=Out.replace(rExp,Tmp); Tmp=(Inn.getMonth()<9)?"0"+(Inn.getMonth()+1):(Inn.getMonth()+1); rExp=/MO/; Out=Out.replace(rExp,Tmp); } Tmp=Inn.getFullYear();rExp=/YYYY/;Out=Out.replace("YYYY",Tmp);Tmp=(Inn.getHours()<10)?"0"+Inn.getHours():Inn.getHours();rExp=/HH/;Out=Out.replace(rExp,Tmp);Tmp=(Inn.getMinutes()<10)?"0"+Inn.getMinutes():Inn.getMinutes();rExp=/MI/;Out=Out.replace(rExp,Tmp);Tmp=(Inn.getSeconds()<10)?"0"+Inn.getSeconds():Inn.getSeconds();rExp=/SS/;Out=Out.replace(rExp,Tmp);return Out;}else{InnStr = new String(Inn); Dp1=Out.indexOf("DD");Mp1=Out.indexOf("MO");Yp1=Out.indexOf("YYYY");Hp1=Out.indexOf("HH");Mip1=Out.indexOf("MI");Sp1=Out.indexOf("SS");y1=(Yp1==-1)?ServerDateTime.getFullYear():InnStr.substring(Yp1,Yp1+4);mo1=(Mp1==-1)?ServerDateTime.getMonth():InnStr.substring(Mp1,Mp1+2)-1;d1=(Dp1==-1)?ServerDateTime.getDate():InnStr.substring(Dp1,Dp1+2);h1=(Hp1==-1)?ServerDateTime.getHours():InnStr.substring(Hp1,Hp1+2);m1=(Mip1==-1)?ServerDateTime.getMinutes():InnStr.substring(Mip1,Mip1+2);s1=(Sp1==-1)?ServerDateTime.getSeconds():InnStr.substring(Sp1,Sp1+2);TimeObj = new Date(y1,mo1,d1,h1,m1,s1);if(DateArray) Tmp = DateArray[TimeObj.getDay()];rExp=/DAY/;Out=Out.replace(rExp,Tmp);Tmp=(TimeObj.getDate()<10)?"0"+TimeObj.getDate():TimeObj.getDate();rExp=/DD/;Out=Out.replace(rExp,Tmp); if(MonthArray==undefined||MonthArray==''){Tmp=(TimeObj.getMonth()<9)?"0"+(TimeObj.getMonth()+1):(TimeObj.getMonth()+1);rExp=/MO/;Out=Out.replace(rExp,Tmp);}else{rExp=/MO/;Out=Out.replace(rExp,MonthArray[parseInt(mo1)]);}Tmp=TimeObj.getFullYear();rExp=/YYYY/;Out=Out.replace("YYYY",Tmp);Tmp=(TimeObj.getHours()<10)?"0"+TimeObj.getHours():TimeObj.getHours();rExp=/HH/;Out=Out.replace(rExp,Tmp);Tmp=(TimeObj.getMinutes()<10)?"0"+TimeObj.getMinutes():TimeObj.getMinutes();rExp=/MI/;Out=Out.replace(rExp,Tmp);Tmp=(TimeObj.getSeconds()<10)?"0"+TimeObj.getSeconds():TimeObj.getSeconds();rExp=/SS/;Out=Out.replace(rExp,Tmp);return Out;}}function trim(s){O = new String(s);rExp = /(^ +| +$)/;O=O.replace(rExp,"");return O;}function Update(caller){ TheObj = eval(caller);Dbg="";var c,Tmp = "",Mnd=-1,Out = new String(TheObj.format); if(TheObj.DateArray){rExp=/DAY/;for (j=0;j<TheObj.DateArray.length;j++){if(TheObj.value.match(TheObj.DateArray[j])){Out = Out.replace(rExp,TheObj.DateArray[j]);}}} if(TheObj.MonthArray){rExp=/MO/;for (j=0;j<TheObj.MonthArray.length;j++){if(TheObj.value.indexOf(TheObj.MonthArray[j])!=-1){Out = Out.replace(rExp,TheObj.MonthArray[j]);Mnd=j;break;}}}else{Mp=Out.indexOf("MO");}Dp=Out.indexOf("DD");Yp=Out.indexOf("YYYY");Hp=Out.indexOf("HH");Mip=Out.indexOf("MI");Sp=Out.indexOf("SS");d1=(Dp==-1)?ServerDateTime.getDate():trim(TheObj.value.substring(Dp,Dp+2));if(d1.length==1){if(Yp>Dp)Yp--;if(Hp>Dp)Hp--;if(Mip>Dp)Mip--;if(Sp>Dp)Sp--;}y1=(Yp==-1)?ServerDateTime.getFullYear():TheObj.value.substring(Yp,Yp+4); if(Mnd==-1){mo1=(Mp==-1)?ServerDateTime.getMonth():TheObj.value.substring(Mp,Mp+2)-1}else{mo1=Mnd};h1=(Hp==-1)?ServerDateTime.getHours():TheObj.value.substring(Hp,Hp+2);m1=(Mip==-1)?ServerDateTime.getMinutes():TheObj.value.substring(Mip,Mip+2);s1=(Sp==-1)?ServerDateTime.getSeconds():TheObj.value.substring(Sp,Sp+2); TimeObj = new Date(y1,mo1,d1,h1,m1,s1);TimeObj.setSeconds(TimeObj.getSeconds()+1); if(TheObj.MonthArray){Tmp=(TimeObj.getDate()<10)?TimeObj.getDate():TimeObj.getDate();}else{Tmp=(TimeObj.getDate()<10)?"0"+TimeObj.getDate():TimeObj.getDate();} rExp=/DD/;Out=Out.replace(rExp,Tmp); if(TheObj.MonthArray==undefined||TheObj.MonthArray==''){Tmp=(TimeObj.getMonth()<9)?"0"+(TimeObj.getMonth()+1):(TimeObj.getMonth()+1);rExp=/MO/;Out=Out.replace(rExp,Tmp);} Tmp=TimeObj.getFullYear();rExp=/YYYY/;Out=Out.replace("YYYY",Tmp);Tmp=(TimeObj.getHours()<10)?"0"+TimeObj.getHours():TimeObj.getHours();rExp=/HH/;Out=Out.replace(rExp,Tmp);Tmp=(TimeObj.getMinutes()<10)?"0"+TimeObj.getMinutes():TimeObj.getMinutes();rExp=/MI/;Out=Out.replace(rExp,Tmp);Tmp=(TimeObj.getSeconds()<10)?"0"+TimeObj.getSeconds():TimeObj.getSeconds();rExp=/SS/;Out=Out.replace(rExp,Tmp);return Out;}function FormatCounter(Out){Tmp=(TmpD.getHours()<10)?"0"+TmpD.getHours():TmpD.getHours();Out = Out.replace("HH",Tmp);Tmp=(TmpD.getMinutes()<10)?"0"+TmpD.getMinutes():TmpD.getMinutes();Out = Out.replace("MI",Tmp);Tmp=(TmpD.getSeconds()<10)?"0"+TmpD.getSeconds():TmpD.getSeconds();Out = Out.replace("SS",Tmp);return Out;}function Counter(caller){TheObj = eval(caller);var c,Tmp = "";Out = new String(TheObj.format);Out = Out.toUpperCase();Hp=Out.indexOf("HH");Mp=Out.indexOf("MI");Sp=Out.indexOf("SS");h1=(Hp==-1)?0:TheObj.value.substring(Hp,Hp+2);m1=(Mip==-1)?0:TheObj.value.substring(Mp,Mp+2);s1=(Sp==-1)?0:TheObj.value.substring(Sp,Sp+2);TmpD = new Date(1970,0,1,h1,m1,s1);if (TheObj.direction==0){if (TheObj.lastupdated==TheObj.step){TheObj.lastupdated = 1;c = TmpD.getSeconds()+TheObj.step;TmpD.setSeconds(c);return FormatCounter(Out);}else{TheObj.lastupdated ++;Out=TheObj.value;return FormatCounter(Out);}}else{if (TheObj.lastupdated==TheObj.step&&((h1*3600)+(m1*60)+s1)>=TheObj.step){TheObj.lastupdated = 1;c = TmpD.getSeconds()-TheObj.step;TmpD.setSeconds(c);return FormatCounter(Out);}else{TheObj.lastupdated ++;Out=TheObj.value;return FormatCounter(Out);}}}function GetProperties(a,b,color){var Msg="";Msg+="<table cellpadding=\"0\" cellspacing=\"0\" style=\"Color: "+color+"\">";Msg+="<tr><td width=\""+a+"\" style=\"vertical-align: top\"><i>id</i></td><td width=\""+b+"\" style=\"vertical-align: top\">"+this.id+"</td></tr>";Msg+="<tr><td width=\""+a+"\" style=\"vertical-align: top\"><i>destination</i></td><td width=\""+b+"\" style=\"vertical-align: top\">"+this.destination+"</td></tr>";Msg+="<tr><td width=\""+a+"\" style=\"vertical-align: top\"><i>format</i></td><td width=\""+b+"\" style=\"vertical-align: top\">"+this.format+"</td></tr>";Msg+="<tr><td width=\""+a+"\" style=\"vertical-align: top\"><i>value</i></td><td width=\""+b+"\" style=\"vertical-align: top\">"+this.value+"</td></tr>";Msg+="<tr><td width=\""+a+"\" style=\"vertical-align: top\"><i>show</i></td><td width=\""+b+"\" style=\"vertical-align: top\">"+this.show+"</td></tr>";Msg+="<tr><td width=\""+a+"\" style=\"vertical-align: top\"><i>update</i></td><td width=\""+b+"\" style=\"vertical-align: top\">"+this.update+"</td></tr>";Msg+="<tr><td width=\""+a+"\" style=\"vertical-align: top\"><i>type</i></td><td width=\""+b+"\" style=\"vertical-align: top\">"+this.type+"</td></tr>";Msg+="<tr><td width=\""+a+"\" style=\"vertical-align: top\"><i>direction</i></td><td width=\""+b+"\" style=\"vertical-align: top\">"+this.direction+"</td></tr>";Msg+="<tr><td width=\""+a+"\" style=\"vertical-align: top\"><i>step</i></td><td width=\""+b+"\" style=\"vertical-align: top\">"+this.step+"</td></tr>";Msg+="<tr><td width=\""+a+"\" style=\"vertical-align: top\"><i>Fdate</i></td><td width=\""+b+"\" style=\"vertical-align: top\">"+this.Fdate+"</td></tr>";Msg+="<tr><td width=\""+a+"\" style=\"vertical-align: top\"><i>Sdate</i></td><td width=\""+b+"\" style=\"vertical-align: top\">"+this.Sdate+"</td></tr>";Msg+="<tr><td width=\""+a+"\" style=\"vertical-align: top\"><i>DateArray</i></td><td width=\""+b+"\" style=\"vertical-align: top\">";for(k=0;k<this.DateArray.length;k++){Msg+=this.DateArray[k]+" ";}Msg+="<tr><td width=\""+a+"\" style=\"vertical-align: top\"><i>MonthArray</i></td><td width=\""+b+"\" style=\"vertical-align: top\">";for(k=0;k<this.MonthArray.length;k++){Msg+=this.MonthArray[k]+" ";}Msg+="</td></tr><table>";return Msg;}function ServerTimeWrite(dest){if (dest){document.getElementById(dest).value=this.value;}else{return "id missing"}}function ServerTime(id,destination,value,show,update,format,type,direction,step,Fdate,Sdate,DateArray,MonthArray){if (AddServerTime(id)==true){this.id=(id==undefined||id=='')?window.status="error: unique id not specified field 1":id;this.destination=(destination==undefined)?"":destination;this.format=(format==undefined||format=='')?"DD-MO-YYYY HH:MI:SS":format;this.DateArray=(DateArray==undefined||DateArray=='')?"":DateArray;this.MonthArray=(MonthArray==undefined||MonthArray=='')?"":MonthArray;this.type=(type==undefined||type=='')?1:type;if (value==undefined||value==''){this.value=FormatDate(ServerDateTime,this.format,this.DateArray,this.MonthArray)}else{this.value=(this.type==1)?FormatDate(value,this.format,this.DateArray,this.MonthArray):value;}this.show=(show==undefined)?0:show;this.update=(update==undefined)?1:update;this.direction=(direction==undefined||direction=='')?0:direction;this.step=(step==undefined||step=='')?1:step;this.Fdate=(Fdate==undefined||Fdate=='')?"":Fdate;this.Sdate=(Sdate==undefined||Sdate=='')?"":Sdate;this.lastupdated=0;this.write=ServerTimeWrite;this.GetProperties = GetProperties;}}function TimeDiff(caller,T1,T2){TheObj = eval(caller);var Mnd1=-1,Mnd2=-1,Tmp = "",ms,D,H,M,S,Out = new String(TheObj.format);T1f = T1.format.toUpperCase();if(T1.DateArray){rExp=/DAY/;for (j=0;j<T1.DateArray.length;j++){if(T1.value.match(T1.DateArray[j])){T1f = T1f.replace(rExp,T1.DateArray[j]);}}} if(T1.MonthArray){rExp=/MO/;for (j=0;j<T1.MonthArray.length;j++){if(T1.value.indexOf(T1.MonthArray[j])!=-1){T1f = T1f.replace(rExp,T1.MonthArray[j]);;Mnd1=j;break;}}}else{Mp1=T1f.indexOf("MO");} Dp1=T1f.indexOf("DD");Yp1=T1f.indexOf("YYYY");Hp1=T1f.indexOf("HH");Mip1=T1f.indexOf("MI");Sp1=T1f.indexOf("SS");d1=(Dp1==-1)?ServerDateTime.getDate():trim(T1.value.substring(Dp1,Dp1+2));if(d1.length==1){if(Yp1>Dp1)Yp1--;if(Hp1>Dp1)Hp1--;if(Mip1>Dp1)Mip1--;if(Sp1>Dp1)Sp1--;}y1=(Yp1==-1)?ServerDateTime.getFullYear():T1.value.substring(Yp1,Yp1+4); if(Mnd1==-1){mo1=(Mp1==-1)?ServerDateTime.getMonth():T1.value.substring(Mp1,Mp1+2)-1;}else{mo1=Mnd1};h1=(Hp1==-1)?ServerDateTime.getHours():T1.value.substring(Hp1,Hp1+2);m1=(Mip1==-1)?ServerDateTime.getMinutes():T1.value.substring(Mip1,Mip1+2);s1=(Sp1==-1)?ServerDateTime.getSeconds():T1.value.substring(Sp1,Sp1+2);Time1 = new Date(y1,mo1,d1,h1,m1,s1);T2f = T2.format.toUpperCase();if(T2.DateArray){rExp=/DAY/;for (j=0;j<T2.DateArray.length;j++){if(T2.value.match(T2.DateArray[j])){T2f = T2f.replace(rExp,T2.DateArray[j]);}}} if(T2.MonthArray){rExp=/MO/;for (j=0;j<T2.MonthArray.length;j++){if(T2.value.indexOf(T2.MonthArray[j])!=-1){T2f = T2f.replace(rExp,T2.MonthArray[j]);Mnd2=j;break;}}}else{Mp2=T2f.indexOf("MO");} Dp2=T2f.indexOf("DD");Yp2=T2f.indexOf("YYYY");Hp2=T2f.indexOf("HH");Mip2=T2f.indexOf("MI");Sp2=T2f.indexOf("SS");d2=(Dp2==-1)?ServerDateTime.getDate():trim(T2.value.substring(Dp2,Dp2+2));if(d2.length==1){if(Yp2>Dp2)Yp2--;if(Hp2>Dp2)Hp2--;if(Mip2>Dp2)Mip2--;if(Sp2>Dp2)Sp2--;}y2=(Yp2==-1)?ServerDateTime.getFullYear():T2.value.substring(Yp2,Yp2+4);if(Mnd2==-1){mo2=(Mp2==-1)?ServerDateTime.getMonth():T2.value.substring(Mp2,Mp2+2)-1;}else{mo2=Mnd2};h2=(Hp2==-1)?ServerDateTime.getHours():T2.value.substring(Hp2,Hp2+2);m2=(Mip2==-1)?ServerDateTime.getMinutes():T2.value.substring(Mip2,Mip2+2);s2=(Sp2==-1)?ServerDateTime.getSeconds():T2.value.substring(Sp2,Sp2+2);Time2 = new Date(y2,mo2,d2,h2,m2,s2);ms=(Time2.getTime()-Time1.getTime())/1000;if(ms<0) ms=Math.abs(ms);D=parseInt(ms/(60*60*24));H=parseInt(ms%(60*60*24)/(60*60));M=parseInt((ms%(60*60*24))%(60*60)/60);S=parseInt(((ms%(60*60*24*1000))%(60*60))%60);Tmp=(D<10)?"0"+D:D;rExp=/DD/;Out=Out.replace(rExp,Tmp);Tmp=(H<10)?"0"+H:H;rExp=/HH/;Out=Out.replace(rExp,Tmp);Tmp=(M<10)?"0"+M:M;rExp=/MI/;Out=Out.replace(rExp,Tmp);Tmp=(S<10)?"0"+S:S;rExp=/SS/;Out=Out.replace(rExp,Tmp);return Out;}function TagWrite(Obj,V){if (Obj.tagName=="INPUT"){Obj.value = V;}else if (Obj.tagName=="DIV"){Obj.innerHTML = V;}}function RealTime(){if (!document.all&&!document.getElementById) return;count++;ServerDateTime.setSeconds(count);if (count==60) count=0;if(TimeObjects.length!=0){for(i=0;i<TimeObjects.length;i++){TheObj = eval(TimeObjects[i]);if (eval(TimeObjects[i] + ".update")==1&&eval(TimeObjects[i] + ".type")==1){TheObj.value = Update(eval(TimeObjects[i] + ".id"));}else if (eval(TimeObjects[i] + ".update")==1&&eval(TimeObjects[i] + ".type")==2){Fo = eval(TimeObjects[i] + ".Fdate");So = eval(TimeObjects[i] + ".Sdate");Fdate = eval(Fo);Sdate = eval(So);if(Fdate.id&&Sdate.id) TheObj.value = TimeDiff(eval(TimeObjects[i] + ".id"),Fdate,Sdate);}else if (eval(TimeObjects[i] + ".update")==1&&eval(TimeObjects[i] + ".type")==3){TheObj.value = Counter(eval(TimeObjects[i] + ".id"));}var O = document.getElementById(eval(TimeObjects[i] + ".destination"));if (eval(TimeObjects[i] + ".show")==1&&eval(TimeObjects[i] + ".type")==1){if(eval(TimeObjects[i] + ".destination")!=""&&eval(TimeObjects[i] + ".destination")!="status") TagWrite(O,eval(TimeObjects[i] + ".value"));if(eval(TimeObjects[i] + ".destination")=="status") window.status = eval(TimeObjects[i] + ".value");}else if (eval(TimeObjects[i] + ".show")==1&&eval(TimeObjects[i] + ".type")==2){Fo = eval(TimeObjects[i] + ".Fdate");So = eval(TimeObjects[i] + ".Sdate");Fdate = eval(Fo);Sdate = eval(So);if(Fdate.id&&Sdate.id){if(eval(TimeObjects[i] + ".destination")!=""&&eval(TimeObjects[i] + ".destination")!="status") TagWrite(O,eval(TimeObjects[i] + ".value"));}if(eval(TimeObjects[i] + ".destination")=="status") window.status = eval(TimeObjects[i] + ".value");}else if (eval(TimeObjects[i] + ".show")==1&&eval(TimeObjects[i] + ".type")==3){if(eval(TimeObjects[i] + ".destination")!=""&&eval(TimeObjects[i] + ".destination")!="status") TagWrite(O,eval(TimeObjects[i] + ".value"));if(eval(TimeObjects[i] + ".destination")=="status") window.status = eval(TimeObjects[i] + ".value");}}}setTimeout("RealTime()",1000);return false;}