
function Phone(Pname1,Pname2)
{
	if (Pname1.value != "")
	{
 		if (Pname1.value.length ==3)
		{
			Pname2.focus();
		}
	}
}


function FieldFocus(Pname1,Pname2,Sval)
{
	if (Pname1.value != "")
	{
 		if (Pname1.value.length ==Sval)
		{
			Pname2.focus();
		}
	}
}


function Zip(Zname1,Zname2)
{
	if (Zname1.value != "")
	{
 		if (Zname1.value.length ==5)
		{
			Zname2.focus();
		}
	}
}

// E mail validation on 14/05/09
function Email_Validation(email) 
{
	if(email.value !="")
	{
	   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	   var address = email.value;
	   if(reg.test(address) == false) 
	   {
	      alert("Invalid Email Address");
		  email.focus();
	      return false;
	   }
   }
}

/*function Email_Validation(src)
{
	if(src.value != "Camp Email" && src.value != "Contact Email")
	{
		if(src.value.length!=0)
		{
		if(!test(src.value))
			{
				alert("Invalid E-Mail address");
				src.select()
				src.focus()
				return;
			}
		}
	}
}*/

 /*function test(src)
 {
     var emailReg = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*(\\.[_A-Za-z0-9-]+)";
     var regex = new RegExp(emailReg);
     return regex.test(src);
  }*/
  
 function mailchk()
{
	if (document.regfrm.txtemail.value !="")
	{
		s=document.regfrm.txtemail.value
		pos1=s.indexOf("@")
		pos2=s.indexOf(".")
		d=pos2-pos1
			if ((pos1==0) || (pos1==-1) || (d<=-1))
			{
				alert("Enter Valid E-Mail");
				regfrm.txtemail.focus();
				return(false);
			}
	}		
	else
	{
		return true;
	}
}

function AcceptOnly(str,sval,slen)
{
	if((str.value.length<slen)&&(str.value.length!=0))
	{
		alert("Please enter valid " + sval);
		str.focus();
		str.select();
		return false;
	}
}

function fNumber(Field)
{
	var KeyPressed, RetVal;
	KeyPressed = window.event.keyCode;
	if ((KeyPressed > 47) && (KeyPressed < 58))
	{
		RetVal = true;
	}
	else
	{
		RetVal = false;
	}
	return RetVal;
}

//following function accepts numerics with dot(period) -Added on 260609
function fNumberChrs(Field)
{
	var KeyPressed, RetVal;
	KeyPressed = window.event.keyCode;
	if ((KeyPressed > 45) && (KeyPressed < 58))
	{
		RetVal = true;
	}
	else
	{
		RetVal = false;
	}
	return RetVal;
}
//end 

function fDate(Field)
{
	var KeyPressed, RetVal;
	KeyPressed = window.event.keyCode;
	if ((KeyPressed > 46) && (KeyPressed < 58))
	{
		RetVal = true;
	}
	else
	{
		RetVal = false;
	}
	return RetVal;
}
function maxlen( field,  maxlimit , MVal)
{
	if ( field.value.length > maxlimit )
	{
  		field.value = field.value.substring( 0, maxlimit );
  		field.blur();
 		field.focus();
  		alert(MVal + " cannot be beyond " + maxlimit + " characters");
  		return false;
  	}
  	else
	{
		return true;
	}
} 

function fTime(Field)
{
	var KeyPressed, RetVal;
	KeyPressed = window.event.keyCode;
	if ((KeyPressed > 47) && (KeyPressed <= 58))
	{
		RetVal = true;
	}
	else
	{
		RetVal = false;
	}
	return RetVal;
}


//// functions for checking float value (start) ///////
function isFloat (s)
{
	var i;
	var decimalPointDelimiter = "."
    var seenDecimalPoint = false;
    if (isEmpty(s)) 
      if (isFloat.arguments.length == 1) return defaultEmptyOK;
      else return (isFloat.arguments[1] == true);
	if(s.length !=1 && s != decimalPointDelimiter)
	{
    	if (s == decimalPointDelimiter) return false;
	}

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {  
        // Check that current character is number.
		var c = s.charAt(i);
		if ((c == decimalPointDelimiter) && !seenDecimalPoint) 
		seenDecimalPoint = true;
        else if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}

// Check whether string s is empty.

function isEmpty(s)
{  return ((s == null) || (s.length == 0))
}

// Returns true if character c is a digit 
// (0 .. 9).

function isDigit (c)
{  return ((c >= "0") && (c <= "9"))
}

function checkFloat(theField,sval)
{
	if(!isEmpty(theField.value))
	{
    	if(isFloat(theField.value) != true)
		{
        	return warnInvalid (theField, sval);
        }
    }
} 

function warnInvalid (theField, s)
{  
	theField.value="";
    theField.focus()
    theField.select()
    alert("Please enter valid "+s)
    return false
}
//// functions for checking float value (end) ///////

//CreditCard Name & Number Validation; link for reference http://www.planetpdf.com/codecuts/pdfs/tutorial/CredCard.pdf//
 function name_Validation(lname)
{
	//var VowCnt;
	strVowel = ' aeiouAEIOU';
	isValidName = true;
	VowCnt = 0;
	if (lname.value != '')
	{
		Lname = lname.value
		//Lname = Lname.replace(' ', 's');
		
		LoopLname = -1;
		
		while ((LoopLname <= Lname.length) && isValidName)
		{
			LoopLname = LoopLname + 1;
			lChar = Lname.charAt(LoopLname);
			if(lChar != '')
			{
				if( isDigit(lChar))
				{
					//alert(lChar);
					isValidName = false;
					break;
				}
				if (strVowel.indexOf(lChar) > 0)
				{
					VowCnt = VowCnt + 1;
				}
				//if( ((c < 'a' || 'z' < c) && (c < 'A' || 'Z' < c)) && (c < '0' || '9' < c) && (c != '-') && (c != '.') && (c!=' ') && (c!='/')&& (c!='\\') && (c!=',')) 
				else
				{
					if( ((lChar < 'a' || 'z' < lChar) && (lChar < 'A' || 'Z' < lChar)) || (lChar == '-') || (lChar == '.') || (lChar ==' ') || (lChar =='/') || (lChar =='\\') || (lChar ==',') || (lChar =='$') || (lChar =='%')) 
					{
						//alert(lChar);
						isValidName = false;
						break;
					}
				}
			}
		}
		if (VowCnt == 0)
		{
			//alert("no Vowels");
			isValidName = false;
		}
	}
	if (isValidName == false)
	{
		return warnInvalid(lname, " Last Name");
	}
}
//counts the number of elements in a textarea and displays the result in a container
//can either return total or the number of chars left based on the maxlength
var LeftValue,TextValue
function writeCharacterCount(field,maxlimit,MVal,DivName) 
{
	var pendingContainer = document.getElementById(DivName);	
	TextValue = field.value.length;
	if ( field.value.length > maxlimit )
	{
		field.value = field.value.substring( 0, maxlimit );
  		field.blur();
 		field.focus();
  		alert(MVal + " cannot be beyond " + maxlimit + " characters");  		
		LeftValue = maxlimit - (TextValue);
		pendingContainer.innerHTML = "0 characters left (limit is " +maxlimit+ " characters)";
		return false;			
  	}
  	else
	{	
		if(maxlimit >= TextValue)
		{
			LeftValue = maxlimit - (TextValue);
			pendingContainer.innerHTML = LeftValue+"&nbsp;characters left (limit is " +maxlimit+ " characters)";
		}			
	}
}

function CCNumber_Validation(CCNumber,CardType)
{
	Err = 0;
	Err_Text = "";

	thisCardType = "";
	 
	if (CCNumber.value != "") 
	{
		Double = false;
		isNumericInput = true;
		isValidNumber = false;
		isValidCardType = false;
		SumString = "";
		Sum = 0;
		ccnumber = CCNumber.value;

		revCCNumber = "";
		
		for (i=ccnumber.length-1; i >= 0; i--)
		{
			revCCNumber = revCCNumber + ccnumber.charAt(i);
		}
		if (revCCNumber.length == 0) isNumericInput = false;
		LoopCC = 0;
	
		while ((LoopCC <= revCCNumber.length) && isNumericInput)
		{
			LoopCC = LoopCC + 1;
			digit = revCCNumber.charAt(LoopCC);
			if (digit < eval("0") && digit > eval("9")) 
			{
				isNumericInput = false;
				break;
			}
			else
			{
				if (Double)	SumString = SumString + eval(digit * 2);
				else SumString = SumString + digit;
				Double = !(Double);
			}
		}
		//alert(SumString);
		if (isNumericInput)
		{
			for(SumLoop = 0; SumLoop <= SumString.length; SumLoop = SumLoop + 1)
			{
				Sum = Sum + SumString.charAt(SumLoop);
			}
			//alert(Sum);
			if (Sum % 10 == 0)
			{
				isValidNumber = true;
			}
			else
			{
				Err = 335;
				Err_Text = "Invalid credit card number.";
			}
		}
		else
		{
			Err = 336;
			Err_Text = "Card number may only contain the digits 0 through 9";
		}
		if (isValidNumber) {
			//Check AMEX cards
			if (ccnumber.length == 15)
			{
				FirstDig = ccnumber.charAt(0);
				SecondDig = ccnumber.charAt(1);
				if ((FirstDig == "3") && (["4,7"].toString().indexOf(SecondDig) >= 0))
				{
					isValidCardType = true;
					thisCardType = "American Express";
				}
			}
			//Check Diners and CarteBlanche cards
			if (ccnumber.length == 14)
			{
				FirstDig = ccnumber.charAt(0);
				SecondDig = ccnumber.charAt(1);
				if ((FirstDig == "3") && (["0,6,8"].toString().indexOf(SecondDig) >= 0))
				{
					isValidCardType = true;
					thisCardType = "Diners Club / CarteBlanche";
				}
			}
			//Check Discover cards
			if (ccnumber.length == 16)
			{
				FirstFourDigs = ccnumber.substring(0,4);
				//alert(FirstFourDigs);
				if (FirstFourDigs == "6011")
				{
					isValidCardType = true;
					thisCardType = "Discover";
				}
			}
			//Check EnRoute cards
			if (ccnumber.length == 15)
			{
				FirstFourDigs = ccnumber.substring(0,4);
				//alert(FirstFourDigs);
				if (["2014,2149"].toString().indexOf(FirstFourDigs) >= 0)
				{
					isValidCardType = true;
					thisCardType = "EnRoute";
				}
			}
	
			//Check JCB cards
			if (ccnumber.length == 16)
			{
				FirstFourDigs = ccnumber.substring(0,4);
				if (["3088,3096,3112,3158,3337,3528"].toString().indexOf(FirstFourDigs) >= 0)
				{
					isValidCardType = true;
					thisCardType = "JCB";
				}
			}
	
			//Check MasterCard cards
			if (ccnumber.length == 16)
			{
				FirstDig = ccnumber.charAt(0);
				SecondDig = ccnumber.charAt(1);
				if ((FirstDig == "5") && (["1,2,3,4,5"].toString().indexOf(SecondDig) > 0))
				{
					isValidCardType = true;
					thisCardType = "MasterCard";
				}
			}
	
			//Check Visa cards
			if ((ccnumber.length == 16) || (ccnumber.length == 13))
			{
				FirstDig = ccnumber.charAt(0);
				if (FirstDig == "4")
				{
					isValidCardType = true;
					thisCardType = "Visa";
					//alert (thisCardType);
				}
			}
			
			if (isValidCardType == false) {
				thisCardType = "Unknown";
			}
		}
			
		if (Err != 0)	
		{
			return warnInvalid(CCNumber, "Credit Card Number " + "Error Number " +Err + " Occurred : " + Err_Text);
			
		}
		else
		{ 
			
			if (CardType.value != "")
			{
				if (thisCardType != CardType.value)
				{
					return warnInvalid(CCNumber, "Credit Card Number");
				}
				
			}
			else
			{
				return warnInvalid(CardType, "Credit Card Type");
			}
		}
	}
}