//function to check valid email address
function isValidEmail(strEmail){
  validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;

   // search email text for regular exp matches
    if (strEmail.search(validRegExp) == -1) 
   {
      return false;
    } 
    return true; 
}


//function to check valid wedding guest amount
function isValidGuestAmount(intGuest){
      if(intGuest==null){return false;}
      if (intGuest.length==0){return false;}
		for (var i = 0; i < intGuest.length; i++) {
            var ch = intGuest.charAt(i)
            if (ch < "0" || ch > "9") {
            return false
            }
      }  
	  
	  if(intGuest > 180){ return false; }
	  
	  return true;
	  
}


//function to check valid corporate guest amount
function isValidCorpGuestAmount(intGuest){
      if(intGuest==null){return false;}
      if (intGuest.length==0){return false;}
		for (var i = 0; i < intGuest.length; i++) {
            var ch = intGuest.charAt(i)
            if (ch < "0" || ch > "9") {
            return false
            }
      }  
	  
	  if(intGuest > 180){ return false; }
	  
	  return true;
	  
}


//function to check valid name
function isValidName(strName){
	if(strName=="")
	{ return false; }
	var alphaExp = /^[a-zA-Z''-'\s]{1,55}$/;
	if(!strName.match(alphaExp))
	{ return false; }
	
	return true;
}


function  isValidPrice(val){
      if(val==null){return false;}
      if (val.length==0){return false;}
      var DecimalFound = false;
      for (var i = 0; i < val.length; i++) {
            var ch = val.charAt(i);
            if (i == 0 && ch == "-") {
                  continue;
            }
            if (ch == "." && !DecimalFound) {
                  DecimalFound = true;
                  continue;
            }
            if (ch < "0" || ch > "9") {
                  return false;
            }
      }
      return true;
}

//function to check that a date is at least one week in the future
function isFeasibleDate(strDate)
{
	var ONE_DAY = 1000 * 60 * 60 * 24;
	var CurrentDate = new Date();
	var UserDate = new Date(strDate.substring(0,4),strDate.substring(5,7) - 1,strDate.substring(8,10));
	
	if(UserDate <= CurrentDate)
	{ return false; }

	var UserDate2 = UserDate.getTime();
	var AcceptableDate = CurrentDate.getTime();
	
	var difference_ms = Math.abs(UserDate2 - AcceptableDate);
	var difference_days = Math.round(difference_ms/ONE_DAY);
	
	if(difference_days < 7)
	{ return false; }
	
	return true;	
}


//function to check that the viewing date is in advance of the wedding date
function isFeasibleViewingDate(strDate, strViewingDate)
{
	var ViewDate = new Date(strViewingDate.substring(0,4),strViewingDate.substring(5,7) - 1,strViewingDate.substring(8,10));
	var UserDate = new Date(strDate.substring(0,4),strDate.substring(5,7) - 1,strDate.substring(8,10));
	
	if(ViewDate >= UserDate)
	{ return false; }
	
	return true;	
}



//function to check valid phone number
	var digits = "0123456789";
	// non-digit characters which are allowed in phone numbers
	var phoneNumberDelimiters = "()- ";
	// characters which are allowed in international phone numbers
	// (a leading + is OK)
	var validWorldPhoneChars = phoneNumberDelimiters + "+";
	// Minimum no of digits in an international phone no.
	var minDigitsInIPhoneNumber = 10;
	
	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 trim(s)
	{   var i;
		var returnString = "";
		// Search through string's characters one by one.
		// If character is not a whitespace, append to returnString.
		for (i = 0; i < s.length; i++)
		{   
			// Check that current character isn't whitespace.
			var c = s.charAt(i);
			if (c != " ") returnString += c;
		}
		return returnString;
	}
	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++)
		{   
			// Check that current character isn't whitespace.
			var c = s.charAt(i);
			if (bag.indexOf(c) == -1) returnString += c;
		}
		return returnString;
	}

function isValidPhone(strPhone){
	var bracket=3
	strPhone=trim(strPhone)
	if(strPhone.indexOf("+")>1) return false
	if(strPhone.indexOf("-")!=-1)bracket=bracket+1
	if(strPhone.indexOf("(")!=-1 && strPhone.indexOf("(")>bracket)return false
	var brchr=strPhone.indexOf("(")
	if(strPhone.indexOf("(")!=-1 && strPhone.charAt(brchr+2)!=")")return false
	if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)return false
	s=stripCharsInBag(strPhone,validWorldPhoneChars);
	return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

