function IsNumber(UserValue)
{
	var lFlag = true;
	if (UserValue.indexOf(",", 0) >= 0 || UserValue.indexOf("-", 0) >= 0)
		lFlag = false;
	else
		lFlag = true;
	return 	lFlag;
}

function checkSpace(strValue)
{
	var lflag = false;
	for(i=0;i<strValue.length;i++)
	{
		if (strValue.charAt(i) != " " && strValue.charAt(i) != "\t" )
		{
			lflag = true;
			break;
		}
	}
	return lflag;
}

function isValidAmount(inpString) {
    inpString = inpString.replace(",", "");
    return /^\s*(\+|-)?((\d+(\.\d\d)?)|(\.\d\d))\s*$/.test(inpString);
}

function TrimSpace(strText)
{
  var intLength = strText.length
  var intStartPos = 0
  var intEndPos = intLength 
  var strOut =  ""
	for (i=0;i<intEndPos;i++)
	{
		if (strText.charAt(i)!= " ")
		{
			strOut	= strOut + strText.charAt(i)
		}
	}
	return strOut
}

function validate_alphanumeric_data(urstr)
{
  var i;
  var result;

  for (i=0; i<urstr.length; i++) {
    if (
      ((urstr.charAt(i) >= "A") && (urstr.charAt(i) <= "Z")) ||
      ((urstr.charAt(i) >= "a") && (urstr.charAt(i) <= "z")) ||
      ((urstr.charAt(i) >= "0") && (urstr.charAt(i) <= "9")) ||
      ((urstr.charAt(i) == "-"))
      )
      result = true;
    else 
      return false;
  }

  if (result == true)
    return true;
}

function ValidEmail(FieldVal) 
{
	if (window.RegExp) 
	{
		var strCheck1 = "^[a-zA-Z0-9\-\_\.\'\]+@[a-zA-Z0-9\-\_\.]+[.]+[a-zA-Z0-9\-\_\.]+$"
		var objCheck1 = new RegExp(strCheck1);
		if (objCheck1.test(FieldVal))
		{
			return true;
		}
		else
			return false;
	}
	else 
	{
		if(FieldVal.indexOf("@") >= 0)
			return true;
		else
			return false;
	}
}

function isDate(dtStr, pMsg){
	var dtCh= "/";
	var minYear=1900;
	var maxYear=2100;

	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=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)

	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pMsg != null)
	{
		if (pMsg != "")
			pMsg = pMsg + "\n\n";
		else
			pMsg = "";
			
		if (!checkSpace(dtStr)){
			alert(pMsg + "Should not be empty" )
			return false
		}
		if (pos1==-1 || pos2==-1){
			alert(pMsg + "The date format should be : mm/dd/yyyy")
			return false
		}
		if (strMonth.length<1 || month<1 || month>12){
			alert(pMsg + "Please enter a valid month")
			return false
		}
		if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
			alert(pMsg + "Please enter a valid day")
			return false
		}
		if (strYear.length != 2 && strYear.length != 4)
		{
			alert("Please enter a valid 2 or 4 digit year")
			return false
		}
		if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
			alert(pMsg + "Please enter a valid date")
			return false
		}
		return true;
	}
	else
	{
		if (!checkSpace(dtStr)){
			return false;
		}
		if (pos1==-1 || pos2==-1){
			return false;
		}
		if (strMonth.length<1 || month<1 || month>12){
			return false;
		}
		if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month])		{
			return false;
		}
		if (strYear.length != 2 && strYear.length != 4){
			return false;
		}
		if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
			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.
    var strYear = new String(year);
    switch (strYear.length)
    {
		case 1:
			strYear = "200" + strYear;
			break;
		case 2:
			strYear = "20" + strYear;
			break;
	}		
	year = parseInt(strYear); 
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
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 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 Querystring(qs) 
{
	this.params = new Object()
	this.get=Querystring_get
	
	if (qs == null)
		qs=location.search.substring(1,location.search.length)

	if (qs.length == 0) return

    // Turn <plus> back to <space>
    // See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	qs = qs.replace(/\+/g, ' ')
	var args = qs.split('&') // parse out name/value pairs separated via &
	
    // split out each name=value pair
	for (var i=0;i<args.length;i++) 
	{
		var value;
		var pair = args[i].split('=')
		var name = unescape(pair[0])

		if (pair.length == 2)
			value = unescape(pair[1])
		else
			value = name
		
		this.params[name] = value
	}
}

function Querystring_get(key, default_) 
{
	// This silly looking line changes UNDEFINED to NULL
	if (default_ == null) default_ = null;

	var value = this.params[key]
	if (value == null) value=default_;
	
	return value;
}
