//-----------------Validations for Login form -------------------------//
function validateLoginForm()
{
	var str = new String();
	var flag;
	var objRegExpUserName = /^[a-zA-Z0-9\s]+$/;
		
	//User Name Of Login
			str=document.frmlogin.txtUserName.value;
			flag = str.match(objRegExpUserName);
			if(str=="")
			{
				alert("User Name cannot be empty.");
				document.frmlogin.txtUserName.focus();
				return false;
			}
			if(flag==null)
			{
				alert("User Name is not valid \n Only alphanumeric are allowed.");
				document.frmlogin.txtUserName.focus();
				return false;
			}
		
		//Password Validation of Login
			str=document.frmlogin.txtPassword.value;
			flag = str.match(objRegExpUserName);
			if(str=="")
			{
				alert("Password cannot be empty.");
				document.frmlogin.txtPassword.focus();
				return false;
			}
			
			if(flag==null)
			{
				alert("Password is not valid. \n Only alphabets and numbers are allowed.");
				document.frmlogin.txtPassword.focus();
				return false;
			}
			
			/*if(str.length<6 || str.length >10)
			{
				alert("Password is not valid. \n Min. 6 and Max. 10 characters are allowed.");
				document.frmlogin.txtPassword.focus();
				return false;
			}*/
	}
//----------------- End of Function Here--------------------------------------//


//-----------------Validations for Registration form -------------------------//
	function Register_CheckForm()
	{
		var str = new String();
		var flag;
		var objRegExpAlphabets = /^[a-zA-Z\s]+$/;
		var objRegExpNumbers = /^[0-9\s]+$/;
		var objRegExpUserName = /^[a-zA-Z0-9\s]+$/;
		var objRegExpAddress = /^[a-zA-Z0-9\,\-\#\/\s]+$/;
		var objRegExpeMail = /^.+@.+\..{2,3}$/;
		var illegalChars= /[\(\)\&lt;\&gt;\,\;\:\\\/\"\[\]]/;
		var myRegExp=/(http:\/\/)/;
		
		
		//First Name Validation
		str=document.frmUserRegistration.txtFirstName.value;
		flag = str.match(objRegExpAlphabets);
		if(str=="")
		{
			alert("First name cannot be empty.");
			document.frmUserRegistration.txtFirstName.focus();
			return false;
		}
		if(flag==null)
		{
			alert("First name is not valid. \n Only alphabets are allowed.");
			document.frmUserRegistration.txtFirstName.focus();
			return false;
		}
		
		//Middle Name Validation
		str=document.frmUserRegistration.txtMiddleName.value;
		flag = str.match(objRegExpAlphabets);
		if(flag==null && str!="")
		{
			alert("Middle name is not valid. \n Only alphabets are allowed.");
			document.frmUserRegistration.txtMiddleName.focus();
			return false;
		}

		//Last Name Validation
		str=document.frmUserRegistration.txtLastName.value;
		flag = str.match(objRegExpAlphabets);
		if(str=="")
		{
			alert("Last name cannot be empty.");
			document.frmUserRegistration.txtLastName.focus();
			return false;
		}
		if(flag==null)
		{
			alert("Last name is not valid. \n Only alphabets are allowed.");
			document.frmUserRegistration.txtLastName.focus();
			return false;
		}
		
		
		//Address
		str=document.frmUserRegistration.txtAddress.value;
		flag = str.match(objRegExpUserName);
		if(str=="")
		{
			alert("Address cannot be empty.");
			document.frmUserRegistration.txtAddress.focus();
			return false;
		}
		if (document.frmUserRegistration.txtAddress.value != "")
		{
			if(flag==null)
			{
				alert("Address is not valid. \n Only alphnumaric are allowed.");
				document.frmUserRegistration.txtAddress.focus();
				return false;
			}
		}
		
		//Address2
		str=document.frmUserRegistration.txtAddress2.value;
		flag = str.match(objRegExpUserName);
		if (document.frmUserRegistration.txtAddress2.value != "")
		{
			if(flag==null)
			{
				alert("Address2 is not valid. \n Only alphnumaric are allowed.");
				document.frmUserRegistration.txtAddress2.focus();
				return false;
			}
		}
		
		//Country
		str=document.frmUserRegistration.txtCountry.value;
		flag = str.match(objRegExpUserName);
		if(str=="")
		{
			alert("Country cannot be empty.");
			document.frmUserRegistration.txtCountry.focus();
			return false;
		}
		if (document.frmUserRegistration.txtCountry.value != "")
		{
			if(flag==null)
			{
				alert("Country is not valid. \n Only alphnumaric are allowed.");
				document.frmUserRegistration.txtCountry.focus();
				return false;
			}
		}
		
		//State
		str=document.frmUserRegistration.txtState.value;
		flag = str.match(objRegExpUserName);
		if(str=="")
		{
			alert("State cannot be empty.");
			document.frmUserRegistration.txtState.focus();
			return false;
		}
		if (document.frmUserRegistration.txtState.value != "")
		{
			if(flag==null)
			{
				alert("State is not valid. \n Only alphnumaric are allowed.");
				document.frmUserRegistration.txtState.focus();
				return false;
			}
		}
		
		//City
		str=document.frmUserRegistration.txtCity.value;
		flag = str.match(objRegExpUserName);
		if(str=="")
		{
			alert("City cannot be empty.");
			document.frmUserRegistration.txtCity.focus();
			return false;
		}
		if (document.frmUserRegistration.txtCity.value != "")
		{
			if(flag==null)
			{
				alert("City is not valid. \n Only alphnumaric are allowed.");
				document.frmUserRegistration.txtCity.focus();
				return false;
			}
		}
		
		//phone (Office) validation			
		str=document.frmUserRegistration.txtPhoneOffice.value;
		flag = str.match(objRegExpNumbers);
		if(str=="")
		{
			alert("Phone (Office) number cannot be empty.");
			document.frmUserRegistration.txtPhoneOffice.focus();
			return false;
		}
		if(flag==null)
		{
			alert("Phone (Office) number is not valid. \n Only numbers are allowed.");
			document.frmUserRegistration.txtPhoneOffice.focus();
			return false;
		}
		if(str.length <8 || str.length>12)
		{
			alert("Phone (Office) number is not valid. \n Minimum 8 digits are required.");
			document.frmUserRegistration.txtPhoneOffice.focus();
			return false;
		}
		
		//phone (Res) validation			
		str=document.frmUserRegistration.txtPhoneRes.value;
		flag = str.match(objRegExpNumbers);
		if(str=="")
		{
			
		}
		else if(flag==null)
		{
			alert("Phone (Res.) number is not valid. \n Only numbers are allowed.");
			document.frmUserRegistration.txtPhoneRes.focus();
			return false;
		}
		else if(str.length <8 || str.length>12)
		{
			alert("Phone (Res.) number is not valid. \n Minimum 8 digits are required.");
			document.frmUserRegistration.txtPhoneRes.focus();
			return false;
		}
		
		//phone (Mobile) validation			
		str=document.frmUserRegistration.txtMobile.value;
		flag = str.match(objRegExpNumbers);
		
		if(str=="")
		{
			
		}
		else if(flag==null && str!="")
		{
			alert("Mobile number is not valid. \n Only numbers are allowed.");
			document.frmUserRegistration.txtMobile.focus();
			return false;
		}
		else if(str.length <10 || str.length>12)
		{
			alert("Mobile number is not valid. \n Minimum 10 digits are required.");
			document.frmUserRegistration.txtMobile.focus();
			return false;
		}
		
		//Fax validation			
		str=document.frmUserRegistration.txtFax.value;
		flag = str.match(objRegExpNumbers);
		if(str=="")
		{
			
		}
		else if(flag==null && str!="")
		{
			alert("Fax number is not valid. \n Only numbers are allowed.");
			document.frmUserRegistration.txtFax.focus();
			return false;
		}
		else if(str.length <8 || str.length>12)
		{
			alert("Fax number is not valid. \n Minimum 8 digits are required.");
			document.frmUserRegistration.txtFax.focus();
			return false;
		}
		
		//Email (Work) Validation
		if(document.frmUserRegistration.txtEmailWork.value == "")
		{
			alert("Email (Work) address cannot be empty.");
			document.frmUserRegistration.txtEmailWork.focus();
			return false;
		}
		
		if(!validEmail(document.frmUserRegistration.txtEmailWork.value))
		{
			alert("Email (Work) address is not valid.");
			document.frmUserRegistration.txtEmailWork.focus();
			return false;
		}
	
		if (!(objRegExpeMail.test(document.frmUserRegistration.txtEmailWork.value)))
		{ 
			alert("Please enter a valid Email (Work) address.");
			document.frmUserRegistration.txtEmailWork.focus();
			return false;
		}
		
		//Email (Business) Validation
		if(document.frmUserRegistration.txtEmailBusiness.value == "")
		{
			alert("Email (Business) address cannot be empty.");
			document.frmUserRegistration.txtEmailBusiness.focus();
			return false;
		}
		
		if(!validEmail(document.frmUserRegistration.txtEmailBusiness.value))
		{
			alert("Email (Business) address is not valid.");
			document.frmUserRegistration.txtEmailBusiness.focus();
			return false;
		}
	
		if (!(objRegExpeMail.test(document.frmUserRegistration.txtEmailBusiness.value)))
		{ 
			alert("Please enter a valid Email (Business) address.");
			document.frmUserRegistration.txtEmailBusiness.focus();
			return false;
		}
		
		//User Name
			str=document.frmUserRegistration.txtUserName.value;
			flag = str.match(objRegExpUserName);
			if(str=="")
			{
				alert("User Name cannot be empty.");
				document.frmUserRegistration.txtUserName.focus();
				return false;
			}
			if(flag==null)
			{
				alert("User Name is not valid \n Only alphanumeric are allowed.");
				document.frmUserRegistration.txtUserName.focus();
				return false;
			}
		
		//Password Validation
			str=document.frmUserRegistration.txtPassword.value;
			flag = str.match(objRegExpUserName);
			if(str=="")
			{
				alert("Password cannot be empty.");
				document.frmUserRegistration.txtPassword.focus();
				return false;txtUsername
			}
			
			if(flag==null)
			{
				alert("Password is not valid. \n Only alphabets and numbers are allowed.");
				document.frmUserRegistration.txtPassword.focus();
				return false;
			}
			
			if(str.length<6 || str.length >10)
			{
				alert("Password is not valid. \n Min. 6 and Max. 10 characters are allowed.");
				document.frmUserRegistration.txtPassword.focus();
				return false;
			}
			
			if(document.frmUserRegistration.txtConfirmPassword.value != document.frmUserRegistration.txtPassword.value)
			{
				alert("Password & Confirm Password doesn't match.");
				document.frmUserRegistration.txtConfirmPassword.focus();
				return false;
			}
			
			
			
			//Hint Question Validation
			str=document.frmUserRegistration.ddlHintQuestions.value;
			if(str=="select")
			{
				alert("Please select the Hint Question.");
				document.frmUserRegistration.ddlHintQuestions.focus();
				return false;
			}
			
			
			//Hint Answer Validation
			str=document.frmUserRegistration.txtHintAnswer.value;
			if(str=="" || str==null)
			{
				alert("Hint Answer cannot be left empty.");
				document.frmUserRegistration.txtHintAnswer.focus();
				return false;
			}
			
					
		
	}

//------------ End of function-------------//


//--------- Function for validating email address---------//
function validEmail(email)
{
	invalidChars="/:,;";
		
	if(email=="")
	{
		return false;
	}
	
	for(i=0;i<invalidChars.length;i++)
	{
		badChar=invalidChars.charAt(i);
		if(email.indexOf(badChar,0)!=-1)
		{
			return false;
		}
	}
	

	atPos=email.indexOf("@",1);
	
	if(atPos==-1 || atPos==0)
		return false;
	
	if(email.indexOf("@",atPos+1)!=-1)
		return false;

	periodPos=email.indexOf(".",atPos);

	if(periodPos==-1)
		return false;
	if(periodPos+3>email.length)
		return false;
		
	return true;
}
//-------------End of function--------------//






//Function For Checking All Check box
function UnSelectGrid(oTemp,nGridNumber,frmName,checkBoxName)
{
	var oGrid, sGrid;
	if (nGridNumber==1){ oGrid=grdData; sGrid="grdData";}
	
	var sCheck;				
			
	if(oTemp.checked==true)
	{
		sCheck = true;
	}
	else
	{
		sCheck = false;
	}
	
	for(i=1;i<=oGrid.rows.length+1;i++)
	{	
		oCheck = eval("document." + frmName + "." + sGrid +"__ctl" + i + "_"+checkBoxName);	
		if (oCheck)
		{			 					
			if(sCheck==false)
			{
				oCheck.checked = false;
			}
				
		}
	}
}

function checkValUserName(source, arguments) 
{
	var str;
	var str = new String(arguments.Value);	
	var mikExp = /[\`\~\!\@\#\$\%\^\&\*\(\)\+\=\|\\\{\}\[\]\:\;\"\'\<\>\,\.\/\?\' ']/;
	// _ and -
	//`~!@#$%^&*()=+|\{}[];:'",.<>/?-_ space 33 characters to be disabled
	if(str.search(mikExp) != -1) {
		//alert("Sorry, but the following characters\n\r\n\r< > @ $ % ^ & * ( ) [ ] \\ { + } ` ~ =  | \n\r\n\r are not allowed!\n");
		arguments.IsValid = false;
		return ; // invalid string
	}
	else
	{
		arguments.IsValid = true;
		return ; // valid string
	}	
}


function checkValName(source, arguments) 
{
	var str;
	var str = new String(arguments.Value);	
	var mikExp = /[\`\~\!\@\#\$\%\^\&\*\(\)\+\=\|\\\{\}\[\]\:\;\"\_\<\>\,\.\/\?\0\1\2\3\4\5\6\7\8\9]/;
	//' and -
	//`~!@#$%^&*()=+|\{}[];:'",.<>/?-_ space 33 characters to be disabled
	if(str.search(mikExp) != -1) {
		//alert("Sorry, but the following characters\n\r\n\r< > @ $ % ^ & * ( ) [ ] \\ { + } ` ~ =  | \n\r\n\r are not allowed!\n");
		arguments.IsValid = false;
		return ; // invalid string
	}
	else
	{
		arguments.IsValid = true;
		return ; // valid string
	}	
}


function CheckIfSelected(source, arguments)
{
	//try
	//{
	
	if(arguments.Value == 0||arguments.Value == -1 )
	{
		arguments.IsValid =false;
	}
	else
	{
		arguments.IsValid =true;
	}
	//}
	//catch(e)
//	{
	//alert(e);
//	}
	return ;
}



function fResetButton (sForm) 
			{
			//alert(oForm.elements.length);
			sForm="document."+sForm;
			var oForm =eval(sForm);
			for (var i = 0; i < oForm.length; i++) 
				{	
					if (oForm.elements[i].type == "select-one")
						{
							if(oForm.elements[i].disabled==false)
								oForm.elements[i].options[0].defaultSelected=true;
						}
					if (oForm.elements[i].type == "textarea")
						{
							if(oForm.elements[i].disabled==false)
								{
								oForm.elements[i].defaultValue = "";
								oForm.elements[i].value = "";
								//oForm.elements[i].value = oForm.elements[i].defaultValue;
								}
						}
					if (oForm.elements[i].type == "text")
						{
							if(oForm.elements[i].disabled==false)
								{
									oForm.elements[i].defaultValue = "";
									oForm.elements[i].value = "";
								}
						}
				}
			}

function CheckAngularBrackets(source, arguments) 
{
	var Str = new String(arguments.Value);
	var mikExp = /[\<\>]/;
	if(Str.search(mikExp) != -1)
    {
	    arguments.IsValid = false;
		return ; // invalid string
	}
	else{
		arguments.IsValid = true;
		return ;// valid string
	}	
}


function validateAlphaNumeric(source, arguments)
{
	var str;
	var str = new String(arguments.Value);
	
	var objRegExp = /^[a-zA-Z0-9\s]+$/;
	var flag = str.match(objRegExp);
	
	if (flag == null)
	{
		arguments.IsValid = false;
		return ; // invalid string
	}
	else 
	{
		arguments.IsValid = true;
		return ; // valid string
	}
}


function checkVal(source, arguments) 
{
	var str;
	var str = new String(arguments.Value);	
	var mikExp = /[$\<\>\\\@\\\%\^\&\*\(\)\[\]\+\_\{\}\`\~\=\|]/;
	if(str.search(mikExp) != -1) {
		//alert("Sorry, but the following characters\n\r\n\r< > @ $ % ^ & * ( ) [ ] \\ { + } ` ~ =  | \n\r\n\rare not allowed!\n");
		arguments.IsValid = false;
		return ; // invalid string
	}
	else
	{
		arguments.IsValid = true;
		return ; // valid string
	}	
}

function validateFirstAlphaNumeric(source, arguments)
{
	
	var str = new String(arguments.Value);
	var objRegExp = /^[0-9]+[a-z A-Z 0-9]/;
	if(objRegExp.test(str)==true)
    {
		arguments.IsValid=false;
		return;
	}
	else
	{
		arguments.IsValid=true;
		return;
	}			 
}

function checkDecimals(source, arguments) 
{	
	decallowed = 2;  // how many decimals are allowed?
	var inputStr = new String(arguments.Value);
	if (inputStr.indexOf('.') == -1) inputStr += ".";
	var dectext = inputStr.substring(inputStr.indexOf('.')+1, inputStr.length);
	if (dectext.length > decallowed)
	{
		arguments.IsValid=false;
		return;
	}
	else
	{
		arguments.IsValid=true;
		return;
	}
}
		
function validateNumeric(source, arguments)
{
	var str;
	var str = new String(arguments.Value);
	
	var objRegExp = /^[0-9\s]+$/;
	var flag = str.match(objRegExp);
	
	if (flag == null)
	{
		arguments.IsValid = false;
		return ; // invalid string
	}
	else 
	{
		arguments.IsValid = true;
		return ; // valid string
	}
}

var isIE = document.all?true:false;
var isNS = document.layers?true:false;

function onlyDigits(e) 
{
	var key = (isIE) ? window.event.keyCode : e.which;
	var obj = (isIE) ? event.srcElement : e.target;
	var isNum = (key > 47 && key < 58) ? true:false;

	if(key < 32)
		return true;
	return (isNum);
}


function SelectGrid(oTemp,nGridNumber,frmName)
{
	var oGrid, sGrid;
	if (nGridNumber==1){ oGrid=grdData; sGrid="grdData";}
	
	var sColor,sCheck;				
			
	if(oTemp.checked==true)
	{
		sColor = "#d3d3d3";
		sCheck = true;
	}
	else
	{
		sColor = "#ffffff";
		sCheck = false;
	}
	
	for(i=2;i<=oGrid.rows.length+1;i++)
	{					
		oCheck = eval("document." + frmName + "." + sGrid +"__ctl" + i + "_chkDelete");								
		//alert("document.Form1." + sGrid +"__ctl" + i + "_chkSelect" + sGrid.substring(3,4));
		if (oCheck)
		{
			 					
			if(oCheck.disabled==false)
			{
				oCheck.checked = sCheck;
				//oCheck.parentElement.parentElement.parentElement.bgColor = sColor;
			}
				
		}
	}
	
}


function confirmReject(frmName) 
{
	// loop through all elements
	frm=eval("document." + frmName);
	var agree = confirm ('Are you sure you want to reject');
	//alert(agree);
	if (agree)
	{
		var rejectwhy = prompt("Rejected Why?"," ");
		frm.hdnRejectWhy.value=rejectwhy;
		return true ;
	}
	else
	{
		return false ;
	}
}
		

function confirmDelete(frmName,chkName,what) 
{
	// loop through all elements
	
	frm=eval("document." + frmName);
	j=0;
	for (i=0; i<frm.length; i++) 
	{
		// Look for our checkboxes only
		if (frm.elements[i].name.indexOf(chkName) !=-1) 
		{
			// If any are checked then confirm alert, otherwise nothing happens\n
			if(frm.elements[i].checked) 
			{
				j=j+1;
				if(what != "Email" && what != "Donate")
				{
					return confirm ('Are you sure you want to' + ' ' + what + ' ' + 'your selection(s)?')
				}
			}
		}
	}

	if(j==0)
	{
		alert('Please select items to' + ' ' + what);
		return false;
	}

}
		
//Function For checking if entered date is greater then current date
function validateCurrentDate(source, arguments)
		{
			currdate = new Date()
			userdate = new Date(arguments.Value)

			currdate.setDate(currdate.getDate()-1)

			if (currdate < userdate)
			{
		          
				arguments.IsValid = false;						
				return;     
			}
			else
			{
				arguments.IsValid = true;
				return ; 
			}
		}
		
		
		//Function For checking if entered date is less then current date
function validateBackDate(source, arguments)
		{
			currdate = new Date()
			userdate = new Date(arguments.Value)

			currdate.setDate(currdate.getDate()-1)

			if (userdate < currdate)
			{
		          
				arguments.IsValid = false;						
				return;     
			}
			else
			{
				arguments.IsValid = true;
				return ; 
			}
		}
		
//Function Phone

var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) 
{
	var keyCode = (isNN) ? e.which : e.keyCode; 
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	if(input.value.length >= len && !containsElement(filter,keyCode)) {
	input.value = input.value.slice(0, len);
	input.form[(getIndex(input)+1) % input.form.length].focus();
}
function containsElement(arr, ele) 
{
	var found = false, index = 0;
	while(!found && index < arr.length)
	if(arr[index] == ele)
		found = true;
	else
		index++;
	return found;
}
function getIndex(input) 
{
	var index = -1, i = 0, found = false;
	while (i < input.form.length && index == -1)
	if (input.form[i] == input)index = i;
	else i++;
	return index;
}
return true;
}
