/*
Versions:
1.13  15-11-2010  (A.Ianovski) - checkEmail(): allowed numbers,dashes and hyphens in domain names (issue 292)
1.12  11-02-2010  (A.Ianovski) - go_payment_prompt() added
1.11  03-02-2010  (A.Ianovski) - added apostrophe to email validation pattern
1.10  24-03-2009  (A.Ianovski) - Added . isValidUserName()
*/

String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}
function checkEmail(inputvalue){
    var pattern=/^(['a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z0-9_-])+([a-zA-Z0-9_-])$/;
    if(pattern.test(inputvalue)){
  		return true;
    }else{
      return false;
    }
}

 function trim(s)
  {
       while (s.substring(s.length-1,s.length) == ' ')
       {
            s = s.substring(0,s.length-1);
       }
       return s;
 }

function isAlphabet(val)
{
	var alphaExp = /^[a-zA-Z]+$/;
	if(val.match(alphaExp))
	{
		return true;
	}
	else
	{
		return false;
	}
}
function isValidUserName(val)
{
	return val.search(/[^a-zA-Z^'^-]/) < 0;
}
function isAlphanumeric(val)
{
	var alphaExp = /^[0-9a-zA-Z]+$/;
	if(val.match(alphaExp))
	{
		return true;
	}
	else
	{

		return false;
	}
}
function isNumeric(val)
{
	var numericExpression = /^[0-9]+$/;
	if(val.match(numericExpression))
	{
		return true;
	}
	else
	{

		return false;
	}
}

function isNumber(str) {
isPrice = /^\d+\.\d{2}$/;
return isPrice.test( str );
}

function checkBlankspace(val)
{
   var blank = /^[ ]+$/


   if(!val.match(blank))
	{
		return true;
	}

	else
	{

		return false;
	}


}

function isEmpty( str ){
    var strRE = /^[\s ]*$/gi;
    return strRE.test( str );
}



/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
/* This can  be customised */
var minYear=1900;
var maxYear=2100;

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 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 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 isDate(dtStr){
	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)
	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 : mm/dd/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("Please enter a valid date")
		return false
	}
return true
}

function go_payment_prompt()
{
  return confirm("When you close this dialog you'll be taken to the Paystation site to make your credit card payment. When that's completed you'll be returned to the Relay For Life site and  payment processing will be confirmed.\n\n If for any reason you're not sure your payment succeeded, please wait for an hour and check your email before trying again: some payments can take a little longer to be confirmed.")
}

