
//CHECKS IS ENTERD NUM IS VALID?
function numValidate(thisObj)
{
	if(isNaN(thisObj.value))
	{
		alert("Invalid Number Entered");
		thisObj.value="0";
	}
}

function amountValidate(thisObj)
{
	numValidate(thisObj);
	checkNegative(thisObj);
}

//use to check if entered values is string
function stringValidate(thisObj)
{
	if(!isNaN(thisObj.value))
	{
		alert("Invalid Value Entered");
		thisObj.value="";
	}
}
function alphaNumValidate(thisObj)
{

	if(!(/^[a-zA-Z]+$/.test(thisObj.value)) && thisObj.value!='')
	{
	if(checkforSpaces(thisObj.value))
	{
	alert("Space is not allowed");
	}
	else
	{
		alert("Don't Specify Names in AlphaNumeric");
	}
	   thisObj.value="";
	}
}

function checkNegative(thisObj)
{
	if(!isNaN(thisObj.value) && thisObj.value<0)
	{
		alert("This Field Cannot Be Negative");
		thisObj.value="";
	}
}

// used to validate empty str
function isEmptyValue(str)
{
	str = trim(str);
	var isValid=true;
	if(str!=null )
	{
		for(var i=0;i<str.length;i++)
		{
			if(str[i]!=" ")
			{
				isValid=false;
				break;
			}
		}
	}
		return isValid;
	
}

function trim(str)
{
  return str.replace(/^\s+|\s+$/g,"");
}

function checkforSpaces(data)
 {
          var Char;
          var ValidChars = " ";
          var IsValid=false;
         for (i = 0; i < data.length ; i++) 
         {
                 Char = data.charAt(i);
                 if(ValidChars.indexOf(Char) != -1) 
         {
         IsValid=true;
         break;
         }
         }
         return IsValid;
 }

function maxTextCounter( field, maxlimit, elementNameForDisplay) 
{	
	if ( field.value.length > maxlimit )
	{
		field.value = field.value.substring( 0, maxlimit );
		alert( elementNameForDisplay+' should only be '+maxlimit+' characters in length.' );
		return false;
	}
}

function minTextCounter( field, minlimit, elementNameForDisplay ) 
{	
	if ( field.value.length <= minlimit )
	{
		field.value = field.value.substring( 0, minlimit );
		alert( elementNameForDisplay+' should be more than or equal '+minlimit+' characters in length.' );
		return false;
	}
}

function comparedDate(startDate, endDate, type)
{
	if('GREATER'==type)
	{
		if (startDate.value <= endDate.value)
		{
			return endDate;
		}
		else
		{
			return startDate;
		}
	}
	else
	{
		//alert(startDate.value+'----'+endDate.value);
		if (startDate.value <= endDate.value)
		{
			return startDate;
		}
		else
		{
			return endDate;
		}
	}
}