// JavaScript Document
var stime=null;
var tzone="";
var offset="";
var days=new Array()                                    //create array for days
	days[0]="Sun";
	days[1]="Mon";
	days[2]="Tue";
	days[3]="Wed";
	days[4]="Thu";
	days[5]="Fri";
	days[6]="Sat";

var months=new Array()                                  //create array for months
	months[0]="Jan";
	months[1]="Feb";
	months[2]="Mar";
	months[3]="Apr";
	months[4]="May";
	months[5]="Jun";
	months[6]="Jul";
	months[7]="Aug";
	months[8]="Sep";
	months[9]="Oct";
	months[10]="Nov";
	months[11]="Dec";

function provinceSelector(){
	var fullURL = window.document.URL.toString();
	if (fullURL.indexOf("?") > 0) {
    	var SplitURL = fullURL.split("?");
    	var param = SplitURL[1].split("=");
		if (param[0] == "id") {
			// alert(param[1]);
			if (param[1] == "BC") {
				document.getElementById(param[1]).innerHTML = "<a href='profile.php?id=BC' class='province_selected'>British Columbia</a>";
			} else if (param[1] == "AB") {
				document.getElementById(param[1]).innerHTML = "<a href='profile.php?id=AB' class='province_selected'>Alberta</a>";
			} else if (param[1] == "SK") {
				document.getElementById(param[1]).innerHTML = "<a href='profile.php?id=SK' class='province_selected'>Saskatchewan</a>";
			} else if (param[1] == "MB") {
				document.getElementById(param[1]).innerHTML = "<a href='profile.php?id=MB' class='province_selected'>Manitoba</a>";
			} else if (param[1] == "ON") {
				document.getElementById(param[1]).innerHTML = "<a href='profile.php?id=ON' class='province_selected'>Ontario</a>";
			} else if (param[1] == "QC") {
				document.getElementById(param[1]).innerHTML = "<a href='profile.php?id=QC' class='province_selected'>Quebec</a>";
			} else if (param[1] == "NS") {
				document.getElementById(param[1]).innerHTML = "<a href='profile.php?id=NS' class='province_selected'>Nova Scotia</a>";
			} else if (param[1] == "NB") {
				document.getElementById(param[1]).innerHTML = "<a href='profile.php?id=NB' class='province_selected'>New Brunswick</a>";
			} else if (param[1] == "PE") {
				document.getElementById(param[1]).innerHTML = "<a href='profile.php?id=PE' class='province_selected'>Prince Edward Island</a>";
			} else if (param[1] == "NF") {
				document.getElementById(param[1]).innerHTML = "<a href='profile.php?id=NF' class='province_selected'>Newfoundland and Labrador</a>";
			} else if (param[1] == "YK") {
				document.getElementById(param[1]).innerHTML = "<a href='profile.php?id=YK' class='province_selected'>Yukon</a>";
			} else if (param[1] == "NT") {
				document.getElementById(param[1]).innerHTML = "<a href='profile.php?id=NT' class='province_selected'>Northwest Territories</a>";
			} else if (param[1] == "NU") {
				document.getElementById(param[1]).innerHTML = "<a href='profile.php?id=NU' class='province_selected'>Nunavut</a>";
			}
		}
    }
}

function convert(value) {
	var hours = parseInt(value);
   	value -= parseInt(value);
	value *= 60;
	var mins = parseInt(value);
   	value -= parseInt(value);
	value *= 60;
	var secs = parseInt(value);
	var display_hours = hours;
	display_hours = (hours < 10 && hours > 0) ? "+0"+hours : "+"+hours; // positive
	display_hours = (hours == 0) ? "0"+hours : display_hours; // handle GMT case (00:00)
	display_hours = (hours < 0 && hours > -10) ? "-0"+Math.abs(hours) : display_hours; // neg
    mins = (mins < 10) ? "0"+mins : mins;
	return display_hours+":"+mins;
}

function getInputTimezone() {
	var rightNow = new Date();
	var jan1 = new Date(rightNow.getFullYear(), 0, 1, 0, 0, 0, 0);  // jan 1st
	var june1 = new Date(rightNow.getFullYear(), 6, 1, 0, 0, 0, 0); // june 1st
	var temp = jan1.toGMTString();
	var jan2 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));
	temp = june1.toGMTString();
	var june2 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));
	var std_time_offset = (jan1 - jan2) / (1000 * 60 * 60);
	var daylight_time_offset = (june1 - june2) / (1000 * 60 * 60);
	if (std_time_offset != daylight_time_offset) {
		var hemisphere = std_time_offset - daylight_time_offset;
		if (hemisphere >= 0) {
			std_time_offset = daylight_time_offset;
		}
	}
	return convert(std_time_offset);
}

function getDaylightSaving() {
	var rightNow = new Date(inp);
	var jan1 = new Date(rightNow.getFullYear(), 0, 1, 0, 0, 0, 0);  // jan 1st
	var june1 = new Date(rightNow.getFullYear(), 6, 1, 0, 0, 0, 0); // june 1st
	var temp = jan1.toGMTString();
	var jan2 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));
	temp = june1.toGMTString();
	var june2 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));
	var std_time_offset = (jan1 - jan2) / (1000 * 60 * 60);
	var daylight_time_offset = (june1 - june2) / (1000 * 60 * 60);
	var dst;
	if (std_time_offset == daylight_time_offset) {
		dst = "0"; // daylight savings time is NOT observed
	} else {
		dst = "1"; // daylight savings time is observed
	}
	return dst;
}

function canadianClock(tzone) {
	var thisDay = new Date();
	var localTime = thisDay.getTime();
	// Obtain local UTC offset and convert to msec
	var localOffset = thisDay.getTimezoneOffset() * 60000;
	// obtain UTC time in msec
	var utc = localTime + localOffset;
	// Find timezone offset
	var tzo = 0;
	var dst = 0;
	if (tzone == "PDT") {
		dst = 1;
		tzo = -8;
	} else if (tzone == "PST") {
		dst = 0;
		tzo = -8;
	} else if (tzone == "MDT") {
		dst = 1;
		tzo = -7;
	} else if (tzone == "MST") {
		dst = 0;
		tzo = -7;
	} else if (tzone == "CDT") {
		dst = 1;
		tzo = -6;
	} else if (tzone == "CST") {
		dst = 0;
		tzo = -6;
	} else if (tzone == "EDT") {
		dst = 1;
		tzo = -5;
	} else if (tzone == "EST") {
		dst = 0;
		tzo = -5;
	} else if (tzone == "ADT") {
		dst = 1;
		tzo = -4;
	} else if (tzone == "AST") {
		dst = 0;
		tzo = -4;
	} else if (tzone == "NDT") {
		dst = 1;
		tzo = -4;
	} else if (tzone == "NST") {
		dst = 0;
		tzo = -4;
	}
	var destination = new Date(utc + (3600000*(tzo+dst))); 
	return destination.toLocaleString();
}

function systemClock(tz) {
	provinceSelector();
	document.getElementById('systemclock').innerHTML = canadianClock(tz);
	id=setTimeout("systemClock(\'"+tz+"\')", 1000);
}

