var win=null;
function NewWindow(mypage,isScroll,myname,w,h,pos,infocus){
if(pos=="random"){myleft=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;mytop=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){myleft=(screen.width)?(screen.width-w)/2:100;mytop=(screen.height)?(screen.height-h-28)/2:100;}
if(pos=="centertop"){myleft=(screen.width)?(screen.width-w)/2:100;mytop=(screen.height)?(screen.height-h-28)/4:100;}
if(pos=="top"){myleft=(screen.width)?(screen.width-w-10)/2:100;mytop=0;}
settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=" + isScroll + ",location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no";
win=window.open(mypage,myname,settings);
if(win != null) win.focus();

}

/* Functions that swaps images. */
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

/* Functions that handle preload. */
function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

/* Tool Bar Specific Functions */
function ToolBar_swapImage() { 
  var i,j=0,x,a=ToolBar_swapImage.arguments; document.ToolBar_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=ToolBar_findObj(a[i]))!=null){document.ToolBar_sr[j++]=x; if(!x.firstChild.oSrc) x.firstChild.oSrc=x.firstChild.src; x.firstChild.src=a[i+2];}
}
function ToolBar_swapImgRestore() { 
  var i,x,a=document.ToolBar_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.firstChild.oSrc;i++) x.firstChild.src=x.firstChild.oSrc;
}
function ToolBar_preloadImages() { 
 var d=document; if(d.images){ if(!d.ToolBar_p) d.ToolBar_p=new Array();
   var i,j=d.ToolBar_p.length,a=ToolBar_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.ToolBar_p[j]=new Image; d.ToolBar_p[j++].src=a[i];}}
}
function ToolBar_findObj(n, d) { 
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=ToolBar_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}


function addField (form, fieldType, fieldName, fieldValue) {
	
  if (document.getElementById) {
    var input = document.createElement('INPUT');
      if (document.all) { // what follows should work 
                          // with NN6 but doesn't in M14
        input.type = fieldType;
        input.name = fieldName;
        input.value = fieldValue;
      }
      else if (document.getElementById) { // so here is the
                                          // NN6 workaround
        input.setAttribute('type', fieldType);
        input.setAttribute('name', fieldName);
        input.setAttribute('value', fieldValue);
      }
    form.appendChild(input);
  }
}
function getField (form, fieldName) {
  if (!document.all)
    return form[fieldName];
  else  // IE has a bug not adding dynamically created field 
        // as named properties so we loop through the elements array 
    for (var e = 0; e < form.elements.length; e++)
      if (form.elements[e].name == fieldName)
        return form.elements[e];
  return null;
}        
function removeField (form, fieldName) {
  var field = getField (form, fieldName);
  if (field && !field.length)
    field.parentNode.removeChild(field);
}
function toggleField (form, fieldName, value) {
  var field = getField (form, fieldName);
  if (field)
    removeField (form, fieldName);
  else
    addField (form, 'hidden', fieldName, value);
}


function SelectAll(){
	var list = document.Form1.listUsed;
	for(x = 0;x<(list.length);x++)
		{
			list.options[x].selected = true;
		}
	return true;
}
		

function moveSelected (select, down) {
  if (select.selectedIndex != -1) {
    if (down) {
      if (select.selectedIndex != select.options.length - 1)
        var i = select.selectedIndex + 1;
      else
        return;
    }
    else {
      if (select.selectedIndex != 0)
        var i = select.selectedIndex - 1;
      else
        return;
    }
    document.Form1.DataChanged.value='1';
    var swapOption = new Object();
    swapOption.text = select.options[select.selectedIndex].text;
    swapOption.value = select.options[select.selectedIndex].value;
    swapOption.selected = select.options[select.selectedIndex].selected;
    swapOption.defaultSelected = select.options
[select.selectedIndex].defaultSelected;
    var anIndex = select.selectedIndex;
    for (var property in swapOption)
      select.options[anIndex][property] = select.options[i][property];
    for (var property in swapOption)
      select.options[i][property] = swapOption[property];
  }
}

function Move(listSource, listDest, selectedOnly){
		for(x = 0;x<(listSource.length);x++)
		{
			if(listSource.options[x].selected || !selectedOnly)
			{
				with(listDest)
				{
					options[options.length] = new Option(listSource.options[x].text,listSource.options[x].value);
					document.Form1.DataChanged.value='1';
				}
				listSource.options[x] = null;
				x = -1;
			}
		}
	return true;
}
function ShowAlert(AlertText){
	if(AlertText != '') alert(AlertText);
}
function SetFocus(control){

	if(control != '')
	{
		var fld = getField(document.Form1, control);
		if(fld) fld.focus();
		
	}
}
function ReloadParent(reload, btn){

	if(reload == 'True') opener.__doPostBack(btn,'');
}
function CloseWin(close){
	if(close == "True") window.close();
}
function ShowCalendar(formname){
	var calendar_window=NewWindow('calendar.aspx?formname=' + formname,'no','calendar_window','202','175','centertop','front');
}
function LostFocus(thisCont){
	thisCont.style.backgroundColor="#ffffff";
}
function GotFocus(thisCont){
	thisCont.style.backgroundColor="#ADD8E6";
}