﻿
function extractPageName(hrefString)
{
	var arr = hrefString.split('/');
	return  (arr.length < 2) ? hrefString : arr[arr.length-2].toLowerCase() + arr[arr.length-1].toLowerCase();
}
 
function setActiveMenu(arr, crtPage)
{
	for (var i=0; i < arr.length; i++)
	{
		if(extractPageName(arr[i].href) == crtPage)
		{
			if (arr[i].parentNode.tagName != "DIV")
			{
				arr[i].id = "mainLeftSideCurrent";
				arr[i].parentNode.id = "mainLeftSideCurrent";
			}
		}
	}
}
 
function setPage()
{
	hrefString = document.location.href ? document.location.href : document.location;
 
	if (document.getElementById("mainLeftSide") !=null )
	setActiveMenu(document.getElementsByTagName("a"), extractPageName(hrefString));
}

function doLogInOut()
{
    var username=getCookie('myNatureName');
    var userID=getCookie('myNatureID');
    if ((username!=null && username!="") && (userID!=null && userID!=""))
      {
        document.write('<h1>Welcome, ' + username + '!</h1>');
        document.write('<ul><li> - <a href="/myNewfoundlandNature.aspx">My Account</a></li>');
        document.write('<li> - <a href="/myNewfoundlandNature.aspx?map=m">Post your sighting</a></li>');
        document.write('<li> - <a href="/Wildlife-Observations-Sightings/' + userID +'.aspx">My public profile</a></li>');
        document.write('<li> - <a href="/myNewfoundlandNature.aspx?logout=true">Logout</a></li></ul>');
      }
   
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}



function textLimiter(formValue, lngLimit){
    var tex = document.getElementById(formValue).value;
    var len = tex.length;
    if(len > lngLimit){
        tex = tex.substring(0,lngLimit);
        document.getElementById(formValue).value=tex;
        return false;
    }
    document.getElementById("txtLimiter").innerHTML = lngLimit-len
}