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

function checkNameEmail(names, emails) {
	names = trim(names);
	emails = trim(emails);	
	nameArray = names.split(',');
	emailArray = emails.split(',');
	
	if (nameArray.length != emailArray.length) {
		return false;
	}
	
	return true;
}

function isEmail(s) {
	s = trim(s);
	var email = s.split(',');
	for (var i = 0; i < email.length; i++) {
		if (!checkEmail(email[i])) {
			return false;
		}
	}
	
	return true;
}

function checkEmail(s) {
	if(s=="") // Email empty
		return true;
	if(s.indexOf(" ")>0) // Email having space
		return false;
	if(s.indexOf("@")==-1) // Email does not have @
		return false;
	var sLength=s.length;
	if(s.indexOf(".")==-1) // Email does not have '.'
		return false;
	if(s.indexOf("..")!=-1) // Email having  '..'
		return false;
	if(s.indexOf("@")!=s.lastIndexOf("@")) // Email having 2 @
		return false;
	if(s.lastIndexOf(".")==s.length-1) // Email having '.' end of sentence
		return false;

	return true; // Email is ok
}

$(document).ready(function(){
	$("#yourName").focus(function() {
		if($(this).val() == "Your Name") {
			$(this).val("");
			$(this).addClass(" ActiveInput");
		}
	});
	$("#yourName").blur(function() {
		if($(this).val() == "") {
			$(this).val("Your Name");
			$(this).removeClass(" ActiveInput");
		}
	});
	
	$("#yourEmail").focus(function() {
		if($(this).val() == "Your E-mail") {
			$(this).val("");
			$(this).addClass(" ActiveInput");
		}
	});
	$("#yourEmail").blur(function() {
		if($(this).val() == "") {
			$(this).val("Your E-mail");
			$(this).removeClass(" ActiveInput");
		}
	});
	
	$("#friendName").focus(function() {
		if($(this).val() == "Recipient's Name") {
			$(this).val("");
			$(this).addClass(" ActiveInput");
		}
	});
	$("#friendName").blur(function() {
		if($(this).val() == "") {
			$(this).val("Recipient's Name");
			$(this).removeClass(" ActiveInput");
		}
	});
	
	$("#friendEmail").focus(function() {
		if($(this).val() == "Recipient's E-mail") {
			$(this).val("");
			$(this).addClass(" ActiveInput");
		}
	});
	$("#friendEmail").blur(function() {
		if($(this).val() == "") {
			$(this).val("Recipient's E-mail");
			$(this).removeClass(" ActiveInput");
		}
	});
});