﻿/***********************************************
* Contractible Headers script- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for legal use. Last updated Oct 21st, 2003.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

var g_enablepersist = "yes" //Enable saving state of content structure using session cookies? (yes/no)
var g_collapseprevious = "no" //Collapse previously open content when opening present? (yes/no)

if (document.getElementById) {
 document.write('<style type="text/css">')
 document.write('.switchcontent{display:none;}')
 document.write('</style>')
}

// MGMA/GRH:6/27/06 Added to support "toggling" content block content on/off
if (document.getElementById) {
 document.write('<style type="text/css">')
 document.write('.nodisplay{display:none;}')
 document.write('</style>')
}

// MGMA/GRH:6/27/06 Added to support "toggling" content block content on/off
function toggleDisplay1( p_cid ) {
	var el = document.getElementById( p_cid );
	if ( el.style.display == "block" )
		el.style.display = "none";
	else
		el.style.display = "block";
}

// MGMA/GRH:6/27/06 Added to support "toggling" content block content on/off
function toggleDisplay2( p_cid, p_xid ) {
  //var strUrl = getUrl()
  var strUrl = ""
  
  var oldstyle = document.getElementById( p_cid ).style.display
  document.getElementById( p_cid ).style.display = (document.getElementById( p_cid ).style.display != "block") ? "block" : "none"
  if ( oldstyle == "none" ) {
    strUrl = strUrl + getImagePath( "minus_img" )
    document.getElementById( p_xid ).src = strUrl
  }
  if ( oldstyle == "block" ) {
    strUrl = strUrl + getImagePath( "plus_img" )
    document.getElementById( p_xid ).src = strUrl
  }
}

// MGMA/GRH:6/27/06 Added to support "toggling" content block content on/off
function getElementbyClass2( p_classname ) {
 g_arrTags2 = new Array()
 var inc = 0
 var alltags=document.all? document.all : document.getElementsByTagName("*")
 for ( i = 0; i < alltags.length; i++ ){
  if ( alltags[i].className == p_classname ) {
   g_arrTags2[inc++] = alltags[i]
  }
 }
}

// MGMA/GRH:6/27/06 Added to support "toggling" content block content on/off
function contractcontent2(p_omit){
 var inc = 0
 while ( g_arrTags2[inc ]){
  if ( g_arrTags2[inc].id != p_omit) {
   g_arrTags2[inc].style.display = "none"
  }
  inc++
 }
}

// MGMA/GRH:4/26/06 Added
function getUrl() {

 // *grh* not called as of 8/15/06
 
 var strLoc = new String( window.location ) // e.g., http://dev2.mgma.com/cms400min/file.htm
 var strPath = new String( window.location.pathname ) // e.g., /cms400min/file.htm
 var strSubsite = new String("")
  
 var intIndex = strPath.indexOf( "/", 1 ) // try to find the second "/" in the Path
 if ( intIndex >= 0 ) {
  strSubsite = new String( strPath.substr( 0, intIndex + 1 )) // e.g. /cms400min/   
 }
 else {
  strSubsite = new String( "/" )  
 } 

 intIndex = strLoc.indexOf( strPath ) // e.g., 20
 var strServer = new String( strLoc.substr( 0, intIndex ) ) // e.g., http://dev2.mgma.com
 var strUrl = strServer + strSubsite
 return strUrl

}

function getElementbyClass1(p_classname){
 g_arrTags1 = new Array()
 var inc = 0
 var alltags = document.all? document.all : document.getElementsByTagName("*")
 for ( i = 0; i < alltags.length; i++ ){
  if ( alltags[i].className == p_classname ) {
   g_arrTags1[inc++] = alltags[i]
  }
 }
}

function contractcontent1(p_omit){
 var inc = 0
 while ( g_arrTags1[inc ]){
  if ( g_arrTags1[inc].id != p_omit) {
   g_arrTags1[inc].style.display = "none"
  }
  inc++
 }
}

function expandcontent( p_cid, p_xid ) {
 if ( typeof g_arrTags1 != "undefined" ) {
  //var strUrl = getUrl()
  var strUrl = ""
  
	if ( g_collapseprevious == "yes" ) {
   contractcontent1( p_cid )
  }
  var oldstyle = document.getElementById( p_cid ).style.display
  document.getElementById( p_cid ).style.display = (document.getElementById( p_cid ).style.display != "block") ? "block" : "none"
  if ( oldstyle == "none" ) {
   strUrl = strUrl + getImagePath( "minus_img" )
   document.getElementById( p_xid ).src = strUrl
  }
  if (oldstyle == "block") {
   strUrl = strUrl + getImagePath( "plus_img" )
   document.getElementById( p_xid ).src = strUrl
  }
 }
}

// MGMA/GRH:7/27/06 Added so that the image to use is retrieved from the HTML and not hard-coded.
// Assumes that a span tag with display:none and id of plus_sign is in the HTML.
// Assumes that a span tag with display:none and id of minus_sign is in the HTML.
// These span tags are put in the HTML by MGMAColAndMenuHtmlUtils.
function getImagePath( p_image_type ) {
  if ( document.getElementById( p_image_type ) != null) {
   if ( document.all ) {
    // IE browser		
    return document.getElementById( p_image_type ).innerText
   }
   else {
    if ( document.getElementById( p_image_type ).textContent ) {
     // Firefox ?
     return document.getElementById( p_image_type ).textContent
    }
    else {
     return ""
    }
   }
  }
  else {
   return ""
  }
}

function revivecontent(){
 g_savecookie = ""
 contractcontent1("omitnothing")
 var selectedItem = getselectedItem()
 var selectedComponents = selectedItem.split("|")
 
 for ( i = 0; i < selectedComponents.length - 1; i++ ) {
 
  var selectedImage = "i" + selectedComponents[i]
  
  if ( document.getElementById(selectedComponents[i]) != null) {
   document.getElementById(selectedComponents[i]).style.display = "block"
  }
  else {
   g_savecookie += selectedComponents[i] + "|"
  }
  
	//var strUrl = getUrl()
	var strUrl = ""
  strUrl = strUrl + getImagePath( "minus_img" )
  
  if ( document.getElementById(selectedComponents[i] ) != null) {
	 if ( document.getElementById( selectedImage ) != null ) {
    document.getElementById( selectedImage ).src = strUrl
   }
  }
 }
}

function get_cookie(p_Name) { 
 var search = p_Name + "="
 var returnvalue = "";
 if (document.cookie.length > 0) {
  var offset = document.cookie.indexOf(search)
  
  if (offset != -1) { 
   offset += search.length
   var end = document.cookie.indexOf(";", offset);
   if (end == -1) end = document.cookie.length;
   returnvalue = unescape( document.cookie.substring( offset, end ) )
  }
 }
 return returnvalue;
}

function getselectedItem() {
 //if (get_cookie(window.location.pathname) != ""){
  //selectedItem=get_cookie(window.location.pathname)
  //if ( get_cookie( escape( window.location.href ) ) != "" ) {
  //selectedItem = get_cookie( escape( window.location.href ) )
  
 if (get_cookie( "ekObj" ) != "" ){
  var selectedItem = get_cookie( "ekObj" )

  return selectedItem
 }
 else {
  return ""
 }
}

function saveswitchstate() {
 var inc = 0
 var selectedItem = ""
 while ( g_arrTags1[inc] ) {
  if ( g_arrTags1[inc].style.display == "block" ) {
   selectedItem += g_arrTags1[inc].id + "|"
  }
 inc++
 }

 selectedItem += g_savecookie
 
 document.cookie="ekObj" + "=" + selectedItem + ";" + " path=/;"
 
 //var escapedHref = escape( window.location.href )
 //document.cookie = escapedHref + "=" + selectedItem
 //document.cookie=window.location.pathname+"="+selectedItem
}

function do_onload() {
  getElementbyClass1("switchcontent")
  if ( g_enablepersist == "yes" && typeof g_arrTags1 != "undefined" ) {
    revivecontent()
  }
  // MGMA/GRH:6/27/06 Added to support "toggling" content block content on/off
  getElementbyClass2("nodisplay")
  contractcontent2("omitnothing")
}


// Login form: Disable Enter key for login form (unless button has focus)
  function checkCR(evt) {
    var evt  = (evt) ? evt : ((event) ? event : null);
    var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
    if ((evt.keyCode == 13) && (node.type=="text")) {return false;}
  }
  document.onkeypress = checkCR;

// Login form: Check and post
function checkLoginFields(login_url) {
  if ( document.getElementById("login_lastname") == null) {
	  return
	}
  if ( document.getElementById("login_id") == null) {
	  return
	}

  if ( document.getElementById("login_lastname").value == "" || document.getElementById("login_id").value == "" ) {
	  alert("Please enter your Last name and Subscriber (MGMA) ID to log in.")
	}
	else {
		//These cookies can be used if we want to take advantage of the TCMS "autologin" capability.
    //document.cookie="TimssPassword" + "=" + document.getElementById("lastname").value + ";" + " path=/;" + "domain=.mgma.com;"
    //document.cookie="TimssUserName" + "=" + document.getElementById("id").value + ";" + " path=/;" + "domain=.mgma.com;"
	  postForm(login_url)
	}
}

function postForm(login_url) {
  var strURL = new String("")
  var strURL1 = new String("")
  var strURL2 = new String("")
  var strURL3 = new String("")
  var strDestURL = new String("")
  var strArrEntry = new String("")
  
  //Get the current URL; ex. http://www.abc.com/default.aspx?id=2254
  strURL = document.URL
  strURL1 = document.URL
  
  //Clean it up by removing previous log in attempt parameters.
  var intIndex = strURL.indexOf( "?", 0 ) // try to find ?
  if ( intIndex >= 0 ) {
		strURL1 = strURL.substr( 0, intIndex + 1 ) //ex. http://www.abc.com/default.aspx?
		strURL2 = strURL.substr(intIndex + 1) // ex. id=2254
  }
  //alert("strURL1= " + strURL1 + " strURL2= " + strURL2)
  
  //Split the parameters up into an array of keyword=value pairs.
  var arrParams = new Array()
  arrParams = strURL2.split("&")

	//Loop through the parameter array; save value of login_dest_url (if it exists) and then discard login_lastname=, login_id= and login_dest_url= params. Save all other params.
  for ( i = 0; i < arrParams.length; i++ ){
		//alert( "arrParams[" + i + "]= " + arrParams[i] )
		strArrEntry = arrParams[i]
		
		if ( strArrEntry.indexOf("login_dest_url") >= 0 ) {
		  var intIndex2 = strArrEntry.indexOf( "=", 0 ) // try to find =
			if ( intIndex2 >= 0 ) {
				strDestURL = strArrEntry.substr( intIndex2 + 1 )
			}
			//alert("strDestURL= " + strDestURL)
		}
		
		if (( strArrEntry.indexOf("login_lastname") >= 0 ) ||
			  ( strArrEntry.indexOf("login_id") >= 0 ) ||
			  ( strArrEntry.indexOf("login_dest_url") >= 0 ))
		{
			// do nothing, skip it
		}
		else {
			if (strURL3.length == 0 ) {
				strURL3 += strArrEntry					
			}
			else {
				strURL3 += "&" + strArrEntry
			}
		}
	}
	
	//alert("strURL3= " + strURL3)
	
	//If a login_dest_url= parameter existed, use if the new login_dest_url. Otherwise, construct a new login_dest_url using the current document URL and all of its parameters (except login_lastname, login_id and login_dest_url).
	if ( strDestURL.length > 0 ) {
		strURL = strDestURL
	}
	else {
		strURL = strURL1 + strURL3
	}
	
	//alert("strURL= " + strURL)
	
  //Encode the new login_dest_url (sort of).
  strURL = strURL.replace("?","!")
  strURL = strURL.replace("&","|")

  //Get rid of viewstate.
  document.forms[0].__VIEWSTATE.value = ""
  document.forms[0].__VIEWSTATE.name = "NOVIEWSTATE"
  
  //Set up form action.
  document.forms[0].action = login_url + "?" + "login_lastname=" + document.getElementById("login_lastname").value + "&" + "login_id=" + document.getElementById("login_id").value + "&" + "login_dest_url=" + strURL

  //Submit the form to the URL specified in login_url.
  document.forms[0].submit()
}		

// Search form
function postSearch(search_url) {
	var strURL = new String("")
	var strQuery = new String("")
	strURL = search_url
	strQuery = strQry = document.forms[0].txtQ.value
	
	//left trim
	while (strQuery.substring(0,1) == ' ')
			{
			strQuery = strQuery.substring(1, strQuery.length);
			}

	if ( strQuery == "" ) {
		alert("Please enter a search term.")
		}
	else {
		document.forms[0].__VIEWSTATE.value = ""
		document.forms[0].__VIEWSTATE.name = "NOVIEWSTATE"
		document.forms[0].action = strURL + strQuery
		document.forms[0].submit()
		}
	}	
// END login and search form functions //

// Pop-up window function //
/*
Open Centered Popup Window Script-
© DHTML Shock (www.dhtmlshock.com)
To add more shock to your site, visit www.DHTML Shock.com
*/
function OpenBrWindow(theURL,winName,features, myWidth, myHeight, isCenter) { //v3.0
  if(window.screen)if(isCenter)if(isCenter=="true"){
    var myLeft = (screen.width-myWidth)/1.25;
    var myTop = (screen.height-myHeight)/4;
    features+=(features!='')?',':'';
    features+=',left='+myLeft+',top='+myTop;
  }
  window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
}
// END pop-up window function //

if (window.addEventListener)
 window.addEventListener("load", do_onload, false)
else if (window.attachEvent)
 window.attachEvent("onload", do_onload)
else if (document.getElementById)
 window.onload = do_onload

if ( g_enablepersist == "yes" && document.getElementById )
 window.onunload = saveswitchstate
