var stateUrl = current_http_host+'cemp/state/';

isIE =  $.browser.msie;
ieVersion = jQuery.browser.version ;
ie6DisableFormElements = false;

$(document).ready(function(){
  $(function()
  {
    $('form').css('position','relative');
    if($('#multiForm').children('.multiForm').length >1){
      navButtons =" <button type='button' id='multiFormNavBack'>Back</button> <button type='button' id='multiFormNavNext'>Next</button>" ;
      
      $('#multiFormNav').append(navButtons);
      $('#multiFormSubmit').attr('disabled','true');
      resetNavbuttons();
    }
    // form Default settings
    $('#multiForm').children('.multiForm').each(function(i){
      $(this).css('display','none');
    });
    $('#multiForm .multiForm:first').css('display','block').addClass('active');
    
    
    $('#multiFormNavNext').click(function(e){
      $(this).attr('disabled','true');      
      multiform(this,'next');
    });
    $('#multiFormNavBack').click(function(e){
      $(this).attr('disabled','true');
      multiform(this,'back');
    });

    $('.menuHead').click(function(){ //alert('asas');
      if($(this).parents('.curvBlock').hasClass('active')) return;
      $(this).parents('.curvBlock').toggleClass('active');
      $(this).parents('.curvBlock').siblings('.curvBlock').removeClass('active');
    });
  });
  // form styling default
  formInit();
  //datagrid colors
  dataGridInit();
  // provides an popup for height fields
  popHeight();
});

function multiform(e,dir)
{
  obj = $('#multiForm fieldset.active');
  //alert(obj);
  if(dir =='next')
  {    
    obj.removeClass('active').slideUp('slow', function(){
      obj.next('fieldset').addClass('active').slideDown('slow',function(){
        // alert($(this).children().eq(0).focus());
        //   $.scrollTo($(this),800);
        $(this).find('input').eq(0).focus();
        resetNavbuttons(e);
           
      });
    });
  }
 

  if(dir =='back')
  {
    obj.removeClass('active').slideUp('slow',function(){
      obj.prev('fieldset').addClass('active').slideDown('slow',function(){
        // alert($(this).children().eq(0).focus());
        //   $.scrollTo($(this),800);
        $(this).find('input').eq(0).focus();
        resetNavbuttons(e);
        
      });
    });
  }
 
}

function resetNavbuttons(e){
  $(e).removeAttr('disabled');
  $('fieldset.active').find('input|select|textarea|radio').eq(0).css('background','#ff9900').focus();
  //$('.dlForm  input , .dlForm  select , .dlForm textarea').blur(function(){ $(this).css('background','');});


  //alert($('#multiForm').children('fieldset').index($('.active'))+':'+ Math.ceil($('#multiForm').children('fieldset').length));

  if($('#multiForm').children('fieldset').index($('.active')) >= Math.ceil($('#multiForm').children('fieldset').length -1))
  {
    $('#multiFormNavNext').css('display','none');
    $('#multiFormSubmit').removeAttr('disabled');
  //return ;
  }else{
    $('#multiFormNavNext').css('display','inline');
    $('#multiFormBack').css('display','none');
    $('#multiFormSubmit').attr('disabled','true');

  }
  //  alert($('#multiForm fieldset').index($('.active')));
  if($('#multiForm fieldset').index($('.active')) >= 1 )
  {
    $('#multiFormNavBack').css('display','inline');
  //return;
  }else{
    $('#multiFormNavBack').css('display','none');
  //return;

  }
}

function formInit()
{
  // set scc class to all input Types
  $('.dlForm :text').addClass('inputText');
  $('.dlForm :radio').addClass('inputRadio');
  $('.dlForm :checkbox').addClass('inputCheckbox');
  $('.dlForm :password').addClass('inputPassword');
  $('.dlForm :file').addClass('inputFile');
  $("fieldset[id*='Address']").addClass('dt25');
//highlight active form element.
/*
  $('.dlForm input, .dlForm textarea, .dlForm select').focus(function(){
    $(this).css('background-color','#ffcf37');
  }).blur(function(){
    $(this).css('background-color','inherit');
  })
   */

  
}// end of function
function dataGridInit()
{
  
  if($('.tGrid').length)
  {
    //sets first and last trow s of the body of the table.
    $('.tGrid tbody :first-child').addClass('first');
    $('.tGrid tbody :last-child').addClass('last');

    $('.tGrid tr :first-child').addClass('first');
    $('.tGrid tr :last-child').addClass('last');

    // set alternative colour css style
    $('.tGrid').each(function(){
      $('.tGrid tbody tr:even').addClass('even');
      $('.tGrid tbody tr:odd').addClass('odd');
    });

  }
}// end of function


///* Default print function for frontend */
//function frontendPrint(url,strWindowFeatures=''){
//  url = url ;
//  if(strWindowFeatures==''){
//      strWindowFeatures = 'width=750px,height=450px' ;
//      }
//  window.open($url, 'print Name', strWindowFeatures) ;
//}// end of function


/* -------------------
 *  HEIGHT POPUP CODE
 * --------------------
 **/
function addheightCode($code){
  //alert('asdas');
  $html = '<div id="'+$code+'_pop" class="popHeightContainer">'
  +'<table border="0" class="popContent" width="400" height="400">'
  +'<tr><td valign="top"><!--[if lte IE 6]><iframe style="filter: alpha(opacity:0);position:absolute;z-index:-1;width:400px;height:400px;"></iframe><![endif]--><div class="dlForm">'
  +'<h3>Specify Height</h3>'
  +'<dl><dt><label>Input Height<sup>*</sup></label></dt><dd><input id="popHeightField" maxlength="4" size="6" type="text" />\n\
<select id="popHeightUnit" onChange="popHeightValidate()"  >\n\
<option value="cm">Centimeter</option>\n\
<option value="ft">Feets</option>\n\
<option value="mt">Meters</option>\n\
</select></dd></dl>\n\
<dl><dt><label>Height (in cm.)</label></dt><dd><input type="text" id="popHeightCm" readonly="readonly" size="5" /></dd></dl>\n\
<dl><dt></dt><dd><!-- <input type="button" id="heightUpdateBtn" onClick="popHeightValidate()" value="OK" />--> <input type="button" id="heightUpdateBtn" onClick="popHeightUpdate()" value="Update" /> <input type="button" id="heightUpdateBtn" onClick="popHeightClose()" value="Cancel" /></dd></dl>'
  +'<div class="pixbr cRed" style="padding:5px">Example for height in feets : For 5 feet 11 inch. use 5.11</div>'
  +'</td></tr></table></div>';
  return $html;
}
function popHeightClose(){

  $('.popHeightContainer').hide().remove();

}
function popHeightUpdate(){
  if(m = popHeightValidate()){
    obj = $('.popHeightContainer').attr('id');
    //alert(obj.length);
    obj1 = obj.substring(0,obj.length - 4);
    //alert(obj1);
    $('#'+obj1).attr('value',m)
    $('#'+obj).hide().remove();
  }
}
function popHeightValidate(){
  m = $('#popHeightField').val();
  unt = $('#popHeightUnit').val();
  if(m=='' || m==' '){
    alert('Please Enter Height');return false;
  }
  $('#popHeightCm').attr('value','');
  if(m==='' || isNaN(m * 1))
  {
    alert('Invalid height value') ;return false;
  }
  switch(unt){
    case 'ft':
      p =  m.indexOf('.');
      if(p >0){
        //alert(p);
        f = m.substr(0,p);
        inch = m.substr(p+1,m.length-1).valueOf()
        if(inch>12){
          alert('Height value in feets not Valid. \n Ex.:- To input 5 feet 11 inch use 5.11');
          return false;
        }
        heightInInch = (f*12)+Math.ceil(inch);
        
      }else{
       
        heightInInch = (m*12);
      }
      
      $('#popHeightCm').val(Math.floor(heightInInch * 2.54));
      break;
    case 'cm':        
      $('#popHeightCm').val(Math.floor(m));
      break;
    case 'mt':      
      $('#popHeightCm').val(Math.floor(m*100));
      break;
  }
  mV = $('#popHeightCm').val();
  if(mV <=25){
    alert('Height is too small');return false;
  }
  if(mV >=300){
    alert('Height is too large');return false;
  }
  return mV ;
}
function popHeight(){
  
 
  $('.popHeight').attr('readonly','readonly');
  $('.popHeight').focus(function(){

   
    
    $code = addheightCode($(this).attr('id'));
    objId = $(this).attr('id');

    // console.log($(this).offset());
    // console.log($('#'+objId+'_row').offset());

    if($('#'+objId+'_pop').length===0){
      $(this).parents('fieldset').eq(0).before($code);
    }
    CHKMRP = $('#mrpSeamansDivIdPart1').offset();
    if(CHKMRP) {
      $('#'+$(this).attr('id')+'_pop').show().css('top',($('#'+objId+'_row').offset().top)-(300+160));
    }else{
      $('#'+$(this).attr('id')+'_pop').show().css('top',($('#'+objId+'_row').offset().top)-300);
    }
    
  })
}//end of function

/* @author : ====================== Manoj Kumar ===============================================
 * @description : Java Script Function for Show Hide Component <Drop Down] and <Input text Box>.
 * =============================== End of the Function ========================================= */

function showHideDropDown(referenceId){
  var val = document.getElementById(referenceId).value;

  if(val == 'examCenter'){
    document.getElementById('center_list').style.display = 'block';
  }else{
    document.getElementById('center_list').style.display = 'none';
  }
  if(val == 'dateRange'){
    document.getElementById('date').style.display = 'block';
  }else{

    document.getElementById('date').style.display = 'none';
  }
}

function showHideInputTag(referenceId){
  var val = document.getElementById(referenceId).value;
  if(val.length>0){
    document.getElementById('center').style.display = 'block';
  }else{

    document.getElementById('center').style.display = 'none';
  }
}

function checkForNumeric(targetId)
{
  if( isNaN( document.getElementById('ss1_'+targetId).value ) || isNaN( document.getElementById('ss2_'+targetId).value ) )
  {
      alert('Please enter a number in the SS1 & SS2 fields.');
      document.getElementById('ss1_'+targetId).value = '';
      document.getElementById('ss2_'+targetId).value = '';
      return false;
  }
}

$(document).ready(function() {
    $(".ss_nonempty").keypress(function (e) {
      if( e.which!=8 && e.which!=0 && (e.which<48 || e.which>57)) {
        return false;
      }
    });

    $(".ss_empty").keypress(function (e) {
      if( e.which!=8 && e.which!=0 && (e.which<48 || e.which>57)) {
        return false;
      }
    });
});

function checkValidForm()
{
    var obj = $('.ss_nonempty');

    var success = true;    

    for(i=0; i<obj.length; i++)
    {

        $.trim($(obj[i]).val());

        if($(obj[i]).val() == '')
        {
            alert('Please fill in values for SS1 & SS2.');
            success = false;
        }
        else
        {
            if( $(obj[i]).val() < 0 || $(obj[i]).val() > 100 )
            {
                alert('Please fill in values between 0 to 100 for SS1 & SS2.');
                success = false;
            }
            
        }
        
       if (success == false) break;
    }   
   
    return success;
}

function showHideDiv(referenceId,targetId){
  var temp = targetId.split('_');

  var rowId = temp[1];

  var val = document.getElementById(referenceId);
  
  if(val.checked){
    document.getElementById(targetId).style.display = 'inline';
    document.getElementById('ss1_'+rowId).className = 'ss_nonempty';
    document.getElementById('ss2_'+rowId).className = 'ss_nonempty';
  }else{
    document.getElementById(targetId).style.display = 'none';
    document.getElementById('ss1_'+rowId).className = 'ss_empty';
    document.getElementById('ss2_'+rowId).className = 'ss_empty';
  }
}
/* @author: ======================= Manoj Kumar ==============================================
 * =============================== End of the Function ======================================== */


/* @author : ====================== Kuldeep Singh ===============================================
 * @description : Java Script Function for validation of form Bank Register and Pin Allocation Form in CEMP Module*/


function ValidBankForm()
{
  var regexp = /^[0-9 ]+$/;
  //var alphanumeric = "^[a-zA-Z]+$";
  if(trim(document.getElementById('bankname').value) == "")
  {
    alert("Please select Bank Name");
    document.getElementById('bankname').focus();
    return false;
  }
  if(trim(document.getElementById('branch').value) == "")
  {
    alert("Please Enter Branch Name");
    document.getElementById('branch').focus();
    return false;
  }

  if(trim(document.getElementById('city').value) =="")
  {
    alert("Please Enter City Name");
    document.getElementById('city').focus();
    return false;
  }

  if(trim(document.getElementById('address').value) == "")
  {
    alert("Please enter Address !");
    document.getElementById('address').focus();
    return false;
  }

  if(trim(document.getElementById('tphone').value) != "")
  {
    if(!(document.getElementById('tphone').value).match(regexp))
    {
      alert("Please enter only correct phone number.");
      document.getElementById('tphone').focus();
      return false;
    }
  }
}
function trim(s)
{
  var l=0; var r=s.length -1;
  while(l < s.length && s[l] == ' ')
  {
    l++;
  }
  while(r > l && s[r] == ' ')
  {
    r-=1;
  }
  return s.substring(l, r+1);
}
// selling point branch bank name action already call in the searchSellingPoint
//$(document).ready(function()
//{
//  //Didsplay office name according to state
//  $("#bank_name").keydown(function (){
//    $("#bank_name").change()
//  });
//  $("#bank_name").change(function()
//  {
//
//    var bank_name = $(this).val();
//
//    var url = "Branches/";
//
//    $('#loader').show();
//    $("#branch_name").load(url, {
//      bank_name: bank_name
//    },function (){
//      $('#loader').hide();
//    });
//  });
//});


function ValidPinAllocationForm()
{
  var regexp = /^[0-9]\d*/;
  //var alphanumeric = "^[0-9a-zA-Z]+$";

  if(document.getElementById('frmpin').value.length != 12 || document.getElementById('topin').value.length != 12)
  {
    alert('Serial Number should be of 12 digits');
    return false;
  }

  if(document.getElementById('frmpin').value > document.getElementById('topin').value)
  {
    alert('Please enter correct serial number');
    document.getElementById('frmpin').focus();
    return false;
  }

  if(document.getElementById('frmpin').value == "")
  {
    alert("Please enter From Pin No. !");
    document.getElementById('frmpin').focus();
    return false;
  }
  if(!(document.getElementById('frmpin').value).match(regexp))
  {
    alert("Please Enter Only Number");
    document.getElementById('frmpin').focus();
    return false;
  }
  if(document.getElementById('topin').value == "")
  {
    alert("Please enter To Pin No. !");
    document.getElementById('topin').focus();
    return false;
  }
  if(!(document.getElementById('topin').value).match(regexp))
  {
    alert("Please Enter Only Number");
    document.getElementById('topin').focus();
    return false;
  }

  if(document.getElementById('bank_name').value == "")
  {
    alert("Please select Bank Name !");
    document.getElementById('bank_name').focus();
    return false;
  }

  if(document.getElementById('branch_name').value == "")
  {
    alert("Please select Branch Name !");
    document.getElementById('branch_name').focus();
    return false;
  }

  $("#multiFormSubmit").attr('disabled', true);

}
function limitText(limitField, limitNum) {
  if (limitField.value.length > limitNum) {
    limitField.value = limitField.value.substring(0, limitNum);
  }
}
 


/* @author: ======================= Kuldeep Singh ==============================================
 * =============================== End of the Function ======================================== */

/* @author : ====================== Kuldeep Singh ===============================================
 * @description : Java Script Function for validation of form Validate User Form  in Bank Admin Module*/

function register()
{
  document.getElementById('newuser').style.display="block";
  document.getElementById('euser').style.display="none";
}

function alphanumeric(alphane)
{
  var numaric = alphane;
  for(var j=0; j<numaric.length; j++)
  {
    var alphaa = numaric.charAt(j);
    var hh = alphaa.charCodeAt(0);
    if((hh > 47 && hh<58) || (hh > 64 && hh<91) || (hh > 96 && hh<123))
    {
    }
    else{
      return false;
    }
  }
  return true;
}

function validateFormFields()
{

  var regexp = /^[0-9 ]+$/;

  if(!alphanumeric(document.getElementById('serial_number').value))
  {
    alert('Please enter correct number');
    document.getElementById('serial_number').focus();
    return false;
  }

  if(document.getElementById('serial_number').value=='')
  {
    alert('Please enter serial number.');
    document.getElementById('serial_number').focus();
    return false;
  }
  if(document.getElementById('fname').value=='')
  {
    alert('Please enter first name.');
    document.getElementById('fname').focus();
    return false;
  }
  if(document.getElementById('lname').value=='')
  {
    alert('Please enter surname.');
    document.getElementById('lname').focus();
    return false;
  }
  if(document.getElementById('gsm_no').value != ""){
    if(!(document.getElementById('gsm_no').value).match(regexp))
    {
      alert('Please enter only numeric values in GSM No.');
      document.getElementById('gsm_no').focus();
      return false;
    }
  }
}

function validateUserRegisterForm()
{
  if(document.getElementById('user_type').value=='')
  {
    alert('Please select user.');
    document.getElementById('user_type').focus();
    return false;
  }
  if(document.getElementById('bank_name').value=='')
  {
    alert('Please select bank name.');
    document.getElementById('bank_name').focus();
    return false;
  }
  if(document.getElementById('branch_name').value=='')
  {
    alert('Please select branch name.');
    document.getElementById('branch_name').focus();
    return false;
  }
}
/*
 *  Created By Uday Prakash
 */

/* for Cemp Registration */

$(document).ready(function()
{
  try{
  $("#country").change(function()
  {
    var nval = $('#country').val();
    if(nval != "NG")
    {
      document.getElementById('stateoforigin').value = '';
      document.getElementById('localgovt').value = '';
      $('#stateoforigin').attr('disabled','disabled');
      $('#localgovt').attr('disabled','disabled');
    }else{
      $('#stateoforigin').removeAttr('disabled');
      $('#localgovt').removeAttr('disabled');
      var country = $(this).val();
//      var url = "GetState/";
      if(country != '' && country != null){
      var url = stateUrl + country + ".html";
      $.get(url, {
        }, function (data){
            $("#stateoforigin").html(data);

           });
    }else{
      $('#stateoforigin').find('option').remove().end().append('<option value="">-- Please Select --</option>').val('whatever');
    }
    }
  });
 
  // create drop down of State after posting the data
  var pcountry = $('#pcountry').val();
  if(pcountry == "NG"){
    $('#ostate').css('display',"block");
    $('#otherstate').css('display',"none");
  }
  // End of State after post code


  $("#pcountry").change(function()
  {
    var nvale = $('#pcountry').val();
    if(nvale == "NG")
    {
      $('#ostate').css('display',"block");
      $('#otherstate').css('display',"none");
    }else{
      $('#ostate').css('display',"none");
      $('#otherstate').css('display',"block");
    }
  });

  // Disabled by Anurag -----------------------------------
  //  //Didsplay Local Govt Area  according to state
  //  $("#stateoforigin").change(function()
  //  {
  //    var state = $(this).val();
  //    var url = "GetLGA/";
  //    $("#localgovt").load(url, {
  //      state_id: state
  //    });
  //  });
  //
  //  // Change LGA after posting the data
  //  var StateofOrg = $('#stateoforigin').val();
  //  if(StateofOrg != ""){
  //    var url = "GetLGA/";
  //    $("#localgovt").load(url, {
  //      state_id: StateofOrg,
  //      lga:$("#localgovt").val()
  //      });
  //  }
  //  // End of LGA after post code
  // Disabled by Anurag Ends -----------------------------------

  // Change State of Origin after posting the data

var country = $('#country').val();
    if(country != "NG")
    {
      document.getElementById('stateoforigin').value = '';
      document.getElementById('localgovt').value = '';
      $('#stateoforigin').attr('disabled','disabled');
      $('#localgovt').attr('disabled','disabled');
    }else{
      $('#stateoforigin').removeAttr('disabled');
      $('#localgovt').removeAttr('disabled');
      
//      var country = $('#country').val();
//      var url = "GetState/";
//      $("#stateoforigin").load(url, {
//        country: country,
//        state: $("#stateoforigin").val()
//      });
    }
}
catch(e){}
//  if(country == "NG"){
//    var url = "GetState/";
//    $("#stateoforigin").load(url, {
//      country: country,
//      state: $("#stateoforigin").val()
//    });
//  }else{
//    $('#stateoforigin').attr('readonly','readonly');
//    $('#localgovt').attr('readonly','readonly');
//  }
// End of State of Origin after post code

});

/* for Jamb */


$(document).ready(function()
{
  $("#cancel").click(function()
  {
    $('form').attr('action','../jambreg');
    $('form').submit();

    return false;

  });

//For getting data after save -- Commented by anurag
//  var State = $('#examstate').val();
//  if(State != ""){
//    var url = "GetTown/";
//    $("#examtown").load(url, {
//      id: State,
//      town:$("#examtown").val()
//      });
//  }


//For Postal Address

//    var nvale = $('#country').val();
//    if(nvale == "nigeria")
//    {
//      $('#ostate').css('display',"block");
//      $('#otherstate').css('display',"none");
//    }else{
//      $('#ostate').css('display',"none");
//      $('#otherstate').css('display',"block");
//    }
//
//    $("#country").change(function()
//    {
//      var nvale = $('#country').val();
//      if(nvale == "nigeria")
//      {
//        $('#ostate').css('display',"block");
//        $('#otherstate').css('display',"none");
//      }else{
//        $('#ostate').css('display',"none");
//        $('#otherstate').css('display',"block");
//      }
//    });

});
// - commented by anurag
//$(document).ready(function()
//{
//
//  $("input:checkbox[value=21]").click(
//    function(){
//      return false;
//    });
//
//  $("input:checkbox[value=21]").attr("checked", "true");
//  $("input:checkbox[value=21]").attr("readonly", "readonly");
//
//});
// - commented by anurag ends

function getLoad(frm,vid,url,pid){

  //alert("hi"+pid);
  if(pid == "#fdegreecourse")
  {
  document.getElementById('facultydiv1').innerHTML="";
  document.getElementById('facultydiv2').innerHTML="";
  document.getElementById('facultydiv3').innerHTML="";
  document.getElementById('facultydiv').innerHTML="";
  }

  if(pid == "#sdegreecourse")
  {
  document.getElementById('sfacultydiv1').innerHTML="";
  document.getElementById('sfacultydiv2').innerHTML="";
  document.getElementById('sfacultydiv3').innerHTML="";
  document.getElementById('sfacultydiv').innerHTML="";
  }

  var inst = vid.value;
  var url = url;
  $("#loader").show();
  $(pid).load(url, {
    id: inst
  },function (){
    $("#loader").hide();
  });
  $(pid).width(180);

}

function checkSubjectGrade(v){
  var sid = "olevelsubject"+v;
  var gid = "grade"+v;
  if(document.getElementById(sid).value == "" ){
    document.getElementById(gid).selectedIndex = 0;
  }
}


function isInteger (s)
{
  var i;
  if (isEmpty(s))
    if (isInteger.arguments.length == 1) return 0;
    else return (isInteger.arguments[1] == true);
  for (i = 0; i < s.length; i++)
  {
    var c = s.charAt(i);
    if (!isDigit(c)) return false;
  }
  return true;
}

function isEmpty(s)
{
  return ((s == null) || (s.length == 0))
}

function isDigit (c)
{
  return ((c >= "0") && (c <= "9"))
}

function validateCheck(frm){

   $('.highlighter').removeClass("highlighter");
   

  //false;
  //alert("hi"+frm.regId.value);
  if(document.getElementById('confirmPersonalData').checked==false)
  {
    $('#confirmPersonalData').addClass("highlighter");
    alert("Please Confirm your personal information");
    document.getElementById('confirmPersonalData').focus();
    return false;
  }

  //    if(document.getElementById('address').value=="" || document.getElementById('address').value=="undefined"){
  //      alert("Please insert your address");
  //      document.getElementById('address').focus();
  //      return false;
  //    }
  //    if(document.getElementById('town').value=="" || document.getElementById('town').value=="undefined"){
  //      alert("Please insert your Town name");
  //      document.getElementById('town').focus();
  //      return false;
  //    }
  //    if(document.getElementById('pcode').value=="" || document.getElementById('pcode').value=="undefined"){
  //      alert("Please insert your Postal Code");
  //      document.getElementById('pcode').focus();
  //      return false;
  //    }

  //  if(!isInteger(document.getElementById('pcode').value)){
  //       alert("Please insert valid Postal Code");
  //      document.getElementById('pcode').focus();
  //      document.getElementById('pcode').select()
  //      return false;
  //  }
  //
  if(document.getElementById('issubmitted').value == ""){
    if( frm.examstate.value == "" ){
      $('#examstate').addClass("highlighter");
      alert("You must select Exam State");
      return false;
    }
    if( frm.examtown.value == "" ){
      $('#examtown').addClass("highlighter");
      alert("You must select Exam Town");
      return false;
    }

    if((document.getElementById('examtown').options[document.getElementById('examtown').selectedIndex].text).toUpperCase() != (document.getElementById('confirmTown').value).toUpperCase())
    {
      $('#confirmTown').addClass("highlighter");
      alert("Please Confirm exam town");
      document.getElementById('confirmTown').focus();
      return false;
    }
  }
  if(frm.regId.value == ""){
    if(frm.firstChoiceFirstInstitutionType.value == ""){
      $('#firstChoiceFirstInstitutionType').addClass("highlighter");
      alert("You must select first choice first institution type");
      document.getElementById('firstChoiceFirstInstitutionType').focus() ;
      return false;
    }


    // alert(frm.firstChoiceFirstInstitutionType.value);
    //For First Choice First institution
    if(frm.firstChoiceFirstInstitutionType.value == 1){
      if( frm.fdegreeinst.value == "" ){
      $('#fdegreeinst').addClass("highlighter");
        alert("You must select first choice Institution");
        document.getElementById('fdegreeinst').focus() ;
        return false;
      }else if( frm.fdegreecourse.value == "" ){
      $('#fdegreecourse').addClass("highlighter");
        alert("You must select first choice Course");
        document.getElementById('fdegreecourse').focus() ;
        return false;
      }
    }else if(frm.firstChoiceFirstInstitutionType.value == 3){
      if( frm.fndinst.value == "" ){
        $('#fndinst').addClass("highlighter");
        alert("You must select first choice Institution");
        document.getElementById('fndinst').focus() ;
        return false;
      }else if( frm.fndcourse.value == "" ){
        $('#fndcourse').addClass("highlighter");
        alert("You must select first choice Course");
        document.getElementById('fndcourse').focus() ;
        return false;
      }

    }else if(frm.firstChoiceFirstInstitutionType.value == 5){
      if( frm.fnceinst.value == "" ){
        $('#fnceinst').addClass("highlighter");
        alert("You must select first choice Institution");
        document.getElementById('fnceinst').focus() ;
        return false;
      }else if( frm.fncecourse.value == "" ){
        $('#fncecourse').addClass("highlighter");
        alert("You must select first choice Course");
        document.getElementById('fncecourse').focus() ;
        return false;
      }
    }

    //For First Choice Second institution
    if(frm.firstChoiceSecondInstitutionType.value == ""){
        $('#firstChoiceSecondInstitutionType').addClass("highlighter");
      alert("You must select first choice second institution type");
      document.getElementById('firstChoiceSecondInstitutionType').focus() ;
      return false;
    }

    if(frm.firstChoiceSecondInstitutionType.value == 1){
      if( frm.fdegreeinst.value == "" ){
        $('#fdegreeinst').addClass("highlighter");
        alert("You must select first choice Institution");
        document.getElementById('fdegreeinst').focus() ;
        return false;
      }else if( frm.fdegreecourse.value == "" ){
        $('#fdegreecourse').addClass("highlighter");
        alert("You must select first choice Course");
        document.getElementById('fdegreecourse').focus() ;
        return false;
      }
    }else if(frm.firstChoiceSecondInstitutionType.value == 3){
      if( frm.fndinst.value == "" ){
        $('#fndinst').addClass("highlighter");
        alert("You must select first choice Institution");
        document.getElementById('fndinst').focus() ;
        return false;
      }else if( frm.fndcourse.value == "" ){
        $('#fndcourse').addClass("highlighter");
        alert("You must select first choice Course");
        document.getElementById('fndcourse').focus() ;
        return false;
      }

    }else if(frm.firstChoiceSecondInstitutionType.value == 5){
      if( frm.fnceinst.value == "" ){
        $('#fnceinst').addClass("highlighter");
        alert("You must select first choice Institution");
        document.getElementById('fnceinst').focus() ;
        return false;
      }else if( frm.fncecourse.value == "" ){
        $('#fncecourse').addClass("highlighter");
        alert("You must select first choice Course");
        document.getElementById('fncecourse').focus() ;
        return false;
      }
    }


    //For First Choice Third institution

    if(frm.firstChoiceThirdInstitutionType.value == ""){
        $('#firstChoiceThirdInstitutionType').addClass("highlighter");
      alert("You must select first choice third institution type");
      document.getElementById('firstChoiceThirdInstitutionType').focus() ;
      return false;
    }

    if(frm.firstChoiceThirdInstitutionType.value == 1){
      if( frm.fdegreeinst.value == "" ){
        $('#fdegreeinst').addClass("highlighter");
        alert("You must select first choice Institution");
        document.getElementById('fdegreeinst').focus() ;
        return false;
      }else if( frm.fdegreecourse.value == "" ){
        $('#fdegreecourse').addClass("highlighter");
        alert("You must select first choice Course");
        document.getElementById('fdegreecourse').focus() ;
        return false;
      }
    }else if(frm.firstChoiceThirdInstitutionType.value == 3){
      if( frm.fndinst.value == "" ){
        $('#fndinst').addClass("highlighter");
        alert("You must select first choice Institution");
        document.getElementById('fndinst').focus() ;
        return false;
      }else if( frm.fndcourse.value == "" ){
        $('#fndcourse').addClass("highlighter");
        alert("You must select first choice Course");
        document.getElementById('fndcourse').focus() ;
        return false;
      }

    }else if(frm.firstChoiceThirdInstitutionType.value == 5){
      if( frm.fnceinst.value == "" ){
        $('#fnceinst').addClass("highlighter");
        alert("You must select first choice Institution");
        document.getElementById('fnceinst').focus() ;
        return false;
      }else if( frm.fncecourse.value == "" ){
        $('#fncecourse').addClass("highlighter");
        alert("You must select first choice Course");
        document.getElementById('fncecourse').focus() ;
        return false;
      }
    }





    //For Second Choice First institution
    if(frm.secondChoiceFirstInstitutionType.value == ""){
      $('#secondChoiceFirstInstitutionType').addClass("highlighter");
      alert("You must select second choice first institution type");
      document.getElementById('secondChoiceFirstInstitutionType').focus() ;
      return false;
    }

    if(frm.secondChoiceFirstInstitutionType.value == 1){
      if( frm.sdegreeindt.value == "" ){
      $('#sdegreeindt').addClass("highlighter");
        alert("You must select second choice Institution");
        document.getElementById('sdegreeindt').focus() ;
        return false;
      }else if( frm.sdegreecourse.value == "" ){
      $('#sdegreecourse').addClass("highlighter");
        alert("You must select second choice Course");
        document.getElementById('sdegreecourse').focus() ;
        return false;
      }
    }else if(frm.secondChoiceFirstInstitutionType.value == 3){
      if( frm.sndinst.value == "" ){
      $('#sndinst').addClass("highlighter");
        alert("You must select second choice Institution");
        document.getElementById('sndinst').focus() ;
        return false;
      }else if( frm.sndcourse.value == "" ){
      $('#sndcourse').addClass("highlighter");
        alert("You must select second choice Course");
        document.getElementById('sndcourse').focus() ;
        return false;
      }

    }else if(frm.secondChoiceFirstInstitutionType.value == 5){
      if( frm.snceinst.value == "" ){
      $('#snceinst').addClass("highlighter");
        alert("You must select second choice Institution");
        document.getElementById('snceinst').focus() ;
        return false;
      }else if( frm.sncecourse.value == "" ){
      $('#sncecourse').addClass("highlighter");
       alert("You must select second choice Course");
        document.getElementById('sncecourse').focus() ;
        return false;
      }
    }

    //For Second Choice Second institution
    if(frm.secondChoiceSecondInstitutionType.value == ""){
      $('#secondChoiceSecondInstitutionType').addClass("highlighter");
      alert("You must select second choice second institution type");
      document.getElementById('secondChoiceSecondInstitutionType').focus() ;
      return false;
    }

    if(frm.secondChoiceSecondInstitutionType.value == 1){
      if( frm.sdegreeindt.value == "" ){
      $('#sdegreeindt').addClass("highlighter");
        alert("You must select second choice Institution");
        document.getElementById('sdegreeindt').focus() ;
        return false;
      }else if( frm.sdegreecourse.value == "" ){
      $('#sdegreecourse').addClass("highlighter");
        alert("You must select second choice Course");
        document.getElementById('sdegreecourse').focus() ;
        return false;
      }
    }else if(frm.secondChoiceSecondInstitutionType.value == 3){
      if( frm.sndinst.value == "" ){
      $('#sndinst').addClass("highlighter");
        alert("You must select second choice Institution");
        document.getElementById('sndinst').focus() ;
        return false;
      }else if( frm.sndcourse.value == "" ){
      $('#sndcourse').addClass("highlighter");
        alert("You must select second choice Course");
        document.getElementById('sndcourse').focus() ;
        return false;
      }

    }else if(frm.secondChoiceSecondInstitutionType.value == 5){
      if( frm.snceinst.value == "" ){
      $('#snceinst').addClass("highlighter");
        alert("You must select second choice Institution");
        document.getElementById('snceinst').focus() ;
        return false;
      }else if( frm.sncecourse.value == "" ){
      $('#sncecourse').addClass("highlighter");
        alert("You must select second choice Course");
        document.getElementById('sncecourse').focus() ;
        return false;
      }
    }


    //For Second Choice Third institution
    if(frm.secondChoiceThirdInstitutionType.value == ""){
      $('#secondChoiceThirdInstitutionType').addClass("highlighter");
      alert("You must select second choice third institution type");
      document.getElementById('secondChoiceThirdInstitutionType').focus() ;
      return false;
    }

    if(frm.secondChoiceThirdInstitutionType.value == 1){
      if( frm.sdegreeindt.value == "" ){
      $('#sdegreeindt').addClass("highlighter");
        alert("You must select second choice Institution");
        document.getElementById('sdegreeindt').focus() ;
        return false;
      }else if( frm.sdegreecourse.value == "" ){
      $('#sdegreecourse').addClass("highlighter");
        alert("You must select second choice Course");
        document.getElementById('sdegreecourse').focus() ;
        return false;
      }
    }else if(frm.secondChoiceThirdInstitutionType.value == 3){
      if( frm.sndinst.value == "" ){
      $('#sndinst').addClass("highlighter");
       alert("You must select second choice Institution");
        document.getElementById('sndinst').focus() ;
        return false;
      }else if( frm.sndcourse.value == "" ){
      $('#sndcourse').addClass("highlighter");
        alert("You must select second choice Course");
        document.getElementById('sndcourse').focus() ;
        return false;
      }

    }else if(frm.secondChoiceThirdInstitutionType.value == 5){
      if( frm.snceinst.value == "" ){
      $('#snceinst').addClass("highlighter");
        alert("You must select second choice Institution");
        document.getElementById('snceinst').focus() ;
        return false;
      }else if( frm.sncecourse.value == "" ){
      $('#sncecourse').addClass("highlighter");
        alert("You must select second choice  Course");
        document.getElementById('sncecourse').focus() ;
        return false;
      }
    }



  }else{
    //alert("hi");
  //  alert("first"+document.getElementById('changefirstChoiceInstitutionType').value);
    if(document.getElementById('changefirstChoiceInstitutionType').value == "false"){
      if( frm.fdegreeinst.value == "" ){
      alert("You must select first choice Institution");
      $('.createuserInput #fdegreeinst').addClass("highlighter");
        document.getElementById('fdegreeinst').focus() ;
        return false;
      }else if( frm.fdegreecourse.value == "" ){
      $('.createuserInput #fdegreecourse').addClass("highlighter");
        alert("You must select first choice Course");
        document.getElementById('fdegreecourse').focus() ;
        return false;
      }

      if( frm.fndinst.value == "" ){
      $('.createuserInput #fndinst').addClass("highlighter");
        alert("You must select first choice Institution");
        document.getElementById('fndinst').focus() ;
        return false;
      }else if( frm.fndcourse.value == "" ){
      $('.createuserInput #fndcourse').addClass("highlighter");
        alert("You must select first choice Course");
        document.getElementById('fndcourse').focus() ;
        return false;
      }

      if( frm.fnceinst.value == "" ){
      $('.createuserInput #fnceinst').addClass("highlighter");
        alert("You must select first choice Institution");
        document.getElementById('fnceinst').focus() ;
        return false;
      }else if( frm.fncecourse.value == "" ){
      $('.createuserInput #fncecourse').addClass("highlighter");
        alert("You must select first choice Course");
        document.getElementById('fncecourse').focus() ;
        return false;
      }
    }else{

      if(frm.firstChoiceFirstInstitutionType.value == ""){
      $('#firstChoiceFirstInstitutionType').addClass("highlighter");
        alert("You must select first choice first institution type");
        document.getElementById('firstChoiceFirstInstitutionType').focus() ;
        return false;
      }
      //For First Choice First institution
      if(frm.firstChoiceFirstInstitutionType.value == 1){
        if( frm.fdegreeinst.value == "" ){
      $('#fdegreeinst').addClass("highlighter");
          alert("You must select first choice Institution");
          document.getElementById('fdegreeinst').focus() ;
          return false;
        }else if( frm.fdegreecourse.value == "" ){
      $('#fdegreecourse').addClass("highlighter");
          alert("You must select first choice Course");
          document.getElementById('fdegreecourse').focus() ;
          return false;
        }
      }else if(frm.firstChoiceFirstInstitutionType.value == 3){
        if( frm.fndinst.value == "" ){
      $('#fndinst').addClass("highlighter");
          alert("You must select first choice Institution");
          document.getElementById('fndinst').focus() ;
          return false;
        }else if( frm.fndcourse.value == "" ){
      $('#fndcourse').addClass("highlighter");
          alert("You must select first choice Course");
          document.getElementById('fndcourse').focus() ;
          return false;
        }

      }else if(frm.firstChoiceFirstInstitutionType.value == 5){
        if( frm.fnceinst.value == "" ){
      $('#fnceinst').addClass("highlighter");
          alert("You must select first choice Institution");
          document.getElementById('fnceinst').focus() ;
          return false;
        }else if( frm.fncecourse.value == "" ){
      $('#fncecourse').addClass("highlighter");
          alert("You must select first choice Course");
          document.getElementById('fncecourse').focus() ;
          return false;
        }
      }

      //For First Choice Second institution
      if(frm.firstChoiceSecondInstitutionType.value == ""){
      $('#firstChoiceSecondInstitutionType').addClass("highlighter");
        alert("You must select first choice second institution type");
        document.getElementById('firstChoiceSecondInstitutionType').focus() ;
        return false;
      }

      if(frm.firstChoiceSecondInstitutionType.value == 1){
        if( frm.fdegreeinst.value == "" ){
      $('#fdegreeinst').addClass("highlighter");
          alert("You must select first choice Institution");
          document.getElementById('fdegreeinst').focus() ;
          return false;
        }else if( frm.fdegreecourse.value == "" ){
      $('#fdegreecourse').addClass("highlighter");
          alert("You must select first choice Course");
          document.getElementById('fdegreecourse').focus() ;
          return false;
        }
      }else if(frm.firstChoiceSecondInstitutionType.value == 3){
        if( frm.fndinst.value == "" ){
      $('#fndinst').addClass("highlighter");
          alert("You must select first choice Institution");
          document.getElementById('fndinst').focus() ;
          return false;
        }else if( frm.fndcourse.value == "" ){
      $('#fndcourse').addClass("highlighter");
          alert("You must select first choice Course");
          document.getElementById('fndcourse').focus() ;
          return false;
        }

      }else if(frm.firstChoiceSecondInstitutionType.value == 5){
        if( frm.fnceinst.value == "" ){
        $('#fnceinst').addClass("highlighter");
          alert("You must select first choice Institution");
          document.getElementById('fnceinst').focus() ;
          return false;
        }else if( frm.fncecourse.value == "" ){
        $('#fncecourse').addClass("highlighter");
          alert("You must select first choice Course");
          document.getElementById('fncecourse').focus() ;
          return false;
        }
      }


      //For First Choice Third institution

      if(frm.firstChoiceThirdInstitutionType.value == ""){
        $('#firstChoiceThirdInstitutionType').addClass("highlighter");
        alert("You must select first choice third institution type");
        document.getElementById('firstChoiceThirdInstitutionType').focus() ;
        return false;
      }

      if(frm.firstChoiceThirdInstitutionType.value == 1){
        if( frm.fdegreeinst.value == "" ){
        $('#fdegreeinst').addClass("highlighter");
          alert("You must select first choice Institution");
          document.getElementById('fdegreeinst').focus() ;
          return false;
        }else if( frm.fdegreecourse.value == "" ){
        $('#fdegreecourse').addClass("highlighter");
          alert("You must select first choice Course");
          document.getElementById('fdegreecourse').focus() ;
          return false;
        }
      }else if(frm.firstChoiceThirdInstitutionType.value == 3){
        if( frm.fndinst.value == "" ){
        $('#fndinst').addClass("highlighter");
          alert("You must select first choice Institution");
          document.getElementById('fndinst').focus() ;
          return false;
        }else if( frm.fndcourse.value == "" ){
        $('#fndcourse').addClass("highlighter");
          alert("You must select first choice Course");
          document.getElementById('fndcourse').focus() ;
          return false;
        }

      }else if(frm.firstChoiceThirdInstitutionType.value == 5){
        if( frm.fnceinst.value == "" ){
        $('#fnceinst').addClass("highlighter");
          alert("You must select first choice Institution");
          document.getElementById('fnceinst').focus() ;
          return false;
        }else if( frm.fncecourse.value == "" ){
        $('#fncecourse').addClass("highlighter");
          alert("You must select first choice Course");
          document.getElementById('fncecourse').focus() ;
          return false;
        }
      }

    }

   // alert("second"+document.getElementById('changeSecondChoiceInstitutionType').value);
    if(document.getElementById('changeSecondChoiceInstitutionType').value == "false"){
      if( frm.sdegreeindt.value == "" ){
        $('.createuserInput #sdegreeindt').addClass("highlighter");
        alert("You must select second choice Institution");
        document.getElementById('sdegreeindt').focus() ;
        return false;
      }else if( frm.sdegreecourse.value == "" ){
        $('.createuserInput #sdegreecourse').addClass("highlighter");
        alert("You must select second choice Course");
        document.getElementById('sdegreecourse').focus() ;
        return false;
      }

      if( frm.sndinst.value == "" ){
        $('.createuserInput #sndinst').addClass("highlighter");
        alert("You must select second choice Institution");
        document.getElementById('sndinst').focus() ;
        return false;
      }else if( frm.sndcourse.value == "" ){
        $('.createuserInput #sndcourse').addClass("highlighter");
        alert("You must select second choice Course");
        document.getElementById('sndcourse').focus() ;
        return false;
      }

      if( frm.snceinst.value == "" ){
        $('.createuserInput #snceinst').addClass("highlighter");
       alert("You must select second choice Institution");
        document.getElementById('snceinst').focus() ;
        return false;
      }else if( frm.sncecourse.value == "" ){
        $('.createuserInput #sncecourse').addClass("highlighter");
        alert("You must select second choice Course");
        document.getElementById('sncecourse').focus() ;
        return false;
      }
    }else{
      //For Second Choice First institution
      if(frm.secondChoiceFirstInstitutionType.value == ""){
        $('#secondChoiceFirstInstitutionType').addClass("highlighter");
        alert("You must select second choice first institution type");
        document.getElementById('secondChoiceFirstInstitutionType').focus() ;
        return false;
      }

      if(frm.secondChoiceFirstInstitutionType.value == 1){
        if( frm.sdegreeindt.value == "" ){
        $('#sdegreeindt').addClass("highlighter");
          alert("You must select second choice Institution");
          document.getElementById('sdegreeindt').focus() ;
          return false;
        }else if( frm.sdegreecourse.value == "" ){
        $('#sdegreecourse').addClass("highlighter");
          alert("You must select second choice Course");
          document.getElementById('sdegreecourse').focus() ;
          return false;
        }
      }else if(frm.secondChoiceFirstInstitutionType.value == 3){
        if( frm.sndinst.value == "" ){
        $('#sndinst').addClass("highlighter");
          alert("You must select second choice Institution");
          document.getElementById('sndinst').focus() ;
          return false;
        }else if( frm.sndcourse.value == "" ){
        $('#sndcourse').addClass("highlighter");
          alert("You must select second choice Course");
          document.getElementById('sndcourse').focus() ;
          return false;
        }

      }else if(frm.secondChoiceFirstInstitutionType.value == 5){
        if( frm.snceinst.value == "" ){
        $('#snceinst').addClass("highlighter");
          alert("You must select second choice Institution");
          document.getElementById('snceinst').focus() ;
          return false;
        }else if( frm.sncecourse.value == "" ){
        $('#sncecourse').addClass("highlighter");
          alert("You must select second choice Course");
          document.getElementById('sncecourse').focus() ;
          return false;
        }
      }

      //For Second Choice Second institution
      if(frm.secondChoiceSecondInstitutionType.value == ""){
        $('#secondChoiceSecondInstitutionType').addClass("highlighter");
        alert("You must select second choice second institution type");
        document.getElementById('secondChoiceSecondInstitutionType').focus() ;
        return false;
      }

      if(frm.secondChoiceSecondInstitutionType.value == 1){
        if( frm.sdegreeindt.value == "" ){
        $('#sdegreeindt').addClass("highlighter");
          alert("You must select second choice Institution");
          document.getElementById('sdegreeindt').focus() ;
          return false;
        }else if( frm.sdegreecourse.value == "" ){
        $('#sdegreecourse').addClass("highlighter");
          alert("You must select second choice Course");
          document.getElementById('sdegreecourse').focus() ;
          return false;
        }
      }else if(frm.secondChoiceSecondInstitutionType.value == 3){
        if( frm.sndinst.value == "" ){
        $('#sndinst').addClass("highlighter");
          alert("You must select second choice Institution");
          document.getElementById('sndinst').focus() ;
          return false;
        }else if( frm.sndcourse.value == "" ){
         $('#sndcourse').addClass("highlighter");
         alert("You must select second choice Course");
          document.getElementById('sndcourse').focus() ;
          return false;
        }

      }else if(frm.secondChoiceSecondInstitutionType.value == 5){
        if( frm.snceinst.value == "" ){
         $('#snceinst').addClass("highlighter");
          alert("You must select second choice Institution");
          document.getElementById('snceinst').focus() ;
          return false;
        }else if( frm.sncecourse.value == "" ){
          $('#sncecourse').addClass("highlighter");
         alert("You must select second choice Course");
           document.getElementById('sncecourse').focus() ;
          return false;
        }
      }


      //For Second Choice Third institution
      if(frm.secondChoiceThirdInstitutionType.value == ""){
          $('#secondChoiceThirdInstitutionType').addClass("highlighter");
        alert("You must select second choice third institution type");
        document.getElementById('secondChoiceThirdInstitutionType').focus() ;
        return false;
      }

      if(frm.secondChoiceThirdInstitutionType.value == 1){
        if( frm.sdegreeindt.value == "" ){
          $('#sdegreeindt').addClass("highlighter");
          alert("You must select second choice Institution");
          document.getElementById('sdegreeindt').focus() ;
          return false;
        }else if( frm.sdegreecourse.value == "" ){
          $('#sdegreecourse').addClass("highlighter");
          alert("You must select second choice Course");
          document.getElementById('sdegreecourse').focus() ;
          return false;
        }
      }else if(frm.secondChoiceThirdInstitutionType.value == 3){
        if( frm.sndinst.value == "" ){
          $('#sndinst').addClass("highlighter");
          alert("You must select second choice Institution");
          document.getElementById('sndinst').focus() ;
          return false;
        }else if( frm.sndcourse.value == "" ){
          $('#sndcourse').addClass("highlighter");
          alert("You must select second choice Course");
          document.getElementById('sndcourse').focus() ;
          return false;
        }

      }else if(frm.secondChoiceThirdInstitutionType.value == 5){
        if( frm.snceinst.value == "" ){
          $('#snceinst').addClass("highlighter");
          alert("You must select second choice Institution");
          document.getElementById('snceinst').focus() ;
          return false;
        }else if( frm.sncecourse.value == "" ){
          $('#sncecourse').addClass("highlighter");
          alert("You must select second choice  Course");
          document.getElementById('sncecourse').focus() ;
          return false;
        }
      }
    }
  }

  if(document.getElementById('examtype').selectedIndex == ""){
    $('#examtype').addClass("highlighter");
    alert("Please select SSCE Exam Type") ;
    return false ;
  }

  if ($("input:checked[name*=utme]").length != 4)
  {
    alert("You must select exactly four subjects");
    return false;
  };

  var i=0;
  olevelsubjectcount =0;
  //    debugger;
  //    olevelgradecount=0;
  for(var i=1; i<=9; i++)
  {
    //  alert(document.getElementById('grade'+i).selectedIndex) ;
    //   alert("testing") ;

    if(document.getElementById('olevelsubject'+i).selectedIndex >0){
      olevelsubjectcount++;
    }

  //    if(document.getElementById('olevelsubject'+i).selected != ''){
  //      alert('please select grade for subject 1.');
  //      frm.getElementById('grade'+i).focus() ;
  //      return false;
  //    }
  //
  //    if(document.getElementById('olevelsubject'+i).selected == ''){
  //      alert('please select subject for grade'+i);
  //      frm.getElementById('grade'+i).focus() ;
  //      return false;
  //    }



  }
  if(olevelsubjectcount < 5){
    alert('please select min 5 subjects with respective grades.');
    return false;
  }

  // For same O Level Subject
  var countNum = 9 ;
  for(var i=1; i<=9; i++)
  {    //alert(i)   ;
    for(var j = (i+1)  ; j <= countNum; j++)
    {
      //        alert(j) ;
      //          alert(document.getElementById('olevelsubject'+i).value) ;
      //          alert(document.getElementById('olevelsubject'+j).value) ;
      if(document.getElementById('olevelsubject'+i).options[document.getElementById('olevelsubject'+i).selectedIndex].text != "Please Select")
      {
        if( (document.getElementById('olevelsubject'+i).value !="") && document.getElementById('olevelsubject'+i).value == document.getElementById('olevelsubject'+j).value)
        {
          $('#olevelsubject'+i).addClass("highlighter");
          alert(document.getElementById('olevelsubject'+i).options[document.getElementById('olevelsubject'+i).selectedIndex].text + ' SSCE subject have duplicate entry');
          document.getElementById('olevelsubject'+i).focus() ;
          return false ;
        }
      }
    }
  }

}


function check_select(jampRegi){
  var inputRefArray = jampRegi.getElementsByTagName('input');
  var countCh=0;

  for (var i=0; i < inputRefArray.length; i++)
  {
    var inputRef = inputRefArray[i];

    if ( inputRef.type== 'checkbox' )
    {
      if ( inputRef.checked == true )
        ++countCh;
    }
  }
  if(countCh > 4){
    return false;
  }
  return true;
}

/* end of code */

// Removes leading whitespaces
function LTrim( value ) {
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}

// Removes ending whitespaces
function RTrim( value ) {
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}

//For state
function ValidForm()
{
 if(LTrim(document.getElementById('fname').value) == ""){
    alert("Please Enter First Name");
    document.getElementById('fname').focus();
    return false;
 }
 if(LTrim(document.getElementById('snamae').value) == ""){
    alert("Please Enter Surname");
    document.getElementById('snamae').focus();
    return false;
 }
 if(LTrim(document.getElementById('date').value) == ""){
    alert("Please Enter Date of Birth");
    document.getElementById('date').focus();
    return false;
 }
 if(LTrim(document.getElementById('date').value) != ""){
   var objFromDate = LTrim(document.getElementById('date').value);

    var date1 = new Date(objFromDate);
    var valCurDate = new Date();
    valCurDate = valCurDate.getMonth()+1 + "/" + valCurDate.getDate() + "/" + valCurDate.getFullYear();
    var CurDate = new Date(valCurDate);
   if(date1 > CurDate){
    alert(" Date of Birth should be less than current date");
    document.getElementById('date').focus();
    return false;
   }
 }


  if(document.getElementById("shouldUpload")){
    document.getElementById("shouldUpload").value = "no";
    document.forms[0].target = "_self";
    document.forms[0].action = "CempRegsSave";
  }
  var count = document.getElementById('pcountry').value;
  if(count == ""){
    alert("Postal country cannot be left blank");
    return false;
  }else if(count == "NG")
  {
    if(document.getElementById('state').value == "")
    {
      //document.getElementById('error').innerHTML="<font color='red'>State is not Empty</font>";
      alert("Postal state cannot be left blank");
      return false;
    }
  }else{
    if(LTrim(document.getElementById('otherstate').value) == "")
    {
      //document.getElementById('error').innerHTML="<font color='red'>State is not Empty</font>";
      alert("Postal state cannot be left blank");
      return false;
    }
  }
  
  if(document.getElementById('image_check')){
      if(document.getElementById('image_check').checked)
        {
        if(document.getElementById('personal_info_check').checked)
          {
            return confirmation();
          }else{
             alert("Please check to confirm the personal details");
             return false;
          }
        }else{
          alert("Please check to confirm the image");
          return false;
        }
      return true;
    }

   
}

function confirmation()
{
   var con = confirm("Please Ensure you have entered your personal information correctly");

   if(con == true){

       return true;

   }else
       {
           return false;
       }
}


function CempProfileValidForm()
{
  if(document.getElementById("shouldUpload")){
    document.getElementById("shouldUpload").value = "no";
    document.forms[0].target = "_self";
    document.forms[0].action = "SaveCempProfile";
  }
  var count = document.getElementById('pcountry').value;
  if(count == ""){
    alert("Postal country cannot be left blank");
    return false;
  }else if(count == "NG")
  {
    if(document.getElementById('state').value == "")
    {
      //document.getElementById('error').innerHTML="<font color='red'>State is not Empty</font>";
      alert("Postal state cannot be left blank");
      return false;
    }
  }else{
    if(LTrim(document.getElementById('otherstate').value) == "")
    {
      //document.getElementById('error').innerHTML="<font color='red'>State is not Empty</font>";
      alert("Postal state cannot be left blank");
      return false;
    }
  }
  if(document.getElementById('image_check')){
      if(document.getElementById('image_check').checked)
        {
        if(document.getElementById('personal_info_check').checked)
          {
            return true;
          }else{
             alert("Please check to confirm the personal details");
             return false;
          }
        }else{
          alert("Please check to confirm the image");
          return false;
        }
      return true;
    }
}

/* end of Code */

/* for Registration */

function validatePin()
{
  if(document.getElementById('sno').value=='')
  {
    alert('Please enter serial number.');
    document.getElementById('sno').focus();
    return false;
  }
  if(document.getElementById('pin').value=='')
  {
    alert('Please enter pin number.');
    document.getElementById('pin').focus();
    return false;
  }
}

/*end of code */

/*
 * End of Code
 */


/* ----------------------------------------------------------------------------
 Option add, remove
 Author : Anurag

 */

function removeIndexOption(selname, indexNum)
{
  var elSel = document.getElementById(selname);
  if (elSel.length > 0)
  {
    elSel.remove(indexNum);
  }
}

function removeAllOption(selname)
{
  var elSel = document.getElementById(selname);
  if (elSel.length > 0)
  {
    for(var i = elSel.length; i > 0; i-- )
    {
      elSel.remove(elSel.length - 1);
    }
  }
}

function appendOptionAtEnd(selname, opttext, optvalue)
{
  var elOptNew = document.createElement('option');
  elOptNew.text = opttext;
  elOptNew.value = optvalue;
  var elSel = document.getElementById(selname);

  try {
    elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
  }
  catch(ex) {
    elSel.add(elOptNew); // IE only
  }
}
  // Option : Add / Remove Ends ------------------------------------------------------

$(document).ready(function()
{
  $("#username").focus();
  $("#username").blur(function()
  {
    $("#error").html('');
    if (($("#username").val() == ""))
    {
        return false;
    }

    $("#erroruser").html('Checking user in database');
    $.get("checkUniqueUser", {
      username: $("#username").val()
      }, function (data) {
      if (data == 'false') {
       
        $("#erroruser").html('<font color=green>Congratulations!! the username is available</font>');
        shouldSubmitRegForm = true;
      }
      else
      {
        
        $("#erroruser").html('<font color="red">We are sorry the selected username is not available please choose another</font>');
        shouldSubmitRegForm = false;
      }
    })
  })
});