// BM - ANCHORS PAGING BAR TO RIGHT EDGE OF SCREEN

var tableControlIDBottomState;

function sizePagingBar() {
	
	var pageIDElement = document.getElementById("pageID");
	
	// IF NO pageID ON THE BODY TAG NEED TO BYPASS
	if (pageIDElement != null){

		// MINUS 20 - Accounts for the 10 pixels of left and right page margin
		// MINUS 10 - Accounts for the 10 pixels between left bar and content
		// MINUS 151 - Accounts for width of left side nav bar
		
		var pageWidth = parseInt(pageID.clientWidth)
		var pageScrollLeft = pageID.scrollLeft	
	
		if (pageWidth > 200) {
			tableControlIDTop.style.width =  pageWidth + pageScrollLeft - 20 - 10 - 151;
			tableControlIDBottom.style.width = tableControlIDTop.style.width;
		}
	}
}

// BM -- SIZE CONTENT NAV BAR HEIGHT **************************************************************************

function sizeContentNavBar() {

	var pageHeight = parseInt(pageID.clientHeight);
	var headerHeight = parseInt(headerMainTableID.scrollHeight);

	if (pageHeight > 200) {
		contentNavBarID.style.height = pageHeight - headerHeight - 40;
	}
}

function sizeHeaderBar() {
	var pageWidth = parseInt(pageID.clientWidth)
	
	if (pageWidth > 200) {
		headerMainTableID.style.width = parseInt(pageID.clientWidth) + pageID.scrollLeft - 20 ;
	}
}


//Global variables
var isNav, isIE, isIE55, browserVer,classrow;
isNav = isIE = isIE55 = false;
browser = navigator.appName;
if (browser == "Netscape")
        isNav = true;
else if (browser == "Microsoft Internet Explorer")
        isIE = true;

/** a string which holds cookies*/
var cookie_value = '';
var Columns = '15678';
var AttributesGrouping = 'AttributesGrouping';

/** The prefix of all coockie names that responsible for opening/closing Header Bars */
var prefixHeader = 'MenuHeader';

/** */
var childWindows = new Array();


/***************************** OPEN/CLOSE HEADER BARS  *************************************/
/** Enable user to expand current "primary" links in menu bar: Activities, Maintenance, Report and Tools. 
 *	Each primary link will be expanded to its appropriate links
 */

/** 
	Makes sure that the headers behaves according to thier state, open or close.
	In case the state was not yet set, the default is 'close', then the state is set and
	the header is closed, otherwise, the header behavior is determind according to its state.
*/
function keepStateOfHeaderBar(header, itemsMenuCount){
	getCookie(prefixHeader + header);
	if(cookie_value==null || cookie_value=='' || cookie_value=='close'){
		setCookie(prefixHeader + header,'close');
		hideSubMenu(header, 1, itemsMenuCount)
	}
	else{
		showSubMenu(header, 1, itemsMenuCount)
	}
}

/**
	Sets the display of the bars if not were set yet.
	Activity bar is opened, and the rest are closed.
 */
function setDefaultDisplayBar(){
	getCookie(prefixHeader + 'Activity');
	if(cookie_value==null || cookie_value==''){
		setCookie(prefixHeader + 'Activity','open'); 
		showSubMenu('Activity',1,27);

	}	
	else if(cookie_value=='close'){
		hideSubMenu('Activity',1,28);
	}
	else{
		showSubMenu('Activity',1,28);
	}
	keepStateOfHeaderBar('Maintenance',12);
	keepStateOfHeaderBar('Report',9);
	keepStateOfHeaderBar('Tool',16);
}
/**	Open/Close the header bar, if the header bar was closed then after the user clicks it becomes opened. */
function openCloseHeaderBar(header, itemsMenuCount){
	getCookie(prefixHeader + header);
	if(cookie_value==null || cookie_value=='' || cookie_value=='open'){
		setCookie(prefixHeader + header,'close');
		hideSubMenu(header, 1, itemsMenuCount)
	}
	else{
		setCookie(prefixHeader + header,'open');
		showSubMenu(header, 1, itemsMenuCount)
	}
}
function hideSubMenu(submenu,from,to){
	for (i=from; i <= to; i++)
	{
		var subMenuID=submenu+parseInt(i);

		if(document.getElementById(subMenuID)!=null){	
			document.getElementById(subMenuID).style.visibility="hidden";
			document.getElementById(subMenuID).style.display="none";
		}
	}		
}
function showSubMenu(submenu,from,to){
	for (i=from; i <= to; i++)
	{
		var subMenuID=submenu+parseInt(i);
		
		if(document.getElementById(subMenuID)!=null){	
			document.getElementById(subMenuID).style.visibility="visible";
			document.getElementById(subMenuID).style.display="";
		}
	}		
}
/*****************************************************************/
function setCookieAttributesGrouping(groupIndex,value)
{
        setCookie('AttributesGrouping'+groupIndex, value);
}

function getCookieAttributesGrouping(groupIndex)
{
        getCookie('AttributesGrouping'+groupIndex);
}
/*****************************************************************/
/**
Used in the expand category list for toggling between viewing as list or as thumbnail list 
 */
function setCookieListView(value)
{
        setCookie('ListView', value);
}

function getCookieListView()
{
        getCookie('ListView');
}
/*****************************************************************/
function setCookieColumns(value)
{
        setCookie('Columns', value);
}

function getCookieColumns()
{
        getCookie('Columns');
        Columns = cookie_value;
        if(Columns==''){
                setCookieColumns('15678')
                getCookie('Columns');
                Columns = cookie_value;
        }
}

function getWinLeftCoord()
{
 if (isNav)
 	return self.screenX;
 else	
 	return self.screenLeft;
}

function getWinTopCoord()
{
 if (isNav)
 	return self.screenY;
 else	
 	return self.screenTop;
}
/** toggling between list view and thumbnnail in expand category list*/
function toggleListView(listView){  
	setCookieListView(listView);	  	
  	location.reload();
}
/*****************************************************************/
/** */
//Call a popup Details window - title = 'Details'
function popUpDetails(URL, w, h ) {
  popUp(URL, 'Details', w, h, 'yes','no');
}

/*****************************************************************/
/** */
function popUpWithStatus(URL, title, w, h, scrollMode, withchilds) {
  if(withchilds==null || withchilds=="" || withchilds=="yes" || withchilds==true)
    openchilds(URL, title, w, h, scrollMode,1);
  else{
    var winl = (screen.width- w)/2 ;
    var wint =(screen.height - h)/2;
    winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scrollMode +',status=1,resizable=1';
        if (URL.indexOf('action')!=-1)
                URL += '&is_popup=true';
    page = window.open(URL, title, winprops);
    page.focus();
  }
}

/*****************************************************************/
/** */
function popUpLargeWithPosition(URL, title, posx, posy)
{
  var vtitle = 'details';
  if (title != null && title != "")
    vtitle = title;
  openchildsWithPos(URL, vtitle,850,640,'yes',0, posx, posy);
}

function popUpLarge(URL, title) {
  var vtitle = 'details';
  if (title != null && title != "")
    vtitle = title;
  openchilds(URL, vtitle,850,640,'yes',0);
}

/*****************************************************************/
/** */
function popUpSmall(URL, title) {

  var vtitle = 'details';
  if (title != null && title != "")
    vtitle = title;
  openchilds(URL, vtitle,400,250,'no',0);
}

/*****************************************************************/
/** Open a popup window */
function popUp(URL, title, w, h, scrollMode, withchilds) {
  if(withchilds==null || withchilds=="" || withchilds=="yes" || withchilds==true || withchilds=='true')
    openchilds(URL, title, w, h, scrollMode,0);
  else{
    var winl = (screen.width- w)/2 ;
    var wint =(screen.height - h)/2;
    winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scrollMode +', resizable=1';
        if (URL.indexOf('action')!=-1)
                URL += '&is_popup=true';
    page = window.open(URL, title, winprops);
    page.focus();
  }
}
/*****************************************************************/
/**
 * Open a popup window, The URL param is included in basic_standalone_no_servlet.jsp.
 * For explanation on this page please look at ./basic/basic_standalone_no_servlet.jsp
 * An example: popUpStandalone('/channel/channel_properties/save_errors.jsp','SaveChannel',700,600,'true')
 *             The popup is opened within the jsp/channel/channel_properties/main.jsp
 */
function popUpStandalone(URL, title, w, h, scrollMode, withchilds) {
        var fullURL = './basic/basic_standalone_no_servlet.jsp'+'?original_path='+URL;
        popUp(fullURL, title, w, h, scrollMode, withchilds);
}

/***************************************************/
/** */
function openchilds(URL, title, w, h, scrollMode,status){
  var winl = (screen.width- w)/2 ;
  var wint =(screen.height - h)/2;
  openchildsWithPos(URL, title, w, h, scrollMode, status, winl, wint);
  
}

function openchildsWithPos (URL, title, w, h, scrollMode,status, winleft, wintop){
  if (status == null || status == "")
    status = 0;
  childWindows = new Array();
  winprops = 'height='+h+',width='+w+',top='+wintop+',left='+winleft+
             ',scrollbars='+scrollMode+', status='+status+' ,resizable=1';
  if (URL.indexOf('action')!=-1)
        URL += '&is_popup=true';
  childWindows[childWindows.length]=window.open( URL, title, winprops );
  childWindows[childWindows.length-1].focus();

}

/** */
function closechilds(){
  if(childWindows!=null && childWindows.length>0){
    for(i=0; i<childWindows.length; i++)    {
      if(!childWindows[i].closed)
        childWindows[i].focus();
    }
  }
}

/** */
function isChildOpen(){
  if(childWindows!=null && childWindows.length>0){
    for(i=0; i<childWindows.length; i++)    {
      if(!childWindows[i].closed)return true
        }
  }
  return false
}

/** */
function openChannelComputedApplet(ind,ID,mode,attType,returnAttType, groupName) {
        if (groupName == null)
      groupName = "default";
        var loc = "?action=CHANNEL_FORMULA&attribute_name="+ind+"&formula="+encodeURIComponent(ID)+"&formula_mode="+mode+"&att_type="+attType+"&return_formula_type="+returnAttType+"&group_name="+groupName;
        popUp(loc,'Select', 473,525);
}

/*****************************************************************/
/**In the table set rows style */
function setRowStyle (tableRef, styleName1, styleName2){
        tableObj = document.getElementById(tableRef);
        tRows = tableObj.rows;
        var sname="";
        for (i=1; i < tRows.length; i++) {
                if (i % 2 == 1)
                        sname= styleName1;
                else
                        sname = styleName2;
                tRows[i].className = sname;
   }
}

/*****************************************************************/
//Select un select rows according to rowCount number
// in case that there is more then one TR in table


function SelectUnSelectAllRowsWithCBName(checkbox, tableRef, styleName1, styleName2, styleSelectRow, rowCount){
        if (checkbox.checked){ //Select all rows
                tableObj = document.getElementById(tableRef);
                tRows = tableObj.rows;
                var sname="";

                for (i=1; i < rowCount; i++){
    	            tRows[i].className = styleSelectRow;
	                 j = 0;
                     while (tRows[i].childNodes[j].nodeName == "#text") j++;
                     h = 0;
                     while (tRows[i].childNodes[j].childNodes[h].nodeName == "#text") h++;

                     var len = tRows[i].childNodes[j].childNodes.length;
                     for (childNodeIndex = h; childNodeIndex<len; childNodeIndex+=2)// to select also hidden feilds
                       void(tRows[i].childNodes[j].childNodes[childNodeIndex].checked=1)
                }

        }
        else{
        tableObj = document.getElementById(tableRef);
                tRows = tableObj.rows;
                var sname="";

                for (i=1; i < rowCount; i++)   {
                        if (i % 2 == 1)
                sname= styleName1;
                        else
                                sname = styleName2;
                        tRows[i].className = sname;
                        j = 0;
                        while (tRows[i].childNodes[j].nodeName == "#text") j++;
                        h = 0;
                        while (tRows[i].childNodes[j].childNodes[h].nodeName == "#text") h++;
                        var len = tRows[i].childNodes[j].childNodes.length;
                        for (childNodeIndex = h; childNodeIndex<len; childNodeIndex+=2)// to un select also hidden feilds
                          void(tRows[i].childNodes[j].childNodes[childNodeIndex].checked=0)
                        //void(tRows[i].childNodes[j].childNodes[h].checked=0)
                }
        }
}
function SelectUnSelectAllRowsCount(tableRef, styleName1, styleName2, styleSelectRow, rowCount){

SelectUnSelectAllRowsWithCBName(document.getElementById("allbox"), tableRef, styleName1, styleName2, styleSelectRow, rowCount);
}


function SelectUnSelectAllRows(tableRef, styleName1, styleName2, styleSelectRow){
        var tableObj = document.getElementById(tableRef);
        var tRows = tableObj.rows;
        var rowCount = tRows.length;

        SelectUnSelectAllRowsCount(tableRef, styleName1, styleName2, styleSelectRow, rowCount);
}

function reselectChannelRows()
{
        if(document.main.catalog_index==null)
          return;

    if(document.main.channel_index.value!=null && document.main.channel_index.checked==true)
          SelectUnSelectRow(document.main.channel_index,0,'false');

    for (var i=0;i<document.main.channel_index.length;i++)
        {
      if(document.main.channel_index[i].checked==true)
          {
        if (document.main.channel_index[i].name != 'allbox')
                {
                        SelectUnSelectRow(document.main.channel_index[i],i,'false');
            }
          }
    }
}

function reselectRows()
{
        if(document.main.catalog_index==null)
          return;

    if(document.main.catalog_index.value!=null && document.main.catalog_index.checked==true)
          SelectUnSelectRow(document.main.catalog_index,0,'false');

    for (var i=0;i<document.main.catalog_index.length;i++)
        {
      if(document.main.catalog_index[i].checked==true)
          {
        if (document.main.catalog_index[i].name != 'allbox')
                {
                        SelectUnSelectRow(document.main.catalog_index[i],i,'false');
            }
          }
    }
}

/**Select/Unselect row according to CB(checkbox) state*/
function SelectUnSelectRowWithStyle(checkbox, rowID, styleRow1, styleRow2, styleSelect)
{
        if (checkbox.checked)
                SelectRow(checkbox, rowID, styleSelect);
        else
                UnSelectRow(checkbox, rowID, styleRow1, styleRow2);
        var TalebRows = TableRowsChecked = 0;
        for (var i = 0; i < document.main.elements.length; i++)
        {
                var e = document.main.elements[i];
                if ((e.name != 'allbox') && (e.type == 'checkbox'))
                {
                        TalebRows++;
                        if (e.checked)
                                TableRowsChecked++;
                }
        }
        //If all rows are checked change the main check box to check
        if (TalebRows == TableRowsChecked)
                document.main.allbox.checked = true;
        else
                document.main.allbox.checked = false;
}

/*****************************************************************/
/**Select/Unselect row according to CB(checkbox) state*/
function SelectUnSelectRow(checkbox, rowID, unified)
{
        if (checkbox.checked)
                SelectRow(checkbox, rowID, 'TRowSelect');
        else
        {
                if (unified == 'true')
                        UnSelectRow(checkbox, rowID, 'TRow1', 'TRow1');
                else
                        UnSelectRow(checkbox, rowID, 'TRow1', 'TRow2');
        }
        var TalebRows = TableRowsChecked = 0;
        for (var i = 0; i < document.main.elements.length; i++)
        {
                var e = document.main.elements[i];
                if ((e.name != 'allbox') && (e.type == 'checkbox'))
                {
                        TalebRows++;
                        if (e.checked)
                                TableRowsChecked++;
                }
        }
        //If all rows are checked change the main check box to check
        if (TalebRows == TableRowsChecked)
                document.main.allbox.checked = true;
        else
                document.main.allbox.checked = false;
}

/*****************************************************************/
/**Change row to selected class*/
function SelectRow(E,rowID, selectStyle)
{
        if (isIE)
        {
                while (E.tagName != "TR")
                {
                          E = E.parentElement;}
                }

        else
        {
                while (E.tagName != "TR")
                {
                        E=E.parentNode;
                }
        }
        E.className = selectStyle;
}

/*****************************************************************/
/**Change row to unselected class*/
function UnSelectRow(E, rowID, styleRow1, styleRow2)
{
        if (isIE)
        {
                while (E.tagName!="TR")	{
                        E=E.parentElement;
                }
        }
        else
        {
                while (E.tagName!="TR")	{
                        E=E.parentNode;
                }
        }

        if (rowID % 2 == 0)
                E.className = styleRow1;
        else
                E.className = styleRow2;
}

/*****************************************************************/
/** */
function isSelectedProductId() {
        var j=0;
  if(document.main.product_id!=null){
    /* one row only */
    if(document.main.product_id.value!=null && document.main.product_id.checked==true)
      j=1;
    else{
      for (var i=0;i<document.main.product_id.length;i++){
        if(document.main.product_id[i].checked==true){
          j++;
        }
      }
    }
  }
  return j;
}
/** */
function showWorkFlow(){
        var org = document.main.organization.value ;
        var ssp = (document.main.self_service_loading.checked)?'&self_service_loading=on':'';

        var activityOwners = "";
        for (var i=0;i<document.main.elements.length;i++)
        {
        var e = document.main.elements[i];
                if ((e.type=='select-one') && (e.name!='template') && (e.name!='automation_profile') && (e.name!='notification_profile'))
                {
                        if(e.name.substring(0,8)=='activity')
                        {
                                 activityOwners += "&"+e.name+"="+e.value;
                        }
                }
    }

        popUp('?action=CATALOG_PREVIEW&organization_name='+org+ssp+activityOwners,'catalogPreview',700,505,'yes');
}
/*****************************************************************/
/** */
function showChannelWorkflow(){
        var notif = document.main.notification_profile.value;
        var encodedValues = document.main.encoded_notifications.value;
        var encodeNotif = getEncodedValue(notif,encodedValues);
        var mode = main.mode.value;
        var fileName = main.encoded_file_name.value;
        var activityOwners = "";
        var automaticModes = "";
        for (var i=0;i<document.main.elements.length;i++)
        {
        var e = document.main.elements[i];
                if ((e.type=='select-one') && (e.name!='notification_profile') && (e.name!='catalog_name'))
                {
                        if(e.name.substring(0,8)=='activity')
                        {
                                 activityOwners += "&"+e.name+"="+e.value;
                        }
                }
                else if ((e.type=='radio') && (e.name!='is_default') && (e.name!='content_mode') && (e.name!='treck_changes') && (e.name!='filter_type'))
                {
                        if(e.name.substring(0,14)=='automatic_mode')
                        {
                                if(e.checked)
                                        automaticModes += "&"+e.name+"="+e.value;
                        }
                }
    }
        popUp('?action=CHANNEL_WORKFLOW&notification_profile='+escape(notif)+activityOwners+automaticModes+'&mode='+mode+'&file_name='+fileName,'ChannelPreview',620,390,'yes');
}
/**
 * <encodedValues> is a string that contains pairs of value/encoded value.
 * <key> is one of the values.
 * the key is searched in the encodedValues and if it is exist the encoded value is returned
 */
function getEncodedValue(key,encodedValues) {
        if (encodedValues==null)
                return '';
        var keyIndex 	= encodedValues.indexOf(key);
        if(keyIndex==-1)
          return '';
        var valueStart 	= encodedValues.indexOf('=',keyIndex);
        var valueEnd 	= encodedValues.indexOf(';',valueStart);
        var value 		= encodedValues.substr(valueStart+1,valueEnd);
        return value;
}
/*****************************************************************/
/**Show/hide div*/
function	ShowHideDiv(DivName, imageHide, imageShow, name)
{
        if(isIE){
                if (document.getElementById(DivName).style.visibility=="hidden")
                {
                        document.getElementById(DivName).style.visibility="visible";
                        document.getElementById(DivName).style.display="";
                        document.images["ShowHideImg"].src=imageHide;
                        if(name!='')
                                setCookie(name, 'Hide');/*save the current state display of the filter's image in cookie*/
                }
                else
                {
                        document.getElementById(DivName).style.visibility="hidden";
                        document.getElementById(DivName).style.display="none";
                        document.images["ShowHideImg"].src=imageShow;
                        if(name!='')
                                setCookie(name, 'Show');//save the current state display of the filter's image in cookie
                }
        }
}


//Show/hide div
//-----------------------------------------------
function	ShowHideDivName(DivName, imageName, imageHide, imageShow)
{
        if (isIE)
        {
                if (document.getElementById(DivName).style.visibility=="hidden")
                {
                        document.getElementById(DivName).style.visibility="visible";
                        document.getElementById(DivName).style.display="";
                        if (imageHide) {
                        document.images[imageName].src=imageHide;
                	}
                }
                else
                {
                        document.getElementById(DivName).style.visibility="hidden";
                        document.getElementById(DivName).style.display="none";
			if (imageShow) {
                        document.images[imageName].src=imageShow;
                	}
                }
        }
}
//Show/hide div filter
/*****************************************************************/
function	ShowHideDivHref(DivName, hrefName, imageHide, imageShow, cookieName, strShow, strHide, imgName)
{
                if (document.getElementById(DivName).style.visibility=="hidden")
                {
                        document.getElementById(DivName).style.visibility="visible";
                        document.getElementById(DivName).style.display="";
                        document.getElementById(hrefName).innerHTML=strHide+'&nbsp;<img  border="0" name="ShowHideImg">';
                        document.images[imgName].src=imageShow;
                        if(cookieName!='')
                                setCookie(cookieName, 'Hide');/*save the current state display of the filter's image in cookie*/
                }
                else
                {
                        document.getElementById(DivName).style.visibility="hidden";
                        document.getElementById(DivName).style.display="none";
                        document.getElementById(hrefName).innerHTML=strShow+'&nbsp;<img  border="0" name="ShowHideImg">';
                        document.images[imgName].src=imageHide;
                        if(cookieName!='')
                                setCookie(cookieName, 'Show');//save the current state display of the filter's image in cookie
                }
}

/*****************************************************************/
/** */
function SendSupplierBack(supplierName) {
        var oldOrg = opener.main.organization.value;
        if(oldOrg!=supplierName)
        opener.main.user.value="";
        opener.main.group.value="";
        opener.main.organization.value = supplierName;
        opener.main.organization_name.value = supplierName;
        checkSupplierName();
        self.close();
}

/*****************************************************************/
/** */
function SendNewSupplierBack() {
        if (dunnit)
        return false;
        else
        {
                var orgName = window.main.organization_name.value;
                var desc    = window.main.description.value;
                window.location = "?action=ADD_SUPPLIER&organization_name="+encodeURIComponent(orgName)+"&description="+encodeURIComponent(desc);
                checkSupplierName();
                dunnit = true;
        }
}
/*****************************************************************/
function getNotificationMessage(activity,index){
        var loc = "?action=NOTIFICATION_MESSAGE&activity_name="+activity+"&index="+index;
        popUp(loc,'NotificationMessage',520,225,'yes');
}
/*****************************************************************/

function SendNewGroupBack() {
        if (dunnit)
        return false;
        else
        {
                var orgName 		= window.main.organization_name.value;
                var desc    		= window.main.description.value;
                var groupName           = window.main.supplier_group_name.value;

        window.location = "?action=ADD_GROUP&organization_name="+encodeURIComponent(orgName)+"&description="+encodeURIComponent(desc)+"&supplier_group_name="+encodeURIComponent(groupName);
        checkGroupName();
                dunnit = true;
        }
}

/*****************************************************************/
/**if in the text field of supplier name in the catalog's definition is filled
 * then new user button and select user button are not disabled and vise versa
 */
function checkSupplierName() {
        if(opener.main.organization.value!=""){
                opener.document.getElementById("select_group").style.visibility = 'visible';
                opener.document.getElementById('new_group').style.visibility = 'visible';
        }
        else{
                opener.document.getElementById("select_group").style.visibility = 'hidden';
                opener.document.getElementById('new_group').style.visibility = 'hidden';
        }
}
function checkGroupName() {
        if(opener.main.supplier_group_name.value!=""){
                opener.document.getElementById("select_user").style.visibility = 'visible';
                opener.document.getElementById('new_user').style.visibility = 'visible';
        }
        else{
                opener.document.getElementById("select_user").style.visibility = 'hidden';
                opener.document.getElementById('new_user').style.visibility = 'hidden';
        }
}

/*****************************************************************/
/** */
  function SendUserBack(userName) {
    opener.main.user.value=userName;
    opener.main.user_name.value=userName;
    self.close();
  }

  function SendGroupBack(groupName) {
    opener.main.user.value="";
    opener.main.group.value=groupName;
    opener.main.supplier_group_name.value=groupName;
    checkGroupName()
    self.close();
  }

/*****************************************************************/
function getSelectedArray(elem_name){
  var j=new Array();
  for (var i=k=0;i<document.main.elements.length;i++){
    var e = document.main.elements[i];
    if (e.name == elem_name ){
      if( e.checked==true){
        j[k]=e.value;
        k++;
      }
    }
  }
  return j;
}

/*****************************************************************/

/** from cancel activity */
function showHideImage() {
        if (document.main.suppNotify.checked)
                document.images["ShowHideImg"].style.visibility = "visible";
        else
                document.images["ShowHideImg"].style.visibility = "hidden";
}
/*****************************************************************/
function disableCheckBox(checkname,ischeck){
  for (var i=0;i<document.main.elements.length;i++){
    var e = document.main.elements[i];
    if (e.name == checkname)
      e.disabled=ischeck;
  }
}
/*****************************************************************/
/** */
function okCancelDialog(appName,action,message,okText,includePage,params,title,isShowApproveWaitPage,isShowWaitPage) {
  if(title==null)
    title="Warning";
  var loc = appName+
  "&actiontwo="+action+"&title="+encodeURIComponent(title)+"&message="+encodeURIComponent(message)+"&oktext="+encodeURIComponent(okText)+"&inc="+includePage+params;
   if(isShowApproveWaitPage=='true')
         loc = loc + "&is_show_approve_wait_page=true";
   if(isShowWaitPage=='true')
         loc = loc + "&is_show_wait_page=true";
  popUp(loc,'Select', 430,250);
}

/*****************************************************************/
function isSelected(elem_name){
  var j=0;
  for (var i=0;i<document.main.elements.length;i++){
    var e = document.main.elements[i];
    if (e.name == elem_name ){
      if( e.checked==true){
        j++;
        //return j;
      }
    }
  }
  return j;
}


/*****************************************************************/
/** show message in input_file_information.jsp  if no catalog is selected*/
function validateParam(param,withclose) {
if(param==null || param==""){
  if (document.getElementById("message").style.visibility=="hidden") {
    document.getElementById("message").style.visibility="visible";
    document.getElementById("message").style.display="";
  }
}
else {
    document.main.submit();
    if(withclose!=null){
      self.close();
    }
  }
}

function enterValidator() {
  if(event.keyCode == 13 ) // enter
      event.returnValue=false;
}


/** Checks that only numeric keys and only one '.' will be entered
 *  e.g: .4, 3.66, 87 etc...
 */
 
function numericFieldValidatorStr(strValid)
{
  var str = String.fromCharCode(event.keyCode);
  if (strValid.indexOf(str) == -1)
	  event.returnValue=false;
  else
	  event.returnValue=true;
  		  
} 

function numericFieldValidator() {
	
  var el = event.srcElement;
  var strValidChars = "0123456789.-";
  var strValidCharsWithoutDot = "0123456789-";
  if(el.value.indexOf('.')>=0){  //If dot already exist - don't allow another dot
	  numericFieldValidatorStr(strValidCharsWithoutDot);
  }	
  else
  {
	  numericFieldValidatorStr(strValidChars);
  }		  
}

/** Checks that only whole numbers keys will be entered
 *  e.g: 4, 366, 87 etc...
 */
function numbersFieldValidator() {
  var strValidChars = "0123456789";
  numericFieldValidatorStr(strValidChars);
}


function PositiveNumericFieldValidator() {
  var strValidChars = "0123456789.";
  var strValidCharsWithoutDot = "0123456789";
  var el = event.srcElement;
  if(el.value.indexOf('.')>=0){  //If dot already exist - don't allow another dot
	  numericFieldValidatorStr(strValidCharsWithoutDot);
  }	
  else
  {
	  numericFieldValidatorStr(strValidChars);
  }		  
}
function oneCharacterValidator() {
  var el = event.srcElement;
  if (el.value.length>0)event.returnValue=false;
}



/***********************************************************/

/*****************************************************************/
function setSearchMethod(isShowID) {
        if (isShowID=='true')
                return;
        var optionFreeText = new Option("Free text  ","Free text",true,false);
        var optionID = new Option("ID","ID",false,false);

        if (document.search.product_or_categories.selectedIndex ==0) {
                document.search.search_method.options.length= 0;
                document.search.search_method.options[0] = optionFreeText;
                document.search.search_method.options[1] = optionID;
        }
        else {
                document.search.search_method.options.length= 0;
                document.search.search_method.options[0] = optionFreeText;
        }
}
/** */
function submitFromFilter(action_name) {
        document.main.action.value = action_name;
}
/***************************************************/
/** */
function setCookie(name, value){
        var d=new Date();
        d.setTime(d.getTime()+(1000*60*60*24));
        document.cookie = name+"="+value+";path=/;expires="+d.toGMTString();
}
/** */
function getCookie(name){
        cookie_value = '';
        if(document.cookie.length > 0) {
                var search = name + "="
                var offset = document.cookie.indexOf(search);
                if(offset != -1) {
                        offset += search.length;
                        var end = document.cookie.indexOf(";", offset);
                        if(end == -1)
                                end = document.cookie.length
                        cookie_value = document.cookie.substring(offset, end);
                }
        }
}

/*****************************************************************/
function getSelectedAsString(firstIndex){
      var selectedString = ""
          var checkedIndex = ""
          var first = new Number (firstIndex)
// one row
          if(main.product_index.value!=null && main.product_index.checked==true){
                  checkedIndex = first
                  selectedString = selectedString + checkedIndex +","

          }else{
         for (var i=0 ; i<main.product_index.length; i++){
                if( main.product_index[i].checked==true){
                                checkedIndex = i + first
                                selectedString = selectedString + checkedIndex +","
                }
         }
           }
           return selectedString
}

/*****************************************************************/
/** */
function submitFromProductSearch(action_name,actionBold,action,product_type) {

  var j = isSelected(product_type);

  if(j==0){
    noSelectedProductMessage(actionBold,action);
  }
  else{
    document.main.action.value = action_name;
    document.main.submit();
  }
}
/*****************************************************************/
/** */
function clearQuantites(){
  for (var i=0;i<document.main.elements.length;i++)
    {
    var e = document.main.elements[i];
    if (e.name.indexOf('quantity')>=0)
      e.value = "";
    }
}

/*****************************************************************/
/** */
function CheckAll(){
  for (var i=0;i<document.main.elements.length;i++)
    {
    var e = document.main.elements[i];
    if (e.name == 'product_id')
      e.checked = document.main.SelectAll.checked;
    }
}

/*****************************************************************/
/** */
function selectUser(){
        var orgName = window.document.main.organization.value;
        var grpName = window.document.main.group.value;
        var loc = "?action=SELECT_USER&organization_name="+encodeURIComponent(orgName)+"&supplier_group_name="+encodeURIComponent(grpName);
        openchilds(loc,'SelectUser',400,210,'yes',0);
}

function selectGroup(){
        var orgName = window.document.main.organization.value;
        var loc = "?action=SELECT_GROUP&organization_name="+encodeURIComponent(orgName);
        openchilds(loc,'SelectGroup',400,210,'yes',0);
}
/*****************************************************************/
/** */
function userProperties(){
        var orgName = window.document.main.organization.value;
        var grpName = window.document.main.group.value;
        var loc = "?action=USER_PROPERTIES&organization_name="+encodeURIComponent(orgName)+"&supplier_group_name="+encodeURIComponent(grpName);
        openchilds(loc,'NewUser',500,345,'yes',0);
}

function groupProperties(){
        var orgName = window.document.main.organization.value;
        var loc = "?action=GROUP_PROPERTIES&organization_name="+encodeURIComponent(orgName);
        openchilds(loc,'NewGroup',500,345,'yes',0);
}


/** */
function submitMainForm(action_name) {
    document.main.action.value = action_name;
    document.main.submit();
}

/*****************************************************************/
/** */
function check_continue_upload(){
  if (document.main.ignore_non_valid.checked)
        {
                document.main.submit.disabled=false;
        }
        else
        {
                document.main.submit.disabled=true;
        }
}

/*****************************************************************/
/** */
function openComputedApplet(ind, ID, groupName) {

  if (groupName == null)
    groupName = "default";
  var loc = "?action=FORMULA&attribute_index="+ind+"&formula="+ID+"&group_name="+groupName;
  popUp(loc,'Select', 473,525);
}

/*****************************************************************/
/** */
function setAction(applicationName, useLimitNum){
    var url = "./"+applicationName+"?action=UPLOAD_CATALOG_STEP2"+"&selected_format="+encodeURIComponent(document.main.selected_format.value)+"&upload_file="+encodeURIComponent(document.main.upload_file.value)+"&upload_description="+encodeURIComponent(document.main.upload_description.value)+"&selected_datasource="+encodeURIComponent(main.selected_datasource.value);
    var formatParameters = "";
        for (var i=0;i<document.main.elements.length;i++)
        {
           var e = document.main.elements[i];
           if(e.name.substring(0,7)=='format_')
           {
              formatParameters += "&"+e.name+"="+e.value;
           }
        }
        url = url + formatParameters;
        document.main.action = url;
        document.main.submit();
}
/**
        this function is called from Portal.upload_catalog_step2
        @param Attribute    supplier attribute name or "Constant.." or "Computed.."
        @param Constant		the name property of textfield that display the computed or constant value
        @param Computed		the name property of select image that open the formula applet
        @param SpanSelectName	the id property of span of select component
        @param SpanTextName		the id property of span of textfield component
        @param isList		indicates whether list of possible constant values exist
        @param ConstantSelect	the name property of select component that display the constant value list,
                                                        if <isList> is false then <ConstantSelect> is ''
*/



/** */
function DelCriteria(){
        document.main.criterialist.options.length = 0;
        document.main.criterias.value = "";
}



/*****************************************************************/
/** */
//this function is called from Reports
function changeURL(){
        window.location.href=window.parent.document.QuickIndex.URL.options[window.parent.document.QuickIndex.URL.selectedIndex].value;
}

/*****************************************************************/
/** */
//this function is called from Reports.detail_info
function closeMe() {
        self.close()
}

/*****************************************************************/
/** */
//sort columns for completed_activities.jsp, running_activities.jsp, catalog_activites.jsp
function sortActivities(action,sortField,direction,activity) {
    document.location="?action="+action+"&sort="+sortField+"&dir="+direction+"&activity="+activity;
}

/** */
//sort
function sort(action,currsortField,sortField,direction) {
  if(currsortField)
    document.location="?action="+action+"&sort_by="+sortField+"&direction="+direction;
  else
    document.location="?action="+action+"&sort_by="+sortField+"&direction=0";
}

/*****************************************************************/
function submitFromBuysideCatalogs(filterByActivity) {
        if (main.supplier_organization_active.checked == true || main.catalog_name_active.checked == true || main.description_active.checked == true)
                main.filtered.value = "true";

        if (filterByActivity!=null && filterByActivity==true && main.activity_name_active.checked == true)
                main.filtered.value = "true";
        main.submit();
}

/*****************************************************************/
/** returns the row class color must end with a call to endRow() */
function switchClassRow() {
  if(classrow=="TRow1"){
    classrow="TRow2";
    document.write("<tr class='TRow2'>");
  }
  else{
    classrow="TRow1";
    document.write("<tr class='TRow1'>");
  }
}

/**  */
function endRow() {
  document.write("</tr>" );
}
/*****************************************************************/
/** showException() */
function showException() {
        if (document.getElementById("stackException").style.visibility=="hidden") {
                document.getElementById("stackException").style.visibility="visible";
                document.getElementById("stackException").style.display="";
        }
        else {
                document.getElementById("stackException").style.visibility="hidden";
                document.getElementById("stackException").style.display="none";
        }
}

/** write the exception line, add the exception param and then must end with a call to  endExceptionLine
 * see detail_info.jsp
 */
function exceptionLine() {
        document.write("<td valign='top'>Stack exception:</td>"+
                 "<td><a href='javascript:showException()'> Details...&nbsp;</a>"+
                 "<div id='stackException' style='visibility:hidden;display:none;'>");
}

/**  */
function endExceptionLine() {
  document.write("&nbsp</div> </td>" );
}
/*****************************************************************/
/** */
function loadImageLine(i) {
  document.write('<img src="'+imagesArr[i].src+'" border="0" '+
                 'width="40" height="40" onerror="HandleImgError(this)">');
}
/** */
function setimage_size(src_name, image_name, max_width, max_height){
        var image = new Image();
        image.src =src_name;

        if (image.width > max_width || image.height > max_height)
        {
                if (image.width/max_width >image.height/max_height)
                {
                        image.height =image.height*max_width/image.width;
                        image.width =max_width;
                }
                else
                {
                        image.width =image.width*max_height/image.height;
                        image.height =max_height;
                }
        }

        document.images[image_name].src = src_name;
        document.images[image_name].height = image.height;
        document.images[image_name].width = image.width;
}

/** */
function HandleImgError(imageObj){
        imageObj.src = "./images/NoImage.gif";
}
/** */
function HandleImgErrorNoDisplay(imageObj){
        imageObj.src = "./images/NoImage.gif";
}

/*****************************************************************/
var maxNum =0;
function updateMaxNum(num)
{
        if (num=="Days") maxNum = 31;
        if (num=="Weeks") maxNum = 5;
        if (num=="Months") maxNum = 12;
        document.main.number.options.length = 0;
        for (var i=1; i <= maxNum; i++)
        {
                var opt = new Option(i, 'maxNum', false, false);
                document.main.number.options[i-1]=opt;
        }
}
/*****************************************************************/
function approve(isMenu){

    if (isMenu=='true'){
                window.opener.location.reload();
        }
        else{
                opener.location = "./portal?action=PORTAL_CATALOG_LIST";
        }
        self.close();
}

/*****************************************************************/
/* This function swap the rows colors**/
function assignAlternatingStyles (tableRef,styleName1,styleName2) {
        tableObj = document.getElementById(tableRef);
        tRows = tableObj.rows;
        for (i=0; i < tRows.length; i++) {
                if (i % 2 == 0)
                tRows(i).className = styleName1;
                else
                        tRows(i).className = styleName2;
     }
}
/*****************************************************************/
function ChangeBundlePolicy()		//for calculating the unit price
{
        switch (document.main["Policy"].selectedIndex) {
        case 0://fixed
        {
                document.getElementById("calculation_type").style.visibility="hidden";
                document.getElementById("calculation_type").style.display="none";
                document.getElementById("sub_add_type").value="";
                document.getElementById("ValueField").style.visibility="visible";
                document.getElementById("ValueField").style.display="";
                document.getElementById("ValueField").value="";
        }
        break;
        case 1:
        {
                document.getElementById("calculation_type").style.visibility="hidden";
                document.getElementById("calculation_type").style.display="none";
                document.getElementById("sub_add_type").value="";
                document.getElementById("ValueField").style.visibility="hidden";
                document.getElementById("ValueField").style.display="none";
                document.getElementById("ValueField").value="none";
        }
        break;
        case 2:
        {
                document.getElementById("calculation_type").style.visibility="visible";
                document.getElementById("calculation_type").style.display="";
                document.getElementById("sub_add_type").value="+";
            document.all.sub_add_type.innerHTML = '+';
                document.getElementById("ValueField").style.visibility="visible";
                document.getElementById("ValueField").style.display="";
                document.getElementById("ValueField").value="";
        }
        break;
        case 3:
        {
                document.getElementById("calculation_type").style.visibility="visible";
                document.getElementById("calculation_type").style.display="";
                document.getElementById("sub_add_type").value="-";
                document.all.sub_add_type.innerHTML = '-';
                document.getElementById("ValueField").style.visibility="visible";
                document.getElementById("ValueField").style.display="";
                document.getElementById("ValueField").value="";
        }
        break;
         case 4:
        {
                document.getElementById("calculation_type").style.visibility="hidden";
                document.getElementById("calculation_type").style.display="none";
                document.getElementById("sub_add_type").value="";
                document.getElementById("ValueField").style.visibility="hidden";
                document.getElementById("ValueField").style.display="none";
                document.getElementById("ValueField").value="none";
        }
        break;
        case 5:
        {
                document.getElementById("calculation_type").style.visibility="visible";
                document.getElementById("calculation_type").style.display="";
                document.getElementById("sub_add_type").value="+";
                document.all.sub_add_type.innerHTML = '+';
                document.getElementById("ValueField").style.visibility="visible";
                document.getElementById("ValueField").style.display="";
                document.getElementById("ValueField").value="";
        }
        break;
        case 6:
        {
                document.getElementById("calculation_type").style.visibility="visible";
                document.getElementById("calculation_type").style.display="";
                document.getElementById("sub_add_type").value="-";
                document.all.sub_add_type.innerHTML = '-';
                document.getElementById("ValueField").style.visibility="visible";
                document.getElementById("ValueField").style.display="";
                document.getElementById("ValueField").value="";
        }
        break;
 }
}
function ChangeBundledPolicy(){    //as a member of another bundle
        switch (document.main.bundled_policy.selectedIndex){
                case 0://fixed
                {
                        document.getElementById("bundled_calculation_type").style.visibility="hidden";
                        document.getElementById("bundled_calculation_type").style.display="none";
                        document.getElementById("bundled_sub_add_type").value="";
                        document.getElementById("bundled_value_field").style.visibility="visible";
                        document.getElementById("bundled_value_field").style.display="";
                        document.getElementById("bundled_value_field").value="";
                        break;
                }
                case 1:
                {
                        document.getElementById("bundled_calculation_type").style.visibility="hidden";
                        document.getElementById("bundled_calculation_type").style.display="none";
                        document.getElementById("bundled_sub_add_type").value="";
                        document.getElementById("bundled_value_field").style.visibility="hidden";
                        document.getElementById("bundled_value_field").style.display="none";
                        document.getElementById("bundled_value_field").value="none";
                        break;
                }
                case 2:
                {
                        document.getElementById("bundled_calculation_type").style.visibility="visible";
                        document.getElementById("bundled_calculation_type").style.display="";
                        document.getElementById("bundled_sub_add_type").value="+";
                document.all.bundled_sub_add_type.innerHTML = '+';
                        document.getElementById("bundled_value_field").style.visibility="visible";
                        document.getElementById("bundled_value_field").style.display="";
                        document.getElementById("bundled_value_field").value="";
                        break;
                }
                case 3:
                {
                        document.getElementById("bundled_calculation_type").style.visibility="visible";
                        document.getElementById("bundled_calculation_type").style.display="";
                        document.getElementById("bundled_sub_add_type").value="-";
                        document.all.bundled_sub_add_type.innerHTML = '-';
                        document.getElementById("bundled_value_field").style.visibility="visible";
                        document.getElementById("bundled_value_field").style.display="";
                        document.getElementById("bundled_value_field").value="";
                        break;
                }
        }
}
/** Returns the count of the selected checkboxes that named as <checkboxName> */
function selectedCheckBoxCount(checkboxName){
	var count = 0;
  	if(document.all[checkboxName]!=null){
    	/* one row only */
    	if(document.all[checkboxName].value!=null && document.all[checkboxName].checked==true){
      		count=1;
    	}
    	else{
      		for (var i=0;i<document.all[checkboxName].length;i++){
        		if(document.all[checkboxName][i].checked==true){
            		count++;
               	}
          	}
      	}
    }
	return count;
}
/*************************************************************************/
/** Functions Written For CSC */
/************************************************************************* */

function checkQuantity(qty,flag) {
        var ret = true;
        for(var i=0;i<document.main.length;i++){
        var e = document.main.elements[i];
        if(e.type=="text" && e.name.indexOf("quantity") !=-1 && e.value > qty && productIsChecked(e.name,flag)){
                        e.focus();
                alert('Maximum Quantity Allowed: '+6);
                ret = false;
                break;
        }
        }
        return ret;
}

function productIsChecked(fld,flg){
   if(flg=='false')
     return true;
   var id = fld.substr(8);
   if(document.main.product_id!=null){
       /* one row only */
       if(document.main.product_id.value!=null && document.main.product_id.checked==true
                    && document.main.product_id.value==id)
         return true;
       else{
         for (var i=0;i<document.main.product_id.length;i++){

           if(document.main.product_id[i].checked==true && document.main.product_id[i].value == id){

             return true;
           }
         }
       }
     }
   return false;
}

function Constant_onchange(Attribute,Constant,Computed,SpanSelectName,SpanTextName,isList,ConstantSelect){
        if (Attribute == "Constant.."){
                if(isList){
                        document.getElementById(SpanSelectName).style.visibility="visible";
                        document.getElementById(SpanSelectName).style.display="";
                        document.getElementById(SpanTextName).style.visibility="hidden";
                        document.getElementById(SpanTextName).style.display="none";
                        ConstantSelect.disabled = false;
                        ConstantSelect.value = "";
                }
                else{
                        Constant.disabled = false;
                        Constant.value = "";
                }
        Computed.style.visibility="hidden";
        Computed.disabled = true;
        Computed.style.cursor="";
        }
        else{
                if(isList){
                        document.getElementById(SpanTextName).style.visibility="visible";
                        document.getElementById(SpanTextName).style.display="";
                        document.getElementById(SpanSelectName).style.visibility="hidden";
                        document.getElementById(SpanSelectName).style.display="none";
                }
                if (Attribute == "Computed.."){
                        Constant.disabled = false;
                Constant.value = "";
                Computed.style.visibility="visible";
                Computed.style.cursor="hand";
                Computed.disabled = false;
                }
                else{
                        Constant.disabled = true;
                        Constant.value = "";
                Computed.style.visibility="hidden";
                Computed.disabled = true;
                }
        }
}

function addProductToCart(action_name,param){
        document.main.action.value = action_name;
        document.main.product_id.value = param;
        document.main.submit();
}

/******************* CATEGORY TREE VIEW METHODS ********************************************/
/**
Indicates whether cookie <CatalogTaxonomy> is changed.
If so then the tree is expanded according to the default tree level expanded, defined in the ini file.
The value of cookie <TreeView>  is no relevant, because it stands for the previous catalog/taxonomy.
*/
function changedCookieCatalogTaxonomy(value)
{	
	setCookie('isCatalogTaxonomyChanged',value);	
}
function isCookieCatalogTaxonomyChanged()
{
	getCookie('isCatalogTaxonomyChanged');
}
/**
Sets the current catalog name to the prefix of cookie <CatalogTaxonomy> value .
 */
function setCookieCatalog(catalogValue)
{
		if(catalogValue!=null && catalogValue!=''){//if no <catalogValue> do nothing
			getCookie('CatalogTaxonomy');
			if(cookie_value!=null && cookie_value!=''){
				var offset = cookie_value.indexOf(':*?');
				if(offset!=-1){
					var currCatalog = cookie_value.substring(0,offset);
					if(currCatalog!=catalogValue){//sets <catalogValue> only if it's different then the old one
						removeAllCookieTreeViewState();//The value of cookie <TreeView>  is no relevant, because it stands for the previous catalog.
						var currTax = cookie_value.substring(offset+3,cookie_value.length);
						var allVal = catalogValue+':*?'+currTax;//create the value of <CatalogTaxonomy>
						setCookie('CatalogTaxonomy', allVal);
						changedCookieCatalogTaxonomy('true');//indicates on new catalog name 
					}	
				}
			}
			else{//<CatalogTaxonomy> was not yet defined.
				setCookie('CatalogTaxonomy', catalogValue+':*?');//sets the <catalogValue> and the delimeter
				changedCookieCatalogTaxonomy('true');//indicates on new catalog name 
			}
		}
}
/**
Sets the current taxonomy name to the prefix of cookie <CatalogTaxonomy> value .
 */
function setCookieTaxonomy(taxonomyValue)
{
		if(taxonomyValue!=null && taxonomyValue!=''){//if no <catalogValue> do nothing
			getCookie('CatalogTaxonomy');
			if(cookie_value!=null && cookie_value!=''){
				var offset = cookie_value.indexOf(':*?');
				if(offset!=-1){
					var catVal = cookie_value.substring(0,offset);
					if(catVal!=''){//taxonomy value wont be set before catalog value.
						var currTax = cookie_value.substring(offset+3,cookie_value.length);
						if(currTax!=taxonomyValue){//sets <taxonomyValue> only if it's different then the old one	
							removeAllCookieTreeViewState();//The value of cookie <TreeView>  is no relevant, because it stands for the previous taxonomy.				
							var allVal = catVal+':*?'+taxonomyValue//create the value of <CatalogTaxonomy>
							setCookie('CatalogTaxonomy', allVal);		
							changedCookieCatalogTaxonomy('true');//indicates on new catalog name				
						}
					}	
				}
			}
		}
}
/**
Gets the current catalog name to the prefix of cookie <CatalogTaxonomy> value .
 */
function getCookieCatalog()
{
        getCookie('CatalogTaxonomy');

		if(cookie_value!=null && cookie_value!=''){
			var offset = cookie_value.indexOf(':*?');
			if(offset!=-1){
				cookie_value = cookie_value.substring(0,offset);
			}
		}
}
/**
Gets the current taxonomy name to the prefix of cookie <CatalogTaxonomy> value .
 */
function getCookieTaxonomy()
{
        getCookie('CatalogTaxonomy');

		if(cookie_value!=null && cookie_value!=''){
			var offset = cookie_value.indexOf(':*?');

			if(offset!=-1){
				cookie_value = cookie_value.substring(offset+3,cookie_value.length);

			}
		}
}
/*****************************************************************/
/**
Used for tree view to recall the state of the categories, expanded or collapsed.
<TreeView> cookie contains the internal ids of the expanded categories, hence when
new value is added it must concatenated it to the current cookie value.
 */
function setCookieTreeViewState(value)
{
		getCookieTreeViewState();
		if(cookie_value==null){
			setCookie('TreeView', value);
		}
		else{	
			cookie_value += value;
			setCookie('TreeView', cookie_value);
		}
}
function removeCookieTreeViewState(value)
{
		getCookieTreeViewState();

		if(cookie_value != null && cookie_value != ''){
			var offset = cookie_value.indexOf(value);

			if(offset != -1){
				sub1 = cookie_value.substring(0,offset);
				offset += value.length;								
				sub2 = cookie_value.substring(offset,cookie_value.length);
				setCookie('TreeView', sub1+sub2);
			}
		}
}
function isCookieTreeViewStateExist(value)
{
		getCookieTreeViewState();

		if(cookie_value == null || cookie_value == '')
			return false;
		else
		{
			var offset = cookie_value.indexOf(value);
			return (offset != -1);
		}
}
function removeAllCookieTreeViewState()
{
		setCookie('TreeView', '');
}
function getCookieTreeViewState()
{
        getCookie('TreeView');
}

// BM -- TOGS TABS VIUSAL STATE **************************************************************************

function togTabState(element) {
	while (element.tagName.toUpperCase() != 'TD' && element != null)
	element = document.all ? element.parentElement : element.parentNode;
	
	if (element.currentStyle.color == "#0b6fa5") {
		element.style.color = "#df0029";
	}
	else {
		element.style.color = "#0b6fa5";
	}
	
}


// BM -- TOG TREE NODE **************************************************************************

function treeNodeTog(nodePass,levelCheck,internalID) {

nodePass = document.getElementById(nodePass)

	if (nodePass.className == "treeNodeClosed") {
		nodePass.className = "treeNodeOpen";
		setCookieTreeViewState(internalID+'$');
	} 
	else {
		nodePass.className = "treeNodeClosed";
		removeCookieTreeViewState(internalID+'$');
	}
	
	if (levelCheck.className == "TreeArrowDown") {
		levelCheck.className = "TreeArrowRight"
	}
	
	else {
		levelCheck.className = "TreeArrowDown"
	}
}

// BM -- EXPAND-COLLAPSE FUNCTIONS **************************************************************************

// COLLAPSE IS INDEPENDENT OF OPEN STATE 
// IT COLLAPSES DOWN TO 1

function treeStateAll(passNodeClass,passWidgetClass,internalIDsConcatenated) {
	var findDivs = document.all.tags("div");
	var findSpans = document.all.tags("span");
	
	// OPEN UP DIVS 

	for (var i = 0; i < findDivs.length; i++) {
	
		// BUILDS AN ARRAY OF DIVS THAT START WITH tree
		// FLIP STATE BASED ON PASS VALUE

		if (findDivs[i].id.substring(0,8) == "treeNode")
		{
			var idString = document.getElementById(findDivs[i].id);
			idString.className = passNodeClass;
		}
	}
	
	// TOG WIDGET STATE
	
	for (var i = 0; i < findSpans.length; i++) {
	
		// BUILDS AN ARRAY OF SPANS THAT START WITH treeWidget
		// FLIP STATE BASED ON PASS VALUE
		
		if (findSpans[i].id.substring(0,10) == "treeWidget")
		{
			var idString = document.getElementById(findSpans[i].id);
			idString.className = passWidgetClass;
		}
	}		

	removeAllCookieTreeViewState()
	setCookieTreeViewState(internalIDsConcatenated)
}
