/* -------------------------------------------------------------------
   Browser Detection ------------------------------------------------- */


	var allow_trans; allow_trans = "1";
	var platformname;
	var browserName;

	function browser_detection() {
		platformname = navigator.platform;
		browserName = whichBrs();	
		browserversion="0";
		var safari = navigator.appVersion.search(/Safari/);
		if (navigator.appVersion.indexOf("2.")!=-1) { browserversion="2"; }
		if (navigator.appVersion.indexOf("3.")!=-1) { browserversion="3"; }
		if (navigator.appVersion.indexOf("5.")!=-1) { browserversion="5"; }
		if (navigator.appVersion.indexOf("4")!=-1) { browserversion="4"; if(safari != -1) { browserversion="100"; } }
		if (navigator.appVersion.indexOf("6.")!=-1) { browserversion="6"; }
		if (navigator.appVersion.indexOf("7.")!=-1) { browserversion="7"; }		
		//netsape 6 and 7 returns a 5 but 4.7 is 4.7
		
		if(browserName == "NS"){
			if(parseInt(browserversion) < 5){
				allow_trans = "0";
			}
		}
	}
	browser_detection();

	function whichBrs() {
		var agt=navigator.userAgent.toLowerCase();
		if (agt.indexOf("opera") != -1) return 'Opera';
		if (agt.indexOf("staroffice") != -1) return 'Star Office';
		if (agt.indexOf("beonex") != -1) return 'Beonex';
		if (agt.indexOf("chimera") != -1) return 'Chimera';
		if (agt.indexOf("netpositive") != -1) return 'NetPositive';
		if (agt.indexOf("phoenix") != -1) return 'Phoenix';
		if (agt.indexOf("firefox") != -1) return 'Firefox';
		if (agt.indexOf("safari") != -1) return 'Safari';
		if (agt.indexOf("skipstone") != -1) return 'SkipStone';
		if (agt.indexOf("msie") != -1) return 'MSIE';
		if (agt.indexOf("netscape") != -1) return 'NS';
		if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';
		if (agt.indexOf('\/') != -1) {
		if (agt.substr(0,agt.indexOf('\/')) != 'mozilla') {
		return navigator.userAgent.substr(0,agt.indexOf('\/'));}
		else return 'Netscape';} else if (agt.indexOf(' ') != -1)
		return navigator.userAgent.substr(0,agt.indexOf(' '));
		else return navigator.userAgent;
	}
	

/* -------------------------------------------------------------------
   AJAX -------------------------------------------------------------- */
	
	function createRequestObject() {		
		var ro;
		if(browserName == "MSIE"){
			ro = new ActiveXObject("Microsoft.XMLHTTP");
		}else{
			ro = new XMLHttpRequest();
		}
		return ro;
	}
	var http = createRequestObject();
	



/* ------------------------------------------------------------------
	Send to a Friend ------------------------------------------------ */
	
	function openSend(which, url){
		theSendDiv = document.getElementById("b_sendfriend_" + which);
		theFlashDiv = document.createElement("div");
		theFlashDiv.setAttribute("id", "div_flash_popin");
		theSendDiv.appendChild(theFlashDiv);
			
		document.getElementById("div_flash_popin").className = "div_flash_popin";
			
		var fo = new FlashObject("/flash/send.swf?path_query_url=" + url + "&sendID=" + which, "flash_popin_movie_" + which, "556", "400", "7", "#ffffff");
		fo.addParam("wmode", "transparent");
		fo.write("div_flash_popin");
	}
		
		
	function sendEmail(name,email,friendname,friendemail,comments,path_query_url) {
		http.open('get', '/send/send.asp?name='+name+'&email='+email+'&friendname='+friendname+'&friendemail='+friendemail+'&comments='+comments+'&path_query_url='+path_query_url);
		http.onreadystatechange = nothing;
		http.send(null);
	}
	function nothing(){
		if(http.readyState == 4){
			closePopin("div_flash_popin");
		}
	};
	
	function closePopin(){
		var myContainer = document.getElementById(document.getElementById("div_flash_popin").parentNode.id);
		var toDelete = document.getElementById("div_flash_popin")
		var throwawayNode = myContainer.removeChild(toDelete);
	}


/* ------------------------------------------------------------------
	Selected State -------------------------------------------------- */
 
 	function selectedState(){
		path = new String(location.href); 
	
		pathSplit = path.split("/"); 
		whichSection = pathSplit[3];
		
		if(whichSection == "archives"){
			whichSection = pathSplit[4];
		}

		switch (whichSection) {
			case "blog":
				document.getElementById("m_blog").src = "/images/m_blog_s.gif";
				break
			case "podcast":
				document.getElementById("m_podcasts").src = "/images/m_podcasts_s.gif";
				break
			case "michael-seaton":
				document.getElementById("m_bio_contact").src = "/images/m_bio_contact_s.gif";
				break
			default:
				document.getElementById("m_blog").src = "/images/m_blog_s.gif";
				break
		}
	}

	
/* ------------------------------------------------------------------
   Current Day ------------------------------------------------------ */
   
	function currentDay(){
		var today = new Date();
		var theCurrentDay = today.getDate();
		
		document.getElementById("date_" + theCurrentDay).className = "currentDay";
	}



	
	
/* ---------------------------------------------------
   Get Element by ClassName -------------------------- */

	function getElementsByClassName(oElm, strTagName, oClassNames){
	    var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
	    var arrReturnElements = new Array();
	    var arrRegExpClassNames = new Array();
	    if(typeof oClassNames == "object"){
	        for(var i=0; i<oClassNames.length; i++){
	            arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames[i].replace(/\-/g, "\\-") + "(\\s|$)"));
	        }
	    }
	    else{
	        arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames.replace(/\-/g, "\\-") + "(\\s|$)"));
	    }
	    var oElement;
	    var bMatchesAll;
	    for(var j=0; j<arrElements.length; j++){
	        oElement = arrElements[j];
	        bMatchesAll = true;
	        for(var k=0; k<arrRegExpClassNames.length; k++){
	            if(!arrRegExpClassNames[k].test(oElement.className)){
	                bMatchesAll = false;
	                break;                      
	            }
	        }
	        if(bMatchesAll){
	            arrReturnElements.push(oElement);
	        }
	    }
	    return (arrReturnElements)
	}

	
	
	
/* ---------------------------------------------------
   HREF Target Blank --------------------------------- */

/*
	function linkblankonload(){
		myArray = getElementsByClassName(document.getElementById("right"), "a", "");
		for(var xx=0; xx<myArray.length; xx++){
			if(myArray[xx].rel!="internal"){
				myArray[xx].target = "_blank";
			}
		}
	}*/

function linkblankonload(){
	var allowedDomains = [location.hostname, "http://www.theclientsideblog.dev/", "http://www.theclientsideblog.com"];
		$("a[@href^=http]:not(.internal)")
		.filter(function(el){
		for ( var i=0; i < allowedDomains.length; i++ )
			if ( this.href.indexOf(allowedDomains[i])>-1 ) return false;
			return true;
			})
		//.addClass('external')
		.bind("click", function(){ return !window.open(this.href); });		
}

/* ------------------------------------------------------------------
	Movable Type Stuff -------------------------------------------- */

	// Copyright (c) 1996-1997 Athenia Associates.
	// http://www.webreference.com/js/
	// License is granted if and only if this entire
	// copyright notice is included. By Tomer Shiran.

	function setCookie (name, value, expires, path, domain, secure) {
	    var curCookie = name + "=" + escape(value) + (expires ? "; expires=" + expires : "") +
	        (path ? "; path=" + path : "") + (domain ? "; domain=" + domain : "") + (secure ? "secure" : "");
	    document.cookie = curCookie;
	}

	function getCookie (name) {
	    var prefix = name + '=';
	    var c = document.cookie;
	    var nullstring = '';
	    var cookieStartIndex = c.indexOf(prefix);
	    if (cookieStartIndex == -1)
	        return nullstring;
	    var cookieEndIndex = c.indexOf(";", cookieStartIndex + prefix.length);
	    if (cookieEndIndex == -1)
	        cookieEndIndex = c.length;
	    return unescape(c.substring(cookieStartIndex + prefix.length, cookieEndIndex));
	}

	function deleteCookie (name, path, domain) {
	    if (getCookie(name))
	        document.cookie = name + "=" + ((path) ? "; path=" + path : "") +
	            ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}

	function fixDate (date) {
	    var base = new Date(0);
	    var skew = base.getTime();
	    if (skew > 0)
	        date.setTime(date.getTime() - skew);
	}



	function rememberMe (f) {
	    var now = new Date();
	    fixDate(now);
	    now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
	    now = now.toGMTString();
	    if (f.author != undefined)
	       setCookie('mtcmtauth', f.author.value, now, '/', '', '');
	    if (f.email != undefined)
	       setCookie('mtcmtmail', f.email.value, now, '/', '', '');
	    if (f.url != undefined)
	       setCookie('mtcmthome', f.url.value, now, '/', '', '');
	}

	function forgetMe (f) {
	    deleteCookie('mtcmtmail', '/', '');
	    deleteCookie('mtcmthome', '/', '');
	    deleteCookie('mtcmtauth', '/', '');
	    f.email.value = '';
	    f.author.value = '';
	    f.url.value = '';
	}

	function hideDocumentElement(id) {
	    var el = document.getElementById(id);
	    if (el) el.style.display = 'none';
	}

	function showDocumentElement(id) {
	    var el = document.getElementById(id);
	    if (el) el.style.display = 'block';
	}

	var commenter_name;

	function individualArchivesOnLoad(commenter_name) {
	    if (document.comments_form) {
	        if (document.comments_form.email != undefined &&
	            (mtcmtmail = getCookie("mtcmtmail")))
	            document.comments_form.email.value = mtcmtmail;
	        if (document.comments_form.author != undefined &&
	            (mtcmtauth = getCookie("mtcmtauth")))
	            document.comments_form.author.value = mtcmtauth;
	        if (document.comments_form.url != undefined && 
	            (mtcmthome = getCookie("mtcmthome")))
	            document.comments_form.url.value = mtcmthome;
	        if (mtcmtauth || mtcmthome) {
	            document.comments_form.bakecookie.checked = true;
	        } else {
	            document.comments_form.bakecookie.checked = false;
	        }
	    }
	}

	function writeTypeKeyGreeting(commenter_name, entry_id) {
			
	}


	// Random encryption key feature by Andrew Moulden, Site Engineering Ltd
	// This code is freeware provided these four comment lines remain intact
	// A wizard to generate this code is at http://www.jottings.com/obfuscator/

	var __MTTBLINK__;
	var __MTTBID__;

	function obfuscator(coded, key, mode, path, hidden) {
		shift = coded.length;
		link = "";
			
		for(i=0;i<coded.length;i++) {
			if (key.indexOf(coded.charAt(i))==-1) {
				ltr = coded.charAt(i);link+=(ltr);
			} else {
				ltr = (key.indexOf(coded.charAt(i)) - shift + key.length) % key.length;
				link += (key.charAt(ltr));
			}
		}

		if(mode == 'hidden_input') {
			document.write('<input type="hidden" name="CCode" value="' + link + '" />');
		} else if(mode == '__MTTBLINK__') {
			__MTTBLINK__ = path + link;
			if(hidden) return;
			document.write(link);
		} else if(mode == '__MTTBID__') {
			__MTTBID__ = link;
			if(hidden) return;
			document.write(link);
		}
	}
	

	