/* --------------------------------------------------------------------------
 * A simple object to maintain any functions required by the application
 * --------------------------------------------------------------------------
 */
var truness = 
{
	Version: '1.0.0'
}

truness.validateNewCompany = function()
{
	var errorMessage = "";
	if( $F('company_name') == null || $F('company_name') == "" )
		errorMessage += "A company name is required\n";
	if( !$('agree').checked )
		errorMessage += "You must agree to the terms and conditions\n";
	if( $F('captcha') == null || $F('captcha') == "" )
		errorMessage += "You must enter the code seen in the image\n";
	if( errorMessage == "" )
		return true;
	else
	{
		alert(errorMessage);
		return false;
	}
}

truness.validateNewReview = function()
{
	var errorMessage = "";
	if( $F('review_rating') == 0 && ( $F('review_comments') == null || $F('review_comments') == "" ) )
		errorMessage += "You must enter either a rating or a review for the company\n";
	if( !$('agree').checked )
		errorMessage += "You must agree to the terms and conditions\n";
	if( $F('captcha') == null || $F('captcha') == "" )
		errorMessage += "You must enter the code seen in the image\n";
	if( errorMessage == "" )
		return true;
	else
	{
		alert(errorMessage);
		return false;
	}
}

truness.validateNewCorrespondence = function()
{
	var errorMessage = "";
	if( $F('correspondence_name') == null || $F('correspondence_name') == "" )
		errorMessage += "You must enter your name\n";
	if( $F('correspondence_comments') == null || $F('correspondence_comments') == "" )
		errorMessage += "You must provide some comments\n";
	if( $F('correspondence_email') != "" && !$F('correspondence_email').match(/^([^@\s]+)@((?:[-a-z0-9]+.)+[a-z]{2,})$/i) )
		errorMessage += "You have entered an invalid email\n";
	if( $F('captcha') == null || $F('captcha') == "" )
		errorMessage += "You must enter the code seen in the image\n";
	if( errorMessage == "" )
		return true;
	else
	{
		alert(errorMessage);
		return false;
	}
}

truness.findCompany = function()
{
	var company = prompt("What company will you review?");
	if( company != null && company != "" && company.replace(/\s*/, "") )
	{
		document.location = location.href + "search?c=" + company;
	}
}

truness.SaveDisplayPreference = function(id)
{
	var index = location.href.lastIndexOf('/') + 1;
	var path  = location.href.substring(index);
	
	if( utility.getCookie && utility.getCookie(id) == 'true' )
		utility.eraseCookie(id, path);
	else
		utility.createCookie(id, 'true', 365, path);
}