﻿// JScript File
//divLeftPane : For tree
//divRightPane : for Content
var Help = new function(){

	/************ Variables *******************/
	var ModuleId = 0;
	var scrollToElementId="";
	/*******************************************/
	
	/************ functions *********************/
	this.setModuleID=function(val){
		ModuleId = val;
	};
	this.init = function(mid,val){
		ModuleId = mid;
		$("#tree").treeview({
			collapsed: true,
			animated: "fast",
			prerendered: false
		});
		this.showTreeNodeById(val);
		this.getHelpTextById(mid,1);
	};
	this.showTreeNodeById = function(val){
		// prepare branches and find all tree items with child lists
		//alert(this.ModuleId+" # "+val);
		try{
			//if(this.ModuleId == val){
				var isVisible = $("#"+val).parents("li").children("ul").css('display');
				var current = $("#tree").find("a").filter('#'+val+'');
				if(isVisible=='none'){
					if(current.length){
						current.addClass("selected").parents("ul,li").add(current.next()).show();
						current.parents("li").children("div").replaceClass("expandable-hitarea","collapsable-hitarea");
						current.parents("li").replaceClass("lastExpandable","lastCollapsable");
						current.parents("li").children("div").replaceClass("lastExpandable-hitarea","lastCollapsable-hitarea");
					}
				}else{
					current.parents("li").children("ul").hide();
					current.parents("li").children("div").replaceClass("collapsable-hitarea","expandable-hitarea");
					current.parents("li").replaceClass("lastCollapsable","lastExpandable");
					current.parents("li").children("div").replaceClass("lastCollapsable-hitarea","lastExpandable-hitarea");
				}
//			}else{
//				this.getHelpTextById(val);
//			}
		}catch(ex){}
	};
	this.getHelpTextById=function(mid){
		ModuleId = mid;
		var isVisible = $("#"+mid).parents("li").children("ul").css('display');
		if(isVisible=='none' || arguments[1]){
			var l = "";
			l = l + "HelpText.aspx?mid="+mid;
			$.ajax({url:l,cache:false,
				success: function(returnStr){
					Help.loadHtmlInRightPane(returnStr);
				}
			});
			scrollToElementId = arguments[1];
		}
	};
	this.loadHtmlInRightPane=function(returnStr){
		$("#divRightPane").html(returnStr);
		if(typeof scrollToElementId != 'undefined'){
			if(scrollToElementId.toString().indexOf("#")!=-1){
				$('#divRightPane').scrollTo($(scrollToElementId),150, { axis:'y' });
				return;
			}
		}
		$('#divRightPane').scrollTo('0px',{ axis:'y' });
	};
	this.showHelpByModuleID=function(mid){
		ModuleId=mid;
		$("#divModal").show();
		$("#divHelp").show();
		var l = "";
        l = l + "Help.aspx?mid="+mid;
        $.ajax({url:l,cache:false,success:function(returnStr){Help.getResponse(returnStr)}});
	};
	this.getResponse=function(returnStr){
		$("#divHelp").html(returnStr);
		$("#tree").treeview({
			collapsed: true,
			animated: "fast",
			prerendered: false
		});
		this.showTreeNodeById(ModuleId);
		this.getHelpTextById(ModuleId);
	};
	this.scrollTo=function(element,mid){
		try{
			if(Number(mid)!=Number(ModuleId)){
				this.getHelpTextById(mid,element);
				
			}
			else{
			    //document.location.hash=element;
				//$('#divRightPane').scrollTo($(element),150, { axis:'y' });
				$.scrollTo( element, 800, {easing:'elasout'} );
			}
		}catch(ex){
		}
	};
	this.closeHelp=function(){
		rediectToHome();
	};
	this.LoadContentWhileNodeOpen=function(me,mid){
		var isVisible = $(me).parents("li").children("ul").css('display');
		if(isVisible=='none'){
			this.getHelpTextById(mid);
		}
	};
	this.showAll=function(){
		var gid=0;
//		if(getUserId){
//			gid=getUserId();
//		}
		//parent.popModule('faq,0,0,0,&helpMid=-1');
		window.location="Help.aspx?mid=-1"
	};
}//class ends

function rediectToHome(){
    try{
        if(typeof self.parent.tb_remove!='undefined'){
            self.parent.tb_remove();
        }
        else{
            window.open("../HomePage.aspx","_self");            
        }//end if
    }
    catch(oError){
        window.open("../HomePage.aspx","_self");
    }
}
