function strTrim(tmpStr)
{
	tmpStr = tmpStr.replace(/^\s+/,"");//remove leading
	tmpStr = tmpStr.replace(/\s+$/,"");//remove trailing
	return tmpStr;
}

//------------------------------------------------------------------------------------
function trimFields()
{
	for(var i=0; i < obj.elements.length; i++)
	{
		if(obj.elements[i].type == "text" || obj.elements[i].type == "textarea" || obj.elements[i].type == "password")
		{
			obj.elements[i].value = strTrim(obj.elements[i].value);
		}
	}
}

// Function to validate email
function chkEmail(tmpStr)
{
	var email_pat = /^[a-z][a-z0-9_\.\-]*[a-z0-9]@[a-z0-9]+[a-z0-9\.\-_]*\.[a-z]+$/i;
	return(email_pat.test(tmpStr));
}

//Checks URL against pattern
function chkURL(tmpStr)
{
	var url_pat = /^(http|https|ftp):\/\/([\w-]+\.)+[\w-]+(\/[\w-\.\/?%&amp;,=#@\/:]*)?/;
	return(url_pat.test(tmpStr));
}

//Checks coupon code
function chkCoupon(tmpStr)
{
	var coupon_pat = /^[A-Z0-9]+$/;
	return(coupon_pat.test(tmpStr));
}

function validateSearch()
{
	if(strTrim($('#keywords').val()) == '' || strTrim($('#keywords').val()) == 'Site Search')
	{
		alert("Please enter the Keywords.");
		$('#keywords')[0].focus();
		return false;
	}
}
function validateSubscribe()
{
	var obj = document.frmNewsletter;
	if(obj.newsletter_email.value == '' && obj.newsletter_email.value == 'JOIN THE NEWSLETTER')
	{
		alert("Please enter your Email Address.");
		obj.newsletter_email.focus();
		return;
	}
	if(!chkEmail(obj.newsletter_email.value))
	{
		alert("Please enter a valid Email Address.");
		obj.newsletter_email.focus();
		obj.newsletter_email.select();
		return;
	}
	$('#newsletter_loader')[0].innerHTML = '<img src="img/ajax-loader1.gif" alt="Loader" style="vertical-align:middle"> <span style="color:#B3B3B3;font-size:7pt;">Please wait</span>';
	params = 'email='+ obj.newsletter_email.value;
	params+= '&hash='+Math.floor(Math.random()*11);
	 $.ajax({
	   type: "GET",
	   data: params,
	   url: "subscribe_newsletter.php",
	   success: function(retVal){
			switch(retVal)
			{
				case "SUCCESS":
					subscribeMsg = 'Thank you for subscribing to the Locker Room updates!';
					break;
				case "EXISTING":
					subscribeMsg = 'You are already subscribed for the TheLockerRoom Monthly Newsletter.';
					break;
				case "NEED_ACTIVATION":
					subscribeMsg = 'You need to activate your subscription.\nWe are sending you another mail incase you have deleted our mail received earlier.\nPlease click on the link specified in your mail to activate your subscription.';
					break;
				default:
					subscribeMsg = "Error occured.";
					break;
			}
			alert(subscribeMsg);
			$('#newsletter_msg').slideDown();
			$('#newsletter_loader')[0].innerHTML = '<input type="button" value="Submit" class="btn" onclick="javascript:validateSubscribe()">'
			obj.reset();
	   }
   });
}
function validateSubscriberExport()
{
	if(confirm('Are you sure you want to export the Subscribers?\nYou will only get the list of active Subscribers'))
	{
		alert("Please wait a few seconds while the list is exported.");
		parent.frames['fraSubExport'].location.href = 'export_csv.php?opt=subscribers';
	}
}
function validateCustomerExport()
{
	if(confirm('Are you sure you want to export the Customers?\nYou will get the list of Customers who have made purchases.'))
	{
		alert("Please wait a few seconds while the list is exported.");
		parent.frames['fraSubExport'].location.href = 'export_csv.php?opt=ordered_subscribers';
	}
}
function validateSearch()
{
	if(strTrim($('#keywords').val()) == '' || strTrim($('#keywords').val()) == 'Site Search')
	{
		alert("Please enter the Keywords.");
		$('#keywords')[0].focus();
		return false;
	}
}































