var bName=navigator.appName;
var bVer=parseInt(navigator.appVersion);
var platform=navigator.platform.substr(0,3);

var redirect='';

// If user OS is Windows
if (platform=="Win") {
	//Netscape
	if ((bName=="Netscape") && (bVer<=4)) {
		document.write("<link href='" + redirect+ "/css/style_pcie.css' rel='styleSheet' type='text/css'>");
		document.write("<link href='" + redirect+ "/css/styles.css' rel='styleSheet' type='text/css'>");
	}
	else if ((bName=="Netscape") && (bVer>4)) {
		document.write("<link href='" + redirect+ "/css/style_pcie.css' rel='styleSheet' type='text/css'>");
		document.write("<link href='" + redirect+ "/css/styles.css' rel='styleSheet' type='text/css'>");
	//MSIE4
	} else {
		document.write("<link href='" + redirect+ "/css/style_pcie.css' rel='styleSheet' type='text/css'>");
		document.write("<link href='" + redirect+ "/css/styles.css' rel='styleSheet' type='text/css'>");
	}
// If user OS is Mac
} else if (platform=="Mac") {
	//Netscape
	if ((bName=="Netscape") && (bVer>=4)) {
		document.write("<link href='/css/style_pcnn.css' rel='styleSheet' type='text/css'>");
		document.write("<link href='" + redirect+ "/css/styles.css' rel='styleSheet' type='text/css'>");
	}
	//MSIE
	else {
		document.write("<link href='/css/style_pcie.css' rel='styleSheet' type='text/css'>");
		document.write("<link href='" + redirect+ "/css/styles.css' rel='styleSheet' type='text/css'>");
	}
}

// function for auto tabbing through fields
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) 
{
  var keyCode = (isNN) ? e.which : e.keyCode; 
  var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
  if(input.value.length >= len && !containsElement(filter,keyCode)) 
  {
    input.value = input.value.slice(0, len);
    input.form[(getIndex(input)+1) % input.form.length].focus();
  }
  
  function containsElement(arr, ele) 
  {
    var found = false, index = 0;
    while(!found && index < arr.length)
      if(arr[index] == ele)
        found = true;
      else
        index++;
    return found;
   }
   
  function getIndex(input) 
  {
    var index = -1, i = 0, found = false;
    while (i < input.form.length && index == -1)
    if (input.form[i] == input)index = i;
    else i++;
    return index;
  }
  return true;
}
//  End -->


var reInteger = /^\d+$/


var daysInMonth = makeArray(12);
daysInMonth[1] = 31;
daysInMonth[2] = 29;   // must programmatically check this
daysInMonth[3] = 31;
daysInMonth[4] = 30;
daysInMonth[5] = 31;
daysInMonth[6] = 30;
daysInMonth[7] = 31;
daysInMonth[8] = 31;
daysInMonth[9] = 30;
daysInMonth[10] = 31;
daysInMonth[11] = 30;
daysInMonth[12] = 31;

function makeArray(n) {
   for (var i = 1; i <= n; i++) {
      this[i] = 0;
   } 
   return this;
}

function popUp(url, wd, ht, scroll, tool, winname, xloc, yloc){
    if (!xloc) xloc="0";
    if (!yloc) yloc="0";
	if (!winname) winname="popUp";
	popupwin_handle= window.open(url,winname,'height='+ht+',width='+wd+',status=yes,scrollbars='+scroll+',toolbar='+tool+',resizable=yes,menubar=no,location=no,screenx='+xloc+',screeny='+yloc+',left='+xloc+',top='+yloc+'');
	popupwin_handle.focus();
}

function isDate (year, month, day){   
    if (! (isYear(year, false) && isMonth(month, false))) return false;
    var intYear = parseInt(year);
    var intMonth = parseInt(month);
    var intDay = parseInt(day);

    // catch invalid days, except for February
    if (intDay > daysInMonth[intMonth]) return false; 

    if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) return false;

    return true;
}

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 isDay (s){ 
    if (isEmpty(s)) 
        return (isDay.arguments[1] == true);   
    return isIntegerInRange (s, 1, 31);
}

function isMonth (s){   
    if (isEmpty(s)) 
       if (isMonth.arguments.length == 1) return false;
       else return (isMonth.arguments[1] == true);
    return isIntegerInRange (s, 1, 12);
}

function isYear (s){ 
    if (isEmpty(s)) 
       if (isYear.arguments.length == 1) return false;
       else return (isYear.arguments[1] == true);
    if (!isNonnegativeInteger(s)) return false;
    return ((s.length == 2) || (s.length == 4));
}

function isIntegerInRange (s, a, b)
{   if (isEmpty(s)) 
       if (isIntegerInRange.arguments.length == 1) return false;
       else return (isIntegerInRange.arguments[1] == true);

    if (!isInteger(s, false)) return false;
    
    var num = parseInt (s);
    return ((num >= a) && (num <= b));
}

function isInteger (s)

{   var i;

    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return false;
       else return (isInteger.arguments[1] == true);

    return reInteger.test(s)
}

function isNonnegativeInteger (s)
{   var secondArg = false;

    if (isNonnegativeInteger.arguments.length > 1)
        secondArg = isNonnegativeInteger.arguments[1];


    return (isSignedInteger(s, secondArg)
         && ( (isEmpty(s) && secondArg)  || (parseInt (s) >= 0) ) );
}

function isSignedInteger (s)

{   if (isEmpty(s)) 
       if (isSignedInteger.arguments.length == 1) return false;
       else return (isSignedInteger.arguments[1] == true);

    
    else {
       return true;
    }
}

function isPositiveInteger (s)
{   var secondArg = false;

    if (isPositiveInteger.arguments.length > 1)
        secondArg = isPositiveInteger.arguments[1];

    return (isSignedInteger(s, secondArg)
         && ( (isEmpty(s) && secondArg)  || (parseInt (s) > 0) ) );
}

function isNegativeInteger (s)
{   var secondArg = false;

    if (isNegativeInteger.arguments.length > 1)
        secondArg = isNegativeInteger.arguments[1];

    return (isSignedInteger(s, secondArg)
         && ( (isEmpty(s) && secondArg)  || (parseInt (s) < 0) ) );
}

function isNonpositiveInteger (s)
{   var secondArg = false;

    if (isNonpositiveInteger.arguments.length > 1)
        secondArg = isNonpositiveInteger.arguments[1];

    return (isSignedInteger(s, secondArg)
         && ( (isEmpty(s) && secondArg)  || (parseInt (s) <= 0) ) );
}

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

function disable(elem) { // elem: form element to be disabled
  elem.onfocus=elem.blur;
}
function enable(elem) { // elem: form element to be reenabled
  elem.onfocus=null;
}

redirect='';
subdirectory='';
