
function Init_List(my_id){

		var arr=document.getElementsByTagName('SELECT')

		for (var i=0;i<arr.length;i++)
		{
		var str = arr[i].id;		
		var str1 = str.indexOf("in_list");	
			if (str1 != -1)
			{
				
				var guid =str.replace("_in_list","")

				var out_list_id=str.replace("_in_","_out_")
				
				var tb_id;
				if(my_id != '' && my_id !=' ')	
					tb_id =my_id+"_"+"SubSubjects_tb_"+guid
				else
					tb_id ="SubSubjects_tb_"+guid

				var hidden_tb=document.getElementById(tb_id);

				if (hidden_tb !=null)
				{
					var out_list=document.getElementById(out_list_id)
					
					//alert(hidden_tb.value)
					
					for (var n=0;n<out_list.options.length;n++)
						if (hidden_tb.value.indexOf(";" + out_list.options[n].value +";")>=0)
						{
							
							out_list.options[n].selected=true	
						}
						Remove_From_List(guid)
				}					
			}
		}
		
}

function Save_Selected_From_List(my_id){

		var arr=document.getElementsByTagName('SELECT')
		for (var i=0;i<arr.length;i++)
		{
		var str = arr[i].id;		
		var str1 = str.indexOf("in_list");	
			if (str1 != -1)
			{	
				var guid =str.replace("_in_list","")
				var out_list_id=str.replace("_in_","_out_")
				var in_list=arr[i]				
				if(my_id != '' && my_id !=' ')	
					tb_id =my_id+"_"+"SubSubjects_tb_"+guid
				else
					tb_id ="SubSubjects_tb_"+guid

				var hidden_tb=document.getElementById(tb_id);

				if (hidden_tb !=null)
				{
					var out_list=document.getElementById(out_list_id)
					
					hidden_tb.value=";"
					//alert(hidden_tb.value)
					//alert(out_list.id)
					//alert(in_list.id +' '+in_list.options.length)
					for (var n=0;n<in_list.options.length;n++)	
					  hidden_tb.value += in_list.options[n].value +";";
//alert(hidden_tb.value)
					
				}					
			}
		}
		
}



function MouseOver(oFont, oImg, IsOver, sImgName)
{	
	if(oImg==null)
	{
		var oTR = oFont.parentElement.parentElement;
		oImg = oTR.children[2].firstChild;
	}
	if(oFont==null)
	{
		var oTR = oImg.parentElement.parentElement;
		oFont = oTR.children[2].firstChild;
	}
		
	/*alert(oFont.tagName);
	alert(oImg.tagName);*/
	
	if(IsOver)
	{
		oFont.color="#ffcc64";
		oImg.src="/IDF/Rsrc/common/" + sImgName + "_arrow_over.gif";
	}
	else
	{
		oFont.color="#00336B";
		oImg.src="/IDF/Rsrc/common/" + sImgName + "_arrow.gif";
	}
}	



function Put_Item(to_place, objItemsSelected, objItems)
{
	try
	{
		if (Check_MoreThenOne_Selected(objItemsSelected)==false)
		{
			if (objItemsSelected.selectedIndex!=-1)
				if (to_place!=-1)
				{
					elementp= objItemsSelected.item(objItemsSelected.selectedIndex);
					objItemsSelected.remove(objItemsSelected.selectedIndex);
					
					try
					{
					     var elOptOld =objItemsSelected.options[to_place-1]
					     objItemsSelected.add(elementp,elOptOld);
					}
					catch(e)
					{
					     objItemsSelected.add(elementp,to_place);
					}
					
					objItemsSelected.selectedIndex=to_place;
					/*
					for(i=objItemsSelected.options.length;i>=0;i--)
					{
						for(ii=objItems.options.length-1;ii>=0;ii--)
						{
							elementp= objItems.item(objItems.options(ii));
							objItems.remove(objItems.selectedIndex);
							objItems.add(elementp,i);
							objItems.selectedIndex=i;
						}
					}*/
				}
			else  alert("Please choose only one record");//alert("! אנא סמן רשומה אחת בלבד");
		}
		else
			alert("Please choose only one record");	//alert("אנא סמן רק רשומה אחת");
	}
	catch(e)
	{
		alert('Put_Item Error ' + e.message + ' occurred.'); 
	}

}

function Remove_From_List(sClientID)
{	
	try
	{

		var objItemsSelected = document.getElementById(sClientID+"_in_list");


		var objItemsCollection = document.getElementById(sClientID + "_out_list");
		//var arrAllData = eval("ALLDATA" + sClientID);
		//var objItems = eval("objItems" + sClientID);
		//var objSearch = eval("objSearch" + sClientID);

		//objSearch.value='';
		//count_options_list=objItems.options.length;
		count_options=objItemsCollection.options.length;

		for(i=count_options-1;i>=0;i--)
		{
			if (objItemsCollection.options[i].selected)
			{ 
				
				/*for(ii=count_options_list-1;ii>=0;ii--)
				{
					if(objItemsCollection.options(i).value==objItems.options(ii).value)
					{	
						objItems.options(ii).selected=true;
					}
				}
				
				for(j=0;j<arrAllData.length;j++)
				{
					if (arrAllData[j].data_id==objItemsCollection.options(i).value)
					{
						arrAllData[j].selected=1;
						break;
					}	
				}*/
				elementp=objItemsCollection.item(i);
				elementp.selected=false;
				objItemsCollection.remove(i);
				try
				{
				 var elOptOld =objItemsSelected.options[0]
				objItemsSelected.add(elementp,elOptOld); // standards compliant; doesn't work in IE
                }
				catch(e)
				{
				objItemsSelected.add(elementp,0); //IE only
				}
				
				/*if(IsMailingRequests && sClientID == 'slbTypes')
					SelectSubjectsByTypes();*/
			}
		}
	
	}
	catch(e)
	{
		alert('Remove_From_List Error ' + e.message + ' occurred.'); 
	}
}

function Add_To_List(sClientID)
{
try
	{
		var objItemsSelected = document.getElementById(sClientID + "_in_list");
		var objItemsCollection = document.getElementById(sClientID + "_out_list");
		//var arrAllData = eval("ALLDATA" + sClientID);
		//var objItems = eval("objItems" + sClientID);
		
		//count_options_list=objItems.options.length;
		count_options=objItemsSelected.options.length;
			
		for(i=count_options-1;i>=0;i--)
		{
			if (objItemsSelected.options[i].selected)
			{ 
				/*for(ii=count_options_list-1;ii>=0;ii--)
				{
					if(objItemsSelected.options(i).value==objItems.options(ii).value)
					objItems.options(ii).selected=false;
				}

				for(j=0;j<arrAllData.length;j++)
				{
					if (arrAllData[j].data_id==objItemsSelected.options(i).value)
					{	
						arrAllData[j].selected=0;					
						break;
					}
				}*/
			elementp= objItemsSelected.item(i);
			elementp.selected=false;
			objItemsSelected.remove(i);
			try
			{
			var elOptOld =objItemsCollection.options[objItemsCollection.options.length]
			objItemsCollection.add(elementp,elOptOld);
			}
			catch(e)
			{
			objItemsCollection.add(elementp,objItemsCollection.options.length);
			}
			/*if(IsMailingRequests && sClientID == 'slbTypes')
				SelectSubjectsByTypes();*/
			}
		}

	}
	catch(e)
	{
		alert('Add_To_List Error ' + e.message + ' occurred.'); 
	}
}

function Check_MoreThenOne_Selected(objItemsSelected)
{
	try
	{
		MoreTheOne=0;
		for(i=0;i<objItemsSelected.options.length;i++)
			{
				if (objItemsSelected.options[i].selected)
				{
					MoreTheOne=MoreTheOne+1;
					if (MoreTheOne==2) 
						break;
				}
			}
		if (MoreTheOne==2) 
			return true;
		else
			return false;
	}
	catch(e)
	{
		alert('Check_MoreThenOne_Selected Error ' + e.message + ' occurred.'); 
		return false;
	}
}

function PutFocusToListItem(objSearch, objItemsCollection)
{
	try
	{
		var sCaption='';
		for(i=0;i<objItemsCollection.options.length;i++)
		{
			sCaption = objItemsCollection.options[i].text;
			objItemsCollection.options[i].selected = (sCaption.indexOf(objSearch.value)==0);
		}
	}
	catch(e)
	{
		alert('PutFocusToListItem Error ' + e.message + ' occurred.'); 
	}
}

function ConfirmDelete(str)
{
	return confirm(str);
}

function GetFocus()
{}

function SelectSubjectsByTypes()
{
	try
	{	
		var oListAllItems = document.getElementsByName("slbTypes:lbAllItems")(0);
		var indx=0;
		var sTypes='';
		
		if(oListAllItems.length>0)
			for(indx=0; indx<oListAllItems.length ; indx++)
				if(oListAllItems.options[indx].selected)
					sTypes += ' or (TYPE_ID=' + oListAllItems.options[indx].value +')';
		
		if(sTypes!='')
		{
			sTypes = sTypes.substr(4);	
			sTypes = '/*/*[' + sTypes + ']';
		}
		else
		{
			sTypes = '/*/*[TYPE_ID=none]';
		}
		
		//alert(sTypes);
		
		var sXML = document.all("TypesXML").innerHTML;			
		var objXML = new ActiveXObject("Microsoft.XMLDOM");
		objXML.loadXML(sXML);
		
		var oXMLNodes = objXML.selectNodes(sTypes);
		
		//alert(oXMLNodes.length);
		//alert(oXMLNodes(0).xml)
		
		UpdateList(oXMLNodes);
		
	} 
	catch (e) 
	{ 
		alert('SelectSubjectsByTypes Error ' + e.message + ' occurred.'); 
	} 
}

function UpdateList(oXMLNodes)
{
	try
	{
		var indx=0;
		var oListCollection = document.getElementsByName("slbSubject:lbItemsCollection")(0);
		var oListSelected = document.getElementsByName("slbSubject:lbItemsSelected")(0);
		var oListAllItems = document.getElementsByName("slbSubject:lbAllItems")(0);

		if(oListAllItems.length>0)
			for(indx=(oListAllItems.length-1);indx>=0;indx--)
				oListAllItems.options[indx].selected=false;		
		if(oListCollection.length>0)
			for(indx=oListCollection.length-1;indx>=0;indx--)
				oListCollection.remove[indx];
		if(oListSelected.length>0)
			for(indx=oListSelected.length-1;indx>=0;indx--)
				oListSelected.remove[indx];

		strMatchValues=';;';

		for(indx=0; indx<oXMLNodes.length ; indx++)
		{
			oNode = oXMLNodes(indx);
			SelValue = oNode.selectSingleNode("CODE_ID").text;
			strMatchValues += SelValue + ';';
		}
		var XX=0;
		var YY=0;

		for(indx=0;indx<oListAllItems.length;indx++)
		{
			opt = new Option(oListAllItems.options[indx].text, oListAllItems.options[indx].value);
			
			sVal = ';' + oListAllItems.options[indx].value + ';';
			if(strMatchValues.indexOf(sVal)>0)
			{
				XX++;				
				oListSelected.add(opt, XX);	
				oListAllItems.options[indx].selected=true;
			}
			else
			{
				YY++;				
				oListCollection.add(opt, YY);	
				oListAllItems.options[indx].selected=false;		
			}
		}
	} 
	catch (e) 
	{ 
		alert('UpdateAdvancedSearchList Error ' + e.message + ' occurred.'); 
	} 
}