var email_pattern = /[\w\-]+\@[\w\-]+\.\w{2,3}/; 

function checkPLRSignup()	{
	if (trim(document.getElementById('f_name').value).length == 0)	{
		alert("Please enter your first name");
		document.getElementById('f_name').focus();
		return false;
		}

	if (trim(document.getElementById('l_name').value).length == 0)	{
		alert("Please enter your last name");
		document.getElementById('l_name').focus();
		return false;
		}

	if (trim(document.getElementById('email_addy').value).length == 0 || !email_pattern.test(document.getElementById('email_addy').value))	{
		alert("Either the email address field is empty or you have entered an incorrectly formatted email address");
		document.getElementById('email_addy').focus();
		return false;
		}

	if (trim(document.getElementById('pass_word_1').value).length < 8)	{
		alert("Please enter a password to use on our site, minimum 8 characters long");
		document.getElementById('pass_word_1').focus();
		return false;
		}

	if (trim(document.getElementById('pass_word_2').value).length < 8 || (document.getElementById('pass_word_2').value != document.getElementById('pass_word_1').value))	{
		alert("The passwords entered into the two password fields do not match");
		document.getElementById('pass_word_2').focus();
		return false;
		}

	if (!document.getElementById('accepted_tos').checked)	 {
		alert("You must read and agree to the adzines.com terms of service before signing up");
		return false;
		}
	}

function checkForgotPassword()	{
	if (trim(document.getElementById('forgot_email').value).length == 0 || !email_pattern.test(document.getElementById('forgot_email').value))	 {
		alert("Please enter the email address you used to sign up with");
		document.getElementById('forgot_email').focus();
		return false;
		}
	
	}

function checkPLRLogin()	 {
	if (trim(document.getElementById('plr_username').value).length == 0 || !email_pattern.test(document.getElementById('plr_username').value))	{
		alert("Please input your membership username");
		document.getElementById('plr_username').focus();
		return false;
		}

	if (trim(document.getElementById('plr_password').value).length == 0)	{
		alert("Please input your membership password");
		document.getElementById('plr_password').focus();
		return false;
		}

	}

function checkResForm()	 {
	if (trim(document.getElementById('mem_name').value).length == 0)	{
		alert('You must enter your name to be added to the reservation list');
		document.getElementById('mem_name').focus();
		return false;
		}
	if (trim(document.getElementById('mem_email').value).length < 5 || !email_pattern.test(document.getElementById('mem_email').value))	{
		alert('Either the email field is empty or the email address is improperly formatted\n\nplease check it and resubmit the form');
		document.getElementById('mem_email').focus();
		return false;
		}

	return confirm("Please make sure your email address is correct! We will only send out one email invitation to each person on the reservation list!");
	}

function checkForgotPass()	{
	if (trim(document.getElementById('emailaddy').value).length == 0 && trim(document.getElementById('author_id').value).length == 0)	{
		alert("Please enter your email address or author id");
		document.getElementById('emailaddy').focus();
		return false;
		}
	else if (trim(document.getElementById('emailaddy').value).length != 0 && !email_pattern.test(document.getElementById('emailaddy').value))	{
		alert("the email address you have entered appears to be incorrectly formatted\n\nPlease check it and resubmit the form");
		document.getElementById('emailaddy').focus();
		return false;
		}
	else if(trim(document.getElementById('author_id').value).length != 0 && trim(document.getElementById('author_id').value).length < 4)	{
		alert("Please enter your author id number");
		document.getElementById('author_id').focus();
		return false;
		}
	}

function checkLogin()	{
	if (trim(document.getElementById('username').value).length == 0 || !email_pattern.test(document.getElementById('username').value))	{
		alert("Please enter your username (the email address on file for your account)");
		document.getElementById('username').focus();
		return false;
		}
	if (trim(document.getElementById('password').value).length < 8)	{
		alert("Please enter your password");
		document.getElementById('password').focus();
		return false;
		}
	}
	
function checkSearchForm()	{
	if (trim(document.getElementById('searchterms').value).length == 0)	{
		alert("please enter the terms you wish to search with");
		document.getElementById('searchterms').focus();
		return false;
		}

	if (!document.getElementById('searchexact').checked && !document.getElementById('searchword').checked)	 {
		alert("please check whether you wish to search for an exact match or any word");
		return false;
		}

	if (document.getElementById('category').selectedIndex == 0)	{
		alert("You have not selected an article category to search in.");
		document.getElementById('category').focus();
		return false;
		}

	if (!document.getElementById('intitle').checked && !document.getElementById('author').checked && !document.getElementById('inarticle').checked)	{
		alert("please check at least one checkbox for where you wish us to search.\n\narticle title's\n\nauthor names\n\nsarticle text");
		return false;
		}
	}

function checkContact()	{

	if (trim(document.getElementById('contact_name').value).length < 5)	{
		alert("Please enter your name (minimum 5 characters)");
		document.getElementById('contact_name').focus();
		return false;
		}

	if (!email_pattern.test(document.getElementById('contact_email').value))	{
		alert("The email address you have entered appears incorrect\n\nPlease check it and resubmit the form");
		document.getElementById('contact_email').focus();
		return false;
		}

	if (document.getElementById('contact_reason').selectedIndex == 0)	{
		alert("please select the reason for contacting adzines");
		document.getElementById('contact_reason').focus();
		return false;
		}

	if (trim(document.getElementById('contact_comments').value).length < 30)	{
		alert("Please enter your comments or questions in the text box provided");
		document.getElementById('contact_comments').focus();
		return false;
		}

	}

function checkArticleReport()	{
	if (document.getElementById('report_reason').selectedIndex == 0)	{
		alert("please select the reason for reporting this article");
		document.getElementById('report_reason').focus();
		return false;
		}
	if (!email_pattern.test(document.getElementById('reporters_email').value))	{
		alert("The email address you have entered in apears incorrect\n\nPlease check it and resubmit the form");
		document.getElementById('reporters_email').focus();
		return false;
		}

	if (document.getElementById('report_reason').selectedIndex == 5 && trim(document.getElementById('report_comments').value).length < 40)	{
		alert("anyone reporting an article using the 'other' reason must explain their reasons in the text box");
		document.getElementById('report_comments').focus();
		return false;
		}

	if (trim(document.getElementById('report_comments').value).length < 40)	{
		return confirm("You have not entered any explanation in the text box provided.\n\n To submit the form any way click OK, to enter comments please click cancel");
		}
	
	}

function checkArticleEmail()	 {
	if (trim(document.getElementById('friend_name').value).length < 5)	{
		alert("Please enter your friends name (minimum 5 characters)");
		document.getElementById('friend_name').focus();
		return false;
		}
	if (!email_pattern.test(document.getElementById('friend_email').value))	{
		alert("The email address you have entered in the friends email address box appears incorrect\n\nPlease check it and resubmit the form");
		document.getElementById('friend_email').focus();
		return false;
		}
	if (trim(document.getElementById('senders_name').value).length < 5)	{
		alert("Please enter your name (minimum 5 characters)");
		document.getElementById('senders_name').focus();
		return false;
		}
	if (!email_pattern.test(document.getElementById('senders_email').value))	{
		alert("The email address you have entered in the your email address box appears incorrect\n\nPlease check it and resubmit the form");
		document.getElementById('senders_email').focus();
		return false;
		}

	if (document.getElementById('email_body').value.indexOf("<a") != -1)	 {
		alert("Links are not allowed in the personal message!\n\nPlease remove it and resubmit the form.");
		document.getElementById('email_body').focus();
		return false;
		}

	
	}

function checkNewReview()	 {
	if (trim(document.getElementById('reviewers_name').value).length < 5)	{
		alert("Please enter your name");
		document.getElementById('reviewers_name').focus();
		return false;
		}
	if (!email_pattern.test(document.getElementById('reviewers_email').value))	{
		alert("The email address you have entered appears incorrect\n\nPlease check it and resubmit the form");
		document.getElementById('reviewers_email').focus();
		return false;
		}

	var ratings = new Array('rate_1', 'rate_2', 'rate_3', 'rate_4', 'rate_5');

	var has_checked_rating = false;
	loop :

	for (var x = 0 ; x < ratings.length ; x++)	{
		if (document.getElementById(ratings[x]).checked)	{
			has_checked_rating = true;
			break loop;
			}
		}

	if (!has_checked_rating)	{
		alert("Please rate this article using the checkboxes provided");
		return false;
		}

	if (trim(document.getElementById('review_text').value).length < 50)	 {
		alert("All reviews must contain a minimum of 50 characters");
		document.getElementById('review_text').focus();
		return false;
		}

	if (trim(document.getElementById('review_text').value).length > 255)	 {
		alert("All reviews must contain a maximum of 255 characters, please shorten your review");
		document.getElementById('review_text').focus();
		return false;
		}

	}

function checkAuthor()	{
	if (!email_pattern.test(document.getElementById('email_addy').value))	{
		alert("The email address you have entered appears incorrect, please check it and resubmit the form");
		document.getElementById('email_addy').focus();
		return false;
		}

	if (trim(document.getElementById('first_name').value).length < 3)	{
		alert("Please enter your first name, minimum 3 characters");
		document.getElementById('first_name').focus();
		return false;
		}

	if (trim(document.getElementById('last_name').value).length < 3)	{
		alert("Please enter your last name, minimum 3 characters");
		document.getElementById('last_name').focus();
		return false;
		}

	if (document.getElementById('country').selectedIndex == 0)	{
		alert("Please select your country");
		document.getElementById('country').focus();
		return false;
		}

	if (!document.getElementById('accepted_tos').checked)	 {
		alert("You must read and accept the terms and conditions to become an author");
		return false;
		}
	}

function trim(str)	{  
	while(str.charAt(0) == " ")	{  
		str = str.substring(1);
		}
	while(str.charAt(str.length-1) == " " )	{  
		str = str.substring(0,str.length-1);
		}
  return str;
}

function openWindow(url)	{
	window.open(url,"Link","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=600,height=500,left=30,top=80");
	}

function showChars()	{
	if (trim(document.getElementById('review_text').value).length != 0)	{

		var totalLeft = 255 - document.getElementById('review_text').value.length;

		if (totalLeft == 0)	{
			document.getElementById('counter').innerHTML = "<b>No characters Left!</b>";
			}
		else if (totalLeft < 0)	{
			var over = document.getElementById('review_text').value.length - 255;
			document.getElementById('counter').innerHTML = "<b>" + over + " characters over limit!</b>";
			}
		else	{
			document.getElementById('counter').innerHTML = totalLeft + " characters left";
			}

		}
	}