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

function submitFrm(theForm)
{
	var v = new RegExp();
	v.compile(/^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/ );
	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.url.value) == "")
	{
		alert ("Oops! You forgot to enter the URL..");
		return false;
	}
	if(theForm.modification[0].checked == false && theForm.modification[1].checked == false)
	{
		alert ("Oops! You forgot to choose an option for - Last Modification, Please select an option.");
		return false;
	}
	if(theForm.modification[1].checked == true) {
		if(trim(theForm.dateText.value) == "") {
			alert("You chose Enter Date in (Last modification field). Please enter a date and time in the suggested format; OR Choose None if you chose (Enter Date) accidentally.");
			return false;
		} else {
			var datePattern = "[0-9][0-9][0-9][0-9]-[0-1][0-9]-[0-3][0-9] [0-2][0-9].[0-5][0-9].[0-5][0-9]";
			var enteredDT = trim(theForm.dateText.value);
			if(!enteredDT.match(datePattern) ) {
				alert ("Sorry! The entered date/time is in an invalid format. Please re-enter in the suggested format.");
				return false;
			}
		}
	}
	if(!v.test(theForm.url.value))
	{
		alert("We're afraid the URL format entered is invalid! Please re-enter the URL as http://www.domain.com; OR www.domain.com.");
		return false;
	}
	if(theForm.pageCount.value == 5)
	{
		if(confirm(" You have requested to process a request for upto 5 pages. Please click OK to continue."))
		{
			showPopup();
			return true;
		}
		else
			return false;
	}
	if(theForm.pageCount.value == 25)
	{
		if(confirm(" You have requested to process a request for upto 25 pages. Please click OK to continue."))
		{
			showPopup();
			return true;
		}
		else
			return false;
	}
	if(theForm.pageCount.value == 50)
	{
		if(confirm("You have requested to process a request for upto 50 pages. Please click OK to continue."))
		{
			showPopup();
			return true;
		}
		else
			return false;
	}
	if(theForm.pageCount.value == 200)
	{
		if(confirm("Processing the request for upto 200 pages will send the result report to you in an email. Please click OK to continue."))
		{
			//showPopup();
			return true;
		}
		else
			return false;
	}
	if(theForm.pageCount.value == 500)
	{
		if(confirm("Processing the request for upto 500 pages will send the result report to you in an email. Please click OK to continue. "))
		{
			//showPopup();
			return true;
		}
		else
			return false;
	}
	if(theForm.pageCount.value == 1000)
	{
		if(confirm("Processing the request for upto 1000 pages will send the result report to you in an email. Please click OK to continue. "))
		{
			//showPopup();
			return true;
		}
		else
			return false;
	}
	//showPopup();
	return true;

}
