// JavaScript Document

function gElement(id) 
{
	return document.getElementById(id);
	
}
//for check null value in input element
function idchk(s)
{
	var	c=document.getElementById(s).value;
	
	String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
	}

		var m = new String(c);
		// use it like this
		p=m.trim();
		if(p=='')
		{
			return(m);	
		}
}

//display div tag 
function block(s)
{
	//alert(s);
	var b="document.getElementById('"+s+"').style.display='block';";
	//alert(b);
	return b;
}

//remove div tag 
function none(s)
{
	//alert(s);
	//document.getElementById(s).style.display='none';
	var n="document.getElementById('"+s+"').style.display='none';";
	//alert(b);
	return n;
}

//finding element length 
function find_len(s)
{
	var le = "document.getElementById('"+s+"').value.length";
	//alert(le);
	return le ;
}

//for check validation

function checknew(ele)
{
	
	var ele_name=ele[0];
	var div_name=ele[1];
	var mylen=ele[2];
	var minlen=ele[3];
	var maxlen=ele[4];
	
	if(eval(idchk(ele_name)))
	{
		var a=block(div_name);
		eval(a);
		return false;	
	}
	else
	{	
		eval(none(div_name));
	}
	if(minlen!=0 && maxlen!=0)
	{

			var temp=find_len(ele_name);
			//alert(eval(temp));
			if((eval(temp) < minlen) || eval(temp) >= maxlen)
			{
				//alert(eval(temp));
				var a=block(mylen);
				eval(a);
				return false;	

			}
			else
			{
				eval(none(mylen));
				
			}
			
	}
	else
	{
		if(mylen!='')
		{
			eval(none(mylen));
		}
	}
	if(ele_name=='email')
	{
		if(echeck(gElement('email').value)==false){
			
		gElement('email').value="";
		gElement('email').focus();
		return false;
		}
		else
		{
			eval(none('div_email'));

		}
		
	}
	if(ele_name=='verify')
	{
		if(vcheck(gElement('verify').value)==false){
			gElement('verify').value="";
			gElement('verify').focus();
			return false;

		}
		else
		{
			eval(none('div_verify'));
			
		}
	}
	
	

	return true;
}

function echeck(str) {
		
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
			eval(block('div_email'));
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
			eval(block('div_email'));
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
			eval(block('div_email'));
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
			eval(block('div_email'));
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
			eval(block('div_email'));
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
			eval(block('div_email'));
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
			eval(block('div_email'));
		    return false
		 }

 		 return true					
	}
function vcheck(str) 
{
	if(str != 12)
	{
		eval(block('div_verify'));
		return false;
	}
	else
	{
		return true;
	}
}
	
function digit(s,d,e)
{

		var n = /^([+/-]?((([0-9]+(\.)?)|([0-9]*\.[0-9]+))([eE][+\-]?[0-9]+)?))$/;
		if(s.match(n))
		{
			eval(none(d));
			return true;
			
		}
		else
		{
			eval(block(d));
			gElement(e).value="";
			return false;
		}
		
		
}
