// JavaScript Document
String.prototype.trimToNumber = function(){ return this.replace(/[^\d\.-]/g,''); } 

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: "Chrome",
			identity: "Chrome"
		},
		{ 	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 MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function MM_changeProp(objName,x,theProp,theValue) { //v6.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
    if (theValue == true || theValue == false)
      eval("obj."+theProp+"="+theValue);
    else eval("obj."+theProp+"='"+theValue+"'");
  }
}
function MM_ChangeAction(selObj){ //v3.0
  MM_changeProp('form1','','action',selObj.options[selObj.selectedIndex].value,'FORM');
  if (selObj.selectedIndex == 0) MM_changeProp('form1','','target','_self','FORM');
  if (selObj.selectedIndex == 1) {
  	MM_changeProp('form1','','target','_blank','FORM');
  	MM_changeProp('form1','','method','get','FORM');
  }
  if (selObj.selectedIndex == 2) {
  	MM_changeProp('form1','','target','_blank','FORM');
  }
  if (selObj.selectedIndex == 3) {
  	MM_changeProp('form1','','target','_blank','FORM');
  	MM_changeProp('form1','','method','get','FORM');
  }
  
}
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];}
}
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_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_nbGroup(event, grpName) { //v6.0
var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])?args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) { img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr) for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}

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 KKSetClass(x, c) {
	var o=MM_findObj(x);
	o.className = c;
}
function KKsetCenter(xthis) {
	var othis=MM_findObj(xthis);
	var smargin = "";
	if (othis.offsetWidth < othis.parentNode.offsetWidth) {
		smargin = parseInt((othis.parentNode.offsetWidth - othis.offsetWidth) / 2) + "px";
	}
	else {
		smargin = "0px";
	}
	/*alert("smargin = " + smargin + " othis.offsetWidth:" + othis.offsetWidth + " othis.parentNode.offsetWidth:" + othis.parentNode.offsetWidth);*/
	othis.style.marginLeft = smargin;
}
function initializeTemplate() {
//this is makind body extend to bottom of screen if content isn't big enough and then setting centerblock to the right height.
//issues to fix, resize doesn't work yet, BodyTag, block need to expqand and one other layer possibly, this is for when
//an elment is added with ajax and makes a div grow bigger the copylayer must increase as well otherwise overflow happens.
	//if ($('BodyTag').getHeight() < document.viewport.getHeight()) {
	//	$('BodyTag').setStyle({height:document.viewport.getHeight()}); 
	//	$('BodyLayer').setStyle({height:document.viewport.getHeight()});
	//}
	//$('CenterLayer').setStyle({height:$('BodyLayer').getHeight() - $('CenterLayer').viewportOffset().top - $('CopyLayer').getHeight()});
	//alert(document.getElementById('BannerLayer').style.width);
	
	//setHeight('InfoLayer', 'CopyLayer', 0);
	
	//setScrollBar();
	//alert(document.className);
	//setHeight('RightSideLayer', 'CopyLayer');
	if ($('BreadCrumbLayer')) { setQuickLinks(); }
}

var ScrollBarTimerGLOBAL;
var currentHeightTimerGLOBAL;
function setHeight(objectToSetId, objectToStretchTo, currentHeight) {
	if (document.getElementById) {
		objectToSetId = $(objectToSetId);
		objectToStretchTo = $(objectToStretchTo);

		var newHeight = objectToStretchTo.viewportOffset().top - objectToSetId.viewportOffset().top;
		if (BrowserDetect.browser == 'Explorer' && BrowserDetect.version == '6') { 
			if (currentHeight != newHeight && currentHeight == newHeight - 2) {
				newHeight = currentHeight;
			}
		}
		//alert('currentHeight' + currentHeight + '\tnewHeight:' + newHeight);
		if (currentHeight != newHeight && newHeight >= 0) {
			//alert(childsHeight);
			//alert("currentHeight:" + currentHeight + "\tnewHeight:" + newHeight);
			currentHeight = newHeight;
			objectToSetId.style.height = newHeight + 'px';
		}
		//alert(Prototype.Browser.IE);
    // version= navigator.appVersion;
		// alert(version);
		currentHeightTimerGLOBAL = setTimeout("setHeight('"+objectToSetId.id+"','"+objectToStretchTo.id+"','"+currentHeight+"')", 250);
		//return true;
		/*
		for (i = 0; i < document.styleSheets.length; i ++) {
			//alert(document.styleSheets[i].href.indexOf("content.css"));
			if (document.styleSheets[i].href.indexOf("content.css") > 0) {
				var theRules = new Array();
				if (document.styleSheets[i].cssRules) {
					theRules = document.styleSheets[i].cssRules;
				} else if (document.styleSheets[i].rules) {
					theRules = document.styleSheets[i].rules;
				}
				for (ii = 0; ii < theRules.length; ii++) {
					//alert(theRules[ii].selectorText);
					if (theRules[ii].selectorText == "HTML") {
						//alert(theRules[ii].style.width + "\tdocument.viewport.getWidth():" + document.viewport.getWidth());
						//alert(theRules[ii].style.overflowX + "\tdocument.viewport.getWidth():" + document.viewport.getWidth());
						if(theRules[ii].style.overflowX == 'hidden' && document.viewport.getWidth() < 800) {
							theRules[ii].style.overflowX = 'scroll';
						} else if (theRules[ii].style.overflowX == 'scroll' && document.viewport.getWidth() > 801){
							theRules[ii].style.overflowX = 'hidden';
						}
					}
					//theRules[theNumber].style.backgroundColor = '#FF0000';
				}
			}
		}*/

	
	}
} 

function setQuickLinks() {
	var breadCrumbTrail = [
	            {currentPage: 'planit_home.jsp', currentPageName: 'Home', breadCrumbs: []}, 
	            {currentPage: 'portal_login.jsp', currentPageName: 'Login', breadCrumbs: []}, 
	            {currentPage: 'portal_forgot.jsp', currentPageName: 'Forgot', breadCrumbs: []}, 
	            {currentPage: 'planit_about.jsp', currentPageName: 'About PlanIT', breadCrumbs: [{url:'planit_home.jsp',name:'Home'},{url:'planit_about.jsp',name:'About Us'}]}, 
	            {currentPage: 'planit_difference.jsp', currentPageName: 'The PlanIT Difference', breadCrumbs: [{url:'planit_home.jsp',name:'Home'},{url:'planit_about.jsp',name:'About Us'}]}, 
	            
	            {currentPage: 'planit_services.jsp', currentPageName: 'Overview', breadCrumbs: [{url:'planit_home.jsp',name:'Home'},{url:'planit_services.jsp',name:'Services'}]}, 
	            {currentPage: 'planit_hpi.jsp', currentPageName: 'Health Plan Intelligence', breadCrumbs: [{url:'planit_home.jsp',name:'Home'},{url:'planit_services.jsp',name:'Services'}]},
	            {currentPage: 'planit_hpidash.jsp', currentPageName: 'HPI-Dashboard', breadCrumbs: [{url:'planit_home.jsp',name:'Home'},{url:'planit_services.jsp',name:'Services'}]},
	            {currentPage: 'planit_hpionline.jsp', currentPageName: 'HPI-Analytics', breadCrumbs: [{url:'planit_home.jsp',name:'Home'},{url:'planit_services.jsp',name:'Services'}]},
	            {currentPage: 'planit_bc.jsp', currentPageName: 'HPI-BeneCalc', breadCrumbs: [{url:'planit_home.jsp',name:'Home'},{url:'planit_services.jsp',name:'Services'}]},
	            {currentPage: 'planit_portal.jsp', currentPageName: 'HPI-Portal', breadCrumbs: [{url:'planit_home.jsp',name:'Home'},{url:'planit_services.jsp',name:'Services'}]},
	            {currentPage: 'planit_pcr.jsp', currentPageName: 'Health Care Procedure Cost Reference', breadCrumbs: [{url:'planit_home.jsp',name:'Home'},{url:'planit_services.jsp',name:'Services'}]},

	            {currentPage: 'planit_partners.jsp', currentPageName: 'Partners', breadCrumbs: [{url:'planit_home.jsp',name:'Home'}]}, 

	            {currentPage: 'planit_empopp.jsp', currentPageName: 'Careers', breadCrumbs: [{url:'planit_home.jsp',name:'Home'}]}, 
	            {currentPage: 'planit_empopp1.jsp', currentPageName: 'Health Information Analyst', breadCrumbs: [{url:'planit_home.jsp',name:'Home'},{url:'planit_empopp.jsp',name:'Careers'}]},

	            {currentPage: 'planit_contact.jsp', currentPageName: 'Location', breadCrumbs: [{url:'planit_home.jsp',name:'Home'},{url:'planit_contact.jsp',name:'Contact Us'}]}, 
	            {currentPage: 'planit_keycontacts.jsp', currentPageName: 'Key Contacts', breadCrumbs: [{url:'planit_home.jsp',name:'Home'},{url:'planit_contact.jsp',name:'Contact Us'}]}, 
	            {currentPage: 'planit_ta_bio.jsp', currentPageName: 'Terrance Adams Bio', breadCrumbs: [{url:'planit_home.jsp',name:'Home'},{url:'planit_contact.jsp',name:'Contact Us'},{url:'planit_keycontacts.jsp',name:'Key Contacts'}]},
	            {currentPage: 'planit_bb_bio.jsp', currentPageName: 'Brian Behnken Bio', breadCrumbs: [{url:'planit_home.jsp',name:'Home'},{url:'planit_contact.jsp',name:'Contact Us'},{url:'planit_keycontacts.jsp',name:'Key Contacts'}]},
	            {currentPage: 'planit_kk_bio.jsp', currentPageName: 'Karl Kvool Bio', breadCrumbs: [{url:'planit_home.jsp',name:'Home'},{url:'planit_contact.jsp',name:'Contact Us'},{url:'planit_keycontacts.jsp',name:'Key Contacts'}]},

	            {currentPage: 'planit_inquiries.jsp', currentPageName: 'Request a Demo', breadCrumbs: [{url:'planit_home.jsp',name:'Home'},{url:'planit_contact.jsp',name:'Contact Us'}]}
	           ];
	var pathArray = window.location.pathname.split('/');
	var currentPageUrl = '';
	for (i = 2; i < pathArray.length; i++) {
		currentPageUrl += pathArray[i];
		if (pathArray.lenght > 2 && i != pathArray.length) {//double check this works with multi action controllers!!
			currentPageUrl += "/";
		}
	}
	
	for (i = 0; i < breadCrumbTrail.length; i++) {
		for (ii = 0; ii < breadCrumbTrail[i].length; ii++) {
			//alert(breadCrumbTrail[i][ii]);
		}
	}
	//alert(breadCrumbTrail.find(function(s) { alert(s.currentPage); return s.currentPage == currentPageUrl; }));
	var breadCrumbArray = breadCrumbTrail.find(function(s) { return s.currentPage == currentPageUrl; });
	var htmlString = '';
	
	if (breadCrumbArray) {

		if (breadCrumbArray.breadCrumbs.length > 0) {
			//alert(breadCrumbArray.breadCrumbs[0].name);
			htmlString += '';
		  breadCrumbArray.breadCrumbs.each(function(s, index) {
		  	htmlString += '<a href="' + s.url + '">' + s.name + '</a> : ';
		  });
		}
  	htmlString += breadCrumbArray.currentPageName ;
		$('BreadCrumbLayer').innerHTML = htmlString;		
		
		/* Block Breadcrumb trail.
		if (breadCrumbArray.breadCrumbs.length > 0) {
			//alert(breadCrumbArray.breadCrumbs[0].name);
			htmlString += '<div id="PlaceHolder" class="BlockIndents">';
			htmlString += '  <table class="" border="0" cellspacing="0" cellpadding="0" width="100%" id="BreadCrumbs">';
		  htmlString += '    <tbody>';
		  htmlString += '      <tr>';
		  htmlString += '       <th align="center">';
		 	htmlString += '        History';
		 	htmlString += '      </th>';
	 		htmlString += '    </tr>';
		  breadCrumbArray.breadCrumbs.each(function(s, index) {
		  	//alert(s);
		  	htmlString += '<tr>';
		  	htmlString += '';
		  	var tempClass = '';
		  	if (index == 0) { tempClass = ''; }
		  	htmlString += '  <td class="' + tempClass + '"><a style="text-indent:' + (index * 5 + 10) +'px;" href="' + s.url + '">' + s.name + '</a></td>';
		  	htmlString += '</tr>';
		  });
		  htmlString += '    </tbody>';
		  htmlString += '  </table>';
		  htmlString += '</div>';			
		}
		$('BlockHeight121px').insert({after: htmlString});
		*/
	} else {
		alert("No Bread Crumb defined for this page!!");
	}
	//for (i = 0; i < breadCrumbTrail.length; i++) {
	//	if (breadCrumbTrail[i][0] == currentPageUrl) {

	//	}
	//}
	
}


Event.observe(window, 'load', function() {
	if ($('signInLink')) { Event.observe($('signInLink'), 'click', function() {
		Modalbox.show($('signInModelBox'), {title:'Sign In (Client Center)', width: 300});
	})};
});


