// Copyright 2005-2009 JIC Design - All Rights Reserved 
// Redistribution and use in source and binary forms, with or without
// modification, are not permitted.By reading this documentation you agree
// to be bound by the terms and conditions set out in our license agreement.

String.prototype.trim = function ()
{
   return this.replace(/^\s+|\s+$/g, '') ;
}

function removeSpaces(string) {
 return string.split(' ').join('');
}

//AJAX Code
function createClient() {
 try {
  client = window.XMLHttpRequest ? new XMLHttpRequest() : 
   new ActiveXObject("Microsoft.XMLHTTP");
 } catch (e) { 
  alert("Sorry, your browser is not AJAX-enabled!"); 
 }
}

function genericUpdate(receiverid, script, query) {
 client.onreadystatechange = function() { callback_genericUpdate(receiverid); };
 client.open('GET',script+"?"+query,true); 
 client.send(null);
}
 
function callback_genericUpdate(receiverid)
{
   if(client.readyState == 1)
   {
      document.getElementById(receiverid).innerHTML = "<img src=/images/ajax-loader.gif align=center>";
   }
   if (client.readyState == 4) 
   {
      if (client.status == 200) 
      {
         document.getElementById(receiverid).innerHTML = client.responseText;
         //if(typeof window.tb_reinit == 'function') {
            // function exists, so we can now call it
            //tb_reinit('a.thickbox');
         //}
      }
      else 
      {
         document.getElementById(receiverid).innerHTML = 'There was a problem with the request.';
      }
      createClient();
   }
}
//END AJAX Code



function getSchoolYearList()
{
   var schoolyearlist = new Ext.data.JsonStore({
        totalProperty: 'total',
        root: 'results',
        fields : [
            {
                name: 'schoolyearname'
            },
            {
                name: 'schoolyearid'
            }
        ],
        url : '/admin/php/get-schoolyearlist.php',
        autoLoad: true
    });
   return schoolyearlist;
}

/** Core functions */
var browserType;
if (document.layers) {browserType = "nn4"}
if (document.all) {browserType = "ie"}
if (window.navigator.userAgent.toLowerCase().match("gecko")) {
   browserType= "gecko"
}

function hide(divname) {
  if (browserType == "gecko" )
  {
     document.poppedLayer = eval('document.getElementById(divname)');
     document.getElementById(divname).style.display = 'none';
  }
  else if (browserType == "ie")
     document.poppedLayer = eval('document.getElementById(divname)');
  else
     document.poppedLayer = eval('document.layers[divname]');
  document.poppedLayer.style.visibility = "hidden";
}

function show(divname) {
  if (browserType == "gecko" )
  {
     document.poppedLayer = eval('document.getElementById(divname)');
     document.getElementById(divname).style.display = 'inline'; 
  }
  else if (browserType == "ie")
     document.poppedLayer = eval('document.getElementById(divname)');
  else
     document.poppedLayer = eval('document.layers[divname]');         
     document.poppedLayer.style.visibility = "visible";
}


function zeroPad(num,count)
{
  var numZeropad = num + '';
  while(numZeropad.length < count) {
    numZeropad = "0" + numZeropad;
  }
  return numZeropad;
}

function capitalizeFirstLetter(string)
{
  return string.charAt(0).toUpperCase() + string.slice(1);
}





/** Student info related functions */
function setBirthProvince ()
{
   if (document.getElementById("birthcountry").value != 'Canada')
   {
      document.getElementById("birthprovinceother").selected = true;
   }
}

function checkArrivalDate()
{
   if ((document.getElementById("birthcountry").value != 'Canada') ||  (document.getElementById("citizenship").value != 'Canada'))
   {
      show('divcitizenship');
   }
   else if ((document.getElementById("birthcountry").value == 'Canada') &&  (document.getElementById("citizenship").value == 'Canada'))
   {
      hide('divcitizenship');
   }  
}