
function isSQLInjectionChars(id){

      var strValue = document.getElementById(id).value ;
        if(strValue != '' && strValue != null){
               var badChars= new Array("/","*","#","select", "drop", ";", "--", "insert","delete", "xp_","1=1","1=1--","=","1=1");
                  for(var i=0; i< badChars.length; i++){
                       if(strValue.replace(badChars[i],'') != strValue ){
                           strValue = strValue.replace(badChars[i],'');
                           alert('Invalid Entry');
                           document.getElementById(id).value='';
                           window.setTimeout(function ()
                                        {
                                            document.getElementById(id).focus();

                                        }, 0);

                           return false ;

                       }//end of if

                }//end of for   

     }//end of if

}//end of function           

/**************************************************
Function : isAlphabetic
Parameters : valueToCheck
Usage : Checks whether the entered value is alphabeticals only
Author : M1008751
Returns : Boolean, returns True if condition is satisfied else False.

**************************************************/

		function isAlphabetic(valueToCheck)
		{
		
		var alphabetpattern = /(\/|-|\.|\\|!|\*|\?|\+|&|\$|%|\^|=|`|~|_|\(|\)|\{|\}|\[|\]|"|<|>|:|;|\,|'|[0-9]|@|#)/
		
		var patternValue = valueToCheck;
		patternMatch = alphabetpattern;
		msgValue = "Only alphabets are allowed.";
		var alphaChars=patternValue.match(alphabetpattern);
		
		if(alphaChars!=null)
		{
		//changeColor(document.forms[0].elements[i]);
		alert(msgValue);
		valueToCheck.focus();
		return 1;
		}
		return 0;
		}

/**************************************************
Function : isAlphaNumeric
Parameters : fieldValue 
Usage : Checks whether the entered value is alphanumeric and not numbers only
Returns :  returns 0 if condition is satisfied else 1.
Author : M1008751
**************************************************/

		function isAlphaNumeric(fieldValue){
		
		strValue = fieldValue;
		
		if(strValue.length != 0)
		{
		var Chars = "~`!@#$%^&*()_+=.{}[]:;'<>?,./-\\|";
		var Chars1 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
		var temp = "";
		
		for (var i = 0; i < strValue.length; i++) {
		if (!(Chars.indexOf(strValue.charAt(i)) == -1)){
		alert("Please enter alphabets, numbers only");
		
		
		return 1;
		}
		if((Chars1.indexOf(strValue.charAt(i)) == -1)){
		
		}else{
		temp = "Y";
		}
		}
		if(temp=="Y"){
		}else{
		alert("Please do not enter numbers only");
		
		return 1;
		}
		}
		return 0;
		}

/**************************************************
Function : isIntegerPositive
Parameters :fieldValue 
Usage : Checks whether the entered integer value is positive only
Author : M1008751
Returns :  returns 0 if condition is satisfied else 1.

**************************************************/


		function isIntegerPositive(fieldId){
				
	 	var str = document.getElementById(fieldId).value;
		tempVal=0;
		
		
		
		if (isNaN(str)){
		alert("Invalid entry!\n\nEnter positive numbers only");
		setFieldFocus(fieldId);
		return 1;
		}
			
		if(str.indexOf('-')== 0)
		{
		alert("Invalid entry!\n\nEnter positive numbers only");
		setFieldFocus(fieldId);
		return 1;
		}
		
		
		/*commented on 11/13/2009 for allowing users to enter decimal in card balance*/
		/*if(str.indexOf('.')>=0)
		{
		alert("Invalid entry!\n\nEnter a non-decimal number");
		setFieldFocus(fieldId);
		return 1;
		}*/
		if(parseInt(str)<parseInt(tempVal))
		{
		alert("Invalid entry!\n\nEnter a positive number ");
		setFieldFocus(fieldId);
		return 1;
		}
		
		return 0;
		}
		
		
		
		

/**************************************************
Function : isValidFloat
Parameters : fieldValue,decPrec
Usage : Checks whether the entered float value is valid or not
Author : M1008751
Returns : Boolean, returns T0rue if condition is satisfied else 1.

**************************************************/
		function isValidFloat(fieldValue, decPrec){
		str=fieldValue;
		var tempor=0;
		if (isNaN(str)){
		alert("Invalid entry!\n\nEnter numbers Only.");
		field.focus();
		return 1;
		}
		
		if(parseFloat(str)<=parseFloat(tempor)){
		alert("Invalid entry!\n\nEnter a number greater than 0.");
		field.focus();
		return 1;
		
		}
		var nos=str.split(".");
		if (nos.length>1){
		if(nos[1].length > decPrec){
		alert("Invalid entry!\n\nDecimal Precision of " + decPrec + " exceeded.");
		field.focus();
		return 1;
		}
		}
		return 0;
		}

/**************************************************
Function : isEmailValid
Parameters : emailId
Usage : Checks whether the entered email id is valid or not
Author : M1008751
Returns : Boolean, returns True if condition is not satisfied  else False.

**************************************************/
		function isEmailValid(emailId) {
		
			
				var at="@"
				var dot="."
				var email=document.getElementById(emailId).value;
				var lat=email.indexOf(at)
				var lstr=email.length
				var ldot=email.indexOf(dot)
				if (email.indexOf(at)==-1){
				   alert("Invalid E-mail ID , Valid Format abc@abc.com")
				   setFieldFocus(emailId);
				   return false;
				}
		
				if (email.indexOf(at)==-1 || email.indexOf(at)==0 || email.indexOf(at)==lstr){
				  alert("Invalid E-mail ID , Valid Format abc@abc.com");
				  setFieldFocus(emailId);
				   return false;
				}
		
				if (email.indexOf(dot)==-1 || email.indexOf(dot)==0 || email.indexOf(dot)==lstr){
				    alert("Invalid E-mail ID , Valid Format abc@abc.com");
				    setFieldFocus(emailId);
				    return false;
				}
		
				 if (email.indexOf(at,(lat+1))!=-1){
				   alert("Invalid E-mail ID , Valid Format abc@abc.com");
				   setFieldFocus(emailId);
				   return false;
				 }
		
				 if (email.substring(lat-1,lat)==dot || email.substring(lat+1,lat+2)==dot){
				    alert("Invalid E-mail ID , Valid Format abc@abc.com");
				    setFieldFocus(emailId);
				    return false;
				 }
		
				 if (email.indexOf(dot,(lat+2))==-1){
				     alert("Invalid E-mail ID , Valid Format abc@abc.com");
				     setFieldFocus(emailId);
				     return false;
				 }
				
				 if (email.indexOf(" ")!=-1){
				     alert("Invalid E-mail ID , Valid Format xxx@xxx.com");
				     setFieldFocus(emailId);
				     return false;
				 }
		
		 		 return true						
			}


/**************************************************
Function : isDateValid
Parameters : dtStr
Usage : Checks whether the entered date is valid or not
Author : M1008751
Returns : Boolean, returns True if condition is satisfied else False.

**************************************************/
		var dtCh= "/";
		var minYear=1900;
		var maxYear=2100;
		
			function isDateValid(dtStr){
			
			var daysInMonth = DaysArray(12)
			var pos1=dtStr.indexOf(dtCh)
			var pos2=dtStr.indexOf(dtCh,pos1+1)
			var strDay=dtStr.substring(0,pos1)
			var strMonth=dtStr.substring(pos1+1,pos2)
			var strYear=dtStr.substring(pos2+1)
			strYr=strYear
			if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
			if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
			for (var i = 1; i <= 3; i++) {
				if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
			}
			month=parseInt(strMonth)
			day=parseInt(strDay)
			year=parseInt(strYr)
			if (pos1==-1 || pos2==-1){
				alert("The date format should be : dd/mm/yyyy")
				return false
			}
			if (strMonth.length<1 || month<1 || month>12){
				alert("Please enter a valid month")
				return false
			}
			if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
				alert("Please enter a valid day")
				return false
			}
			if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
				alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
				return false
			}
			if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
				alert('Invalid Date!\n\nDo not enter any special characters space or alphabets.');
		
				return false
			}
		return true
		}
		
		
		function daysInFebruary (year){
				// February has 29 days in any year evenly divisible by four,
				// EXCEPT for centurial years which are not also divisible by 400.
				return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
		}
		
		
		function isInteger(s)
		{
			var i;
			for (i = 0; i < s.length; i++)
			{
			// Check that current character is number.
			var c = s.charAt(i);
			if (((c < "0") || (c > "9")))
			return false;
			}
			// All characters are numbers.
			return true;
		}

		
		function stripCharsInBag(s, bag)
		{
			var i;
			var returnString = "";
			// Search through string's characters one by one.
			// If character is not in bag, append to returnString.
			for (i = 0; i < s.length; i++){
			var c = s.charAt(i);
			if (bag.indexOf(c) == -1) returnString += c;
			}
			return returnString;
		}
		
		function DaysArray(n) {
			for (var i = 1; i <= n; i++) {
			this[i] = 31
			if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
			if (i==2) {this[i] = 29}
			}
			return this
		}
/**************************************************
Function : isPasswordValid
Parameters :strPwd
Usage : Checks whether the entered password is valid or not
Author : M1008751
Returns : Boolean, returns True  if condition is  satisfied else False.

**************************************************/
		function isPasswordValid(strPwd){
		
		
		var invalid = " "; // Invalid character is a space
		var minLength = 5; // Minimum length
		var maxLength = 50;
		// check for minimum length
		if (strPwd.length < minLength) {
		alert('Your password must be at least ' + minLength + ' characters long. Try again.');
		return false;
		}
		
		// check for maximum length
		if (strPwd.length > maxLength) {
		alert('Your password length exceeded ' + maxLength + ' characters . Try again.');
		return false;
		}
		
		
		// check for spaces
		if (strPwd.indexOf(invalid) > -1) {
		alert("Sorry, spaces are not allowed.");
		return false;
		}
		
		return true;
		     }
/**************************************************
Function : checkFieldLength
Parameters : fieldName,valueToCheck,minLength,maxLength
Usage : Checks whether the entered password is valid or not
Author : M1008751
Returns : Boolean, returns True  if condition is  satisfied else False.

**************************************************/
		function checkFieldLength(fieldName,valueToCheck,minLength,maxLength){
		
		
		var invalid = " "; // Invalid character is a space
		var minLength = minLength; // Minimum length
		var maxLength = maxLength;
		// check for minimum length
		
			if(maxLength != '' && minLength != ''){	
				
				if(maxLength < minLength ){
		                 return false;
				}
		
				if (valueToCheck.length < minLength) {
				alert(' '+fieldName+' Value must be at least ' + minLength + ' characters long. Try again.');
				return false;
				}
		
				// check for maximum length
				if (valueToCheck.length > maxLength) {
				alert(' '+fieldName+' Value length exceeded ' + maxLength + ' characters . Try again.');
				return false;
				}
		
		
				// check for spaces
				if (valueToCheck.indexOf(invalid) > -1) {
				alert("Sorry, spaces are not allowed.");
				return false;
				}
		
				return true;
		  }else{
			return false;
		  }
		
		}
		  


  /**************************************************
Function : isPercentValid
Parameters :valueToCheck
Usage : Checks whether the entered donation percentage is valid or not
Author : M1008751
Returns : Boolean, returns True  if condition is  satisfied else False.

**************************************************/
  
		  function isPercentValid(fieldId){
		
		
			var percentage = document.getElementById(fieldId).value;
			
		    var percentArray = new Array(1,2,3,4,5,6,7,8,9,10,
						11,12,13,14,15,16,17,18,19,20,
						21,22,23,24,25,27,27,28,29,30,
						31,32,33,34,35,36,37,38,39,40,
						41,42,43,44,45,46,47,48,49,50,
						51,52,53,54,55,56,57,58,59,60,
						61,62,63,64,65,66,67,68,69,70,
						71,72,73,74,75,76,77,78,79,80,
						81,82,83,84,85,86,87,88,89,90,
						91,92,93,94,95,96,97,98,99);
											
		   		
					if(percentage != ''){
		  
							
						if(isIntegerPositive(fieldId) != 1){
							
						 for(var index=0; index < percentArray.length ; index++){
		
									   if(percentage == percentArray[index]){
										 return true;
									   }
						 
									   if(index == percentArray.length-1){
											alert("Invalid entry Please enter Values between 1 and 99");
											setFieldFocus(fieldId);
											return false;
									   }
						 
						 	}//end of for
		
			 
						 }
			 
			  }//end of if percentage
			 else{
					alert("Invalid entry Please enter Values between 1 and 100");
					setFieldFocus(fieldId);
					return false;
			 }
			
		}


  /**************************************************
Function : setFieldFocus
Parameters :fieldId
Usage : This method is to set the field focus based on the Field id
Author : M1008751


**************************************************/
  	 
		  function setFieldFocus(fieldId){
		  
		      document.getElementById(fieldId).value='';
                           window.setTimeout(function ()
                                        {
                                            document.getElementById(fieldId).focus();

                                        }, 0);
		
		  
		  }
		  
		  
		  
		  
		  
		  function check(){
			 
			  document.getElementById('enterEmail').style.visibility = 'hidden'; 
			  document.getElementById('validateEmail').style.visibility = 'hidden'; 


			  }

			  function isEmailValidContact(emailId) {
				 

			  var at="@"
			  var dot="."
			  var lat=emailId.indexOf(at)
			  var lstr=emailId.length
			  var ldot=emailId.indexOf(dot)
			  if (emailId.indexOf(at)==-1){

			  document.getElementById('enterEmail').style.visibility = 'visible'; 
			  document.getElementById('validateEmail').style.visibility = 'visible'; 
			  document.getElementById('validateEmail').className = 'error';
			  document.getElementById('lbEmail').className = 'error';
			  return false
			  }

			  if (emailId.indexOf(at)==-1 || emailId.indexOf(at)==0 || emailId.indexOf(at)==lstr){

			  document.getElementById('enterEmail').style.visibility = 'visible'; 
			  document.getElementById('validateEmail').style.visibility = 'visible'; 
			  document.getElementById('validateEmail').className = 'error';
			  document.getElementById('lbEmail').className = 'error';
			  return false
			  }

			  if (emailId.indexOf(dot)==-1 || emailId.indexOf(dot)==0 || emailId.indexOf(dot)==lstr){

			  document.getElementById('enterEmail').style.visibility = 'visible'; 
			  document.getElementById('validateEmail').style.visibility = 'visible'; 
			  document.getElementById('validateEmail').className = 'error';
			  document.getElementById('lbEmail').className = 'error';
			  return false
			  }

			  if (emailId.indexOf(at,(lat+1))!=-1){

			  document.getElementById('enterEmail').style.visibility = 'visible'; 
			  document.getElementById('validateEmail').style.visibility = 'visible'; 
			  document.getElementById('validateEmail').className = 'error';
			  document.getElementById('lbEmail').className = 'error';
			  return false
			  }

			  if (emailId.substring(lat-1,lat)==dot || emailId.substring(lat+1,lat+2)==dot){

			  document.getElementById('enterEmail').style.visibility = 'visible'; 
			  document.getElementById('validateEmail').style.visibility = 'visible'; 
			  document.getElementById('validateEmail').className = 'error';
			  document.getElementById('lbEmail').className = 'error';
			  return false
			  }

			  if (emailId.indexOf(dot,(lat+2))==-1){

			  document.getElementById('enterEmail').style.visibility = 'visible'; 
			  document.getElementById('validateEmail').style.visibility = 'visible';
			  document.getElementById('validateEmail').className = 'error';
			  document.getElementById('lbEmail').className = 'error'; 
			  return false
			  }

			  if (emailId.indexOf(" ")!=-1){

			  document.getElementById('enterEmail').style.visibility = 'visible'; 
			  document.getElementById('validateEmail').style.visibility = 'visible'; 
			  document.getElementById('validateEmail').className = 'error';
			  document.getElementById('lbEmail').className  = 'error';
			  return false
			  }

			  return true
			  }
		  
		  
			  /*
			   * Validates create Merchant alert Form.
			   */
			  function validateMerchantForm(merchantForm){
				  
				  var merchantName=merchantForm.merchantName.value;
				  var merchantEmailId=merchantForm.emailId.value;
				  var bool=true;

				  if(trim(merchantName)==null || trim(merchantName)==""){
				     alert("Please Enter Merchant Name");
				     bool=false;
				     merchantForm.merchantName.focus();
				     return;
				  }
				  if(trim(merchantEmailId)==null || trim(merchantEmailId)==""){
				     alert("Please Enter EmailId");
				     bool=false;
				    // merchantForm.merchantEmailId.focus();
				     return;
				  }
				  if(!isEmail(merchantEmailId)){
				     alert("Please enter valid  EmailId");
				     bool=false;
				    // merchantForm.merchantEmailId.focus();
				     return;
				  }
				  return bool;
				  // if(bool){
				   // document.merchantForm.submit();
				   // }
				  }
				  
				  function isEmail(emailId){
				     filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
					  if (filter.test(emailId)) {
						return true;
					  }
					  else
					    {return false;}

				  }
				  
				  function submitMerchantForm(merchantForm){
					  //alert('23  ' );
					  var url = merchantForm.action;
					  //alert(validateMerchantForm(merchantForm));
					  if(!validateMerchantForm(merchantForm)) return;
					  //alert("merchantForm.action:"+merchantForm.action);
					  showProgressImg();
					  new Ajax.Request(((url)? url : merchantForm.action), {
							method : 'post',
							parameters : getFormParams(merchantForm),
							onSuccess : function(transport) {
								/*var response = transport.responseText || "no response text";
								checkLogin(response);
								resp=setMessages(response);
								response=(resp) ? resp : response;
								closeModal('pleaseWait');
								showHideElements(response, null, 'myModal');
								showOverLay();
								showModalWindow('myModal');	*/
						  		hideProgressImg();
								closeModal('mw_merchant_na');
							},
							onFailure : function() {
						
								closeModal('pleaseWait');
								alert('Something went wrong...')
							}
						});
				  }
		  
		  
		  
		  
		  