//General
//for example: instead of each module writing out script found in moduleMaxMin_OnClick have the functionality cached
//

var DNN_COL_DELIMITER = String.fromCharCode(16);
var DNN_ROW_DELIMITER = String.fromCharCode(15);
var __dnn_m_bPageLoaded = false;
var theControlName;
var lastTabIDVal = '0';

window.onload = __dnn_Page_OnLoad;
window.onunload = PageUnloadChecks;

function __dnn_ClientAPIEnabled(){
	return typeof(dnn) != 'undefined';
}


function __dnn_Page_OnLoad(){
	if (__dnn_ClientAPIEnabled()){
		var sLoadHandlers = dnn.getVar('__dnn_pageload');
		if (sLoadHandlers != null)
			eval(sLoadHandlers);
	}
	__dnn_m_bPageLoaded = true;
	PageLoadChecks()		// added 20.11.05 ensures that other load checks are performed
	//checkMe();
}

function __dnn_KeyDown(iKeyCode, sFunc, e){
	if (e == null)
		e = window.event;

	if (e.keyCode == iKeyCode){
		eval(unescape(sFunc));
		return false;
	}
}


function __dnn_bodyscroll(){
	var oF=document.forms[0];	
	if (__dnn_ClientAPIEnabled() && __dnn_m_bPageLoaded)
		oF.ScrollTop.value=dnn.dom.getByTagName("body")[0].scrollTop;
}


function __dnn_setScrollTop(iTop){
	if (__dnn_ClientAPIEnabled()){
		if (iTop == null)
			iTop = document.forms[0].ScrollTop.value;
	
		var sID = dnn.getVar('ScrollToControl');
		if (sID != null && sID.length > 0){
			var oCtl = dnn.dom.getById(sID);
			if (oCtl != null){
				iTop = dnn.dom.positioning.elementTop(oCtl);
				dnn.setVar('ScrollToControl', '');
			}
		}
		dnn.dom.getByTagName("body")[0].scrollTop = iTop;
	}
}

//Focus logic
function __dnn_SetInitialFocus(sID){
	var oCtl = dnn.dom.getById(sID);	
	if (oCtl != null && __dnn_CanReceiveFocus(oCtl))
		oCtl.focus();
}	

function __dnn_CanReceiveFocus(e){
	//probably should call getComputedStyle for classes that cause item to be hidden
	if (e.style.display != 'none' && e.tabIndex > -1 && e.disabled == false && e.style.visible != 'hidden'){
		var eParent = e.parentElement;
		while (eParent != null && eParent.tagName != 'BODY'){
			if (eParent.style.display == 'none' || eParent.disabled || eParent.style.visible == 'hidden')
				return false;
			eParent = eParent.parentElement;
		}
		return true;
	}
	else
		return false;
}

//Max/Min Script
function __dnn_ContainerMaxMin_OnClick(oLnk, sContentID){
	var oContent = dnn.dom.getById(sContentID);
	if (oContent != null)	{
		var oBtn = oLnk.childNodes[0];
		var sContainerID = oLnk.getAttribute('containerid');
		var sCookieID = oLnk.getAttribute('cookieid');
		var sCurrentFile = oBtn.src.toLowerCase().substr(oBtn.src.lastIndexOf('/'));
		var sMaxFile;
		var sMaxIcon;
		var sMinIcon;

		if (dnn.getVar('min_icon_' + sContainerID))
			sMinIcon = dnn.getVar('min_icon_' + sContainerID);
		else
			sMinIcon = dnn.getVar('min_icon');

		if (dnn.getVar('max_icon_' + sContainerID))
			sMaxIcon = dnn.getVar('max_icon_' + sContainerID);
		else
			sMaxIcon = dnn.getVar('max_icon');

		sMaxFile = sMaxIcon.toLowerCase().substr(sMaxIcon.lastIndexOf('/'));

		var iNum = 5;
		if (oLnk.getAttribute('animf') != null)
			iNum = new Number(oLnk.getAttribute('animf'));
			
		if (sCurrentFile == sMaxFile){
			oBtn.src = sMinIcon;				
			//oContent.style.display = '';
			dnn.dom.expandElement(oContent, iNum);
			oBtn.title = dnn.getVar('min_text');
			if (sCookieID != null)	{
				if (dnn.getVar('__dnn_' + sContainerID + ':defminimized') == 'true')
					dnn.dom.setCookie(sCookieID, 'true', 365);
				else
					dnn.dom.deleteCookie(sCookieID);
			}else
				dnn.setVar('__dnn_' + sContainerID + '_Visible', 'true');
		}else{
			oBtn.src = sMaxIcon;				
			//oContent.style.display = 'none';
			dnn.dom.collapseElement(oContent, iNum);
			oBtn.title = dnn.getVar('max_text');
			if (sCookieID != null)	{
				if (dnn.getVar('__dnn_' + sContainerID + ':defminimized') == 'true')
					dnn.dom.deleteCookie(sCookieID);
				else
					dnn.dom.setCookie(sCookieID, 'false', 365);				
			}
			else
				dnn.setVar('__dnn_' + sContainerID + '_Visible', 'false');			
		}
		
		return true;	//cancel postback
	}
	return false;	//failed so do postback
}
// Help
function __dnn_Help_OnClick(sHelpID){
	var oHelp = dnn.dom.getById(sHelpID);
	alert('help context clicked');
	if (oHelp != null){
		if (oHelp.style.display == 'none')
			oHelp.style.display = '';
		else
			oHelp.style.display = 'none';

		return true;	//cancel postback
	}
	return false;	//failed so do postback
}

//Section MaxMin
function __dnn_SectionMaxMin(oBtn, sContentID){
	var oContent = dnn.dom.getById(sContentID);
	if (oContent != null){
		var sMaxIcon = oBtn.getAttribute('max_icon');
		var sMinIcon = oBtn.getAttribute('min_icon');
		if (oContent.style.display == 'none'){
			oBtn.src = sMinIcon;				
			oContent.style.display = '';
			dnn.setVar(oBtn.id + ':exp', 1);
			//alert('going max')
		}else{
			oBtn.src = sMaxIcon;				
			oContent.style.display = 'none';
			dnn.setVar(oBtn.id + ':exp', 0);
			//alert('going min')
		}
		return true;	//cancel postback
	}
	return false;	//failed so do postback
}

//Drag N Drop
function __dnn_enableDragDrop(){
	var aryConts = dnn.getVar('__dnn_dragDrop').split(";");	
	var aryTitles;

	for (var i=0; i < aryConts.length; i++){
		aryTitles = aryConts[i].split(" ");
		if (aryTitles[0].length > 0){			
			var oCtr = dnn.dom.getById(aryTitles[0]);
			var oTitle = dnn.dom.getById(aryTitles[1]);
			if (oCtr != null && oTitle != null){
				oCtr.setAttribute('moduleid', aryTitles[2]);
				dnn.dom.positioning.enableDragAndDrop(oCtr, oTitle, '__dnn_dragComplete()', '__dnn_dragOver()');
			}	
		}
	}
}

var __dnn_oPrevSelPane;
var __dnn_oPrevSelModule;
var __dnn_dragEventCount=0;
function __dnn_dragOver(){
	__dnn_dragEventCount++;
	if (__dnn_dragEventCount % 75 != 0)	//only calculate position every 75 events
		return;
	
	var oCont = dnn.dom.getById(dnn.dom.positioning.dragCtr.contID);
	var oPane = __dnn_getMostSelectedPane(dnn.dom.positioning.dragCtr);
		
	if (__dnn_oPrevSelPane != null)	//reset previous pane's border
		__dnn_oPrevSelPane.pane.style.border = __dnn_oPrevSelPane.origBorder;

	if (oPane != null){		
		__dnn_oPrevSelPane = oPane;
		oPane.pane.style.border = '4px double ' + DNN_HIGHLIGHT_COLOR;
		var iIndex = __dnn_getPaneControlIndex(oCont, oPane);
		var oPrevCtl;
		var oNextCtl;
		for (var i=0; i<oPane.controls.length; i++){
			if (iIndex > i && oPane.controls[i].id != oCont.id)
				oPrevCtl = oPane.controls[i];
			if (iIndex <= i && oPane.controls[i].id != oCont.id)
			{
				oNextCtl = oPane.controls[i];
				break;
			}
		}			
		
		if (__dnn_oPrevSelModule != null)
			dnn.dom.getNonTextNode(__dnn_oPrevSelModule.control).style.border = __dnn_oPrevSelModule.origBorder;
			

		if (oNextCtl != null){
			__dnn_oPrevSelModule = oNextCtl;
			dnn.dom.getNonTextNode(oNextCtl.control).style.borderTop = '2px groove ' + DNN_HIGHLIGHT_COLOR;
		}else if (oPrevCtl != null){
			__dnn_oPrevSelModule = oPrevCtl;
			dnn.dom.getNonTextNode(oPrevCtl.control).style.borderBottom = '2px groove ' + DNN_HIGHLIGHT_COLOR;
		}
	}
}

function __dnn_dragComplete(){
	var oCtl = dnn.dom.getById(dnn.dom.positioning.dragCtr.contID);
	var sModuleID = oCtl.getAttribute('moduleid');
	
	if (__dnn_oPrevSelPane != null)
		__dnn_oPrevSelPane.pane.style.border = __dnn_oPrevSelPane.origBorder;

	if (__dnn_oPrevSelModule != null)
		dnn.dom.getNonTextNode(__dnn_oPrevSelModule.control).style.border = __dnn_oPrevSelModule.origBorder;
		
	var oPane = __dnn_getMostSelectedPane(dnn.dom.positioning.dragCtr);
	var iIndex;
	if (oPane == null){
		var oPanes = __dnn_Panes();
		for (var i=0; i<oPanes.length; i++)
		{
			if (oPanes[i].id == oCtl.parentNode.id)
				oPane = oPanes[i];
		}
	}	
	if (oPane != null){
		iIndex = __dnn_getPaneControlIndex(oCtl, oPane);
		__dnn_MoveToPane(oPane, oCtl, iIndex);

		dnn.callPostBack('MoveToPane', 'moduleid=' + sModuleID, 'pane=' + oPane.paneName, 'order=' + iIndex * 2); 
	}
}

function __dnn_MoveToPane(oPane, oCtl, iIndex){

	if (oPane != null){
		var aryCtls = new Array();
		for (var i=iIndex; i<oPane.controls.length; i++){
			if (oPane.controls[i].control.id != oCtl.id)
				aryCtls[aryCtls.length] = oPane.controls[i].control;
			dnn.dom.removeChild(oPane.controls[i].control);
		}
		dnn.dom.appendChild(oPane.pane, oCtl);
		oCtl.style.top=0;
		oCtl.style.left=0;
		oCtl.style.position = 'relative';
		for (var i=0; i<aryCtls.length; i++){
			dnn.dom.appendChild(oPane.pane, aryCtls[i]);
		}
		__dnn_RefreshPanes();
	}else{
		oCtl.style.top=0;
		oCtl.style.left=0;
		oCtl.style.position = 'relative';
	}
}

function __dnn_RefreshPanes(){
	var aryPanes = dnn.getVar('__dnn_Panes').split(';');
	var aryPaneNames = dnn.getVar('__dnn_PaneNames').split(';');
	__dnn_m_aryPanes = new Array();
	for (var i=0; i<aryPanes.length; i++){
		if (aryPanes[i].length > 0)
			__dnn_m_aryPanes[__dnn_m_aryPanes.length] = new __dnn_Pane(dnn.dom.getById(aryPanes[i]), aryPaneNames[i]);
	}
}

var __dnn_m_aryPanes;
var __dnn_m_aryModules;
function __dnn_Panes(){
	if (__dnn_m_aryPanes == null){
		__dnn_m_aryPanes = new Array();
		__dnn_RefreshPanes();
	}
	return __dnn_m_aryPanes;
}

function __dnn_Modules(sModuleID){
	if (__dnn_m_aryModules == null)
		__dnn_RefreshPanes();
	
	return __dnn_m_aryModules[sModuleID];
}

function __dnn_getMostSelectedPane(oContent){
	var oCDims = new dnn.dom.positioning.dims(oContent);
	var iTopScore=0;
	var iScore;
	var oTopPane;
	for (var i=0; i<__dnn_Panes().length; i++)	{
		var oPane = __dnn_Panes()[i];
		var oPDims = new dnn.dom.positioning.dims(oPane.pane);
		iScore = dnn.dom.positioning.elementOverlapScore(oPDims, oCDims);
		
		if (iScore > iTopScore){
			iTopScore = iScore;
			oTopPane = oPane;
		}
	}
	return oTopPane;
}

function __dnn_getPaneControlIndex(oContent, oPane){
	if (oPane == null)
		return;
	var oCDims = new dnn.dom.positioning.dims(oContent);
	var oCtl;
	if (oPane.controls.length == 0)
		return 0;
	for (var i=0; i<oPane.controls.length; i++){
		oCtl = oPane.controls[i];
		var oIDims = new dnn.dom.positioning.dims(oCtl.control);
		if (oCDims.t < oIDims.t)
			return oCtl.index;
	}
	if (oCtl != null)
		return oCtl.index+1;
	else
		return 0;
}

//Objects
function __dnn_Pane(ctl, sPaneName){
	this.pane = ctl;
	this.id = ctl.id;
	this.controls = new Array();
	this.origBorder = ctl.style.border;
	this.paneName = sPaneName;
	
	var iIndex = 0;
	var strModuleOrder='';
	for (var i=0; i<ctl.childNodes.length; i++)	{
		var oNode = ctl.childNodes[i];
		if (dnn.dom.isNonTextNode(oNode)){
			if (__dnn_m_aryModules == null)
				__dnn_m_aryModules = new Array();

			//if (oNode.tagName == 'A' && oNode.childNodes.length > 0)
			//	oNode = oNode.childNodes[0];	//DNN now embeds anchor tag 
				
			var sModuleID = oNode.getAttribute('moduleid');
			if (sModuleID != null && sModuleID.length > 0){
				strModuleOrder += sModuleID + '~';
				this.controls[this.controls.length] = new __dnn_PaneControl(oNode, iIndex);
				__dnn_m_aryModules[sModuleID] = oNode.id;
				iIndex+=1;
			}
		}
	}
	this.moduleOrder = strModuleOrder;
}

function __dnn_PaneControl(ctl, iIndex){
	this.control = ctl;
	this.id = ctl.id;
	this.index = iIndex;
	this.origBorder = ctl.style.border;
	
}

<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->

// * Dependencies * 
// this function requires the following snippets:
// JavaScript/readable_MM_functions/findObj
//
// Accepts a variable number of arguments, in triplets as follows:
// arg 1: simple name of a layer object, such as "Layer1"
// arg 2: ignored (for backward compatibility)
// arg 3: 'hide' or 'show'
// repeat...
//
// Example: showHideLayers(Layer1,'','show',Layer2,'','hide');
function _showHideLayers(){ 
  var i, visStr, obj, args = showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3){
    if ((obj = findObj(args[i])) != null){
      visStr = args[i+2];
      if (obj.style){
        obj = obj.style;
        if(visStr == 'show') visStr = 'visible';
        else if(visStr == 'hide') visStr = 'hidden';
      }
      obj.visibility = visStr;
    }
  }
}

function showHide(){
var i, visStr, obj, args = showHide.arguments;
	for (i=0; i<(args.length-2); i+=3){
		visStr = args[i+2];
		switch(visStr){
			case 'show': args[i].style.visibility = 'visible';
			break;
			
			case 'hide': args[i].style.visibility = 'hidden';
			break;
		}
	}		
}	



function hide(){
	this.layer2.style.visibility = "hidden";
	this.alert("ext file")
}


function PageLoadChecks(){
	if(theControlName !=null){
		if(getCookie(theControlName) == null){
			setCookie(theControlName, currentIDTab)
			//setCookie('theEditorLoadedFlag', theEditorLoadedFlag)
		}
		var tab = getCookie(theControlName);
		reveal(getCookie(theControlName));

		if(theControlName != null){
			//alert(theControlName);
		}
		//alert(IsEditorLoaded)
		alert(lastTabIDVal);
		if(lastTabIDVal != lastTabID()){
			//delete cookie
			alert('lastTabIDVal: ' + lastTabIDVal + ' lastTabID(): ' + lastTabID() + ' deleting cookie: '+theControlName )
			deleteCookie(theControlName);
		}
	}
}



function PageUnloadChecks(){
	//deleteCookie('uiCurrentTab');
	//alert('unloading page');
	//alert(document.location.hash);
	
}	

// ADDITIONAL JS
var isNav4, isNav6, isIE4;
/* Browser version snooper; determines your browser (Navigator 4, Navigator 6, or Internet Explorer 4/5)*/
function setBrowser(){
    if (navigator.appVersion.charAt(0) == "4")    {
        if (navigator.appName.indexOf("Explorer") >= 0){
            isIE4 = true;
        }else{
            isNav4 = true;
        }
    }else if (navigator.appVersion.charAt(0) > "4"){
        isNav6 = true;
    }
}

/* Given a selector string, return a style object by searching through stylesheets. Return null if none found */
function getStyleBySelector( selector ){
    if (!isNav6){
        return null;
    }
    var sheetList = document.styleSheets;
    var ruleList;
    var i, j;
    /* look through stylesheets in reverse order that they appear in the document */
    for (i=sheetList.length-1; i >= 0; i--){
        ruleList = sheetList[i].cssRules;
        for (j=0; j<ruleList.length; j++){
            if (ruleList[j].type == CSSRule.STYLE_RULE &&
                ruleList[j].selectorText == selector)
            {
                return ruleList[j].style;
            }   
        }
    }
    return null;
}

/*Given an id and a property (as strings), return the given property of that id.  Navigator 6 willfirst look for the property in a tag; if not found,  it will look through the stylesheet.
 *Note: do not precede the id with a # -- it will be appended when searching the stylesheets
 */
function getIdProperty( id, property ){
    if (isNav6)    {
        var styleObject = document.getElementById( id );
        if (styleObject != null){
            styleObject = styleObject.style;
            if (styleObject[property]){
                return styleObject[ property ];
            }
        }
        styleObject = getStyleBySelector( "#" + id );
        return (styleObject != null) ?
            styleObject[property] :
            null;
    }else if (isNav4){
        return document[id][property];
    }else{
        return document.all[id].style[property];
    }
}

/*Given an id and a property (as strings), set the given property of that id to the value provided. The property is set directly on the tag, not in thestylesheet. */
function setIdProperty( id, property, value ){
    if (isNav6){
        var styleObject = document.getElementById( id );
        if (styleObject != null){
            styleObject = styleObject.style;
            styleObject[ property ] = value;
        }
    }else if (isNav4){
        document[id][property] = value;
    }else if (isIE4){
         document.all[id].style[property] = value;
    }
}

/*Move a given id.  If additive is true, then move it by xValue dots horizontally and yValue units vertically.  If additive is false, then move it to (xValue, yValue)
 * Note: do not precede the id with a # -- it will be appended when searching the stylesheets
 * Note also: length units are preserved in Navigator 6 and Internet Explorer. That is, if left is 2cm and top is 3cm, and you move to (4, 5), the left will become 4cm and the top 5cm.
  */
function generic_move( id, xValue, yValue, additive ){
    var left = getIdProperty(id, "left");
    var top = getIdProperty(id, "top");
    var leftMatch, topMatch;

    if (isNav4){
        leftMatch = new Array( 0, left, "");
        topMatch = new Array( 0, top, "");
    }else if (isNav6 || isIE4 ){
        var splitexp = /([-0-9.]+)(\w+)/;
        leftMatch = splitexp.exec( left );
        topMatch = splitexp.exec( top );
        if (leftMatch == null || topMatch == null){
            leftMatch = new Array(0, 0, "px");
            topMatch = new Array(0, 0, "px");
        }
    }
    left = ((additive) ? parseFloat( leftMatch[1] ) : 0) + xValue;
    top = ((additive) ? parseFloat( topMatch[1] ) : 0) + yValue;
    setIdProperty( id, "left", left + leftMatch[2] );
    setIdProperty( id, "top", top + topMatch[2] );
}

/*Move a given id to position (xValue, yValue) */
function moveTo( id, x, y ){
    generic_move( id, x, y, false );
}

/*Move a given id to (currentX + xValue, currentY + yValue) */
function moveBy( id, x, y){
    generic_move( id, x, y, true );
}

/*Function used when converting rgb format colors from Navigator 6 to a hex format */ 
function hex( n ){
    var hexdigits = "0123456789abcdef";
    return ( hexdigits.charAt(n >> 4) + hexdigits.charAt(n & 0x0f) );
}

/*Retrieve background color for a given id.The value returned will be in hex format (#rrggbb) */ 
function getBackgroundColor( id ){
    var color;
    if (isNav4){
        color = document[id].bgColor;
    }else if (isNav6){
        var parseExp = /rgb.(\d+),(\d+),(\d+)./;
        var rgbvals;
        color = getIdProperty( id, "backgroundColor" );
        if (color){
            rgbvals = parseExp.exec( color );
            if (rgbvals){
                color = "#" + hex( rgbvals[1] ) + hex( rgbvals[2] ) + hex( rgbvals[3] );
            }
        }
        return color;
    }else if (isIE4){
        return document.all[id].backgroundColor;
    }
    return "";
}

/*Return a division's document */
function getDocument( divName ){
    var doc;
    if (isNav4){
        doc = window.document[divName].document;
    }else if (isNav6){
        doc = document;
    }else if (isIE4){
        doc = document;
    }
    return doc;
}


/*Manage the Tab Nav*/
  	var currentID = "config_section";
	var currentIDTab = "config";
	var currentHiliteTab = "configTab";
	var IsEditorLoaded = false;
	var theEditorState = false;
	
	function reveal(theID){
  		if(theID != null){
			 hide(currentID)
		}
		if (document.getElementById){
			document.getElementById(theID + "_section").style.visibility = 'visible';
			currentID = theID + "_section";
			setBrowser();
			moveTo(currentID, 300,300);
			resetTabClass(currentHiliteTab);
			setTabClass(theID + "Tab");
			currentHiliteTab = theID + "Tab";
			currentHeadingLabel(theID + "Tab");
			
			setCookie(theControlName , theID);
			
			//alert(document.location.search);
			lastTabIDVal = lastTabID();
			//alert(lastTabIDVal);
			//deleteCookie(theControlName);
		}
		if (IsEditorLoaded){
			//autoHideEditor(true)	// 24.12.05 hides the text editor control automatically
		}
	}
	
	
	function hide(theID){
		if (document.getElementById){
			document.getElementById(theID).style.visibility = 'hidden';
		}
	}

	function moveDiv(theID){
		if(document.getElementById){
			document.getElementById(theID).style.position = "absolute";
			document.getElementById(theID).style.position.top = 320;
			document.getElementById(theID).style.position.left = 20;
		}
	}

	function setTabClass(theID){
		if(document.getElementById){
			document.getElementById(theID).className = "current";
		}
	}

	function resetTabClass(theID){
		if(document.getElementById){
			document.getElementById(theID).className = "";
		}
	}

	function lastTab(){
		var queryStr = document.location.hash;
		var lenStr = queryStr.length;
		var startStr = queryStr.indexOf('#');
		if(startStr != -1){
			var endStr = queryStr.substring(startStr, lenStr);
			var str = queryStr;
			return queryStr;
		}
	}
	
	function lastTabID(){
		var queryStr = document.location.search;
		var startStr = queryStr.indexOf('&');
		if(startStr != -1){
			var endStr = queryStr.substring(7, startStr);
			var str = queryStr;
			//alert(endStr)
			return endStr;
		}
	}	
	

	function currentHeadingLabel(theID){
		var theLabel = document.getElementById(theID).innerText;
		document.getElementById('headingLabel').innerText = theLabel;
	}

	function cpreveal(theID){
		if (document.getElementById){
			document.getElementById(theID).style.visibility = 'visible';
		}
	}
	
	function cphide(theID){
		if (document.getElementById){
			document.getElementById(theID).style.visibility = 'hidden';
			document.getElementById(theID).style.zindex = "-1";
		}
	}
	
	function contextHelp(theHelpMsg){
		if (document.getElementById){
			document.getElementById('updateHelp').innerHTML = "<h3>" + theHelpMsg + "</h3>";
			document.getElementById('updateHelp').style.visibility = 'visible';
		}
	}

	function checkMe(){
		alert('load')
	}

	function writeCookie(theCookieName, theValue){
		//write the last tab selected
		document.cookie = theCookieName + "=" + escape(theValue);
		alert('Written: '+ theValue);			
	}

	function readCookie(theCookieName){
		//read the last tab selected
		var result = null;
		var myCookie = " " + document.cookie + ";";
		var searchName = " " + name + "=";
		var start = myCookie.indexOf(searchName);
		var endCookie;
		
		if(start != -1){
			start += searchName.length;
			endCookie = myCookie.indexOf(";", start);
			result = unescape(myCookie.substring(start, endCookie));
		}
		alert(theCookieName + '::' + result)
		return result;
//		var theValue;
		//theValue = document.cookie(theCookieName)
		//return theValue
	}
	
	function deleteACookie(theCookieName){
		//clear thelast tab value
	}
	
	// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments
	function setCookie(name, value, expires, path, domain, secure) {
	  var curCookie = name + "=" + escape(value) +
	      ((expires) ? "; expires=" + expires.toGMTString() : "") +
	      ((path) ? "; path=" + path : "") +
	      ((domain) ? "; domain=" + domain : "") +
	      ((secure) ? "; secure" : "");
	  document.cookie = curCookie;
	}

// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist
	function getCookie(name) {
	  var dc = document.cookie;
	  var prefix = name + "=";
	  var begin = dc.indexOf("; " + prefix);
	  if (begin == -1) {
	    begin = dc.indexOf(prefix);
	    if (begin != 0) return null;
	  } else
	    begin += 2;
	  var end = document.cookie.indexOf(";", begin);
	  if (end == -1)
	    end = dc.length;
	  return unescape(dc.substring(begin + prefix.length, end));
	}

// name - name of the cookie
// [path] - path of the cookie (must be same as path used to create cookie)
// [domain] - domain of the cookie (must be same as domain used to create cookie)
// * path and domain default if assigned null or omitted if no explicit argument proceeds
	function deleteCookie(name, path, domain) {
	  if (getCookie(name)) {
	    document.cookie = name + "=" + 
	    ((path) ? "; path=" + path : "") +
	    ((domain) ? "; domain=" + domain : "") +
	    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
	  }
	}
	
	
	
