var arrSectionName = new Array("Section5","Section1","Section1-2","Section2","Section2-2","Section3","Section3-2","Section4","Section4-2","sortByFour","sortByFourshort");

/* Funtion for finding HTML Control */
function getCWSObj(id) 
{
	if (document.getElementById)
		return document.getElementById(id);
	else if (document.all)
		return document.all[id];
}


function setInitialPageState()
{

	if(getCWSObj('hdContentGroup') && getCWSObj('hdContentGroup').value!="")
	{	
		var content = getCWSObj('hdContentGroup').value.split(";");
		var defaultViewBy;

		for (var i = 0;i<(content.length);i++)
		{
			defaultViewBy=getCWSObj('hdDefaultViewBy_' + content[i]);
			if (defaultViewBy)			
			{
				SetActiveSection(getCWSObj(content[i] + '_Section' + defaultViewBy.value),content[i]);
				SetActiveButton(getCWSObj(content[i] + '_SectionButton' + defaultViewBy.value),content[i]);
			}
			else
			{
				SetActiveSection(null,content[i]);
				SetActiveButton(null,content[i]);			
			}
		}
	}	
}



/* function for setting the active buttons */
function SetActiveSection(obj,listGuid)
{

	/* Declare Section state value */
	var Hide='none';
	var Show='';
	var maxNoOfContents = 100;



	/* Check if container for section content is already exist on html body */
	if(getCWSObj(listGuid + '_' + 'SectionContent')==null) return;

	if (obj==null) obj = getCWSObj(listGuid + '_' + 'Section1')


	/* Iterate to child of buttons control */
	for (var i = 0;i<=maxNoOfContents;i++)
	{
		
		//Pre-terminate Loop if arrSectionName[i] is equal to null
		if (arrSectionName[i]==null) return;
		
		if (getCWSObj(listGuid + '_' + arrSectionName[i])!=null) 
		{

		 /* test if current buttons id is not equal to arguments obj id then hide the current content and set current buttons to inactive, else show the current section and set the current buttons to active */
		if (listGuid + '_' + arrSectionName[i]!=obj.id) 
		{
			getCWSObj(listGuid + '_' + arrSectionName[i]).style.display  = Hide;
		}
		else
		{
			getCWSObj(listGuid + '_' +  arrSectionName[i]).style.display  = Show;
			writeCWSCookie("ActiveIHPBSectionButton", arrSectionName[i]);
		}
		}

	}

}	

/* function for setting the active buttons */
function SetActiveButton(obj,listGuid)
{


var maxNoOfButtons = 100;
	
	/* Check if container for section buttons is already exist on html body */
	if(getCWSObj(listGuid + '_' + 'SectionButtons')==null) return;


	if (obj==null) obj = getCWSObj(listGuid + '_' + 'SectionButton1');

	
	for (var i = 1;i<=maxNoOfButtons;i++)
	{
		
			//Pre-terminate Loop if SectionButton# is equal to null
			if (getCWSObj(listGuid + '_' + 'SectionButton' + i)==null) return;
		
			/* test if current buttons id is not equal to arguments obj id then hide the current content and set current buttons to inactive, else show the current section and set the current buttons to active */
		    if (getCWSObj(listGuid + '_' + 'SectionButton' + i).id!=obj.id) 
		    {
				getCWSObj(listGuid + '_' + 'SectionButton' + i).className = ''; 
		    }
		    else
		    {
				getCWSObj(listGuid + '_' + 'SectionButton' + i).className = 'bodload';
		    }
	}
	
}	


/* 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)
{
   document.cookie = name + '=' + escape(value);
}

function setDisplay(obj,style)
{
	obj.style.display=style;
}

/* function for hiding contents for pingback control onload */
function pingbackhide()
{

	document.getElementById('pingback_body').style.display="none";
	document.getElementById('pingback_expand').style.display="block";
	document.getElementById('pingback_collapse').style.display="none";
}		


function doBookmark(url)
{
	var currentURL = document.location.href;
	var sharpLocation = currentURL.lastIndexOf('#')
	
	if (sharpLocation != -1) currentURL = currentURL.substring(0,sharpLocation)
	
	location = currentURL + url;
}