/* Funtion for resetting the active button by clearing the cookies */
 function ResetActiveSection()
{		

	var IE = document.all?true:false;
	if (IE)
        { 
		if (event.clientY < 0 && event.clientX > document.body.offsetWidth-30) 
		{		
			writeCWSCookie(ActiveSectionButton, "");
		}
	}
	else 
	{
		writeCWSCookie(ActiveSectionButton, "");
	}
}

/* Funtion for finding HTML Control */
function getCWSObj(id) 
{
	if (document.getElementById) {
		return document.getElementById(id);
		}
	else if (document.all) {
		getCWSObj = document.all[id];
		}
}

/* Funtion for Setting the initial state of the page */
function setInitialPageState()
{
	var IE = document.all?true:false;
	try
	{
		SetActiveSection(getCWSObj(readCWSCookie(ActiveSectionButton)));
	}
	catch(Err)
	{
	}
	
	if(!IE) ResetActiveSection();
}

/* function for reading cookies */
function readCWSCookie(name)
{
  var cookieValue = '';
  var search = name + '=';
  if(document.cookie.length > 0)
  { 
    offset = document.cookie.indexOf(search);
    if (offset != -1)
    { 
      offset += search.length;
      end = document.cookie.indexOf(';', offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = unescape(document.cookie.substring(offset, end))
    }
  }
  return cookieValue;
}

/* function for creating cookies */
function writeCWSCookie(name, value)
{
  try
  {
	document.cookie = name + '=' + escape(value);
  }
  catch(Err)
  {}
}

/* function for setting the active buttons */
function SetActiveSection(obj)
{

/* Declare Section state value */
var Hide='none';
var Show='block';
var maxNoOfButtons = 100;

/* Check if container for section buttons and content are already exist on html body */
if(getCWSObj('SectionButtons')==null || getCWSObj('SectionContent')==null) return;


	if (obj==null) obj = getCWSObj('SectionButton1');

	for (var i = 1;i<=maxNoOfButtons;i++)
	{
			//Pre-terminate Loop if SectionButton# is equal to null
			if (getCWSObj("SectionButton" + i)==null) return;

			if ('SectionButton' + i !=obj.id) 
			{
				getCWSObj("SectionButton" + i).className = ''; 
				getCWSObj("Section" + i).style.display  = Hide;
			}
			else
			{
				obj.className = 'bodloadTab';
				getCWSObj("Section" + i).style.display  = Show;
			}
	}
	
}