var current_http_host;
var stateUrl = current_http_host+'cemp/state/';
var neighborhoodURL = current_http_host+'cemp/neighborhood/';

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
/* -------------------
 *  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 Selling Point");
        document.getElementById('bankname').focus();
        return false;
    }
    if(trim(document.getElementById('branch').value) == "")
    {
        alert("Please Enter Locations");
        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;
        }
    }
//    if(spaceWithAlphaNumeric(document.getElementById('branch'))){
//        if(spaceWithAlphaNumeric(document.getElementById('city'))){
//            if(spaceWithAlphaNumeric(document.getElementById('address'))){
//                return true;
//            }else{
//                alert("Invalid data in Address.");
//                return false;
//            }
//        }else{
//            alert("Invalid data in City.");
//            return false;
//        }
//    }else{
//        alert("Invalid data in Selling Point Name.");
//        return false;
//    }

}
function spaceWithAlphaNumeric(element){
    //	var branchStr = new  String(element.value)
    //	var SpaceExpr = /^\s+|\s+$/g;
    //	var SpacePos = branchStr.search(SpaceExpr);
    //	if (SpacePos > -1)
    //        return false;

    if(trim(element.value).match(/^[a-zA-Z0-9 _-]*$/) == null)
        return false;

    return true;
}
function trim(s)
{
    return s.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
//  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);
}

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 Selling Point !");
        document.getElementById('bank_name').focus();
        return false;
    }

    if(document.getElementById('branch_name').value == "")
    {
        alert("Please select Locations !");
        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");
            }
        });
        // 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');

        }
    }
    catch(e){}

});

/* for Jamb */


$(document).ready(function()
{
    $("#cancel").click(function()
    {
        $('form').attr('action','../jambreg');
        $('form').submit();

        return false;

    });


});

function getLoad(frm,vid,url,pid){

    var inst = vid.value;
    var url = url;
    $("#loader").show();
    $(pid).load(url, {
        id: inst
    },function (){
        $("#loader").hide();
    });
    $(pid).width(180);

}

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 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 b_date=objFromDate.split("/");
        var sel_date=b_date[1]+"/"+b_date[0]+"/"+b_date[2];
        var date1 = new Date(sel_date);
        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;
        }
        var bD=objFromDate.split("/");
        now = new Date();

        if(bD.length==3){
            born = new Date(bD[2], bD[1]*1-1, bD[0]);
            years = new Date(now.getTime() - born.getTime());
            base = new Date(0);
            age = years.getFullYear()-base.getFullYear();
        }
        if((age > 100) || (age < 7)){
            alert("Applicant age too high or too low!  Please provide accurate date of birth.");
            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("Please Select Postal Country ");
        return false;
    }else if(count == "NG")
    {
        if(document.getElementById('state').value == "")
        {
            //document.getElementById('error').innerHTML="<font color='red'>State is not Empty</font>";
            alert("Please Select Postal State");
            return false;
        }
    }else{
        if(LTrim(document.getElementById('otherstate').value) == "")
        {
            alert("Please Select Postal State");
            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(frm)
{
    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(LTrim(document.getElementById('date').value) != ""){
        var objFromDate = LTrim(document.getElementById('date').value);
        var b_date=objFromDate.split("/");
        var sel_date=b_date[1]+"/"+b_date[0]+"/"+b_date[2];
        var date1 = new Date(sel_date);
        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;
        }
        var bD=objFromDate.split("/");
        now = new Date();

        if(bD.length==3){
            born = new Date(bD[2], bD[1]*1-1, bD[0]);
            years = new Date(now.getTime() - born.getTime());
            base = new Date(0);
            age = years.getFullYear()-base.getFullYear();
        }
        if((age > 100) || (age < 7)){
            alert("Applicant age too high or too low!  Please provide accurate date of birth.");
            document.getElementById('date').focus();
            return false;
        }
        document.getElementById('tempDate').value = sel_date;
    }
    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;
    }
  var inputRefArray = frm.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 && inputRef.id != 'image_check')
        ++countCh;
    }
  }

        if(countCh < 5 || countCh > 9 ){
            alert("Please select minimum of 5 Subjects (including english) OR maximum of 9 Subjects (including english)");
    return false;
  }
    //return true;
    $('#save').hide();
   var success = checkValidForm();
   if(success)
       return true;
   else{
       $('#save').show();
       return false;
   }
}

/* 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 if(data == 'not_valid')
            {
                $("#erroruser").html('<font color="red">Username should contain minimum 6 characters</font>');
                shouldSubmitRegForm = false;
            }
            else {
        
                $("#erroruser").html('<font color="red">We are sorry the selected username is not available please choose another</font>');
                shouldSubmitRegForm = false;
            }
        })
    })
});

function getNeighbourhood(state,neigh){
    var state_id = $("#"+state).val();
    $("#loader").show();
    $.get(neighborhoodURL+state_id+'.html', {
        }, function (data){
            $("#examNeigh").html(data);
            if(neigh!=0){
                $('#examNeigh').val(neigh);
            }
            $("#loader").hide();
        });
    $("#examNeigh").width(180);
}

$(document).ready(function()
{
    //Didsplay office name according to state
    $("#exam_body").keydown(function (){
        $("#exam_body").change()
    });

    $("#exam_body").change(function()
    {
        var exambodyId = document.getElementById('exam_body').selectedIndex ;
        var programs = document.getElementById('allPrograms').value ;
        var splitExamType = programs.split(",") ;
        var optstr = '<option value="">Please Select</option>';
        clearOptionLast('program') ;
        for(var j=0; j < splitExamType.length; j++)
        {
            var splitProgram = splitExamType[j].split("#") ;
            var exambodytype = splitProgram[0].split(":");
            if(exambodytype[0] == exambodyId)
            {

                for(var i = 0 ; i < splitProgram.length; i++)
                {
                    var exambodytype = splitProgram[i].split(":");
                    if(exambodytype[0] == exambodyId )
                    {
                        var programKeyValue = exambodytype[1].split("@") ;

                        appendOptionLast('program', programKeyValue[1], programKeyValue[0]) ;
                        optstr += '<option value="'+programKeyValue[0]+'">'+ programKeyValue[1]+'</option>';
                    }
                }
            }
        }
        document.getElementById('amount').innerHTML = "0";
        document.getElementById('session').value = "";

    });



    // ZAID
    $("#program").change(function()
    {
        var programId = $(this).val();
        var sessions = document.getElementById('allSessions').value ;
        var splitExamType = sessions.split(",") ;
        var optstr = '<option value="">-- Please Select --</option>';
        clearOptionLast('session') ;
        for(var j=0; j < splitExamType.length; j++)
        {
            var splitProgram = splitExamType[j].split("#") ;
            var exambodytype = splitProgram[0].split(":");
            if(exambodytype[0] == programId)
            {
                for(var i = 0 ; i < splitProgram.length; i++)
                {
                    var exambodytype = splitProgram[i].split(":");
                    if(exambodytype[0] == programId )
                    {
                        var programKeyValue = exambodytype[1].split("@") ;
                        appendOptionLast('session', programKeyValue[1], programKeyValue[0]) ;
                        optstr += '<option value="'+programKeyValue[0]+'">'+ programKeyValue[1]+'</option>';
                    }
                }
            }
            document.getElementById('amount').innerHTML = "0";
        }
    });


    $("#session").change(function()
    {
        var no_of_card=document.getElementById('serial_number_to').value - document.getElementById('serial_number_from').value +1;
        if(no_of_card > 0){
            var sessionId = $(this).val();
            var allFees = document.getElementById('allFees').value ;
            var completeFee = allFees.split("@") ;
            for(var i=0; i < completeFee.length; i++)
            {
                var feeType = completeFee[i].split(":") ;
                if(feeType[0] == sessionId)
                {
                    document.getElementById('amount').innerHTML = feeType[1]*no_of_card ;
                    var totalAmount = parseInt(document.getElementById('amount').innerHTML) + parseInt(document.getElementById('amount_cemp').value);

                    document.getElementById('total_amount').innerHTML = totalAmount ;
                    break ;
                }

            }
        }else{
            alert('Please enter serial number in right way');
            return false;
        }
    });
    // END ZAID

    //Didsplay office name according to state
    $("#serial_number_from").keyup(function()
    {
        showtotalamount();

    });

    //Didsplay office name according to state
    $("#serial_number_to").keyup(function()
    {
        showtotalamount();
    });
});

/************* common methods ***********/
function clearOptionLast(selname)
{
    var elSel = document.getElementById(selname);
    if (elSel.length > 0)
    {
        for(var i = elSel.length; i > 1; i-- )
        {
            elSel.remove(elSel.length - 1);
        }
    }
}
function appendOptionLast(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
    }
}

function showtotalamount()
{
    var from = document.getElementById('serial_number_from').value;
    var to = document.getElementById('serial_number_to').value;
    var pre_amt = document.getElementById('amount_cemp1').value;
    if(from != "" && to != "" && from <= to){
        var total_amt = ((to - from)+1)*pre_amt;
        document.getElementById('amount_cemp').value = total_amt;
    }
}
function validateExamPayment()
{
    if(!alphanumeric(document.getElementById('serial_number_from').value))
    {
        alert('Please enter correct number');
        document.getElementById('serial_number_from').focus();
        return false;
    }
    if(!alphanumeric(document.getElementById('serial_number_to').value))
    {
        alert('Please enter correct number');
        document.getElementById('serial_number_to').focus();
        return false;
    }
    if(jQuery.trim(document.getElementById('serial_number_from').value)=='')
    {
        alert('Please enter valid From serial number.');
        document.getElementById('serial_number_from').focus();
        document.getElementById('serial_number_from').select();
        return false;
    }

    if(jQuery.trim(document.getElementById('serial_number_to').value)=='')
    {
        alert('Please enter valid To serial number.');
        document.getElementById('serial_number_to').focus();
        document.getElementById('serial_number_to').select();
        return false;
    }

    if(document.getElementById('exam_body').value=='')
    {
        alert('Please select exam body.');
        document.getElementById('exam_body').focus();
        return false;
    }

    // for stoping the payment of Nabteb and Jamb By Kuldeep //
    //START

    //    if(document.getElementById('exam_body').value==1)
    //    {
    //      alert('You can not pay for JAMB.Please select other Exam body .');
    //      document.getElementById('exam_body').focus();
    //      return false;
    //    }
    //
    //    if(document.getElementById('exam_body').value==3)
    //    {
    //      alert('You can not pay for Nabteb . Please select other Exam body .');
    //      document.getElementById('exam_body').focus();
    //      return false;
    //    }
    //END



    if(document.getElementById('program').value=='')
    {
        alert('Please select program type.');
        document.getElementById('program').focus();
        return false;
    }
    if(document.getElementById('session').value=='')
    {
        alert('Please select session type.');
        document.getElementById('session').focus();
        return false;
    }
    if(document.getElementById('amount_cemp').value <= 0 )
    {
        alert('The amount is not calculated please enter from serial number and then enter to serial number.');
        return false;
    }
    if(document.getElementById('serial_number_from').value > document.getElementById('serial_number_to').value)
    {
        alert('Please enter correct serial number');
        document.getElementById('serial_number_from').focus();
        return false;
    }

    if(document.getElementById('serial_number_from').value.length != 12 || document.getElementById('serial_number_to').value.length != 12)
    {
        alert('Serial Number should be of 12 digits');
        return false;
    }

    $("#multiFormSubmit").attr('disabled', true);

    return true;
}
// dropdown.js : Anurag
function dropdown(mySel)
{
    var myWin, myVal;
    myVal = mySel.options[mySel.selectedIndex].value;
    if(myVal)
    {
        if(mySel.form.target)myWin = parent[mySel.form.target];
        else myWin = window;
        if (! myWin) return true;
        myWin.location = myVal;
    }
    return false;
}

function setSession(){
    var program = "";
    var url = "<?php echo url_for('bankadmin/Session/'); ?>";
    $("#session").load(url, {
        program: program
    });
    document.getElementById('amount').innerHTML = "0";
//document.getElementById('hiden').value = "0";
}

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;
}

/**************** upload.js ***********/

/**
 * @fileoverview
 * JavaScript Image Upload Preview.
 * Tested and compatible with IE6, IE7, IE8, Firefox 3.
 *
 * @author Hedger Wang (hedgerwang@gmail.com)
 *
 */

/**
 * @constructor
 * @param {HTMLInputElement|String} input
 * @param {Function?} opt_onSuccess
 * @param {Function?} opt_onFail
 */
function ImageUploadPreview(input, opt_onSuccess, opt_onFail) {
    this.construct(input, opt_onSuccess, opt_onFail);
}

/**
 * Empty image that shows either for Http:// or Https://.
 * @define {String}
 */
ImageUploadPreview.BLANK_IMAGE_SRC = '//www.google.com/images/cleardot.gif';


/**
 * @define {RegExp}
 */
ImageUploadPreview.BASE64_IMG_URL_PATTERN =
    /^data:image\/((png)|(gif)|(jpg)|(jpeg)|(bmp));base64/i;


/**
 * @type {HTMLInputElement}
 * @private
 */
ImageUploadPreview.prototype.input_ = null;


/**
 * @type {Function}
 * @private
 */
ImageUploadPreview.prototype.onChangeHandler_ = null;


/**
 * @type {Function}
 * @private
 */
ImageUploadPreview.prototype.onPreviewSuccessHandler_ = null;


/**
 * @type {Function}
 * @private
 */
ImageUploadPreview.prototype.onPreviewFailHandler_ = null;


/**
 * @type {HTMLImageElement}
 * @private
 */
ImageUploadPreview.prototype.image_ = null;


/**
 * @private
 * @type {boolean}
 */
ImageUploadPreview.prototype.isCompatible_ = null;


/**
 * @private
 * @type {Number}
 */
ImageUploadPreview.prototype.maxWidth_ = 200;


/**
 * @private
 * @type {Number}
 */
ImageUploadPreview.prototype.maxHeight_ = 200;


/**
 * @param {HTMLInputElement|String} input
 * @param {Function?} opt_onSuccess
 * @param {Function?} opt_onFail
 * @public
 */
ImageUploadPreview.prototype.construct =
    function(input, opt_onSuccess, opt_onFail) {
        if (typeof input == 'string') {
            input = document.getElementById(input);
        }

        this.onPreviewFailHandler_ = opt_onFail;
        this.onPreviewSuccessHandler_ = opt_onSuccess;
        this.input_ = input;
        this.bindEvents_();
        this.image_ = this.createImage_();
    };


/**
 * @public
 */
ImageUploadPreview.prototype.dispose = function() {
    var fn = this.onChangeHandler_;

    // Already disposed.
    if (!fn) return;

    var el = this.input_;

    if (el.addEventListener) {
        el.removeEventListener('change', fn, false);
    } else if (el.attachEvent) {
        el.detachEvent('onchange', fn);
    }

    this.onChangeHandler_ = null;
    this.input_ = null;
    this.image_ = null;
};

/**
 * @public
 */
ImageUploadPreview.prototype.preview = function() {
    var that = this;

    var onLoad = function(imgInfo) {
        // Do thing now, maybe do something later.
        that.maybeCallFunction_(that.onPreviewSuccessHandler_, imgInfo);
    };

    var onError = function(src) {
        if (!tryLoad()) {
            that.showEmptyImage_();
            that.maybeCallFunction_(that.onPreviewFailHandler_, src);
        }
    };

    var loadMethods = [
    this.maybeShowImageWithDataUri_,
    this.maybeShowImageByPath_
    ];

    var tryLoad = function() {
        if (!loadMethods.length) {
            return false;
        }
        var fn = loadMethods.shift();
        fn.call(that, onLoad, onError);
        return true;
    };
    tryLoad();
};


/**
 * @public
 * @return {HTMLImageElement}
 */
ImageUploadPreview.prototype.getImageElement = function() {
    return this.image_;
};


/**
 * @public
 * @return {HTMLInputElement}
 */
ImageUploadPreview.prototype.getInputElement = function() {
    return this.input_;
};


/**
 * @public
 * @param {Number} maxW
 * @param {Number} maxH
 */
ImageUploadPreview.prototype.setMaxImageSize = function(maxW, maxH) {
    this.maxHeight_ = isNaN(maxH) ? 10000 : maxH;
    this.maxWidth_ = isNaN(maxW) ? 10000 : maxW;
};


/**
 * @private
 * @return {HTMLImageElement}
 */
ImageUploadPreview.prototype.createImage_ = function() {
    var doc = this.input_.document || this.input_.ownerDocument;
    var img = doc.createElement('img');
    img.src = ImageUploadPreview.BLANK_IMAGE_SRC;
    img.width = 0;
    img.height = 0;
    this.input_.parentNode.insertBefore(img, this.input_.nextSibling || null);
    return img;
};



/**
 * @private
 */
ImageUploadPreview.prototype.bindEvents_ = function() {
    var that = this;

    var fn = this.onChangeHandler_ = function(e) {
        e = e || window.event;

        if (!e.target && e.srcElement) {
            e.target = e.srcElement;
        }

        that.handleOnchange_.call(that, e);
    };

    var el = this.input_;

    if (el.addEventListener) {
        el.addEventListener('change', fn, false);
    } else if (el.attachEvent) {
        el.attachEvent('onchange', fn);
    }
};


/**
 * @param {Event} e
 * @private
 */
ImageUploadPreview.prototype.handleOnchange_ = function(e) {
    this.preview();
};


/**
 * @private
 */
ImageUploadPreview.prototype.showEmptyImage_ = function() {
    this.showImage_(ImageUploadPreview.BLANK_IMAGE_SRC, 0, 0)
};


/**
 * @private
 * @param {string} src
 * @param {number} w
 * @param {number} h
 */
ImageUploadPreview.prototype.showImage_ = function(src, w, h) {

    if (w > h) {
        if (w > this.maxWidth_) {
            h = h * this.maxWidth_ / w;
            w = this.maxWidth_;
        }
    } else {
        if (h > this.maxHeight_) {
            w = w * this.maxHeight_ / h;
            h = this.maxHeight_;
        }
    }

    var img = this.image_;
    img.src = src;

    var imgStyle = img.style;
    imgStyle.maxHeight = this.maxHeight_ + 'px';
    imgStyle.maxWidth = this.maxWidth_ + 'px';
    imgStyle.width = (w >= 0) ? Math.round(w) + 'px' : 'auto';
    imgStyle.height = (h >= 0) ? Math.round(h) + 'px' : 'auto';
};


/**
 * @param {Function?} fn
 * @param {Object?} var_args
 */
ImageUploadPreview.prototype.maybeCallFunction_ = function(fn, var_args) {
    if (typeof fn != 'function') return;
    var_args = Array.prototype.slice.call(arguments, 1);
    fn.apply(this, var_args);
};


/**
 * Note: Only Firefox 3 can do file.getAsDataURL() by 6/1/2009.
 * See {@link https://developer.mozilla.org/En/NsIDOMFile}.
 * @private
 * @param {Function?} opt_onload
 * @param {Function?} opt_onerror
 */
ImageUploadPreview.prototype.maybeShowImageWithDataUri_ =
    function(opt_onload, opt_onerror) {
        var el = this.input_;
        var file = el.files && el.files[0];
        var src;
        var fileName = el.value;

        // Check if we can access the serialized file via getAsDataURL().
        if ((file && file.getAsDataURL) &&
            (src = file.getAsDataURL()) &&
            (ImageUploadPreview.BASE64_IMG_URL_PATTERN.test(src))) {

            var that = this;
            var img = this.image_;


            if ('naturalWidth' in this.image_) {
                // Firefox has naturalWidth.
                this.image_.src = src;

                setTimeout(function() {
                    that.showImage_(src, img.naturalWidth, img.naturalHeight);
                    that.maybeCallFunction_(opt_onload, {
                        width: img.naturalWidth,
                        height: img.naturalHeight,
                        fileName : fileName,
                        fileSize: el.files[0].fileSize
                    });
                }, 10);

            } else {
                // Use default CSS max-width / max-height to render the size.
                that.showImage_(src, -1, -1);

                this.maybeCallFunction_(opt_onload, {
                    fileName : fileName,
                    width: img.offsetWidth,
                    height: img.offsetHeight,
                    fileSize: el.files[0].fileSize
                });
            }
        } else {
            this.maybeCallFunction_(opt_onerror, fileName);
        }
    };


/**
 * Note: IE6 ~ IE8 can access image with local path. By 6/1/2009.
 *       However, this may still not work if the security setting changes.
 * @private
 * @param {Function?} opt_onload
 * @param {Function?} opt_onerror
 */
ImageUploadPreview.prototype.maybeShowImageByPath_ =
    function(opt_onload, opt_onerror) {

        var that = this;
        var el = this.input_;
        var img = new Image();
        var timer;
        var fileName = el.value.split(/[\\\/]/ig).pop();

        var dispose = function() {
            if (timer) {
                window.clearInterval(timer);
            }
            img.onload = null;
            img.onerror = null;
            timer = null;
            dispose = null;
            img = null;
            that = null;
            checkIsComplete = null;
            handleError = null;
            handleComplete = null;
        };

        // Handle the case whether the File is not a image file or the path is not a
        // valid path to access.
        var handleError = function() {
            that.maybeCallFunction_(opt_onerror, el.value);
            dispose();
        };

        var handleComplete = function() {
            var w = img.width;
            var h = img.height;
            that.showImage_(img.src, w, h);
            that.maybeCallFunction_(opt_onload, {
                src:fileName,
                width: w,
                height: h,
                fileSize: img.fileSize // Note that FileSize is an IE's only attribute.
            });
            dispose();
        };

        var checkIsComplete = function(e) {
            e = e || window.event;
            var type = e && e.type;

            if (type == 'error') {
                // If the onError event is called.
                handleError();
            } else  if (img.complete || type == 'load') {
                // Sometimes IE does not fire "onload" event if the image was cahced.
                // So we have to check the "complete" state to know whether it's ready.
                if (!img.width || !img.height) {
                    // Even it's not a real image, the onload event may still gets fired.
                    // Check if its width or height is 0. If true, it's not a real image.
                    handleError();
                } else {
                    handleComplete();
                }
            }
        };


        img.onload = checkIsComplete;
        img.onerror = checkIsComplete;
        timer = window.setInterval(checkIsComplete, 50);

        // In IE, el.value us the full path of the file rather than just the fileName,
        // and we'd test if we can load image from this path.
        img.src = el.value;

    };
/** end of upload.js ***/
/** start of dhtmlwindow.js **/
// -------------------------------------------------------------------
// DHTML Window Widget- By Dynamic Drive, available at: http://www.dynamicdrive.com
// v1.0: Script created Feb 15th, 07'
// v1.01: Feb 21th, 07' (see changelog.txt)
// v1.02: March 26th, 07' (see changelog.txt)
// v1.03: May 5th, 07' (see changelog.txt)
// v1.1:  Oct 29th, 07' (see changelog.txt)
// -------------------------------------------------------------------

var dhtmlwindow={
    imagefiles:[''], //Path to 4 images used by script, in that order
    ajaxbustcache: true, //Bust caching when fetching a file via Ajax?
    ajaxloadinghtml: '<b>Loading Page. Please wait...</b>', //HTML to show while window fetches Ajax Content?

    minimizeorder: 0,
    zIndexvalue:100,
    tobjects: [], //object to contain references to dhtml window divs, for cleanup purposes
    lastactivet: {}, //reference to last active DHTML window

    init:function(t){
        var domwindow=document.createElement("div") //create dhtml window div
        domwindow.id=t
        domwindow.className="dhtmlwindow"
        var domwindowdata=''
        domwindowdata='<div class="drag-handle">'
        domwindowdata+='DHTML Window <div class="drag-controls"><img src="'+this.imagefiles[0]+'" title="Minimize" /></div>'
        domwindowdata+='</div>'
        domwindowdata+='<div class="drag-contentarea"></div>'
        domwindowdata+='<div class="drag-statusarea"><div class="drag-resizearea" style="background: transparent url('+this.imagefiles[3]+') top right no-repeat;">&nbsp;</div></div>'
        domwindowdata+='</div>'
        domwindow.innerHTML=domwindowdata
        document.getElementById("dhtmlwindowholder").appendChild(domwindow)
        //this.zIndexvalue=(this.zIndexvalue)? this.zIndexvalue+1 : 100 //z-index value for DHTML window: starts at 0, increments whenever a window has focus
        var t=document.getElementById(t)
        var divs=t.getElementsByTagName("div")
        for (var i=0; i<divs.length; i++){ //go through divs inside dhtml window and extract all those with class="drag-" prefix
            if (/drag-/.test(divs[i].className))
                t[divs[i].className.replace(/drag-/, "")]=divs[i] //take out the "drag-" prefix for shorter access by name
        }
        //t.style.zIndex=this.zIndexvalue //set z-index of this dhtml window
        //t.handle._parent=t //store back reference to dhtml window
        t.resizearea._parent=t //same
        t.controls._parent=t //same
        t.onclose=function(){
            return true
            } //custom event handler "onclose"
        t.onmousedown=function(){
            dhtmlwindow.setfocus(this)
            } //Increase z-index of window when focus is on it
        //t.handle.onmousedown=dhtmlwindow.setupdrag //set up drag behavior when mouse down on handle div
        t.resizearea.onmousedown=dhtmlwindow.setupdrag //set up drag behavior when mouse down on resize div
        t.controls.onclick=dhtmlwindow.enablecontrols
        t.show=function(){
            dhtmlwindow.show(this)
            } //public function for showing dhtml window
        t.hide=function(){
            dhtmlwindow.hide(this)
            } //public function for hiding dhtml window
        t.close=function(){
            dhtmlwindow.close(this)
            } //public function for closing dhtml window (also empties DHTML window content)
        t.setSize=function(w, h){
            dhtmlwindow.setSize(this, w, h)
            } //public function for setting window dimensions
        t.moveTo=function(x, y){
            dhtmlwindow.moveTo(this, x, y)
            } //public function for moving dhtml window (relative to viewpoint)
        t.isResize=function(bol){
            dhtmlwindow.isResize(this, bol)
            } //public function for specifying if window is resizable
        t.isScrolling=function(bol){
            dhtmlwindow.isScrolling(this, bol)
            } //public function for specifying if window content contains scrollbars
        t.load=function(contenttype, contentsource, title){
            dhtmlwindow.load(this, contenttype, contentsource, title)
            } //public function for loading content into window
        this.tobjects[this.tobjects.length]=t
        return t //return reference to dhtml window div
    },

    open:function(t, contenttype, contentsource, title, attr, recalonload){
        var d=dhtmlwindow //reference dhtml window object
        function getValue(Name){
            var config=new RegExp(Name+"=([^,]+)", "i") //get name/value config pair (ie: width=400px,)
            return (config.test(attr))? parseInt(RegExp.$1) : 0 //return value portion (int), or 0 (false) if none found
        }
        if (document.getElementById(t)==null) //if window doesn't exist yet, create it
            t=this.init(t) //return reference to dhtml window div
        else
            t=document.getElementById(t)
        this.setfocus(t)
        t.setSize(getValue(("width")), (getValue("height"))) //Set dimensions of window
        var xpos=getValue("center")? "middle" : getValue("left") //Get x coord of window
        var ypos=getValue("center")? "middle" : getValue("top") //Get y coord of window
        //t.moveTo(xpos, ypos) //Position window
        if (typeof recalonload!="undefined" && recalonload=="recal" && this.scroll_top==0){ //reposition window when page fully loads with updated window viewpoints?
            if (window.attachEvent && !window.opera) //In IE, add another 400 milisecs on page load (viewpoint properties may return 0 b4 then)
                this.addEvent(window, function(){
                    setTimeout(function(){
                        t.moveTo(xpos, ypos)
                        }, 400)
                    }, "load")
            else
                this.addEvent(window, function(){
                    t.moveTo(xpos, ypos)
                    }, "load")
        }
        t.isResize(getValue("resize")) //Set whether window is resizable
        t.isScrolling(getValue("scrolling")) //Set whether window should contain scrollbars
        t.style.visibility="visible"
        t.style.display="block"
        t.contentarea.style.display="block"
        t.moveTo(xpos, ypos) //Position window
        t.load(contenttype, contentsource, title)
        if (t.state=="minimized" && t.controls.firstChild.title=="Restore"){ //If window exists and is currently minimized?
            t.controls.firstChild.setAttribute("src", dhtmlwindow.imagefiles[0]) //Change "restore" icon within window interface to "minimize" icon
            t.controls.firstChild.setAttribute("title", "Minimize")
            t.state="fullview" //indicate the state of the window as being "fullview"
        }
        return t
    },

    setSize:function(t, w, h){ //set window size (min is 150px wide by 100px tall)
        t.style.width=Math.max(parseInt(w), 150)+"px"
        t.contentarea.style.height=Math.max(parseInt(h), 100)+"px"
    },

    moveTo:function(t, x, y){ //move window. Position includes current viewpoint of document
        this.getviewpoint() //Get current viewpoint numbers
        t.style.left=(x=="middle")? this.scroll_left+(this.docwidth-t.offsetWidth)/2+"px" : this.scroll_left+parseInt(x)+"px"
        t.style.top=(y=="middle")? this.scroll_top+(this.docheight-t.offsetHeight)/2+"px" : this.scroll_top+parseInt(y)+"px"
    },

    isResize:function(t, bol){ //show or hide resize inteface (part of the status bar)
        t.statusarea.style.display=(bol)? "block" : "none"
        t.resizeBool=(bol)? 1 : 0
    },

    isScrolling:function(t, bol){ //set whether loaded content contains scrollbars
        t.contentarea.style.overflow=(bol)? "auto" : "hidden"
    },

    load:function(t, contenttype, contentsource, title){ //loads content into window plus set its title (3 content types: "inline", "iframe", or "ajax")
        if (t.isClosed){
            alert("DHTML Window has been closed, so no window to load contents into. Open/Create the window again.")
            return
        }
        var contenttype=contenttype.toLowerCase() //convert string to lower case
        if (typeof title!="undefined")
            t.handle.firstChild.nodeValue=title
        if (contenttype=="inline")
            t.contentarea.innerHTML=contentsource
        else if (contenttype=="div"){
            var inlinedivref=document.getElementById(contentsource)
            t.contentarea.innerHTML=(inlinedivref.defaultHTML || inlinedivref.innerHTML) //Populate window with contents of inline div on page
            if (!inlinedivref.defaultHTML)
                inlinedivref.defaultHTML=inlinedivref.innerHTML //save HTML within inline DIV
            inlinedivref.innerHTML="" //then, remove HTML within inline DIV (to prevent duplicate IDs, NAME attributes etc in contents of DHTML window
            inlinedivref.style.display="none" //hide that div
        }
        else if (contenttype=="iframe"){
            t.contentarea.style.overflow="hidden" //disable window scrollbars, as iframe already contains scrollbars
            if (!t.contentarea.firstChild || t.contentarea.firstChild.tagName!="IFRAME") //If iframe tag doesn't exist already, create it first
                t.contentarea.innerHTML='<iframe src="" style="margin:0; padding:0; width:100%; height: 100%" name="_iframe-'+t.id+'"></iframe>'
            window.frames["_iframe-"+t.id].location.replace(contentsource) //set location of iframe window to specified URL
        }
        else if (contenttype=="ajax"){
            this.ajax_connect(contentsource, t) //populate window with external contents fetched via Ajax
        }
        t.contentarea.datatype=contenttype //store contenttype of current window for future reference
    },

    setupdrag:function(e){
        var d=dhtmlwindow //reference dhtml window object
        var t=this._parent //reference dhtml window div
        d.etarget=this //remember div mouse is currently held down on ("handle" or "resize" div)
        var e=window.event || e
        d.initmousex=e.clientX //store x position of mouse onmousedown
        d.initmousey=e.clientY
        d.initx=parseInt(t.offsetLeft) //store offset x of window div onmousedown
        d.inity=parseInt(t.offsetTop)
        d.width=parseInt(t.offsetWidth) //store width of window div
        d.contentheight=parseInt(t.contentarea.offsetHeight) //store height of window div's content div
        if (t.contentarea.datatype=="iframe"){ //if content of this window div is "iframe"
            t.style.backgroundColor="#F8F8F8" //colorize and hide content div (while window is being dragged)
            t.contentarea.style.visibility="hidden"
        }
        document.onmousemove=d.getdistance //get distance travelled by mouse as it moves
        document.onmouseup=function(){
            if (t.contentarea.datatype=="iframe"){ //restore color and visibility of content div onmouseup
                t.contentarea.style.backgroundColor="white"
                t.contentarea.style.visibility="visible"
            }
            d.stop()
        }
        return false
    },

    getdistance:function(e){
        var d=dhtmlwindow
        var etarget=d.etarget
        var e=window.event || e
        d.distancex=e.clientX-d.initmousex //horizontal distance travelled relative to starting point
        d.distancey=e.clientY-d.initmousey
        if (etarget.className=="drag-handle") //if target element is "handle" div
            d.move(etarget._parent, e)
        else if (etarget.className=="drag-resizearea") //if target element is "resize" div
            d.resize(etarget._parent, e)
        return false //cancel default dragging behavior
    },

    getviewpoint:function(){ //get window viewpoint numbers
        var ie=document.all && !window.opera
        var domclientWidth=document.documentElement && parseInt(document.documentElement.clientWidth) || 100000 //Preliminary doc width in non IE browsers
        this.standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body //create reference to common "body" across doctypes
        this.scroll_top=(ie)? this.standardbody.scrollTop : window.pageYOffset
        this.scroll_left=(ie)? this.standardbody.scrollLeft : window.pageXOffset
        this.docwidth=(ie)? this.standardbody.clientWidth : (/Safari/i.test(navigator.userAgent))? window.innerWidth : Math.min(domclientWidth, window.innerWidth-16)
        this.docheight=(ie)? this.standardbody.clientHeight: window.innerHeight
    },

    rememberattrs:function(t){ //remember certain attributes of the window when it's minimized or closed, such as dimensions, position on page
        this.getviewpoint() //Get current window viewpoint numbers
        t.lastx=parseInt((t.style.left || t.offsetLeft))-dhtmlwindow.scroll_left //store last known x coord of window just before minimizing
        t.lasty=parseInt((t.style.top || t.offsetTop))-dhtmlwindow.scroll_top
        t.lastwidth=parseInt(t.style.width) //store last known width of window just before minimizing/ closing
    },

    move:function(t, e){
        t.style.left=dhtmlwindow.distancex+dhtmlwindow.initx+"px"
        t.style.top=dhtmlwindow.distancey+dhtmlwindow.inity+"px"
    },

    resize:function(t, e){
        t.style.width=Math.max(dhtmlwindow.width+dhtmlwindow.distancex, 150)+"px"
        t.contentarea.style.height=Math.max(dhtmlwindow.contentheight+dhtmlwindow.distancey, 100)+"px"
    },

    enablecontrols:function(e){
        var d=dhtmlwindow
        var sourceobj=window.event? window.event.srcElement : e.target //Get element within "handle" div mouse is currently on (the controls)
        if (/Minimize/i.test(sourceobj.getAttribute("title"))) //if this is the "minimize" control
            d.minimize(sourceobj, this._parent)
        else if (/Restore/i.test(sourceobj.getAttribute("title"))) //if this is the "restore" control
            d.restore(sourceobj, this._parent)
        else if (/Close/i.test(sourceobj.getAttribute("title"))) //if this is the "close" control
            d.close(this._parent)
        return false
    },

    minimize:function(button, t){
        dhtmlwindow.rememberattrs(t)
        button.setAttribute("src", dhtmlwindow.imagefiles[2])
        button.setAttribute("title", "Restore")
        t.state="minimized" //indicate the state of the window as being "minimized"
        t.contentarea.style.display="none"
        t.statusarea.style.display="none"
        if (typeof t.minimizeorder=="undefined"){ //stack order of minmized window on screen relative to any other minimized windows
            dhtmlwindow.minimizeorder++ //increment order
            t.minimizeorder=dhtmlwindow.minimizeorder
        }
        t.style.left="10px" //left coord of minmized window
        t.style.width="200px"
        var windowspacing=t.minimizeorder*10 //spacing (gap) between each minmized window(s)
        t.style.top=dhtmlwindow.scroll_top+dhtmlwindow.docheight-(t.handle.offsetHeight*t.minimizeorder)-windowspacing+"px"
    },

    restore:function(button, t){
        dhtmlwindow.getviewpoint()
        button.setAttribute("src", dhtmlwindow.imagefiles[0])
        button.setAttribute("title", "Minimize")
        t.state="fullview" //indicate the state of the window as being "fullview"
        t.style.display="block"
        t.contentarea.style.display="block"
        if (t.resizeBool) //if this window is resizable, enable the resize icon
            t.statusarea.style.display="block"
        t.style.left=parseInt(t.lastx)+dhtmlwindow.scroll_left+"px" //position window to last known x coord just before minimizing
        t.style.top=parseInt(t.lasty)+dhtmlwindow.scroll_top+"px"
        t.style.width=parseInt(t.lastwidth)+"px"
    },


    close:function(t){
        try{
            var closewinbol=t.onclose()
        }
        catch(err){ //In non IE browsers, all errors are caught, so just run the below
            var closewinbol=true
        }
        finally{ //In IE, not all errors are caught, so check if variable isn't defined in IE in those cases
            if (typeof closewinbol=="undefined"){
                alert("An error has occured somwhere inside your \"onclose\" event handler")
                var closewinbol=true
            }
        }
        if (closewinbol){ //if custom event handler function returns true
            if (t.state!="minimized") //if this window isn't currently minimized
                dhtmlwindow.rememberattrs(t) //remember window's dimensions/position on the page before closing
            if (window.frames["_iframe-"+t.id]) //if this is an IFRAME DHTML window
                window.frames["_iframe-"+t.id].location.replace("about:blank")
            else
                t.contentarea.innerHTML=""
            t.style.display="none"
            t.isClosed=true //tell script this window is closed (for detection in t.show())
        }
        return closewinbol
    },


    setopacity:function(targetobject, value){ //Sets the opacity of targetobject based on the passed in value setting (0 to 1 and in between)
        if (!targetobject)
            return
        if (targetobject.filters && targetobject.filters[0]){ //IE syntax
            if (typeof targetobject.filters[0].opacity=="number") //IE6
                targetobject.filters[0].opacity=value*100
            else //IE 5.5
                targetobject.style.filter="alpha(opacity="+value*100+")"
        }
        else if (typeof targetobject.style.MozOpacity!="undefined") //Old Mozilla syntax
            targetobject.style.MozOpacity=value
        else if (typeof targetobject.style.opacity!="undefined") //Standard opacity syntax
            targetobject.style.opacity=value
    },

    setfocus:function(t){ //Sets focus to the currently active window
        this.zIndexvalue++
        t.style.zIndex=this.zIndexvalue
        t.isClosed=false //tell script this window isn't closed (for detection in t.show())
        this.setopacity(this.lastactivet.handle, 0.5) //unfocus last active window
        this.setopacity(t.handle, 1) //focus currently active window
        this.lastactivet=t //remember last active window
    },


    show:function(t){
        if (t.isClosed){
            alert("DHTML Window has been closed, so nothing to show. Open/Create the window again.")
            return
        }
        if (t.lastx) //If there exists previously stored information such as last x position on window attributes (meaning it's been minimized or closed)
            dhtmlwindow.restore(t.controls.firstChild, t) //restore the window using that info
        else
            t.style.display="block"
        this.setfocus(t)
        t.state="fullview" //indicate the state of the window as being "fullview"
    },

    hide:function(t){
        t.style.display="none"
    },

    ajax_connect:function(url, t){
        var page_request = false
        var bustcacheparameter=""
        if (window.XMLHttpRequest) // if Mozilla, IE7, Safari etc
            page_request = new XMLHttpRequest()
        else if (window.ActiveXObject){ // if IE6 or below
            try {
                page_request = new ActiveXObject("Msxml2.XMLHTTP")
            }
            catch (e){
                try{
                    page_request = new ActiveXObject("Microsoft.XMLHTTP")
                }
                catch (e){}
            }
        }
        else
            return false
        t.contentarea.innerHTML=this.ajaxloadinghtml
        page_request.onreadystatechange=function(){
            dhtmlwindow.ajax_loadpage(page_request, t)
            }
        if (this.ajaxbustcache) //if bust caching of external page
            bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
        page_request.open('GET', url+bustcacheparameter, true)
        page_request.send(null)
    },

    ajax_loadpage:function(page_request, t){
        if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){
            t.contentarea.innerHTML=page_request.responseText
        }
    },


    stop:function(){
        dhtmlwindow.etarget=null //clean up
        document.onmousemove=null
        document.onmouseup=null
    },

    addEvent:function(target, functionref, tasktype){ //assign a function to execute to an event handler (ie: onunload)
        var tasktype=(window.addEventListener)? tasktype : "on"+tasktype
        if (target.addEventListener)
            target.addEventListener(tasktype, functionref, false)
        else if (target.attachEvent)
            target.attachEvent(tasktype, functionref)
    },

    cleanup:function(){
        for (var i=0; i<dhtmlwindow.tobjects.length; i++){
            dhtmlwindow.tobjects[i].handle._parent=dhtmlwindow.tobjects[i].resizearea._parent=dhtmlwindow.tobjects[i].controls._parent=null
        }
        window.onload=null
    }

} //End dhtmlwindow object

document.write('<div id="dhtmlwindowholder"><span style="display:none">.</span></div>') //container that holds all dhtml window divs on page
window.onunload=dhtmlwindow.cleanup
/** end of dhtmlwindow.js ***/
/*** modal.js ***/
// // -------------------------------------------------------------------
// DHTML Modal window- By Dynamic Drive, available at: http://www.dynamicdrive.com
// v1.0: Script created Feb 27th, 07'
// v1.01 May 5th, 07' Minor change to modal window positioning behavior (not a bug fix)
// v1.1: April 16th, 08' Brings it in sync with DHTML Window widget. See changelog.txt for the later for changes.
// REQUIRES: DHTML Window Widget (v1.01 or higher): http://www.dynamicdrive.com/dynamicindex8/dhtmlwindow/
// -------------------------------------------------------------------

if (typeof dhtmlwindow=="undefined")
    alert('ERROR: Modal Window script requires all files from "DHTML Window widget" in order to work!')

var dhtmlmodal={
    veilstack: 0,
    open:function(t, contenttype, contentsource, title, attr, recalonload){
        var d=dhtmlwindow //reference dhtmlwindow object
        this.interVeil=document.getElementById("interVeil") //Reference "veil" div
        this.veilstack++ //var to keep track of how many modal windows are open right now
        this.loadveil()
        if (recalonload=="recal" && d.scroll_top==0)
            d.addEvent(window, function(){
                dhtmlmodal.adjustveil()
                }, "load")
        var t=d.open(t, contenttype, contentsource, title, attr, recalonload)
        t.controls.firstChild.style.display="none" //Disable "minimize" button
        t.controls.onclick=function(){
            dhtmlmodal.close(this._parent, true)
            } //OVERWRITE default control action with new one
        t.show=function(){
            dhtmlmodal.show(this)
            } //OVERWRITE default t.show() method with new one
        t.hide=function(){
            dhtmlmodal.close(this)
            } //OVERWRITE default t.hide() method with new one
        return t
    },


    loadveil:function(){
        var d=dhtmlwindow
        d.getviewpoint()
        this.docheightcomplete=(d.standardbody.offsetHeight>d.standardbody.scrollHeight)? d.standardbody.offsetHeight : d.standardbody.scrollHeight
        this.interVeil.style.width=d.docwidth+"px" //set up veil over page
        this.interVeil.style.height=this.docheightcomplete+"px" //set up veil over page
        this.interVeil.style.left=0 //Position veil over page
        this.interVeil.style.top=0 //Position veil over page
        this.interVeil.style.visibility="visible" //Show veil over page
        this.interVeil.style.display="block" //Show veil over page
    },

    adjustveil:function(){ //function to adjust veil when window is resized
        if (this.interVeil && this.interVeil.style.display=="block") //If veil is currently visible on the screen
            this.loadveil() //readjust veil
    },

    closeveil:function(){ //function to close veil
        this.veilstack--
        if (this.veilstack==0) //if this is the only modal window visible on the screen, and being closed
            this.interVeil.style.display="none"
    },


    close:function(t, forceclose){ //DHTML modal close function
        t.contentDoc=(t.contentarea.datatype=="iframe")? window.frames["_iframe-"+t.id].document : t.contentarea //return reference to modal window DIV (or document object in the case of iframe
        if (typeof forceclose!="undefined")
            t.onclose=function(){
                return true
                }
        if (dhtmlwindow.close(t)) //if close() returns true
            this.closeveil()
    },


    show:function(t){
        dhtmlmodal.veilstack++
        dhtmlmodal.loadveil()
        dhtmlwindow.show(t)
    }
} //END object declaration


document.write('<div id="interVeil"></div>')
dhtmlwindow.addEvent(window, function(){
    if (typeof dhtmlmodal!="undefined") dhtmlmodal.adjustveil()
        }, "resize")
/** end of modal.js **/

function necovalidation(frm){
    /*   START CEMTP REGISTRATION VALIDATION      */
    if(LTrim(document.getElementById('username').value) == ""){
        alert("Please Enter User Name");
        document.getElementById('username').focus();
        return false;
    }else if(LTrim(document.getElementById('username').value) != ""){
        if(LTrim(document.getElementById('username').value).length<6){
            alert("User Name is too short (6 characters minimum)");
            document.getElementById('username').focus();
            return false;
        }
        if(LTrim(document.getElementById('username').value).length>15){
            alert("User Name is too long (15 characters maximum)");
            document.getElementById('username').focus();
            return false;
        }
    }
    if(LTrim(document.getElementById('pass').value) == ""){
        alert("Please Enter Password");
        document.getElementById('pass').focus();
        return false;
    }else if(LTrim(document.getElementById('pass').value) != ""){
        if(LTrim(document.getElementById('pass').value).length<6){
            alert("Password is too short (6 characters minimum)");
            document.getElementById('pass').focus();
            return false;
        }
        if(LTrim(document.getElementById('pass').value).length>15){
            alert("Password is too long (15 characters maximum)");
            document.getElementById('pass').focus();
            return false;
        }
    }
    if(LTrim(document.getElementById('cpass').value) == ""){
        alert("Please Enter Confirm Password");
        document.getElementById('cpass').focus();
        return false;
    }else if(LTrim(document.getElementById('cpass').value) != ""){
        if(LTrim(document.getElementById('cpass').value).length<6){
            alert("Confirm Password is too short (6 characters minimum)");
            document.getElementById('cpass').focus();
            return false;
        }
        if(LTrim(document.getElementById('cpass').value).length>15){
            alert("Confirm Password is too long (15 characters maximum)");
            document.getElementById('cpass').focus();
            return false;
        }
    }
    if(LTrim(document.getElementById('pass').value) != LTrim(document.getElementById('cpass').value)){
        alert("Password and Confirm Password does not match");
        document.getElementById('pass').focus();
        return false;
    }
    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('gsmno').value) != "")
    {
        var reg = /^-?\d+(\.\d+)?$/;
        var gsm = LTrim(document.getElementById('gsmno').value);
        if(reg.test(gsm) == false) {
            alert('Please eneter valid GSM No');
            document.getElementById('gsmno').focus();
            return false;
        }
    }
    if(LTrim(document.getElementById('gsmno').value) == ""){
        alert("Please Enter GSM No");
        document.getElementById('gsmno').focus();
        return false;
    }
    if(LTrim(document.getElementById('sex').value) == ""){
        alert("Please Select Gender Type");
        document.getElementById('sex').focus();
        return false;
    }
    if(LTrim(document.getElementById('mstatus').value) == ""){
        alert("Please Select Marital Status");
        document.getElementById('mstatus').focus();
        return false;
    }
    if(LTrim(document.getElementById('disablility').value) == ""){
        alert("Please Select Disability Type");
        document.getElementById('disablility').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 b_date=objFromDate.split("/");
        var sel_date=b_date[1]+"/"+b_date[0]+"/"+b_date[2];
        var date1 = new Date(sel_date);
        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;
        }
        var bD=objFromDate.split("/");
        now = new Date();

        if(bD.length==3){
            born = new Date(bD[2], bD[1]*1-1, bD[0]);
            years = new Date(now.getTime() - born.getTime());
            base = new Date(0);
            age = years.getFullYear()-base.getFullYear();
        }
        if((age > 100) || (age < 7)){
            alert(" Applicant age too high or too low!  Please provide accurate date of birth.");
            document.getElementById('date').focus();
            return false;
        }
        document.getElementById('setDate').value = sel_date;
    }
    if(LTrim(document.getElementById('email').value) != "")
    {
        var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
        var email = LTrim(document.getElementById('email').value);
        if(reg.test(email) == false) {
            alert('Please eneter valid Email Address');
            document.getElementById('email').focus();
            return false;
        }
        if(LTrim(document.getElementById('confirm_email').value) == ""){
            alert("Please Enter Confirm Email");
            document.getElementById('confirm_email').focus();
            return false;
        }
        if(LTrim(document.getElementById('email').value) != LTrim(document.getElementById('confirm_email').value)){
            alert('Email and Confirm Email not match');
            document.getElementById('email').focus();
            return false;
        }
    }else{
        if(LTrim(document.getElementById('confirm_email').value) != ""){
            alert("Please Enter Email");
            document.getElementById('email').focus();
            return false;
        }
    }

    if(LTrim(document.getElementById('address').value) == ""){
        alert("Please Enter Address");
        document.getElementById('address').focus();
        return false;
    }
    if(LTrim(document.getElementById('town').value) == ""){
        alert("Please Enter Town");
        document.getElementById('town').focus();
        return false;
    }
    var count = document.getElementById('pcountry').value;
    if(count == ""){
        alert("Please Select Postal Country ");
        return false;
    }else if(count == "NG")
    {
        if(document.getElementById('state').value == "")
        {
            //document.getElementById('error').innerHTML="<font color='red'>State is not Empty</font>";
            alert("Please Select Postal State");
            return false;
        }
    }else{
        if(LTrim(document.getElementById('otherstate').value) == "")
        {
            alert("Please Select Postal State");
            return false;
        }
    }
    if(validateImage()){
        if(document.getElementById("shouldUpload")){
            document.getElementById("shouldUpload").value = "no";
            document.forms[0].target = "_self";
            document.forms[0].action = "save";
        }
    }else{
        return false;
    }
    if(document.getElementById('image_check')){
        if(!document.getElementById('image_check').checked)
        {
            alert("Please check to confirm the image");
            return false;
        }
    }



    /*   END CEMTP REGISTRATION VALIDATION      */

    /*   START NECO REGISTARTION VALIDATION      */
    if(frm.examState.value== 0){
        alert("Please Select Exam State");
        frm.examState.focus();
        return false;
    }
    if(frm.confirmExamState.value==''){
        alert("Please Confirm Exam State");
        frm.confirmExamState.focus();
        return false;
    }
    if(frm.examNeigh.value==''){
        alert("Please Select Neighborhood");
        frm.examNeigh.focus();
        return false;
    }

    if((document.getElementById('examState').options[document.getElementById('examState').selectedIndex].text).toUpperCase() != (document.getElementById('confirmExamState').value).toUpperCase())
    {
        $('#examState').addClass("highlighter");
        alert("Exam State mis-match");
        document.getElementById('examState').focus();
        return false;
    }
    if(frm.confirmNeighborhood.value==''){
        alert("Please Confirm Neighborhood");
        frm.confirmNeighborhood.focus();
        return false;
    }

    if((document.getElementById('examNeigh').options[document.getElementById('examNeigh').selectedIndex].text).toUpperCase() != (document.getElementById('confirmNeighborhood').value).toUpperCase())
    {
        $('#examNeigh').addClass("highlighter");
        alert("Exam Neighborhood mis-match");
        document.getElementById('examNeigh').focus();
        return false;
    }


    var inputRefArray = frm.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 && inputRef.id != 'image_check' && inputRef.id != 'personal_info_check')
                ++countCh;
        }
    }

    if(countCh < 5 || countCh > 9 ){
        alert("Please select minimum of 5 Subjects (including english) OR maximum of 9 Subjects (including english)");
        document.getElementById('subbtn').style.display = 'block';
        return false;
    }
    if(document.getElementById('personal_info_check').checked == true){
        return confirmation();

    }else{
        alert('Please select confirmation checkbox ');
        return false;
    }

/*   END NECO REGISTARTION VALIDATION      */

}

function validateImage()
{
    var file = $('#image').val();
    var file_ext = "";
    if(file!=""){
        if(file.lastIndexOf(".jpg") == -1){
            if(file.lastIndexOf(".JPG") == -1){
                if(file.lastIndexOf(".jpeg") == -1){
                    if(file.lastIndexOf(".JPEG") == -1){
                        file_ext = "";
                    }else{
                        file_ext = "JPEG";
                    }
                }else{
                    file_ext = "jpeg";
                }
            }else{
                file_ext = "JPG";
            }
        }else{
            file_ext = "jpg";
        }
    }else{
        alert('Please upload Image');
        $('#image').focus();
        return false;
    }
    if(file != "" && (file_ext=="jpg" || file_ext=="JPG" || file_ext=="jpeg" || file_ext=="JPEG"))
    {
        return true;
    }
    else
    {
        alert('Please upload JPG or JPEG file only');
        document.getElementById('image').focus();
        return false;
    }
}

function confirmation(){
    var callopen = openPreviewWindow();
    browserDisable();
    if (callopen){
        $("#subbtn").attr('disabled', true);
        return true;
    } else {
        return false;
    }

    return true;
}