// adds to the destination list

function addToDestList() {
	destList = window.document.forms[0].destList;
	srcList = window.document.forms[0].srcList; 
	var len = destList.length;
	for(var i = 0; i < srcList.length; i++) {
		if ((srcList.options[i] != null) && (srcList.options[i].selected)) {
			//Check if this value already exist in the destList or not
			//if not then add it otherwise do not add it.
			var found = false;
			var hostids = "";
			for(var count = 0; count < len; count++) {
				if (destList.options[count] != null) {
					if (srcList.options[i].text == destList.options[count].text) {
						found = true;
						break;
		      }
					hostids = hostids + destList.options[count].value + " ";
					//if(count < len-1)
   			}
			}
			if (found != true) {
				destList.options[len] = new Option(srcList.options[i].text, srcList.options[i].value); 
				hostids = hostids + destList.options[len].value;
				len++;
      }
    }
 	}
	window.document.forms[0].hostids.value = hostids;
}

// Deletes from the destination list.

function removeFromDestList() {
	var destList  = window.document.forms[0].destList;
	var len = destList.options.length;
	for(var i = (len-1); i >= 0; i--) {
		if ((destList.options[i] != null) && (destList.options[i].selected == true)) {
			destList.options[i] = null;
    }
  }
	var hostids = "";
	var len = destList.length;
	for(var count = 0; count < len; count++) {
		hostids = hostids + destList.options[count].value;
		if(count < len-1) hostids = hostids + " ";
	}
	window.document.forms[0].hostids.value = hostids;
}

function maxDay(zmon, year) {

	var mon = zmon+1;

	// Jan, Mar, May, Jul, Aug, Oct, Dec:
	if(mon==1 || mon==3 || mon==5 || mon==7 || mon==8 || mon==10 || mon==12) return 31;

	// Apr, Jun, Sep, Nov:
	if(mon==4 || mon==6 || mon==9 || mon==11) return 30;

	// Feb is a special case:
	if(mon==2) return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );

	return 0;
}

function getWeekday() {
	var day = document.forms[0].day.value;
	var mon = document.forms[0].mon.selectedIndex;
	var year = document.forms[0].year.value;
	
	if(year < 1900 || year > 2100) return "err";
	if(day < 1 || day > maxDay(mon, year)) return "err";
	
	var date = new Date(year, mon, day);
	//alert(date.toDateString());
	return date.toDateString().substr(0,3);
}