/**
 * @author wenbin
 */
 
 function myFormat(str)
 {
     var s = str;
     s = s.toLowerCase();
     s = s.replace(/ /g, "_");
    s = s.replace("&", "_");
    s = s.replace("-", "_");
     
     return s;
 }

var myObj = null;
var PageObjectName = myFormat(myPageName);


function IsMyObject(ObjName)
{
    if (ObjName == 'NULL') {return false;}
    
    var Result = false;
    for (var i = 0; i < arrObjectList.length; i++)
    {
        if (arrObjectList[i] == ObjName) {Result = true;}
    }
    if (!Result) {return false;}
    
    var Obj = null;
    try
    {
        Obj = eval(ObjName);
        return true;
    }
    catch(e) {return false;}
}


if (IsMyObject(PageObjectName)) {myObj = eval(PageObjectName);}


function GetItemsByParentName(sParentName)
{
    var arr = new Array();
    for (var i = 0; i < arrObjectList.length; i++)
    {
        if (IsMyObject(arrObjectList[i])) 
        {
            var obj = eval(arrObjectList[i]);
            if (obj.ParentPageObjectName == sParentName) {arr.push(arrObjectList[i]);}
        }
    }
    
    return arr;
}



function PrintLi(URL, DisplayName)
{
    document.write('<li>');
    document.write('<a href="' + URL + '">');
    document.write(DisplayName);
    document.write('</a></li>');
}

function Print(URL, DisplayName, AddtionalStr)
{
    document.write('<a href="' + URL + '"');
    if (AddtionalStr != '') {document.write(" " + AddtionalStr)}
    document.write('>');
    document.write(DisplayName);
    document.write('</a>');
}

function ShowBreadCrumb()
{
    if (!IsMyObject(PageObjectName))     {return;}
    //Self Object
    myObj = eval(PageObjectName);
     if ((myObj.DisplayType == -20) || (myObj.DisplayType == -30)) {return;}
    
    var BreadCrumb;
    if (myObj.DisplayName(myLocalLang) != '')
    {
        BreadCrumb = "<span class='active'>" + myObj.DisplayName(myLocalLang) + "</span>";
    }
    else
    {
        BreadCrumb = "<span class='active'>Not Found</span>";
    }
        
    //Parent Object 
        var ParentInfo = myObj.ParentPageObjectName;
    
        while (ParentInfo != 'NULL')
        {        
            if (IsMyObject(ParentInfo))
            {
                var ParentObject = eval(ParentInfo);
                var ParentObjectDisplayName = '';
                
                BreadCrumb = '<a href="' + ParentObject.SelfURL + '">' 
                    + ParentObject.DisplayName(myLocalLang)
                    + '</a>&nbsp;&gt;&nbsp;' 
                    + BreadCrumb;            
            }
            else     {break;}
            ParentInfo = ParentObject.ParentPageObjectName;
        } 
    //Parent Object  end
    
    //Print BreadCrumb
    document.write('<div class="text">' + BreadCrumb + '</div>');
    //Print BreadCrumb End
}

//Title of Drop Menu 
function ShowTitle()
{
    if ((myObj.DisplayType == -10) || (myObj.DisplayType == -30)) {	return; }
    //Parent Object 
    var ParentInfo = myObj.ParentPageObjectName;
    var myInside_Nav = '';
    var TabNavigationDisplayName = '';
    
    if (IsMyObject(ParentInfo)) 
    {            
        var ParentObject = eval(ParentInfo);
        
        if (ParentObject.ParentPageObjectName != 'NULL')
        {        	
            if (Inside_Nav.InsideNavDisplayPosition(myLocalLang) == 'RIGHT') 
                //{myInside_Nav = TabNavigationDisplayName + Inside_Nav.DisplayName(myLocalLang);}
                {myInside_Nav = ParentObject.DisplayName(myLocalLang) + Inside_Nav.DisplayName(myLocalLang);}
            if (Inside_Nav.InsideNavDisplayPosition(myLocalLang) == 'LEFT') 
                //{myInside_Nav = Inside_Nav.DisplayName(myLocalLang) + TabNavigationDisplayName;}
                {myInside_Nav = Inside_Nav.DisplayName(myLocalLang) + ParentObject.DisplayName(myLocalLang);}
            
            //Print("javascript:void(0)", "" + myInside_Nav, "class='info' onclick=\"javascript:showTip('inside_menu')\"");
			document.write(myInside_Nav);
        }
        else
        {
            //If displaytype = 20, Tab navigation will show parent's name
            if (myObj.DisplayType == 20 || myObj.DisplayType == -1) {TabNavigationDisplayName = 'LSI';}
            else {TabNavigationDisplayName = myObj.DisplayName(myLocalLang);}

            if (Inside_Nav.InsideNavDisplayPosition(myLocalLang) == 'RIGHT') 
                //{myInside_Nav = myObj.DisplayName(myLocalLang) + Inside_Nav.DisplayName(myLocalLang);}
                {myInside_Nav = TabNavigationDisplayName + Inside_Nav.DisplayName(myLocalLang);}
            if (Inside_Nav.InsideNavDisplayPosition(myLocalLang) == 'LEFT') 
                //{myInside_Nav = Inside_Nav.DisplayName(myLocalLang) + myObj.DisplayName(myLocalLang);}
                {myInside_Nav = Inside_Nav.DisplayName(myLocalLang) + TabNavigationDisplayName;}

            //Print("javascript:void(0)", "" + myInside_Nav, "class='info' onclick=\"javascript:showTip('inside_menu')\"");
			document.write(myInside_Nav);
        }
    }
    else
    {
        if (ParentInfo == 'NULL')
        {
                if (Inside_Nav.InsideNavDisplayPosition(myLocalLang) == 'RIGHT') 
                    {myInside_Nav = myObj.DisplayName(myLocalLang) + Inside_Nav.DisplayName(myLocalLang);}
                if (Inside_Nav.InsideNavDisplayPosition(myLocalLang) == 'LEFT') 
                    {myInside_Nav = Inside_Nav.DisplayName(myLocalLang) + myObj.DisplayName(myLocalLang);}

                //Print("javascript:void(0)", "" + myInside_Nav, "class='info' onclick=\"javascript:showTip('inside_menu')\"");
				document.write(myInside_Nav);
        }
        else
        {
             //Print("javascript:void(0)", "Not Found", "class='info' onclick=\"javascript:showTip('inside_menu')\"");
			 document.write('Not Found');
        }
    }
    //Parent Object  end    
}

function ShowLeftColumn()
{
    //Left Column
    if ((myObj.DisplayType == -10) || (myObj.DisplayType == -30)) {	return; }
	
//	document.write('<ul>');
		document.write('<ul><li class="title"><a>' + myObj.DisplayName(myLocalLang) + '</a></li></ul>');

	         //Get Child items
	             var arr_1 = GetItemsByParentName(PageObjectName);
	
	             for (var i = 0; i < arr_1.length; i++)
	             {
	                 var TempObj = eval(arr_1[i]);
	                
	                if ((TempObj.DisplayType == myObj.DisplayType) && (TempObj.DisplayName(myLocalLang) != ''))
	                { 
	                  //PrintLi(TempObj.SelfURL, TempObj.DisplayName(myLocalLang));
						document.write("<ul>");
							document.write('<li><a href="' + TempObj.SelfURL + '">' + TempObj.DisplayName(myLocalLang) + '</a>');

								document.write("<ul>");
		                        var arr_2 = GetItemsByParentName(arr_1[i]);
		                        for (var j = 0; j < arr_2.length; j++)
		                        {   
		                            var ChildTempObj = eval(arr_2[j]);     
		                            //if (ChildTempObj.AutoHidden == false) 
		                            if ((ChildTempObj.DisplayType == TempObj.DisplayType) && (ChildTempObj.DisplayName(myLocalLang) != ''))
		                            {
		                              if (j == arr_2.length - 1)
									  {document.write("<li><a href='" + ChildTempObj.SelfURL + " class='last'>" + ChildTempObj.DisplayName(myLocalLang) + "</a></li>");}
									  else {PrintLi(ChildTempObj.SelfURL, ChildTempObj.DisplayName(myLocalLang));}
		                            }
		                        }
								document.write("</ul>");

							document.write("</li>");
						document.write("</ul>");
	                }
	                 
	             }
	         
	         //Get Child items End
	         document.write('</li>');
//	     document.write('</ul>');

    //Left Column End
}

function ShowRightColumn()
{
    //Right Column
    if ((myObj.DisplayType == -10) || (myObj.DisplayType == -20)) {	return; }
     document.write('<ul>');
    if (myObj.ParentPageObjectName == 'NULL') {return;}
    var ParentObject = eval(myObj.ParentPageObjectName);
    
	
    var arr_1 = GetItemsByParentName(myObj.ParentPageObjectName);
    
     for (var i = 0; i < arr_1.length; i++)
     {
         var TempObj = eval(arr_1[i]);
         if (TempObj.SelfURL != myObj.SelfURL)
         {//alert(myObj.DisplayType);
             if ((myObj.DisplayType == 20) || ((myObj.DisplayType == 10) && (ParentObject.ParentPageObjectName == 'NULL'))) 
            {
                if (TempObj.DisplayType == 0)
                {
                    if (TempObj.DisplayName(myLocalLang) != '')
                    {
                        PrintLi(TempObj.SelfURL, TempObj.DisplayName(myLocalLang));
                    }
                }
            }
            else
            {
                //if (TempObj.AutoHidden == false) 
                if (TempObj.DisplayType == myObj.DisplayType) 
                {
                    if (TempObj.DisplayName(myLocalLang) != '')
                    {
                        PrintLi(TempObj.SelfURL, TempObj.DisplayName(myLocalLang));
                    }
                }
                else
                {
                    //If TempObj have the same Displaytype with ParentObj 
                    //Even though its displaytype <> myobj.displaytype, brothers should be shown.
                    if (TempObj.DisplayType == ParentObject.DisplayType) 
                    {
                        if (TempObj.DisplayName(myLocalLang) != '')
                        {
                            PrintLi(TempObj.SelfURL, TempObj.DisplayName(myLocalLang));
                        }
                    }
                }
            }
            
         }
     }
      
     document.write('</ul>');
    //Right Column End    
}
