var animatelogolock = false;
		
function submitLogin()
{
	var username = document.getElementById('loginusernameinput').value;
	var password = document.getElementById('loginpasswordinput').value;
	
	// removes leading/ending whitespace
	username = username.replace(/^\s+|\s+$/g, '');
	password = password.replace(/^\s+|\s+$/g, '');
	
	var valid = true;
	
	if(username == '' || username == 'Email')
	{
		document.getElementById('loginusernameinput').style.color = 'crimson';
		valid = false;
	}
	
	if(password == '' || password == 'Password')
	{
		document.getElementById('loginpasswordinput').style.color = 'crimson';
		valid = false;
	}
	
	try
	{
		if(valid && (ajaxRequest.readyState == 4 || ajaxRequest.readyState == 0))
		{
			var params = "username=" + encodeURIComponent(username);
			params += "&password=" + encodeURIComponent(password);

			ajaxRequest.open("POST", "/social/forms/Signin.php", true);
			ajaxRequest.onreadystatechange = handleLoginSubmit;
			ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			ajaxRequest.setRequestHeader("Content-length", params.length);
			ajaxRequest.setRequestHeader("Connection", "close");
			ajaxRequest.send(params);
			
			document.getElementById('loginusernameinput').disabled = true;
			document.getElementById('loginpasswordinput').disabled = true;
			document.getElementById('loginsubmit').style.cursor = 'default';
			document.getElementById('loginsubmit').innerHTML = 'Signing in...';
		}
	}
	catch (error)
	{
		//alert("Error submitting form: " + error);
		//alert(error.getMessage());
	}
}

function handleLoginSubmit()
{
	if(ajaxRequest.readyState == 4)
	{
		var result = ajaxRequest.responseText;
		
		if(result.match(/^ok=.+/i))
		{
			window.location.reload(false);
//			var arr = result.split('=');
//			
//			var named = arr[1];
//			
//			document.getElementById('loginsubmit').style.visibility = 'hidden';
//			document.getElementById('loginsignup').style.visibility = 'hidden';
//			document.getElementById('loginusernameinput').style.visibility = 'hidden';
//			document.getElementById('loginpasswordinput').style.visibility = 'hidden';
//			document.getElementById('loginsuccess').style.visibility = 'visible';
//			document.getElementById('loginlogout').style.visibility = 'visible';
//			document.getElementById('loginmembername').innerHTML = named;
		}
		else if(result == 'no member')
		{
			document.getElementById('loginusernameinput').disabled = false;
			document.getElementById('loginpasswordinput').disabled = false;
			document.getElementById('loginusernameinput').style.color = 'red';
			document.getElementById('loginusernameinput').value = 'Wrong...';
			document.getElementById('loginsubmit').innerHTML = 'Sign in';

			document.getElementById('loginusernameinput').onfocus = function() {				
				document.getElementById('loginusernameinput').style.color = '#380b53';
				document.getElementById('loginusernameinput').value = '';
				this.onfocus = function() {if(this.value=='Email'){this.value='';this.style.color='#000033'}};
			};
		}
		else if(result == 'bad')
		{
			document.getElementById('loginusernameinput').disabled = false;
			document.getElementById('loginpasswordinput').disabled = false;
			document.getElementById('loginpasswordinput').style.color = 'red';
			document.getElementById('loginpasswordinput').type = 'text';
			document.getElementById('loginpasswordinput').value = 'Wrong...';
			document.getElementById('loginsubmit').innerHTML = 'Sign in';

			document.getElementById('loginpasswordinput').onfocus = function() {				
				document.getElementById('loginpasswordinput').style.color = '#380b53';
				document.getElementById('loginpasswordinput').value = '';
				document.getElementById('loginpasswordinput').type = 'password';
				this.onfocus = function() {if(this.value=='Password'){this.value='';this.type='password';this.style.color='#000033'}};
			};
		}
		else if(result == 'error')
		{
			document.getElementById('loginsubmit').style.visibility = 'hidden';
			document.getElementById('loginusernameinput').style.visibility = 'hidden';
			document.getElementById('loginpasswordinput').style.visibility = 'hidden';
			document.getElementById('loginerror').style.visibility = 'visible';
		}
	}
}

function submitLogout()
{
	if(ajaxRequest.readyState == 4 || ajaxRequest.readyState == 0)
	{
		try
		{
			ajaxRequest.open("GET", "/social/forms/Signout.php", true);
			ajaxRequest.onreadystatechange = handleLogoutSubmit;
			ajaxRequest.send(null);
		}
		catch (error)
		{
			//alert("Error submitting form: " + error);
		}
	}
}

//
function handleLogoutSubmit()
{
	if(ajaxRequest.readyState == 4)
	{
		var result = ajaxRequest.responseText;
		
		if(result.match(/^ok/i))
		{
			window.location.reload(false);
//			document.getElementById('loginsuccess').style.visibility = 'hidden';
//			document.getElementById('loginlogout').style.visibility = 'hidden';
//			document.getElementById('loginusernameinput').disabled = false;
//			document.getElementById('loginusernameinput').style.color = '#666666';
//			document.getElementById('loginusernameinput').value = 'Email';
//			document.getElementById('loginpasswordinput').disabled = false;
//			document.getElementById('loginpasswordinput').style.color = '#666666';
//			document.getElementById('loginpasswordinput').value = 'Password';
//			document.getElementById('loginpasswordinput').type = 'text';
//			document.getElementById('loginsubmit').style.cursor = 'pointer';
//			document.getElementById('loginsubmit').innerHTML = 'Sign in';
//			document.getElementById('loginsignup').style.visibility = 'visible';
//			document.getElementById('loginsubmit').style.visibility = 'visible';
//			document.getElementById('loginusernameinput').style.visibility = 'visible';
//			document.getElementById('loginpasswordinput').style.visibility = 'visible';
		}
	}

}

var voteentryid = false;

//
function submitVote(entryid, pos)
{
	if(!voteentryid && (ajaxRequest.readyState == 4 || ajaxRequest.readyState == 0))
	{
		try
		{
			if(!pos) {
				ajaxRequest.open("GET", "/social/forms/Vote.php?entryid="+entryid+"&bury=1", true);
			} else {
				ajaxRequest.open("GET", "/social/forms/Vote.php?entryid="+entryid, true);
			}
			
			ajaxRequest.onreadystatechange = handleVoteSubmit;
			voteentryid = entryid;
			ajaxRequest.send(null);
			document.getElementById('entriesvote'+entryid).innerHTML = '<img src="/_images/social/working.gif" border=0 style="position:relative;top:2px;left:8px;width:12;height:12;" />';
			document.getElementById('entriesvote'+entryid).blur();
		}
		catch (error)
		{
			//alert("Error submitting form: " + error);
		}
	}
}

function handleVoteSubmit()
{
	if(ajaxRequest.readyState == 4)
	{
		var result = ajaxRequest.responseText;
		var entryid = voteentryid;
		voteentryid = false;

		if(result == 'ok' || result == 'redundant')	{
			document.getElementById('entriesvote'+entryid).innerHTML = 'VOTED';
			document.getElementById('entriesvote'+entryid).style.cursor = 'default';
			document.getElementById('entriesvote'+entryid).style.textDecoration = 'none';
			document.getElementById('entriesvote'+entryid).onclick = null;
			document.getElementById('entriesbury'+entryid).innerHTML = '';
			document.getElementById('entriesbury'+entryid).style.cursor = 'default';
			document.getElementById('entriesbury'+entryid).style.textDecoration = 'none';
			document.getElementById('entriesbury'+entryid).onclick = null;
			document.getElementById('entriesvoteimgdisable'+entryid).style.visibility = visible;
		}
		else if(result == 'no member')	{
			document.getElementById('entriesvote'+entryid).innerHTML = 'VOTE';
			var t = fadeOutIn('entriesdefault'+entryid, 'entriessignin'+entryid);
			setTimeout('fadeOutIn("entriessignin'+entryid+'", "entriesdefault'+entryid+'");', t+1000);
		}
		else if(result == 'error' || result == 'no entry')	{
			document.getElementById('entriesvote'+entryid).innerHTML = 'ERROR';
			document.getElementById('entriesvote'+entryid).style.cursor = 'default';
			document.getElementById('entriesvote'+entryid).style.textDecoration = 'none';
			document.getElementById('entriesvote'+entryid).onclick = null;
			document.getElementById('entriesvote'+entryid).style.color = 'crimson';
			document.getElementById('entriesbury'+entryid).innerHTML = '';
			document.getElementById('entriesbury'+entryid).style.cursor = 'default';
			document.getElementById('entriesbury'+entryid).style.textDecoration = 'none';
			document.getElementById('entriesbury'+entryid).onclick = null;
			document.getElementById('entriesvoteimgdisable'+entryid).style.visibility = visible;
		}
	}
}

function defaultHeader()
{
	document.getElementById('categoryvideosover').style.visibility=hidden;
	document.getElementById('categorypicsover').style.visibility=hidden;
	document.getElementById('categorywebover').style.visibility=hidden;
	document.getElementById('categoryvideos').style.visibility=visible;
	document.getElementById('categorypics').style.visibility=visible;
	document.getElementById('categoryweb').style.visibility=visible;
}

function toggleShare(entryid)
{
	if(document.getElementById('entriesshare'+entryid).innerHTML.match(/share/i)) {
		// show share form
		var t = fadeOutIn('entriesdefault'+entryid, 'entriesshareform'+entryid);
		setTimeout('document.getElementById("entriesshare'+entryid+'").innerHTML="CLOSE";document.getElementById("entriesvote'+entryid+'").style.visibility=hidden;document.getElementById("entriesbury'+entryid+'").style.visibility=hidden;', t+10);
	} else if(document.getElementById('entriesshare'+entryid).innerHTML.match(/close/i)) {
		// hide share form
		var t = fadeOutIn('entriesshareform'+entryid, 'entriesdefault'+entryid);
		setTimeout('document.getElementById("entriesshare'+entryid+'").innerHTML="SHARE";document.getElementById("entriesvote'+entryid+'").style.visibility=visible;document.getElementById("entriesbury'+entryid+'").style.visibility=visible;', t+10);
	}
}

var shareentryid = false;

function submitShare(entryid)
{
	var email = document.getElementById('entriesshareformemailinput'+entryid).value;
	var message = document.getElementById('entriesshareformmsginput'+entryid).value;
	
	// removes leading/ending whitespace
	email = email.replace(/^\s+|\s+$/g, '');
	message = message.replace(/^\s+|\s+$/g, '');
	
	if(!shareentryid && checkShareEmail(entryid) && (ajaxRequest.readyState == 4 || ajaxRequest.readyState == 0))
	{
		var params = "entryid=" + entryid;
		params += "&emailaddress=" + encodeURIComponent(email);
		params += "&message=" + encodeURIComponent(message);
		try
		{
			ajaxRequest.open("GET", "/social/forms/Share.php?"+params, true);
			
			ajaxRequest.onreadystatechange = handleShareSubmit;
			shareentryid = entryid;
			ajaxRequest.send(null);
			document.getElementById('entriesshareformsubmit'+entryid).innerHTML = '<img src="/_images/social/working.gif" border=0 style="position:relative;top:2px;left:8px;width:22;height:22;" />';
			document.getElementById('entriesshareformsubmit'+entryid).blur();
		}
		catch (error)
		{
			//alert("Error submitting form: " + error);
		}
	}
}

function handleShareSubmit()
{
	if(ajaxRequest.readyState == 4)
	{
		var result = ajaxRequest.responseText;
		var entryid = shareentryid;

		if(result == 'ok')	{
			document.getElementById('entriesshareformsubmit'+entryid).innerHTML = 'Ok';
			setTimeout('shareentryid=false;document.getElementById(\'entriesshareformsubmit'+entryid+'\').innerHTML=\'Submit &gt\';', 1100);
		}
		else if(result == 'error' || result == 'no entry')	{
			shareentryid = false;
			document.getElementById('entriesshareformsubmit'+entryid).innerHTML = 'ERROR';
			document.getElementById('entriesshareformsubmit'+entryid).style.cursor = 'default';
			document.getElementById('entriesshareformsubmit'+entryid).style.textDecoration = 'none';
			document.getElementById('entriesshareformsubmit'+entryid).style.color = 'crimson';
			document.getElementById('entriesshareformsubmit'+entryid).onclick = null;
			document.getElementById('entriesshareformemailinput'+entryid).disabled = true;
			document.getElementById('entriesshareformmsginput'+entryid).disabled = true;
		}
	}
}


function checkShareEmail(entryid) {
	var emailinput = document.getElementById('entriesshareformemailinput'+entryid);
	var email = emailinput.value;
	email = email.replace(/^\s+|\s+$/g, ''); // removes leading/ending whitespace
	
	// email filter basic: /^.+@.+\..{2,3,4,6}$/
	if(email != '' && !email.match(/^([^()<>\[\],;:\\\/\"]+)@([^()<>\[\],;:\\\/\"]+\.[a-zA-Z0-9]{2,6})$/)) {
		emailinput.style.border='1px solid red';
		return false;
	} else {
		emailinput.style.border='1px solid black';
		return true;
	}
}

function animateLogo()
{
	if(!animatelogolock)
	{
		animatelogolock = true;
		globalarr[0] = document.getElementById('headerlogo').style;
		
		setTimeout('globalarr[0].top=-150.0',16);
		setTimeout('globalarr[0].top=-150.0',32);
		setTimeout('globalarr[0].top=-149.99',48);
		setTimeout('globalarr[0].top=-149.96',64);
		setTimeout('globalarr[0].top=-149.92',80);
		setTimeout('globalarr[0].top=-149.85',96);
		setTimeout('globalarr[0].top=-149.75',112);
		setTimeout('globalarr[0].top=-149.6',128);
		setTimeout('globalarr[0].top=-149.39',144);
		setTimeout('globalarr[0].top=-149.12',160);
		setTimeout('globalarr[0].top=-148.77',176);
		setTimeout('globalarr[0].top=-148.34',192);
		setTimeout('globalarr[0].top=-147.8',208);
		setTimeout('globalarr[0].top=-147.14',224);
		setTimeout('globalarr[0].top=-146.36',240);
		setTimeout('globalarr[0].top=-145.44',256);
		setTimeout('globalarr[0].top=-144.37',272);
		setTimeout('globalarr[0].top=-143.12',288);
		setTimeout('globalarr[0].top=-141.69',304);
		setTimeout('globalarr[0].top=-140.05',320);
		setTimeout('globalarr[0].top=-138.2',336);
		setTimeout('globalarr[0].top=-136.11',352);
		setTimeout('globalarr[0].top=-133.77',368);
		setTimeout('globalarr[0].top=-131.17',384);
		setTimeout('globalarr[0].top=-128.27',400);
		setTimeout('globalarr[0].top=-125.08',416);
		setTimeout('globalarr[0].top=-121.56',432);
		setTimeout('globalarr[0].top=-117.7',448);
		setTimeout('globalarr[0].top=-113.47',464);
		setTimeout('globalarr[0].top=-108.87',480);
		setTimeout('globalarr[0].top=-103.87',496);
		setTimeout('globalarr[0].top=-98.45',512);
		setTimeout('globalarr[0].top=-92.59',528);
		setTimeout('globalarr[0].top=-86.26',544);
		setTimeout('globalarr[0].top=-79.46',560);
		setTimeout('globalarr[0].top=-72.15',576);
		setTimeout('globalarr[0].top=-64.31',592);
		setTimeout('globalarr[0].top=-55.93',608);
		setTimeout('globalarr[0].top=-46.98',624);
		setTimeout('globalarr[0].top=-37.43',640);
		setTimeout('globalarr[0].top=-27.27',656);
		setTimeout('globalarr[0].top=-16.47',672);
		setTimeout('globalarr[0].top=-5.01',688);
		setTimeout('globalarr[0].top=7.14',704);
		setTimeout('globalarr[0].top=20.0',720);
		setTimeout('globalarr[0].top=16.97',736);
		setTimeout('globalarr[0].top=14.18',752);
		setTimeout('globalarr[0].top=11.64',768);
		setTimeout('globalarr[0].top=9.36',784);
		setTimeout('globalarr[0].top=7.35',800);
		setTimeout('globalarr[0].top=5.62',816);
		setTimeout('globalarr[0].top=4.19',832);
		setTimeout('globalarr[0].top=3.08',848);
		setTimeout('globalarr[0].top=2.32',864);
		setTimeout('globalarr[0].top=2.0',880);
		setTimeout('delete globalarr[0];animatelogolock=false;',890);
	}
}