var preloadFlag = false;
var ie  = (navigator.appName.toLowerCase().indexOf('microsoft') != -1);
var ns  = (navigator.appName.toLowerCase().indexOf('netscape') != -1);
var win = (navigator.platform.toLowerCase().indexOf('win') != -1);
var mac = (navigator.platform.toLowerCase().indexOf('mac') != -1);
var browserVer = parseFloat(ie ? navigator.appVersion.substring(navigator.appVersion.toLowerCase().indexOf('msie') + 4) : navigator.appVersion);

function newImage(arg) {
   if (document.images) {
      rslt = new Image();
      rslt.src = arg;
      return rslt;
   }
}

function changeImages() {
   if (document.images && (preloadFlag == true)) {
      for (var i = 0; i < changeImages.arguments.length; i += 2) {
         document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
      }
   }
}

function getCookie(strname) {
   var c = document.cookie;
   var p = c.split(";");
   for(var i = 0; i < p.length; i++) {
      var a = p[i].split('=');
      while(a[0].charAt(0) == ' ') a[0] = a[0].substr(0);
      if(a[0] == strname && a.length > 1) return a[1];
   }
   return '';
}

function fieldIsEmpty(obj, strprompt) {
   var s = obj.value;
   if (s == '') {
      alert(strprompt);
      obj.focus();
      return true;
   }
   return false;
}

function validateEmail(str) {
   var re = new RegExp('^\\w+((-\\w+)|(\.\\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\\.[A-Za-z0-9]{2,}$');
   return re.test(str);
}

function isValidFormalName(str) {
   var re = new RegExp('^[A-Za-z][\\w_]*$');
   return re.test(str);
}

function popWindow(u, nwidth, nheight, bscroll) {
   var w, h, x, y, p;
   w = nwidth; h = nheight;
   if (ie && mac) { w -= 16; h -= 16; }
   x = (screen.availWidth - w)/2;
   y = (screen.availHeight - h)/2;
   p = 'resizable,left=' + x + ',top=' + y + ',width=' + w + ',height=' + h;
   if (bscroll) p += ',scrollbars';
   window.open(u, 'Propower', p);
}

function popPPWindow(u) {
   var w, h, x, y, p;
   var heightNeeded = 650;
   if (screen.availHeight >= heightNeeded) { w = 800; h = 600; } 
   else { w = 640; h = 480; }
   if (ie && mac) { w -= 16; h -= 16; }
   x = (screen.availWidth - w)/2;
   y = (screen.availHeight - h)/2;
   p = 'resizable,left=' + x + ',top=' + y + ',width=' + w + ',height=' + h;
   window.open(u, 'Propower', p);
}

function popIntroEnglishWindow(u, nwidth, nheight) {
   var w, h, x, y, p;
   w = nwidth; h = nheight;
   if (ie && mac) { w -= 16; h -= 16; }
   x = (screen.availWidth - w)/2;
   y = (screen.availHeight - h)/2;
   p = 'resizable,left=' + x + ',top=' + y + ',width=' + w + ',height=' + h;
   popwin = window.open(u, 'IntroductoryEnglish', p);
   popwin.focus();
}

var htmlpopwin;

function popScreenWithHtml(theFilepath,theTitle,w,h) {
   if (w == null) w = 800;
   if (h == null) h = 600;
   var aHtmlText = 
      '<html><head><title>' + 
      theTitle +
      '<\/title><\/head>' +
      '<body bgcolor=\"#000000\" leftmargin=\"0\" topmargin=\"0\" rightmargin=\"0\" bottommargin=\"0\" marginwidth=\"0\" marginheight=\"0\">' +
      '<img src=\"' + theFilepath + '\" width=\"' + w + '\" height=\"' + h + '\">' +
      '<\/body> <\/html>';
   if (ie && mac) { w -= 16; h -= 16; }
   x = (screen.availWidth - w)/2;
   y = (screen.availHeight - h)/2;
   p = 'resizable,left=' + x + ',top=' + y + ',width=' + w + ',height=' + h;
   htmlpopwin = window.open('', '_blank', p);
   htmlpopwin.document.write(aHtmlText);
   htmlpopwin.focus();
}

function tellafriend(s, b) {
   if (s == null) s = 'Page at EnglishElearning: ' + document.title;
   if (b == null) b = 'Check out this page: ' + document.location;
   location = 'mailto:?subject=' + s + '&body=' + b;
}

