// JavaScript Document

function check_login_frm(){
	if(document.frm1.FAC_USRNAME.value==''){
		alert("Please type in your user name");
		return false;
	}
	if(document.frm1.FAC_PASSWD.value==''){
		alert("Please type in your password");
		return false;
	}
	return true;
}

function check_new_session(){
	if(document.frm_session.evn_title.value==''){
                alert("Please type in the session title.");
                return false;
    }
	//document.frm_session.submit();
	return true;
}
function change_login_text(){
	if(document.frm_login.login_type[0].checked==true){
                document.getElementById('j_Username').innerHTML='VUNetID: ';
				document.getElementById('j_Password').innerHTML='E-password: ';
    }else{
				document.getElementById('j_Username').innerHTML='User Name:';
				document.getElementById('j_Password').innerHTML='Password: ';
	}
}

function check_edit_session(){
	if(document.frm_session.evn_title.value==''){
                alert("Please type in the session title.");
                return false;
    }
	if(document.frm_session.evn_sponsor_type.value=='0'){
                alert("Please select the sponsor type.");
                return false;
    }
	if(document.frm_session.evn_session_type.value=='0'){
                alert("Please select the session type.");
                return false;
    }
	//document.frm_session.submit();
	return true;
}

function check_agenda(){
	var filter = /^\d+$/i	
	if(document.frm_session.agenda_hr_s.value==''){
                alert("Please type in the start hour.");
                return false;
    }
	if(!(filter.test(document.frm_session.agenda_hr_s.value))){
                alert("The start hour is not a digit.");
				document.frm_session.agenda_hr_s.value='';
				document.frm_session.agenda_hr_s.focus();
                return false;
    }
	if(document.frm_session.agenda_min_s.value==''){
                alert("Please type in the start minute.");
                return false;
    }	
	if(!(filter.test(document.frm_session.agenda_min_s.value))){
                alert("The start minute is not a digit.");
				document.frm_session.agenda_min_s.value='';
				document.frm_session.agenda_min_s.focus();
                return false;
    }
	if(document.frm_session.agenda_hr_e.value==''){
                alert("Please type in the end hour.");
                return false;
    }
	if(!(filter.test(document.frm_session.agenda_hr_e.value))){
                alert("The end hour is not a digit.");
				document.frm_session.agenda_hr_e.value='';
				document.frm_session.agenda_hr_e.focus();
                return false;
    }
	if(document.frm_session.agenda_min_e.value==''){
                alert("Please type in the end minute.");
                return false;
    }	
	if(!(filter.test(document.frm_session.agenda_min_e.value))){
                alert("The end minute is not a digit.");
				document.frm_session.agenda_min_e.value='';
				document.frm_session.agenda_min_e.focus();
                return false;
    }
	if(document.frm_session.agenda_speaker.value==''){
                alert("Please select a speaker.");
                return false;
    }
	return true;
}

function check_pay_cat(){
	if(document.frm_session.cat_name.value==''){
                alert("Please type in the catalog name.");
				document.frm_session.cat_name.focus();
                return false;
    }
	return true;
}
function delete_contact(del_id){
	var temp_id = del_id;
	document.frm_session.del_contact.value=temp_id;
	document.frm_session.submit();
}

function delete_agenda(del_id){
	var temp_id = del_id;
	document.frm_session.del_agenda.value=temp_id;
	document.frm_session.submit();
}

function delete_pay_cat(del_id){
	var temp_id = del_id;
	document.frm_session.del_pay_cat.value=temp_id;
	document.frm_session.submit();
}


function check_new_activity(){
	if(document.frm_activity.evn_title.value==''){
                alert("Please type in the event title.");
                return false;
    }
	document.frm_activity.submit();
	return true;
}

function check_register(){
	var el = document.frm_register.pay_cat;
	var itemchecked = false;
	for (var i=0; i<el.length; i++){
		if(el[i].checked){
			itemchecked = true;
			break;
		}
	}
	if(!itemchecked){
                alert("Please select Admission Fee type.");
                return false;
    }
	return true;
}

function click_field(form_nm,field_id,val){
	var tmp_field = document.forms[form_nm].elements[field_id];
	var check_val = val;
	if(tmp_field.value==check_val){
		tmp_field.value='';		
	}
}

function check_new_registrant(){
	if(document.fr_registration.reg_first_name.value==''){
                alert("Please type in your first name");
                return false;
        }
	if(document.fr_registration.reg_last_name.value==''){
			alert("Please type in your last name");
			return false;
	}	
	if(document.fr_registration.reg_user_name.value==''){
		alert("Please type in your user name");
		return false;
	}
	
	var tmp_email = document.fr_registration.reg_email.value;
	var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if(tmp_email==''){
        alert("Please type in your email");
        return false;
    }
	if (!(filter.test(tmp_email))){
		alert("The email address format is incorrect");
		return false;
	}
	if(document.fr_registration.reg_password.value==''){
		alert("Please type in your password");
		return false;
	}
	if(document.fr_registration.reg_password.value.length<6){
		alert("Your password is too short, it must be 6-20 characters in length.");
		return false;
	}
	if(document.fr_registration.reg_password.value!=document.fr_registration.reg_password_cf.value){
		alert("The passwords do not match, please try again.");
		return false;
	}
	return true;
}

function retrieve_id(){
	popwin = window.open("retrieve_id.php","Vanderbilt_CME",'toolbar=0,menubar=0.scrillbars=0,resizable=1,width=450,height=240,top=100,left=150')
}

function loadform(){
	document.frm_attendee.submit();
	document.frm_attendee.session_list.value='';
}

function loadsessionform(){
	document.frm_session.submit();
	//document.frm_activity_session.session_list.value='';
}
function loadactivityform(){
	document.frm_activity.submit();
}	
function load_activity(){
	document.frm_activity.load_choice.value=0;
	document.frm_activity.submit();
}
function load_dept(){
	document.frm_activity.load_choice.value=1;
	document.frm_activity.submit();
}
function reg_load_dept(){
	document.frm_registrant.load_choice.value=1;
	document.frm_registrant.submit();
}
function defaultattendee(){
	document.frm_attendee.attendee_list.value='';
}

function defaultactsession(){
	document.frm_session.session_list.value='';
}
function defaultsession(){
	document.frm_attendee.session_list.value='';
}

function toggleLayer(whichLayer)
{
	if (document.getElementById)
	{
		// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
		if(style2.display == "none"){
				style2.display = "block";
		}else{
				style2.display = "none";
		}
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
		if(style2.display == "none"){
				style2.display = "block";
		}else{
				style2.display = "none";
		}
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
		if(style2.display == "none"){
				style2.display = "block";
		}else{
				style2.display = "none";
		}
	}
}

/*function toggleLayer(whichLayer)
{
	if (document.getElementById)
	{
		// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
		style2.display = style2.display? "":"block";
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
		style2.display = style2.display? "":"block";
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
		style2.display = style2.display? "":"block";
	}
}
*/
function disableSubmit(whichButton)
{
	if (document.getElementById)
	{
		// this is the way the standards work
		document.getElementById(whichButton).disabled = true;
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		document.all[whichButton].disabled = true;
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		document.layers[whichButton].disabled = true;
	}
}
function load_attendee(){
	if( document.frm_session.session_list.value ==''){
		alert('Please select activity session'); 
		return false;
	} 
		
	for (var i=0;i<document.frm_session.email_att.length;i++){
		if(document.frm_session.email_att[i].checked){
			document.frm_session.sending_email.value = document.frm_session.email_att[i].value;			
		}
	}
	if(frm_session.sending_email.value ==''){
		alert('Please choose sending email or not'); 
		return false;
	}
}
function add(type) { 
	//Create an input type dynamically. 
	var element = document.createElement("input"); 
	
	//Assign different attributes to the element. 
	element.setAttribute("type", type); 
	element.setAttribute("value", type); 
	element.setAttribute("name", type); 
	
	var foo = document.getElementById("fooBar"); 
	
	//Append the element in page (in span).     
	foo.appendChild(element); 
}