(window.attachEvent)?window.attachEvent('onload', getIdfromURL ):window.addEventListener('load', getIdfromURL, false);

//At the time of loading, Verify URL for the existence of "accordion" argument.
//If exists, extract the ID and then open that section
function getIdfromURL(){
  var accordionId;
  var currentURL=location.href;
  var indexAccordion=currentURL.indexOf("accordion=");
  if(indexAccordion != -1){
    str = currentURL.substr(indexAccordion+10)
    if(str.indexOf("&") == -1){accordionId = str;}
    else accordionId = str.substr(0,str.indexOf("&"))
  }
  
  if(accordionId){

    if(document.getElementById("solutionAsset")){
  	var solutionAssetDiv = document.getElementById("solutionAsset");
  	solutionAssetDiv.className = "solutionAssetExpanded"; 	
    }

    showSearchKeyWord(accordionId);
    sectionExpand(accordionId);
    window.location="#accordionClose"+accordionId;
  }
} //getIdfromURL()

//It opens the all sections when click the ExpandAll button
function accordionExpandAll(noOfSection){
  if (document.getElementById("searchKeywordValue") && document.getElementById("defaultKeyword").value != ''){
    document.getElementById("searchKeywordValue").innerHTML = document.getElementById("defaultKeyword").value;
  } 

  if(document.getElementById("solutionAsset")){
  	var solutionAssetDiv = document.getElementById("solutionAsset");
  	solutionAssetDiv.className = "solutionAssetExpanded"; 	
  }

  for(ID = 1; ID <= noOfSection; ID++){sectionExpand(ID);}
  
  var sectionExpandAll = document.getElementById("expandAll");
  sectionExpandAll.style.display = "none";

  var sectionExpandAllDisabled = document.getElementById("expandAllDisabled");
  sectionExpandAllDisabled.style.display = "";

  var sectionCloseAll = document.getElementById("collapseAll");
  sectionCloseAll.style.display = "";

  var sectionCloseAllDisabled = document.getElementById("collapseAllDisabled");
  sectionCloseAllDisabled.style.display = "none";
} //accordionExpandAll()

//It closes the all sections when click the CloseAll button
function accordionCloseAll(noOfSection){
  if (document.getElementById("searchKeywordValue") && document.getElementById("defaultKeyword").value != ''){
    document.getElementById("searchKeywordValue").innerHTML = document.getElementById("defaultKeyword").value;
  }

  if(document.getElementById("solutionAsset")){
  	var solutionAssetDiv = document.getElementById("solutionAsset");
  	solutionAssetDiv.className = "solutionAsset"; 	
  }

  for(ID = 1; ID <= noOfSection; ID++){sectionClose(ID);}
  	
  var sectionCloseAll = document.getElementById("collapseAll");
  sectionCloseAll.style.display = "none";

  var sectionCloseAllDisabled = document.getElementById("collapseAllDisabled");
  sectionCloseAllDisabled.style.display = "";

  var sectionExpandAll = document.getElementById("expandAll");
  sectionExpandAll.style.display = "";

  var sectionExpandAllDisabled = document.getElementById("expandAllDisabled");
  sectionExpandAllDisabled.style.display = "none";
} //accordionCloseAll()

//It opens the indevisual section and sets the search keyword value
function accordionExpand(ID,noOfSection){
  var sectionCloseAll,sectionCloseAllDisabled;
  showSearchKeyWord(ID);

  if(document.getElementById("solutionAsset")){
  	var solutionAssetDiv = document.getElementById("solutionAsset");	
  	solutionAssetDiv.className = "solutionAssetExpanded"; 	
  }

  sectionExpand(ID);  

  //check if all the sections are opened
  var flag = 1;
  for(id = 1; id <= noOfSection; id++){
    if(document.getElementById("expandSection"+id).style.display == "")continue;
    else{
      flag = 0;
      break;
    }
  }

  //if all the sections are opened, show the collapseAll button enabled
  if(flag == 1){
    var sectionExpandAll = document.getElementById("expandAll");
    sectionExpandAll.style.display = "none";

    var sectionExpandAllDisabled = document.getElementById("expandAllDisabled");
    sectionExpandAllDisabled.style.display = "";
  }
}

//It closes the indevisual section
function accordionClose(ID,noOfSection){
  sectionClose(ID);

  var sectionExpandAll = document.getElementById("expandAll");
  sectionExpandAll.style.display = "";

  var sectionExpandAllDisabled = document.getElementById("expandAllDisabled");
  sectionExpandAllDisabled.style.display = "none";

  //check if all the sections are closed
  var flag = 1;
  for(id = 1; id <= noOfSection; id++){
    if(document.getElementById("expandSection"+id).style.display == "none")continue;
    else{
      flag = 0;
      break;
    }
  }

  //if all the sections are closed, show the expandAll button enabled
  if(flag == 1){
    if (document.getElementById("searchKeywordValue") && document.getElementById("defaultKeyword").value != '')
      document.getElementById("searchKeywordValue").innerHTML = document.getElementById("defaultKeyword").value;

    if(document.getElementById("solutionAsset")){
  	var solutionAssetDiv = document.getElementById("solutionAsset");
  	solutionAssetDiv.className = "solutionAsset"; 	
    }

    var sectionCloseAll = document.getElementById("collapseAll");
    sectionCloseAll.style.display = "none";

    var sectionCloseAllDisabled = document.getElementById("collapseAllDisabled");
    sectionCloseAllDisabled.style.display = "";
  }

} //accordionClose()

//It shows the search keyword value when any section is opened
function showSearchKeyWord(sectionsID){
  if (document.getElementById("searchKeywordValue") && document.getElementById("defaultKeyword").value == ''){
    if(document.getElementById("searchKeywordValue").innerHTML == "")document.getElementById("defaultKeyword").value = " ";
    else document.getElementById("defaultKeyword").value = document.getElementById("searchKeywordValue").innerHTML;
  }
  if (document.getElementById("searchKeywordValue"))document.getElementById("searchKeywordValue").innerHTML = document.getElementById("searchKeywordValue"+sectionsID).value;
} //showSearchKeyWord()

function sectionExpand(sectionsID){
  var setSectionClass = document.getElementById("solutionSection"+sectionsID); 
  setSectionClass.className = "solutionSectionOpened";

  var sectionExpand = document.getElementById("expand"+sectionsID);
  sectionExpand.style.display = "none";
  var sectionCollapse = document.getElementById("collapse"+sectionsID);
  sectionCollapse.style.display = "";

  var divOpen = document.getElementById("expandSection"+sectionsID);
  divOpen.style.display = "";

  var sectionCloseAll = document.getElementById("collapseAll");
  sectionCloseAll.style.display = "";

  var sectionCloseAllDisabled = document.getElementById("collapseAllDisabled");
  sectionCloseAllDisabled.style.display = "none";


} //sectionExpand()

function sectionClose(ID){
  var setSectionClass = document.getElementById("solutionSection"+ID);
  setSectionClass.className = "solutionSectionClosed";

  var sectionExpand = document.getElementById("expand"+ID);
  sectionExpand.style.display = "";
  var sectionCollapse = document.getElementById("collapse"+ID);
  sectionCollapse.style.display = "none";

  var divOpen = document.getElementById("expandSection"+ID);
  divOpen.style.display = "none";
} //sectionClose()

//It Opens the Print window with the content of the section in which print button is clicked
function printPopupPage(ID){
  var linkHTML = '';
  var params = 'toolbar=no,location=no,status=no,scrollbars=yes,resizable=no,width=640,height=480';
  var cssLink = document.getElementsByTagName("link");

  var data = document.getElementById("solutionSection"+ID).innerHTML;
  var hideCollapseDiv = document.getElementById("collapse"+ ID).innerHTML;
  var hidePageToolDIv = document.getElementById("sharePrint"+ ID).innerHTML;

  data = data.replace(hideCollapseDiv,"");  //remove the Collapse Div from the print window
  data = data.replace(hidePageToolDIv,"");  //remove the PageTool Div from the print window
	
  var userAgent = navigator.userAgent.toLowerCase();
  if (userAgent.indexOf('msie') > 0|| userAgent.indexOf('internet explorer') > 0){                       

          data = data.replace(/<css3(.*)?>(.*)?<\/css3(.*)?>/,"");
  }

  //Add the all CSS links from the parent window
  for( i=0;i<cssLink.length;i++){
    if(cssLink[i].type =="text/css"){
	    var sHref = cssLink[i].href;
		 if(sHref.substr(sHref.lastIndexOf('/')+1) == "business.css") 
		 	linkHTML = linkHTML + "<link type='text/css' rel= 'stylesheet' href="+sHref.substring(0,sHref.lastIndexOf('/')+1)+"business_Print_test.css"+"/>";
		 else
		 	linkHTML = linkHTML + "<link type='text/css' rel= 'stylesheet' href='"+cssLink[i].href+"'/>";
    }
	
  }

 
  printWindow = window.open('','printablePage',params);

  var print = '<script type="text/javascript" language = "javascript">'
  print += 'setTimeout(printAndClose, 1000);'
  print += 'function printAndClose() {'
  print += 'window.print();'
  print += 'self.close();}'
  print += "</"
  print += "script>"

  var newDocument = printWindow.document;
  popupHTML ='<html><head>'+linkHTML+print+'</head><body style="background: none;"><div id="displayArea"><div style="background: none repeat scroll 0% 0% transparent; border: 0pt none; behavior:none" id="solutionAsset" class="solutionAssetExpanded"><div id= "solutionSection'+ID+'" class="solutionSectionOpened" style = "behavior:none">'+data+'</div></div></div></body></html>';

  newDocument.write(popupHTML);
  newDocument.close();
} //printPopupPage()
