function getCookie(Name) {
  var search = Name + "="                       
  var CookieString = document.cookie            
  var result = null                               
  if (CookieString.length > 0) {                
    offset = CookieString.indexOf(search)       
    if (offset != -1) {                         
      offset += search.length                   
      end = CookieString.indexOf(";", offset)   
      if (end == -1)                            
        end = CookieString.length               
      result = unescape(CookieString.substring(offset, end))         
                                                
      } 
    }
   return result                                
}


function deleteCookie(Name, Path) {
  setCookie(Name,"Deleted", -1, Path)
}

function scaleWidth()
{
	var optimalLineLength = "35em";
	var extraAccounting = "12em";
	var minimumTextHeight = "10px";
	var windowWidth = document.body.clientWidth;
	var optimalSize = windowWidth / (parseInt(optimalLineLength) + parseInt(extraAccounting));

	if (optimalSize >= parseInt(minimumTextHeight))
	{
		document.body.style.fontSize = optimalSize + "px";
	}
	else
	{
		document.body.style.fontSize = parseInt(minimumTextHeight) + "px";
	}

	return true;
}


function startTextSize()
{
	
    var theContainer = document.getElementById("frame");
    var theContainer2 = document.getElementById("udm");
    var theContainer3 = document.getElementById("loggedin");


    fontcookie=getCookie("fontcookie");
    if (fontcookie=="null" || fontcookie=="NaN" || fontcookie==null)
    {
        currentSize = 1;
        document.cookie = "fontcookie="+currentSize+";path=/";
        theContainer.style.fontSize = currentSize + "em";
	theContainer2.style.fontSize = currentSize + "em";  
	theContainer3.style.fontSize = currentSize + "em";       
    }
    else{
        currentSize=getCookie("fontcookie");
        theContainer.style.fontSize = currentSize + "em";
	theContainer2.style.fontSize = currentSize + "em";
	theContainer3.style.fontSize = currentSize + "em";
    }
} 

function textSize(size)
{
	var theContainer = document.getElementById("frame");
	var theContainer2 = document.getElementById("udm");
        var theContainer3 = document.getElementById("loggedin");

	var increment = 0.1
	var currentSize = parseFloat(document.getElementById("frame").style.fontSize);

	if (!currentSize)
	{
		currentSize = 1;
	}

	
	if (size == "smaller")
	{
		currentValue=(currentSize - increment);
                theContainer.style.fontSize = (currentSize - increment) + "em";
		theContainer2.style.fontSize = (currentSize - increment) + "em";		
		theContainer3.style.fontSize = (currentSize - increment) + "em";	
	}
	else
	{
		currentValue=(currentSize + increment);
                theContainer.style.fontSize = (currentSize + increment) + "em";
		theContainer2.style.fontSize = (currentSize + increment) + "em";
                theContainer3.style.fontSize = (currentSize + increment) + "em";
	}
	

document.cookie = "fontcookie="+currentValue+";path=/";


	return true;
}

function resetSize(norm)
{
	var theContainer = document.getElementById("frame");
	var theContainer2 = document.getElementById("udm");
        var theContainer3 = document.getElementById("loggedin");
	theContainer.style.fontSize = (norm) + "em";
	theContainer2.style.fontSize = (norm) + "em";
	theContainer3.style.fontSize = (norm) + "em";
	document.cookie = "fontcookie="+norm+";path=/";
	return true;
}
