function getElementsByClassName(strClass, strTag, objContElm) {
  strTag = strTag || "*";
  objContElm = objContElm || document;
  var objColl = objContElm.getElementsByTagName(strTag);
  if (!objColl.length &&  strTag == "*" &&  objContElm.all) objColl = objContElm.all;
  var arr = new Array();
  var delim = strClass.indexOf('|') != -1  ? '|' : ' ';
  var arrClass = strClass.split(delim);
  for (var i = 0, j = objColl.length; i < j; i++) {
    var arrObjClass = objColl[i].className.split(' ');
    if (delim == ' ' && arrClass.length > arrObjClass.length) continue;
    var c = 0;
    comparisonLoop:
    for (var k = 0, l = arrObjClass.length; k < l; k++) {
      for (var m = 0, n = arrClass.length; m < n; m++) {
        if (arrClass[m] == arrObjClass[k]) c++;
        if (( delim == '|' && c == 1) || (delim == ' ' && c == arrClass.length)) {
          arr.push(objColl[i]);
          break comparisonLoop;
        }
      }
    }
  }
  return arr;
}

Array.prototype.push = function(value) {
  this[this.length] = value;
}

function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
		cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '$' + num + '.' + cents);
}

/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Patrick Hunlock | http://www.hunlock.com */
function getCSSRule(ruleName, deleteFlag) {               // Return requested style obejct
  if (document.styleSheets) {                             // If browser can play with stylesheets
    for (var i=0; i<document.styleSheets.length; i++) {   // For each stylesheet
      var styleSheet=document.styleSheets[i];             // Get the current Stylesheet
      var ii=0;                                           // Initialize subCounter.
      var cssRule=false;                                  // Initialize cssRule. 
      do {                                                // For each rule in stylesheet
        if (styleSheet.cssRules) {                        // Browser uses cssRules?
          cssRule = styleSheet.cssRules[ii];              // Yes -- Mozilla Style
        } else {                                          // Browser usses rules?
          cssRule = styleSheet.rules[ii];                 // Yes IE style. 
        }                                                 // End IE check.
        if (cssRule)  {                                   // If we found a rule...
          if (cssRule.selectorText==ruleName) {           // Does current rule match ruleName?
            if (deleteFlag=='delete') {                   // Yes.  Are we deleteing?
              if (styleSheet.cssRules) {                  // Yes, deleting...
                styleSheet.deleteRule(ii);                // Delete rule, Moz Style
              } else {                                    // Still deleting.
                styleSheet.removeRule(ii);                // Delete rule IE style.
              }                                           // End IE check.
              return true;                                // return true, class deleted.
            } else {                                      // found and not deleting.
              return cssRule;                             // return the style object.
            }                                             // End delete Check
          }                                               // End found rule name
        }                                                 // end found cssRule
        ii++;                                             // Increment sub-counter
      } while (cssRule)                                   // end While loop
    }                                                     // end For loop
  }                                                       // end styleSheet ability check
  return false;                                           // we found NOTHING!
}                                                         // end getCSSRule 

function killCSSRule(ruleName) {                          // Delete a CSS rule   
  return getCSSRule(ruleName,'delete');                   // just call getCSSRule w/delete flag.
}                                                         // end killCSSRule

function addCSSRule(ruleName) {                           // Create a new css rule
  if (document.styleSheets) {                             // Can browser do styleSheets?
    if (!getCSSRule(ruleName)) {                          // if rule doesn't exist...
      if (document.styleSheets[0].addRule) {              // Browser is IE?
        document.styleSheets[0].addRule(ruleName, null,0);      // Yes, add IE style
      } else {                                            // Browser is IE?
        document.styleSheets[0].insertRule(ruleName+' { }', 0); // Yes, add Moz style.
      }                                                   // End browser check
    }                                                     // End already exist check.
  }                                                       // End browser ability check.
  return getCSSRule(ruleName);                            // return rule we just created.
} 

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};

BrowserDetect.init();

function showhideText(box,id)  {
	 var dbox = document.getElementById(box);
	 var elm = document.getElementById(id) ;
	 //elm.style.display = dbox.checked ? '':'none';
	 var myObjColl = getElementsByClassName(id, 'tr');
	 for (var i = 0, j = myObjColl.length; i < j; i++) {
			myObjColl[i].style.display = dbox.checked ? '':'none';
			}
}

function hideshowText(box,id)  {
	 var dbox = document.getElementById(box);
	 var elm = document.getElementById(id) ;
	 //elm.style.display = dbox.checked ? '':'none';
	 var myObjColl = getElementsByClassName(id, 'tr');
	 for (var i = 0, j = myObjColl.length; i < j; i++) {
			myObjColl[i].style.display = dbox.checked ? 'none':'';
			}
}

function SetPanels1(IDname) {
	
	var panelname;
	jsInt = document.getElementById(IDname);
	cpg1.closeAllPanels();
	for (i=0; i <= jsInt.value-1; i++)  {
		panelname = "Panel " + String(i);
		cpg1.openPanel(i);	
	}
}
function SetPanels2(IDname) {
	
	var panelname;
	jsInt = document.getElementById(IDname);
	cpg2.closeAllPanels();
	for (i=0; i <= jsInt.value-1; i++)  {
		panelname = "Panel " + String(i);
		cpg2.openPanel(i);	
	}
}
function SetPanels3(IDname) {
	
	var panelname;
	jsInt = document.getElementById(IDname);
	cpg3.closeAllPanels();
	for (i=0; i <= jsInt.value-1; i++)  {
		panelname = "Panel " + String(i);
		cpg3.openPanel(i);	
	}
}
function SetPanels4(IDname) {
	
	var panelname;
	jsInt = document.getElementById(IDname);
	cpg4.closeAllPanels();
	for (i=0; i <= jsInt.value-1; i++)  {
		panelname = "Panel " + String(i);
		cpg4.openPanel(i);	
	}
}
function SetPanels5(IDname) {
	
	var panelname;
	jsInt = document.getElementById(IDname);
	cpg5.closeAllPanels();
	for (i=0; i <= jsInt.value-1; i++)  {
		panelname = "Panel " + String(i);
		cpg5.openPanel(i);	
	}
}

function SetSubmitStatus(objId2,objId,upStatus,SubStatus) { //v9.0
	var obj = document.getElementById(objId);
	var obj2 = document.getElementById(objId2);
	if (obj) { 
		if (obj2.checked) {
	 		obj.value = SubStatus;
		}
		else
		{
			obj.value = upStatus;
		}
	}
}

function myPopup() {
window.open( "http://www.centerpointcorporate.com/timeout.html", "myWindow", 
"status = 1, height = 300, width = 300, resizable = 0" )
}

