var pass=document.getElementById("pass");
btnvalid=false;
textval=false;
passval=false;
emailval=false;
var text_validate=function(){
	var text=document.getElementById('textin').value;
	var text_valid=document.getElementById('text_valid');
	if(text.length>100||text.length<6){
		text_valid.innerHTML="Please enter text ranging from 6-50 characters in length";textval=false;
		btnvalidate();
	}
	else{
		text_valid.innerHTML="";textval=true;
		btnvalidate();
	}
}
var text_empty=function(){
	var text_valid=document.getElementById('text_valid');
	text_valid.innerHTML="";
}
var pass_validate= function(){
	var pass=document.getElementById('pass').value;
	var pass_valid=document.getElementById('pass_valid');
	if(pass.length>20||pass.length<8){
		pass_valid.innerHTML="Please enter a password ranging from 8-20 characters in length";emailval=false;
		btnvalidate();
	}
	else{
		if(pass.split('$').length>1||pass.split('!').length>1||pass.split('@').length>1||pass.split('_').length>1){
			pass_valid.innerHTML=""; passval=true;
			btnvalidate();
		}
		else{
			pass_valid.innerHTML="Please enter a password with at least one special character among {$,!,@,_}"; passval=false;
			btnvalidate();
		}
	}
}
var pass_empty=function(){
	var pass_valid=document.getElementById('pass_valid');
	pass_valid.innerHTML="";
}
var email_validate=function(){
	var email=document.getElementById('email').value;
	var email_valid=document.getElementById('email_valid');
	var store=email.split('@');
	var cor1=true,cor2=true;

	if(store.length>2||store.length==1){
		cor1=false;
	}
	else{	
		var local=store[0];
		var domain=store[1].split('.');
		if(domain.length==1){
			cor2=false;
		}
		for(var i=0;i<domain.length;i++){
			if(i==0){
				if(domain[i].length<3){
					cor2=false;
				}
			}
			else{
				if(domain[i].length<2){
					cor2=false;
				}
			}
			for(var j=0;j<domain[i].length;j++){
				if((domain[i][j]>='a'&&domain[i][j]<='z')||(domain[i][j]>='A'&&domain[i][j]<='Z')){}
				else{
					cor2=false;
				}
			}
		}
		if(local.length<3){
			cor1=false;
		}
		else{
			for(var i=0;i<local.length;i++){
				if((local[i]>='0'&&local[i]<='9')||(local[i]>='a'&&local[i]<='z')||(local[i]>='A'&&local[i]<='Z')||local[i]=='.'||local[i]=='_'){
				}
				else{
					cor1=false;
				}
			}
		}
	}
	if(cor1&&cor2){
		email_valid.innerHTML="";emailval=true;
		btnvalidate();
	}
	else{
		email_valid.innerHTML="Please enter a valid email id";emailval=false;
		btnvalidate();
	}
}
var email_empty=function(){
	var email_valid=document.getElementById('email_valid');
	email_valid.innerHTML="";
}
var encode=function(){
	text=document.getElementById('textin').value;
	pass=document.getElementById('pass').value;
	email=document.getElementById('email').value;
	text=encodestr(text);
	pass=encodestr(pass);
	email=encodestr(email);
}
var encodestr=function(str){
	var len=str.length;
	for(var i=0;i<len;i++){
		if(str[i]=='<'){
			var front=str.substring(0,i);
			var back=str.substring(i+1,len);
			var store=front+"&lt"+back;
			str=store;
		}
		if(str[i]=='>'){
			var front=str.substring(0,i);
			var back=str.substring(i+1,len);
			var store=front+"&gt"+back;
			str=store;
		}
		if(str[i]=='/'){
			var front=str.substring(0,i);
			var back=str.substring(i+1,len);
			var store=front+"&#47"+back;
			str=store;
		}
	}
	return str;
}
var btnvalidate=function(){
	var submitbtn=document.getElementById('submitbtn')
	btnvalid=emailval&&passval&&textval;
	if(btnvalid){
		submitbtn.disabled=false;
	}
	else{
		submitbtn.disabled=true;
	}
}
window.onload=btnvalidate();