// validation junk

function trim(s)
	{
	 return s.replace(/^\s+|\s+$/, '');
	}

function updateProfile(id) {
	var phone = document.getElementById('phone').value;
	var email = document.getElementById('email').value;
	
	var error="";
	var tphone = trim(phone);
	var temail = trim(email);
	var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
	var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
	
	var temail_array = new Array();
	temail_array = (temail.split("@",2));
	mydomain = (temail_array[1]);
		
	 if (tphone == "") {
			document.getElementById('errorText').innerHTML = 'Your phone number is required.';
		} else if (tphone.match(illegalChars)) {
			document.getElementById('errorText').innerHTML = 'Your phone number contains illegal characters.';
		} else if (temail == "") {
			document.getElementById('errorText').innerHTML = 'Your email address is required.';
		} else if (!emailFilter.test(temail)) {
			document.getElementById('errorText').innerHTML = 'Your email address must be a valid address.';
		} else if (temail.match(illegalChars)) {	
			document.getElementById('errorText').innerHTML = 'Your email address contains illegal characters.';
		} else if ( mydomain in oc(['madmadmad.com', 'mercycollege.edu']) ) {
			$.post("/profile/updateProfile", {id: id, phone: phone, email: email}, function() {
 			$('#profile_content').load("../profile/viewProfilelist/ajax");
 			});
		} else {	
			document.getElementById('errorText').innerHTML = 'Your email address does not match approved domains.';
		} 
}

function oc(a)
{
  var o = {};
  for(var i=0;i<a.length;i++)
  {
    o[a[i]]='';
  }
  return o;
}

// end validation junk


function updateProfile_admin(id) {

	var email = document.getElementById('email').value;
	var phone = document.getElementById('phone').value;

	$.post("/go/updateProfile", {id: id, phone: phone, email: email}, function() {
			$('#profile_content').load("../labs/viewProfilelist/ajax");
		});

}

function updateInfo() {

	var subhead = document.getElementById('subhead').value;
	var body = document.getElementById('body').value;

	$.post("/admin/labs/updateInfo", {subhead: subhead, body: body}, function() {
			$('#info_content').load("../labs/viewInfolist/ajax/");
		});

}


function clearStudents() {
	 document.reportForm.name.value = "";
}

function addSignUp(lab_id) {
	
	var name = document.getElementById('name').value;
	faderDiv = 'NULL';
	
	var last = signup_array.length;
	
	//alert (name+"="+signup_array[0]);
	
	for (var i = 0; i < last; i++) {		
		if (name == signup_array[i]) {
			var signedup = 1;
			break;
		}
	}
		
	if (signedup == 1) {
		alert ("Sorry. Already signed up!");
			window.location.href = "/go/editLab/"+lab_id;
	} else {
		$.post("/admin/labs/addSignUp", {lab_id: lab_id, name: name}, function() {
		            window.location.href = "/go/editLab/"+lab_id;
        });
	}
		
	document.reportForm.name.value = "";
}


function findUser() {
	
	var name = document.getElementById('name').value;
	faderDiv = 'NULL';
	
		// $('#user_list').load("/admin/users/viewpage", {name: name}, function() {$("#flashMessage").show("normal",
//         function()
//         {
//             $("#flashMessage").fadeOut(10000);
//         }
//         );});
        
        $.post("/admin/users/checkField", {name: name}, function() {
            $('#user_list').load("/admin/users/viewpage", {name: name}, function() {$("#flashMessage").show("normal",
        function()
        {
            $("#flashMessage").fadeOut(7500);
        });
        });
		});
        
	document.reportForm.name.value = "";
}


function response_deleteUser(yes, id) {

	if (yes==1) {	
	$.post("/admin/users/del", {id: id}, function() {
            //$('#mainContent').load("/auth/template_admin/users/list");
            $('#user_list').load("/admin/users/viewpage", {}, function() {$("#flashMessage").show("normal",
        function()
        {
            $("#flashMessage").fadeOut(10000);
        });
        });
		});
		
        C_oldid=0;
        oldid=0;
	}
}
