function valiDate(confType){
// Suggests full pathname for realmedia file depending  
// on Type and Date as entered by the user.

	var mm = document.newConf.date1.value.substr(0,2)
	var dd = document.newConf.date1.value.substr(3,2)
	var yy = document.newConf.date1.value.substr(6,4)

	var pathname = "ram/" + yy+ "/" + mm+yy+ "/" + mm+dd+yy  
//	var pathname = "ram/"           + mm+yy+ "/" + mm+dd+yy  

	if (isOpen(document.newConf.type1.options[document.newConf.type1.selectedIndex].value) < 0 ) {
		document.newConf.fileRM1.value =   pathname + ".ram"
	}else{
		document.newConf.fileRM1.value =   pathname + ".html"
	}


	document.newConf.wDay1.value = DayOfWeek(dd,mm,yy)

}

function isOpen(typeVal) {
//  Checks if conference is "open" or "labmed" to help  
//  finding the location to save real media file.

	var closeConf1 = "Clinical Pathology Didactic Lecture"
	var closeConf2 = "Current Topics in Laboratory Medicine"
	var closeConf = new Array(closeConf1, closeConf2)
	var i=0
	var pos = -1
	for (i=0; i<closeConf.length; i++){
		if (pos < 0) {
			pos = closeConf[i].indexOf(typeVal)
		}	
	}
		return pos
}

function checkForEmpty() {
// Checks if values are entered for Title and Speaker fields. Also,
// calls isDate to check if date is valid and in MM/DD/YYYY format.
		var title = document.newConf.title1.value
		var speaker = document.newConf.speaker1.value
		var type = document.newConf.type1.value
		var typeOther = document.newConf.type1Other.value
		var confRM = document.newConf.fileRM1.value
		var theDate = document.newConf.date1
		var mm = theDate.value.substr(0,2)
		var dd = theDate.value.substr(3,2)
		var yy = theDate.value.substr(6,4)

		var retVal = true
		
		if (title.length < 1) {
			alert("Please enter Title")
			retVal = false
		}else{
			if (speaker.length < 1) {
				alert("Speaker can't be blank")
				retVal = false
			} else {
				 retVal = true
			}
		}
//		Ensure that Conference type is entered by the user if Type "Other" is selected.
		if (retVal == true){
			if (type == "Other") {
				if (typeOther == "") {
					alert("Conference Type can't be blank.\n\nSelect from the dropdown list or enter a value for type 'OTHER' ")
					 retVal = false
				}	 
			}
		}
//		
		if (retVal == true) {
			retVal = isDate(dd, mm, yy)
		}	

		if (retVal == true) {
// Confirm the info before submitting the form		
			var confirmWrite = "Do you want to save these conference details?\n"
			confirmWrite += "Title: " + title + "\n"
			confirmWrite += "Speaker: " + speaker + "\n"
			if (type = "Other") {
				confirmWrite += "Type: " + type + "; Entered Value: " + typeOther + " \n"
			}else{
				confirmWrite += "Type: " + type + "\n"
			}
			confirmWrite += "Date: " + theDate.value + "\n"
			confirmWrite += "Media File: " + confRM + "\n"
			retVal = confirm(confirmWrite); 
		}	
	return retVal
}

function isDate (day, month, year) {
// checks if date passed is valid
// will accept dates in following format:
// isDate(dd,mm,ccyy), or
// isDate(dd,mm) - which defaults to the current year, or
// isDate(dd) - which defaults to the current month and year.
// Note, if passed the month must be between 1 and 12, and the
// year in ccyy format.

    var today = new Date();
    year = ((!year) ? y2k(today.getYear()):year);
    month = ((!month) ? today.getMonth():month-1);
    if (!day) return false
    var test = new Date(year,month,day);
    if ( (y2k(test.getYear()) == year) &&
         (month == test.getMonth()) &&
         (day == test.getDate()) )
        return true;
    else
		alert("\t" + document.newConf.date1.value+ " is not a valid date.\n\nDate should be in MM/DD/CCYY format such as 01/01/2003")
        return false
}

function y2k(number) { 
	return (number < 1000) ? number + 1900 : number; 
}

function makeArray()    {
// Used to create daysofweek array
    this[0] = makeArray.arguments.length;
    for (i = 0; i<makeArray.arguments.length; i++)
        this[i+1] = makeArray.arguments[i];
}

function DayOfWeek(day, month,year) {
	//displays the day of the week for a date.
	var yy = year*1
	var mm = 1


	if (month > 1) {
		mm = (1*month -1)
	}else{
		mm = 12
	}
	var thisdate = new Date(yy, mm, day);

	var dd = 0
	if (thisdate.getDay()< 7) {
		dd=thisdate.getDay()+1
	}else{
		dd=0	
	}
	return daysofweek[dd]
}

function toggleType(confType) {
	if (confType.options[confType.selectedIndex].value == "Other") {
		if (confType.name == "confType")	{		// Search Page
			document.confSearch.confTypeOther.style.display = "block"
			document.confSearch.confType.style.display = "none"
			document.confSearch.confTypeOther.focus()
		}else{							// Create Page
			document.newConf.type1Other.style.display = "block"
			document.newConf.type1.style.display = "none"
			document.newConf.type1Other.focus()
			valiDate(confType)	
		}
	}
}

function toggleReverse(confType) 
{
		if (confType.name == "confType")	
		{		// Search Page
			document.confSearch.confTypeOther.style.display = "none"
			document.confSearch.confType.style.display = "block"
		}else{		// Create Page
			document.newConf.type1Other.style.display = "none"
			document.newConf.type1.style.display = "block"
		}
}

var daysofweek 
	= new makeArray('Sunday','Monday','Tuesday','Wednesday', 'Thursday','Friday', 'Saturday');
                               
