
function validateRewardsSearchForm(){
			//check searchindex
			var searchIndex=document.getElementById("searchIndex");
			if(isRequired(searchIndex.value,"Search Index")==false){
				searchIndex.value="";
				searchIndex.focus();
				return false;
			}
			return true;
		}

/**
//This function will verify that given email is in correct format or not
function emailCheck(str) {


		var Re = new RegExp("^[a-z][a-z|0-9|]*([_][a-z|0-9]+)*([.][a-z|" + 
                "0-9]+([_][a-z|0-9]+)*)?@[a-z][a-z|0-9|]*\\.([a-z]" + 
                "[a-z|0-9]*(\\.[a-z][a-z|0-9]*)?)$");

		if(!str.match(Re)){
			alert("Invalid E-mail ID")
		    return false
		}
		return true					
	}
*/	
/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

function emailCheck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}

/**	
//Same as emailCheck but this one does not alerts the user
function emailCheckNoAlert(str) {


		var Re = new RegExp("^[a-z][a-z|0-9|]*([_][a-z|0-9]+)*([.][a-z|" + 
                "0-9]+([_][a-z|0-9]+)*)?@[a-z][a-z|0-9|]*\\.([a-z]" + 
                "[a-z|0-9]*(\\.[a-z][a-z|0-9]*)?)$");

		if(!str.match(Re)){
		    return false
		}
		return true					
	}
*/

function emailCheckNoAlert(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }
 		 return true					
	}
	
//This function will remove leading anf trailing sapces
function trim(stringToTrim) {
		//return stringToTrim.replace(/^\s+|\s+$/g,"");
		return stringToTrim.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
	} 
	
	//This function will check that given string should not be blank
function isRequired(string,fieldName){
	if(trim(string) == ''){
		alert(fieldName+" is required");
		return false;
	}
	return true;
} 
//This function will check the length of a variable should not excceds the given length
function checkLength(string,length,fieldName){

	var originalLength=(trim(string)).length;
	if(originalLength>length){
		alert(fieldName+" is exceeding the given length i.e."+length);
		return false;
	}
	return true;
}


function lengthCheck(element, length, message, focus) {
  if(element == null || element.value.length > length) {
  	if(message != null) {
  		alert(message);
  	}
  	if(focus == true) {
  		element.focus();
  	}
  	return false;
   }
  return true;
}


function isEmpty(element, message, focus) {
  if(element == null || trim(element.value).length == 0) {
  	if(message != null) {
  		alert(message);
  	}
  	if(focus == true) {
  		element.focus();
  	}
  	return true;
  }
  return false;
}

function equalLength(string,length,fieldName){
	var originalLength=(trim(string)).length;
	if(originalLength!=length){
		alert("Please enter "+length+" digits for "+fieldName);
		return false;
	}
	return true;
		
}

function IsNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
  
   return blnResult;
   }
   //This method check that given string has valid chars or not
   // Note that comma is allowed here
   function checkSpecialChar(strString){
  	var strValidChars = "!@#$%^&*()+=-[]\\\';./{}|\":<>?";
  	var strChar;
    var blnResult = false;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == false; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) != -1)
         {
         blnResult = true;
         }
      }
  
   return blnResult;
   }
   
   //This function selects all checkboxes.
   //@param the checkbox control/s that need to be checked.
   
	function selectAllCheckBoxes(chkBox) {
		if(chkBox != null) {
			if(chkBox.length == undefined) {
				chkBox.checked = true;
			} else {
				for(var ii = 0; ii < chkBox.length; ii++) {
					chkBox[ii].checked = true;
				}
			}
		}
	}
	
	function removeSelectAllCheckBoxes(chkBox) {
		if(chkBox != null) {
			if(chkBox.length == undefined) {
				chkBox.checked = false;
			} else {
				for(var ii = 0; ii < chkBox.length; ii++) {
					chkBox[ii].checked = false;
				}
			}
		}
	}
	
	//This function returns true if any checkbox is selected.
	 //@param the checkbox control/s that need to be checked.
	 
	function isAnyCheckboxChecked(chkBox) {
		if(chkBox.length == undefined) {
			return chkBox.checked;
		} else {
			for(var ii = 0; ii < chkBox.length; ii++) {
				if(chkBox[ii].checked == true) {
					return true;
				}
			}
			return false;
		}
	}
	
function IsValidDollar(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789.,";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
    if(strString.indexOf('.') != strString.lastIndexOf('.')){
    	return false;
    }
  
   return blnResult;
   }
   


// Copyright (c) 1998 Sudhakar Chandrasekharan (thaths@netscape.com)
// All rights reserved
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; version 2 dated June, 1991.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.

// Thanks to Martin Honnen (Martin.Honnen@sector27.de) for some coding
// tips.

// Funtion to return the type of credit card
function typeOfCard(number) {
	/* 
	//	Card Prefixes
	//
	//	Mastercard	51-55
	//	Visa		4
	//	AmEx		34,37
	//	Discover	6011
	*/

	var firstNumber = number.substring(0,1);
	var firstThreeNumbers = number.substring(0,3);

	if (firstNumber == 4) {
		return "Visa";
	} 

	var firstTwoNumbers = number.substring(0,2);
	if (firstTwoNumbers > 50 && firstTwoNumbers < 56) {
		return "MasterCard";
	}

	if (firstTwoNumbers == 34 || firstTwoNumbers == 37) {
		return "Amex";
	}

	var firstFourNumbers = number.substring(0,4);
	if (firstFourNumbers == 6011) {
		return "Discover";
	}
}

// Function that determines whether a credit card number is valid
// Please note that a valid credit card number is not essentially a
// credit card in good standing.
function isValidCreditCard(number) {
	var total = 0;
	var flag = 0;
	for (var i=(number.length - 1);i>=0; i--) {
		if (flag == 1) {
			var digits = number.charAt(i) * 2;
			if (digits > 9) digits -= 9;
			total += digits;
//			var reminder = digits % 10;
//			var quotient = (digits - reminder) / 10;
//			total = total + parseInt(reminder);
//			total = total + parseInt(quotient);
			flag = 0;
		} else {
			total = total + parseInt(number.charAt(i));
			flag = 1;
		}
	}
	if ((total%10) == 0) {
		return true;
	} else {
		return false;
	}
}

function validateURL(strString){
   var Re = new RegExp("^(ftp|http|file|https)://");
		if(Re.test(strString)){
		    return true;
		}
		return false;			
}

function greaterThanTodaysDate(checkDate, yearIn2Digits) {
  	
  	var startDateArr = checkDate.split("/");
  	var currentMonth = startDateArr[0] - 1;
  	var currentDate = startDateArr[1];
  	var currentYear = startDateArr[2];

  	if(yearIn2Digits == true) {
  		currentYear = "20" + currentYear;
  	}  	

  	var dateNow = new Date();
  	
  	var startDate = dateNow.setFullYear(currentYear, currentMonth, currentDate);
  	
  	if(startDate > new Date().getTime()) {
  	  	return true;
  	} 
  	return false;
}

function a(p) {
alert(p);
}


/*  
dateElementParent is basically the struts name of dateTimePicker
*/
   function dateValue(dateElementParent) {
   var dateValue = null;
   		var dateChildNodes = document.getElementById(dateElementParent).childNodes;
   	if(dateChildNodes != null) {
   		for(var ii = 0; ii < dateChildNodes.length; ii++) {
   			if(dateChildNodes[ii].type == "text") {
   				dateValue = dateChildNodes[ii].value;
   			}
   		}
   	}
   	return dateValue;
   }


/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year

var dtCh= "/";
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 enterKeySubmission(evt,functionName, obj) {

  var key =
            document.all ? event.keyCode :
            evt.which ? evt.which : evt.keyCode;
            
  if(key == 13) {
    var parameters = new Array();
    for(ii = 0; ii < arguments.length; ii++) {
      if( ii >= 3) {
        parameters[ii-3] = arguments[ii];
      }
    }
     if (functionName != null && typeof functionName =="function") {
    functionName.apply(this, parameters); 
    }
  }
}

// Amazon Product Search posible only for 2500+ points
function forAmazonSearch(points){
	if(points < 2500){
		document.getElementById('searchMsg').innerHTML="Minimum points that can be redeemed is 2500. You currently have "+points+" points only.";
		return false;
	}
	return true;
}

/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Steve | http://jsmadeeasy.com/ */
function getObject(obj) {
  var theObj;
  if(document.all) {
    if(typeof obj=="string") {
      return document.all(obj);
    } else {
      return obj.style;
    }
  }
  if(document.getElementById) {
    if(typeof obj=="string") {
      return document.getElementById(obj);
    } else {
      return obj.style;
    }
  }
  return null;
}

function toCount(entrance,exit,characters,counterId) {
  var entranceObj=getObject(entrance);
  var exitObj=getObject(exit);
  var length=characters - entranceObj.value.length;
  if(length <= 0) {
    length=0;
    entranceObj.value=entranceObj.value.substr(0,characters);
  }
  exitObj.innerHTML = length;
  displayText(exit, counterId)
}


function displayText(id, counterId){
	document.getElementById(counterId).style.visibility = 'visible';
}