function checkform(f){

	var msg = "Some errors were made filling out the form.  \nPlease correct these errors and re-submit the form:\n";

	if (f.username.value== "") {
		msg += "\n-Your username is required information.";
		}

	if (f.password.value== "") {
		msg += "\n-Your password is required information.";
		}

	if (f.password2.value== "") {
		msg += "\n-Please re-enter your password.";
		}

	if (f.interests.value== "") {
		msg += "\n-Please enter your interests.";
		}

	if (f.strLocation.value== "") {
		msg += "\n-Please enter your location.";
		}

	if (f.password.value != f.password2.value) {
		msg += "\n-The two passwords entered don't match.";
		}

	if (f.strEmail.value == "") {
		msg += "\n-Please enter your email address.";
		}

	 if (f.terms.checked == false)
	{
	msg += "\n-To continue you must read and agree to the Terms of Use.";
	}

	if ((f.username.value== "") || (f.password.value == "") || (f.password2.value == "") || (f.interests.value == "") || (f.strLocation.value == "") || (f.password.value != f.password2.value) || (f.strEmail.value == "") || (f.terms.checked == false)){
		alert(msg);
		return false;
		}
		else
		{
		return true;
		}
}//end function checkform


function setFocusHere(thisElement)
{
	var focusOnField = document.getElementById(thisElement);
	focusOnField.focus();
}

function setSearchTarget()
{
	if (document.getElementById('searchType').value == 'finds')
	{
		document.getElementById('headerSearch').action = 'finds.php';
		document.getElementById('searchTerm').name = 'find_title';
	}
	else 
	{
		document.getElementById('headerSearch').action = 'profiles.php';
		document.getElementById('searchTerm').name = 'interests';
	}
}

function popUp(url)
{
	if (url.indexOf("http://") < 0) {
		url = "http://"+url;
	}				
	sealWin=window.open(url,"win",'toolbar=1,location=1,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=400,height=340');
	self.name = "mainWin";
	sealWin.focus();
}

function doSomething(e) 
{
	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 
	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 
	{
		posx = e.clientX + document.body.scrollLeft	+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	}
}

var ac_comment = {
	expand:function(commentId)
	{
		document.getElementById('comment'+commentId).className = 'expanded';
		document.getElementById('moreLink'+commentId).className = 'hidden';
		document.getElementById('lessLink'+commentId).className = 'shown';
	},
	collapse:function(commentId)
	{
		document.getElementById('comment'+commentId).className = 'collapsed';
		document.getElementById('moreLink'+commentId).className = 'shown';
		document.getElementById('lessLink'+commentId).className = 'hidden';
	}
}

var ac_nav = {
	goBack:function()
	{
		window.history.back();
	}
}

function confirmation(thisImage, action) {
	if (action == 'delete') {
		var answer = confirm("Are you sure you want to delete this image?");
		if (answer) {
			window.location = "image_upload.php?action=delete&image_id="+thisImage;
		}
		else {
			return;
		}
	}
	else if (action == 'setMainImage') {
		window.location = "image_upload.php?action=setMainImage&image_id="+thisImage;
	}
	else {
		return;
	}
}

var ac_form = {
	clearField: function(field, formType){
		if (formType == 'headerSearch')
		{
			if(field.value == 'Enter search terms here'){field.value=''}
		}
	}
}

function postRating(findId, userIp, m_uni, targetId) { $.ajax({
      type: "POST",
	  url: "include/rateFind.php",
	  data: "findId="+findId+"&userIp="+userIp+"&m_uni="+m_uni,
	  success: function(msg){
	  alert(msg);
	  if (msg.indexOf('successfully') > -1)
	  {
	  var starsHTML = "";
	  if (targetId=='0') {
	  var starsHTML = document.getElementById('stars0').innerHTML;
	  $('<img src=\"images/star.gif\" class=\"align\" />').appendTo('#stars0');
	  
	  }
	  else if (targetId=='1') {
	  var starsHTML = document.getElementById('stars1').innerHTML;
	  $('<img src=\"images/star.gif\" class=\"align\" />').appendTo('#stars1');
	  
	  }
	  else if (targetId=='2') {
	  var starsHTML = document.getElementById('stars2').innerHTML;
	  $('<img src=\"images/star.gif\" class=\"align\" />').appendTo('#stars2');
	  
	  }
	  else if (targetId=='3') {
	  var starsHTML = document.getElementById('stars3').innerHTML;
	  $('<img src=\"images/star.gif\" class=\"align\" />').appendTo('#stars3');
	  
	  }
	  else if (targetId=='4') {
	  var starsHTML = document.getElementById('stars4').innerHTML;
	  $('<img src=\"images/star.gif\" class=\"align\" />').appendTo('#stars4');
	  
	  }
	  else if (targetId=='5') {
	  var starsHTML = document.getElementById('stars5').innerHTML;
	  $('<img src=\"images/star.gif\" class=\"align\" />').appendTo('#stars5');
	  
	  }
	  else if (targetId=='6') {
	  var starsHTML = document.getElementById('stars6').innerHTML;
	  $('<img src=\"images/star.gif\" class=\"align\" />').appendTo('#stars6');
	  
	  }
	  else if (targetId=='7') {
	  var starsHTML = document.getElementById('stars7').innerHTML;
	  $('<img src=\"images/star.gif\" class=\"align\" />').appendTo('#stars7');
	  }
	  else if (targetId=='8') {
	  var starsHTML = document.getElementById('stars8').innerHTML;
	  $('<img src=\"images/star.gif\" class=\"align\" />').appendTo('#stars8');
	  }
	  else if (targetId=='9') {
	  var starsHTML = document.getElementById('stars9').innerHTML;
	  $('<img src=\"images/star.gif\" class=\"align\" />').appendTo('#stars9');
	  }	
	  }
	  }
  }); 
}



function postComment(findId,m_uni,memberNameLoggedIn,targetId, comments) {
	$.ajax({
				type: "POST",
				url: "include/commentFind.php",
				data: "findId="+findId+"&m_uni="+m_uni+"&memberNameLoggedIn="+memberNameLoggedIn+"&targetId="+targetId+"&comments="+comments,
				success: function(msg){
				//if (msg != "") {
					//alert(msg)
				//}
					if (msg.indexOf('must be') < 0 && msg.indexOf('Please enter a comment') < 0)
					{
						if (targetId=='0') {
						var commentsHTML = document.getElementById('comments0').innerHTML;
						 document.getElementById('comments0').innerHTML =  document.getElementById('comments0').innerHTML + msg;
	
						}
						else if (targetId=='1') {
							var commentsHTML = document.getElementById('comments1').innerHTML;
							$(msg).appendTo('#comments1');
						}
						else if (targetId=='2') {
						var commentsHTML = document.getElementById('comments2').innerHTML;
						$(msg).appendTo('#comments2');
						}
						else if (targetId=='3') {
						var commentsHTML = document.getElementById('comments3').innerHTML;
						$(msg).appendTo('#comments3');
						}
						else if (targetId=='4') {
						var commentsHTML = document.getElementById('comments4').innerHTML;
						$(msg).appendTo('#comments4');
						}
						else if (targetId=='5') {
						var commentsHTML = document.getElementById('comments5').innerHTML;
						$(msg).appendTo('#comments5');
						}
						else if (targetId=='6') {
						var commentsHTML = document.getElementById('comments6').innerHTML;
						$(msg).appendTo('#comments6');
						}
						else if (targetId=='7') {
						var commentsHTML = document.getElementById('comments7').innerHTML;
						$(msg).appendTo('#comments7');
						}
						else if (targetId=='8') {
						var commentsHTML = document.getElementById('comments8').innerHTML;
						$(msg).appendTo('#comments8');
						}
						else if (targetId=='9') {
						var commentsHTML = document.getElementById('comments9').innerHTML;
						$(msg).appendTo('#comments9');
						}
					}
				}
	   }); 
}

var findNumber = "";
var thisTargetId = "";
function runEffect(targetId, findId){

	findNumber = findId;
	thisTargetId = targetId

	$('#effect').hide();

	// begin: find position
	if (targetId=='0') {
		var pos = $('#addComment0').position();
		
	}
	else if (targetId=='1') {
		var pos = $('#addComment1').position();
		
	}
	else if (targetId=='2') {
		var pos = $('#addComment2').position();
		
	}
	else if (targetId=='3') {
		var pos = $('#addComment3').position();
	}
	else if (targetId=='4') {
		var pos = $('#addComment4').position();
	}
	else if (targetId=='5') {
		var pos = $('#addComment5').position();
	}
	else if (targetId=='6') {
		var pos = $('#addComment6').position();
	}
	else if (targetId=='7') {
		var pos = $('#addComment7').position();
	}
	else if (targetId=='8') {
		var pos = $('#addComment8').position();
	}
	else if (targetId=='9') {
		var pos = $('#addComment9').position();
	}
	//var posEffect = $('#effect').position();
	$('#effect').css("left", pos.left);
	$('#effect').css("top", pos.top+28);
	// end: find position

	var options = {direction:'up'};
	
	$("#effect").toggle("slide",options,500);
}