var lgaUrl = 'http://'+location.host+'/lga/';
var stateUrl = 'http://'+location.host+'/state/';
var courseUrl = 'http://'+location.host+'/course/';

isIE =  $.browser.msie;
ieVersion = jQuery.browser.version ;
ie6DisableFormElements = false;

$(document).ready(function(){isIE =  $.browser.msie;
ieVersion = jQuery.browser.version ;
ie6DisableFormElements = false;
  $(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';
  }
}
/* @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 Seller");
    document.getElementById('bankname').focus();
    return false;
  }
  if(trim(document.getElementById('branch').value) == "")
  {
    alert("Please Enter Selling Point 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);
}



function niceTrim(testStr) {
  var strnew = trim(testStr);

  alert(strnew.toString().length);

  return strnew.toString().length;
}

// 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 Seller ");
    document.getElementById('bank_name').focus();
    return false;
  }

  if(document.getElementById('branch_name').value == "")
  {
    alert("Please select Selling Point ");
    document.getElementById('branch_name').focus();
    return false;
  }

  if((document.getElementById('pin_range') != undefined && document.getElementById('pin_range').value == ""))
  {
    alert("Please select  Range");
    document.getElementById('pin_range').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 Seller.');
    document.getElementById('bank_name').focus();
    return false;
  }
  if(document.getElementById('branch_name').value=='')
  {
    alert('Please select Selling Point.');
    document.getElementById('branch_name').focus();
    return false;
  }
}
/*
 *  Created By Uday Prakash
 */

/* for Cemp Registration */

$(document).ready(function()
{
  try{
    $("#country").change(function()
    {

$('#localgovt').find('option').remove().end().append('<option value="">-- Please Select --</option>').val('whatever');
//      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';
        $("#loader").show();
        $.get(url, {
        }, function (data){
            $("#stateoforigin").html(data);
            $("#loader").hide();
           });

      }
    });

    // 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').val('');
      //$('#localgovt').val('');

      //$('#stateoforigin').attr('disabled','disabled');
      //$('#localgovt').attr('disabled','disabled');
    //}else{
      //$('#stateoforigin').removeAttr('disabled');
      //$('#localgovt').removeAttr('disabled');

	// issue fix for edit reg.
      var country = $('#country').val();
     if(country != "" && country != null && $("#stateoforigin").val()== '' && $("#stateoforigin").val()== null ){   //    var url = "GetState/";
      var url = stateUrl+country+'.html';
        $("#loader").show();
        $.get(url, {
        }, function (data){
            $("#stateoforigin").html(data);
            $("#loader").hide();
           });

//      $("#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();
  $.get(url, {
    id: inst
  },function (data){
     $(pid).html(data);
    $("#loader").hide();
  });
  if(pid == '#examtown')
    $(pid).width(244);
  else
    $(pid).width(400);

}

function getLoadCourse(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 = courseUrl+inst+".html";
  $("#loader").show();
  $.get(url, {
  },function (data){
     $(pid).html(data);
    $("#loader").hide();
  });
  if(pid == '#examtown')
    $(pid).width(244);
  else
    $(pid).width(400);

}


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 saveRegInfo()
{
  // if only registration form is displayed
  if ($("#saveUserOnly").val() != undefined)
  {
    // validate provided information in user details box (username and password)
    return validateUserNamePasswordBox(true);
  }
}

var validateRegistration = true;
var regxspace =  /^[\s]/;
function validateUserNamePasswordBox(validateFlag)
{
  if ($("#username").val() == "")
  {
    alert("Username cannot be left blank");
    document.getElementById('username').focus();
    return false;
  }else if($("#username").val().length < 6){
    alert("Username should contain minimum 6 characters");
    document.getElementById('username').focus();
    return false;
  }
  if (($("#pass").val()).match(regxspace))
  {
    alert("Spaces are not allowed");
    $("#pass").val("");
    $("#pass").focus();
     return false;
  }
  if (trim($("#pass").val()) == "")
  {
    alert("Password cannot be left blank");
    document.getElementById('pass').focus();
    return false;
  }else if($("#pass").val().length < 6){
    alert("Password should contain minimum 6 characters");
    document.getElementById('pass').focus();
    return false;

  }
if (($("#cpass").val()).match(regxspace))
  {
    alert("Spaces are not allowed");
    $("#cpass").val("");
    $("#cpass").focus();
     return false;
  }
  if (trim($("#cpass").val()) == "")
  {
    alert("Confirm password cannot be left blank");
    document.getElementById('cpass').focus();
    return false;
  }else if($("#cpass").val().length < 6){
    alert("Confirm password should contain minimum 6 characters");
    document.getElementById('cpass').focus();
    return false;
  }

  if(trim($("#pass").val()).toUpperCase() != trim($("#cpass").val()).toUpperCase())
  {
    alert("The typed password are not same, please try again");
    return false;
  }

  //var dateReg = "/^[0-9]{4,4}[-][0-1]{1,2}?[0-9]{1,2}[-][0-3]{1,2}?[0-9]{1,2}$/";
//  var dob = $('#date').val();
//  alert(dob);
//  st_date = new Date(dob.split('/')[2],dob.split('/')[0],dob.split('/')[1]);
//  //alert(dob.split('/')[2]);
//  end_date = new Date('1998','10','10');
//
//  if(trim($('#date').val()) == ""){
//    alert("Check your Date of Birth");
//    document.getElementById('date').focus();
//    return false;
//  }else if(dob.split('/')[2] >= 1998){ //if(st_date.getTime() > end_date.getTime() ){ //if(dob.match(/^[0-9]{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])/)){//if(dateReg.test(trim($('#date').val()))){
//    alert("Date of birth year should be less than 1998");
//    return false;
//  }


  if (!isDate($("#date_month").val()+'/'+$("#date_day").val()+'/'+$("#date_year").val()))
  {
     return false;
  }
  else
  {
      if($("#date_year").val() == '1998') {
        if ($("#date_month").val() > 9)
        {
           alert("You must be 12 years old to appear for JAMB examination");
           return false;
        }
      }
  }


  if (validateFlag == false)
  {
    validateRegistration = false;
  }
  else
  {
    validateRegistration = true;
  }

  return true;
}




    /**
     * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
     */
    // Declaring valid date character, minimum year and maximum year
    var dtCh= "/";
    var minYear=1900;
    var maxYear=2100;

    function isInteger(s){
        var i;
        for (i = 0; i < s.length; i++){
            // Check that current character is number.
            var c = s.charAt(i);
            if (((c < "0") || (c > "9"))) return false;
        }
        // All characters are numbers.
        return true;
    }

    function stripCharsInBag(s, bag){
        var i;
        var returnString = "";
        // Search through string's characters one by one.
        // If character is not in bag, append to returnString.
        for (i = 0; i < s.length; i++){
            var c = s.charAt(i);
            if (bag.indexOf(c) == -1) returnString += c;
        }
        return returnString;
    }

    function daysInFebruary (year){
        // February has 29 days in any year evenly divisible by four,
        // EXCEPT for centurial years which are not also divisible by 400.
        return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
    }
    function DaysArray(n) {
        for (var i = 1; i <= n; i++) {
            this[i] = 31
            if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
            if (i==2) {this[i] = 29}
       }
       return this
    }

    function isDate(dtStr){
        var daysInMonth = DaysArray(12)
        var pos1=dtStr.indexOf(dtCh)
        var pos2=dtStr.indexOf(dtCh,pos1+1)
        var strMonth=dtStr.substring(0,pos1)
        var strDay=dtStr.substring(pos1+1,pos2)
        var strYear=dtStr.substring(pos2+1)
        strYr=strYear
        if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
        if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
        for (var i = 1; i <= 3; i++) {
            if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
        }
        month=parseInt(strMonth)
        day=parseInt(strDay)
        year=parseInt(strYr)
        if (pos1==-1 || pos2==-1){
            alert("The date format should be : mm/dd/yyyy")
            return false
        }
        if (strMonth.length<1 || month<1 || month>12){
            alert("Please enter a valid month")
            return false
        }
        if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
            alert("Please enter a valid date")
            return false
        }
        if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
            alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
            return false
        }
        if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
            alert("Please enter a valid date")
            return false
        }
     return true
    }




///

 function validateCheck(frm) {

  if (shouldSubmitRegForm == false)
  {
    alert("The selected username is not available, please select another.");
    return false;
  }


  if (validateRegistration == false)
  {
    $("#saveRegistration").val("no");
    $("#saveUserOnly").attr('disabled', true);
    $("#cancel").attr('disabled', true);
    return true;
  }

  $('.highlighter').removeClass("highlighter");
  if (frm.regId.value == "") {
    if (!ValidForm())
    {
      return false;
    }
  }

//alert(frm.adminsupport.value);
//return false;
//  if(frm.adminsupport.value != ""){
//    if (!validateCheck(frm))
//    {
//      return false;
//    }
//  }

//  if (frm.regId.value == "") {
//    if (!ValidForm())
//    {
//      return false;
//    }
//  }

  //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('confirmTown').value == ""){
       $('#confirmTown').addClass("highlighter");
       alert("Please Confirm examination town");
       document.getElementById('confirmTown').focus();
       return false;
    }

    if((document.getElementById('examtown').options[document.getElementById('examtown').selectedIndex].text).toUpperCase() != (document.getElementById('confirmTown').value).toUpperCase())
    {
      $('#examtown').addClass("highlighter");
      alert("Examination town mis-match");
      document.getElementById('examtown').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 minimum 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 ;
        }
      }
    }
  }


  // open preview window
  // If new registration open preview window
  if(frm.regId.value == ""){

      var callopen = openPreviewWindow();
      browserDisable();

    if (callopen)
    {
        $("#save").attr('disabled', true);
        $("#cancel").attr('disabled', true);
        return true;
    }
    else
    {
        return false;
    }
  }

 return true;
}

var shouldSubmitRegForm = true;
$(document).ready(function()
{
  $("#username").focus();
  $("#username").blur(function()
  {
    $("#error").html('');
    if (($("#username").val() == ""))
    {
        return false;
    }

    $("#error").html('Checking user in database');
    $.get("checkUniqueUser", {
      username: $("#username").val()
      }, function (data) {
      if (data == 'false') {
        $("#error").html('<font color=green>Congratulations!! the username is available</font>');
        shouldSubmitRegForm = true;
      }
      else
      {
        $("#error").html('<font color="red">We are sorry the selected username is not available please choose another</font>');
        shouldSubmitRegForm = 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 && inputRef.id != 'image_check')
        ++countCh;
    }
  }
  if(countCh > 4){
    return false;
  }
  return true;
}

/* end of code */


//For state

var regxalpha =  /^[A-Za-z]+$/;
var postal_regxalpha =  /^[A-Za-z0-9]+$/;
var add = /^[A-Za-z0-9-\s,\/]+$/
function ValidForm()
{
  var regexp = /^[0-9]+$/;
  if(document.getElementById("shouldUpload")){
    document.getElementById("shouldUpload").value = "no";
    document.forms[0].target = "_self";
    document.forms[0].action = "saveReg";
  }

  //added on 9 september 2009
  if(trim(document.getElementById('fname').value) == ""){
    alert("First name cannot be left blank");
    document.getElementById('fname').value = "";
    document.getElementById('fname').focus();
    return false;
  }
  if(!(document.getElementById('fname').value).match(regxalpha)){
    alert("Special characters are not allowed in first name");
    document.getElementById('fname').value = "";
    document.getElementById('fname').focus();
    return false;
  }
  if(document.getElementById('mname').value != "" && !(document.getElementById('mname').value).match(regxalpha)){
    alert("Special characters are not allowed in middle name");
    document.getElementById('mname').value = "";
    document.getElementById('mname').focus();
    return false;
  }
  if(trim(document.getElementById('snamae').value) == ""){
    alert("Surname cannot be left blank");
    document.getElementById('snamae').value = "";
    document.getElementById('snamae').focus();
    return false;
  }
   if(!(document.getElementById('snamae').value).match(regxalpha)){
    alert("Special characters are not allowed in sur name");
    document.getElementById('snamae').value = "";
    document.getElementById('snamae').focus();
    return false;
  }
  var pattern = /^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;

    if(document.getElementById('email').value != "" && !(document.getElementById('email').value).match(pattern)){
      alert("please enter valid e-mail address");
      document.getElementById('email').value = "";
      document.getElementById('email').focus();
      return false;
    }
  if(document.getElementById('sex').value == ""){
    alert("Please select Sex");
    document.getElementById('sex').focus();
    return false;
  }
   if(trim(document.getElementById('gsmno').value) == ""){
    alert("GSM no. cannot be left blank");
     document.getElementById('gsmno').value = "";
    document.getElementById('gsmno').focus();
    return false;
  }

    if(!(document.getElementById('gsmno').value).match(regexp))
    {
      alert('Please enter only numeric values in GSM No.');
      document.getElementById('gsmno').value = "";
      document.getElementById('gsmno').focus();
      return false;
    }
    if((document.getElementById('gsmno').value).match(regexp) && document.getElementById('gsmno').value.length < 9 ){
        alert('Please enter valid GSM No.');
        document.getElementById('gsmno').value = "";
        document.getElementById('gsmno').focus();
        return false;
    }
  //end of code on 9 september 2009

  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(trim(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(alltrim(document.getElementById('town').value) == ""){
    alert("Town cannot be left blank");
    document.getElementById('town').value = "";
    document.getElementById('town').focus();
    return false;
  }
 if(!(document.getElementById('town').value).match(add)){
    alert("Please use only AlphaNumerics in town , / - characters");
    document.getElementById('town').value = "";
    document.getElementById('town').focus();
    return false;
  }

  if(alltrim(document.getElementById('address').value) == ""){
    alert("Address cannot be left blank");
    document.getElementById('address').value = "";
    document.getElementById('address').focus();
    return false;
  }

  function alltrim(str) {
    return str.replace(/^\s+|\s+$/g, '');
  }



 if(!(document.getElementById('address').value).match(add)){
    alert("Please use only AlphaNumerics in address , / - characters");
    document.getElementById('address').value = "";
    document.getElementById('address').focus();
    return false;
  }

  if(document.getElementById('postalcode').value != "" && !(document.getElementById('postalcode').value).match(postal_regxalpha)){
    alert("Special characters are not allowed in postalcode");
    document.getElementById('postalcode').value = "";
    document.getElementById('postalcode').focus();
    return false;
  }

     if( document.getElementById('country').value == "" ){
      $('#country').addClass("highlighter");
      alert("You must select a country of origin");
      return false;
    }

    if( document.getElementById('stateoforigin').value == "" ){
      $('#stateoforigin').addClass("highlighter");
      alert("You must select a state of origin");
      return false;
    }

    if(  document.getElementById('localgovt').value == "" ){
      $('#localgovt').addClass("highlighter");
      alert("You must select a Local Government");
      return false;
    }

  //Added on 9 sep 2009
  //  if(document.getElementById('username').value == ""){
  //    alert("Username cannot be left blank");
  //    document.getElementById('username').focus();
  //    return false;
  //  }
  //
  //  if(document.getElementById('pass').value == ""){
  //    alert("Password cannot be left blank");
  //    document.getElementById('pass').focus();
  //    return false;
  //  }
  //
  //  if(document.getElementById('cpass').value == ""){
  //    alert("Confirm password cannot be left blank");
  //    document.getElementById('cpass').focus();
  //    return false;
  //  }
  //
  //  if((document.getElementById('pass').value).toUpperCase() != (document.getElementById('cpass').value).toUpperCase())
  //  {
  //    alert("Please Confirm the password");
  //    return false;
  //  }

  //End of code
  var filePath = document.getElementById('file-info').src.toString();
  if(document.getElementById('image').value == "" || filePath.indexOf('passport_pic') < 0){
    alert("Please upload a image");
    return false;
  }else
  {
    var imagePath = document.getElementById('image').value; //document.FormTwo.picFile.value;
    var pathLength = imagePath.length;
    var lastDot = imagePath.lastIndexOf(".");
    var fileType = imagePath.substring(lastDot,pathLength).toUpperCase();
    if((fileType == ".JPEG") || (fileType == ".JPG")) {
      if(document.getElementById('image_check')){
        if(document.getElementById('image_check').checked)
        {
          return true;
        }else{
          alert("Please check to confirm the image");
          return false;
        }
        return true;
      }
//      return true;
    }else{
      alert("We support .JPEG and .JPG image format only. Your file-type is " + fileType + ".");
      return false;

    }

  }

}

function CempProfileValidForm(frm)
{
  var regexp = /^[0-9]+$/;
  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 == "")
    {
      alert("Postal state cannot be left blank");
      return false;
    }
  }else{
    if(document.getElementById('otherstate').value == "")
    {
      alert("Postal state cannot be left blank");
      return false;
    }
  }


 if (!validateCheck(frm))
    {
      return false;
    }
  return true;
}

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 ------------------------------------------------------
// add 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


// Added 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")
