﻿
var dtCh = "/";
var minYear = 1900;
var maxYear = 2100;

function Usercomments()
{
var name=document.getElementById(username);
var contactno=document.getElementById(usercontactno);
var emailid=document.getElementById(email);
var company=document.getElementById(company);
var suggestions=document.getElementById(suggestions);

if(name.value=="")
{
    alert('Please enter User Name.');
      name.focus();
      return false;
}
if(emailid.value=="")
{
    alert('Please enter E-mail.');
      emailid.focus();
      return false;
}
if(emailid.value!='')
  {
      if(EmailValid(email)==false)
      { 
      emailid.focus();
      return false;
      }  
  }

if(company.value=="")
{
    alert('Please enter Your Organization Name.');
      company.focus();
      return false;
}if(contactno.value=="")
{
    alert('Please enter Contact No.');
      contactno.focus();
      return false;
}
if(suggestions.value=="")
{
    alert('Please enter Your Suggestions/ Requirements.');
      suggestions.focus();
      return false;
}

}


function userlogincheck()
{   
    var userloginid = document.getElementById(userid);
    var password = document.getElementById(userpassword);
  
      if(userloginid.value=='')
      {
      alert('Please enter User Name.');
      userloginid.focus();
      return false;
      }
if(userloginid.value!='')
  {
      if(EmailValid(userid)==false)
      { 
      userloginid.focus();
      return false;
      }  
  }
  //--------------------------------
   if(password.value=='')
      {
      alert('Please enter your Password.');
      password.focus();
      return false;
      }

}


function Adminlogincheck()
{
    var adminuserid = document.getElementById(adminid);
    var password = document.getElementById(adminpassword);
     
     if(adminuserid.value=='')
      {
      alert('Please enter User Name.');
      adminuserid.focus();
      return false;
      }
//if(adminuserid.value!='')
//  {
//      if(EmailValid(adminid)==false)
//      { 
//      adminuserid.focus();
//      return false;
//      }  
//  }
  //--------------------------------
   if(password.value=='')
      {
      alert('Please enter your Password.');
      password.focus();
      return false;
      }


}



function CorporateRegistration()
{

 var uemailid = document.getElementById(emailid);
    var upassword = document.getElementById(password);
    var uconfirmpassword = document.getElementById(confirmpassword);
    var ucompany = document.getElementById(company);
    var ucontactperson = document.getElementById(contactperson);
     var udesignation = document.getElementById(designation);
       var uindustrytype = document.getElementById(industrytype);
     var uaddress = document.getElementById(address);
      var usecurity= document.getElementById(security);
  
     
     // check validation details of trainee registrations
  
      if(uemailid.value=='')
      {
      alert('Please enter Email-Id.');
      uemailid.focus();
      return false;
      }
if(uemailid.value!='')
  {
      if(EmailValid(emailid)==false)
      { 
      uemailid.focus();
      return false;
      }  
  }
  //--------------------------------
   if(upassword.value=='')
      {
      alert('Please enter Password.');
      upassword.focus();
      return false;
      }
 //-------------------------------- 
 if(uconfirmpassword.value=='')
      {
      alert('Please enter Confirm-Password.');
      uconfirmpassword.focus();
      return false;
      }
 
      
      if(uconfirmpassword.value!=upassword.value)
      {
      alert('Confirm-Password and Password Should be same.');
      uconfirmpassword.focus();
      return false;
      }
      
      
      //-------------------------
       if(ucompany.value=='')
      {
      alert('Please enter Company Name.');
      ucompany.focus();
      return false;
      }
      
      
       if(uindustrytype.selectedIndex==0)
      {
      alert('Please select Industry type.');
      uindustrytype.focus();
      return false;
      }
      
     if(ucontactperson.value=='')
      {
      alert('Please enter Contact Person Name.');
      ucontactperson.focus();
      return false;
      }
     if(udesignation.value=='')
      {
      alert('Please enter Contact Person Designation.');
      udesignation.focus();
      return false;
      }
     if(uaddress.value=='')
      {
      alert('Please enter Address Details.');
      uaddress.focus();
      return false;
      }
       if(uaddress.value!='')
      {
     if(DescCheck(address)==false){uaddress.focus();return false;}
      } 
      if(usecurity.value=='')
      {
      alert('Please enter Security No Which is Display Above.');
      usecurity.focus();
      return false; 
      }  
}


function TraineeRegistration() {
    var uemailid = document.getElementById(emailid);
    var upassword = document.getElementById(password);
    var uconfirmpassword = document.getElementById(confirmpassword);
    var ufirstname = document.getElementById(firstname);
    var ulastname = document.getElementById(lastname);
    var ufathername = document.getElementById(fathername);
    var utempcontact = document.getElementById(tempcontact);
    var upermanentcontact = document.getElementById(permanentcontact);
    var utelareacode = document.getElementById(telareacode);
    var utelephoneno = document.getElementById(telephoneno);
    var umobileno = document.getElementById(mobileno);
    var ugender = document.getElementById(gender);
    var udobdays = document.getElementById(dobdays);
    var udobmonth = document.getElementById(dobmonth);
    var udobyear = document.getElementById(dobyear);
//    var HighestQualification = document.getElementById(HighestQualification);
//    var txtspecialization = document.getElementById(txtspecialization);
    var utxtuniversity = document.getElementById(txtuniversity);
    var utrainingday = document.getElementById(trainingday);
    var utrainingmonth = document.getElementById(trainingmonth);
    var utrainingyear = document.getElementById(trainingyear);
    var uddno = document.getElementById(ddno);
    var uddamount = document.getElementById(ddamount);
    var ubankname = document.getElementById(bankname);
    var ubranchname = document.getElementById(branchname);
    var udddate = document.getElementById(dddate);
      var uprogram = document.getElementById(program);
       var usecurity= document.getElementById(security);
  
  // check validation details of trainee registrations
  
      if(uemailid.value=='')
      {
      alert('Please enter Email-Id.');
      uemailid.focus();
      return false;
      }
if(uemailid.value!='')
  {
      if(EmailValid(emailid)==false)
      { 
      uemailid.focus();
      return false;
      }  
  }
  //--------------------------------
   if(upassword.value=='')
      {
      alert('Please enter Password.');
      upassword.focus();
      return false;
      }
 //-------------------------------- 
 if(uconfirmpassword.value=='')
      {
      alert('Please enter Confirm-Password.');
      uconfirmpassword.focus();
      return false;
      }
 
      
      if(uconfirmpassword.value!=upassword.value)
      {
      alert('Confirm-Password and Password Should be same.');
      uconfirmpassword.focus();
      return false;
      }
        //--------------------------------
   if(ufirstname.value!='')
      {
           if(CheckName(firstname)==false){ufirstname.focus();return false;}
      }
     
     if(ufirstname.value=='')
      {
      alert('Please enter First Name.');
      ufirstname.focus();
      return false;
      }
     
         //--------------------------------
   if(ulastname.value=='')
      {
      alert('Please enter Last Name.');
      ulastname.focus();
      return false;
      }
        if(ulastname.value!='')
      {
           if(CheckName(lastname)==false){ulastname.focus();return false;}
      }
           //--------------------------------
   if(ufathername.value=='')
      {
      alert('Please enter Father/Husband Name.');
      ufathername.focus();
      return false;
      }
      
    if(utempcontact.value!='')
      {
     if(DescCheck(tempcontact)==false){utempcontact.focus();return false;}
      }
    if(upermanentcontact.value!='')
      {
     if(DescCheck(permanentcontact)==false){upermanentcontact.focus();return false;}
      }
//-------------------------------------
      
 if( utelareacode.value!='')
      {
     if(IsNumeric(utelareacode,"Area Code.")==false){utelareacode.focus();return false;}
      }
      
       //----------------------------------------
      
    if( utelephoneno.value!='')
      {
     if(IsNumeric(utelephoneno,"Telephone No.")==false){utelephoneno.focus();return false;}
      }
      
      if(umobileno.value=='')
      {
      alert('Please enter Mobile No.');
      umobileno.focus();
      return false;
      
      }
      
      if( umobileno.value!='')
      {
     if(IsNumeric(umobileno,"Mobile No.")==false){umobileno.focus();return false;}
      }
      
//------------------------------------------
       if(ugender.selectedIndex==0)
      {
      alert('Please select Sex.');
      ugender.focus();
      return false;
      
      }
  //------------------------------------------
       if(ugender.selectedIndex==0)
      {
      alert('Please select Sex.');
      ugender.focus();
      return false;
      
      }
    //----------Date Of Birth Validation--------------------------------
       if(udobdays.selectedIndex==0)
      {
      alert('Please select Date of Birth Day.');
      udobdays.focus();
      return false;
      
      }
     //----------Date Of Birth Validation--------------------------------
       if(udobmonth.selectedIndex==0)
      {
      alert('Please select Date of Birth Month.');
      udobmonth.focus();
      return false;
      
      }
       //----------Date Of Birth Validation--------------------------------
       if(udobyear.selectedIndex==0)
      {
      alert('Please select Date of Birth Year.');
      udobyear.focus();
      return false;
      
      }
        //----------Training Date Validation--------------------------------
       if(utrainingday.selectedIndex==0)
      {
      alert('Please select Training Start Day.');
      utrainingday.focus();
      return false;
      
      }
       //----------Training Date Validation--------------------------------
       if(utrainingmonth.selectedIndex==0)
      {
      alert('Please select Training Start Month.');
      utrainingmonth.focus();
      return false;
      
      }   //----------Training Date Validation--------------------------------
       if(utrainingyear.selectedIndex==0)
      {
      alert('Please select Training Start Year.');
      utrainingyear.focus();
      return false;
      
      }
      
      ///Registration Fee Details------------------------------------
      //-----------------------------------------
     if(uddno.value=='')
      {
      alert('Please enter DD No.');
      uddno.focus();
      return false;
      
      } 
           //-----------------------------------------
     if(uddno.value!='')
      {
       if(IsNumeric(uddno,"DD No.")==false){uddno.focus();return false;}
      
      }      //-----------------------------------------
     if(udddate.value=='')
      {
      alert('Please enter DD Date.');
      udddate.focus();
      return false;
      
      }      //-----------------------------------------
   
    if(udddate.value!='')
      {
       if(dateFormat(dddate)==false){udddate.focus();return false;}
      
      }  
      
    if(uddamount.value=='')
      {
      alert('Please enter DD Amount.');
      uddamount.focus();
      return false; 
      }  
      if(uddamount.value!='')
      {
       if(IsNumeric(uddamount,"DD Amount.")==false){uddamount.focus();return false;}
      
      }   
      
      if(ubankname.value=='')
      {
      alert('Please enter Bank Name.');
      ubankname.focus();
      return false; 
      }   
     if(ubranchname.value=='')
      {
      alert('Please enter Bank Branch Name.');
      ubranchname.focus();
      return false; 
      }  
      if(uprogram.selectedIndex==0)
      {
      alert('Please select Training Program.');
      uprogram.focus();
      return false;
      
      }
       if(usecurity.value=='')
      {
      alert('Please enter Security No Which is Display Above.');
      usecurity.focus();
      return false; 
      }  
}


function IsNumeric(fld, field) {
    var num = /^\d+$/;

    if (!num.test(fld.value)) {
        alert("Only Numeric values allowed in " + field);
        return false;


    }
}


function isDate(dtStr) {
    var daysInMonth = DaysArray(12)
    var pos1 = dtStr.indexOf(dtCh)
    var pos2 = dtStr.indexOf(dtCh, pos1 + 1)
    var strDay = dtStr.substring(0, pos1)
    var strMonth = dtStr.substring(pos1 + 1, pos2)
    var strYear = dtStr.substring(pos2 + 1)
    strYr = strYear
    if (strDay.charAt(0) == "0" && strDay.length > 1) strDay = strDay.substring(1)
    if (strMonth.charAt(0) == "0" && strMonth.length > 1) strMonth = strMonth.substring(1)
    for (var i = 1; i <= 3; i++) {
        if (strYr.charAt(0) == "0" && strYr.length > 1) strYr = strYr.substring(1)
    }
    month = parseInt(strMonth)
    day = parseInt(strDay)
    year = parseInt(strYr)
    if (pos1 == -1 || pos2 == -1) {
        alert("The date format should be : dd/mm/yyyy")
        return false
    }
    if (strMonth.length < 1 || month < 1 || month > 12) {
        alert("Please enter a valid month")
        return false
    }
    if (strDay.length < 1 || day < 1 || day > 31 || (month == 2 && day > daysInFebruary(year)) || day > daysInMonth) {
        alert("Please enter a valid day")
        return false
    }
    if (strYear.length != 4 || year == 0 || year < minYear || year > maxYear) {
        alert("Please enter a valid 4 digit year between " + minYear + " and " + maxYear)
        return false
    }
    if (dtStr.indexOf(dtCh, pos2 + 1) != -1 || isInteger(stripCharsInBag(dtStr, dtCh)) == false) {
        alert("Please enter a valid date")
        return false
    }
    return true
}

function ValidateForm(date) {

    var dt = document.getElementById(date);
    if (isDate(dt.value) == false) {
        dt.focus()
        return false
    }
    return true
}

   function CheckName(obj)
{

 var objval = document.getElementById(obj);
 var numaric = objval.value;
        for(var j=0; j<numaric.length; j++)
        {
            var alphaa = numaric.charAt(j);
            var hh = alphaa.charCodeAt(0);
            if((hh==32 || hh==46 || hh > 64 && hh<91) || (hh > 96 && hh<123))
            {
            }
            else 
            {
            objval.focus();
            alert("Only Alphabets are allowed.");
            return false;
            }
        }
        return true;
}


function DescCheck(alphane)
    {
//debugger;
        var numaric = document.getElementById(alphane).value;
        var spcount=0,ncount=0;
        var iChars = "_~`!@#$%^&*()+=-[]\\\';,./{}|\":<>?";

        for(var j=0; j<numaric.length; j++)
        {
        if (iChars.indexOf(numaric.charAt(j)) != -1)
        {
        spcount=spcount+1;
        }
        else
        {
        spcount=0;
        }
        var strValidChars = "0123456789";
        if (strValidChars.indexOf(numaric.charAt(j)) != -1)
        {
        ncount=ncount+1;
        }
        else
        {
        ncount=0;
        }
        }
        if(spcount>2)
        {
        alert ("Address Field has special characters only. \nThese are not allowed.\n Please remove them and add Alphanumeric values.");
  	    return false;
        }
         if(ncount>2)
        {
        alert ("Address Field has numeric characters only. \nThese are not allowed.\n Please remove them and add Alphanumeric values.");
  	    return false;
        }
         for(var j=0; j<numaric.length; j++)
        {
        var alphaa = numaric.charAt(j);
        var hh = alphaa.charCodeAt(0);
        if(hh >= 32 && hh<=128)
        //if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123))
        {
        }
        else 
        {
        alert("Please enter alphanumeric values only.");
        alphane.value='';
        alphane.focus();
        
        return false;
        }
        }
        return true;
    }

    

function EmailValid(obj)
{
var src = document.getElementById(obj);
if(src.value!="")
{
srcVal=src.value;
var panPat=/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
//var panPat=/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
if(srcVal.search(panPat)== -1)
{
alert("Enter valid email ID in format : xxx@abc.com");
src.focus();
return false;
}
//check for email length
else if(srcVal.length<6)
{
//alert("A");
alert("Please enter email ID with at least 6 characters.");
src.focus();
return true;
}
}
}

function isNumber(obj){
//debugger;
var inputStr = document.getElementById(obj).value;
	for (var i = 0; i < inputStr.length; i++) {
	var oneChar = inputStr.substring(i, i + 1)
	if (oneChar < "0" || oneChar > "9")
	{
	alert("Please enter number(s) only.")
	document.getElementById(obj).focus();
	return false;
	}
	}
	return true;
}
function dateFormat(fld) 
{

    var fldValue = document.getElementById(fld).value;
    if ( fldValue != "")
    {
    //var pattern = /\b(?:(?:0?[1-9]|1\d|2[0-8])(\/|-)(?:0?[1-9]|1[0-2]))(\/|-)(?:[1-9]\d\d\d|\d[1-9]\d\d|\d\d[1-9]\d|\d\d\d[1-9])$|^(?:(?:31(\/|-)(?:0?[13578]|1[02]))|(?:(?:29|30)(\/|-)(?:0?[1,3-9]|1[0-2])))(\/|-)(?:[1-9]\d\d\d|\d[1-9]\d\d|\d\d[1-9]\d|\d\d\d[1-9])$|^(29(\/|-)0?2)(\/|-)(?:(?:0[48]00|[13579][26]00|[2468][048]00)|(?:\d\d)?(?:0[48]|[2468][048]|[13579][26]))\b/
    
    var pattern = /\b(?:(?:0?[1-9]|1\d|2[0-8])(\/)(?:0?[1-9]|1[0-2]))(\/)(?:[1-9]\d\d\d|\d[1-9]\d\d|\d\d[1-9]\d|\d\d\d[1-9])$|^(?:(?:31(\/)(?:0?[13578]|1[02]))|(?:(?:29|30)(\/)(?:0?[1,3-9]|1[0-2])))(\/)(?:[1-9]\d\d\d|\d[1-9]\d\d|\d\d[1-9]\d|\d\d\d[1-9])$|^(29(\/|-)0?2)(\/)(?:(?:0[48]00|[13579][26]00|[2468][048]00)|(?:\d\d)?(?:0[48]|[2468][048]|[13579][26]))\b/
    if (pattern.test(fldValue)) 
    {
       // checkFutureDate(fld);            
        return true;        
    }
    else 
    {
        alert("Valid Date Format is DD/MM/YYYY"); 
        document.getElementById(fld).value = "" ;
        document.getElementById(fld).focus();
        return false;        
    }
    }
 }
