/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

function submitFrm(theForm)
{

	function trim( str )
	{
		str = str.replace(/^\s+/, "");
		for( var i = str.length-1; i > 0;--i )
		{
			if( /\S/.test( str[i] ) ) {
				str = str.substring( 0, i+1 );
				break;
			}
		}
		return str;
	}

	String.prototype.trimAll = function()
	{
		return this.replace(/\s+/g,"");
	}

	if(trim(theForm.keyword.value) == "")
	{
		alert ("Oops... no keyword entered! Please re-enter and try again.");
		return false;
	}
	result = (theForm.keyword.value).split("\n");

	var resultCount = 0;
	var temp2 =new Array();

	for(i=0; i<result.length; i++)
	{
		var v = new RegExp();
		v.compile("[A-Za-z0-9]$");
		var temp3=trim(result[i]);

		if(trim(temp3)!="")
		{
			if (!v.test(temp3))
			{
				alert(" Sorry! We can't process the request with special characters included. Please remove them and continue.");
				return false;

			}
			temp2[resultCount]=temp3.trimAll();
			resultCount++;
		}
	}

	if(theForm.submitID.value == 0 && resultCount > 1)
	{
		if(confirm("You have entered "+resultCount+" Keywords. Entering more than 1 keyword requires you to login. Please login and try again."))
		{
			//showPopup();
			return true;
		}
		else
			return false;
	}
	if(theForm.submitID.value == 0 && resultCount <= 1)
	{
		//showPopup();
		return true;
	}
	if(theForm.submitID.value == 1 )
	{
		if(resultCount > 1 && resultCount <= 5 )
		{
			if(confirm("You have entered "+resultCount+" Keywords. Entering 2 to 5 keywords will shortly send the results to you in an email. Please click OK to proceed!"))
			{
				//showPopup();
				return true;
			}
			else
				return false;
		}
		if(resultCount > 5 && resultCount <= 10 )
		{
			if(confirm("You have entered "+resultCount+" Keywords. Entering 6 to 10 keywords will shortly send the results to you in an email. Please click OK to proceed!"))
			{
			//	showPopup();
				return true;
			}
			else
				return false;
		}
		if(resultCount > 10 && resultCount <= 15 )
		{
			if(confirm("You have entered "+resultCount+" Keywords. Entering 11 to 15 keywords will shortly send the results to you in an email. Please click OK to proceed!"))
			{
			//	showPopup();
				return true;
			}
			else
				return false;
		}
		
		if(resultCount > 15)
		{
			alert ("Oops... too many keywords! Please enter less than 15 Keywords at a time.");
			return false;
		}
	}
	//showPopup();
	return true;


}


