		
		// remote scripting library
		// (c) copyright 2005 modernmethod, inc
		var sajax_debug_mode = false;
		var sajax_request_type = "POST";
		
		function sajax_debug(text) {
			if (sajax_debug_mode)
				alert("RSD: " + text)
		}
 		function sajax_init_object() {
 			sajax_debug("sajax_init_object() called..")
 			
 			var A;
			try {
				A=new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					A=new ActiveXObject("Microsoft.XMLHTTP");
				} catch (oc) {
					A=null;
				}
			}
			if(!A && typeof XMLHttpRequest != "undefined")
				A = new XMLHttpRequest();
			if (!A)
				sajax_debug("Could not create connection object.");
			return A;
		}
		function sajax_do_call(func_name, args) {
			var i, x, n;
			var uri;
			var post_data;
			
			uri = "/New_Hampshire/ajax.php";
			if (sajax_request_type == "GET") {
				if (uri.indexOf("?") == -1) 
					uri = uri + "?rs=" + escape(func_name);
				else
					uri = uri + "&rs=" + escape(func_name);
				for (i = 0; i < args.length-1; i++) 
					uri = uri + "&rsargs[]=" + escape(args[i]);
				uri = uri + "&rsrnd=" + new Date().getTime();
				post_data = null;
			} else {
				post_data = "rs=" + escape(func_name);
				for (i = 0; i < args.length-1; i++) 
					post_data = post_data + "&rsargs[]=" + escape(args[i]);
			}
			
			rss_sajax_busy();
			
			x = sajax_init_object();
			x.open(sajax_request_type, uri, true);
			if (sajax_request_type == "POST") {
				x.setRequestHeader("Method", "POST " + uri + " HTTP/1.1");
				x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			}
			x.onreadystatechange = function() {
				if (x.readyState != 4) 
					return;
				sajax_debug("received " + x.responseText);
				
				var status;
				var data;
				status = x.responseText.charAt(0);
				data = x.responseText.substring(2);
				if (status == "-") {
					alert("Error: " + data);
				} else {
					args[args.length-1](data);
				}
				rss_sajax_unbusy();
			}
			sajax_debug(func_name + " uri = " + uri + "\n/post = " + post_data);
			x.send(post_data);
			sajax_debug(func_name + " waiting..");
			delete x;
		}
		
		function rss_sajax_unbusy() {
			span = document.getElementById('ajax_throbber');
			if (span) {
				devnull = span.parentNode.removeChild(span);
			}
			
		}
		
		function rss_sajax_busy() {			
			var span=document.createElement('span');
			span.id='ajax_throbber';
			span.style.position='fixed';
			span.style.left = '5px';
    	span.style.top = '5px';
    	span.style.padding = '3px;';
    	span.className = 'frame';    	
    	span.innerHTML = '<img src="/New_Hampshire/themes/default/web/media/busy.gif" />';
			document.body.appendChild(span);
		}
		
				
		// wrapper for __exp__submitTag		
		function x___exp__submitTag() {
			sajax_do_call("__exp__submitTag",
				x___exp__submitTag.arguments);
		}
		
				
		// wrapper for __exp__getSideContent		
		function x___exp__getSideContent() {
			sajax_do_call("__exp__getSideContent",
				x___exp__getSideContent.arguments);
		}
		
				
		// wrapper for __exp__getFeedContent		
		function x___exp__getFeedContent() {
			sajax_do_call("__exp__getFeedContent",
				x___exp__getFeedContent.arguments);
		}
		
		
/// End Sajax javscript
/// From here on: Copyright (C) 2003 - 2006 Marco Bonetti, gregarius.net
/// Released under GPL

function miniloginform() {
	span = document.getElementById('loginformcontainer');
	if (span.style.display == 'none') {
		span.style.display = 'block';
	} else {
		span.style.display = 'none';
	}
}

function loginHandler() {
	pw = document.getElementById('password');
	username = document.getElementById('username');
	var re = /[0-9a-f]{32}/ ;
	if (! re.test(pw.value)) {
		pw.value = hex_md5(pw.value + username.value);
	} 
	return true;
}

function setTags(id,tagss) {
  tags = tagss.split(' ');

  var fld=document.getElementById("t" + id);
  var html = "";
  for (i=0;i<tags.length;i++) {
     html = html + "<a href=\"/New_Hampshire/tags.php?tag=" + tags[i] + "\">" + tags[i] + "</a> ";
  }
  fld.innerHTML = html;

  var aspan=document.getElementById("ta" + id);
  aspan.innerHTML = "<a href=\"#\" onclick=\"_et(" +id +"); return false;\">edit</a>";
}

function submit_tag_cb(ret) {
    data= ret.replace(/[^a-zA-Z0-9\ _\.,]/gi,"").split(',');
    id=data[0];
    tags=data[1];
    setTags(id,tags);
}


function submit_tag(id,tags) {
    x___exp__submitTag(id, tags, submit_tag_cb);
}

function _et(id) {
   var actionSpan = document.getElementById("ta" + id);
    var toggle = actionSpan.firstChild;
    if (toggle.innerHTML == "submit") {
        var fld = document.getElementById("tfield" + id);
      toggle.innerHTML="...";
        submit_tag(id,fld.value);
    } else if (toggle.innerHTML == "edit") {
       var isIE=document.all?true:false;
       // the tag container
       var tc=document.getElementById("t"+id);
        var tags = tc.innerHTML.replace(/<\/?a[^>]*>(\ $)?/gi,"").replace(/[^a-zA-Z0-9\ _\.]/gi,"");
        // submit link
        toggle.innerHTML="submit";
        // cancel link
        cancel = document.createElement("a");
        cancel.style.margin="0 0 0 0.5em";
        cancel.innerHTML = "cancel";
        cancel.setAttribute("href","#");
        if (isIE) {
            // the IE sucky way
            cancel.onclick = function() { setTags(id,tags); return false;}
       } else {
          // the proper DOM way
            cancel.setAttribute("onclick","setTags("+id+",'"+tags+"'); return false;");
       }
        actionSpan.appendChild(cancel);

		  		  
        tc.innerHTML = "<input class=\"tagedit\" id=\"tfield"
         +id+"\" type=\"text\" value=\"" + tags + "\" />";

        // set the caret to the end of the field for bloody IE
        var control = tc.firstChild;
        control.focus();
        if (control.createTextRange) {
            var range = control.createTextRange();
        range.collapse(false);
            range.select();
        } else if (control.setSelectionRange) {
            control.focus();
            var length = control.value.length;
            control.setSelectionRange(length, length);
        }
    }
    return false;
}


cs = getCookie('side');
if (!cs) {
	cs = '1';
}
document.currentSide = cs;
document.currentSideCache = new Array();
for (i=0;i<3;i++) {
	document.currentSideCache[i] = null;
}


function _side(what) {
	if (document.currentSide == what) {
		return 0;
	} 
	
	document.currentSideCache[document.currentSide] = document.getElementById('channels').innerHTML;
	if ((content = document.currentSideCache[what]) != null) {	
		_setSideContent_cb( what + "#@#" + content );
	} else {
		x___exp__getSideContent(what, _setSideContent_cb);
	}
}

function _setSideContent_cb(ret) {
 	data=ret.split('#@#');
 	kind=data[0];
 	content=data[1];
	c = document.getElementById('channels').innerHTML;
	ul = document.getElementById('sidemenu');
	lis= ul.getElementsByTagName('li');
	for (j=0;j<lis.length;j++) {
		var li = lis[j];
		if (li.id == ('sidemenu'+kind)) {
			li.className = "active";
		} else {
			li.className = "";
		}
	}

	document.currentSide = kind;
	document.currentSideCache[kind] = content;
	document.getElementById('channels').innerHTML = content;
    setRootCookie("side",kind);
}



// feed collapsing
function _ftgl(cid) {
	cids = getCookie('collapsedfeeds');
	if (cids) {
		cidsArr = cids.split(":");
	} else {
		cidsArr = new Array();
	}
	
	var ul = document.getElementById('f'+cid);
	var img = document.getElementById('cli'+cid);
	var collapsed  = (img.parentNode.className == 'expand');
	
	if (collapsed) {
		img.src = img.src.replace(/plus/g,'minus');
		img.parentNode.className = "collapse";
		img.parentNode.parentNode.className="";
		for(i=0;i<cidsArr.length;i++) {
			if (cidsArr[i] == cid) {
				cidsArr[i] = -1;
			}
		}
		if (ul.style.display == "none") {
			ul.style.display = "block";
		} else {
			ul.innerHTML = "...";
			x___exp__getFeedContent(cid, get_feed_content_cb);
		}
	} else {
		img.src = img.src.replace(/minus/g,'plus');
		img.parentNode.className = "expand";
		img.parentNode.parentNode.className="collapsed";
		ul.style.display = "none";
		cidsArr[cidsArr.length]=cid;
	}
	
	cidsArr.sort();
	cidsCookie = "";
	for (i=0;i<cidsArr.length;i++) {
		if (cidsArr[i] > 0) {
			cidsCookie = cidsCookie + cidsArr[i];
			if (i<cidsArr.length -1) {
				cidsCookie += ":";
			}
		}
	}
	setRootCookie('collapsedfeeds',cidsCookie);
}


function get_feed_content_cb(data) {
	d=data.split('|@|');
	cid=d[0];
	html=d[1];
	if (cid) {
		ul = document.getElementById('f'+cid);
		if (ul) {
			ul.innerHTML = html;
			ul.style.display = "block";
		}
	}
}

function setRootCookie(cookieName,cookieValue) {
  setCookie(cookieName,cookieValue,"/New_Hampshire/");	
}	
function setRootSessionCookie(cookieName,cookieValue) {
  setSessionCookie(cookieName,cookieValue,"/New_Hampshire/");	
}	
// src: http://www.javascripter.net/faq/settinga.htm
function setCookie(cookieName,cookieValue,path) {
    //alert(cookieValue);
    var today = new Date();
    var expire = new Date();
    // 1 year
    expire.setTime(today.getTime() + 31536000000);
    document.cookie = cookieName+"="+escape(cookieValue) 
    	+ "; expires="+expire.toGMTString()
    	+ "; path="+path;
}

function setSessionCookie(cookieName,cookieValue,path) {
    document.cookie = cookieName+"="+escape(cookieValue) 
    	+ "; path="+path;    
}

function getCookie(cookieName) {
    var theCookie=""+document.cookie;
    var ind=theCookie.indexOf(cookieName);
    if (ind==-1 || cookieName=="") return "";
    var ind1=theCookie.indexOf(';',ind);
    if (ind1==-1) ind1=theCookie.length;
    return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}


