function recover_password(page)
{
	var email = document.getElementById('email').value;
	if(email == '')
	{
		alert("Please enter a valid email address");
	}
	if(window.XMLHttpRequest)
	{
		req = new XMLHttpRequest();
	}
	else
	{
		try
		{
			req = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				req = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(E)
			{
				if(window.createRequest)
				{
					req = window.createRequest();
				}
			}
		}
	}
        req.open('POST', 'index.php', false);
        req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded;charset=UTF-8;');
        req.send('p='+page+'&f=newpass&email='+email);
	if(req.status == 200)
	{
	}	
}

function validate_email(email)
{
	invalidChars = " /:,;";
	var valid = 1;
	if(email == "")
	{
		valid = 0;
	}
	
	for(i=0; i < invalidChars.length; i++)
	{
		badChar = invalidChars.charAt(i);
		if(email.indexOf(badChar,0) > -1)
		{
			valid = 0;
		}
	}

	atPos = email.indexOf("@",1);
	if(atPos == -1)
	{
		valid = 0;
	}

	if(email.indexOf("@", atPos+1) > -1)
	{
		valid = 0;
	}

	periodPos = email.indexOf(".",atPos);
	
	if(periodPos == -1)
	{
		valid = 0;
	}

	if(periodPos+3 > email.length)
	{
		valid = 0;
	}
	
	if(valid == 1)
	{
		return true;
	}
	else
	{
		alert("The Email Address you entered was not correct. Please enter a valid email.");
		return false;
	}
}

function deleteimage(imid, p_type, sci_id)
{
	if(imid == '')
	{
		alert('No image was selected to delete');
		return false;
	}
	else
	{
		if(window.XMLHttpRequest)
	        {
        	        req = new XMLHttpRequest();
	        }
	        else
        	{
                	try
	                {
        	                req = new ActiveXObject("Msxml2.XMLHTTP");
                	}
	                catch(e)	
        	        {
                	        try
                        	{
                                	req = new ActiveXObject("Microsoft.XMLHTTP");
	                        }
        	                catch(E)
                	        {
                        	        if(window.createRequest)
                                	{
                                        	req = window.createRequest();
	                                }
        	                }
                	}
	        }
		req.open('POST', 'index.php', false);
		req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded;charset=UTF-8;');
		req.send('p='+p_type+'&f=im_del&im_id='+imid+'&sci_id='+sci_id);
		if(req.status == 200)
		{
			if(p_type == 'scientist')
			{
				window.location = 'index.php?p='+p_type+'&f=ed_im';
			}
			else if(p_type == 'sturep')
			{
				window.location = 'index.php?p='+p_type+'&f=ed_sci_im&sci_id='+sci_id;
			}
			else if(p_type == 'admin')
			{
				window.location = '/?p='+p_type+'&f=ed_sc&id='+sci_id+'&stage=4';
			}
		}
		else
		{
			alert('Something went wrong!');
		}
	}
}

function getSearchResults(searchform, p_type)
{
	if(searchform == '')
	{
		alert('There has been an error');
		return false;
	}
	else
	{
		if(window.XMLHttpRequest)
	        {
        	        req = new XMLHttpRequest();
	        }
        	else
	        {
        	        try
                	{
                        	req = new ActiveXObject("Msxml2.XMLHTTP");
	                }
        	        catch(e)
                	{
                        	try
	                        {
        	                        req = new ActiveXObject("Microsoft.XMLHTTP");
                	        }
                        	catch(E)
	                        {
        	                        if(window.createRequest)
                	                {
                        	                req = window.createRequest();
                                	}
	                        }
        	        }
        	}

		req.open('POST', 'index.php', false);
		req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded;charset=UTF-8;');
		
req.send('p='+p_type+'&f=search&pref1='+searchform.answ1.value+'&pref2='+searchform.answ2.value+'&pref3='+searchform.answ3.value+'&pref4='+searchform.answ4.value+'&pref5='+searchform.answ5.value);
		alert(req.responseText);
		return false;
	}
	return false;
}

function rememberMe(id, p_type)
{
	if(id == '')
	{
		alert('There is no id submitted, please select a scientist or student');
	}
	else
	{
		if(p_type == 1)
		{
			p_type = 'student';
		}
		else if(p_type == 2)
		{
			p_type = 'scientist';
		}
		if(window.XMLHttpRequest)
	        {
        	        req = new XMLHttpRequest();
	        }
        	else
        	{
                	try
                	{
                        	req = new ActiveXObject("Msxml2.XMLHTTP");
	                }
        	        catch(e)
                	{
                        	try
	                        {
        	                        req = new ActiveXObject("Microsoft.XMLHTTP");
                	        }
                        	catch(E)
	                        {
        	                        if(window.createRequest)
                	                {
                        	                req = window.createRequest();
                                	}
	                        }
        	        }
	        }

                req.open('POST', 'index.php', false);
                req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded;charset=UTF-8;');
                req.send('p='+p_type+'&f=rm_stusci&id='+id);
                if(req.status == 200)
                {
			document.getElementById('rm_link'+id).innerHTML = "<strong>Remembered</strong>";
                }
	}
}

function finishIM(ptype, id)
{
	if(ptype == 1)
	{
		window.location = '/?p=sturep&=ed_sci&sci_id'+id;
	}
	else if(ptype == 2)
	{
		window.location = '/?p=scientist';
	}
}

function delUser(id, utype)
{
        if(id == '')
        {
                alert('No user was selected to delete');
                return false;
        }
        else
        {
		var conf = confirm("Warning, deleting this user is a permanant action. Are you sure you wish to delete?");
		if(conf)
		{
			if(window.XMLHttpRequest)
		        {
	        	        req = new XMLHttpRequest();
		        }
	        	else
		        {
	        	        try
	                	{
	                        	req = new ActiveXObject("Msxml2.XMLHTTP");
		                }
	        	        catch(e)
	                	{
	                        	try
		                        {
	        	                        req = new ActiveXObject("Microsoft.XMLHTTP");
	                	        }
	                        	catch(E)
		                        {
	        	                        if(window.createRequest)
        	        	                {
	                        	                req = window.createRequest();
	                                	}
		                        }
        		        }
	        	}

	                req.open('POST', 'index.php', false);
	                req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded;charset=UTF-8;');
	                req.send('p=admin&f=deluser&id='+id+"&utype="+utype);
        	        if(req.status == 200)
	                {
	                        window.location = 'index.php?p=admin&f=lu';
			}
		}
		else
		{
			return false;
		}
	}
}

function goto_visitors_search()
{
	window.location = '?p=casvis';
}

function return_to_search(spage, sfunc)
{
	window.location = '?p='+spage+'&f='+sfunc
}

function open_window(url)
{
	window.open(url,'view', 'width=900,height=1024,scrollbars=yes,toolbars=no');
}
