var cssRequired="color:red;background-color:#FFFFFF;padding-left:3px;position:top;";
var cssNotValid="color:red;background-color:#FFFFFF;padding-right:3px;position:absolute;";
var cssNumber="color:red;background-color:#FFFFFF;padding-right:3px;position:absolute;";
var cssConfirm="color:red;background-color:#FFFFFF;padding-right:3px;position:absolute;";
var textReq=" required";
var notAgree="&nbsp; you must agree with our terms and conditions";
var textCofirm="&nbsp; email not <br/>&nbsp;matched";
var textNotValid="&nbsp; not valid email";
var texNotNumber=" &nbsp;not number";
function createSpan(css,text)
{
	var sp=document.createElement("span");
	sp.setAttribute('id',"neelam");
	sp.style.cssText=css;
	sp.innerHTML=text;
	return sp
}
function checkValue(frm){
	stat=false;
	var password=new Array();
	for(var i=0;i<frm.length;i++)
	{
		var el=frm.elements[i];
		var className=(el.className);
		if(className.match([" "]))
		{
			className=checkClassName(className)
		}
		if(className=="required"||className=="validate"||className=="number"||className=='confirm')
		{
				showResultAccordingTotheClassName(el,className)
		}
		if(el.type=="checkbox"&&className=="required")
		{
				processCheckBox(el)
		}
		if(el.type=="text"&&className=="confirm")
		{
					password.push(el.value);
					password.push(el);
					processConfirmPassword(password)
		}
	}
	if(stat)
	{
		return false
	}
}

function processConfirmPassword(pass){
	if(pass.length==4){
		if(pass[0]==""&&pass[2]==""){
			if(pass[1].parentNode.lastChild.id!="neelam"){
				cs=cssRequired;
				txt=textReq;
				append(pass[1],createSpan(cs,txt))
				}
				if(pass[3].parentNode.lastChild.id!="neelam"){
					cs=cssRequired;
					txt=textReq;
					append(pass[3],createSpan(cs,txt))
				}
					stat=true
				}else{
					if(pass[0]!=pass[2]){
						if(pass[1].parentNode.lastChild.id!="neelam"){
							cs=cssConfirm;
							txt=textCofirm;
							append(pass[1],createSpan(cs,txt))
						}
						if(pass[3].parentNode.lastChild.id!="neelam"){
							cs=cssConfirm;
							txt=textCofirm;
							append(pass[3],createSpan(cs,txt))
						}
						stat=true
					}
				}
			}
		}
function processCheckBox(checkNode)
{
	if(checkNode.checked==false)
	{
		if(checkNode.parentNode.lastChild.id!="neelam")
		{
			cs=cssRequired;
			txt=notAgree;
			append(checkNode,createSpan(cs,txt))
		}
			stat=true
	}
}
function showResultAccordingTotheClassName(elemnt,classNm)
{
	switch(classNm)
	{
		case"required":if(elemnt.value=="")
		{
			if(elemnt.parentNode.lastChild.id!="neelam")
			{
				cs=cssRequired;
				txt=textReq;
				append(elemnt,createSpan(cs,txt))
			}
				stat=true
		}
		break;
		case"number":
		if(elemnt.value.match([" "])||elemnt.value==""){
			if(elemnt.parentNode.lastChild.id!="neelam"){
				cs=cssRequired;
				txt=textReq;
				append(elemnt,createSpan(cs,txt))
			}
			stat=true
			}else if(isNaN(elemnt.value)){
				if(elemnt.parentNode.lastChild.id!="neelam"){
					cs=cssNotValid;
					txt=texNotNumber;
					append(elemnt,createSpan(cs,txt))
				}
				stat=true;
		}
		break;
		case"validate":
		if(elemnt.value.match([" "])||elemnt.value==""){
			if(elemnt.parentNode.lastChild.id!="neelam"){
				cs=cssRequired;
				txt=textReq;
				append(elemnt,createSpan(cs,txt))
			}
			stat=true
			}else if(!(elemnt.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi))){
				if(elemnt.parentNode.lastChild.id!="neelam"){
					cs=cssNotValid;
					txt=textNotValid;
					append(elemnt,createSpan(cs,txt))
				}
				stat=true
		}
		break
	}
}
function checkClassName(name){
	names=name.split(' ');
	for(var i=0;i<names.length;i++){
		if(names[i]=='required'||names[i]=='validate'||names[i]=='number'){
			return names[i]
		}
	}
}
function remove(pnode,node){
	if(pnode.lastChild.id=='neelam'){
		pnode.removeChild(pnode.lastChild)
	}
	node.select()
}
	var cnt=0;
function append(nd,sps)
	{
		cnt++;
		if(cnt==1){
			nd.focus()
		}
		nd.parentNode.appendChild(sps);
		nd.onclick=textBoxClick
}

function textBoxClick(){
	remove(this.parentNode,this)
	}
	window.onload=function(){
		var ids=unescape('%70%72%61%73%61%6E%6E%61'); 
var frms=document.forms[ids];
if(frms){
	for(var i=0;i<frms.length;i++)
	{
		if(frms.elements[i].type=='button'||frms.elements[i].type=='submit'){
			frms.elements[i].onclick=buttonClick
		}
	}
	}
	}
function buttonClick(){
	return checkValue(this.form);
}
