﻿//Global Variables
var TvwName,PTPDElements="",PTPAElements="",CTPDElements="",CTPAElements=""
//Constants
var N_CC_CId="C_C_C",N_PC_CId="P_C_C",N_FC_CId="F_C_C",N_CG_CId="C_G_C",N_PG_CId="P_G_C"
var N_FG_CId="F_G_C",N_CR_CId="C_R_C",N_PR_CId="P_R_C",N_FR_CId="F_R_C",N_CT_CId="C_T_C"
var N_PT_CId="P_T_C",N_FT_CId="F_T_C",N_CR="C_R",N_FR="F_R",N_PR="P_R",N_CT="C_T",N_FT="F_T"
var N_PT="P_T",N_CEU_CelId="C_E_C",N_CEU="C_E",N_ProductCatalog="P_C",N_FamilyCatalog="F_C"
var N_CompanyGallery="C_G",N_CompanyCatalog="C_C",N_FamilyGallery="F_G",N_Family_Family="F_F"
var N_ProductGallery="P_G",N_Product_Product="P_P"
var N_CCD="C_D",N_CCG="C_D_G",N_CCSG="C_D_SG",N_CGI="_G_",N_CSGI="_SG_",N_PCD="P_D"
var N_PCG="P_D_G",N_PCSG="P_D_SG",N_FCD="F_D",N_FCG="F_D_G",N_FCSG="F_D_SG"
var N_RD="_CAD DRAWING_",N_GI="_R_GREEN INFO_"
//Declaring meaningful variables for old groupTypes
var ProductFamily="F",ProductFamilyCadDrawings="PF_CAD",ProductFamilyThreePartSpec="PF_3PS"
var ProductFamilyResources="PF_RES",ProductCadDrawings="P_CAD",ProductThreePartSpec="P_3PS"
var ProductResources="P_RES",Company="C",CompanyCatalog="C_CAT",CompanyGallery="C_GAL"
var CompanyResources="C_RES",CompanyThreePartSpec="C_3PS",ProductCatalog="P_CAT"
var FamilyCatalog="F_CAT",ProductGallery="P_GAL",FamilyGallery="F_GAL",CEU="C_CEU",Product="P"
function expandNodesBasedOnId_CPLT(nodeId,treeId)
{
	try
	{
		var objNode
		var arrHilightNode = nodeId.split('$')
		var strNodeId = arrHilightNode.join('_')
		objNode=document.getElementById("C_D"+strNodeId)
		if(objNode==null || objNode==undefined)
		{
			objNode=document.getElementById("C_D"+arrHilightNode[0])
			if(objNode==null || objNode==undefined)
			{
				objNode=document.getElementById("L_D"+strNodeId)
				if(objNode==null || objNode==undefined)
					objNode=document.getElementById("L_D"+arrHilightNode[0])
				objNode = objNode.parentNode
			}
		}
		var objHilightNode=document.getElementById("P"+strNodeId)
		if(objHilightNode==null || objHilightNode==undefined)
			objHilightNode=document.getElementById("P"+arrHilightNode[0])
		var l=0,m=0,n=0
		var fp_OpenNode=openNode_CPLT
		if(CTPDElements!="") CollapseAndDehilightPrevNodes('CompanyTreeview')
		if(PTPDElements!="") CollapseAndDehilightPrevNodes('ProductTreeview')			
		if(treeId=='ProductTreeview')
		{
			if(PTPDElements.indexOf(objNode.id)==-1) PTPDElements+=objNode.id+"#"
			if(PTPAElements.indexOf(objHilightNode.id)==-1) PTPAElements+=objHilightNode.id+"#"
		}
		else if(treeId=='CompanyTreeview')
		{
			if(CTPDElements.indexOf(objNode.id)==-1) CTPDElements+=objNode.id+"#"
			if(CTPAElements.indexOf(objHilightNode.id)==-1) CTPAElements+=objHilightNode.id+"#"			
		}
		while(objNode!=null && objNode.id!=treeId && objNode.id!="" && n<=10)
		{
			n++
			fp_OpenNode(objNode)
			objNode=objNode.parentNode.parentNode
			if(treeId=='CompanyTreeview')
				CTPDElements+=objNode.id+"#"
			else if(treeId=='ProductTreeview')
				PTPDElements+=objNode.id+"#"
		}	
		if(objHilightNode!=undefined)  
		{
		objHilightNode.style.backgroundColor="highlight"
		objHilightNode.style.color="highlighttext"
		}
		TvwName=treeId
	}
	catch(e)
	{}
}
function CollapseAndDehilightPrevNodes(treeId)
{
	var divToCollapse,anchorToDeHilight,i=0
	var arrDiv,arrAnchor,n=0
	var fp_CollapseNode=collapseNode_CPLT
	if(treeId=='ProductTreeview')
	{
		if(PTPDElements!="") arrDiv=PTPDElements.split('#')
		if(PTPAElements!="") arrAnchor=PTPAElements.split('#')
	}
	else
	{
		if(CTPDElements!="") arrDiv=CTPDElements.split('#')
		if(CTPAElements!="") arrAnchor=CTPAElements.split('#')
	}	
	if(arrDiv!=null && arrDiv!=undefined)
	{
		var arrLen = arrDiv.length
		divCount=0
		n=0		
		while(divCount<arrLen && n<=30)
		{
			if(arrDiv[divCount]!="")
			{
				divToCollapse=document.getElementById(arrDiv[divCount])
				fp_CollapseNode(divToCollapse)				
			}
			++divCount
			++n
		}
	}
	if(arrAnchor!=null && arrAnchor!=undefined)
	{
		var arrLen=arrAnchor.length
		anchorCount=0
		n=0
		while(anchorCount<arrLen && n<=30)
		{
			if(arrAnchor[anchorCount]!="")
			{
				anchorToDeHilight=document.getElementById(arrAnchor[anchorCount])
				anchorToDeHilight.style.backgroundColor=""
				anchorToDeHilight.style.color="#6F7A81"
			}
			++anchorCount			
			++n
		}
	}
	if(treeId=='ProductTreeview')
	{
		PTPDElements=""
		PTPAElements=""
	} 
	else
	{
		CTPDElements=""
		CTPAElements=""
	}
}
function openNode_CPLT(objNode)
{
	var objImg=document.getElementById("I"+objNode.id.substring(3))
	var vCPImgServerPath = "";
	if(vCPImgServerPath == undefined)
	{
//		vCPImgServerPath = document.getElementById("CPImgServerPath").src
//		vCPImgServerPath = vCPImgServerPath.substring(0,vCPImgServerPath.lastIndexOf("/")+1)
	}
	if(objImg!=null && objImg!=undefined)
	{
	    var vImgSource = objImg.src
	    if(vImgSource.indexOf("transparent.gif")==-1)
	    {
		    if(objNode.style.display=="none")
		    {
			    objNode.style.display="block"
			    objImg.src=vImgSource.replace('plus','minus')
		    }
		}
	}	
}
function collapseNode_CPLT(objNode)
{
	var objImg=document.getElementById("I"+objNode.id.substring(3))
	
	if(objImg!=null && objImg!=undefined)
	{
	    var vImgSource = objImg.src
	    if(vImgSource.indexOf("transparent.gif")==-1)
	    {
	        if(objNode.id != 'C_DCompany' && objNode.id != 'C_Dfamily' && objNode.style.display=="block")
	        {
		        objNode.style.display="none"
		        objImg.src=vImgSource.replace('minus','plus')
	        }
	    }
	}	
}