var summarypage_id = ""

var NodeTypeElement = 1;
var NodeTypeText = 3;

function getXMLDocument (xmldata)
{
	var xmlDoc = null;
	if (document.all)
	{
		try
		{
			xmlDoc = new ActiveXObject("MSXML2.DOMDocument.4.0");
			xmlDoc.async = false;
		}
		catch (e)
		{
		}
		if (xmlDoc == null)
		{
			try
			{
				xmlDoc = new ActiveXObject("MSXML2.DOMDocument");
				xmlDoc.async = false;
			}
			catch (e)
			{
			}
		}
		xmlDoc.loadXML(xmldata);
	}
	else if (document.implementation && document.implementation.createDocument)
	{
    // Mozilla, create a new DOMParser 
	    var parser = new DOMParser(); 
		 xmlDoc = parser.parseFromString(xmldata, "text/xml"); 
	}
	return xmlDoc;
}


function sendHTTPRequest (url, callbackname)
{
	if (callbackname == null) callbackname = defaultcallback;
	//instantiate XmlHttpRequest
	
	var xmlhttp = null;

	// Checking if IE-specific document.all collection exists 
	// to see if we are running in IE 
	if (document.all)
	{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	else
	{ 
		// Mozilla - based browser 
		xmlhttp = new XMLHttpRequest();
	}

	var func =
		function ()
		{
			if (xmlhttp != null && xmlhttp.readyState == 4)
			{
				var rt = xmlhttp.responseText;
//                                 alert("returnvalue" + rt);
				try
				{
                                     
					var xmlDoc = getXMLDocument(rt);

					callbackname(xmlDoc);
				}
				catch (e)
				{
					alert("Error " + e);
				}
			}
		};

	//hook the event handler
	xmlhttp.onreadystatechange = func;
	//prepare the call, http method=GET, false=asynchronous call
	xmlhttp.open("GET", url, true);
	
	//finally send the call
	xmlhttp.send(null);
}

function defaultcallback ()
{
}


function getXMLNodeValue (Item)
{
  if (Item.childNodes.length == 1)
  {
    var child = Item.childNodes.item(0);
    return child.nodeValue
  }
  else
  {
    return Item.text;
  }
}

function postComment ()
{
    var f = document.getElementById('commentform');
    var commentfield = document.getElementById('newcommentfield');
    if (commentfield.value == '')
    { alert("You must enter a comment before submitting the form.");}
    else
    { f.submit();}
}

function deleteComment (commentid, obj_id, obj_type)
{
    if (confirm("Are you sure you want to delete the comment?"))
    {
        document.location = "/zonesadmin/deletecomment/" + commentid + "?obj_type=" + obj_type + "&obj_id=" + obj_id;
    }
}


function showCommentBox ()
{
    var usercookie = Z_GetCookie("remember_me");
    var showit = usercookie != null && usercookie != "";

    if (showit)
    {
        var commentdiv = document.getElementById('newcomment');
        if (commentdiv != null)
        {
            commentdiv.style.display = "block";
        }
    }
    else
    {
        var commentlogindiv = document.getElementById('newcommentlogin');
        if (commentlogindiv != null)
        {
            commentlogindiv.style.display = "block";
        }
    }
}


function showSuggestBox ()
{
    var usercookie = Z_GetCookie("remember_me");
    var showit = usercookie != null && usercookie != "";

    if (!showit)
    {
        newurl = heliumdomain + "/login?login_redirect=" + document.URL;
        document.location = newurl;
        return;
    }

	var sl = document.getElementById('submitLink');
  var snl = document.getElementById('submitNewLink');
  if (sl != null && sl.style.display == 'none')
  {
      sl.style.display = "block";
      snl.style.display = "none";
  }
  else
  {
      sl.style.display = "none";
      snl.style.display = "block";
  }
}

function tracklinkclick (elem, type, id)
{
    try
    {
    var u = document.location.href;
    var l = elem;
    //alert(elem + "hello");
    path = spdomain + "/zones/linkclick/?id=" + id + "&type=" + type + "&fromurl=" + escape(u) + "&tourl=" + escape(l)
    if (typeof (XMLHttpRequest) != "undefined")
    {
        //alert(path);
        req = new XMLHttpRequest();
        req.open("GET", path, false);
        req.send(null);
    }
    }
    catch (e)
    {
    }
}

var HELGoogleMaps = null;

function HELGoogleMap (divid, location, info, maptype)
{
    this.divid = divid;
    this.location = location;
		this.info = info;
		this.maptype = maptype;
}

function HELaddMap (divid, location, info, maptype)
{
    if (HELGoogleMaps == null)
    {
        HELGoogleMaps = new Array();
    }
    HELGoogleMaps[HELGoogleMaps.length] = new HELGoogleMap(divid, location, info, maptype);
}

function showAddress (geocoder, address, map, info)
{
    geocoder.getLatLng(address,    
        function(point) {
            if (!point)
                {
                    alert(address + " not found");     
                }
                else
                    {
                        map.setCenter(point, 13);
                        var marker = new GMarker(point);
                        map.addOverlay(marker);
												if (info != null && info.length > 0)
                        {marker.openInfoWindowHtml(info);}
                    }
                });
}

function initMaps ()
{
    if (HELGoogleMaps != null && GBrowserIsCompatible())
    {
        for (var i = 0; i < HELGoogleMaps.length; i++)
        {
                    var map = new GMap2(document.getElementById(HELGoogleMaps[i].divid));
										var mtype = G_NORMAL_MAP;
										if (HELGoogleMaps[i].maptype == "satellite")
											 {mtype = G_SATELLITE_MAP;}
										else if (HELGoogleMaps[i].maptype == "hybrid")
											 {mtype = G_HYBRID_MAP;}
										else if (HELGoogleMaps[i].maptype == "physical")
											 {mtype = G_PHYSICAL_MAP;}
											 
										map.setMapType(mtype);
                    showAddress(new GClientGeocoder(), HELGoogleMaps[i].location, map, HELGoogleMaps[i].info);
        }
    }
}

function onloadpage ()
{
    if (HELGoogleMaps != null)
    {
        initMaps();
    }
}

function onunloadpage ()
{
    if (HELGoogleMaps != null)
    {
        GUnload();
    }
}

function addLoadEvent(func) {
   var oldonload = window.onload;
   if (typeof window.onload != 'function') {
       window.onload = func;
   }
   else {
       window.onload = function() {
           oldonload();
           func();
       }
   }
}

function addUnLoadEvent(func) {
   var oldonunload = window.onunload;
   if (typeof window.onunload != 'function') {
       window.onunload = func;
   }
   else {
       window.onunload = function() {
           oldonunload();
           func();
       }
   }
}

var googleattached = false;
function addGoogleFunctions ()
{
    if (!googleattached)
    {
        googleattached = true;
        addLoadEvent(onloadpage);
        addUnLoadEvent(onunloadpage);
    }
}


function handleDelicious (links)
{
    html = new Array();
    var l = links.length;
    html[html.length] = "<ul>"
    for (var i = 0; i < l; i++)
    {
        link = links[i];
        var url = link.u;
        var desc = link.d;
        html[html.length] = "<li><a ";
        html[html.length] = "onclick=\"tracklinkclick(this, 'delicious','" + summarypage_id + "')\" ";
        html[html.length] = " target=\"_blank\" href=\"" + url + "\">" + desc + "</a></li>"
    }
    html[html.length] = "</ul>"
    document.write(html.join('\n'));
}

function handleTwitter (twitters)
{
    html = new Array();
    var l = twitters.length;
    html[html.length] = "<ul>"
    for (var i = 0; i < l; i++)
    {
        var twitter = twitters[i];
        var username = twitter.user.screen_name;
        var desc = twitter.text;
        var id = twitter.id;
        html[html.length] = '<li><span>'+ desc +'</span><div id=\"pubdate\"<a ';
        html[html.length] = "onclick=\"tracklinkclick(this, 'twitter','" + summarypage_id + "')\" ";
        html[html.length] = ' target=\"_blank\" href="http://twitter.com/'+ username +'/statuses/'+ id +'">' + relative_time(twitters[i].created_at) + '</a></div></li>'
    }
    html[html.length] = "</ul>"
    document.write(html.join('\n'));
}



function relative_time(time_value) {
  var values = time_value.split(" ");
  time_value = values[1] + " " + values[2] + ", " + values[5] + " " + values[3];
  var parsed_date = Date.parse(time_value);
  var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
  var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);
  delta = delta + (relative_to.getTimezoneOffset() * 60);

  if (delta < 60) {
    return 'less than a minute ago';
  } else if(delta < 120) {
    return 'about a minute ago';
  } else if(delta < (60*60)) {
    return (parseInt(delta / 60)).toString() + ' minutes ago';
  } else if(delta < (120*60)) {
    return 'about an hour ago';
  } else if(delta < (24*60*60)) {
    return 'about ' + (parseInt(delta / 3600)).toString() + ' hours ago';
  } else if(delta < (48*60*60)) {
    return '1 day ago';
  } else {
    return (parseInt(delta / 86400)).toString() + ' days ago';
  }
}

var windowResizers = null;
function handleWindowResize ()
{
    if (windowResizers != null)
    {
        (windowResizers)();
    }
}

function gotoPage (nextpage)
{
    document.TheSearchForm.startpage.value = nextpage;
    document.TheSearchForm.submit();
}
function changeSort (sorton)
{
    document.TheSearchForm.sorton.value = sorton;
    document.TheSearchForm.submit();
}



function restartsearch ()
{
    document.TheSearchForm.startpage.value = "1";
    document.TheSearchForm.submit();
}



/* Override Ad Server */

HELAD_PageLocations_Google[HELAD_PageLocations_Google.length] = "groupright1"
HELAD_PageLocations_Google[HELAD_PageLocations_Google.length] = "220"
HELAD_PageLocations_Google[HELAD_PageLocations_Google.length] = "groupright2"
HELAD_PageLocations_Google[HELAD_PageLocations_Google.length] = "221"

HELAD_PageLocations_Google[HELAD_PageLocations_Google.length] = "zoneright1"
HELAD_PageLocations_Google[HELAD_PageLocations_Google.length] = "225"
HELAD_PageLocations_Google[HELAD_PageLocations_Google.length] = "zoneright2"
HELAD_PageLocations_Google[HELAD_PageLocations_Google.length] = "226"

HELAD_PageLocations_Google[HELAD_PageLocations_Google.length] = "messagingright1"
HELAD_PageLocations_Google[HELAD_PageLocations_Google.length] = "230"
HELAD_PageLocations_Google[HELAD_PageLocations_Google.length] = "messagingright2"
HELAD_PageLocations_Google[HELAD_PageLocations_Google.length] = "231"

HELAD_PageLocations_Google[HELAD_PageLocations_Google.length] = "peopleright1"
HELAD_PageLocations_Google[HELAD_PageLocations_Google.length] = "235"
HELAD_PageLocations_Google[HELAD_PageLocations_Google.length] = "peopleright2"
HELAD_PageLocations_Google[HELAD_PageLocations_Google.length] = "236"

HELAD_PageLocations_Google[HELAD_PageLocations_Google.length] = "articlesright1"
HELAD_PageLocations_Google[HELAD_PageLocations_Google.length] = "240"
HELAD_PageLocations_Google[HELAD_PageLocations_Google.length] = "articlesright2"
HELAD_PageLocations_Google[HELAD_PageLocations_Google.length] = "241"

function HELAD_getMappedZones (adparams, zonemappings)
{
    if (adzonetag == "group")
    {
      return "260"
    }
    else if (adzonetag == "zone")
    {
      return "261"
    }
    else if (adzonetag == "messaging")
    {
      return "262"
    }
    else if (adzonetag == "people")
    {
      return "263"
    }
    else if (adzonetag == "articles")
    {
      return "264"
    }
    return "";
}

var lastblockopenid = null;

function showBlockCommands (item, blockid)
{
    if (lastblockopenid != null)
    {
        closeBlockWindow(lastblockopenid);
    }
    var block = document.getElementById("blockcommands" + blockid)
    if (block != null)
    {
        //var parent = block.parentNode;
        //var bb = getBoundingBox(parent);
        //shiftTo(block, bb.left, bb.top);
        block.style.visibility = "visible";
        lastblockopenid = blockid;
    }
}

function closeBlockWindow (blockid)
{
    var block = document.getElementById("blockcommands" + blockid)
    if (block != null)
    {
        block.style.visibility = "hidden";
    }
    lastblockopenid = null;
}

function pollAnswer (id,nvotes,title)
{
    this.id = id;
    this.nvotes = nvotes;
    this.title = title;
}

function pr_updateBar ()
{
    for (var i = 0; i < this.results.length; i++)
    {
        var answer = this.results[i];
        var answer_id = answer.id;
        var imgid  = "pollimg" + this.poll_id + "-" + answer_id;
        var img = document.getElementById(imgid);
        var answerpercentage = this.totalVotes > 0 ? (100*answer.nvotes / this.totalVotes) : 0;
        if (imgid != null)
        {
            answerpercentage = answerpercentage * this.percentage / 100;
            img.style.width = "" + answerpercentage + "%";
            if (answer.nvotes == this.highestVotes)
            {
                var parent = img.parentNode.parentNode;
                if (parent != null)
                {
                    parent.style.fontSize = "14px";
                    parent.style.fontWeight = "bold";
                }
            }
        }
    }
}


var PollResults = null;
function PollResult (poll_id, results, totalVotes, highestVotes)
{
    this.poll_id = poll_id;
    this.results = results;
    this.totalVotes = totalVotes;
    this.highestVotes = highestVotes;
    this.percentage = 0;
    this.updateBar = pr_updateBar;
}

function getPollResults (poll_id)
{
    if (PollResults != null)
    {
        for (var i = 0; i < PollResults.length; i++)
        {
            if (PollResults[i].poll_id == poll_id)
            {
                return PollResults[i];
            }
        }
    }
    return null;
}

function updatePercentageBar (poll_id)
{
    presults = getPollResults(poll_id);
    if (presults != null)
    {
        if (presults.percentage < 100)
        {
            presults.percentage += 2;
            presults.updateBar();
            window.setTimeout("updatePercentageBar(" + poll_id + ")", 10);
        }
    }
}


//window.setTimeout("scrollRibbon()", 2)


function handlePollClick (xmlDoc)
{
    var poll_id = null;
    var results = new Array();
    try
    {
	var root = xmlDoc.documentElement;
	var oNodeList = root.childNodes;

	for (var i=0; i < oNodeList.length; i++)
	{
		var Item = oNodeList.item(i);
		if (Item.nodeType == NodeTypeElement)
		{
                   if (Item.nodeName == "poll_id")
                   {
                     if (Item.childNodes.length == 1)
                     {
                         var child = Item.childNodes.item(0);
                         poll_id = child.nodeValue
                     }
                     else
                     {
                        poll_id = Item.text;
                     }
                   }
                   else if (Item.nodeName == "pollresult")
   		   {
                        var title = "";
                     if (Item.childNodes.length == 1)
                     {
                         var child = Item.childNodes.item(0);
                         title = child.nodeValue
                     }
                     else
                     {
                        title = Item.text;
                     }
                        var id = Item.getAttribute("id");
                        var nvotes = parseInt(Item.getAttribute("nvotes"));
                        results[results.length] = new pollAnswer(id, nvotes, title)
                   }
		}
       	}
    }
    catch (e)
    {
    	alert("Error " + e);
    }
    if (poll_id != null && results.length > 0)
    {
        if (PollResults == null)
        {
            PollResults = new Array();
        }
    	var thediv = document.getElementById("pollanswers" + poll_id);
        if (thediv != null)
        {
            var totalVotes = 0;
            var highestVotes = 0;
            for (var i = 0; i < results.length; i++)
            {
                result = results[i];
                totalVotes += result.nvotes;
                if (result.nvotes > highestVotes)
                {
                    highestVotes = result.nvotes;
                }
            }
            PollResults[PollResults.length] = new PollResult(poll_id, results, totalVotes, highestVotes);
            html = new Array();
            html[html.length] = "<ul>"
            for (var i = 0; i < results.length; i++)
            {
                result = results[i];
                var percentage = Math.round(totalVotes > 0 ? (100 * result.nvotes /  totalVotes) : 0);
                html[html.length] = "<li>" + result.title + " " + result.nvotes + " votes";
                html[html.length] = "(" + percentage + "%)";
                html[html.length] = "<div id=\"pollbackground\">";
                html[html.length] = "<img style=\"width=:" + 0 + "%\" id=\"pollimg" + poll_id + "-" + result.id + "\" src=\"/spresources/images/new/poll_spacer.gif\">";
                html[html.length] = "</div></li>";
            }
            html[html.length] = "</ul>";
            thediv.innerHTML = html.join("\n");
            window.setTimeout("updatePercentageBar(" + poll_id + ")", 10);
        }
    }
}



function pollclick (poll_id, answer_id)
{
    // Ajax to update data and to show results
    url = "/zones/handlePollClick/?poll_id=" + poll_id + "&answer_id=" + answer_id;

    sendHTTPRequest(url, handlePollClick);

    //var cookie_date = new Date ( );  // current date & time
    //cookie_date.setTime ( cookie_date.getTime() + 10000000000 );
    //document.cookie = "pollclick" + poll_id + "=voted; expires=" + cookie_date.toGMTString() + ";path=/zones";

}


function checkpollvoted (poll_id)
{
    // Ajax to update data and to show results
    url = "/zones/checkPollVoted/?poll_id=" + poll_id;
    sendHTTPRequest(url, handlePollClick);

}

function bb_insideof (x, y)
{
	return this.left <= x && x <= (this.left + this.width) &&
				 this.top  <= y && y <= (this.top + this.height);
}

function bb_above (x, y)
{
	return this.left <= x && x <= (this.left + this.width) &&
				 this.top  > y;
}

function bb_below (x, y)
{
	return this.left <= x && x <= (this.left + this.width) &&
				 y > (this.top + this.height);
}

function WindowBoundingBox (left, top, width, height)
{
	this.left = left;
	this.top = top;
	this.width = width;
	this.height = height;
	this.insideof = bb_insideof;
	this.above = bb_above;
	this.below = bb_below;
}

function getBoundingBox (obj)
{
	if (obj.offsetParent == null)
		return new WindowBoundingBox(obj.offsetLeft, obj.offsetTop, obj.offsetWidth, obj.offsetHeight);
	else
	{
		var bb = getBoundingBox(obj.offsetParent);
		bb.left += obj.offsetLeft;
		bb.top += obj.offsetTop;
		bb.width = obj.offsetWidth;
		bb.height = obj.offsetHeight;
		return bb;
	}
}

var HelpWindowOpen = null;

function closeHelpWindow ()
{
    var helpbox = document.getElementById("HelpBox");
    helpbox.style.visibility = "hidden";
    helpbox.style.display = "none";    
		HelpWindowOpen = null;
}


function onMouseMoveHelpBox (evt)
{
	if (HelpWindowOpen == null)
	{	 return;}
		
	var evtPageX = 0;
	var evtPageY = 0;
	if (typeof(evt) == "undefined")
	{
		evt = window.event;
		evtPageX = evt.offsetX;
		evtPageY = evt.offsetY;
	}
	else
	{
		evtPageX = evt.pageX;
		evtPageY = evt.pageY;
	}
	 
	if (!HelpWindowOpen.insideof(evt.clientX, evt.clientY))
	{
		 closeHelpWindow();
	}
}

function showHelpText (control, title, text)
{
    var objBB = getBoundingBox(control);
		
    var helpbox = document.getElementById("HelpBox");
    helpbox.style.visibility = "visible";
    helpbox.style.display = "block";
    helpbox.style.top = (objBB.top - 20) + "px"; //"-11px";
    helpbox.style.left =  (objBB.left + 40) + "px"; //"525px";
    
    var arrow = document.getElementById("HelpBox-arrow");
    arrow.className = "transp nw";
    arrow.style.top = "22px";
    
    var content = document.getElementById("HelpBox-content");
    var html = "<span class=\"title\">" + title + "&nbsp;&nbsp;<a href=\"javascript:closeHelpWindow()\">Close</a></span><div class=\"bobContent\"><div class=\"agMovie\"><p class=\"synopsis\">" +
        text + "</p></div>";
    content.innerHTML = html;
		
		HelpWindowOpen = new WindowBoundingBox(objBB.left-10, objBB.top-10, 200, 200);

		document.onmousemove = onMouseMoveHelpBox;
}


function postFormUnlessEmptySearch ()
{
  var search_field_value = document.searchForm.phrase.value;
  if (search_field_value.length == 0 || search_field_value == "Search Helium")
  {
    document.searchForm.phrase.value = "";
  }
  else
  {
    newurl = "/zones/fullsearch/?fromButton=yes&searchType=" + escape(document.searchForm.searchType.value) + 
        "&phrase=" + escape(document.searchForm.phrase.value);
    document.location.href = newurl;
  }
}

function popup_help(page) {
  day = new Date();
  id = day.getTime();
  URL = '/search' + page;
  window.open(URL, id, 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=800,height=500,left = 100,top = 100');
}

function clearSearchBox(textToClear)
{
  if (document.searchForm.phrase.value == textToClear)
  {
    document.searchForm.phrase.value = "";
  }
  document.searchForm.phrase.style.color ="#000000";
}

function Z_GetCookie(check_name) {
 var a_all_cookies = document.cookie.split(';');
 for ( i = 0; i < a_all_cookies.length; i++ )
 {var a_temp_cookie = a_all_cookies[i].split('=');
  if (a_temp_cookie[0].replace(/^\s+|\s+$/g, "") == check_name)
  {if (a_temp_cookie.length > 1)
   {return unescape(a_temp_cookie[1]);}
   return null;}}
 return null;
}

var HELAD_PageAdSlots = new Array("Article", "left1,leaderboard1,c_billboard1,right1,right2,right3,right4,right5",
"ArticleShort", "left1,leaderboard1,right1,right2,right3,right4,right5",
//"ArticleList", "left1,leaderboard1,right1,right2,right3,right4,right5,right6,right7,right8,right9,right10,right11,right12,right13,right14,center_banner1",
"ArticleList", "left1,leaderboard1,right1,right2,right3,right5,right7,right9,center_banner1,articlelist2",
"Channel", "left1,left2,right1,right2,right3,right4,right5,right6,right7,right8,right9,center_banner1,center_banner2,center_banner3",
//"Home", "left1,left2,right1,right2,right3,right4,right5,right6,right7,right8,right9,center_banner1,center_banner2,center_banner3,center_banner4,center_banner5,center_banner6,center_banner7",
"Home", "left1,left2,right1,right3,right5,right7,right9,center_banner1,center_banner2,center_banner3",
"LeftTwo", "left1,left2",
"Discussion", "leaderboard1",
"Zone", "zonemiddle,sp_leaderboard1,zoneright1,zoneright2",
"Zones", "zoneright1,zoneright2",
"ZonesAdmin", "zoneright1,zoneright2",
"People", "peopleright1,peopleright2",
"Groups", "groupright1,groupright2",
"Messaging", "messagingright1,messagingright2",
"Other", "left1"
);


var htmleditors = null;
function toggleeditorhtml (ctrl)
{
    if (htmleditors == null)
    {
        htmleditors  = new Array();
    }
    toggleeditor(ctrl);
    var foundit = -1;
    for (var i = 0; i < htmleditors.length; i++)
    {
        var item = htmleditors[i];
        if (item == ctrl)
        {
            foundit = i;
            break;
        }
    }
    if (foundit == -1)
    {
        htmleditors[htmleditors.length] = ctrl;
    }
    else
    {
        htmleditors.splice(foundit, 1);
    }
}

function finishedits ()
{
    if (htmleditors != null)
    {
      for (var i = 0; i < htmleditors.length; i++)
      {
          var item = htmleditors[i];
          toggleeditor(item);
      }
      htmleditors = null;
    }
}
function validateForm ()
{
	return true;
}

function submitForm ()
{
    finishedits();
		if (!validateForm())
		{
		  return false;
		}
    document.TheForm.submitaction.value = "Done";
    document.TheForm.submit();
}


function recordView (id)
{
	var docurl = document.location.href;
	var referringurl = document.referrer;
	if (docurl.indexOf("/zone/") >= 0)
	{
	  var url = "/zones/recordZoneView/" + id + "?rurl=" + escape(referringurl);
	  sendHTTPRequest(url, null);
  }
}


function setTimeZone (needit)
{
	var timezonesaved = document.cookie.indexOf("zonetimezone");
	if (needit == 'true' || timezonesaved == -1)
	{
		var tzcurrentTime = new Date();
		var tztimezone = tzcurrentTime.getTimezoneOffset();

		var timezoneurl = "/zones/setUserTimeZone/" + tztimezone;
	  sendHTTPRequest(timezoneurl, null);
		 
		document.cookie = "zonetimezone=;path=/";
	}
}


function TrimString(sInString) {
  sInString = sInString.replace( /^\s+/g, "" );// strip leading
  return sInString.replace( /\s+$/g, "" );// strip trailing
}


function rateUp (id)
{
  url = "/zones/recordZoneRating/" + id + "?rating=up"
  sendHTTPRequest(url, null);	
	alert("Thank you for your rating.  Your rating will be processed later today.");
}

function rateDown (id)
{
  url = "/zones/recordZoneRating/" + id + "?rating=down"
  sendHTTPRequest(url, null);	
	alert("Thank you for your rating.  Your rating will be processed later today.");
}

var SlideShows = new Array();
function SlideShow (slideshow_id, autoplay, delay, slidewidth, slideheight, nslides)
{
	this.slideshow_id = slideshow_id;
	this.slide_id = 0;
	this.slide_number = 1;
	this.autoplay = autoplay;
	this.playing = autoplay;
	this.delay = delay;
	this.slidewidth = slidewidth;
	this.slideheight = slideheight;
	this.nslides = nslides;
	SlideShows[SlideShows.length] = this;
}

function findSlideShow (slideshow_id)
{
	for (var i=0; i < SlideShows.length; i++)
  {
		var ss = SlideShows[i];
		if (ss.slideshow_id == slideshow_id)
		{
			 return ss;
		}
	}
	var ss = new SlideShow(slideshow_id, false, 5);
	SlideShows[SlideShows.length] = ss;
	return ss;
}

function showslideinzone (slideshow_id, slide_id, imagefile, imgwidth, imgheight, slide_title, slide_description, slide_number)
{
	var ss = findSlideShow(slideshow_id);
	ss.slide_id = slide_id;
	ss.slide_number = slide_number;
	var div = document.getElementById("slideshow" + slideshow_id);
	if (div != null)
	{
		 if (imgwidth >= imgheight)
		 {
				div.innerHTML = "<img src=\"" + imagefile + "\" />";
		 }
		 else
		 {
				div.innerHTML = "<img src=\"" + imagefile + "\" />";
		 }
	}
	var ctrls = document.getElementById("slidetitle" + slideshow_id);
	if (ctrls != null)
	{
		 ctrls.innerHTML = slide_title;
	}
	var ctrls = document.getElementById("slidedescription" + slideshow_id);
	if (ctrls != null)
	{
		 ctrls.innerHTML = slide_description;
	}
	var ctrls = document.getElementById("slidenumber" + slideshow_id);
	if (ctrls != null)
	{
		 ctrls.innerHTML = "Showing " + slide_number + " out of " + ss.nslides;
	}
	 
  var d = document.getElementById("prevslide" + slideshow_id);
  if (d != null)
  {
		if (parseInt(slide_number) == 1)
		{
			 d.disable = true;
			 d.removeAttribute("href");
		}	
		else
		{
			 d.disable = false;
			 d.href = "javascript:prevSlide(" + slideshow_id + ")";
		}	
  }
	 
  var d = document.getElementById("nextslide" + slideshow_id);
  if (d != null)
  {
		if (parseInt(slide_number) == ss.nslides)
		{
			 d.disable = true;
			 d.removeAttribute("href");
		}
		else
		{
			 d.href = "javascript:nextSlide(" + slideshow_id + ")";
			 d.disable = false;
		}
  }
	 
	var func1 = "nextSlideAutoPlay(" + ss.slideshow_id + ")";
	var d = ss.delay * 1000;
	if (ss.playing)
  {
		window.setTimeout(func1, d);
  }
}


function handleSlideShow (xmlDoc)
{
    var slideshow_id = null;
    var slide_number = null;
    var slide_id = null;
    var slide_file = null;
    var slide_title = null;
    var slide_description = null;
    var slide_width = null;
    try
    {
	var root = xmlDoc.documentElement;
	var oNodeList = root.childNodes;

	for (var i=0; i < oNodeList.length; i++)
	{
            var Item = oNodeList.item(i);
            if (Item.nodeType == NodeTypeElement)
            {
               if (Item.nodeName == "slideshow_id")
               {
                  slideshow_id = getXMLNodeValue(Item);
               }
							 else if (Item.nodeName == "slide_number")
               {
                  slide_number = getXMLNodeValue(Item);
               }
							 else if (Item.nodeName == "slide_id")
               {
                  slide_id = getXMLNodeValue(Item);
               }
               else if (Item.nodeName == "slide_file")
               {
                  slide_file = getXMLNodeValue(Item);
               }
               else if (Item.nodeName == "slide_width")
               {
                  slide_width = getXMLNodeValue(Item);
               }
               else if (Item.nodeName == "slide_height")
               {
                  slide_height = getXMLNodeValue(Item);
               }
               else if (Item.nodeName == "slide_description")
               {
                  slide_description = getXMLNodeValue(Item);
               }
               else if (Item.nodeName == "slide_title")
               {
                  slide_title = getXMLNodeValue(Item);
               }
            }
       	}
    }
    catch (e)
    {
    	alert("Error " + e);
    }
    if (slide_file != null && slide_file != "")
    {
			showslideinzone(slideshow_id, slide_id, slide_file, slide_width, slide_height, slide_title, slide_description, slide_number);
    }
}

function prevSlide (slideshow_id)
{
	var ss = findSlideShow(slideshow_id);
	if (ss != null)
	{
	  ss.playing = false;
    url = "/groups/prevSlide/?slideshow_id=" + slideshow_id + "&slide_id=" + ss.slide_id + "&slidewidth=" + ss.slidewidth + "&slideheight=" + ss.slideheight + "&slide_number=" + ss.slide_number;
    sendHTTPRequest(url, handleSlideShow);
	}
}

function nextSlideAutoPlay (slideshow_id)
{
	var ss = findSlideShow(slideshow_id);
	if (ss != null)
	{
		 if (ss.playing)
		 {
				nextSlide(slideshow_id);
		 }
	}
}

function nextSlide (slideshow_id)
{
	var ss = findSlideShow(slideshow_id);
	if (ss != null)
	{
    url = "/groups/nextSlide/?slideshow_id=" + slideshow_id + "&slide_id=" + ss.slide_id + "&slidewidth=" + ss.slidewidth + "&slideheight=" + ss.slideheight + "&slide_number=" + ss.slide_number;
    sendHTTPRequest(url, handleSlideShow);
	}
}

function stopSlide (slideshow_id)
{
	var ss = findSlideShow(slideshow_id);
	if (ss != null)
	{
		 ss.playing = false;
	}
}

function playSlide (slideshow_id)
{
	var ss = findSlideShow(slideshow_id);
	if (ss != null)
	{
		 ss.playing = true;
		 nextSlide(slideshow_id);
	}
}

function submitLinkCheck ()
{
	var newtitle = document.suggestform.suggesttitle.value;
	var newurl = document.suggestform.suggesturl.value;
	if (newtitle.indexOf("www.") >= 0 || newtitle.indexOf(".com") >= 0 || newtitle.indexOf("http:") >= 0)
	{
		 alert("Your title looks like a URL.  Please check that you have entered the information in the correct fields.");
	}
	else if (newtitle.length == 0 || newurl.length == 0)
  {
		alert("You have not filled out both a title and a url.");
	}
	else
	{
		 document.suggestform.submit();
	}
}

function subscribezone (pageid)
{
    var usercookie = Z_GetCookie("remember_me");
    var showit = usercookie != null && usercookie != "";
		if (showit)
		{
			document.location.href = "/zones/subscribe/" + pageid;
		}
		else
		{
			 alert("You must be logged into Helium to subscribe to a Zone.")
		}
}


function handleFollowNew (xmlDoc)
{
    alert("You have been added as a follower.")
}


function followUser (id)
{
  url = "/people/follow_new/" + id
  sendHTTPRequest(url, handleFollowNew);	
}


function handleStopFollowNew (xmlDoc)
{
    alert("You have been removed as a follower.")
}


function stopFollowUser (id)
{
  url = "/people/follow_stop/" + id
  sendHTTPRequest(url, handleStopFollowNew);	
}



/*
Under the Copyright laws, this software may not be copied, translated,
reduced to any electronic or machine readable form or used, in whole or in part
without the prior written consent of Micro Outsource.com, Inc.  
(c)Copyright 2000  Micro Outsource.com,Inc. All rights reserved.
Permission given by Andrew Ressler to use the below functions
*/


function verifyNumber (val, required)
{
	if (val.length == 0)
	{
		return !required;
	}
	var foundPeriod = false;
	for (var i = 0; i < val.length; i++)
	{
		var c = val.charAt(i);
		if (c == '+' || c == '-')
		{
			if (i != 0) return false;
		}
		else if (c == '.')
		{
			if (foundPeriod) return false;
			foundPeriod = true;
		}
		else if (c < '0' || c > '9')
			return false;		
	}
	if (foundPeriod && val.length <= 1) return false;
	return val.length > 0;
}

function verifyNumberWithError (name, val, required)
{
	if (verifyNumber(val, required)) return true;
	alert("Field, " + name + ", must be a numeric value");
	return false;
}


function verifyInteger (val, required)
{
	if (val.length == 0)
	{
		return !required;
	}
	for (var i = 0; i < val.length; i++)
	{
		var c = val.charAt(i);
		if (c == '+' || c == '-')
		{
			if (i != 0) return false;
		}
		else if (c < '0' || c > '9')
			return false;		
	}
	return true;
}
function verifyIntegerWithError (name, val, required)
{
	if (verifyInteger(val, required)) return true;
	alert("Field, " + name + ", must be an integer value");
	return false;
}
function verifyIntegerWithLimits (name, field, required, min, max)
{
	var fieldvalue = field.value;
	if (!verifyInteger(fieldvalue, required))
	{
		alert("Field, " + name + ", must be an integer value");
		field.focus();
		return false;
	}
	if (fieldvalue < min)
	{
		alert("Field, " + name + ", must be greater than " + min + ".");
		field.focus();
		return false;
	}
	else if (fieldvalue > max)
	{
		alert("Field, " + name + ", must be less than " + max + ".");
		field.focus();
		return false;
	}
	return true;
}


function verifyString (value, field, minlength, maxlength, name)
{
	var l = value.length;
	if (l >= minlength && l <= maxlength)
		return true;
	if (l < minlength)
		alert("The field, " + name + ", must be at least " + minlength + " characters long.");
	else if (l > maxlength)
		alert("The field, " + name + ", cannot be longer than " + maxlength + " characters long.");
	field.focus();
	return false;
}

function GetVerifyString (fieldname, field, minlength, maxlength, errmsg)
{
	var value = field.value;
	var l = value.length;
	if (l < minlength)
	{
		field.focus();
		if (errmsg.length > 0) errmsg += "\n";
		if (minlength == 1)
		{
			errmsg += "The field, " + fieldname + ", is required.";
		}
		else
		if (minlength == 1)
		{
			errmsg += "The field, " + fieldname + ", must be at least " + minlength + " characters long.";
		}
	}
	else if (l > maxlength)
	{
		field.focus();
		if (errmsg.length > 0) errmsg += "\n";
		errmsg += "The field, " + fieldname + ", cannot be longer than " + maxlength + " characters long.";
	}
	return errmsg;
}


function trimString (str)
{
	if (str == null || str == '') return '';
	// search for leading spaces
	var foundfirstchar = -1;
	for (var i = 0; i < str.length; i++)
	{
		if (str.charAt(i) == ' ') continue;
		foundfirstchar = i;
		break;
	}
	if (foundfirstchar > 0)
	{
		str = str.substr(foundfirstchar);
	}
	var foundlastchar = -1;
	for (var i = str.length-1; i >= 0; i--)
	{
		if (str.charAt(i) == ' ') continue;
		foundlastchar = i;
		break;
	}
	if (foundlastchar >= 0 && foundlastchar < (str.length-1))
	{
		str = str.substr(0, foundlastchar+1);
	}
	return str;
}

function getSearchCompleteMethod (divid)
{
	var func =
		function (searcher)
		{
			 searchComplete(searcher, divid);
		};
	return func;
}

function searchComplete(searcher, divid) {
  // Check that we got results
  if (searcher.results && searcher.results.length > 0) {
    // Grab our content div, clear it.
    var contentDiv = document.getElementById(divid);
    contentDiv.innerHTML = '';

		var ulContainer = document.createElement('ul');
    contentDiv.appendChild(ulContainer);

    // Loop through our results, printing them to the page.
    var results = searcher.results;
    for (var i = 0; i < results.length; i++) {
      // For each result write it's title and image to the screen
      var result = results[i];
      var imgContainer = document.createElement('li');
			imgContainer.className = "googleimage";

      var title = document.createElement('div');
			imgContainer.className = "googleimagetitle";
      // We use titleNoFormatting so that no HTML tags are left in the title
			var titletouse = result.titleNoFormatting;
			if (titletouse.length > 15)
			{
				 titletouse = titletouse.substr(0, 15) + " ...";
			}
      title.innerHTML = titletouse;

      var imgDiv = document.createElement('div');
			imgDiv.className = "googleimagediv";

      var newImg = document.createElement('img');
      // There is also a result.url property which has the escaped version
      newImg.src = result.tbUrl;

      imgDiv.appendChild(newImg);
      imgContainer.appendChild(imgDiv);
			
			var anchor = document.createElement('a');
			anchor.appendChild(title);
      anchor.setAttribute("href", result.unescapedUrl);
				
      imgContainer.appendChild(anchor);

      var clearDiv = document.createElement('div');
			clearDiv.className = "clear";
      imgContainer.appendChild(clearDiv);

			// Put our title + image in the content
      ulContainer.appendChild(imgContainer);
    }
  }
}
