function textbox_onkeypress()
{
    if(event.keyCode >= 97 && event.keyCode <= 122)
        event.keyCode -= 32;
}

function applied() {
	
	document.getElementById("errorPanel").innerHTML = "";
	var errorMsgs = new Array();
	var errorFlag = false;
	var errorIndex = 0;	
	
	
	var friendsName =document.InviteFriendForm.friendsName.value;		
	//var name=document.InviteFriendForm.userEmailID.value;
	var email=document.InviteFriendForm.email.value;
	var phone=document.InviteFriendForm.phoneNumber.value;
	var useremailid=document.InviteFriendForm.registrationNumber.value;
	var classes=document.InviteFriendForm.classes.value;
	var school=document.InviteFriendForm.school.value;
	var city=document.InviteFriendForm.city.value;
	var country=document.InviteFriendForm.country.value;
	
	/*if(name == ''  )
	{
		errorMsgs[errorIndex] = "Please enter Registration Number .";
		errorIndex = errorIndex + 1;
		errorFlag =true;
	}	
	
	if(!isValidRegNo(name) && !isEmpty(name))
	{
		errorMsgs[errorIndex] = "Please enter valid Registration Number .";
		errorIndex = errorIndex + 1;
		errorFlag =true;
	}	*/
		
	if( useremailid == '' || !trim(useremailid))
	{
		errorMsgs[errorIndex] = "Please enter User Email ID .";
		errorIndex = errorIndex + 1;
		errorFlag =true;
	}
	if(!isEmpty(useremailid) && !isEmpty(email) && useremailid == email)
	{
		errorMsgs[errorIndex] = " User Email ID and Friends Email ID cannot be same.";
		errorIndex = errorIndex + 1;
		errorFlag =true;
	}
	
	if(friendsName == '' || !trim(friendsName))
	{	
		errorMsgs[errorIndex] = "Please enter friends name.";
		errorIndex = errorIndex + 1;
		errorFlag =true;
	}
	
	if (!isEmpty(friendsName) && !isValidCNames(friendsName))
	{
		errorMsgs[errorIndex] = "Please enter valid name.";
		errorIndex = errorIndex + 1;
		errorFlag = true;
	}		
	/*if (!isEmpty(friendsName) && valid(friendsName))
	{
		errorMsgs[errorIndex] = "Please enter valid name.";
		errorIndex = errorIndex + 1;
		errorFlag = true;
	}	*/	
	if(email == '' || !trim(email))
	{
		errorMsgs[errorIndex] = "Please enter friends Email.";
		errorIndex = errorIndex + 1;
		errorFlag =true;
	}		
	
	/*if(phone == '')
	{
		errorMsgs[errorIndex] = "Please enter phone number.";
		errorIndex = errorIndex + 1;
		errorFlag =true;
	}*/	
	if(classes == "0" || classes == "ZERO" || classes == "zero")
	{
		errorMsgs[errorIndex] = "Please enter valid class name.";
		errorIndex = errorIndex + 1;
		errorFlag =true;
	}
	if(!isEmpty(classes) && validClass(classes))
	{
		errorMsgs[errorIndex] = "Please enter valid class name.";
		errorIndex = errorIndex + 1;
		errorFlag =true;
	}
	if (!isEmpty(school) && !isValidSchool(school))
	{
		errorMsgs[errorIndex] = "Please enter valid school name.";
		errorIndex = errorIndex + 1;
		errorFlag = true;
	}	
	if (!isEmpty(school) && isValidSchoolName(school))
	{
		errorMsgs[errorIndex] = "Please enter valid school name.";
		errorIndex = errorIndex + 1;
		errorFlag = true;
	}	
	/*if (!isEmpty(city) && !isValidDNames(city) || validCountryAndCity(city))
	{
		errorMsgs[errorIndex] = "Please enter valid city name.";
		errorIndex = errorIndex + 1;
		errorFlag = true;
	}	
	
	if (!isEmpty(country) && !isValidDNames(country) || validCountryAndCity(country))
	{
		errorMsgs[errorIndex] = "Please enter valid country name.";
		errorIndex = errorIndex + 1;
		errorFlag = true;
	}	*/
	if (!isEmpty(city) && !isValidOther(city))
	{
		errorMsgs[errorIndex] = "Please enter valid city name.";
		errorIndex = errorIndex + 1;
		errorFlag = true;
	}	
	if (!isEmpty(country) && !isValidOther(country) )
	{
		errorMsgs[errorIndex] = "Please enter valid country name.";
		errorIndex = errorIndex + 1;
		errorFlag = true;
	}
	
	if(!isValidPhoneNumber(phone) && !isEmpty(phone))
	{
	  errorMsgs[errorIndex] = "Please enter Valid Phone Number.";
		errorIndex = errorIndex + 1;
		errorFlag =true;
	}
		if(!isEmpty(phone) &&  validphone(phone))
	{
	  errorMsgs[errorIndex] = "Please enter Valid Phone Number.";
		errorIndex = errorIndex + 1;
		errorFlag =true;
	}
		
	if(document.InviteFriendForm.contactBy[1].checked == true && isEmpty(phone))
	{	
		
		errorMsgs[errorIndex]  = "Please provide your friends phone number.";
		errorIndex = errorIndex + 1;
		errorFlag =true;
	}
			
	if((document.InviteFriendForm.contactBy[0].checked == false) && (document.InviteFriendForm.contactBy[1].checked == false))
	{
		errorMsgs[errorIndex] = "Please select Contact  By.";
		errorIndex = errorIndex + 1;
		errorFlag =true;
	}
	
	var x = isValidFriendEmail(email);
	if (!isEmpty(email) && -1 != x) {	
		errorMsgs[errorIndex] = emailErrorFriend[x];
		errorIndex = errorIndex + 1;
		errorFlag = true;
	}
	var y = isValidEmail(useremailid);
	if (!isEmpty(useremailid) && -1 != y) {
		errorMsgs[errorIndex] = emailError[y];
		errorIndex = errorIndex + 1;
		errorFlag = true;
	}
	
	var answer = false;
	
	/*if (!errorFlag) {
		var alertMsg = "";		
			alertMsg = "Are you sure to save?";
		 answer = confirm(alertMsg);
		
	}else{*/	
		document.getElementById("errors").style.display='none';
		document.getElementById("divforfailure").style.display='none';
		var errorMsg = "";
		for (var i = 0; i < errorIndex; i++) {
			errorMsg = errorMsg + errorMsgs[i] + "<br/>" ;	
		document.getElementById("errorPanel").style.display = "block";
		document.getElementById("errorPanel").innerHTML = errorMsg;
		document.getElementById("errorPanel").setAttribute("class", "err");
		document.getElementById("errorPanel").focus();
	}
	//}
	if (!errorFlag) {	
		document.InviteFriendForm.submit();		
		}
			return;
	
}	

function show(display) {
	if(display == "yes"){
	var answer = confirm("Do you want to refer more friends?");
	 	/*if(answer ){
		document.location="inviteFriend.do";	
		}
		else*/
		if(!answer){
		document.location="registrationHome.do";
		}
	}
	
}	
function clickCancel() {
 
	var answer = confirm("Are you sure you want to cancel?");
			if(answer)	{
		document.location="registrationHome.do";	
	}
}
