function SetJsFlag() {
	document.form1.IsJs.value=1;
}

function FocusFirst() {
	document.form1.UserName.focus();
}
/*


*/
function IsValInList(List, Val)
{
  var loop;
  for (loop=0; loop < List.options.length; loop++) {
    if (List.options[loop].value == Val) {
      return 1;
    }
  }
  return 0;
}
/*


*/
function IsListFull(List, FullSize)
{
   return (List.options.length >=FullSize ?1:0);
}
/*


*/
function MoveRight(ListSrc, ListDest, FullSize)
{
  var SrcOpt;
  //var ListSrc = document.form1.StateList;
  //var ListDest = document.form1.StateSel;
  var DestCt = ListDest.options.length;
  var loop;
  for (loop=0; loop < ListSrc.options.length; loop++) {
    SrcOpt=ListSrc.options[loop];
    if (SrcOpt.selected == true)
    {
      if (!IsValInList(ListDest, SrcOpt.value) && !IsListFull(ListDest,FullSize)) {
        ListDest.options[DestCt] = new Option(SrcOpt.text,SrcOpt.value);
        DestCt++;
      }
    }
  }
}
/*

*/
function Remove(ListDest)
{
  //var ListDest;
  //ListDest = document.form1.StateSel;
  var SelIdx = ListDest.selectedIndex;
  if (SelIdx >=0) {
     ListDest.options[SelIdx] = null;
  }
}

function SelectAll() {
  SelectAllInList(document.form1.elements['StateSel[]']);
  SelectAllInList(document.form1.elements['IndSel[]']);
}

function SelectAllInList(List)
{
  for (var i = 0; i < List.length;i++) {
    List.options[i].selected=true;
  }
}
/*--------------------------------------------------------------------
   v_match

--------------------------------------------------------------------*/
function ClearCounts() {
	document.getElementById('CountDirectMatch').innerHTML='';
	document.getElementById('CountSpecMatch').innerHTML='';
	document.getElementById('CountGenMatch').innerHTML='';
	document.getElementById('CountTotalMatch').innerHTML='';
}

function IsListsFull(fullSize) {
	StateList=document.form1.elements['StateSel[]'];
	IndList=document.form1.elements['IndSel[]'];
	var i;
	var IndCt, StateCt;
	for (i=0,IndCt=0;i < IndList.options.length;i++) {
		if (IndList.options[i].selected) {
			IndCt++;
		}
	}
	for (i=0,StateCt=0;i < StateList.options.length;i++) {
		if (StateList.options[i].selected) {
			StateCt++;
		}
	}
	msg='';
	if ( IndCt <= parseInt(fullSize)&&(IndCt>=1)&&(StateCt>=1) )
		return true;
	if (IndCt > parseInt(fullSize))
		msg = "Please select fewer than " + fullSize + " industries from the list";
	if (IndCt==0)
		msg = "Please select at least 1 industry from the list";
	if (StateCt==0)
		msg += "\nPlease select at least 1 state from the list";
	alert(msg);
	return false;
}

function StateListChanged(List) {
	ClearCounts();
	var StateCsv = GetListCsv(List);
	document.getElementById('STATE_LIST').innerHTML = StateCsv;
}

function IndustryListChanged(List) {
	ClearCounts();
	var IndCsv = GetListCsv(List);
	document.getElementById('INDUSTRY_LIST').innerHTML = IndCsv;
}

function GetListCsv(List) {
	var i,idx;
	var IndSel;
	var arr = new Array();

	for(i=0,idx=0;i < List.options.length;i++) {
		if (List.options[i].selected) {
			arr[idx++] = List.options[i].text;
		}
	}
	if (idx) {
		return WrapText(arr.join(', '), 15, '<br>');
	}
}

function WrapText(str, wrapWidth, wrapText) {
	// Kill carriage returns and split by newlines:
	var sections = String(str).replace(/\r/g,"").split("\n");
	var result = "";

	for (var i in sections) {
		var newLine = "";
		var words = sections[i].split(" ");
		for (var j=0; j<words.length; ++j) {
			var word = words[j];
			if ((newLine + word).length >= wrapWidth) {
				result += newLine.substr(0,newLine.length-1) + wrapText;
				newLine = word + " ";
			}
			else {
				newLine += word + " ";
			}
		}
		if (newLine != "") {
			// Final line may not be exactly wrapWidth chars long, so may 
			// not have been concatenated during final loop, if so add it now.
 			result += newLine + wrapText;
		}
	}
	return result;
}

function Test() {
	alert('hi');
}