﻿function ChangeBackground()
{
    var name=document.getElementById("txtName");
    var email=document.getElementById("txtEmail");
    var tno=document.getElementById("txtPhone");
    var city=document.getElementById("txtCity");
    var need=document.getElementById("txtNeeds");
   
    if(name.value==null || name.value=='')
    {
        name.style.background='red';
    }
    if(email.value==null || email.value=='')
    {
        email.style.background='red';
    }
    if(tno.value==null || tno.value=='')
    {
        tno.style.background='red';
    }
    if(city.value==null || city.value=='')
    {
        city.style.background='red';
    }
    if(need.value==null || need.value=='')
    {
        need.style.background='red';
    }
    
    if(name.value!=null && name.value!='')
    {
        name.style.background='#999999';
         
        if(tno.value!=null && tno.value!='')
        {
            tno.style.background='#999999';
           
                    if(city.value!=null && city.value!='')
                    {
                        city.style.background='#999999';
                        
                        if(need.value!=null && need.value!='')
                        {
                            need.style.background='#999999';
                            
                            if(email.value!=null && email.value!='')
                            {
                                //email.style.background='#999999';
                                //var val=echeck(email.value);
                                
                                var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;   
                                return emailPattern.test(email.value);                                 
                            }
                            else
                            {
                                email.style.background='red';
                                return false;
                            }              
                        }
                        else
                        {
                            need.style.background='red';
                            return false;
                        }   
                    }
                    else
                    {
                        city.style.background='red';
                        return false;
                    }  
          }
        else
        {
            tno.style.background='red';
            return false;
        }        
    }
    else
    {
        name.style.background='red';
        return false;
    }    
}
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){
		   alert("Invalid E-mail ID1")
		   return false
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID2")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID3")
		    return false
		}
		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID4")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID5")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID6")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID7")
		    return false
		 }
 		 return true					
	}


function ChangeBorder()//Ctrlid,Ctrlval
{
    var name=document.getElementById("txtName");
    var email=document.getElementById("txtEmail");
    var tno=document.getElementById("txtPhone");
    var city=document.getElementById("txtCity");
    var need=document.getElementById("txtNeeds");
    
    
//alert("Id:"+Ctrlid+":"+Ctrlval);
   
//    if(Ctrlval.value!=null || Ctrlval.value!='')
//    {
//        name1.style.borderColor='#999999';
//    }
//    else
//    {
//        name1.style.borderColor='red';
//    }   
   
//    if(email.value<0)
//    {
//        email.style.borderColor='red';
//    }
//    else
//    {
//        email.style.borderColor='#999999';
//    }
//    if(tno.value<0)
//    {
//        tno.style.borderColor='red';
//    }
//    else
//    {
//        tno.style.borderColor='#999999';
//    }
//    if(city.value<0)
//    {
//        city.style.borderColor='red';
//    }
//    else
//    {
//        city.style.borderColor='#999999';
//    }
//    if(need.value<0)
//    {
//        need.style.borderColor='red';
//    }
//    else
//    {
//        need.style.borderColor='#999999';
//    }
  
}

function ChangeBackground1()
{
    var name=document.getElementById("txtName1");
    var email=document.getElementById("txtEmail1");
    var tno=document.getElementById("txtphone1");
    var city=document.getElementById("txtAddress");
    var need=document.getElementById("txtHelpNeeds");
   
    if(name.value==null || name.value=='')
    {
        name.style.background='red';
    }
    if(email.value==null || email.value=='')
    {
        email.style.background='red';
    }
    if(tno.value==null || tno.value=='')
    {
        tno.style.background='red';
    }
    if(city.value==null || city.value=='')
    {
        city.style.background='red';
    }
    if(need.value==null || need.value=='')
    {
        need.style.background='red';
    }
    
    if(name.value!=null && name.value!='')
    {
        name.style.background='#FFFFFF';
         
        if(tno.value!=null && tno.value!='')
        {
            tno.style.background='#FFFFFF';
           
                    if(city.value!=null && city.value!='')
                    {
                        city.style.background='#FFFFFF';
                        
                        if(need.value!=null && need.value!='')
                        {
                            need.style.background='#FFFFFF';
                            
                            if(email.value!=null && email.value!='')
                            {
                                //email.style.background='#999999';
                                //var val=echeck(email.value);
                                
                                var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;   
                                return emailPattern.test(email.value);                                 
                            }
                            else
                            {
                                email.style.background='red';
                                return false;
                            }              
                        }
                        else
                        {
                            need.style.background='red';
                            return false;
                        }   
                    }
                    else
                    {
                        city.style.background='red';
                        return false;
                    }  
          }
        else
        {
            tno.style.background='red';
            return false;
        }        
    }
    else
    {
        name.style.background='red';
        return false;
    }    
}


