﻿// JScript File
function Validation(fullname,Organisation,address,city,zip,day,month,year,TelNos,MobileNumber,Email,ConfirmEmail,Password,ConfirmPassword)
{ if(document.getElementById(fullname).value == '')
   { alert("Full name can not be blank ");
     document.getElementById(fullname).focus();
     return false;
   }
   if(document.getElementById(Organisation).value == '')
   { alert("Organisation can not be blank ");
     document.getElementById(Organisation).focus();
     return false;
   }
   if(document.getElementById(address).value == '')
   { alert("Address can not be blank ");
     document.getElementById(address).focus();
     return false;
   }
   if(document.getElementById(city).value == '')
   { alert("city can not be blank ");
     document.getElementById(city).focus();
     return false;
   }
   if(document.getElementById(zip).value == '')
   { alert("zip can not be blank ");
     document.getElementById(zip).focus();
     return false;
   }
 //  if(document.getElementById(zip).value != '')
  // { if(isNaN(document.getElementById(zip).value))
  //    { alert("Zip must be digit");
  //      document.getElementById(zip).value = '';
  //      document.getElementById(zip).focus();
   //     return false;
   //   }
 //  }     
   if(document.getElementById(day).value == '0')
   { alert("Select day ");
     document.getElementById(day).focus();
     return false;
   }    
   if(document.getElementById(month).value == '0')
   { alert("Select month ");
     document.getElementById(month).focus();
     return false;
   }   
   if(document.getElementById(year).value == '0')
   { alert("Select year ");
     document.getElementById(year).focus();
     return false;
   }  
   if(document.getElementById(TelNos).value == '')
   { alert("TelNos can not be blank ");
     document.getElementById(TelNos).focus();
     return false;
   }
   if(document.getElementById(TelNos).value != '')
   { if(isNaN(document.getElementById(TelNos).value))
      { alert("TelNos must be digit");
        document.getElementById(TelNos).value = '';
        document.getElementById(TelNos).focus();
        return false;
      }
   } 
   if(document.getElementById(MobileNumber).value == '')
   { alert("MobileNumber can not be blank ");
     document.getElementById(MobileNumber).focus();
     return false;
   }
   if(document.getElementById(MobileNumber).value != '')
   { if(isNaN(document.getElementById(MobileNumber).value))
      { alert("MobileNumber must be digit");
        document.getElementById(MobileNumber).value = '';
        document.getElementById(MobileNumber).focus();
        return false;
      }
   } 
   if(document.getElementById(Email).value == '')
   { alert("Email can not be blank ");
     document.getElementById(Email).focus();
     return false;
   }
   if(!emailCheck(document.getElementById(Email).value))
   { document.getElementById(Email).value = '';
     document.getElementById(Email).focus();
     return false;
   }  
   if(document.getElementById(ConfirmEmail).value == '')
   { alert("ConfirmEmail can not be blank ");
     document.getElementById(ConfirmEmail).focus();
     return false;
   }
   if(document.getElementById(Email).value != document.getElementById(ConfirmEmail).value)
   { alert("ConfirmEmail and Email must be same ");
     document.getElementById(ConfirmEmail).value = '';
     document.getElementById(ConfirmEmail).focus();
     return false;
   }
       
   if(document.getElementById(Password).value == '')
   { alert("Password can not be blank ");
     document.getElementById(Password).focus();
     return false;
   }    
   if(document.getElementById(ConfirmPassword).value == '')
   { alert("ConfirmPassword can not be blank ");
     document.getElementById(ConfirmPassword).focus();
     return false;
   } 
   if(document.getElementById(Password).value != document.getElementById(ConfirmPassword).value)
   { alert("ConfirmPassword  and  Password must be same ");
     document.getElementById(ConfirmPassword).value = '';
     document.getElementById(ConfirmPassword).focus();
     return false;
   }
        
}     




function emailCheck(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
    
	    // check if '@' is at the first position or  at last position or absent in given email 
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
		{
		   alert("Invalid E-mail ID")
		   return false
		}
        // check if '.' is at the first position or at last 
     //   position or absent in given email
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
		{
		    alert("Invalid E-mail ID")
		    return false
		}
        // check if '@' is used more than one times in given email
		if (str.indexOf(at,(lat+1))!=-1)
		{
		    alert("Invalid E-mail ID")
		    return false
		 }
   
         // check for the position of '.'
		 if (str.substring(lat-1,lat)==dot ||  str.substring(lat+1,lat+2)==dot)
		 {
		    alert("Invalid E-mail ID")
		    return false
		 }
         // check if '.' is present after two characters 
       //  from location of '@'
		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 // check for blank spaces in given email
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
 		 return true					
	}


