	// Global Variables
	var wlehaveerrors=0;
	var wlemsg="";


	function checkWLUpdateComments(abc)
	{
	wlehaveerrors=0;
	wlemsg="";
		var userInput=abc.User_Comments.value;
		userInput=wlreplace(userInput,"\u0022","`"); //double quotes
		userInput=wlreplace(userInput,"\u0027","`"); //single quotes 
		if(userInput.length>250)
		{
			wlemsg += "Comments can not be more than 250 characters.\n";
			wlehaveerrors=1;	
		}	
		isValidUserInputDesc(userInput);
	if(wlehaveerrors==0)
		{
		abc.User_Comments.value=userInput;
		return true;
		}
		else
		{
		showErrorMsg();
		return false;
		}
	return(!wlehaveerrors);
	}

	function isValidUserInputDesc(field1)
	{
	var valid="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ,.~`!@#$%^&*()_+-=~:;?|{}0123456789><[]/";
	var ok="yes";
	var temp;
	if (field1==null || field1=="")
	{
		return true;
	}
		for (var i=0;i<field1.length;i++)
		{
			temp = "" + field1.substring(i,i+1);
			if (valid.indexOf(temp)=="-1")
			{ 
			//check for carriage return
				if (temp == "\u000D" || temp =="\u000A")					
				{
					ok="yes";
				}
				else
				{
						ok="no";
						break;
				}					
			}
		}

		if (ok=="no")
		{
		
			wlemsg += "Description cannot contain any special characters.\n";
			wlehaveerrors=1;
			return false;
		}
		else
		{
			return true;
		}
	}


	function checkWLEmail()
	{

	 haveerrors="0"
	 var emailid = ""
	 emailstring=document.Send_Email.email_address_list.value;
	 emailstring=trim(emailstring);
	 emailstring=removelastcomma(emailstring);
	 emailstring=wlreplace(emailstring,"\u000A",""); //line feed
	 emailstring=wlreplace(emailstring,"\u000D",""); //carraige return
	 emailstring=wlreplace(emailstring,"\u0009",""); //tab
	 emailstring=wlreplace(emailstring,"\u0020",""); //space
	 emailstring=wlreplace(emailstring,"\u0022",""); //double quotes
	 emailstring=wlreplace(emailstring,"\u0027",""); //single quotes 
	 emailstring=wlreplace(emailstring,"\u005C",""); //back slash 
	 errorString="The following email address(s) are invalid. Please enter coma(,) seperated valid email addresses.\n\n";
	 var arrTemp = emailstring.split(",");
	 for(i=0;i<arrTemp.length;i++)
	 {
		emailid=arrTemp[i];

		if(emailid.length>0)
		{
				isWLValidEmailAddress(emailid);
				if(wlehaveerrors=="1")
				{
					errorString+=emailid;
					errorString+="\n"
					wlemsg=""
					wlehaveerrors="0"
					haveerrors="1"
				}
		}
	 }

	 if(haveerrors=="1")
	 {
		alert(errorString);
		return false;
	 }
	 return true;
	} // end of checkWLEmail


	//--------------------------------

	function isWLValidEmailAddress(emailStr)
	{
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)<>@,&;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

	if (emailStr==null || emailStr=="")
	{
		return true;
	}


	if (emailStr.substring(0,4)=="www." || emailStr.substring(0,4)=="WWW.")
	{
		wlemsg += "The e-mail address you have entered is invalid.\nPlease remove the www. portion and try again.\n";
		wlehaveerrors=1;
		return false;
	}

	var matchArray=emailStr.match(emailPat);
	if (matchArray==null)
	{
		wlemsg += "The e-mail address you have entered is invalid.\n";
		wlehaveerrors=1;
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];

	// See if "user" is valid 
	if (user.match(userPat)==null)
	{
		// user is not valid
		wlemsg += "The e-mail address you have entered is invalid.\n";
		wlehaveerrors=1;
		return false;
	}

	/* if the e-mail address is at an IP address (as opposed to a symbolic
	   host name) make sure the IP address is valid. */
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null)
	{
		// this is an IP address
		  for (var i=1;i<=4;i++)
		  {
			if (IPArray[i]>255)
			{
				wlemsg += "The IP address of the e-mail address you have entered is invalid.\n";
			wlehaveerrors=1;
			return false;
			}
		}
		return true;
	}

	// Domain is symbolic name
	var domainArray=domain.match(domainPat);
	if (domainArray==null)
	{
		wlemsg +=  "The domain name of the e-mail address you have entered is invalid.\n";
		wlehaveerrors=1;
		return false;
	}

	/* domain name seems valid,but now make sure that it ends in a
	   three-letter word (like com,edu,gov) or a two-letter word,
	   representing country (us,uk,nl),and that there's a hostname preceding 
	   the domain or country. */

	var atomPat=new RegExp(atom,"g");
	var domArr=domain.match(atomPat);
	var len=domArr.length;
	if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3)
	{
	   // the address must end in a two letter or three letter word.
	   wlemsg +=  "E-mail addresses must end in a three-letter domain,or two-letter country code.\n";
	   wlehaveerrors=1;
	   return false;
	}

	// Make sure there's a host name preceding the domain.
	if (len<2)
	{
	   wlemsg += "The e-mail address you have entered is missing a hostname.\n";
	   wlehaveerrors=1;
	   return false;
	}

	return true;
	}




	//--------------------------------

	function removelastcomma(mailstr)
	{
		while (1)
		{
			if(mailstr.charAt(mailstr.length-1)!=",")
			break;
			mailstr=mailstr.substring(0,mailstr.length-1);
		}	
		return mailstr;
	}



	function trim(argvalue) 
	{
		var tmpstr = ltrim(argvalue);
		return rtrim(tmpstr);
	}

	function ltrim(argvalue) 
	{
		while (1) 
		{
				if (argvalue.substring(0, 1) != " ")
				break;
				argvalue = argvalue.substring(1, argvalue.length);
		}
	  return argvalue;
	}

	function rtrim(argvalue) 
	{
	  while (1) 
	  {
			if (argvalue.substring(argvalue.length - 1, argvalue.length) != " ")
			break;
			argvalue = argvalue.substring(0, argvalue.length - 1);
	  }
	  return argvalue;
	}



	function wlreplace(argvalue, x, y) 
	{
	  while (argvalue.indexOf(x) != -1) 
	  {
		var leading = argvalue.substring(0, argvalue.indexOf(x));
		var trailing = argvalue.substring(argvalue.indexOf(x) + x.length, 
		argvalue.length);
		argvalue = leading + y + trailing;
	  }

	  return argvalue;
	}

	function showErrorMsg()
	{
		var msgNN=wlemsg.replace(/<br>/gi,"\n");
		alert(msgNN);
	}

	//-----------------------------------------------------

	function checkWLCustomerData()
	{
	wlehaveerrors=0;
	wlemsg="";
	nameisnull = 0;
	emailisnull = 0;
		//Define form fields
		var userName=document.WLsearch.WL_Cust_Name.value;
		var emailAddress=document.WLsearch.WL_Cust_Email.value;

		userName=trim(userName);
		emailAddress=trim(emailAddress);
		emailAddress=wlreplace(emailAddress,"\u0020",""); //space
		
		document.WLsearch.WL_Cust_Name.value=userName;
		document.WLsearch.WL_Cust_Email.value=emailAddress;

		if (userName==null || userName=="")
		{
			nameisnull = 1;
		}

		if (emailAddress==null || emailAddress=="")
		{
			emailisnull = 1;
		}	

		if (nameisnull ==1 && emailisnull ==1)
		{
			wlemsg += "Please input either name or e-mail address.\n";
			showWLErrorMsg(wlemsg);
			return false;
		}

		if (nameisnull==0)
		{
			if (userName.length < 2)
			{	
				if (emailisnull==0)
				{
					isWLValidUserName(userName);							
				}
				else
				{
					wlemsg += "Please enter a minimum of two characters in the name field for getting a search result.\n";
					showWLErrorMsg(wlemsg);
					return false;
				}
			}
			else		
			{
				isWLValidUserName(userName);
			}
		}

		if (emailisnull==0)
		{
			isWLValidEmailAddress(emailAddress);
		}

		if(wlehaveerrors==0)
		{
			document.WLsearch.submit();
		}
		else
		{
			showWLErrorMsg(wlemsg);
			return false;
		}

	return(!wlehaveerrors);
	}

	function isWLValidUserName(field)
	{
	var valid="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-, ";
	var ok="yes";
	var temp;
	if (field==null || field=="")
	{
		return true;
	}
	for (var i=0;i<field.length;i++)
	{
		temp = "" + field.substring(i,i+1);
		if (valid.indexOf(temp)=="-1") ok="no";
	}
		if (ok=="no")
		{
		wlemsg += "Name cannot contain any special characters.\n";
		wlehaveerrors=1;
		return false;
		}
		else
		{
		return true;
		}
	}


	function showWLErrorMsg(wlerror)
	{
		var msgNN=wlerror.replace(/<br>/gi,"\n");
		alert(msgNN);
	}

		function validateQTY(qty_object){
			qty_value = qty_object.value.replace(/\D/g, '');
			if(qty_value == "" || qty_value == 0){ qty_value = 1; }
			qty_object.value = qty_value;
		}

function checkAddToGearBag()
{
	var products = document.getElementsByName('OMProductId');

	for (var i=0; i < products.length; i++) {
		if (products.item(i).checked == true) {
			return true; // make true
		}
	}

	alert('Please select at least one item to add to your Gear Bag.');
	return false;
}