
function getSelectedRadioValues (control)
{
	var val = "";
	for ( i = 0 ; i < control.length ; i ++ )
	{
		if ( control[i].checked)
		{
			if ( val != "")  val += ",";
			val +=control[i].value;
		}
	}
	return val;
}

function getSelectedValues (control)
{
	var val = "";
	for ( i = 0 ; i < control.length ; i ++ )
	{
		if ( control.options[i].selected)
		{
			if ( val != "")  val += ",";
			val +=control.options[i].value;
		}
	}
	return val;
}

function getSelectControlValues (control)
{
	var val = "";
	for ( i = 0 ; i < control.length ; i ++ )
	{
		if ( val != "")  val += ",";
		val +=control.options[i].value;
	}
	return val;
}

function setSelectItemSelected (control,val)
{
	for ( i = 0 ; i < control.length ; i ++ )
		if (control.options[i].value == val) control.selectedIndex=i;
}


function assign (cv,ct,v,t)
{
	cv.value =v.replace(/\+/g," ");
	ct.value = t.replace(/\+/g," ");
	hideDiv('slide1');
}

function assignFile (c,v)
{
	c.value =v.replace(/\+/g," ");
	hideDiv('slide1');
}

function clearWSelect (c,dc)
{
	c.value="";
	dc.value="";
}
function clearFile (c)
{
	c.value="";
}

function selectPopup(ffid,fname,qs)
{
	serveGetRequest ("selectPopup.php","ffid="+ffid+"&fname="+fname+"&"+qs,"slide1");
	showDiv('slide1');
}

function selectFile(ffid,fname)
{
	serveGetRequest ("folderBrowser.php","ffid="+ffid+"&fname="+fname,"slide1");
	showDiv('slide1');
}

function mselectPopup(ffid,fname,divname,qs)
{
	serveGetRequest ("mselectPopup.php","ffid="+ffid+"&fname="+fname+"&"+qs,"slide1");
	showDiv('slide1');
}

function Popup(script)
{
	serveGetRequest (script,"","slide1");
	showDiv('slide1');
}

function PopupPost(script,oform)
{
	servePostRequest (script,oform,"slide1");
	showDiv('slide1');
}

//**********************************************************
function SelectElement (id,value)
{
	this.id = id;
	this.value = value;

}
var insertPosition;
function searchListIDs (list,v,_from,_to)
{
	for ( i = 0 ; i < 10; i++ )
	{
		
		if ( _to == -1) 
		{
			insertPosition = 0;
			return -1;
		}
		else if ( _from == _to )
		{
			if (list.options[_from].value == v ) return _from;
			else 
			{
				if ( list.options[_from].value > v ) insertPosition = _from;
				else insertPosition = _from+1;
				return -1;
			}
		} 
		else if ( list.options[_from].value < v && list.options[_to].value > v ) 
		{
			var mid = Math.round((_to-_from)/2) + _from;
			if ( list.options[mid].value > v ) 
			{
				if ( _to == mid ) _to = mid-1;
				else _to = mid;
			}
			if ( list.options[mid].value < v ) 
			{
				if ( _from == mid ) _from=mid+1;
				else _from = mid;
			}
			if ( list.options[mid].value == v ) return mid;
		}
		else if ( list.options[_from].value == v ) return _from;
		else if ( list.options[_to].value == v ) return _to;
		else 
		{
			if ( list.options[_from].value > v ) insertPosition = _from;
			else if ( list.options[_to].value < v ) insertPosition = _to+1;
			return -1;
		}
	}
}
function searchListText (list,t,_from,_to)
{
	for ( i = 0 ; i < 10; i++ )
	{
		
		if ( _to == -1) 
		{
			insertPosition = 0;
			return -1;
		}
		else if ( _from == _to )
		{
			if (list.options[_from].text == t ) return _from;
			else 
			{
				if ( list.options[_from].text > t ) insertPosition = _from;
				else insertPosition = _from+1;
				return -1;
			}
		} 
		else if ( list.options[_from].text < t && list.options[_to].text > t ) 
		{
			var mid = Math.round((_to-_from)/2) + _from;
			if ( list.options[mid].text > t ) 
			{
				if ( _to == mid ) _to = mid-1;
				else _to = mid;
			}
			if ( list.options[mid].text < t ) 
			{
				if ( _from == mid ) _from=mid+1;
				else _from = mid;
			}
			if ( list.options[mid].text == t ) return mid;
		}
		else if ( list.options[_from].text == t ) return _from;
		else if ( list.options[_to].text == t ) return _to;
		else 
		{
			if ( list.options[_from].text > t ) insertPosition = _from;
			else if ( list.options[_to].text < t ) insertPosition = _to+1;
			return -1;
		}
	}
}

function searchListNormal (list,v)
{
	for ( i = 0 ;i < list.options.length ; i ++)
		if ( list.options[i].value == v ) return i;
	return -1;
}

function addToMSelectWithoutSort (v,t,formgenlist,popuplist)
{
	var op1 = new Option (t,v);
	var op2 = new Option (t,v);
	var index = searchListNormal(formgenlist,v);
	if ( index == -1)	
	{
		formgenlist.options.add(op1);
		formgenlist.selectedIndex = formgenlist.options.length-1;
		popuplist.options.add(op2);
	}
	return;
}

function addToMSelect (v,t,formgenlist,popuplist)
{
	var op1 = new Option (t,v);
	var op2 = new Option (t,v);
	var index = searchListText(formgenlist,t,0,formgenlist.options.length-1);
	if ( index == -1)	
	{
		formgenlist.options.add(op1,insertPosition);
		formgenlist.selectedIndex = insertPosition;
		if (searchListText(popuplist,t,0,popuplist.options.length-1) == -1)
			popuplist.options.add(op2,insertPosition);
	}
	return;
}

function addToMSelectFromAnoterForm (v,t,formgenlist)
{
	var op1 = new Option (t,v);
	var op2 = new Option (t,v);
	var index = searchListText(formgenlist,t,0,formgenlist.options.length-1);
	if ( index == -1)	
	{
		formgenlist.options.add(op1,insertPosition);
		formgenlist.selectedIndex = insertPosition;
	}
	return;
}

function addToMSelectFromAnoterFormWithoutSort (v,t,formgenlist)
{
	var op1 = new Option (t,v);
	var op2 = new Option (t,v);
	var index = searchListNormal(formgenlist,v);
	if ( index == -1)	
	{
		formgenlist.options.add(op1);
		formgenlist.selectedIndex = formgenlist.options.length-1;
	}
	return;
}

function updateMSelectFromAnoterForm (v,t,formgenlist)
{
	var op1 = new Option (t,v);
	var op2 = new Option (t,v);
	clearMSelectFirstSelection(formgenlist);
	var index = searchListText(formgenlist,t,0,formgenlist.options.length-1);
	if ( index == -1)	
	{
		formgenlist.options.add(op1,insertPosition);
		formgenlist.selectedIndex = insertPosition;
	}
	return;
}

function updateMSelectFromAnoterFormWithoutSort (v,t,formgenlist)
{
	var op1 = new Option (t,v);
	var op2 = new Option (t,v);
	var index = searchListNormal(formgenlist,v);
	if ( index != -1)	
	{
		formgenlist.options[index].value=v;
		formgenlist.options[index].text=t;
	}
	return;
}

function clearMSelect (formgenlist)
{
  var i;
  for (i = formgenlist.length - 1; i>=0; i--) {
    if (formgenlist.options[i].selected) {
      formgenlist.remove(i);
    }
  }
}
function clearMSelectFirstSelection (formgenlist)
{
  var i;
  for (i = formgenlist.length - 1; i>=0; i--) {
    if (formgenlist.options[i].selected) {
      formgenlist.remove(i);
	return
    }
  }
}

function moveElementUp (l)
{
	if ( l.length > 1 && l.selectedIndex!= 0 )
	{
		index = l.selectedIndex;
		swap_value = l.options[index-1].value;
		swap_text = l.options[index-1].text;
		l.options[index-1].value=l.options[index].value;
		l.options[index-1].text=l.options[index].text;
		l.options[index].value=swap_value;
		l.options[index].text=swap_text;
		l.selectedIndex --;
	}
}

function moveElementDown (l)
{
	if ( l.length > 1 && l.selectedIndex < l.length-1 )
	{
		index = l.selectedIndex;
		swap_value = l.options[index+1].value;
		swap_text = l.options[index+1].text;
		l.options[index+1].value=l.options[index].value;
		l.options[index+1].text=l.options[index].text;
		l.options[index].value=swap_value;
		l.options[index].text=swap_text;
		l.selectedIndex ++;
	}
}

function disableEnterKey(e)
{
     var key;

     if(window.event)
          key = window.event.keyCode;     //IE
     else
          key = e.which;     //firefox

     if(key == 13)
          return false;
     else
          return true;
}

function updateSelectDevelFormFieldList (fieldname,vfname,tfname,oForm)
{
		formBody = "";
		if (oForm != "" ) formBody=getFormRequestBody (oForm);
		formBody += "&formlistname="+fieldname+"&targetvfname="+vfname+"&targettfname="+tfname+"&target=devel/update_devel_select_lists.php";
		syncServePostStreamAndExecJS ("rindexm.php",formBody);
}


function updateSelectDevelMenuList ()
{
		formBody = "menu_cat="+document.menu_cat_form.menu_cat.options[document.menu_cat_form.menu_cat.selectedIndex].value+"&target=devel/update_menu_select_list.php";
		syncServePostStreamAndExecJS ("rindexm.php",formBody);
}

function updateFormLinksList ()
{
		formBody = "fid="+document.cwe_forms.fid.options[document.cwe_forms.fid.selectedIndex].value+"&target=devel/update_form_links_list.php";
		syncServePostStreamAndExecJS ("rindexm.php",formBody);
}

function addToSelect (v,t,formgenlist)
{
	var op1 = new Option (t,v);
	formgenlist.options.add(op1);
}


