function MICGenMenuLnk(id,nexturl,nm,sel)
{	return "<td style=\""+(sel==id?"font-weight:bold;font-size:120%;background-color:lightgreen;border:1px solid red;color:white":"background-color:mediumseagreen;color:gray")+";width:15ex;cursor:pointer\" onclick=this.firstChild.click()><a href=\""+request.webroot+"index.cfm?fusebox=SVCsec&fuseaction=act_setlogin&setlogin="+id+"&nexturl="+encodeURIComponent(nexturl)+"&"+request.mtoken+"\">"+nm+"</a></td>";
}
function MICGenMenu(modlist,sel)
{	var l,s,t;
	if(modlist==null)modlist=""
		else modlist=","+modlist+",";
	l=modlist.split(",");
	s="";
	
	var s1="";
	
	for(t=0;t<l.length;t++)
	{
		switch(l[t])
		{
			case "1":s+=AddTabMenu(1,"Admin","fusebox=MICadmin&fuseaction=dsp_coprofile&", "tabmadmin",null,sel,null);break;
			case "2":s+=AddTabMenu(2,"Policy","fusebox=MICpolicy&fuseaction=dsp_policymain&", "tabmpolicy",null,sel,null);break;
			case "3":s+=AddTabMenu(3,"Claim","fusebox=MICclaims&fuseaction=dsp_claimmain&", "tabmclaim",null,sel,null);break;
			case "4":s+=AddTabMenu(4,"Billing","fusebox=MICbill&fuseaction=dsp_billmain&", "tabmbilling",null,sel,null);break;
			case "5":s+=AddTabMenu(5,"Dashboard","fusebox=MICdash&fuseaction=dsp_dashboard&", "tabmdashboard",null,sel,null);break;
			case "6":s+=AddTabMenu(6,"Customer","fusebox=MICcust&fuseaction=dsp_custsearch&", "tabmcustomer",null,sel,null);break;
			case "7":s+=AddTabMenu(7,"Products","fusebox=MICpolicy&fuseaction=dsp_prodselect&", "tabmproduct",null,sel,null);break;
			case "8":s+=AddTabMenu(8,"Settings","fusebox=MICcust&fuseaction=dsp_custsettings&", "tabmsettings",null,sel,null);break;
			case "9":s+=AddTabMenu(9,"Reports","fusebox=MICreports&fuseaction=dsp_reports&", "tabmreports",null,sel,null);break;
			case "10":s+=AddTabMenu(10,"Home","fusebox=MICcust&fuseaction=dsp_custhome&", "tabmcusthome",null,sel,null);break;
			case "11":s+=AddTabMenu(11,"Accounts","fusebox=MICacc&fuseaction=dsp_accmain&", "tabmaccounts",null,sel,null);break;
			case "99":s1+=AddTabMenu(99,"Preferences","fusebox=MICdash&fuseaction=dsp_preferences&", "tabmpreferences",null,sel,null);break;
		}

	}
	// other menu : logout
	s1+=AddTabMenu(null,"Logout","fusebox=SVCsec&fuseaction=act_logout&root=MIC", "tabmlogout",null,sel,null);
	
	//return "<table align=center width=100% cellborder=1 style=text-align:center><tr>"+s+"<td align=left style=padding-left:5px><input type=button class=clsButton value=\"Logout\" onclick=\"location.href=request.webroot+'index.cfm?fusebox=SVCsec&fuseaction=act_logout&'+request.mtoken;\"></td></tr></table>";
	//return DrawTabMenuSet(s,'left'); // align to left
	
	return "<table align=center width=100% cellspacing=0 cellpadding=0 border=0><tr><td>"+DrawTabMenuSet(s,'left')+"</td><td>"+DrawTabMenuSet(s1,'right')+"</td><td width=30px></td></tr></table>"
	
}
function TabMOver(obj)
{
	var targetobj=obj.getElementsByTagName('td');
	targetobj[0].className='TabHover_left';//  .backgroundImage='url(images/hovertab_l.jpg)';
	targetobj[1].className='TabHover_mid'; //.backgroundImage='url(images/hovertab_m.jpg)';
	targetobj[2].className='TabHover_right'; //backgroundImage='url(images/hovertab_r.jpg)';
}
function TabMOut(obj)
{
	var targetobj=obj.getElementsByTagName('td');
	targetobj[0].className='TabInactive_left';//  .backgroundImage='url(images/hovertab_l.jpg)';
	targetobj[1].className='TabInactive_mid'; //.backgroundImage='url(images/hovertab_m.jpg)';
	targetobj[2].className='TabInactive_right'; //backgroundImage='url(images/hovertab_r.jpg)';
	/*
	targetobj[0].style.backgroundImage='url(images/inactivetab_l.jpg)';
	targetobj[1].style.backgroundImage='url(images/inactivetab_m.jpg)';
	targetobj[2].style.backgroundImage='url(images/inactivetab_r.jpg)';*/
}
function AddTabMenu(refid,menutext,menulink,menuid,menutarget,menuselected,menutohide) 
{	/* param:
	menutext : menu text
	menulink : href
	menuid : the menu id declaration
	menutarget : target  (default is "_self ")
	menuselected : ID number to indicate the menu is selected
	menutohide : 1 or 0 to show/hide the menu (default is 0) 
	*/
 
	var tabmenus="";
	var addon="";
	if (menutarget != null) addon += " target='"+menutarget+"'";
	if (menuid != null) addon += " id='"+menuid+"'";
	if (menutohide != null) addon += " style='display:none'";
	
	if (menulink != null) 
	{
		if (refid !=null) 
			addon += " href='"+request.webroot+"index.cfm?fusebox=SVCsec&fuseaction=act_setlogin&setlogin="+refid+"&nexturl="+encodeURIComponent(menulink)+"&"+request.mtoken+"'";
		else 
			addon += " href='"+request.webroot+"index.cfm?"+menulink+"&"+request.mtoken+"'";
	}

	tabmenus=tabmenus+'<td><table border="0" cellpadding="0" cellspacing="0" style="cursor:pointer"'+
	(menulink!=null? ' onclick="MClk(this);return false;"':'')+(menuselected!=refid? ' onmouseover="TabMOver(this);" onmouseout="TabMOut(this)"':'') +'><tr>';
	if (menuselected==refid) //selected
		tabmenus+='<td class="TabActive_left"><span style="width:18px"></span></td><td class="TabActive_mid" nowrap><span><a class="TabMenuTextSelected" '+addon+'>'+menutext+'</a></span></td><td class="TabActive_right"><span style="width:18px"></span></td>';
	else //not selected
		tabmenus+='<td class="TabInactive_left"><span style="width:18px"></span></td><td class="TabInactive_mid" nowrap><span><a class="TabMenuText" '+addon+'>'+menutext+'</a></span></td><td class="TabInactive_right"><span style="width:18px"></span></td>';
	tabmenus+='</tr></table></td>';
	return tabmenus;
}
function DrawTabMenuSet(content,align) // obj=navouter
{
	return '<table border="0" cellspacing="0" cellpadding="0" '+(align!=null?'align="'+align+'"':'')+'><tr>'+content+'</tr></table>';
}

/* For EPL */
function EPLGenMenu(modlist, sel, statuslist)
{
	var _d = new Date();
	var _dtnow=(_d.getDate().toString().length==1? '0'+_d.getDate():_d.getDate())+'/'+(_d.getMonth()+1)+'/'+_d.getFullYear();
	var _dtbeg='01'+'/'+(_d.getMonth()+1)+'/'+_d.getFullYear();
	
	if (statuslist != null) {
		var st = statuslist.split('|');
		var arrPolStatus = new Array();
		var tmp;
		
		for (var z = 0; z < st.length; z++) {
			tmp = st[z].split(':');
			if (tmp[0] == 930) 
				arrPolStatus[z] = new Array(tmp[1], "fusebox=MICpolicy&fuseaction=dsp_eplpolmain&fltPolStat=930&fltDtFrom=" + _dtbeg + "&fltDtTo=" + _dtnow + "&fltDtType=4&fltJoin=2&m=1&");
			else 
				arrPolStatus[z] = new Array(tmp[1], "fusebox=MICpolicy&fuseaction=dsp_eplpolmain&fltPolStat=" + tmp[0] + "&fltJoin=2&m=1&");
		}
		
		var arrPol = [["Create " + _pword, "fusebox=MICpolicy&fuseaction=dsp_polagprecreate&iacoid=" + _gcoid + "&from=PRODSELECT&"],/* tmp hardcode to allow viewing of product details */ [_pword + " Status", "fusebox=MICpolicy&fuseaction=dsp_polindex&", arrPolStatus], ["Search " + _pword, "fusebox=MICpolicy&fuseaction=dsp_eplpolmain&"]
					, ["Renew Old " + _pword, "fusebox=MICrenewal&fuseaction=dsp_renew&"]];
	} else 
		var arrPol;
	
	var l, s, t;
	
	if(modlist == null) modlist = "";
		else modlist = "," + modlist + ",";
	l = modlist.split(",");
	s = "";

	var s1="";

	for(t=0;t<l.length;t++)
	{
		switch(l[t])
		{
			case "1":s+= EPLAddTabMenu(1, "Admin", "fusebox=MICadmin&fuseaction=dsp_coprofile&", "tabmadmin", null, sel, null);break;
			case "2":s+= EPLAddTabMenu(2, _pword, "fusebox=MICpolicy&fuseaction=dsp_polindex&", "tabmpolicy", null, sel, null, arrPol);break;
			case "3":s+= EPLAddTabMenu(3, "Claim", "fusebox=MICclaims&fuseaction=dsp_claimmain&", "tabmclaim", null, sel, null);break;
			case "4":s+= EPLAddTabMenu(4, "Billing", "fusebox=MICbill&fuseaction=dsp_billmain&", "tabmbilling", null, sel, null);break;
			case "5":s+= EPLAddTabMenu(5, "Dashboard", "fusebox=MICdash&fuseaction=dsp_dashboard&", "tabmdashboard", null, sel, null);break;
			case "6":s+= EPLAddTabMenu(6, "Customer", "fusebox=MICcust&fuseaction=dsp_custsearch&", "tabmcustomer", null, sel, null);break;
			case "7":s+= EPLAddTabMenu(7, "Products", "fusebox=MICpolicy&fuseaction=dsp_prodselect&", "tabmproduct", null, sel, null);break;
			case "8":s+= EPLAddTabMenu(8, "Settings", "fusebox=MICcust&fuseaction=dsp_custsettings&", "tabmsettings", null, sel, null);break;
			case "9":s+= EPLAddTabMenu(9, "Reports", "fusebox=MICreports&fuseaction=dsp_eplreports&", "tabmreports", null, sel, null);break;
			case "10":s+= EPLAddTabMenu(10, "Home", "fusebox=MICcust&fuseaction=dsp_custhome&", "tabmcusthome", null, sel, null);break;
			case "11":s+= EPLAddTabMenu(11, "Accounts", "fusebox=MICacc&fuseaction=dsp_accmain&", "tabmaccounts", null, sel, null);break;
			case "12":s+= EPLAddTabMenu(12, "User Profile", "fusebox=MICadmin&fuseaction=dsp_changepwd&", "tabmuserprofile", null, sel, null);break;
			case "13":s+= EPLAddTabMenu(13, "Comments & Rating", "fusebox=MICRatings&fuseaction=dsp_ratingdtls&", "tabmratings", null, sel, null);break;
			case "14":s+= EPLAddTabMenu(14, "Help", "fusebox=MICSupport&fuseaction=dsp_helppage&", "tabmsupport", null, sel, null);break;
			case "99":s+= EPLAddTabMenu(99,"Preferences","fusebox=MICdash&fuseaction=dsp_preferences&", "tabmpreferences",null,sel,null);break;
		}
	}
	// other menu : logout
	s1 = '<a href="' + request.webroot + 'index.cfm?fusebox=SVCsec&fuseaction=act_logout&root=MIC&' + request.mtoken + '" style="border:0px;padding-left:3px;color:navy;cursor:pointer;">';
	s1 += '<div style="float:left"><img src="' + request.microot + 'images/001_05.gif" border=0></div>';
	s1 += '<div style="float:left;font-weight:bold;margin-top:4px">&nbsp;Logout</div></a>';

	return "<table border=\"0\" style=\"width:100%;padding-left:10px;padding-right:10px\" cellspacing=\"0\" cellpadding=\"0\"><tr><td>" + EPLDrawTabMenuSet(s, 'left') + "</td><td width=\"100px\" style=\"text-align:right\" valign=\"middle\" nowrap>" + s1 + "</td></tr></table>"
}
function EPLAddTabMenu(refid, menutext, menulink ,menuid, menutarget, menuselected, menutohide, arrChild)
{	/* param:
	menutext : menu text
	menulink : href
	menuid : the menu id declaration
	menutarget : target  (default is "_self ")
	menuselected : ID number to indicate the menu is selected
	menutohide : 1 or 0 to show/hide the menu (default is 0)
	*/

	var tabmenus="";
	var addon="";
	var url = "";
	var selected = "";
	var childmenu = "";
	if (menutarget != null) addon += " target='" + menutarget + "'";
	if (menuid != null) addon += " id='" + menuid + "'";
	if (menutohide != null) addon += " style = 'display:none'";

	if(arrChild != null)
	{
		menutext += " + ";
		childmenu = " " + EPLDrawChildMenu(arrChild);
	}

	if (menulink != null)
	{
		if (refid != null)
			url = request.webroot + "index.cfm?fusebox=SVCsec&fuseaction=act_setlogin&setlogin=" + refid + "&nexturl=" + encodeURIComponent(menulink) + "&" + request.mtoken;
		else
			url = request.webroot + "index.cfm?" + menulink + "&" + request.mtoken;
	}

	if (menuselected == refid) selected = " SELECTED";

	tabmenus = tabmenus + '<li><div class="navmenumain" URL="' + url + '"' + selected + ' onmouseover="navmenuhandler(this, \'MOVER\')" onmouseout="navmenuhandler(this, \'MOUT\')" onclick="navmenuhandler(this, \'MCLICK\')"' + addon + '>';
	if(selected != "")
		tabmenus = tabmenus + '		<div class="TabActive_left"></div><div class="TabActive_mid">' + menutext + '</div><div class="TabActive_right"></div>' + childmenu;
	else
		tabmenus = tabmenus + '		<div class="TabInactive_left"></div><div class="TabInactive_mid">' + menutext + '</div><div class="TabInactive_right"></div>' + childmenu;
	tabmenus = tabmenus + '	</div></li>';

	return tabmenus;
}

function EPLDrawTabMenuSet(content)
{
	return '<div id="nav" style="height:28px"><ul id="navmenu">' + content + '</ul></div>';
}

function EPLDrawChildMenu(arr)
{
	var str = "";
	var node;
	var childnode = "";

	if(arr)
	{
		if(arr.length)
		{
			str = "<UL>";

			for(var i = 0; i < arr.length; i ++)
			{
				var node = arr[i];

				childnode = "";
				if(node.length >= 3)
					if(node[2] != 0 && node[2] != "")
					{
						node[0] = node[0] + " + ";
						childnode = EPLDrawChildMenu(node[2]);
					}

				if(node.length >= 1)
				{
					str += "<LI>";
					if(node.length >= 2)
					{
						if(Trim(node[1]) != "")
							str += "<a href=\"" + request.webroot + "index.cfm?" + node[1] + request.mtoken + "\">" + node[0] + "</a>";
						else
							str += "<a>" + node[0] + "</a>";
					}
					else
						str += "<a>" + node[0] + "</a>";
					str += childnode + "</LI>" ;
				}
			}

			str += "</UL>";
		}
	}

	return str;
}

function navmenuhandler(obj,handler)
{
	var objptr;
	var count;

	if (handler=='MCLICK')
	{
		objptr=obj.getAttribute('URL');
		if (objptr!=null && objptr.toString()!='') location.href=objptr.toString();
	}
	else if (handler=='MOVER')
	{
		objptr=obj.getElementsByTagName("div");
		for (count=0; count<objptr.length;count++)
			objptr[count].className=(count==0?'TabHover_left':count==1?'TabHover_mid':count==2?'TabHover_right':'');
		objptr=obj.getAttribute('CHILDMENU');
		if (objptr!=null && objptr.toString()!='') document.getElementById(objptr.toString()).style.display='block';
	}
	else if (handler=='MOUT')
	{
		objptr=obj.getElementsByTagName("div");

		if (obj.getAttribute('SELECTED')!=null)
		{
			for (count=0; count<objptr.length;count++)
				objptr[count].className=(count==0?'TabActive_left':count==1?'TabActive_mid':count==2?'TabActive_right':'');
		}
		else {
			for (count=0; count<objptr.length;count++)
				objptr[count].className=(count==0?'TabInactive_left':count==1?'TabInactive_mid':count==2?'TabInactive_right':'');
		}
		objptr=obj.getAttribute('CHILDMENU');
		if (objptr!=null && objptr.toString()!='') document.getElementById(objptr.toString()).style.display='none';
	}
	return;
}
/* END For EPL */


function RptFormVerify(frm,days)
{
	var dt1,dt2,obj2;
	if(FormVerify(frm))
	{
		obj2=document.getElementById("DrTo");
		if(obj2==null)
			return true;
		obj1=document.getElementById("DrFrom");
		if(obj1==null)
			return true;
		dt1=CalParseDate(obj1.value);
		if(days==null)
		{
			days=obj2.getAttribute("MAXDAYS");
			if(days==null || days=="")
				days=366;
		}
		dt1=dt1.setDate( dt1.getDate()+days );
		dt2=CalParseDate(obj2.value);
		if(dt2>=dt1)
		{
			alert(/*{LID5016}*/"The maximum allowable period is "+/*{X}*/days/*{/X}*/+" days.\nPlease set your 'To' date to within "+/*{X}*/days/*{/X}*/+" days from the 'From' date."/*{/LID}*/);
			obj2.focus();
			obj2.select();
			return false;
		}
		// MIKE
		var t=document.getElementsByTagName("A");
		for(var i=0;i<t.length;i++) {
			var b=t[i];
			if(b.href=="javascript:ProcessReport()") {
				b.parentNode.id="TDRPTSUBMIT";
				var a=new Date();
				RptDispTime(a.getTime());
				window.setInterval("RptDispTime("+a.getTime()+")",1000);
			}
		}
		return true;
	} else
		return false;
}
function RptDispTime(begintime) { // MIKE
	var o=document.all("TDRPTSUBMIT");
	if(o) {
		var a=new Date();
		var b=new Date(a-begintime);
		b=b.getTime()/1000; // seconds
		var c=Math.floor((b/60)%60);
		var d=Math.floor(b%60);
		/* IE 7 not compatible // window.status="Report running..."+Math.floor((b/3600)%24)+" hour(s) "+Math.floor((b/60)%60)+" min(s) "+Math.floor(b%60)+" sec(s)";*/
		o.innerHTML="<span style=color:white>Processing..."+(c.toString().length==1?"0"+c:c)+":"+(d.toString().length==1?"0"+d:d)+"</span>";
	}
}

function MM_Highlight(row, highlightclass)
{
	if (highlightclass==null) highlightclass='clsHighlight1';
    row.className=highlightclass;   
}
function MM_Dehighlight(row, name)
{
    row.className=name;   
}

/*function DateAdd(interval,number,date){
 switch(interval.toLowerCase()){
  case "y": return new Date(date.setFullYear(date.getFullYear()+number));
  case "m": return new Date(date.setMonth(date.getMonth()+number));
  case "d": return new Date(date.setDate(date.getDate()+number));
  case "w": return new Date(date.setDate(date.getDate()+7*number));
  case "h": return new Date(date.setHours(date.getHours()+number));
  case "n": return new Date(date.setMinutes(date.getMinutes()+number));
  case "s": return new Date(date.setSeconds(date.getSeconds()+number));
  case "l": return new Date(date.setMilliseconds(date.getMilliseconds()+number));
 } 
}*/

function MICtimeConvert(timestr)
{
	var hour,period,cvttimestr;
	hour=parseInt(timestr.substring(0,2));
	period=' am';
	if(hour >= 12){
		hour-=12;
		period=' pm';
	}
	if(hour == 0){
		hour=12;
	}
	cvttimestr = hour.toString()+timestr.substring(2,5) + period;
	return cvttimestr;
}
