tempDivId=0;
tempChildDivId=0;
function formTableSucsess(userName){
hyperLinkDivID = 1000;
globalDivIdIncrement=0;
myStrLinks=constructMenu();
var tableText="<table border='0' cellpadding='0' cellspacing='0' width='100%'><tr><td width='20%'><div style='position: relative;'><div style='position: absolute; top: 0px; left: 35px;'><font class='logout'>Welcome "+userName+"</font></div></div></td><td width='60%'><div style='position: relative;'><div id='adminlinksdisplay' style='position: absolute; top: 0px; left: 35px; '>"+myStrLinks+"</div></div></td><td width='20%'><div style='position: relative;'><div style='position: absolute; top: 0.5px; right: 15px;'><form name='loginForm' action='/obs/OBSLoginAction.do' method='post'><input name='event' value='LogOut' type='hidden'><font class='logout'><a href='#' onclick='document.loginForm.submit()'>Sign Out</a></font></form></div></div></td></tr></table>";
document.location.reload(true);
//window.location.href=window.location.href;
//history.go(0);
return tableText;
}

function loginCheck(contKey,uName,pWord,SID,cont){
var URL = cont+"/OBSLoginAction.do?contextKey="+contKey+"&userName="+uName+"&password="+pWord+"&event=checkLoginAj&JSESSIONID="+SID;
myHttpRequest=makeRequest();
getUrl(myHttpRequest,URL);
return false;
}

function getUrl(myhttpRequest,url) {
        myhttpRequest.onreadystatechange = function() { doParse(myhttpRequest); };
        try {
                                	myhttpRequest.open('GET', url, true);
                               } 
                             catch (e) {  alert (e);}

        myhttpRequest.send('');

    }
    
function doParse(alhttpRequest) {

        if (alhttpRequest.readyState == 4) {
            if (alhttpRequest.status == 200) {        
			writecontent(alhttpRequest.responseText);
            } else {
			writecontent(' There was a problem with the request. <br>'+ alhttpRequest.responseText);
            }
        }

    }

function writecontent(mytextCUA){
	var reN = /Oops!/;

		if (reN.test(mytextCUA)){
				document.getElementById('loginError').innerHTML="Unexpected Error";
			}
			else{			
				if (mytextCUA.split("|")[0] == "false"){
				  document.getElementById('loginError').innerHTML=mytextCUA.split("|")[1];
				}
				else{
				  document.getElementById('loginDetails').innerHTML=formTableSucsess(mytextCUA.split("|")[1]);
				  document.getElementById('signin').style.visibility="hidden";				  
				  }
				
			}
			
}


function constructMenu(){

myString=document.adminLinksForm.adminLinksHidden.value;
	
	if (myString == "NIL"){
	return "";
	}
	
	menuMain = new Array();
	menuSub = new Array();
	innerSub = new Array();
	divIdIncrement=0;
	divIdIncrementParent=0;
	
	
	
	menuMain = myString.split('\@');
	
	myDivContentString="";
	myReturnStringSubMenuMainRow="";
	if(menuMain.length>1)
	{

	  for(i=0;i<menuMain.length;i++)
		{
		mySubMenuDataArray = new Array();
		mySubMenuDataArray = menuMain[i].split("{");
		if (mySubMenuDataArray.length > 1){
		myReturnStringSubMenuMainRow+="<td width='33%'><font class='mainmenulinksbar'>"+formHyperLink(mySubMenuDataArray[0],(divIdIncrement+1),'0','0')+"</font></td>";
		}
		else{
		myReturnStringSubMenuMainRow+="<td width='33%'><font class='mainmenulinksbar'>"+formHyperLink(mySubMenuDataArray[0],'0','0','0')+"</font></td>";		}
		
		myResivedString=constructSubMenu(menuMain[i],divIdIncrement);
		myResivedStringArray = new Array();
		myResivedStringArray = myResivedString.split("\@");
		myDivContentString+= myResivedStringArray[0];
		divIdIncrement=parseInt(myResivedStringArray[1]);					
		}
	}
	else{
		mySubMenuDataArray = new Array();
		mySubMenuDataArray = menuMain[0].split("{");
		myReturnStringSubMenuMainRow+="<td width='33%'><font class='mainmenulinksbar'>"+formHyperLink(mySubMenuDataArray[0],(divIdIncrement+1),'0','0')+"</font></td>";
		myResivedString=constructSubMenu(menuMain[0],divIdIncrement);
		myResivedStringArray = new Array();
		myResivedStringArray = myResivedString.split("\@");
		myDivContentString+= myResivedStringArray[0];
		divIdIncrement=parseInt(myResivedStringArray[1]);
	}
	
	myDivContentString="<table width='100%' cellspacing='0' cellpadding='0' border='0'><tr>"+myReturnStringSubMenuMainRow+"</tr>"+"<tr>"+myDivContentString+"</tr>"+"</table>";
	globalDivIdIncrement=divIdIncrement;
	return myDivContentString;
}


function constructSubMenu(mySubMenuData,myDivIdIncrement){

	mySubMenuDataArray = new Array();
	mySubMenuDataArray = mySubMenuData.split("{");
	//myReturnStringSubMenuMainRow="";
	myReturnStringSubMenuSubRow="";
	//myReturnStringSubMenuMainRow+="<td>"+formHyperLink(mySubMenuDataArray[0],myDivIdIncrement,myDivIdIncrement,'0')+"</td>";
	if (mySubMenuDataArray.length > 1)
	{
		mySubMenuDataArray = mySubMenuDataArray[1].split("}");
		
		mySubMenuDataArray = mySubMenuDataArray[0].split("<");	

		myDivIdIncrement++;
		myDivIdIncrementParentSubMenu=myDivIdIncrement;
		myReturnStringSubMenuSubRow+= "<td><div id="+myDivIdIncrement+" style='position:relative; visibility:hidden;'><div style='position:absolute; top:0px; left:-20px;'><table width='100%' cellspacing='0' cellpadding='0' border='0' class='contenttexttable'>";
		
		if (mySubMenuDataArray.length > 0)
		{

			for (myi=0;myi<mySubMenuDataArray.length;myi++){
				myResivedString=constructSubMenuLinks(mySubMenuDataArray[myi],myDivIdIncrement,myDivIdIncrementParentSubMenu);				
				myResivedStringArray = new Array();
				myResivedStringArray = myResivedString.split("\@");
				myReturnStringSubMenuSubRow+=myResivedStringArray[0];
				myDivIdIncrement=parseInt(myResivedStringArray[1]);
			}
		}
		else{
			//myDivIdIncrement++;			
			//myResivedString=constructSubMenuLinks(mySubMenuDataArray[0],myDivIdIncrement);
			//myResivedStringArray = new Array();
			//myResivedStringArray = myResivedString.split("\@");
			myReturnStringSubMenuSubRow+= "<tr><td class='adminCPST'>"+formHyperLink(mySubMenuDataArray[0],myDivIdIncrementParentSubMenu,'0','1')+"</td></tr>";
			//myDivIdIncrement=parseInt(myResivedStringArray[1]);
		}
		myReturnStringSubMenuSubRow+= "</table></div></div></td>\n";
	}
	else{
			 myReturnStringSubMenuSubRow+= "<td>&nbsp;</td>\n";
	}	
	myReturnStringSubMenuSubRow+="@"+myDivIdIncrement;
	return myReturnStringSubMenuSubRow;
}

function constructSubMenuLinks(mySubMenuLinkData,myDivIdIncrement,myDivIdIncrementParent){
mySubMenuLinkDataArray = new Array();
mySubMenuLinkDataArray = mySubMenuLinkData.split("[");
if (mySubMenuLinkDataArray.length>1){
myReturnString="\n<tr><td class='adminCPST'>"+formHyperLink(mySubMenuLinkDataArray[0],myDivIdIncrementParent,(myDivIdIncrement+1),'1')+"</td><td>";
}
else{
myReturnString="\n<tr><td class='adminCPST'>"+formHyperLink(mySubMenuLinkDataArray[0],myDivIdIncrementParent,'0','1')+"</td><td>";
}
if (mySubMenuLinkDataArray.length >1){
	 mySubMenuLinkDataArray = mySubMenuLinkDataArray[1].split("]");
}

	if (mySubMenuLinkDataArray.length >1){	


		mySubMenuLinkDataArray = mySubMenuLinkDataArray[0].split(">");
		
			if (mySubMenuLinkDataArray.length >1)
			{	
				myDivIdIncrement++;
				myReturnString+="<div id="+myDivIdIncrement+" style='position:relative; visibility:hidden;' onmouseout='mysub(0,0,0);hyperLinkDivSubNormal(tempDivId);' onmouseover='markParent("+myDivIdIncrement+")'><div style='position:absolute; top:-10px; left:-20px;'><table width='200px' cellspacing='0' cellpadding='0' border='0' class='contenttexttable'>";
				for(k=0;k<mySubMenuLinkDataArray.length;k++)
				{
				 	 myReturnString+="<tr><td class='adminCPST'>"+formHyperLink(mySubMenuLinkDataArray[k],myDivIdIncrementParent,myDivIdIncrement,'1')+"</td></tr>";
				}
				myReturnString+="</table></div></div>";	
			}
			else{
				myDivIdIncrement++;
				myReturnString+="<div id="+myDivIdIncrement+" style='position:relative; visibility:hidden;' onmouseout='mysub(0,0,0);hyperLinkDivSubNormal(tempDivId);'  onmouseover='markParent("+myDivIdIncrement+")'><div style='position:absolute; top:-10px; left:-20px;'><table width='200px' cellspacing='0' cellpadding='0' border='0' class='contenttexttable'><tr><td class='adminCPST'>"+formHyperLink(mySubMenuLinkDataArray[0],myDivIdIncrementParent,myDivIdIncrement,'1')+"</td></tr></table></div></div>"
			}
	}
	else{

	}
	myReturnString+="</td></tr>";	
	myReturnString+="@"+myDivIdIncrement;
	
return myReturnString;
}

function assignChildDivId(myTempChildDivId,myTempDivId){
tempChildDivId=myTempChildDivId;
tempDivId=myTempDivId;
}

function markParent(mymarkParentChildDivId){
if (mymarkParentChildDivId == tempChildDivId){hyperLinkDivSub(tempDivId);}
}

function formHyperLink(myData,myDivIdIncrementParent,myDivIdIncrementChild,formHyperLinkFlag){
DataArray = new Array();
DataArray = myData.split("::");
myRetStr ="";
hyperLinkDivID++;
myWindowLocation="";
	if (DataArray[1] != "NA"){
		//myWindowLocation=";window.location.href=\""+DataArray[1]+"\"";
		myWindowLocation=";postHref(\""+DataArray[1]+"\");";
	}
		//for stable menu uncomment the below line and comment the next line to the below line.
		//myRetStr="<div id='"+hyperLinkDivID+"' class='adminCPDiv' onmouseout='hyperLinkDivSubNormal("+hyperLinkDivID+")' onmouseover='assignChildDivId("+myDivIdIncrementChild+","+hyperLinkDivID+");hyperLinkDivSub("+hyperLinkDivID+");mysub("+myDivIdIncrementParent+","+myDivIdIncrementChild+","+formHyperLinkFlag+","+hyperLinkDivID+")' onclick='mysub("+myDivIdIncrementParent+","+myDivIdIncrementChild+","+formHyperLinkFlag+","+hyperLinkDivID+")"+myWindowLocation+"'>&nbsp;"+DataArray[0]+"</div>";
		myRetStr="<div id='"+hyperLinkDivID+"' class='adminCPDiv' onmouseout='mysub(0,0,0);hyperLinkDivSubNormal("+hyperLinkDivID+")' onmouseover='assignChildDivId("+myDivIdIncrementChild+","+hyperLinkDivID+");hyperLinkDivSub("+hyperLinkDivID+");mysub("+myDivIdIncrementParent+","+myDivIdIncrementChild+","+formHyperLinkFlag+","+hyperLinkDivID+")' onclick='mysub("+myDivIdIncrementParent+","+myDivIdIncrementChild+","+formHyperLinkFlag+","+hyperLinkDivID+")"+myWindowLocation+"'>&nbsp;"+DataArray[0]+"</div>";
return myRetStr;
}

function hyperLinkDivSub(myHyperLinkDivIdNew)
{
	if (myHyperLinkDivIdNew != 0){
	//document.getElementById(myHyperLinkDivIdNew).style.color="white";		
	document.getElementById(myHyperLinkDivIdNew).className="adminCPDivHover";		
	//document.getElementById(myHyperLinkDivIdNew).style.backgroundColor="#0052CC";
	}
}
function hyperLinkDivSubNormal(myHyperLinkDivIdNormalNew)
{
	if (myHyperLinkDivIdNormalNew != 0){
	//document.getElementById(myHyperLinkDivIdNormalNew).style.color="#009BC2";
	document.getElementById(myHyperLinkDivIdNormalNew).className="adminCPDiv";		
	//document.getElementById(myHyperLinkDivIdNormalNew).style.backgroundColor="transparent";	
	}
			
}


function hyperLinkDivSubold(myHyperLinkDivIdOld)
{
	for (hypi=1000;hypi<=hyperLinkDivID;hypi++){
		if (hypi == myHyperLinkDivIdOld){
			document.getElementById(myHyperLinkDivIdOld).style.backgroundColor="#0052CC";
			document.getElementById(myHyperLinkDivIdOld).style.color="white";
		}
		else{
			document.getElementById(myHyperLinkDivIdOld).style.backgroundColor="transparent";
			document.getElementById(myHyperLinkDivIdOld).style.color="#009BC2";
		}
	}
}

function mysub(id1,id2,mysubflag,hyperLinkDivIDMySub)
{
 				 if (id2 != 0) {if (tempChildDivId==id2){hyperLinkDivSub(tempDivId);}}
 				 for(i=1;i<=globalDivIdIncrement;i++)
				 {
				 		if(i==id1)
						{
	    					if (mysubflag == 1){
								document.getElementById(i).style.visibility="visible";
    						}
    						else{    							
    							if(id2==0 && document.getElementById(i).style.visibility=="visible")
	    						{
										document.getElementById(i).style.visibility="hidden";
	    						}
	    						else
	    						{
										document.getElementById(i).style.visibility="visible";
								}
    						}
    						
						}
						else if(i==id2)
						{
    						if (mysubflag == 1){
								document.getElementById(i).style.visibility="visible";								
	    					}
	    					else{
	    						if(document.getElementById(i).style.visibility=="visible")
	    						{
										document.getElementById(i).style.visibility="hidden";
	    						}
	    						else
	    						{
										document.getElementById(i).style.visibility="visible";
	    						}						
	    					}
						}
						else
						{
						document.getElementById(i).style.visibility="hidden";
						}
				 }
				 
}

function postHref(hrefData){
	document.adminHrefPostForm.action=hrefData;
	document.adminHrefPostForm.submit();
}
