
// array init
var tab = new Array();
var mvd = new Array();
var cellcolor = new Array();
var hdiv = new Array();

// preset values
var mtop = 22; // y position of tab menus
var tabwidth = 260; // width of tab & submenus
var submenuxpos = 62; // x position of submenus
var submenuypos = -4; // y position of submenus relative to white line below the parent tab item
var linecolor = "#FFFFFF"; // color of tab menu outlines - if this is changed, the /c/pics/tmp/pipe.gif must be changed to match
var sublinecolor = "#FFFFFF"; // color of submenu outlines
var tabhcolor = "#336699"; // bgcolor of tab or submenu
var tabcolor = "#08347B"; // bgcolor of highlighted tab or submenu item

// calculated values
var spwidth = tabwidth - 2;
var thisdoc = document;
var tabxpos = (tabwidth * -1) - 1;
openedtab = null;
openedmenu = null;

// tab menu & submenu items
tab['1']	 = 'What is Epilepsy|#';
tab['1-1']	 = 'Seizures Vs Epilepsy|Seizures_epi.asp';
tab['1-2']	 = 'Diagnosing Epilepsy|Diagnosing_epi.asp';
tab['1-3']	 = 'Photosensitive Epilepsy|Photosensitive_epi.asp';
tab['1-4']	 = 'Non-Epileptic Seizures|Attacks_epi.asp';
tab['1-5']	 = 'MRI|Magnetic_Resonance_Imaging_epi.asp';

tab['2']	 = 'Managing Epilepsy|#';
tab['2-1']	 = 'First Aid|#';
tab['2-2']	 = 'Drug Treatment|Drug_Treatment.asp';
tab['2-3']	 = 'Non-Drug Therapies|non-drug.asp';
tab['2-4']	 = 'Epilepsy Surgery|Facts_Surgery_epi.asp';

tab['2-3-1']	 = 'Ketogenic Diet|Ketogenic_Diet.asp';
tab['2-3-2']	 = 'Yoga in epilepsy|yoga.asp';
tab['2-3-3']	 = 'Vagal Nerve Stimulation|Vagal.asp';

tab['3']	 = 'Special Groups|#';
tab['3-1']	 = 'Children & Epilepsy|Children_epi.asp';
tab['3-2']	 = 'Epilepsy & Learning Disability|Learning_Disability_epi.asp';
tab['3-3']	 = 'Women & Epilepsy|women_epi.asp';
tab['3-4']	 = 'Epilepsy in later life|Facts_Later_epi.asp';

tab['3-3-1']	 = 'Pregnancy & Child Care|Pregnancy_Childcare.asp';

tab['4']	 = 'Living with Epilepsy|#';
tab['4-1']	 = 'Epilepsy@School|School_epi.asp';
tab['4-2']	 = 'Safety in the home|safety_home.asp';
tab['4-3']	 = 'Epilepsy & leisure|Leisure_epi.asp';
tab['4-4']	 = 'Epilepsy & Employment|Employment_epi.asp';
tab['4-5']	 = 'Epilepsy & Mental Health|Mental_health_epi.asp';
tab['4-6']	 = 'Government Policies & Concessions in India|Government_Policies.asp';

tab['5']	 = 'Archives|#';
tab['5-1']	 = 'Recent Advances in Treatment|recent_advances.asp';
tab['5-2']	 = 'traditional methods of treatment |traditional.asp';



//browser sniff
is = new BrowserCheck();
function BrowserCheck() {
	var b = navigator.appName
	if (b=="Netscape") this.b = "ns"
	else this.b = b
	this.version = navigator.appVersion
	this.v = parseInt(this.version)
	this.ns = (this.b=="ns" && this.v>=5)
	this.op = (navigator.userAgent.indexOf('Opera')>0)
	this.ie56 = (this.version.indexOf('MSIE 5')>0||this.version.indexOf('MSIE 6')>0)
	this.iewin = (this.ie56 && navigator.userAgent.indexOf('Windows')>0)
	this.docom = (this.ie56||this.ns||this.iewin||this.op)
}

//open tab
function opentab(pullname){
	if (is.docom){
		if (openedtab != null && openedtab != pullname){
			closetab();
		}else if(openedtab != pullname){
			//alert(pullname);
			pplus = (pullname * 1) + 1;
			clrcell('tab'+pullname, tabhcolor);
			clrcell('pipe'+pullname, linecolor);
			clrcell('pipe'+pplus, linecolor);
			if (is.op){
				moveit('divtab'+pullname,'im'+pplus,tabxpos,mtop);
			}
			if (is.op||is.iewin){
				fx = 0;
				while(thisdoc.forms[fx]){
					ex = 0;
					while(thisdoc.forms[fx].elements[ex]){
						if (is.op){
							thisdoc.forms[fx].elements[ex].style.visibility="hidden";
						}else if(is.iewin && thisdoc.forms[fx].elements[ex].type.indexOf('select')>=0){
							thisdoc.forms[fx].elements[ex].style.visibility="hidden";
						}
						ex++;
					}
					fx++;
				}
			}
			showhidediv('divtab'+pullname,'visible');
			showhidediv('offdiv','visible');
			openedtab = pullname;
		}
	}
}

// close tab
function closetab(){
	if (is.docom && openedtab != null){
		showhidediv('offdiv','hidden');
		clrcell('tab'+openedtab, tabcolor);
		clrcell('pipe'+openedtab, tabcolor);
		pplus = (openedtab * 1) + 1;
		clrcell('pipe'+pplus, tabcolor);
		showhidediv('divtab'+openedtab,'hidden');
		openedtab = null;
		if (is.op||is.iewin){
			fx = 0;
			while(thisdoc.forms[fx]){
				ex = 0;
				while(thisdoc.forms[fx].elements[ex]){
					if (is.op){
						thisdoc.forms[fx].elements[ex].style.visibility="visible";
					}else if(is.iewin && thisdoc.forms[fx].elements[ex].type.indexOf('select')>=0){
						thisdoc.forms[fx].elements[ex].style.visibility="visible";
					}
					ex++;
				}
				fx++;
			}
		}
	}
}

// open submenu
function openmenu(menuname){
	if (openedmenu != null && openedmenu != menuname){
		closemenu();
	}else if(openedmenu != menuname){
		colorit('mcell'+menuname)
		if (is.op){
			mvd[menuname] = 'im'+menuname;
			moveit('divtab'+menuname,mvd[menuname],submenuxpos,submenuypos);
		}
		showhidediv('divtab'+menuname,'visible');
		openedmenu = menuname;
	}
}

// close submenu
function closemenu(){
	uncolorit('mcell'+openedmenu)
	showhidediv('divtab'+openedmenu,'hidden');
	openedmenu = null;
}

// show/hide div
function showhidediv(pullname,sh){
//if (pullname != 'divtab6'){
	hdiv[pullname].style.visibility=sh;
//	}
}

// color menu cells
function colorit(thiscell){
	ithiscell = thiscell+'i';
	clrcell(ithiscell, tabcolor);
	clrcell(thiscell, tabcolor);
}

// uncolor menu cells
function uncolorit(thiscell){
	ithiscell = thiscell+'i';
	clrcell(ithiscell, tabhcolor);
	clrcell(thiscell, tabhcolor);
}

// generic color cell
function clrcell(cid,clrval){
	cellcolor[cid].style.backgroundColor = clrval;
}

// position div
function moveit(pullname,origin,xoff,yoff){
	if (xoff == null){ xoff = 0; }
	if (yoff == null){ yoff = 0; }
	if (is.iewin){
		xoff = xoff - 13;
	}
	if (thisdoc.images[origin].offsetLeft >= 0){
		plft = thisdoc.images[origin].offsetLeft;
		ptop = thisdoc.images[origin].offsetTop;
		parr = thisdoc.images[origin].offsetParent;
		while(parr != null){
			plft = plft + parr.offsetLeft;
			ptop = ptop + parr.offsetTop;
			parr = parr.offsetParent;
		}
	}else{
		plft = getElementById(origin).offsetLeft;
		ptop = getElementById(origin).offsetTop;
	}
	plft = plft + xoff;
	ptop = ptop + yoff;
	thisdoc.getElementById(pullname).style.top=ptop;
	if (pullname != 'offdiv'){
		thisdoc.getElementById(pullname).style.left=plft;
	}
}


//print hidden divs
function printdivs(){
	if (is.docom){

		level1divs = level2divs = "";
		x = xx = xxx = 1;
		
		// set white line for sub menus
		subwhiteline = '<tr><td colspan="2" bgcolor="'+sublinecolor+'"><img src="images/spacer1.gif" height="1" width="'+spwidth+'"><\/td><\/tr>\n';
		

		while (tab[x]){

			// start tab menu div
			level1divs = level1divs+'\n<div id="divtab'+x+'" class="hiddendivs" onmouseover="opentab('+x+');">\n';
			level1divs = level1divs+'<table border="0" width="'+tabwidth+'" cellspacing="0" cellpadding="0">';
			level1divs = level1divs+'<tr valign="top">\n';
			level1divs = level1divs+'<td bgcolor="'+linecolor+'" width="1" rowspan="2"><img src="images/spacer1.gif"  height="1" width="1"><\/td>\n';
			level1divs = level1divs+'<td bgcolor="'+tabhcolor+'" width="'+tabwidth+'">\n';
			level1divs = level1divs+'<table border="0" width="'+tabwidth+'" cellspacing="0" cellpadding="0">\n';

			while (tab[x+'-'+xx]){ 
				nx = xx - 1;
				// set white line - spacer image is named to key sub menu position.
				whiteline = '\n<tr><td colspan="2" bgcolor="'+linecolor+'"><img src="images/spacer1.gif"  height="1" width="'+spwidth+'" name="im'+x+'-'+nx+'"><\/td><\/tr>\n';
				linkpath = tab[x+'-'+xx].split('|'); 
				mcell = '\'mcell'+x+'-'+xx+'\'';
			
				if (tab[x+'-'+xx+'-'+xxx]){
					// + item
					level1divs = level1divs+whiteline+'\n<tr valign="top" class="menulink">\n';
					level1divs = level1divs+'<td id="mcell'+x+'-'+xx+'i"><div>&#43;<\/div><\/td>\n';
					level1divs = level1divs+'<td width="100%" id="mcell'+x+'-'+xx+'" onmouseover="javascript:openmenu(\''+x+'-'+xx+'\');" onmouseout="javascript:closemenu();"><div><a href="'+linkpath[1]+'" class="menulink">'+linkpath[0]+'<\/a><\/div><\/td>\n';
					level1divs = level1divs+'<\/tr>\n';
					// start submenu
					level2divs = level2divs+'\n<div id="divtab'+x+'-'+xx+'" class="hiddensubdivs" onmouseover="javascript:opentab('+x+');openmenu(\''+x+'-'+xx+'\');" onmouseout="javascript:closemenu();">\n';
					level2divs = level2divs+'<table border="0" width="'+tabwidth+'" cellspacing="0" cellpadding="0">\n';
					level2divs = level2divs+'<tr valign="top">\n';
					level2divs = level2divs+'<td bgcolor="'+sublinecolor+'" width="1" rowspan="2"><img src="images/spacer1.gif"  height="1" width="1"><\/td>\n';
					level2divs = level2divs+'<td bgcolor="'+tabhcolor+'" width="'+tabwidth+'">\n';
					level2divs = level2divs+'<table border="0" width="'+tabwidth+'" cellspacing="0" cellpadding="0">\n';
				}else{
					// - item
					level1divs = level1divs+whiteline+'<tr valign="top" class="menulink" onmouseover="javascript:colorit('+mcell+');" onmouseout="javascript:uncolorit('+mcell+');">\n<td id="mcell'+x+'-'+xx+'i"><div>&#150;<\/div><\/td>\n<td width="100%" id="mcell'+x+'-'+xx+'"><div><a href="'+linkpath[1]+'" class="menulink">'+linkpath[0]+'<\/a><\/div><\/td>\n<\/tr>\n';
				}
				
				// build submenu
				while (tab[x+'-'+xx+'-'+xxx]){
					sublinkpath = tab[x+'-'+xx+'-'+xxx].split('|');
					subcell = '\'mcell'+x+'-'+xx+'-'+xxx+'\'';
					level2divs = level2divs+subwhiteline+'<tr valign="top" class="menulink" onmouseover="javascript:colorit('+mcell+');colorit('+subcell+');" onmouseout="javascript:uncolorit('+subcell+');">\n';
					level2divs = level2divs+'<td id="mcell'+x+'-'+xx+'-'+xxx+'i"><div>&#150;<\/div><\/td>\n';
					level2divs = level2divs+'<td width="100%" id="mcell'+x+'-'+xx+'-'+xxx+'"><div><a href="'+sublinkpath[1]+'" class="menulink">'+sublinkpath[0]+'<\/a><\/div><\/td>\n';
					level2divs = level2divs+'<\/tr>\n';
					xxx++;	
				}
				// end submenu
				xxx = 1;
				if (tab[x+'-'+xx+'-'+xxx]){
					level2divs = level2divs+'<\/td><\/tr><\/table><\/td>\n';
					level2divs = level2divs+'<td bgcolor="'+sublinecolor+'" width="1" rowspan="2"><img src="images/spacer1.gif"  height="1" width="1"><\/td><\/tr>\n';
					level2divs = level2divs+'<tr><td bgcolor="'+sublinecolor+'" width="'+spwidth+'"><img src="images/spacer1.gif"  height="1" width="'+spwidth+'"><\/td><\/tr>\n';
					level2divs = level2divs+'<\/table>\n<\/div>\n';
				}
				xx++;
			}
			// end tab menu
			nx++;
			level1divs = level1divs+'<\/table><\/td>\n';
			level1divs = level1divs+'<td bgcolor="'+linecolor+'" width="1" rowspan="2"><img src="images/spacer1.gif"  height="1" width="1"><\/td><\/tr>\n';
			level1divs = level1divs+'<tr><td bgcolor="'+linecolor+'"><img src="images/spacer1.gif"  height="1" width="'+spwidth+'"  name="im'+x+'-'+nx+'"><\/td><\/tr>\n';
			level1divs = level1divs+'<\/table><\/div>\n';
			x++;
			xx = 1;
		}
		
	document.write(level1divs+'\n'+level2divs+'\n');

	offdiv = '<div id="offdiv"><table border="0" width="100%" cellspacing="0" cellpadding="0"><tr><td onmouseover="javascript:closetab();"><img src="images/spacer1.gif"  height="400" width="600"><\/td><\/tr><\/table><\/div>\n';
	document.write(offdiv+'\n');


	}
}

//set vars
function setvars(){
	if (is.docom){
		sethdiv('offdiv');
		moveit('offdiv','im1',0,mtop);
		x = xx = xxx = 1;
		dx = 2;
		setcell('pipe'+x);
		while (tab[x]){
		setcell('tab'+x);
		sethdiv('divtab'+x);
		moveit('divtab'+x,'im'+dx,tabxpos,mtop);
			while (tab[x+'-'+xx]){ 
			setcell('mcell'+x+'-'+xx);
			setcell('mcell'+x+'-'+xx+'i');
				if (tab[x+'-'+xx+'-1'] && xxx < 2){
					sethdiv('divtab'+x+'-'+xx);
					moveit('divtab'+x+'-'+xx,'im'+x+'-'+xx,submenuxpos,submenuypos);
				}
				while (tab[x+'-'+xx+'-'+xxx]){
					setcell('mcell'+x+'-'+xx+'-'+xxx);
					setcell('mcell'+x+'-'+xx+'-'+xxx+'i');
					xxx++;	
				}
				xxx = 1;
				xx++;
			}
			x++;
			dx++;
			setcell('pipe'+x);
			xx = 1;
		}
	}
}

//cellcolor array
function setcell(cid){
	if (is.docom){
		cellcolor[cid] = document.getElementById(cid);
	}
}

//hdiv array
function sethdiv(cid){
	if (is.docom){
		hdiv[cid] = document.getElementById(cid);
	}
}
