<!--
function sendvote(value)
        {
        self.name = "home"; // names current window as "home"
        voteresult = window.open("","voteresult",'scrollbars,width=330,height=260,toolbar=0,location=0,directory=0,status=0,copyhistory=0,resizable');
        }
function sendvote2(value)
{
        self.name = "home"; // names current window as "home"

        voteresult = window.open("","voteresult",'resizable=yes,scrollbars=yes,width=468,height=420,toolbar=0,location=0,directory=0,status=0,copyhistory=0');
        return true;
}
function sendcomment(value)
	{
	self.name = "comment"; // names current window as "home"
	voteresult = NewWindow("","comments",'200','160');
	return true;
}
function NewWindow(mypage, myname, w, h) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',resizable,scrollbars'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { 
		win.window.focus();
	}
}
function viewPhoto(mypage, myname, w, h) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',resizable,scrollbars'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { 
		win.window.focus();
	}
}
function PopUp(mypage, myname, w, h) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',resizable=no,scrollbars=no'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { 
		win.window.focus();
	}
}
function getAdvWindow(adnr) {
  adn = adnr.toString();
  if (adn != "NULL") {
    switch (adn) {
      //case: statements here for special ads
      default:
      pagewidth=460;
      void window.open('http://www.calgarysun.com/saletoday/view.php?adnum='+adn,adn,'width='+pagewidth+',height=600,toolbars=no,location=no,status=no,scrollbars=yes,scrolling=yes,resizable=yes');
      break;
    }
  }
  else {
    void(null);
  }
}

function getTestWindow(adnr) {
  adn = adnr.toString();
  if (adn != "NULL") {
    switch (adn) {
      //case: statements here for special ads
      default:
      pagewidth=460;
      void window.open('http://www.calgarysun.com/ads/25th/testimonials/showme.php?adnum='+adn,adn,'width='+pagewidth+',height=600,toolbars=no,location=no,status=no,scrollbars=yes,scrolling=yes,resizable=yes');
      break;
    }
  }
  else {
    void(null);
  }
}

function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name)
{
	createCookie(name,"",-1);
}

function sethome(objByRef) {
	if (document.all) {
		objByRef.style.behavior='url(#default#homepage)';
		objByRef.setHomePage('http://www.calgarysun.com');
		return false;
	}
	else {
		alert("This function is only supported by Internet Explorer\nfor Windows. To make calgarysun.com your home\n"+
		      "page on any other browser, use your browser's\npreferences dialog.");
		return false;
	}
}

function weatherStart(icn) {
	theDate = new Date();
	srarray = SunRiseSet(theDate.getFullYear(),theDate.getMonth()+1,theDate.getDate(),51.1139,-114.02);
	srutc=hmsstring(srarray[0]).split(":");
	ssutc=hmsstring(srarray[1]).split(":");
	sunrise=new Date();
	sunset=new Date();

	sunrise.setUTCSeconds(srutc[2]);
	sunrise.setUTCMinutes(srutc[1]);
	sunrise.setUTCHours(srutc[0]);
	sunrise.setDate(theDate.getDate());

	sunset.setUTCSeconds(ssutc[2]);
	sunset.setUTCMinutes(ssutc[1]);
	sunset.setUTCHours(ssutc[0]);
	sunset.setDate(theDate.getDate());

	sunriseReal = sunrise.getTime();
	sunsetReal = sunset.getTime();
	dateReal = theDate.getTime();

	//alert(sunriseReal+":"+dateReal+":"+sunsetReal+"\n"+((dateReal>sunriseReal)&&(dateReal<sunsetReal)));
	document.theweather.prefix = ((dateReal>sunriseReal)&&(dateReal<sunsetReal))?'day':'night';
	document.getElementById('weathericon').src = '/weather/images/'+document.theweather.prefix+document.theweather.icon+".gif";
	//alert(document.theweather.icon);
	document.getElementById('wtextcell').innerHTML = document.theweather.txt;
	document.getElementById('tempdispcell').innerHTML = document.theweather.temp+" &deg;C / "+document.theweather.tempf+" &deg;F";
	document.getElementById('winddispcell').innerHTML = "<b>"+document.theweather.wdir+"</b> "+document.theweather.wspeed+" kph";
	document.getElementById('pressdispcell').innerHTML = document.theweather.press+" KPa";
	document.getElementById('curcond').innerHTML = "CURRENT CONDITIONS<br />as of "+document.theweather.date;
}

function rev(angle){
	return(angle-Math.floor(angle/360.0)*360.0);
}
function sind(angle){return Math.sin((angle*Math.PI)/180.0);}
function cosd(angle){return Math.cos((angle*Math.PI)/180.0);}
function tand(angle){return Math.tan((angle*Math.PI)/180.0);}
function asind(c){return (180.0/Math.PI)*Math.asin(c);}
function acosd(c){return (180.0/Math.PI)*Math.acos(c);}
function atan2d(y,x){return (180.0/Math.PI)*Math.atan(y/x)-180.0*(x<0);}

function hmsstring(t) {
// takes hours and returns hh:mm:ss
  var hours = Math.abs(t);
  var minutes = 60.0*(hours-Math.floor(hours));
  hours=Math.floor(hours);
  var seconds = Math.round(60.0*(minutes-Math.floor(minutes)));
  minutes=Math.floor(minutes);
  if (seconds >= 60) { minutes+=1; seconds-=60; }
  if (minutes >= 60) { hour+=1; minutes-=60; }
  if (hours >= 24) { hours-=24; }
  var hmsstr=(t < 0) ? "-" : "";
  hmsstr=((hours < 10) ? "0" : "" )+hours;
  hmsstr+=((minutes < 10) ? ":0" : ":" )+minutes;
  hmsstr+=((seconds < 10) ? ":0" : ":" )+seconds;
  return hmsstr;
}

function dayno(year,month,day,hours) {
  // Day number is a modified Julian date, day 0 is 2000 January 0.0
  // which corresponds to a Julian date of 2451543.5
  var d= 367*year-Math.floor(7*(year+Math.floor((month+9)/12))/4)+Math.floor((275*month)/9)+day-730530+hours/24;
  return d;
}

function local_sidereal(year,month,day,hours,lon) {
  // Compute local siderial time in degrees
  // year, month, day and hours are the Greenwich date and time
  // lon is the observers longitude
  var d=dayno(year,month,day,hours);
  var lst=(98.9818+0.985647352*d+hours*15+lon);
  return rev(lst)/15;
}

function SunRiseSet(year,month,day,latitude,longitude) {
  // Based on method in sci.astro FAQ by Paul Schlyter
  // returns an array holding rise and set times in UTC hours
  // NOT accurate at high latitudes 
  // latitude = your local latitude: north positive, south negative
  // longitude = your local longitude: east positive, west negative
  // Calculate the Suns position at noon local zone time
  var d=dayno(year,month,day,12.0-longitude/15);
  var oblecl=23.4393-3.563E-7*d;
  var w=282.9404+4.70935E-5*d;
  var M=356.0470+0.9856002585*d;
  e=0.016709-1.151E-9*d;
  var E=M+e*(180/Math.PI)*sind(M)*(1.0+e*cosd(M));
  var A=cosd(E)-e;
  var B=Math.sqrt(1-e*e)*sind(E);
  var slon=w+atan2d(B,A);
  var sRA=atan2d(sind(slon)*cosd(oblecl),cosd(slon));
  while(sRA<0)sRA+=360; while(sRA>360)sRA-=360; sRA=sRA/15;
  var sDec=asind(sind(oblecl)*sind(slon));
  // Time sun is on the meridian
  var lst=local_sidereal(year,month,day,12-longitude/15,longitude);
  var MT=12.0-longitude/15+sRA-lst;
  while(MT<0)MT+=24; while(MT>24)MT-=24;
  // hour angle
  var cHA0=(sind(-0.833)-sind(latitude)*sind(sDec))/(cosd(latitude)*cosd(sDec));
  var HA0=acosd(cHA0);
  HA0=rev(HA0)/15;
  // return rise and set times
  return new Array((MT-HA0),(MT+HA0));
}
function encode(str) {
	return escape(str);
}
function decode(str) {
	return unescape(str.replace(/\+/g,  " "));
}

getViewportWidth = function() {
  var width = 0;
  if( document.documentElement && document.documentElement.clientWidth ) {
    width = document.documentElement.clientWidth;
  }
  else if( document.body && document.body.clientWidth ) {
    width = document.body.clientWidth;
  }
  else if( window.innerWidth ) {
    width = window.innerWidth - 18;
  }
  return width;
};

getViewportHeight = function() {
  var height = 0;
  if( document.documentElement && document.documentElement.clientHeight ) {
    height = document.documentElement.clientHeight;
  }
  else if( document.body && document.body.clientHeight ) {
    height = document.body.clientHeight;
  }
  else if( window.innerHeight ) {
    height = window.innerHeight - 18;
  }
  return height;
};

getViewportScrollX = function() {
  var scrollX = 0;
  if( document.documentElement && document.documentElement.scrollLeft ) {
    scrollX = document.documentElement.scrollLeft;
  }
  else if( document.body && document.body.scrollLeft ) {
    scrollX = document.body.scrollLeft;
  }
  else if( window.pageXOffset ) {
    scrollX = window.pageXOffset;
  }
  else if( window.scrollX ) {
    scrollX = window.scrollX;
  }
  return scrollX;
};

getViewportScrollY = function() {
  var scrollY = 0;
  if( document.documentElement && document.documentElement.scrollTop ) {
    scrollY = document.documentElement.scrollTop;
  }
  else if( document.body && document.body.scrollTop ) {
    scrollY = document.body.scrollTop;
  }
  else if( window.pageYOffset ) {
    scrollY = window.pageYOffset;
  }
  else if( window.scrollY ) {
    scrollY = window.scrollY;
  }
  return scrollY;
};

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function stripper(txt) {
	r = /\W/i;
	t = txt.replace(r,"");
	t = t.toLowerCase();
	return t;
}

function callSubMenu(x,y,id) {
	x=parseInt(x,10);
	y=parseInt(y,10);
	mnu = document.getElementById(id);
	mnu.style.visibility = "visible";
	mnu.style.left = x+'px';
	mnu.style.top = y+'px';
	//alert(findPosX(mnu)+":"+findPosY(mnu));
}

function dismissSubMenu(id) {
	mnu = document.getElementById(id);
  mnu.style.visibility = "hidden";
  subMenuStatus[id]=0;
  clearInterval(eval("intr"+id));
}

function subpoint(source,id) {
	if (id!="") {
		//for (i in source) {
		//	out+=i+":"+source[i];
		//}
		//document.getElementsByTagName('BODY')[0].innerHTML+=out;
		//alert((findPosX(source)-getViewportScrollX())+parseInt(source.offsetWidth,10));
		subMenuStatus[id]=1;
		startFloatTimer(800,id);
		callSubMenu((findPosX(source))+parseInt(source.offsetWidth,10),(findPosY(source)),id);
	}
}

function unpoint(id) {
	subMenuStatus[id]=0;
}

function startFloatTimer(intr,id) {
	eval("intr"+id+" = setInterval('checkSubMenu(\""+id+"\")',"+intr+")");
}

function checkSubMenu(id) {
  obj = document.getElementById(id);
  if(subMenuStatus[id]==0) {
  	dismissSubMenu(id);
  }
  else {
  }
}

function mousehit(lnk,im) {
	//i = document.getElementById(im);
	//n = i.src;
	//f = n.replace(/off\./i,"on.");
	//i.src = f;
}

function mouseoff(im) {
	//c = document.getElementById(im);
	//n = c.src;
	//f = n.replace(/on\./i,"off.");
	//c.src = f;
}

subMenuStatus = new Array();

function submitpoll(pollform) {
	sendvote();
	document.forms[pollform].target='voteresult';
	document.forms[pollform].submit();
}

function results(pollform) {
	sendvote();
	document.forms[pollform].target='voteresult';
	document.forms[pollform].a.value="display";
	document.forms[pollform].submit();
}
//-->
