//=========================================================================================================
//' Purpose         :   This component create time object which can get local date and time of any country giving GMST time different of that country. 
//	browser			: IE4+ and NS4+		
//' Source           :   Java Script 1.2
//' Author            :   Upendra Prasad Haputantry
//' Date Created  :   30-May-2001
//' Date Modified :   03-December-2001
//' Copyright By  :   Copyright © 2000 eRUNWAY Inc.
//========================================================================================================

//=========================================================================================================





//======================================================
//' Method : countryTime
//' Purpose : Create the time object and get the GMST time and set the specific country time according to the GMST time difference
//' Inputs : GMST time different in minutes
//' Returns : none
//' Created : on 30 May 2001 - Upendra Prasad Haputantry
//======================================================
function countryTime(GMST_Time_dif){
weekDays = new Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
monthName = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
this.dateObj = new Date();
this.DD;
this.MM;
this.YY; 
this.hh;
this.h24;
this.mm;
this.ss; 
this.day;
this.strDay;
this.strMonth;
this.getGMSTtime()
this.setTimeTo(GMST_Time_dif)
this.format12Hour();

}

countryTime.prototype.setTimeTo = setTimeDiff;
countryTime.prototype.getGMSTtime = getGMTtime;
countryTime.prototype.format12Hour = set12Hour;



//======================================================
//' Method : getGMTtime
//' Purpose : Get the GMST(UTC) date & time values
//' Inputs : none
//' Returns : none
//' Created : on 30 May 2001 - Upendra Prasad Haputantry
//======================================================
function getGMTtime(){
this.DD = this.dateObj.getUTCDate();
this.MM = this.dateObj.getUTCMonth() + 1;
this.YY = this.dateObj.getUTCFullYear();
this.hh = this.dateObj.getUTCHours();
this.mm = this.dateObj.getUTCMinutes();
this.ss = this.dateObj.getUTCSeconds();

}



//=======================================================
//' Method : setTimeDiff
//' Purpose : Add the time different value to the GMST time
//' Inputs : Time different in minutes
//' Returns : none
//' Created : on 30 May 2001 - Upendra Prasad Haputantry
//=======================================================
function setTimeDiff(dif_val){

	if(dif_val >= 0){
	this.mm = this.mm + dif_val;
	if(this.mm >= 60){
		this.hh = this.hh + Math.floor(this.mm/60);
		this.mm = this.mm%60;
		}
	if(this.hh >= 24){
		this.DD = this.DD + Math.floor(this.hh/24);
		this.hh = this.hh%24;
		}	
	if ((this.DD > 31) && (this.MM == 1 || this.MM == 3 || this.MM == 5 || this.MM == 7 || this.MM == 8 || this.MM == 10 || this.MM == 12 )){
		this.MM = this.MM + Math.floor(this.DD/31);
		this.DD = this.DD%31;
		}
	if ((this.DD > 30) && (this.MM == 4 || this.MM == 6 || this.MM == 9 || this.MM == 11)){
		this.MM = this.MM + Math.floor(this.DD/30);
		this.DD = this.DD%30;
		}
	if ((this.DD > 29) && (this.MM == 2) && (isLeapYear(this.YY))){
		this.MM = this.MM + Math.floor(this.DD/29);
		this.DD = this.DD%29;
		}
	if ((this.DD > 28) && (this.MM == 2) && (!isLeapYear(this.YY))){
		this.MM = this.MM + Math.floor(this.DD/28);
		this.DD = this.DD%28;
		}
	if(this.MM > 12){
		this.YY = this.YY + Math.floor(this.MM/12);
		this.MM = this.MM%12;
		}	

	}else

	if(dif_val < 0){
	this.mm = this.mm + (dif_val%60);
	this.hh = this.hh + Math.ceil(dif_val/60);
	if(this.mm < 0){
		this.hh = this.hh - 1;
		this.mm = 60 + this.mm;
		}
	if(this.hh < 0){
		this.DD = this.DD - 1;
		this.hh = 24 + this.hh;
		}
	if((this.DD <= 0) && ( this.MM == 5 || this.MM == 7 || this.MM == 10 || this.MM == 12 )){
		this.MM = this.MM - 1;
		this.DD = 30 + this.DD;
		}
	if((this.DD <= 0) && (this.MM == 1 || this.MM == 2 || this.MM == 4 || this.MM == 6 || this.MM == 8 || this.MM == 9 || this.MM == 11)){
		this.MM = this.MM - 1;
		this.DD = 31 + this.DD;
		}
	if((this.DD <= 0) && (this.MM == 3) && (isLeapYear(this.YY))){
		this.MM = this.MM - 1;
		this.DD = 29 + this.DD;
		}
	if((this.DD <= 0) && (this.MM == 3) && (!isLeapYear(this.YY))){
		this.MM = this.MM - 1;
		this.DD = 28 + this.DD;
		}
	if(this.MM <= 0){
		this.YY = this.YY - 1;
		this.MM = 12 + this.MM;
		}

	}

this.dateObj.setYear(this.YY);
this.dateObj.setMonth(this.MM - 1);
this.dateObj.setDate(this.DD);
this.dateObj.setHours(this.hh);
this.dateObj.setMinutes(this.mm);
this.h24= this.hh;

this.day = this.dateObj.getDay();
this.strDay = weekDays[this.day]
this.strMonth = monthName[this.MM-1]
}


//=======================================================
//' Method : set12Hour
//' Purpose : Cnvert the time in to 12 hour formet
//' Inputs : none
//' Returns : none
//' Created : on 30 May 2001 - Upendra Prasad Haputantry
//=======================================================
function set12Hour(){

this.ampm="AM";
if(this.hh >=12){this.ampm="PM"}
if(this.mm < 10){this.mm ='0'+ this.mm;}
if(this.ss < 10){this.ss ='0'+ this.ss;}
if(this.hh == 0){this.hh = 12;}
if(this.hh >12){this.hh =this.hh - 12;}
if(this.hh < 10){this.hh ='0'+ this.hh;}
if(this.DD < 10){this.DD ='0'+ this.DD;}
if(this.MM < 10){this.MM ='0'+ this.MM;}
}


//=======================================================
//' Method : isLeapYear
//' Purpose : Check weather the year is leap year
//' Inputs : year
//' Returns : true or false
//' Created : 
//=======================================================
function isLeapYear(Year) {

    if (((Year % 4)==0) && ((Year % 100)!=0) || ((Year % 400)==0)) {
        return (true);
    }
    else {
        return (false);
    }
}

//=======================================================
//' Method : set the Daylight saving changes for US
//' Purpose : Check weather the year is leap year
//' Inputs : GMT different in minutes
//' Returns : Adjusted GMT different in minutes
//' Created : on 3 December 2001 - Upendra Prasad Haputantry
//=======================================================
var thisYear, AprilDate, OctoberDate, MarchDateEU, OctoberDateEU;
CurrentDate = new Date();

var  thisYear = CurrentDate.getYear();

var AprilDay = (2+6 * thisYear - Math.floor (thisYear / 4) ) % 7 + 1;
var OctoberDay=  (31-( Math.floor (thisYear * 5 / 4) + 1) % 7);

var MarchDateEU =  (31-( Math.floor (thisYear * 5 / 4) + 4) % 7);
var OctoberDateEU =  (31-( Math.floor (thisYear * 5 / 4) + 1) % 7);

var AprilDate = eval('new Date("April '+ AprilDay +', '+ thisYear +' 02:00:00")');
var OctoberDate = eval('new Date("October '+ OctoberDay +', '+ thisYear +' 02:00:00")');


function SetDayLightSavingForUS(TimeDif){
	if((CurrentDate > AprilDate) && (CurrentDate < OctoberDate)){

	 return TimeDif + 60;
	}else {
	 return TimeDif;
	}
}



var sl
function Clock(){
//ind = new countryTime(330);
sl = new countryTime(360);
usBoston = new countryTime(SetDayLightSavingForUS(-300));
uk = new countryTime(SetDayLightSavingForUS(0));
//usCalfo = new countryTime(SetDayLightSavingForUS(-480));
chennai = new countryTime(330);
//perth =  new countryTime(480);

	var	ElementLankaDate=document.getElementById('sriLankaDate'); 
	//var	ElementIndiaDate=document.getElementById('indiaDate'); 
	//var	ElementBostonDate=document.getElementById('usaDate'); 
	//var	ElementukTime=document.getElementById('ukTime');
	//var	ElementCaliforniaTime=document.getElementById('californiaTime');
	//var	ElementChennaiTime=document.getElementById('chennaiTime');
	
	var	ElementLankaTime=document.getElementById('sriLankaTime'); 
	//var	ElementIndiaTime=document.getElementById('indiaTime'); 
	//var	ElementBostonTime=document.getElementById('usaTime'); 
	//var	ElementukDate=document.getElementById('ukDate'); 
	//var	ElementCaliforniaDate=document.getElementById('californiaDate'); 
	//var	ElementChennaiDate=document.getElementById('chennaiDate'); 



ElementLankaDate.innerHTML= sl.strDay + '&nbsp;' + sl.DD +'-'+ sl.strMonth +'-'+ sl.YY ;
//ElementIndiaDate.innerHTML= ind.strDay + '&nbsp;' + ind.DD +'-'+ ind.strMonth +'-'+ ind.YY;
//ElementBostonDate.innerHTML= usBoston.strDay + '&nbsp;' + usBoston.DD +'-'+ usBoston.strMonth +'-'+ usBoston.YY;
//ElementukDate.innerHTML= uk.strDay + '&nbsp;' + uk.DD +'-'+ uk.strMonth +'-'+ uk.YY;
//ElementCaliforniaDate.innerHTML= usCalfo.strDay + '&nbsp;' + usCalfo.DD +'-'+ usCalfo.strMonth +'-'+ usCalfo.YY;
//ElementChennaiDate.innerHTML= chennai.strDay + '&nbsp;' + chennai.DD +'-'+ chennai.strMonth +'-'+ chennai.YY;

ElementLankaTime.innerHTML= sl.hh +':'+ sl.mm  +'&nbsp;<span class="Second">' + sl.ss + '</span>&nbsp;' +  sl.ampm;
//ElementIndiaTime.innerHTML= ind.hh +':'+ ind.mm  +'&nbsp;<span class="Second">' + ind.ss + '</span>&nbsp;' +  ind.ampm;
//ElementBostonTime.innerHTML= usBoston.hh +':'+ usBoston.mm  +'&nbsp;<span class="Second">' + usBoston.ss + '</span>&nbsp;' +  usBoston.ampm ;
//ElementukTime.innerHTML= uk.hh +':'+ uk.mm  +'&nbsp;<span class="Second">' + uk.ss + '</span>&nbsp;' +  uk.ampm ;
//ElementCaliforniaTime.innerHTML= usCalfo.hh +':'+ usCalfo.mm  +'&nbsp;<span class="Second">' + usCalfo.ss + '</span>&nbsp;' +  usCalfo.ampm ;
//ElementChennaiTime.innerHTML= chennai.hh +':'+ chennai.mm  +'&nbsp;<span class="Second">' + chennai.ss + '</span>&nbsp;' +  chennai.ampm ;


if((sl.h24 >=  6)&&(sl.h24 < 18)) document.images["DNcolombo"].src="Images/sun.gif"; else document.images["DNcolombo"].src="Images/moon.gif";
//if((ind.h24 >=  6)&&(ind.h24 < 18)) document.images["DNhydrabad"].src="Images/sun.gif"; else document.images["DNhydrabad"].src="Images/moon.gif";
//if((usBoston.h24 >=  6)&&(usBoston.h24 < 18)) document.images["DNboston"].src="Images/sun.gif"; else document.images["DNboston"].src="Images/moon.gif";
//if((uk.h24 >=  6)&&(uk.h24 < 18)) document.images["DNuk"].src="Images/sun.gif"; else document.images["DNuk"].src="Images/moon.gif";
//if((usCalfo.h24 >=  6)&&(usCalfo.h24 < 18)) document.images["DNcalifornia"].src="Images/sun.gif"; else document.images["DNcalifornia"].src="Images/moon.gif";
//if((chennai.h24 >=  6)&&(chennai.h24 < 18)) document.images["DNchennai"].src="Images/sun.gif"; else document.images["DNchennai"].src="Images/moon.gif";

window.setTimeout("Clock()",500);

}



