﻿// Created By: Roel Bondoc
// Created On: March 14, 2007
// Standard bookmarking function. Compatabily with most major browsers.
// Alerts the user if javascript bookmarking is not available.
function bookmark(url,title){
  if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
  window.external.AddFavorite(url,title);
  } else if (navigator.appName == "Netscape") {
    window.sidebar.addPanel(title,url,"");
  } else {
    alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
  }
}

// Added By: Dan L.
// Added On: March 20th, 2007
// Default Macromedia functio for popup a window

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/* API: cookies*/
function getCookie(name){  
	var the_cookie = name + "="; 
	if (d.cookie.length > 0) {     
		begin = d.cookie.indexOf(the_cookie);  
		if (begin != -1) {       
			begin += the_cookie.length;
			end = d.cookie.indexOf(";", begin);
			if (end == -1) { end = d.cookie.length; }
			return unescape(d.cookie.substring(begin, end));
		} 
	} return null;
}

function setCookie(name, value, time){
	if(!time){
		var time = new Date();
		time.setTime(time.getTime() + (1000*60*60*24*365))
		time.toGMTString();//expires in a year
	}
	d.cookie = name + "=" + escape(value) + "; path=/; expires=" + time;
}

function deleteCookie(name) {
	if(getCookie(name)) d.cookie = name + "=" + "; path=/; expires=Mon, 01 Jan 01 01:01:01 GMT";
}	


/* NB: create an element */
function createElement(el,i,cN,url,alt,w,h,t,type,rel){
// only el is required; unused parms should be empty quotes
// if el=="link" and the url ends with ".css", type and rel aren't needed 
// if el=="script" and the url ends with ".js", don't define type
// if el=="input" and the url is included, don't define type
// example: 
// 1) createElement("p");
// 2) createElement("img","","icon","/icon.gif","Icon",12,12);
// 3) createElement("a","back","","/lastpage/","","","","Go back","","previous");
// returns: 
// 1) <p></p>
// 2) <img src="/icon.gif" class="icon" alt="Icon" width="12" height="12">
// 3) <a href="/lastpage/" id="back" title="Go back" rel="previous"></a>
	if(el) { el = el.toLowerCase(); } 
	else { return null; }
	
	var nObj = d.createElement(el);
	if(i){ nObj.id = i; }
	if(cN){ nObj.className = cN; }
	if(t){ nObj.title = t; }
	if(w){ nObj.width = w; }	
	if(h){ nObj.height = h; }	
	
	if(url && (el=="a" || el=="area" || el=="link" || el=="base")){ 
		nObj.href = url; 	
	}	else if(url && (el=="img" || el=="input" || el=="script" || el=="frame" || el=="iframe")){ 	
		nObj.src = url;
	} else if(el=="object" && type=="application/x-shockwave-flash"){ 	
		nObj.data = url;
	} 
	
	if(el=="img" || el=="input" || el=="area"){ 
		nObj.alt = (alt) ? alt : "";
	}
	
	if(el=="input" && url){ 
		nObj.type = "image";
	} else if(el=="link" && url.indexOf(".css")==url.length-4 && !rel){
		nObj.type = "text/css";
		nObj.rel = "stylesheet";
	}	else if(el=="script" && url.indexOf(".js")==url.length-3){
		nObj.type = "text/javascript";
	}	else {
		if(rel){ nObj.rel = rel; }
		if(type){ nObj.type = type; }
	}
	
	return nObj;
}

/* 
	NB: add + remove elements 
	written by Dan L., 2007 with input from Dean Edwards
*/ 

function addEvent(element, type, handler) {
	if (!handler.$$guid) handler.$$guid = addEvent.guid++;
	if (!element.events) element.events = {};
	var handlers = element.events[type];
	if (!handlers) {
		handlers = element.events[type] = {};
		if (element["on" + type]) {
			handlers[0] = element["on" + type];
		}
	}
	handlers[handler.$$guid] = handler;
	element["on" + type] = handleEvent;
};

addEvent.guid = 1;
	
function removeEvent(element, type, handler) {
	if (element.events && element.events[type]) {
		delete element.events[type][handler.$$guid];
	}
};

function handleEvent(event) {
	var returnValue = true;
	event = event || fixEvent(window.event);
	var handlers = this.events[event.type];
	for (var i in handlers) {
		this.$$handleEvent = handlers[i];
		if (this.$$handleEvent(event) == false) {
			returnValue = false;
		}
	}
	return returnValue;
};

function fixEvent(event) {
	event.preventDefault = fixEvent.preventDefault;
	event.stopPropagation = fixEvent.stopPropagation;
	return event;
};

fixEvent.preventDefault = function() {
	this.returnValue = false;
};

fixEvent.stopPropagation = function() {
	this.cancelBubble = true;
};

/*-----------------------------------------------
------------------------------------------------
Digg and Delicious
-------------------------------------------------
------------------------------------------------*/

function diggIt() {
    //window.open('http://digg.com/submit?phase=2&url=http://www.citynews.ca/news/news_7657.aspx&title='+encodeURIComponent(document.title), 'digg','toolbar=no,scrollbars=yes,width=950,height=600');
    window.open('http://digg.com/submit?phase=2&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title), 'digg','toolbar=no,scrollbars=yes,width=950,height=600');
}
function delicious() {
    window.open('http://del.icio.us/post?v=4&noui&jump=close&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title), 'delicious','toolbar=no,width=700,height=400');
}

function techmorati() {
    window.open('http://technorati.com/faves/yourname?add='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title), 'techmorati','toolbar=no,width=700,height=400');
}

function google() {
    window.open('http://www.google.com/bookmarks/mark?op=add&bkmk='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title), 'google','toolbar=no,width=700,height=400');
}
