﻿/*
	
	 created By Neeraj Ahuja
	
	
*/

function multi_movebox(frombox,tobox,maxsels,whichBox,type)
{
 
 
  var to_box = document.getElementById(tobox);
  var from_box = document.getElementById(frombox);
  
   
  var totalsels=to_box.options.length;
 
  for(var i=0; i<from_box.options.length; i++)
  {
    if(from_box.options[i].selected && from_box.options[i].value!="" && (totalsels<maxsels || maxsels==-1))
    {
      totalsels++;
      multi_insertbox(to_box,from_box.options[i].value,from_box.options[i].text);
      from_box.options[i].value="";
      from_box.options[i].selected = false;
    }
  }
  multi_deletespaces(from_box);
  if(type == 0)
  {
     save1(whichBox);
  }
  if(type == 1)
  {
     save(whichBox);
  }
  if(type == 2)
  {
     save3(whichBox);
  }
 
  
}
function save(saveBox)
  {
 
  //          var roleArray = new Array();
   
  document.aspnetForm.newlist2.value=""
  newvals = ""
      if(document.aspnetForm.elements[saveBox])
      {
        for(var i = 0; i < document.aspnetForm.elements[saveBox].length; i++)
        {

        var newval=document.aspnetForm.elements[saveBox].options[i].value;
        var newvals=newval+','+newvals
        document.aspnetForm.newlist2.value=newvals.slice(0,-1)
        
        }
       
      }
   }
function save1(saveBox)
  {
	
  
  document.aspnetForm.newlist3.value=""
  newvals = ""
 
      if(document.aspnetForm.elements[saveBox])
      {
		
        for(var i = 0; i < document.aspnetForm.elements[saveBox].length; i++)
        {

        var newval=document.aspnetForm.elements[saveBox].options[i].value;
        
        var newvals=newval+','+newvals
        document.aspnetForm.newlist3.value=newvals.slice(0,-1)
        
        }
      }
     
     
  }
function save3(saveBox)
  {

  //          var roleArray = new Array();
 
  document.aspnetForm.newAttrib.value=""
  newvals = ""
      if(document.aspnetForm.elements[saveBox])
      {
        for(var i = 0; i < document.aspnetForm.elements[saveBox].length; i++)
        {

        var newval=document.aspnetForm.elements[saveBox].options[i].value;	
        var newvals=newval+','+newvals
        document.aspnetForm.newAttrib.value=newvals.slice(0,-1)
       
        }
      
      }
      
      
  }

function multi_deletespaces(box)
{
  var displace=0;
  for (var i=0; i<box.options.length; i++)
  {
    if (box.options[i].value=="")
      displace++;
    else
      if (displace!=0)
      {
        box.options[i-displace].value=box.options[i].value;
        box.options[i-displace].text=box.options[i].text;
      }
  }
  i=box.options.length;
  while (displace>0)
  {
    i--;
    box.options[i]=null;
    displace--;
  }
}

function multi_insertbox(box,value,text)
{
  
  var pos=box.options.length;
  var option=new Option(text,value);
  box.options[pos]=option;
  Array

  var i=0;
  while(pos>0)
  {
    i++;
    if (text>box.options[pos-1].text)
      break;
    box.options[pos].value=box.options[pos-1].value;
    box.options[pos].text=box.options[pos-1].text;
    pos--;
  }

  box.options[pos].value=value;
  box.options[pos].text=text;
  document.getElementById("hdnText").value +=text+",";     
   document.getElementById("hdnValue").value +=value+"";
  // alert(document.getElementById("hdnText").value);
   
}



function multi_setsave(frombox,tobox)
{
  var i;
  for (i=0; i<frombox.options.length; i++)
    frombox.options[i].selected=false;
  for (i=0; i<tobox.options.length; i++)
    tobox.options[i].selected=true;
}

function multi_boxtransfer(frombox,tobox,id)
{
  for (var i=0;i<frombox.options.length;i++)
    if (frombox.options[i].value==id)
    {
      multi_insertbox(tobox,frombox.options[i].value,frombox.options[i].text);
      frombox.options[i].value="";
    }
  multi_deletespaces(frombox);
}

function multi_boxtransferlist(frombox,tobox,str)
{
  var start=0;
  var end;

  while (start<str.length)
  {
    for (end=start+1;end<=str.length;end++)
      if (str.substring(end-1,end)==',')
        break;
    multi_boxtransfer(frombox,tobox,str.substring(start,end-1));
    start=end;
  }
}

function multi_findobject(form,name)
{
  for(var i=0;i<form.elements.length;i++)
    if (form.elements[i].name==name)
      return form.elements[i];
  return null;
}


