
var cssRequired = "color:#DF3A00;padding-right:3px;width:200px;font-family:Verdana,Arial,Helvetica,sans-serif; align:right; font-size:11px;";
var cssNotValid = "color:#DF3A00;padding-right:3px;width:200px;font-family:Verdana,Arial,Helvetica,sans-serif;font-size:11px;";
var cssNumber =  "color:#DF3A00;padding-right:3px;width:200px;font-family:Verdana,Arial,Helvetica,sans-serif;font-size:11px;"; 
var cssLength =  "color:#DF3A00;padding-right:3px;width:200px;font-family:Verdana,Arial,Helvetica,sans-serif;font-size:11px;"; 
var cssConfirm =  "color:#DF3A00;padding-right:3px;width:200px;font-family:Verdana,Arial,Helvetica,sans-serif;font-size:11px;";
var cssNoImage =  "color:#DF3A00;padding-right:3px;width:200px;font-family:Verdana,Arial,Helvetica,sans-serif;font-size:11px;";

var txtNoImage = "Not image file";
var textReq = "Required field" ; 
var textCofirm = "Not matched";
/*var textCofirm = "Email not matched";
*/
var textNotValid = "Not valid email" ; 
var textNumber  =  "Not number"; 
var textLength  =  "Invalid text length"; 

function createSpan(css,text)
{
    var sp = document.createElement("span");
    sp.setAttribute('id',"neelam"); 
    
    sp.style.cssText=css;
    sp.innerHTML=text; 
    return sp;
}
//this function is called when user clicks the button
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); 
        //to check if the there is more than one class on that input field;
       
	   
	   if (className.match([" "]))
        { 
            className = checkClassName(className); 
        } 
       	if (className == "required" || className == "validate" || className == "number" || className =='confirm' ||
			className =='count' ||  className =='confirmemail' )
		{ 
			//this function checks the class name and does the respective action 
			showResultAccordingTotheClassName(el , className);
		}
	   if (el.type == "checkbox" && className =="required")
		{ 
			processCheckBox(el);
		}
	   if (el.type == "password" && className =="confirm")
		{ 
		 
			password.push(el.value); 
			password.push(el); 
			processConfirmPassword(password);
		}
		
		if (el.type == "text" && className =="confirmemail")
		{ 
		   
			password.push(el.value); 
			password.push(el); 
			processConfirmEmail(password);
		}
		
		if(el.type =="file" && className =="image") 
		{ 
			checkImage(el); 
		} 
    }
    //stop submitting the form if there if it is not valid 
    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 processConfirmEmail(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)
	 { 
	 	//var spn  = createSpan(cssRequired ,textReq); 
		 if(checkNode. parentNode.lastChild.id != "neelam")
		{ 
			cs= cssRequired; 
			txt = textReq ;
			append(checkNode,createSpan(cs ,txt));
		}
		
		stat = true; 
	 } 
	
} 
function checkImage(els)
{ 
	
	if (els.value == "")
	{ 
		if(els.parentNode.lastChild.id != "neelam")
		{ 
			cs= cssRequired; 
			txt = textReq ;
			append(els,createSpan(cs,txt ));
		}
		stat = true; 
	}
	else if(!(els.value.match(/(png|jpg|JPG|JPEG|jpeg|gif|PNG|BMP|bmp)$/)))
	{ 
		
		if(els.parentNode.lastChild.id != "neelam")
		{ 
			
			cs  = cssNoImage;
			txt = txtNoImage;
			append(els,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  = cssNumber; 
                                        txt = textNumber; 
                                        append(elemnt,createSpan(cs,txt));
                                    }
                                    stat = true; 
                                    
                                } 
                                
                                break; 
								
			  case "count" :       
                                
                              if (elemnt.value == "")
                                { 
                                    if(elemnt. parentNode.lastChild.id != "neelam")
                                    { 
                                        cs= cssRequired; 
                                        txt = textReq;
                                        append(elemnt,createSpan(cs ,txt));
                                    }
                                    
                                    stat = true; 
                                } 
                                
                                else if (elemnt.value.length > 150 ||  elemnt.value.length < 2)
                                { 
                                   if(elemnt. parentNode.lastChild.id != "neelam")
                                    { 
                                        cs  = cssLength; 
                                        txt = textLength; 
                                        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; 
         }
} 


// splits the class Name with " " if there is more than one class name 
function checkClassName(name)
{ 
    names  = name.split(' ');
    for(var i=0; i < names.length; i++)
    { 
        if (names[i] == 'required' || names[i] == 'validate' || names[i] =='number' || names[i]=='confirm' || names[i]=='length')
        { 
            return names[i]; 
        } 
    } 
}

//removes the alert message if clicked on the textbox 
function remove(pnode,node)
{ 
    //to check if the message if still displayed or not 
   if (pnode.lastChild.id=='neelam')
    { 
        pnode.removeChild(pnode.lastChild);
    } 
    //node.removeAttribute("onclick"); 
    node.select(); 
}
//appends the span that displays the message to next to the textbox
var cnt = 0; 
function append(nd,sps)
{ 
    cnt++; 
	if (cnt ==1)
		{ 
			
			nd.focus();
		} 
    nd.parentNode.appendChild(sps); 
    //nd.setAttribute('onclick','remove(this.parentNode,this)'); 
    nd.onclick = textBoxClick;  
    
    
}

function textBoxClick()
{ 
    remove(this.parentNode, this);
} 
//check the form with id 'prabeen' and adds attribute to  the button which calls the check function on click;

window.onload = function()
{ 
    var ids = 'taxraja_form'; 
	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].setAttribute('onclick',"return checkValue(this.form);"); 
				frms.elements[i].onclick = buttonClick;   
            } 
        } 
    } 
	
	var ids1 = 'taxraja_form1'; 
	var frms1 = document.forms[ids1]; 
    if (frms1)
    { 
        
        for(var i=0; i < frms1.length;i++)
        {     
            if (frms1.elements[i].type == 'button' || frms1.elements[i].type =='submit')
            { 
                //frms.elements[i].setAttribute('onclick',"return checkValue(this.form);"); 
				frms1.elements[i].onclick = buttonClick;   
            } 
        } 
    } 
	
	
}
function buttonClick() 
{     
  
	return checkValue(this.form);
//return false
} 