User = {'id':0,'premium':0,'fname':'','lname':'','email':'','zip':''};
Term       = {};
Term.id    = '4f458881b1aae';
Term.ticks = 0;
//Term.site  = 'website';
Term.todo  = "";
Term.start = new Date().getTime();

DialogBox = {};

DialogBox.titleBarBackgroundColor = '#189CCE';
DialogBox.titleBarColor           = 'white';
DialogBox.titleBarFontFamily      = 'Arial,Helvetica,Sans-Serif';
DialogBox.titleBarFontSize        = '16px';
DialogBox.titleBarFontWeight      = 'bold';

DialogBox.alertColor              = 'black';
DialogBox.alertFontFamily         = 'Arial,Helvetica,Sans-Serif';
DialogBox.alertFontSize           = '16px';
DialogBox.alertFontWeight         = 'normal';

DialogBox.bgcolor                 = 'white';

DialogBox.closeIcon    = '/jobs-over-50/images/dialog/closeicon.gif';
DialogBox.waitImage    = '/jobs-over-50/images/dialog/wait2.gif';
DialogBox.overlayImage = '/jobs-over-50/images/dialog/overlay.png';

DialogBox.stack        = new Array();

DialogBox.ticking      = false;

DialogBox.tick = function() {

   if(DialogBox.stackSize() < 1) {
      DialogBox.ticking = false;
      return;
   }
   DialogBox.ticking = true;
   DialogBox.resize();
   setTimeout('DialogBox.tick()', 200);

}

DialogBox.box = function(width, height) {

   if(DialogBox.stack.length) {
      var data = DialogBox.stack[DialogBox.stack.length-1];
      data.ol.style.visibility = 'hidden';
   }

   DialogBox.hideThings(true);

   var box = document.createElement('div');
   box.style.zIndex     = (DialogBox.stack.length + 1) * 100;
   box.style.width      = width + 'px';
   box.style.height     = height + 'px';
   box.style.position   = 'fixed';
   box.style.display    = 'block';
   box.style.visibility = 'hidden';
   //box.style.top  = '0px';
   //box.style.left = '0px';
   box.className = 'dboxBox';

   box.style.top  = '50%';
   box.style.left = '50%';
   var mtop  = '-' + parseInt(height/2) + 'px';
   var mleft = '-' + parseInt(width/2) + 'px';
   box.style.marginTop  = mtop;
   box.style.marginLeft = mleft;


   box.style.background = 'url(/jobs-over-50/images/dombox-bg.gif) left bottom repeat-x';

   var container = document.getElementById('pageContainer');

   var ol = document.createElement('div');
   ol.style.zIndex = box.style.zIndex - 1;
   ol.style.position = 'absolute';
   ol.style.top    = '0px';
   ol.style.left   = '0px';

   //ol.style.width  = '100%';
   //ol.style.width  = (container.offsetWidth-40) + 'px';
   //ol.style.width  = (document.getElementsByTagName('body')[0]).offsetWidth + 'px';

   ol.style.width  = container.offsetWidth  + 'px';
   ol.style.height = container.offsetHeight + 'px';

   ol.style.backgroundRepeat = 'repeat';
   ol.style.display = 'block';

   if(DialogBox.isExplorer()) {
      ol.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader" +
                        "(src='" + DialogBox.overlayImage + "', sizingMethod='scale');}";
   } else { ol.style.backgroundImage = 'url(' + DialogBox.overlayImage + ')'; }

   var data = {};
   data.box    = box;
   data.ol     = ol;
   data.width  = width;
   data.height = height;

   DialogBox.stack.push(data);

   (document.getElementsByTagName('body')[0]).appendChild(ol);
   (document.getElementsByTagName('body')[0]).appendChild(box);

   return box;
}




DialogBox.close = function() {
   if(!DialogBox.stack.length) {
      DialogBox.hideThings(false);
      return;
   }
   var data = DialogBox.stack.pop();
 
   data.box.innerHTML = '';
   data.ol.innerHTML  = '';

   (document.getElementsByTagName('body')[0]).removeChild(data.box);
   (document.getElementsByTagName('body')[0]).removeChild(data.ol);

   if(!DialogBox.stack.length) {
      DialogBox.hideThings(false);
   } else {
      var data = DialogBox.stack[DialogBox.stack.length-1];
      data.ol.style.visibility = 'visible';
   }
}

DialogBox.closeAlert = function(id) {
   DialogBox.close();
   var el = document.getElementById(id);
   if(el) { el.focus(); }
}

DialogBox.resize = function() {
   return;
   if(!DialogBox.stackSize()) { return; }
   var container = document.getElementById('pageContainer');
   for(var i=0; i<DialogBox.stack.length; i++) {
      var data = DialogBox.stack[i];
      var top  = DialogBox.scrollTop();
      var left = DialogBox.scrollLeft();
      left  = ((DialogBox.pageWidth() - data.width)/2) + left + 'px';
      data.box.style.left = left;
      top   = ((DialogBox.pageHeight() - data.height)/2) + top + 'px';
      data.box.style.top = top;
      data.ol.style.width = container.offsetWidth + 'px';
      //data.ol.style.width = DialogBox.pageWidth() + 'px';
      //data.ol.style.width =
   }
}

DialogBox.titleBar = function(title, width, callback) {
   if(!callback) { callback = "DialogBox.close()"; }

   var style = '';
   style += "height:26px;";
   style += "width:" + width + "px;";
   style += "background-color:" + DialogBox.titleBarBackgroundColor + ";";
   style += "color:white;";
   style += "line-height:26px;";
   style += "padding-left:10px;";
   style += "padding-right:10px;";
   style += "font-weight:bold;";
   style += "font-family:Arial;";
   style += "font-size:16px;";
   style += "text-align:left;";
   style += "margin-bottom:0px;";

   var table = "";
   table += "<table style='" + style + "' cellpadding='0' cellspacing='0' border='0'><tr>";
   table += "<td align='left'>" + title + "</td>";
   table += "<td align='right'><img ";
   table += "onmouseover=\"this.style.cursor='pointer'\" ";
   table += "onclick=\"" + callback + "\" ";
   table += "src='" + DialogBox.closeIcon + "' /></td>";
   table += "</tr></table>";

   return table;
}

DialogBox.confirmBox = function(title, text, callbackYes, callbackNo) {
   if(!callbackYes) { callbackYes = 'DialogBox.close()'; }
   if(!callbackNo)  { callbackNo  = 'DialogBox.close()'; }
   if(!title)       { title       = 'Alert Message'; }

   var html = '';

   var fontMetrics = document.getElementById('font.metrics');
   if(!fontMetrics) {
      fontMetrics    = document.createElement('span');
      fontMetrics.id = 'font.metrics';
      fontMetrics.style.visibility = 'hidden';
      document.getElementsByTagName('body')[0].appendChild(fontMetrics);
   }
   fontMetrics.style.fontFamily = 'Trebuchet MS';
   fontMetrics.style.fontSize   = '24px';
   fontMetrics.innerHTML = 'notice: ' + title.toLowerCase();
   width = parseInt(fontMetrics.offsetWidth) + 75;
   fontMetrics.innerHTML = '';

   title = "<span class='headtxt'><span>notice: </span>" + title.toLowerCase() + "</span>";

   html += "<div class='dombox'>";
   html += title;
   html += "<div style='margin-top:10px;margin-bottom:20px;'><span class='domboxtxt'>" + text + "</span></div>";
   html += "<div>";
   html += "<input type='button' style='float:right;' class='domboxbutton' onclick=\"" + callbackNo + "\" value=' No ' /> ";
   html += "<input type='button' style='float:right;' class='domboxbutton' onclick=\"" + callbackYes + "\" value=' Yes ' /> ";
   html += "<div style='clear:both;'></div>";
   html += "</div>";

   height = DialogBox.getContentHeight(width, html);
   var box = DialogBox.box(width, height);
   box.style.backgroundColor = 'white';
   box.innerHTML = html;
   DialogBox.resize();

   box.style.display = 'none'; // added for fade.
   box.style.visibility = 'visible';

   $(box).css('filter', 'alpha(opacity=100)'); // added for fade.
   $(box).fadeIn(500); // added for fade.

   if(!DialogBox.ticking) { DialogBox.tick(); }












   /*
   var width = Term.getStringWidth(title, '') + 150;
   if(width < 300) { width = 300; }

   var html = '';

   html += "<div class='dboxTitleBar' style='line-height:35px;height:35px;width:100%;'>";
   html += "<div style='width:35px;height:35px;float:left;margin-right:20px;' class='dboxIcon'></div>";
   html += "<span class='dboxTitle'>" + title + "</span>";
   html += "</div>";

   html += "<div id='alertbox' style='padding:10px;'>";
   html += "<div class='dboxContent' style='margin-bottom:20px;'>" + text + "</div>";
   html += "<div style='text-align:right;'>"
   html += "<button class='dboxButton' id='confirmBoxYes' onclick=\"" +  callbackYes + "\">Yes</button>\n";
   html += "<button class='dboxButton' id='confirmBoxNo' onclick=\"" +  callbackNo + "\">No</button>\n";
   html += "</div>";
   html += "</div>";

   DialogBox.domBox(width, html);
   */
}


DialogBox.alertBox = function(text, callback, title, width, height, focus) {

   if(!callback) { callback = 'DialogBox.close()'; }
   if(!title)    { title    = 'Alert Message'; }
   if(!width)    { width    = 350;  }
   if(!height)   { height   = 125; }

   var html = '';

   var fontMetrics = document.getElementById('font.metrics');
   if(!fontMetrics) {
      fontMetrics    = document.createElement('span');
      fontMetrics.id = 'font.metrics';
      fontMetrics.style.visibility = 'hidden';
      document.getElementsByTagName('body')[0].appendChild(fontMetrics);
   }
   fontMetrics.style.fontFamily = 'Trebuchet MS';
   fontMetrics.style.fontSize   = '24px';
   fontMetrics.innerHTML = 'notice: ' + title.toLowerCase();
   width = parseInt(fontMetrics.offsetWidth) + 75;
   fontMetrics.innerHTML = '';
   
   title = "<span class='headtxt'><span>notice: </span>" + title.toLowerCase() + "</span>";

   html += "<div class='dombox'>";
   html += title;
   html += "<div style='margin-top:10px;margin-bottom:20px;'><span class='domboxtxt'>" + text + "</span></div>";
   //html += "<center><button class='domboxbutton' id='alertbox_close' onclick=\"" +  callback + "\">Close</button></center>";
   html += "<center><input type='button'  class='domboxbutton' id='alertbox_close' value=' Close ' onclick=\"" +  callback + "\" /></center>";
   html += "</div>";

   height = DialogBox.getContentHeight(width, html);

   var box = DialogBox.box(width, height);
   box.style.backgroundColor = 'white';
   box.innerHTML = html;
   DialogBox.resize();

   box.style.display = 'none'; // added for fade.

   box.style.visibility = 'visible';


   $(box).css('filter', 'alpha(opacity=100)'); // added for fade.
   $(box).fadeIn(500); // added for fade.

   if(!DialogBox.ticking) { DialogBox.tick(); }
}


/*
DialogBox.dialogBox = function(width, height, title, content, callback, bgcolor) {
   if(!width)    { width    = 300;  }
   if(!height)   { height   = 125; }
   if(!title)    { title    = 'Dialog Box'; }
   if(!content)  { content  = 'Dialog Box'; }
   if(!callback) { callback = 'DialogBox.close()'; }
   if(!bgcolor)  { bgcolor  = 'white'; }

   var box = DialogBox.box(width, height + 26);
   box.style.backgroundColor = bgcolor;

   content = content.replace(/^[ ]+/, '');
   content = content.replace(/[ ]+$/, '');

   box.innerHTML += DialogBox.titleBar(title, width, callback);
   box.innerHTML += content;

   DialogBox.resize();
   box.style.visibility = 'visible';
   if(!DialogBox.ticking) { DialogBox.tick(); }

   box.focus();
}
*/

/*
DialogBox.alertBox = function(text, callback, title, width, height, focus) {

   if(!callback) { callback = 'DialogBox.close()'; }
   if(!title)    { title    = 'Alert Message'; }
   if(!width)    { width    = 300;  }
   if(!height)   { height   = 125; }

   var style = '';
   style += 'height:'           + height + 'px' + ';';
   // Don't use this: style += 'width:'            + width + 'px' + ';';
   style += 'color:'            + DialogBox.alertColor + ';';
   style += 'font-family:'      + DialogBox.alertFontFamily + ';'
   style += 'font-weight:'      + DialogBox.alertFontWeight + ';';
   style += 'font-size:'        + DialogBox.alertFontSize   + ';';
   style += 'padding-left:'     + '10px' + ';';
   style += 'padding-right:'    + '10px' + ';';
   style += 'background-color:' + 'white' + ';';
   style += 'text-align:center;';
   style += 'padding-top:0px;';
   style += 'margin-top:0px;';
   style += 'padding-bottom:0px;';
   style += 'margin-bottom:0px;';


   var message = '';
   message += "<div style='" + style + "'>";
   message += "<br />" + text + "<br /><br />";
   message += "<button id='alertbox_close' onclick=\"" +  callback + "\">Close</button>";
   message += "</div>";

   DialogBox.dialogBox(width, height, title, message, callback);

   var closeButton = document.getElementById('alertbox_close');
       closeButton.focus();
}
*/

/*
DialogBox.squareBox = function(width, height, content, bgcolor) {
   var box = DialogBox.box(width, height);
   box.innerHTML = content;
   if(bgcolor) {
      box.style.backgroundColor = bgcolor;
   }
   DialogBox.resize();
   box.style.visibility = 'visible';
   if(!DialogBox.ticking) { DialogBox.tick(); }

}
*/

DialogBox.domFormBox = function(width, height, content, widgets) {

   if(typeof widgets == 'undefined') {
      widgets = {'checkbox' : true, 'radio' : true, 'text' : true};
   }

   height = 0;
   content = content.replace(/[ ]+$/, '');
   content = content.replace(/^[ ]+/, '');

   height  = DialogBox.getContentHeight(width, content);


/*
   checks = [];
   radios = [];
   boxes  = [];
   matches = content.match(/\<input[^>]+\>/g);
   for(var i=0; i<matches.length; i++) {
      var id = '';
      match = new RegExp("id=('|\")([^'\"]+)(\"|')","");
      match = match.exec(matches[i]);
      if(!match) { continue; }
      var id = match[2];
      if(matches[i].match(/type=('|")checkbox('|")/) && widgets['checkbox']) {
         checks[checks.length] = id;
         continue;
      }
      if(matches[i].match(/type=('|")radio('|")/) && widgets['radio']) {
         radios[radios.length] = id;
         continue;
      }
      if(matches[i].match(/type=('|")text('|")/) && widgets['text']) {
         boxes[boxes.length] = id;
      }
   }
*/


   var box = DialogBox.box(width, height);
   //box.style.backgroundColor = 'white';
   box.style.backgroundColor = '#F5F5F5';
   box.innerHTML = content;
   
   WidgetUtils.init();

   DialogBox.resize();
   box.style.display = 'none';  // added for fade.
   box.style.visibility = 'visible';

   $(box).css('filter', 'alpha(opacity=100)'); // added for fade.
   $(box).fadeIn(500); // added for fade.



    //$("input[type='radio'],input[type='checkbox']").custCheckBox();
    //$("input#jobseeker_newsletter").custCheckBox();

/*
    for(var i=0; i<checks.length; i++) {
       $("input#" + checks[i]).custCheckBox();
    }
    for(var i=0; i<radios.length; i++) {
       $("input#" + radios[i]).custCheckBox();
    }
    for(var i=0; i<boxes.length; i++) {
       $("input#" + boxes[i]).labelify({text: "label", labelledClass: "labelify"});
    }
*/


    //$("input#keyword, input#location, input#somename").labelify({text: "label", labelledClass: "labelify"});

/*
   $('.domboxtip').qtip({
                 show: {when: {event: 'focus'},
                 effect: {type: 'fade', length: 300}
                         },
                 hide: {when: {event: 'blur'}
                         },
                 position: { corner: {target: 'topMiddle', tooltip: 'bottomMiddle'}
                         },
         style: {width: 300,padding: 5, color: 'black', border: { width: 1, radius: 5, color:'#F8E98E'},
        corner: {target: 'topLeft', tooltip: 'topLeft'},
           tip: 'bottomMiddle',
          name: 'cream'
                         }
                 });
*/





   if(!DialogBox.ticking) { DialogBox.tick(); }

}


DialogBox.getStringWidth = function(html, style) {
   var fontMetrics = document.getElementById('font.metrics');
   if(!fontMetrics) {
      fontMetrics    = document.createElement('span');
      fontMetrics.id = 'font.metrics';
      fontMetrics.style.visibility = 'hidden';
      document.getElementsByTagName('body')[0].appendChild(fontMetrics);
   }
   fontMetrics.innerHTML = html;
   fontMetrics.className = style;
   var width = parseInt(fontMetrics.offsetWidth);
   fontMetrics.innerHTML = '';
   return width;
}

DialogBox.getContentHeight = function(width, content) {
   var height = 0;
   var div    = document.getElementById('content.height');
   if(!div) {
      div = document.createElement('div');
      div.id = 'content.height';
      div.style.display = 'none';
      div.style.visibility = 'hidden';
      div.style.overflow = 'scroll';
      (document.getElementsByTagName('body')[0]).appendChild(div);
   }
   div.style.width   = width + 'px';
   div.style.display = 'block';
   div.innerHTML = content;

   height = div.scrollHeight;

   /*
   if(document.defaultView) {
      //alert('using default view');
      height = parseInt(document.defaultView.getComputedStyle(div, null).getPropertyValue("height").replace(/px/, ''));
   } else if(div.clientHeight) {
      //height = div.clientHeight;
   } else if(div.offsetHeight) {
      //height = div.offsetHeight;
   }
   */

   div.style.display = 'none';

   /**
   Very important to do this below, or scripts using this content
   will get confused as to which version to use.
   */
   div.innerHTML     = '';

   //(document.getElementsByTagName('body')[0]).removeChild(div);

   return height;
}

DialogBox.getContentWidth = function(html, style) {
   var fontMetrics = document.getElementById('font_metrics');
   if(!fontMetrics) {
      fontMetrics    = document.createElement('span');
      fontMetrics.id = 'font_metrics';
      fontMetrics.style.visibility = 'hidden';
      document.getElementsByTagName('body')[0].appendChild(fontMetrics);
   }
   fontMetrics.innerHTML = html;
   fontMetrics.className = style;
   return parseInt(fontMetrics.offsetWidth);
}


/*
DialogBox.waitBox = function() {


   var content = '';
   //content += "<div style='border:1px solid black;background-color:white;' align='center'>";
   content += "<div style='text-align:center;'>";
   content += "<div style='color:#303030;margin-top:20px;margin-bottom:10px;'>One Moment Please...</div>";
   content += "<img style='margin-bottom:20px;' id='spinner' src='" + DialogBox.waitImage + "' />";
   content += "</div>";

   var width  = 200;
   var height = DialogBox.getContentHeight(width, content);
   var box = DialogBox.box(width, height);
   box.style.backgroundColor = 'white';
   box.innerHTML = content;
   DialogBox.resize();
   box.style.display = 'none'; // added for fade.
   box.style.visibility = 'visible';
   $(box).css('filter', 'alpha(opacity=100)'); // added for fade.
   $(box).fadeIn(500); // added for fade.


   if(!DialogBox.ticking) { DialogBox.tick(); }

   //(document.getElementById('spinner')).focus();
}
*/


DialogBox.waitBox = function() {

   var box = DialogBox.box(200, 50);
   DialogBox.resize();
   box.className = 'dboxWait';
   box.style.lineHeight = '50px';
   box.innerHTML = "One Moment Please ...";
   box.style.visibility = 'visible';
   if(!DialogBox.ticking) { DialogBox.tick(); }
}

DialogBox.stackSize = function() {
   return DialogBox.stack.length;
}

DialogBox.busy = function() {
   return DialogBox.stackSize() == 0 ? false : true;
}

DialogBox.closeAll = function() {
   while(DialogBox.stackSize()) {
      DialogBox.close();
   }
}

DialogBox.isExplorer = function() {
   var version = 0;
   if(navigator.appVersion.indexOf("MSIE")!=-1) {
      var temp = navigator.appVersion.split("MSIE");
      version = parseFloat(temp[1]);
      return version ? true : false;
   }
   return false;
}

DialogBox.scrollTop = function() {
   var pos = 0;
   if(window.pageYOffset) {
      pos = window.pageYOffset;
   } else if(document.documentElement && document.documentElement.scrollTop) {
      pos = document.documentElement.scrollTop;
   } else if(document.body) {
      pos = document.body.scrollTop;
   }
   return pos;
}

DialogBox.scrollLeft = function() {
   var pos = 0;
   if(window.pageXOffset) {
      pos = window.pageXOffset;
   } else if(document.documentElement && document.documentElement.scrollLeft) {
      pos = document.documentElement.scrollLeft;
   } else if(document.body) {
      pos = document.body.scrollLeft;
   }
   return pos;
}

DialogBox.pageWidth = function() {
   return window.innerWidth != null? window.innerWidth:
   document.documentElement && document.documentElement.clientWidth ?
   document.documentElement.clientWidth:document.body != null? document.body.clientWidth:null;
}

DialogBox.pageHeight = function() {
   return window.innerHeight != null? window.innerHeight:
   document.documentElement && document.documentElement.clientHeight ?
   document.documentElement.clientHeight:document.body != null? document.body.clientHeight:null;
}

DialogBox.hideThings = function(yorn) {

   //This fuction is only necessary for IE,
   //so return if it isn't.
   if(!document.all) { return; }

   var v = 'visible';
   if(yorn) { v = 'hidden'; }

   var tag=document.getElementsByTagName('select');
   for(i=tag.length-1;i>=0;i--) tag[i].style.visibility=v;

   tag=document.getElementsByTagName('iframe');
   for(i=tag.length-1;i>=0;i--)tag[i].style.visibility=v;


   tag=document.getElementsByTagName('object');
   for(i=tag.length-1;i>=0;i--)tag[i].style.visibility=v;

   tag=document.getElementsByTagName('embed');
   for(i=tag.length-1;i>=0;i--)tag[i].style.visibility=v;

}

CommonLib = {};

CommonLib.getRequestObject = function() {
   if(window.XMLHttpRequest) {
      return new XMLHttpRequest();
   }
   if(window.ActiveXObject) {
      try {
         return new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
         try {
            return new ActiveXObject("Microsoft.XMLHTTP");
         } catch (e) {}
      }
   }
   return null;
}

CommonLib.parseElement = function(xml, tag) {
   var start_tag = '<'  + tag + '>';
   var end_tag   = '</' + tag + '>';
   var start_index;
   var end_index;
   var content;
   if((start_index = xml.indexOf(start_tag)) < 0) { return ''; }
   if((end_index = xml.indexOf(end_tag)) < 0) { return ''; }
   content = xml.substring(start_index, end_index + end_tag.length);
   content = content.replace(start_tag, '');
   content = content.replace(end_tag, '');
   return content;
}

CommonLib.parseElements = function(xml, tag) {
   var elements   = new Array();
   var start_tag  = '<'  + tag + '>';
   var end_tag    = '</' + tag + '>';
   var element;
   var start_index;
   var end_index;
   while((start_index = xml.indexOf(start_tag)) >= 0) {
      end_index = xml.indexOf(end_tag);
      if(end_index < 0) { break; }
      element = xml.substring(start_index, end_index + end_tag.length);
      xml = xml.substring(end_index + end_tag.length, xml.length);
      elements[elements.length] = element;
   }
   return elements;
}

CommonLib.createCookie = function(name,value,days) {
   if(days) {
      var date = new Date();
      date.setTime(date.getTime()+(days*24*60*60*1000));
      var expires = '; expires=' + date.toGMTString();
   } else {
      var expires = "";
   }
   document.cookie = name + '=' + value + expires + '; path=/';
}

CommonLib.readCookie = function(name) {
   var nameEQ = name + "=";
   var ca = document.cookie.split(';');
   for(var i=0;i < ca.length;i++) {
      var c = ca[i];
      while (c.charAt(0)==' ') c = c.substring(1,c.length);
      if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
   }
   return null;
}

CommonLib.eraseCookie = function(name) {
   CommonLib.createCookie(name,"",-1);
}

CommonLib.isValidEmail = function(email) {
   return email.match(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/) ? true : false;
}

CommonLib.isValidURL = function(url) {
   //return (!preg_match('/^(http|https|ftp):\/\/([A-Z0-9][A-Z0-9_-]*(?:\.[A-Z0-9][A-Z0-9_-]*)+):?(\d+)?\/?/i', $url)) ? false : true;
   return !url.match(/^(http|https|ftp):\/\/([A-Z0-9][A-Z0-9_-]*(?:\.[A-Z0-9][A-Z0-9_-]*)+):?(\d+)?\/?/i) ? false : true;
}

CommonLib.isLeapYear = function(yr) {
   return new Date(yr,2-1,29).getDate()==29;
}

CommonLib.randomize = function(limit) {
   return Math.floor(Math.random()*limit);
}

CommonLib.hashcode = function(key, range) {
   key = new String(key);
   var sum = 0;
   for(var i=0; i<key.length; i++) {
       sum = 331 * sum + key.charCodeAt(i);
   }
   return Math.abs(sum % range);
}

CommonLib.hash256 = function(string) {
   return CommonLib.hashcode(string, 256);
}


CommonLib.hexdecode = function(string) {
   var temp = '';
   while(string.length) {
      var hex = string.substr(0, 2);
      string  = string.substr(2);
      var ord = parseInt(hex, 16);
      temp += String.fromCharCode(ord)
   }
   return temp;
}

CommonLib.hexencode = function(string) {
   var temp = '';
   for(i=0; i<string.length; i++) {
      temp += string.charCodeAt(i).toString(16).toUpperCase();
   }
   return temp;
}

CommonLib.comify = function(n) {
   n = new String(n);
   comified = '';
   while(n.length > 3) {
      comified = n.substring(n.length -3) + comified;
      n = n.substring(0, n.length-3);
      if(n.length) { comified = ',' + comified; }
   }
   if(n.length) { comified = n + comified; }
   return comified;
}

CommonLib.ucaseFirst = function(string) {
   if(!string.length) { return; }
   string = string.toLowerCase();
   if(string.length == 1) { return string.toUpperCase(); }
   return (string.substring(0, 1)).toUpperCase() + string.substring(1);
}

CommonLib.capitalize = function(string) {
   var words = string.split(/\s+/);
   string    = '';
   for(var i=0; i<words.length; i++) {
      string += ucaseFirst(words[i]);
      if(i < words.length -1) { string += ' '; }
   }
   return string;
}

// Create a JSON object only if one does not already exist. We create the
// methods in a closure to avoid creating global variables.

if (!this.JSON) {
    this.JSON = {};
}

(function () {

    function f(n) {
        // Format integers to have at least two digits.
        return n < 10 ? '0' + n : n;
    }

    if (typeof Date.prototype.toJSON !== 'function') {

        Date.prototype.toJSON = function (key) {

            return isFinite(this.valueOf()) ?
                   this.getUTCFullYear()   + '-' +
                 f(this.getUTCMonth() + 1) + '-' +
                 f(this.getUTCDate())      + 'T' +
                 f(this.getUTCHours())     + ':' +
                 f(this.getUTCMinutes())   + ':' +
                 f(this.getUTCSeconds())   + 'Z' : null;
        };

        String.prototype.toJSON =
        Number.prototype.toJSON =
        Boolean.prototype.toJSON = function (key) {
            return this.valueOf();
        };
    }

    var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
        escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
        gap,
        indent,
        meta = {    // table of character substitutions
            '\b': '\\b',
            '\t': '\\t',
            '\n': '\\n',
            '\f': '\\f',
            '\r': '\\r',
            '"' : '\\"',
            '\\': '\\\\'
        },
        rep;


    function quote(string) {

// If the string contains no control characters, no quote characters, and no
// backslash characters, then we can safely slap some quotes around it.
// Otherwise we must also replace the offending characters with safe escape
// sequences.

        escapable.lastIndex = 0;
        return escapable.test(string) ?
            '"' + string.replace(escapable, function (a) {
                var c = meta[a];
                return typeof c === 'string' ? c :
                    '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
            }) + '"' :
            '"' + string + '"';
    }


    function str(key, holder) {

// Produce a string from holder[key].

        var i,          // The loop counter.
            k,          // The member key.
            v,          // The member value.
            length,
            mind = gap,
            partial,
            value = holder[key];

// If the value has a toJSON method, call it to obtain a replacement value.

        if (value && typeof value === 'object' &&
                typeof value.toJSON === 'function') {
            value = value.toJSON(key);
        }

// If we were called with a replacer function, then call the replacer to
// obtain a replacement value.

        if (typeof rep === 'function') {
            value = rep.call(holder, key, value);
        }

// What happens next depends on the value's type.

        switch (typeof value) {
        case 'string':
            return quote(value);

        case 'number':

// JSON numbers must be finite. Encode non-finite numbers as null.

            return isFinite(value) ? String(value) : 'null';

        case 'boolean':
        case 'null':

// If the value is a boolean or null, convert it to a string. Note:
// typeof null does not produce 'null'. The case is included here in
// the remote chance that this gets fixed someday.

            return String(value);

// If the type is 'object', we might be dealing with an object or an array or
// null.

        case 'object':

// Due to a specification blunder in ECMAScript, typeof null is 'object',
// so watch out for that case.

            if (!value) {
                return 'null';
            }

// Make an array to hold the partial results of stringifying this object value.

            gap += indent;
            partial = [];

// Is the value an array?

            if (Object.prototype.toString.apply(value) === '[object Array]') {

// The value is an array. Stringify every element. Use null as a placeholder
// for non-JSON values.

                length = value.length;
                for (i = 0; i < length; i += 1) {
                    partial[i] = str(i, value) || 'null';
                }

// Join all of the elements together, separated with commas, and wrap them in
// brackets.

                v = partial.length === 0 ? '[]' :
                    gap ? '[\n' + gap +
                            partial.join(',\n' + gap) + '\n' +
                                mind + ']' :
                          '[' + partial.join(',') + ']';
                gap = mind;
                return v;
            }

// If the replacer is an array, use it to select the members to be stringified.

            if (rep && typeof rep === 'object') {
                length = rep.length;
                for (i = 0; i < length; i += 1) {
                    k = rep[i];
                    if (typeof k === 'string') {
                        v = str(k, value);
                        if (v) {
                            partial.push(quote(k) + (gap ? ': ' : ':') + v);
                        }
                    }
                }
            } else {

// Otherwise, iterate through all of the keys in the object.

                for (k in value) {
                    if (Object.hasOwnProperty.call(value, k)) {
                        v = str(k, value);
                        if (v) {
                            partial.push(quote(k) + (gap ? ': ' : ':') + v);
                        }
                    }
                }
            }

// Join all of the member texts together, separated with commas,
// and wrap them in braces.

            v = partial.length === 0 ? '{}' :
                gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' +
                        mind + '}' : '{' + partial.join(',') + '}';
            gap = mind;
            return v;
        }
    }

// If the JSON object does not yet have a stringify method, give it one.

    if (typeof JSON.stringify !== 'function') {
        JSON.stringify = function (value, replacer, space) {

// The stringify method takes a value and an optional replacer, and an optional
// space parameter, and returns a JSON text. The replacer can be a function
// that can replace values, or an array of strings that will select the keys.
// A default replacer method can be provided. Use of the space parameter can
// produce text that is more easily readable.

            var i;
            gap = '';
            indent = '';

// If the space parameter is a number, make an indent string containing that
// many spaces.

            if (typeof space === 'number') {
                for (i = 0; i < space; i += 1) {
                    indent += ' ';
                }

// If the space parameter is a string, it will be used as the indent string.

            } else if (typeof space === 'string') {
                indent = space;
            }

// If there is a replacer, it must be a function or an array.
// Otherwise, throw an error.

            rep = replacer;
            if (replacer && typeof replacer !== 'function' &&
                    (typeof replacer !== 'object' ||
                     typeof replacer.length !== 'number')) {
                throw new Error('JSON.stringify');
            }

// Make a fake root object containing our value under the key of ''.
// Return the result of stringifying the value.

            return str('', {'': value});
        };
    }


// If the JSON object does not yet have a parse method, give it one.

    if (typeof JSON.parse !== 'function') {
        JSON.parse = function (text, reviver) {

// The parse method takes a text and an optional reviver function, and returns
// a JavaScript value if the text is a valid JSON text.

            var j;

            function walk(holder, key) {

// The walk method is used to recursively walk the resulting structure so
// that modifications can be made.

                var k, v, value = holder[key];
                if (value && typeof value === 'object') {
                    for (k in value) {
                        if (Object.hasOwnProperty.call(value, k)) {
                            v = walk(value, k);
                            if (v !== undefined) {
                                value[k] = v;
                            } else {
                                delete value[k];
                            }
                        }
                    }
                }
                return reviver.call(holder, key, value);
            }


// Parsing happens in four stages. In the first stage, we replace certain
// Unicode characters with escape sequences. JavaScript handles many characters
// incorrectly, either silently deleting them, or treating them as line endings.

            cx.lastIndex = 0;
            if (cx.test(text)) {
                text = text.replace(cx, function (a) {
                    return '\\u' +
                        ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
                });
            }

// In the second stage, we run the text against regular expressions that look
// for non-JSON patterns. We are especially concerned with '()' and 'new'
// because they can cause invocation, and '=' because it can cause mutation.
// But just to be safe, we want to reject all unexpected forms.

// We split the second stage into 4 regexp operations in order to work around
// crippling inefficiencies in IE's and Safari's regexp engines. First we
// replace the JSON backslash pairs with '@' (a non-JSON character). Second, we
// replace all simple value tokens with ']' characters. Third, we delete all
// open brackets that follow a colon or comma or that begin the text. Finally,
// we look to see that the remaining characters are only whitespace or ']' or
// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.

            if (/^[\],:{}\s]*$/.
test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').
replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').
replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {

// In the third stage we use the eval function to compile the text into a
// JavaScript structure. The '{' operator is subject to a syntactic ambiguity
// in JavaScript: it can begin a block or an object literal. We wrap the text
// in parens to eliminate the ambiguity.

                j = eval('(' + text + ')');

// In the optional fourth stage, we recursively walk the new structure, passing
// each name/value pair to a reviver function for possible transformation.

                return typeof reviver === 'function' ?
                    walk({'': j}, '') : j;
            }

// If the text is not JSON parseable, then a SyntaxError is thrown.

            throw new SyntaxError('JSON.parse');
        };
    }
}());
Term.get = function(url, callback) {
   var tid = url.match(/\?/) ? '&termid=' + Term.id : '?termid=' + Term.id;
   var request = CommonLib.getRequestObject();
   request.open('GET', url, true);
   request.onreadystatechange = function() {
      if(request.readyState == 4) {
         if(request.status == 200 && request.responseText) {
            callback(request.responseText);
         }
         request = null;
      }
   };
   request.send(null);
}

Term.post = function(url, data, type, callback) {
   if(!type) { type = "application/x-www-form-urlencoded"; }
   var request = CommonLib.getRequestObject();
   request.open('POST', url, true);
   request.setRequestHeader("Content-Type", type);
   //request.setRequestHeader("Content-Length", data.length);
   request.onreadystatechange = function() {
      if(request.readyState == 4 && request.status == 200) {
         if(request.responseText){
            callback(request.responseText);
         }
      }
   };
   request.send(data);
}

Term.getContentHeight = function(content) {
   var div = document.getElementById('content.height');
   if(!div) {
      div = document.createElement('div');
      div.id = 'content.height';
      div.style.display = 'none';
      div.style.visibility = 'hidden';
      div.style.overflow = 'scroll';
      (document.getElementsByTagName('body')[0]).appendChild(div);
   }
   div.innerHTML = content;
   div.style.display = 'block';
   var height = div.scrollHeight;
   div.style.innerHTML = '';
   div.style.display = 'none';
   return height;
}

Term.ignore = function(xml) { return; }

Term.setFocus = function(id, really) {
   if(!really) {
      setTimeout("Term.setFocus('"+id+"', true)", 500);
      return;
   }
   el = document.getElementById(id);
   if(el) { el.focus(); }
}

Term.restore = function(id) {
   var el = document.getElementById(id);
   if(!el) { return; }
   el.style.visibility = 'visible';
}

Term.now = function() {
   return new Date().getTime();
}
JobSearch = {};

JobSearch.states = new Array("AL","ALABAMA","AK","ALASKA","AS","AMERICAN SAMOA","AZ","ARIZONA","AR","ARKANSAS","CA","CALIFORNIA",
"CO","COLORADO","CT","CONNECTICUT","DE","DELAWARE","DC","DISTRICT OF COLUMBIA","FM","FEDERATED STATES OF MICRONESIA","FL","FLORIDA",
"GA","GEORGIA","GU","GUAM","HI","HAWAII","ID","IDAHO","IL","ILLINOIS","IN","INDIANA","IA","IOWA","KS","KANSAS","KY","KENTUCKY","LA",
"LOUISIANA","ME","MAINE","MH","MARSHALL ISLANDS","MD","MARYLAND","MA","MASSACHUSETTS","MI","MICHIGAN","MN","MINNESOTA","MS",
"MISSISSIPPI","MO","MISSOURI","MT","MONTANA","NE","NEBRASKA","NV","NEVADA","NH","NEW HAMPSHIRE","NJ","NEW JERSEY","NM","NEW MEXICO",
"NY","NEW YORK","NC","NORTH CAROLINA","ND","NORTH DAKOTA","MP","NORTHERN MARIANA ISLANDS","OH","OHIO","OK","OKLAHOMA","OR","OREGON",
"PW","PALAU","PA","PENNSYLVANIA","PR","PUERTO RICO","RI","RHODE ISLAND","SC","SOUTH CAROLINA","SD","SOUTH DAKOTA","TN","TENNESSEE",
"TX","TEXAS","UT","UTAH","VT","VERMONT","VI","VIRGIN ISLANDS OF THE U.S.","VA","VIRGINIA","WA","WASHINGTON","WV","WEST VIRGINIA","WI",
"WISCONSIN","WY","WYOMING");

JobSearch.isValidState = function(state) {
   state = state.toUpperCase();
   for(var i=0; i<JobSearch.states.length; i++) {
      if(state == JobSearch.states[i]) { return true; }
   }
   return false;
}

JobSearch.trim = function(str) {
   str = str.replace(/^\s+/, '');
   str = str.replace(/\s+$/, '');
   return str;
}
JobSearch.focus = function(id) {
   DialogBox.close();
   (document.getElementById(id)).focus();
}

JobSearch.procForm = function() {


   var city       = '';
   var state      = '';
   var zip        = '';
   var searchform = 'jobboard';
   var keyword = document.getElementById('keyword')
   if(!keyword) { searchform = 'home'; }

   var location = JobSearch.trim((document.getElementById('location')).value);

   if(location.match(/^enter/i)) { location = ''; }

   if(!location) {
      if(searchform == 'home') {
         DialogBox.alertBox("Please enter your 5 digit Zip Code.", "JobSearch.focus('location')", 'Missing Zip Code');
      } else {
         DialogBox.alertBox("Please enter your search location <br /> (City, State) OR (ZIP Code).", "JobSearch.focus('location')", 'Missing Job Location');
      }
      return false;
   }

   if(!location.charAt(0).match(/[0-9]/)) {
      if(!location.match(/,/)) {
         DialogBox.alertBox("Pleast enter city and state separated by a comma.", "JobSearch.focus('location')", 'Wrong City, State Format');
         return false;
      }
      if(location.match(/,$/)) {
         DialogBox.alertBox("Pleast enter city and state separated by a comma.", "JobSearch.focus('location')", 'Wrong City, State Format');
         return false;
      }
      location = location.split(/,/);
      if(location.length != 2) {
         DialogBox.alertBox("Pleast enter city and state separated by a comma.", "JobSearch.focus('location')", 'Wrong City, State Format');
         return false;
      }
      city  = JobSearch.trim(location[0]);
      state = JobSearch.trim(location[1]);

      if(!city || !state) {
         DialogBox.alertBox("Pleast enter city and state separated by a comma.", "JobSearch.focus('location')", 'Wrong City, State Format');
         return false;
      }

      if(!JobSearch.isValidState(state)) {
         DialogBox.alertBox(state + " is not a valid state.", "JobSearch.focus('location')", 'Invalid State');
         return false;
      }

      (document.getElementById('city')).value  = city;
      (document.getElementById('state')).value = state;

   } else {
      if(location.charAt(0).match(/[0-9]/) && !location.match(/^[0-9][0-9][0-9][0-9][0-9]$/)) {
         DialogBox.alertBox(location + " is not a 5 digit ZIP Code.", "JobSearch.focus('location')", 'Malformed Zip Code');
         return false;
      } else {
         zip = location;
      }
   }

   if(searchform != 'home') {
      keyword = JobSearch.trim(keyword.value);
      if(keyword.match(/^enter/i)) { keyword = ''; }
   } else {
      keyword = '';
   }

   var radius = 10;
   var status = 2;

   if(searchform != 'home') {
      var inputs = document.getElementsByTagName('input');
      for(var i=0; i<inputs.length; i++) {
         if(inputs[i].type != 'radio') { continue; }
         if(inputs[i].name != 'radius') { continue; }
         if(!inputs[i].checked) { continue; }
         radius = inputs[i].value;
         break;
      }
      for(var i=0; i<inputs.length; i++) {
         if(inputs[i].type != 'radio') { continue; }
         if(inputs[i].name != 'status') { continue; }
         if(!inputs[i].checked) { continue; }
         status = inputs[i].value;
         break;
      }
   }

   data = {'keyword' : keyword, 'location' : location, 'radius' : radius, 'status' : status};
   data = JSON.stringify(data);
   CommonLib.createCookie('SEARCH_TERMS', data);

   var url  = '/jobs-over-50/job.search/?';
       url += 'city='     + escape(city) + '&';
       url += 'state='    + escape(state) + '&';
       url += 'zip='      + zip + '&';
       url += 'keyword='  + escape(keyword) + '&';
       url += 'location=' + escape(location) + '&';
       url += 'status='   + status + '&';
       url += 'radius='   + radius;

   document.location.href = url;

   //document.getElementById('simple_search').submit();
   return false;
}

JobSearch.init = function() {
   if(!document.getElementById('location')) { return; }
   if(document.location.href.match(/\.retirementjobs\.com\/$/)) { return; }
   if(document.location.href.match(/\.retirementjobs\.com\/index\.php/)) { return; }
   //if(document.location.href.match(/detail=/)) { return; }
   var data = CommonLib.readCookie('SEARCH_TERMS');
   if(!data) { return; }
   data = JSON.parse(data);
   var keyword  = data['keyword'];
   var location = data['location'];
   var radius   = data['radius'];
   var status   = data['status'];
   if(keyword) { (document.getElementById('keyword')).value = keyword; }
   (document.getElementById('location')).value = location;
   var inputs = document.getElementsByTagName('input');
   for(var i=0; i<inputs.length; i++) {
      if(inputs[i].type != 'radio') { continue; }
      if(inputs[i].name != 'radius') { continue; }
      inputs[i].checked = false;
      if(parseInt(inputs[i].value) == parseInt(radius)) { inputs[i].checked = true; }
   }
   for(var i=0; i<inputs.length; i++) {
      if(inputs[i].type != 'radio') { continue; }
      if(inputs[i].name != 'status') { continue; }
      inputs[i].checked = false;
      if(parseInt(inputs[i].value) == parseInt(status)) { inputs[i].checked = true; }
   }
}
JobSearch.init();
JobSeeker = {};
JobSeeker.focus = function(form, field) {
   DialogBox.close();
   document[form][field].focus();
   if(form == 'profile') {
      document.profile.category.style.visibility = 'visible';
      document.profile.category.style.display = 'block';
   }

}
JobSeeker.setProfile = function(xml) {
   if(!xml) {
      var fname = document.getElementById('profile_fname').value;
      var lname = document.getElementById('profile_lname').value;
      var zip   = document.getElementById('profile_zip').value;
      var email = document.getElementById('profile_email').value;

      if(!fname) {
         DialogBox.alertBox('Please enter your first name.', "DialogBox.close();Term.setFocus('profile_fname');", 'Missing First Name');
         return;
      }
      if(!lname) {
         DialogBox.alertBox('Please enter your last name.', "DialogBox.close();Term.setFocus('profile_lname');", 'Missing Last Name');
         return;
      }
      if(!email) {
         DialogBox.alertBox('Please enter your email address.', "DialogBox.close();Term.setFocus('profile_email');", 'Missing Email Address');
         return;
      }
      if(!CommonLib.isValidEmail(email)) {
         DialogBox.alertBox('The email address you entered is invalid.', "DialogBox.close();Term.setFocus('profile_email');", 'Malformed Email Address');
         return;
      }
      if(!zip) {
         DialogBox.alertBox('Please enter your Zip Code.', "DialogBox.close();Term.setFocus('profile_zip');", 'Missing Zip Code');
         return;
      }
      if(!zip.match(/^[0-9][0-9][0-9][0-9][0-9]$/)) {
         DialogBox.alertBox('Please enter your five digit Zip Code.', "DialogBox.close();Term.setFocus('profile_zip');", 'Malformed Zip Code');
         return;
      }
      var category   = '';
      var categories = (document.getElementById('category_select')).options;
      for(var i=0; i<categories.length; i++) {
         if(categories[i].selected && categories[i].value != '') {
            category = categories[i].value;
            break;
         }
      }
      if(!category) {
         DialogBox.alertBox('Please select a job category.', "DialogBox.close();Term.restore('category_select');", 'Missing Job Category');
         return;
      }

      fname    = escape(fname);
      lname    = escape(lname);
      email    = escape(email);
      zip      = escape(zip);
      category = escape(category);

      var url = '/jobs-over-50/jobseeker/ajax/set.profile.php?fname='+fname+'&lname='+lname+'&email='+email+'&zip='+zip+'&category='+category;

      DialogBox.waitBox();
      Term.get(url, JobSeeker.setProfile);
      return;
   }

   DialogBox.close();
   var status   = CommonLib.parseElement(xml, 'status');
   var message  = CommonLib.parseElement(xml, 'message');
   var callback = CommonLib.parseElement(xml, 'callback');
   var fname    = CommonLib.parseElement(xml, 'fname');
   var lname    = CommonLib.parseElement(xml, 'lname');
   var email    = CommonLib.parseElement(xml, 'email');

   var title    = 'Profile Update Successful';
   if(status == 'failure') {
      title = 'Profile Update Failed';
   } else {
      LoginUtils.init();
   }
   DialogBox.alertBox(message, callback, title);
}

JobSeeker.getProfile = function(xml) {

   if(!xml) {
      DialogBox.waitBox();
      Term.get('/jobs-over-50/jobseeker/ajax/get.profile.php', JobSeeker.getProfile);
      return;
   }

   DialogBox.close();

   var status  = CommonLib.parseElement(xml, 'status');
   var content = CommonLib.parseElement(xml, 'content');
   var message = CommonLib.parseElement(xml, 'message');
   var script  = CommonLib.parseElement(xml, 'script');
   var width  = parseInt(CommonLib.parseElement(content, 'width'));
   var height = parseInt(CommonLib.parseElement(content, 'height'));
   var html   = CommonLib.parseElement(content, 'html');
   DialogBox.domFormBox(width, height, html);
   if(script) { eval(script); }

}

JobSeeker.logout = function(xml) {
   if(!xml) {
      DialogBox.waitBox();
      Term.get('/jobs-over-50/login/ajax/logout.php', JobSeeker.logout);
      return;
   }
   var status = CommonLib.parseElement(xml, 'status');
   if(status == 'success') {
      document.location.href = '/login/';
   }
}

JobSeeker.coverLetter = "";

JobSeeker.setResume  = function(xml) {
   if(!xml) {
      var name   = document.getElementById('resume_name').value;
      var resid  = parseInt(document.getElementById('resume_resid').value);
      var text   = document.getElementById('resume_text').value;
      var jobid  = parseInt(document.getElementById('resume_jobid').value);

      /*
      alert("jobid: " + jobid);
      alert("resid: " + resid);
      return;
      */

      if(!name) {
         DialogBox.alertBox('Please enter a name for your resume.', "DialogBox.close();Term.setFocus('resume_name');", 'Missing Resume Name');
         return;
      }
      if(!text) {
         DialogBox.alertBox('Please enter your resume text.', "DialogBox.close();Term.setFocus('resume_text');", 'Missing Resume Text');
         return;
      }

      var data = "";
      data += "resid="    + resid;
      data += "&name="    + escape(name);
      data += "&text="    + escape(text);
      data += "&jobid="   + escape(jobid);

      /*
      alert(data);
      return;
      */

      DialogBox.waitBox();

      Term.post('/jobs-over-50/jobseeker/ajax/set.resume.php', data, null, JobSeeker.setResume); 

      return;
   }

   DialogBox.close();

   var resid   = CommonLib.parseElement(xml, 'resid');
   var jobid   = parseInt(CommonLib.parseElement(xml, 'jobid'));
   var status  = CommonLib.parseElement(xml, 'status');
   var message = CommonLib.parseElement(xml, 'message');
   var name    = CommonLib.parseElement(xml, 'name');
   var script  = CommonLib.parseElement(xml, 'script');

   if(status == 'failure') {
      DialogBox.alertBox(message, null, 'Resume Storage Failure');
      return;
   }

   if(!jobid) {
      document.getElementById('resume_message').innerHTML = "Editing your resume named <b>" + name + "</b>.";
      document.getElementById('resume_resid').value = resid;
      DialogBox.alertBox(message, null, 'Resume Successfully Saved');
      return;
   }

   DialogBox.close();
   var resume = CommonLib.parseElement(xml, 'resume');
   ApplyUtils.resume = resume;
   ApplyUtils.getCoverLetter();
}

JobSeeker.getResume = function(xml) {

   resid = 0;
   jobid = 0;
   query = '';
   if((typeof xml) == 'object') {
      if((typeof xml.resid) != 'undefined') { 
         resid = parseInt(xml.resid);
         if(resid == 0) { resid = -1; } // means new cut and paste resume.
         query += "&resid=" + resid;
      }
      if((typeof xml.jobid) != 'undefined') {
         jobid = parseInt(xml.jobid); 
         query += "&jobid=" + jobid;
      }
      query = query.replace(/^\&/, '');
      xml = '';
   }
   
   if(!xml) {
      DialogBox.waitBox();
      Term.get('/jobs-over-50/jobseeker/ajax/get.resume.php?' + query, JobSeeker.getResume);
      return;
   }
   DialogBox.close();
   var content  = CommonLib.parseElement(xml, 'content');
   var html     = CommonLib.parseElement(content, 'html');
   var width    = parseInt(CommonLib.parseElement(content, 'width'));
   var height   = parseInt(CommonLib.parseElement(content, 'height'));
   var script   = CommonLib.parseElement(xml, 'script');
   DialogBox.domFormBox(width, height, html);
   if(script) { eval(script); }
   //if(!parseInt(document.resume_form.id.value)) { document.resume_form.name.focus(); }
}

JobSeeker.selectResume = function() {
   var jobid  = parseInt(document.getElementById('resume_jobid').value);
   var inputs = document.getElementsByTagName('input');
   var resid  = 0;
   for(var i=0; i<inputs.length; i++) {
      if(inputs[i].type != 'radio') { continue; }
      if(inputs[i].name != 'resume') { continue; }
      if(!inputs[i].checked) { continue; }
      resid = inputs[i].value;
      break;
   }
   DialogBox.close();
   JobSeeker.getResume({'resid':resid,'jobid':jobid});
}

JobSeeker.setPassword = function(xml) {
   if(!xml) {
      var password         = document.getElementById('password').value;
      var confirm_password = document.getElementById('confirm').value;
      if(!password) {
         DialogBox.alertBox("Please enter your new password.", "DialogBox.close();Term.setFocus('password');", 'Set Password Failure');
         return false;
      }
      if(password.length > 10) {
         DialogBox.alertBox("Your password can't exceed 10 characters.",
                            "DialogBox.close();Term.setFocus('password');", 'Set Password Failure');
         return false;
      }
      if(!confirm_password) {
         DialogBox.alertBox("Please enter your new password again.",
                            "DialogBox.close();Term.setFocus('confirm');", 'Set Password Failure');
         return false;
      }
      if(password != confirm_password) {
         DialogBox.alertBox("Your two new passwords don't match.", 
                            "DialogBox.close();Term.setFocus('confirm');", 'Set Password Failure');
         (document.getElementById('password')).value = '';
         (document.getElementById('confirm')).value = '';
         return false;
      }
      DialogBox.waitBox();
      Term.get('/jobs-over-50/jobseeker/ajax/set.password.php?password=' + escape(password), JobSeeker.setPassword);
      return;
   }
   DialogBox.close();
   var status  = CommonLib.parseElement(xml, 'status');
   var message = CommonLib.parseElement(xml, 'message');
   if(status == 'success') {
      DialogBox.alertBox(message, 'DialogBox.closeAll()', 'Set Password Success');
   } else { 
      DialogBox.alertBox(message, null, 'Set Password Failure');
   }
}

JobSeeker.getPassword = function(xml) {
   if(!xml) {
      DialogBox.waitBox();
      Term.get('/jobs-over-50/jobseeker/ajax/get.password.php', JobSeeker.getPassword);
      return;
   }
   var content = CommonLib.parseElement(xml, 'content');
   var script  = CommonLib.parseElement(xml, 'script');
   var width   = parseInt(CommonLib.parseElement(content, 'width'));
   var height  = parseInt(CommonLib.parseElement(content, 'height'));
   var html    = CommonLib.parseElement(content, 'html');
   DialogBox.domFormBox(width, height, html);
   eval(script);
}

JobSeeker.setSubscriptions = function(xml) {
   if(!xml) {
      var jobseeker_newsletter = 0;
      var agent_mail           = 0;
      var premium_service      = 0;
      var premium_workshops    = 0;
      var partner_email        = 0;
      if(document.getElementById('partner_email') && document.getElementById('partner_email').checked) {
         partner_email = 1;
      }

      if(document.getElementById('jobseeker_newsletter') && document.getElementById('jobseeker_newsletter').checked) {
         jobseeker_newsletter = 1;
      }
      if(document.getElementById('agent_mail') && document.getElementById('agent_mail').checked) {
         agent_mail = 1;
      }
      if(document.getElementById('premium_service') && document.getElementById('premium_service').checked) {
         premium_service = 1;
      }
      if(document.getElementById('premium_workshops') && document.getElementById('premium_workshops').checked) {
         premium_workshops = 1;
      }
      var url = "/jobs-over-50/jobseeker/ajax/set.subscriptions.php";
          url += "?jobseeker_newsletter=" + jobseeker_newsletter;
          url += "&agent_mail=" + agent_mail;
          url += "&premium_service=" + premium_service;
          url += "&premium_workshops=" + premium_workshops;
          url += "&partner_email=" + partner_email;

      DialogBox.waitBox();
      Term.get(url, JobSeeker.setSubscriptions);
      return;
   }
   DialogBox.close();
   var message = CommonLib.parseElement(xml, 'message');
   DialogBox.alertBox(message, 'DialogBox.closeAll()', 'Email Preferences Set');
}

JobSeeker.getSubscriptions = function(xml) {
   if(!xml) {
      DialogBox.waitBox();
      Term.get('/jobs-over-50/jobseeker/ajax/get.subscriptions.php', JobSeeker.getSubscriptions);
      return;
   }

   DialogBox.close();
   var content = CommonLib.parseElement(xml, 'content');
   var html    = CommonLib.parseElement(content, 'html');
   var width   = parseInt(CommonLib.parseElement(content, 'width'));
   var height  = parseInt(CommonLib.parseElement(content, 'height'));
   var script  = CommonLib.parseElement(xml, 'script');
   DialogBox.domFormBox(width, height, html);
   if(script) { eval(script); }
}

JobSeeker.setAlert = function(xml) {
   if(!xml) {
      var id         = document.getElementById('alert_id').value;
      var zip        = document.getElementById('alert_zip').value;

      var freq  = 'weekly';
      var freqs = document.getElementsByTagName('input');
      for(var i=0; i<freqs.length; i++) {
         if(freqs[i].type != 'radio')     { continue; }
         if(freqs[i].name != 'frequency') { continue; }
         if(freqs[i].checked) {
            freq = freqs[i].value;
            break;
         }
      }

      if(!zip) {
         DialogBox.alertBox('Please enter a Zip Code.', "DialogBox.close();Term.setFocus('alert_zip');", 'Missing Zip Code');
         return;
      }

      if(!zip.match(/^[0-9][0-9][0-9][0-9][0-9]$/)) {
         DialogBox.alertBox('Please enter a five digit Zip Code.', "DialogBox.close();Term.setFocus('alert_zip');", 'Malformed Zip Code');
         return;
      }

      var category   = '';
      var categories = (document.getElementById('category_select')).options;
      for(var i=0; i<categories.length; i++) {
         if(categories[i].selected && categories[i].value != '') {
            category = categories[i].value;
            break;
         }
      }
      if(!category) {
         DialogBox.alertBox('Please select a job category.', "DialogBox.close();Term.restore('category_select');", 'Missing Job Category');
         return;
      }

      DialogBox.waitBox();
      var url = '/jobs-over-50/jobseeker/ajax/set.alert.php';
      url += '?id=' + id;
      url += '&zip='        + escape(zip);
      url += '&frequency='  + escape(freq);
      url += '&category=' + escape(category);

      Term.get(url, JobSeeker.setAlert);
      return;
   }
   DialogBox.close();
   var status   = CommonLib.parseElement(xml, 'status');
   var message  = CommonLib.parseElement(xml, 'message');
   var id       = CommonLib.parseElement(xml, 'id');
   var callback = CommonLib.parseElement(xml, 'callback');
   var content  = CommonLib.parseElement(xml, 'content');

   if(status == 'success') {
      //if(parseInt(id)) { (document.getElementById('alert_id')).value = id; }
      //DialogBox.alertBox(message, 'DialogBox.closeAll()', 'Alert Successfully Saved');
      DialogBox.close();
      var html  = CommonLib.parseElement(content, 'html');
      var width = parseInt(CommonLib.parseElement(content, 'width'));
      DialogBox.domFormBox(width, null, html);
      return;
   }   
   DialogBox.alertBox(message, callback, 'Alert Storage Failure');
}

JobSeeker.getAlert = function(xml) {
   if(!xml) {
      DialogBox.waitBox();
      Term.get('/jobs-over-50/jobseeker/ajax/get.alert.php', JobSeeker.getAlert);
      return;
   }
   DialogBox.close();
   var content = CommonLib.parseElement(xml, 'content'); 
   var html    = CommonLib.parseElement(content, 'html');
   var width   = parseInt(CommonLib.parseElement(content, 'width'));
   var height  = parseInt(CommonLib.parseElement(content, 'height'));
   var script  = CommonLib.parseElement(xml, 'script');
   DialogBox.domFormBox(width, height, html);
   if(script) { eval(script); }
}

JobSeeker.getCategories = function(xml) {
   if(!xml) {
      var category = document.getElementById('catkey').value;
      var alert_id  = document.getElementById('alert_id').value;
      DialogBox.closeAll();
      DialogBox.waitBox();
      var url = '/jobs-over-50/jobseeker/ajax/get.categories.php';
      url += '?category=' + escape(category);
      url += '&alert_id=' + escape(alert_id);
      Term.get(url, JobSeeker.getCategories);
      return;
   }
   DialogBox.close();
   var content = CommonLib.parseElement(xml, 'content');
   var html    = CommonLib.parseElement(content, 'html');
   var width   = parseInt(CommonLib.parseElement(content, 'width'));
   var height  = parseInt(CommonLib.parseElement(content, 'height'));

   DialogBox.domFormBox(width, height, html);

   /*
   DialogBox.domFormBox(width, height, html, {'checkbox' : false, 'radio' : false, 'text' : false});
   var cats = (document.getElementById('alert_categories')).value.split(/ /);
   for(var i=0; i<cats.length; i++) {
      var el = document.getElementById(cats[i]);
      el.checked = true;
   }

   inputs = document.getElementsByTagName('input');
   for(var i=0; i<inputs.length; i++) {
      if(inputs[i].type != 'checkbox') { continue; }
      $("input#" + inputs[i].id).custCheckBox();
   }
   */

}
JobSeeker.setCategories = function(xml) {
   if(!xml) {
      var cats = document.getElementsByTagName('input');
      var categories = '';
      for(var i=0; i<cats.length; i++) {
         if(cats[i].type != 'checkbox') { continue; }
         if(cats[i].className != 'category') { continue; }
          if(cats[i].checked) {
            categories += cats[i].id + ' ';
         }
      }
      categories = categories.replace(/ $/, '');
      if(!categories) {
         DialogBox.alertBox('Please select one or more job search categories.', null, 'Missing Categories');
         return;
      }

      var alert_id = document.getElementById('alert_id').value;

      var url = '/jobs-over-50/jobseeker/ajax/set.categories.php';
      url += '?categories=' + escape(categories);
      url += '&alert_id=' + escape(alert_id);

      DialogBox.waitBox();
      Term.get(url, JobSeeker.setCategories);
      return;

      //(document.getElementById('alert_categories')).value = categories;
      //DialogBox.close();
      //DialogBox.alertBox('Thank you. Your job search categories are set. Click <b>Save Alert</b> to save all changes.', null, 'Categories Set', 300, 150);
   }

   DialogBox.close();

   var status  = CommonLib.parseElement(xml, 'status');
   var title   = CommonLib.parseElement(xml, 'title'); 
   var message = CommonLib.parseElement(xml, 'message');

   DialogBox.alertBox(message, 'DialogBox.closeAll();', title);
}
LoginUtils = {};

LoginUtils.setAccount = function(xml) {
   if(!xml) {
      var email         = document.getElementById('account_email').value.toLowerCase();
      var confirm_email = document.getElementById('account_confirm').value.toLowerCase();
      var fname         = document.getElementById('account_fname').value;
      var lname         = document.getElementById('account_lname').value;
      var zip           = document.getElementById('account_zip').value;
      var jobid         = document.getElementById('account_jobid').value;
 
      if(!email) {
         DialogBox.alertBox('Please enter your email address.', "Term.setFocus('account_email');DialogBox.close();", "Missing Email Address");
         return;
      }
      if(!CommonLib.isValidEmail(email)) {
         DialogBox.alertBox('Your email address is malformed.', "Term.setFocus('account_email');DialogBox.close();", "Malformed Email Address");
         return;
      }

      if(!confirm_email) {
         DialogBox.alertBox('Please enter your email address again.', "Term.setFocus('account_confirm');DialogBox.close();", "Missing Email Address");
         return;
      }
      if(email != confirm_email) {
         DialogBox.alertBox('Your two email addresses are mismatched.', "Term.setFocus('account_confirm');DialogBox.close();", "Mismatched Email Addresses");
         return;
      }
      if(!fname) {
         DialogBox.alertBox('Please enter your first name.', "Term.setFocus('account_fname');DialogBox.close();", "Missing First Name");
         return;
      }
      if(!lname) {
         DialogBox.alertBox('Please enter your last name.', "Term.setFocus('account_lname');DialogBox.close();", "Missing Last Name");
         return;
      }
      if(!zip) {
         DialogBox.alertBox('Please enter your Zip Code.', "Term.setFocus('account_zip');DialogBox.close();", "Missing Zip Code");
         return;
      }
      if(!zip.match(/^[0-9][0-9][0-9][0-9][0-9]$/)) {
         DialogBox.alertBox('Please enter your five digit Zip Code.', "Term.setFocus('account_zip');DialogBox.close();", "Malformed Zip Code");
         return;
      }

      DialogBox.waitBox();

      var url  = "/jobs-over-50/login/ajax/set.account.php";
          url += "?email=" + escape(email);
          url += "&fname=" + escape(fname);
          url += "&lname=" + escape(lname);
          url += "&zip="   + escape(zip);
          url += "&jobid=" + escape(jobid);

      Term.get(url, LoginUtils.setAccount);
      return;
   }

   DialogBox.close();

   var status   = CommonLib.parseElement(xml, 'status');
   var message  = CommonLib.parseElement(xml, 'message');
   var script   = CommonLib.parseElement(xml, 'script');
   var jobid    = parseInt(CommonLib.parseElement(xml, 'jobid'));
   var callback = CommonLib.parseElement(xml, 'callback');

   if(status == 'failure') {
      DialogBox.alertBox(message, null, 'Create Account Failure');
      return;
   }

   if(script) { eval(script); }
   DialogBox.alertBox(message, callback, 'Create Account Success');
}

LoginUtils.getAccount = function(xml) {

   var jobid = 0; 

   if((typeof xml) == 'object') {
      jobid = xml.jobid;
      xml = '';
   }

   if(!xml) {
      DialogBox.waitBox();
      var url = '/jobs-over-50/login/ajax/get.account.php?jobid=' + jobid;
      Term.get(url, LoginUtils.getAccount);
      return;
   }

   DialogBox.close();

   var status  = CommonLib.parseElement(xml, 'status');
   var message = CommonLib.parseElement(xml, 'message');
   var content = CommonLib.parseElement(xml, 'content');
   var script  = CommonLib.parseElement(xml, 'script');

   if(status == 'failure') {
      DialogBox.alertBox(message, null, 'Create Account Failure');
      return;
   }

   var width  = parseInt(CommonLib.parseElement(content, 'width'));
   var height = parseInt(CommonLib.parseElement(content, 'height'));
   var html   = CommonLib.parseElement(content, 'html');

   DialogBox.domFormBox(width, height, html);
   Term.setFocus('account_email');

}


LoginUtils.logout = function(xml) {
   if(!xml) {
      DialogBox.waitBox();
      Term.get('/jobs-over-50/login/ajax/logout.php', LoginUtils.logout);
      return;
   }
   var script = CommonLib.parseElement(xml, 'script');
   if(script) { eval(script); }
   LoginUtils.init();
}


LoginUtils.setPasswordForgot = function(xml) {
   if(!xml) {
      var email = document.getElementById('password_email').value;
      if(!email) {
          DialogBox.alertBox('Please enter your email address.', "Term.setFocus('password_email');DialogBox.close();", 'Missing Email Address');
          return;
      }
      if(!CommonLib.isValidEmail(email)) {
          DialogBox.alertBox('Please enter a valid mail address.', "Term.setFocus('password_email');DialogBox.close();", 'Malformed Email Address');
          return;
      }
      DialogBox.waitBox();
      Term.get('/jobs-over-50/login/ajax/set.password.forgot.php?email=' + escape(email), LoginUtils.setPasswordForgot);
      return;
   }

   DialogBox.close();
   var status  = CommonLib.parseElement(xml, 'status');
   var message = CommonLib.parseElement(xml, 'message');
   if(status == 'failure') {
      DialogBox.alertBox(message, null, "Password Reset Failure");
   } else {
      DialogBox.closeAll();
      DialogBox.alertBox(message, 'DialogBox.closeAll()', "Password Reset Success", null, 150);
   }
}


LoginUtils.getPasswordForgot = function(xml) {
   if(!xml) {
      DialogBox.waitBox();
      Term.get('/jobs-over-50/login/ajax/get.password.forgot.php', LoginUtils.getPasswordForgot);
      return;
   }
   DialogBox.close();
   var content = CommonLib.parseElement(xml, 'content');
   var script  = CommonLib.parseElement(xml, 'script');
   var width   = CommonLib.parseElement(content, 'width');
   var height  = CommonLib.parseElement(content, 'height');
   var html    = CommonLib.parseElement(content, 'html');
   DialogBox.domFormBox(width, height, html);
   if(script) { eval(script); }

}


LoginUtils.getLogin = function(xml) {
   var jobid = 0;

   if((typeof xml) == 'object') {
      jobid = xml.jobid;
      xml = '';
   }

   if(!xml) {
      DialogBox.waitBox();
      Term.get('/jobs-over-50/login/ajax/get.login.php?jobid=' + jobid, LoginUtils.getLogin);
      return;
   }
   DialogBox.close();
   var content = CommonLib.parseElement(xml, 'content');
   var html    = CommonLib.parseElement(content, 'html');
   var width   = parseInt(CommonLib.parseElement(content, 'width'));
   var height  = parseInt(CommonLib.parseElement(content, 'height'));
   DialogBox.domFormBox(width, height, html);
   var el = document.getElementById('login_email');
   Term.setFocus('login_email');
}


LoginUtils.loginEmail    = '';
LoginUtils.loginJobId    = 0;
LoginUtils.loginPassword = '';
LoginUtils.loginPrefix   = '';

LoginUtils.setLogin = function(xml) {

   if(!xml) {

      var jobid    = 0;
      var email    = '';
      var password = '';
      var prefix   = '';

      if(DialogBox.stackSize() > 0) {
         
         email      = document.getElementById('login_email').value;
         password   = document.getElementById('login_password').value;
         loginJobid = document.getElementById('login_jobid');
         if(loginJobid) {
            jobid = parseInt(loginJobid.value);
         }

      } else {

         email      = document.getElementById('block_login_email').value;
         password   = document.getElementById('block_login_password').value;
         prefix     = 'block_';

      }

      if(!email) {
         DialogBox.alertBox('Please enter your email address.', 
         "DialogBox.close();Term.setFocus('" + prefix + "login_email');", 'Missing Email Address');
         return false;
      }

      /*
      if(Term.site == 'website') {
         if(email == 'admin') {
            var url  = '/index.php/login/do_login/'
            document.location.href = url;
            return;
         }
      }
      */

      if(!CommonLib.isValidEmail(email)) {
         DialogBox.alertBox('Please enter your correct email address.', 
         "DialogBox.close();Term.setFocus('" + prefix + "login_email');", 'Malformed Email Address');
         return false;
      }
      if(!password) {
         DialogBox.alertBox('Please enter your password.', 
         "DialogBox.close();Term.setFocus('" + prefix + "login_password');", 'Missing Password');
         return false;
      }

      email    = escape(email);
      password = escape(password);
      DialogBox.waitBox();
      Term.get('/jobs-over-50/login/ajax/set.login.php?email=' + email + '&password=' + password + '&jobid=' + jobid, LoginUtils.setLogin);
      return false;
   }


   DialogBox.close();

   var status         = CommonLib.parseElement(xml, 'status');
   var message        = CommonLib.parseElement(xml, 'message');
   var script         = CommonLib.parseElement(xml, 'script');
   var jobid          = parseInt(CommonLib.parseElement(xml, 'jobid'));
   var callback       = CommonLib.parseElement(xml, 'callback');

   if(status == 'failure') {
      DialogBox.alertBox(message, callback, 'Login Failure');
      return;
   }
   //alert(script);
   if(script) { eval(script); }
}

LoginUtils.init = function() {
   var welcome = '';
   var links   = '';
   if(User.id) {
      var email = User.email;
      var fname = User.fname;
      var lname = User.lname;

      /*
      var user = CommonLib.readCookie('RJC_USER');
      if(!user) { return; }
      user = JSON.parse(unescape(user));
      var email = user['email'];
      var fname = user['fname'];
      var lname = user['lname'];
      */

      var welcome = "Welcome " + email;
      if(fname && lname) {
         welcome = "Welcome " + fname + " " + lname;
      }
      links = "<a style='cursor:pointer;' onclick='LoginUtils.logout()'>Logout</a>";

      /*
      if(Term.site == 'website') {
         var div = document.getElementById('website_login');
         if(div) {
            div.style.visibility = 'hidden';
            div.style.display = 'none';
         }
      }
      */

      var loginBlock = document.getElementById('login.block');
      //if(loginBlock && loginBlock.style.display == 'block') {
      if(loginBlock) {
         loginBlock.style.visibility = 'hidden';
         loginBlock.style.display = 'none';
         (document.getElementById('block_login_email')).value = '';
         (document.getElementById('block_login_password')).value = '';

      }

   } else {
      links += "<a href='javascript:LoginUtils.getLogin()'>Login</a><br />";
      links += "<a href='javascript:LoginUtils.getAccount()'>Create Account</a><br />";
      links += "<a href='javascript:LoginUtils.getPasswordForgot()'>Reset Password?</a>";

      /*
      if(Term.site == 'website') {
         var div = document.getElementById('website_login');
         if(div) {
            div.style.visibility = 'visible';
            div.style.display = 'block';
         }
      }
      */

      var loginBlock = document.getElementById('login.block');
      //if(loginBlock && loginBlock.style.display == 'none') {
      if(loginBlock) {
         loginBlock.style.visibility = 'visible';
         loginBlock.style.display = 'block';
         //(document.getElementById('block_login_email')).value = '';
         //(document.getElementById('block_login_password')).value = '';
      }

   }

   var account  = '';
       account += "<table style='width:100%;font-size:16px;' cellpadding='0' cellspacing='0 border='0'>";
       account += "<tr>";
       account += "<td align='right' valign='top'>" + welcome + "</td>";
       account += "<td align='right' valign='top'>" + links + "</td>";
       account += "</tr>";
       account += "</table>";
   var el = document.getElementById('account');
   if(el) { el.innerHTML = account; }

}


/*
LoginUtils.isConnected = function(xml) {
   if(!xml) {
      Term.get('/jobs-over-50/login/ajax/is.connected.php', LoginUtils.isConnected);
      return;
   }
   var uid = parseInt(CommonLib.parseElement(xml, 'uid'));
   Term.uid = uid; 
   LoginUtils.init();
}
*/



LoginUtils.init();
// ADAMS's RADIO CUSTOMISATION
// adam.burmister@gmail.com, Copyright 2005.


/**
NAME: initARC()

ABOUT:
 Detects the current user browser and customises the form's radio buttons if
 the browser is not IE mac, <= IE 4 or NS4.

USAGE:
 In your main HTML body use onLoad() to call initARC(), passing in the form id
 and on/off class names you wish to use to customise your radio buttons.
 e.g. <body onLoad="initARC('myform','radioOn', 'radioOff');">
 
PARAMS:
 formId   - The ID of the form you wish to customise
 onClass  - The CSS class name for the radio button's on style
 offClass - The CSS class name for the radio button's off style
*/


function initARC(formId,onClassRadio,offClassRadio,onClassCheckbox,offClassCheckbox) {

    var agt=navigator.userAgent.toLowerCase();

    // Browser Detection stuff
    this.major = parseInt(navigator.appVersion);
    this.ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
    this.ie3    = (this.ie && (this.major < 4));
    this.ie4    = (this.ie && (this.major == 4) && (agt.indexOf("msie 4")!=-1) );
	this.iemac  = (this.ie && (agt.indexOf("mac")!=-1));

	if( !(this.iemac || ie3 || ie4) ){
		customiseInputs(formId,onClassRadio,offClassRadio,onClassCheckbox,offClassCheckbox);
	}
}



//Add a .label reference to all input elements. Handy! Borrowed from...
//http://www.codingforums.com/archive/index.php/t-14672
function addLabelProperties(f){
	if(typeof f.getElementsByTagName == 'undefined') return;
	var labels = f.getElementsByTagName("label"), label, elem, i = j = 0;
	
	while (label = labels[i++]){
		if(typeof label.htmlFor == 'undefined') return;
		elem = document.getElementById(label.htmlFor);
		//elem = f.elements[label.htmlFor]; /* old method */
		
		if(typeof elem == 'undefined'){
			//no label defined, find first sub-input
			var inputs = label.getElementsByTagName("input");
			if(inputs.length==0){
				continue;
			} else {
				elem=inputs[0];
			}
		} else if(typeof elem.label != 'undefined') { // label property already added
			continue;
		} else if(typeof elem.length != 'undefined' && elem.length > 1 && elem.nodeName != 'SELECT'){
			for(j=0; j<elem.length; j++){
				elem.item(j).label = label;
			}
		}
		elem.label = label;
	}
} 



/**
NAME: toggleLabelStyle()

ABOUT:
 This function is attached to our label's onClick event. So when the label is
 clicked this function alters the radio group's members to an unchecked state
 and style, and alters the currently selected label to the on style and checked
 state.

USAGE:
 ARC currently assumes that the label contains a FOR='id' in it's HTML. The other
 valid form of a label is <label>text <input /></label> - while it is possible
 to modify this code to allow for this form I have left this as an exercise for
 the reader.
 
PARAMS:
 formId   - Parent form of this label
 label    - The label for a radio button we wish to toggle
 onClass  - The CSS class name for the radio button's on style
 offClass - The CSS class name for the radio button's off style
*/
function toggleLabelStyle(formId, label, onClass, offClass){
	if(!document.getElementById || !label) return;
		
	var form = document.getElementById(formId); //label.form;
	if(!form) return;
	
	//find radio associated with label (if in htmlFor form)
	if(label.htmlFor) {
		var e = document.getElementById(label.htmlFor);
		
		if(e.type=="checkbox"){
			e.label.className = (e.label.className==onClass) ? offClass : onClass;
			e.checked = (e.label.className==onClass);
		} else if(e.type=="radio"){
			var radioGroup = form.elements[e.name];
			if(!radioGroup) return;
			
			for(var i=0; i<radioGroup.length; i++){
				if(radioGroup[i].label){
					radioGroup[i].label.className = ((radioGroup[i].checked=(radioGroup[i].id == e.id))
													 && radioGroup[i].label) ? onClass : offClass;
				}
			}
		}
	}
}



/**
NAME: customiseInputs()

ABOUT:
 This function does all the magic. It finds the <input>'s within the passed form
 and attaches a .label reference to the element, and also adds an onClick
 function to that label to the toggleLabelStyle() function.
 It hides all radio elements from the form and mirrors the startup checked values
 in the label's customised radio button styles.

USAGE:
 Called from initARC()
 
PARAMS:
 formId   - The form we're customising
 onClass  - The CSS class name for the radio button's on style
 offClass - The CSS class name for the radio button's off style
*/
function customiseInputs(formId, onClassRadio, offClassRadio, onClassCheckbox, offClassCheckbox) {
	if(!document.getElementById) return;

	var prettyForm = document.getElementById(formId);
	if(!prettyForm) return;
		
	//onReset, reset radios to initial values
	prettyForm.onreset = function() { customiseInputs(formId, onClassRadio, offClassRadio, onClassCheckbox, offClassCheckbox); }
	
	//attach an easy to access .label reference to form elements
	addLabelProperties(prettyForm);

	var inputs = prettyForm.getElementsByTagName('input');
	for (var i=0; i < inputs.length; i++) {
		/* NB: Yeah, i know this code is duplicated - I can't figure out how to create a local, persistent
			variable within the anonymous function calls. Fix it if you can, and let me know. */
			
		//RADIO ONLY
		if( (inputs[i].type=="radio") && inputs[i].label && onClassRadio && offClassRadio){
			//hide element
			inputs[i].style.position="absolute"; inputs[i].style.left = "-1000px";
			//initialise element
			inputs[i].label.className=offClassRadio;
			//when the label is clicked, call toggleLabelStyle and toggle the label
			inputs[i].label.onclick = function (){ toggleLabelStyle(formId, this, onClassRadio, offClassRadio); return false; };
			//enable keyboard navigation
			inputs[i].onclick = function (){ toggleLabelStyle(formId, this.label, onClassRadio, offClassRadio); };
			//if the radio was checked by default, change this label's style to checked
			if(inputs[i].defaultChecked || inputs[i].checked){ toggleLabelStyle(formId, inputs[i].label, onClassRadio, offClassRadio); }
		}
		
		//CHECKBOX ONLY
		if( (inputs[i].type=="checkbox") && inputs[i].label && onClassCheckbox && offClassCheckbox){
			//hide element
			inputs[i].style.position="absolute"; inputs[i].style.left = "-1000px";
			//initialise element
			inputs[i].label.className=offClassCheckbox;
			inputs[i].checked = false;
			//when the label is clicked, call toggleLabelStyle and toggle the label
			inputs[i].label.onclick = function (){ toggleLabelStyle(formId, this, onClassCheckbox, offClassCheckbox); return false; };
			//enable keyboard navigation
			inputs[i].onclick = function (){ toggleLabelStyle(formId, this.label, onClassCheckbox, offClassCheckbox); };
			//if the radio was checked by default, change this label's style to checked
			if(inputs[i].defaultChecked || inputs[i].checked){ toggleLabelStyle(formId, inputs[i].label, onClassCheckbox, offClassCheckbox); }
		}

		if( (inputs[i].type=="checkbox") || (inputs[i].type=="radio") && inputs[i].label ){
			//Attach keyboard navigation
			if(!this.ie){ //IE has problems with this method
				//You could set these to grab a passed in class name if you wanted to
				//do something a bit more interesting for keyboard states. But for now the
				//generic dotted outline will do for most elements.
				inputs[i].label.style.margin = "1px";
				inputs[i].onfocus = function (){ this.label.style.border = "1px dotted #333"; this.label.style.margin="0px"; return false; };
				inputs[i].onblur  = function (){ this.label.style.border = "none"; this.label.style.margin="1px"; return false; };
			}
		}
}
}

WidgetUtils = {};
WidgetUtils.init = function() {
   forms = document.forms;
   for(var i=0; i<forms.length; i++) {
      forms[i].style.visibility = 'hidden';
      initARC(forms[i].id,'radioOn','radioOff','checkboxOn','checkboxOff')
      forms[i].style.visibility = 'visible';
   }
   //initARC(formId,onClassRadio,offClassRadio,onClassCheckbox,offClassCheckbox)
}
Premium = {};
Premium.email   = '';
Premium.fname   = '';
Premium.lname   = '';
Premium.cc      = '';
Premium.month   = '';
Premium.year    = '';
Premium.zip     = '';
Premium.package = null;
/*
Premium.steps   = ['package.info', 'cc.info'];
Premium.step    = 0;
*/

Premium.page = function() {
   if(User.premium) { document.location.href = '/premium-member/' }
   else { document.location.href = '/premium-nonmember/' }
}

/*
Premium.close = function() {
   DialogBox.waitBox();
   CommonLib.createCookie('DBOXCLOSE', Term.id, 0);
}
*/

Premium.parseXML = function(xml) {
   var content = CommonLib.parseElement(xml, 'content');
   var script  = CommonLib.parseElement(xml, 'script');
   if(content) {
      var width  = parseInt(CommonLib.parseElement(content, 'width'));
      var html   = CommonLib.parseElement(content, 'html');
      DialogBox.domFormBox(width, 0, html);
   }
   if(script) { eval(script); }
}

/*
Premium.getOrderForm = function(xml) {
   if(!xml) {
      //alert('Term id: ' + Term.id);
      DialogBox.waitBox();
      Term.get('/jobs-over-50/premium/ajax/get.order.form.php?termid=' + Term.id, Premium.getOrderForm);
      return;
   }
   DialogBox.close();
   Premium.parseXML(xml);
}
*/

Premium.trim = function(str) {
   return str.replace(/^\s+/, '').replace(/\s+$/, '');
}

Premium.closeAlert = function(id) {   
   DialogBox.closeAlert(id);
   var selects = document.getElementsByTagName('select');
   for(var i=0; i<selects.length; i++) {
      selects[i].style.visibility = 'visible';
      selects[i].style.display = 'block';
   }
}

Premium.closeBox = function() {
   DialogBox.closeAll();
   var href = document.location.href; 
   if(href.match(/^https/)) {
      DialogBox.waitBox();
      href = href.replace(/^https/, 'http');
      document.location.href = href;
   }
}

Premium.getCC = function(xml) {
   if(!xml) {
      DialogBox.closeAll();
      DialogBox.waitBox();
      Term.get('/jobs-over-50/premium/ajax/get.cc.php', Premium.getCC);
      return;
   }
   DialogBox.close();
   Premium.parseXML(xml);
   (document.getElementById('package.desc')).innerHTML = Packages[Premium.package]['desc'];
   if(Premium.cc) { (document.getElementById('cc_number')).value = Premium.cc; }
   else { (document.getElementById('cc_number')).focus(); }
   if(Premium.month) {
      var month   = document.getElementById('cc_month');
      var options = month.options;
      for(var i=0; i<options.length; i++) {
         if(options[i].value == Premium.month) {
            options[i].selected = true;
            break;
         }
      }
   }
   if(Premium.year) {
      var year   = document.getElementById('cc_year');
      var options = year.options;
      for(var i=0; i<options.length; i++) {
         if(options[i].value == Premium.year) {
            options[i].selected = true;
            break;
         }
      }
   }
}

Premium.setCC = function(xml) {
   if(!xml) {
      var year   = document.getElementById('cc_year');
      var month  = document.getElementById('cc_month');
      var number = Premium.trim(document.getElementById('cc_number').value);
      year  = year.options[year.selectedIndex].value;
      month = month.options[month.selectedIndex].value;
      if(!number) {
         DialogBox.alertBox('Please enter your credit card number.', "Premium.closeAlert('cc_number');", "Missing Card Number");
         return;
      }
      if(!month) {
         DialogBox.alertBox('Please select your credit card expire month.', "Premium.closeAlert();", "Missing Expire Month");
         return;
      }
      if(!year) {
         DialogBox.alertBox('Please select your credit card expire year.', "Premium.closeAlert();", "Missing Expire Year");
         return;
      }
      Premium.cc = number;
      Premium.month = month;
      Premium.year  = year;
      var package  = Packages[Premium.package];
      var data = '';

      data +=  '&uid='    + escape(User.id);
      data +=  '&email='  + escape(User.email);
      data +=  '&fname='  + escape(Premium.fname);
      data +=  '&lname='  + escape(Premium.lname);
      data +=  '&number=' + escape(Premium.cc);
      data +=  '&month='  + escape(Premium.month);
      data +=  '&year='   + escape(Premium.year);
      data +=  '&desc='   + escape(package.desc);
      data +=  '&days='   + escape(package.days);
      data +=  '&price='  + escape(package.price);
      data +=  '&index='  + escape(Premium.package);

      //alert(data);
      //return;

      DialogBox.waitBox();
      Term.post('/jobs-over-50/premium/ajax/set.purchase.php', data, null, Premium.setCC);
      return;
   }
   DialogBox.close();
   Premium.parseXML(xml);
}

Premium.setName = function() {
   var fname = Premium.trim(document.getElementById('cc_fname').value);
   var lname = Premium.trim(document.getElementById('cc_lname').value);
   if(!fname) {
      DialogBox.alertBox('Please enter your credit card first name.', "DialogBox.closeAlert('cc_fname');", "Missing First Name");
      return;
   }
   if(!lname) {
      DialogBox.alertBox('Please enter your credit card last name.', "DialogBox.closeAlert('cc_lname');", "Missing Last Name");
      return;
   }
   Premium.fname = fname;
   Premium.lname = lname;
   Premium.getCC();
}

Premium.getName = function(xml) {
   if(!xml) {
      DialogBox.closeAll();
      DialogBox.waitBox();
      Term.get('/jobs-over-50/premium/ajax/get.name.php', Premium.getName);
      return;
   }
   DialogBox.close();
   Premium.parseXML(xml);
   (document.getElementById('package.desc')).innerHTML = Packages[Premium.package]['desc'];
   if(Premium.fname) { document.getElementById('cc_fname').value = Premium.fname; }
   if(Premium.lname) { document.getElementById('cc_lname').value = Premium.lname; }
}

Premium.setPackage = function(xml) {
   var package = null;
   var inputs = document.getElementsByTagName('input');
   for(var i=0; i<inputs.length; i++) {
      if(inputs[i].type != 'radio') { continue; }
      if(inputs[i].name != 'package') { continue; }
      if(inputs[i].checked) {
         package = inputs[i].value;
         break;
      }
   }
   if(package == null) {
      DialogBox.alertBox('Please select your premium upgrade package.', "DialogBox.close();", "No Package Selected");
      return;
   }
   Premium.package = parseInt(package);
   DialogBox.close();
   Premium.getName();
}

Premium.checkPackage = function() {
   if(Premium.package != null) {
      var el = document.getElementById('p_' + Premium.package);
      el.checked = true;
      WidgetUtils.init();
   }
}

Premium.getPackage = function(xml) {
   if(!xml) {
      DialogBox.closeAll();
      DialogBox.waitBox();
      /*
      var url = "http://ww2.retirementjobs.com/jobs-over-50/premium/ajax/get.package.php";
      if(document.location.href.match(/^https/)) {
         url = url.replace(/^http/, 'https');
      }
      */
      var url = "/jobs-over-50/premium/ajax/get.package.php";
      Term.get(url, Premium.getPackage);
      return;
   }
   var script = CommonLib.parseElement(xml, 'script');
   if(script && script.match(/^document\.location\.href/)) { eval(script); return; }
   DialogBox.close();
   Premium.parseXML(xml);
}

Premium.getProfile = function(xml) {
   if(!xml) {
      DialogBox.waitBox();
      Term.get('/jobs-over-50/premium/ajax/get.profile.php', Premium.getProfile);   
      return;
   }
   DialogBox.close();
   Premium.parseXML(xml);
}

Premium.setProfile = function(xml) {
   if(!xml) {
      var fname = document.getElementById('premium_fname').value;
      var lname = document.getElementById('premium_lname').value;
      var zip   = document.getElementById('premium_zip').value;
      if(!fname) {
         DialogBox.alertBox('Please enter your first name.', "Term.setFocus('premium_fname');DialogBox.close();", "Missing First Name");
         return;
      }
      if(!lname) {
         DialogBox.alertBox('Please enter your last name.', "Term.setFocus('premium_lname');DialogBox.close();", "Missing Last Name");
         return;
      }
      if(!zip) {
         DialogBox.alertBox('Please enter your Zip Code.', "Term.setFocus('premium_zip');DialogBox.close();", "Missing Zip Code");
         return;
      }
      if(zip.length != 5 || !zip.match(/^[0-9]+$/)) {
         DialogBox.alertBox('Please enter your five digit Zip code.', "Term.setFocus('premium_zip');DialogBox.close();", "Malformed Zip Code");
      }

      Premium.fname = fname;
      Premium.lname = lname;
      Premium.zip   = zip;

      DialogBox.waitBox();

      var url = '/jobs-over-50/premium/ajax/set.profile.php';
      url += User.email ? '?email=' + escape(User.email) : '?email=' + escape(Premium.email);
      url += '&fname=' + escape(Premium.fname);
      url += '&lname=' + escape(Premium.lname);
      url += '&zip='   + escape(Premium.zip);

      //alert(url);
      //return;

      Term.get(url, Premium.setProfile);
     
      return;
   }
 
   DialogBox.close();
   Premium.parseXML(xml);
}

Premium.getEmail = function(xml) {
   if(!xml) {
      DialogBox.waitBox();
      Term.get('/jobs-over-50/premium/ajax/get.email.php', Premium.getEmail);
      return;
   }
   DialogBox.close();
   Premium.parseXML(xml);
}

Premium.setEmail = function(xml) {
   if(!xml) {
      var email_1 = document.getElementById('premium_email_1').value.toLowerCase();
      var email_2 = document.getElementById('premium_email_2').value.toLowerCase();;
      if(!email_1) {
         DialogBox.alertBox('Please enter your email address.', "Term.setFocus('premium_email_1');DialogBox.close();", "Missing Email Address");
         return;
      }

      if(!email_2) {
         DialogBox.alertBox('Please enter your confirmation email address.', "Term.setFocus('premium_email_2');DialogBox.close();", 
         "Missing Confirmation Email Address");
         return;
      }

      if(email_1 != email_2) {
         DialogBox.alertBox("Your email addresses don't match.", "Term.setFocus('premium_email_2');DialogBox.close();",
         "Mismatched Email Addresses");
         return;
      }

      if(!CommonLib.isValidEmail(email_1)) {
         DialogBox.alertBox('Your email address is malformed.', "Term.setFocus('premium_email_1');DialogBox.close();", "Malformed Email Address");
         return;
      }
      Premium.email = email_1;

      DialogBox.waitBox();
      Term.get('/jobs-over-50/premium/ajax/set.email.php?email=' + escape(Premium.email), Premium.setEmail);
      return;
   }
   DialogBox.close();
   Premium.parseXML(xml);
}

Premium.getCheckPassword = function(xml) {
   if(!xml) {
      DialogBox.waitBox();
      Term.get('/jobs-over-50/premium/ajax/get.check.password.php?email=' + escape(Premium.email), Premium.getCheckPassword);
      return;
   }
   DialogBox.close();
   Premium.parseXML(xml);
}

Premium.setCheckPassword = function(xml) {
   if(!xml) {
      var pass = document.getElementById('premium_password').value;
      if(!pass) {
         DialogBox.alertBox('Please enter your password.', "Term.setFocus('premium_password');DialogBox.close();", "Missing Password");
         return;
      }
      var url = '/jobs-over-50/premium/ajax/set.check.password.php?email=' + escape(Premium.email) + '&pass=' + escape(pass);
      DialogBox.waitBox();
      Term.get(url, Premium.setCheckPassword);
      return;
   }
   DialogBox.close();
   Premium.parseXML(xml);
}

Premium.upgrade = function(xml) {
   if(User.premium) {
      DialogBox.confirmBox('Already Premium', '<b>' + User.fname + '</b>, you are already a premium member. Do you want to go to your premium page?', 
                           "DialogBox.close();DialogBox.waitBox();document.location.href='/premium-member/';", 'DialogBox.close();');
      return;
   }
   if(!User.id) { Premium.getEmail(); return;}
   if(!User.fname || !User.lname || !User.zip) { Premium.getProfile(); return;}
   Premium.getPackage();
   return;
}
PostJob = {};
PostJob.jobid    = 0;
PostJob.title    = '';
PostJob.zip      = '';
PostJob.city     = '';
PostJob.state    = '';
PostJob.company  = '';
PostJob.email    = '';
PostJob.url      = '';
PostJob.desc     = '';
PostJob.status   = '';
PostJob.days     = 0;
PostJob.fname    = '';
PostJob.lname    = '';
PostJob.cc       = '';
PostJob.month    = '';
PostJob.year     = '';
PostJob.package  = {};
PostJob.employer = 'ecom';
PostJob.maxdays  = 30;

PostJob.reset = function() {

   PostJob.jobid    = 0;
   PostJob.title    = '';
   PostJob.zip      = '';
   PostJob.city     = '';
   PostJob.state    = '';
   PostJob.company  = '';
   PostJob.email    = '';
   PostJob.url      = '';
   PostJob.desc     = '';
   PostJob.status   = '';
   PostJob.days     = 0;
   PostJob.fname    = '';
   PostJob.lname    = '';
   PostJob.cc       = '';
   PostJob.month    = '';
   PostJob.year     = '';
   PostJob.package  = {};
   PostJob.employer = 'ecom';
   PostJob.maxdays  = 30;
}


PostJob.parseXML = function(xml) {
   var content = CommonLib.parseElement(xml, 'content');
   var script  = CommonLib.parseElement(xml, 'script');
   if(content) {
      var width  = parseInt(CommonLib.parseElement(content, 'width'));
      var html   = CommonLib.parseElement(content, 'html');
      DialogBox.domFormBox(width, 0, html);
   }
   if(script) { eval(script); }
}

PostJob.trim = function(str) {
   return str.replace(/^\s+/, '').replace(/\s+$/, '');
}

PostJob.closeBox = function(xml) {
   if(typeof(xml) == 'number' && xml == 0) {
      DialogBox.closeAll();
      return;
   }
   if(!xml) {
      DialogBox.closeAll();
      PostJob.reset();
      DialogBox.waitBox();
      Term.get('/jobs-over-50/post.job/ajax/set.close.box.php', PostJob.closeBox);
      return;
   }
   DialogBox.close();
   PostJob.parseXML(xml);
}

PostJob.closeJobAlert = function(id) {
   DialogBox.close();
   var el = document.getElementById(id);
   if(el) { el.focus(); }
   el = document.getElementById('postjob_status');
   if(el) {
      el.style.display    = 'block';
      el.style.visibility = 'visible';
   }
}

PostJob.getCheckPassword = function(xml) {
   if(!xml) {
      DialogBox.waitBox();
      Term.get('/jobs-over-50/post.job/ajax/get.check.password.php?email=' + escape(PostJob.email), PostJob.getCheckPassword);
      return;
   }
   DialogBox.close();
   PostJob.parseXML(xml);
}

PostJob.setCheckPassword = function(xml) {
   if(!xml) {
      var pass = document.getElementById('postjob_password').value;
      if(!pass) {
         DialogBox.alertBox('Please enter your password.', "Term.setFocus('postjob_password');DialogBox.close();", "Missing Password");
         return;
      }
      var url = '/jobs-over-50/post.job/ajax/set.check.password.php?email=' + escape(PostJob.email) + '&pass=' + escape(pass);
      DialogBox.waitBox();
      Term.get(url, PostJob.setCheckPassword);
      return;
   }
   DialogBox.close();
   PostJob.parseXML(xml);
}

/*
$jobid   = intval(trim($_REQUEST['jobid']));
$desc    = trim($_REQUEST['desc']);
$uid     = trim($_REQUEST['uid']);
$title   = trim($_REQUEST['title']);
$company = trim($_REQUEST['company']);
$status  = trim($_REQUEST['status']);
$city    = trim($_REQUEST['city']);
$state   = trim($_REQUEST['state']);
$zip     = trim($_REQUEST['zip']);
$email   = trim($_REQUEST['email']);
*/

PostJob.setEdit = function(xml) {
   if(!xml) {

      var data = '';
      data    +=  '&uid='     + escape(User.id);
      data    +=  '&email='   + escape(PostJob.email);
      data    +=  '&url='     + escape(PostJob.url);
      data    +=  '&desc='    + escape(PostJob.desc);
      data    +=  '&title='   + escape(PostJob.title);
      data    +=  '&company=' + escape(PostJob.company);
      data    +=  '&city='    + escape(PostJob.city);
      data    +=  '&state='   + escape(PostJob.state);
      data    +=  '&zip='     + escape(PostJob.zip);
      data    +=  '&status='  + escape(PostJob.status);
      data    +=  '&jobid='   + escape(PostJob.jobid);
      data    +=  '&days='    + escape(PostJob.days);

      //alert(data);
      //return;

      DialogBox.waitBox();
      Term.post('/jobs-over-50/post.job/ajax/set.edit.php', data, null, PostJob.setEdit);
      return;
   }
   DialogBox.close();
   PostJob.parseXML(xml);

}

PostJob.setCC = function(xml) {
   if(!xml) {
      var year   = document.getElementById('cc_year');
      var month  = document.getElementById('cc_month');
      var number = PostJob.trim(document.getElementById('cc_number').value);
      year  = year.options[year.selectedIndex].value;
      month = month.options[month.selectedIndex].value;
      if(!number) {
         DialogBox.alertBox('Please enter your credit card number.', "Premium.closeAlert('cc_number');", "Missing Card Number");
         return;
      }
      if(!month) {
         DialogBox.alertBox('Please select your credit card expire month.', "Premium.closeAlert();", "Missing Expire Month");
         return;
      }
      if(!year) {
         DialogBox.alertBox('Please select your credit card expire year.', "Premium.closeAlert();", "Missing Expire Year");
         return;
      }
      PostJob.cc    = number;
      PostJob.month = month;
      PostJob.year  = year;

      var data = '';
      data    +=  '&uid='     + escape(User.id);
      data    +=  '&email='   + escape(PostJob.email);
      data    +=  '&fname='   + escape(PostJob.fname);
      data    +=  '&lname='   + escape(PostJob.lname);
      data    +=  '&number='  + escape(PostJob.cc);
      data    +=  '&month='   + escape(PostJob.month);
      data    +=  '&year='    + escape(PostJob.year);
      data    +=  '&desc='    + escape(PostJob.desc);
      data    +=  '&price='   + escape(PostJob.package['price']);
      data    +=  '&package=' + escape(PostJob.package['desc']);
      data    +=  '&title='   + escape(PostJob.title);
      data    +=  '&company=' + escape(PostJob.company);
      data    +=  '&city='    + escape(PostJob.city);
      data    +=  '&state='   + escape(PostJob.state);
      data    +=  '&zip='     + escape(PostJob.zip);
      data    +=  '&status='  + escape(PostJob.status);

      //alert(data);
      //return;

      DialogBox.waitBox();
      Term.post('/jobs-over-50/post.job/ajax/set.purchase.php', data, null, PostJob.setCC);
      return;
   }
   DialogBox.close();
   PostJob.parseXML(xml);
}

PostJob.getCC = function(xml) {
   if(!xml) {
      DialogBox.closeAll();
      DialogBox.waitBox();
      Term.get('/jobs-over-50/post.job/ajax/get.cc.php', PostJob.getCC);
      return;
   }
   DialogBox.close();
   PostJob.parseXML(xml);
   (document.getElementById('package.desc')).innerHTML = PostJob.package['desc'];
   if(PostJob.cc) { (document.getElementById('cc_number')).value = PostJob.cc; }
   else { (document.getElementById('cc_number')).focus(); }
   if(PostJob.month) {
      var month   = document.getElementById('cc_month');
      var options = month.options;
      for(var i=0; i<options.length; i++) {
         if(options[i].value == PostJob.month) {
            options[i].selected = true;
            break;
         }
      }
   }
   if(PostJob.year) {
      var year   = document.getElementById('cc_year');
      var options = year.options;
      for(var i=0; i<options.length; i++) {
         if(options[i].value == PostJob.year) {
            options[i].selected = true;
            break;
         }
      }
   }
}


PostJob.setName = function() {
   var fname = PostJob.trim(document.getElementById('cc_fname').value);
   var lname = PostJob.trim(document.getElementById('cc_lname').value);
   if(!fname) {
      DialogBox.alertBox('Please enter your credit card first name.', "DialogBox.closeAlert('cc_fname');", "Missing First Name");
      return;
   }
   if(!lname) {
      DialogBox.alertBox('Please enter your credit card last name.', "DialogBox.closeAlert('cc_lname');", "Missing Last Name");
      return;
   }
   PostJob.fname = fname;
   PostJob.lname = lname;
   PostJob.getCC();
}


PostJob.getName = function(xml) {
   if(!xml) {
      DialogBox.closeAll();
      DialogBox.waitBox();
      Term.get('/jobs-over-50/post.job/ajax/get.name.php', PostJob.getName);
      return;
   }
   DialogBox.close();
   PostJob.parseXML(xml);
   (document.getElementById('package.desc')).innerHTML = PostJob.package['desc'];
   if(PostJob.fname) { document.getElementById('cc_fname').value = PostJob.fname; }
   if(PostJob.lname) { document.getElementById('cc_lname').value = PostJob.lname; }
}

PostJob.getPreview = function(xml) {
   if(!xml) {
      DialogBox.closeAll();
      DialogBox.waitBox();

      var data = '';
      data += '&desc='    + escape(PostJob.desc);
      data += '&title='   + escape(PostJob.title);
      data += '&company=' + escape(PostJob.company);
      data += '&city='    + escape(PostJob.city);
      data += '&state='   + escape(PostJob.state);
      data += '&zip='     + escape(PostJob.zip);
      data += '&status='  + escape(PostJob.status);
      data += '&jobid='   + escape(PostJob.jobid);

      Term.post('/jobs-over-50/post.job/ajax/get.preview.php', data, null, PostJob.getPreview);
      return;
   }
   DialogBox.close();
   PostJob.parseXML(xml);
}

PostJob.setDesc = function(xml) {
   if(!xml) {
      var desc = document.getElementById('postjob_desc').value;
      DialogBox.waitBox();
      Term.post('/jobs-over-50/post.job/ajax/set.desc.php', 'desc=' + escape(desc), null, PostJob.setDesc);
      return;
   }
   DialogBox.close();
   var desc = CommonLib.parseElement(xml, 'desc');
   PostJob.desc = desc.replace(/\[\[n\]\]/, "\n");
   document.getElementById('postjob_desc').value = desc;
   PostJob.parseXML(xml);
}

PostJob.getDesc = function(xml) {

   if(!xml) {
      DialogBox.closeAll();
      DialogBox.waitBox();
      var url = "/jobs-over-50/post.job/ajax/get.desc.php?jobid=" + PostJob.jobid;
      Term.get(url, PostJob.getDesc);
      return;
   }
   DialogBox.close();
   PostJob.parseXML(xml);
   PostJob.desc = PostJob.desc.replace(/\[\[n\]\]/g, "\n");

   var desc = PostJob.desc;
   desc = desc.replace(/\<br\s+\/\>/g, "\n");
   desc = desc.replace(/\<p\s+\/\>/g, "\n");
   desc = desc.replace(/\n\n+/g, "\n\n");
   PostJob.desc = desc;


   if(PostJob.desc)   { (document.getElementById('postjob_desc')).value = PostJob.desc; }
   (document.getElementById('postjob_desc')).focus();
   

   /*
   var script = CommonLib.parseElement(xml, 'script');
   if(script && script.match(/^document\.location\.href/)) { eval(script); return; }
   DialogBox.close();
   PostJob.parseXML(xml);
   if(PostJob.title)   { (document.getElementById('postjob_title')).value = PostJob.title; }
   if(PostJob.zip)     { (document.getElementById('postjob_zip')).value = PostJob.zip; }
   if(PostJob.company) { (document.getElementById('postjob_company')).value = PostJob.company; }
   if(PostJob.email)   { (document.getElementById('postjob_email')).value = PostJob.email; }

   if(!document.getElementById('postjob_title').value) { document.getElementById('postjob_title').focus(); return; }
   if(!document.getElementById('postjob_zip').value) { document.getElementById('postjob_zip').focus(); return; }
   if(!document.getElementById('postjob_company').value) { document.getElementById('postjob_company').focus(); return; }
   if(!document.getElementById('postjob_email').value) { document.getElementById('postjob_email').focus(); return; }
   */
}


PostJob.setJob = function(xml) {
   if(!xml) {

      var title    = PostJob.trim(document.getElementById('postjob_title').value);
      var zip      = PostJob.trim(document.getElementById('postjob_zip').value);
      var company  = PostJob.trim(document.getElementById('postjob_company').value);
      var email    = PostJob.trim(document.getElementById('postjob_email').value);
      var url      = PostJob.trim(document.getElementById('postjob_url').value);
      var days     = PostJob.trim(document.getElementById('postjob_days').value);
      
      var status   = document.getElementById('postjob_status');
      status = status.options[status.selectedIndex].value;

      if(!title) {
         DialogBox.alertBox('Please enter your job title.', "PostJob.closeJobAlert('postjob_title');", "Missing Job Title");
         return;
      }
      if(title.length > 80) {
         DialogBox.alertBox("Your job title can't be longer than 80 characters.", "PostJob.closeJobAlert('postjob_title');", "Title Too Long");
         return;
      }
      if(!zip) {
         DialogBox.alertBox('Please enter your Zip Code.', "PostJob.closeJobAlert('postjob_zip');", "Missing Zip Code");
         return;
      }
      if(!zip.match(/^[0-9][0-9][0-9][0-9][0-9]$/)) {
         DialogBox.alertBox('Please enter your five digit Zip Code.', "PostJob.closeJobAlert('postjob_zip');", "Invalid Zip Code");
         return;
      }
      if(!company) {
         DialogBox.alertBox('Please enter your company name.', "PostJob.closeJobAlert('postjob_company');", "Missing Company Name");
         return;
      }
      if(!status) {
         DialogBox.alertBox('Please select your job status.', "PostJob.closeJobAlert('postjob_status');", "Missing Job Status");
         return;
      }

      if(PostJob.employer == 'contract') {
         if(!email && !url) {
            DialogBox.alertBox('Please enter either job apply email address or URL.', "PostJob.closeJobAlert('postjob_email');", "Missing Apply Method");
            return;
         }
         if(email && url) {
            DialogBox.alertBox('Please enter either a job apply email address or URL, but not both.', "PostJob.closeJobAlert('postjob_email');", "Extra Apply Method");
            return;
         }
         if(!days) {
            DialogBox.alertBox('Please enter the number of days this job will be active.', "PostJob.closeJobAlert('postjob_days');", "Missing Job Active Days");
            return;
         }
         if(!days.match(/^[0-9]+$/)) {
            DialogBox.alertBox('Please enter the number of days this job will be active as a number', 
                               "PostJob.closeJobAlert('postjob_days');", "Wrong Type Job Active Days");
            return;
         }
         if(parseInt(days) > parseInt(PostJob.maxdays)) {
            var msg = "Job active days can't exceed " + PostJob.maxdays + '.';
            DialogBox.alertBox(msg, "PostJob.closeJobAlert('postjob_days');", "Excessive Job Active Days");
            return;
         }
      } else if(!email) {
         DialogBox.alertBox('Please enter your job apply email address.', "PostJob.closeJobAlert('postjob_email');", "Missing Email Address");
         return;
      }

      if(email && !CommonLib.isValidEmail(email)) {
         DialogBox.alertBox('Your apply email address is malformed.', "PostJob.closeJobAlert('postjob_email');", "Malformed Email Address");
         return;
      }
      if(url && !CommonLib.isValidURL(url)) {
         DialogBox.alertBox('Your apply URL is malformed.', "PostJob.closeJobAlert('postjob_url');", "Malformed URL");
         return;
      }

      days = days ? parseInt(days) : 0;

      PostJob.title   = title;
      PostJob.zip     = zip;
      PostJob.company = company;
      PostJob.email   = email;
      PostJob.status  = status;
      PostJob.url     = url;
      PostJob.days    = days;

      data  = '';
      data += '&title='   + escape(title);
      data += '&zip='     + escape(zip);
      data += '&company=' + escape(company);
      data += '&email='   + escape(email);
      data += '&url='     + escape(url);
      data += '&jobid='   + escape(PostJob.jobid);
      data += '&days='    + escape(PostJob.days);
      
      var url = '/jobs-over-50/post.job/ajax/set.job.php' + data.replace(/^\&/, '?');
      DialogBox.waitBox();
      Term.get(url, PostJob.setJob);
      return;
   }

   DialogBox.close();
   PostJob.parseXML(xml);
}

PostJob.getInfo = function(xml) {
   var jobid = 0;
   if(typeof(xml) == 'number') {
      jobid = xml;
      xml = '';
   }
   if(!xml) {
      DialogBox.waitBox();
      Term.get('/jobs-over-50/post.job/ajax/get.info.php?jobid=' + jobid, PostJob.getInfo);
      return;
   }
   DialogBox.close();
   PostJob.parseXML(xml);
}

PostJob.getJob = function(xml) {

   if(typeof(xml) == 'number') {
      PostJob.jobid = xml;
      xml = '';
   }

   if(!xml) {
      DialogBox.closeAll();
      DialogBox.waitBox();
      var url = "/jobs-over-50/post.job/ajax/get.job.php?jobid=" + PostJob.jobid;
      Term.get(url, PostJob.getJob);
      return;
   }
   var prescript = CommonLib.parseElement(xml, 'prescript');
   if(!PostJob.title && prescript) {
      eval(prescript);
      PostJob.desc = PostJob.desc.replace(/\[\[n\]\]/, "\n");
   }
   var script    = CommonLib.parseElement(xml, 'script');
   if(script && script.match(/^document\.location\.href/)) { eval(script); return; }
   DialogBox.close();
   PostJob.parseXML(xml);

   if(PostJob.title)   { (document.getElementById('postjob_title')).value = PostJob.title; }
   if(PostJob.zip)     { (document.getElementById('postjob_zip')).value = PostJob.zip; }
   if(PostJob.company) { (document.getElementById('postjob_company')).value = PostJob.company; }
   if(PostJob.email)   { (document.getElementById('postjob_email')).value = PostJob.email; }
   if(PostJob.url)     { (document.getElementById('postjob_url')).value = PostJob.url; }
   if(PostJob.days)    { (document.getElementById('postjob_days')).value = PostJob.days; }

   if(PostJob.status) {
      var status   = document.getElementById('postjob_status');
      var options = status.options;
      for(var i=0; i<options.length; i++) {
         if(options[i].value == PostJob.status) {
            options[i].selected = true;
            break;
         }
      }
   }

   if(!document.getElementById('postjob_title').value) { document.getElementById('postjob_title').focus(); return; }
   if(!document.getElementById('postjob_zip').value) { document.getElementById('postjob_zip').focus(); return; }
   if(!document.getElementById('postjob_company').value) { document.getElementById('postjob_company').focus(); return; }
   if(!document.getElementById('postjob_email').value) { document.getElementById('postjob_email').focus(); return; }
}

PostJob.setProfile = function(xml) {
   if(!xml) {
      var fname = document.getElementById('postjob_fname').value;
      var lname = document.getElementById('postjob_lname').value;
      var zip   = document.getElementById('postjob_zip').value;
      if(!fname) {
         DialogBox.alertBox('Please enter your first name.', "Term.setFocus('postjob_fname');DialogBox.close();", "Missing First Name");
         return;
      }
      if(!lname) {
         DialogBox.alertBox('Please enter your last name.', "Term.setFocus('postjob_lname');DialogBox.close();", "Missing Last Name");
         return;
      }
      if(!zip) {
         DialogBox.alertBox('Please enter your Zip Code.', "Term.setFocus('postjob_zip');DialogBox.close();", "Missing Zip Code");
         return;
      }
      if(zip.length != 5 || !zip.match(/^[0-9]+$/)) {
         DialogBox.alertBox('Please enter your five digit Zip code.', "Term.setFocus('postjob_zip');DialogBox.close();", "Malformed Zip Code");
      }

      PostJob.fname = fname;
      PostJob.lname = lname;
      PostJob.zip   = zip;

      DialogBox.waitBox();

      var url = '/jobs-over-50/post.job/ajax/set.profile.php';
      url += User.email ? '?email=' + escape(User.email) : '?email=' + escape(PostJob.email);
      url += '&fname=' + escape(PostJob.fname);
      url += '&lname=' + escape(PostJob.lname);
      url += '&zip='   + escape(PostJob.zip);
      Term.get(url, PostJob.setProfile);

      return;
   }

   DialogBox.close();
   PostJob.parseXML(xml);
}

PostJob.getProfile = function(xml) {
   if(!xml) {
      DialogBox.waitBox();
      Term.get('/jobs-over-50/post.job/ajax/get.profile.php', PostJob.getProfile);
      return;
   }
   DialogBox.close();
   PostJob.parseXML(xml);
}

PostJob.setEmail = function(xml) {
   if(!xml) {
      var email_1 = document.getElementById('postjob_email_1').value.toLowerCase();
      var email_2 = document.getElementById('postjob_email_2').value.toLowerCase();;
      if(!email_1) {
         DialogBox.alertBox('Please enter your email address.', "Term.setFocus('postjob_email_1');DialogBox.close();", "Missing Email Address");
         return;
      }

      if(!email_2) {
         DialogBox.alertBox('Please enter your confirmation email address.', "Term.setFocus('postjob_email_2');DialogBox.close();",
         "Missing Confirmation Email Address");
         return;
      }

      if(email_1 != email_2) {
         DialogBox.alertBox("Your email addresses don't match.", "Term.setFocus('postjob_email_2');DialogBox.close();",
         "Mismatched Email Addresses");
         return;
      }

      if(!CommonLib.isValidEmail(email_1)) {
         DialogBox.alertBox('Your email address is malformed.', "Term.setFocus('postjob_email_1');DialogBox.close();", "Malformed Email Address");
         return;
      }

      PostJob.email = email_1;

      DialogBox.waitBox();
      Term.get('/jobs-over-50/post.job/ajax/set.email.php?email=' + escape(PostJob.email), PostJob.setEmail);
      return;
   }
   DialogBox.close();
   PostJob.parseXML(xml);
}

PostJob.getEmail = function(xml) {
   if(!xml) {
      DialogBox.waitBox();
      Term.get('/jobs-over-50/post.job/ajax/get.email.php', PostJob.getEmail);
      return;
   }
   DialogBox.close();
   PostJob.parseXML(xml);
}

PostJob.over = function(el) { el.style.backgroundColor = '#E59275'; }
PostJob.out  = function(el) { el.style.backgroundColor = '#DDDDDD'; }

PostJob.getJobs = function(xml) {
   if(!xml) {
      DialogBox.waitBox();
      Term.get('/jobs-over-50/post.job/ajax/get.jobs.php', PostJob.getJobs);
      return;
   }
   DialogBox.close();
   PostJob.parseXML(xml);
}

PostJob.reallyDelete = function(xml) {
   var jobid = 0;
   if(typeof(xml) == 'number') {
      jobid = xml;
      xml   = '';
   }
   if(!xml) {
      DialogBox.closeAll();
      DialogBox.waitBox();
      var url = '/jobs-over-50/post.job/ajax/set.delete.php?jobid=' + jobid;
      Term.get(url, PostJob.reallyDelete);
      return;
   }
   DialogBox.close();
   PostJob.parseXML(xml);
}

PostJob.expire = function(jobid) {
   DialogBox.confirmBox('Really Delete?', 'Are you really quite certain you want to delete this job?', 
                        'DialogBox.close();PostJob.reallyDelete('+jobid+')', 'DialogBox.close()');
}

PostJob.getStart = function(xml) {
   if(!xml) {
      DialogBox.waitBox();
      Term.get('/jobs-over-50/post.job/ajax/get.start.php', PostJob.getStart);
      return;
   }
   DialogBox.close();
   PostJob.parseXML(xml);
}

PostJob.start = function() {
   if(!User.id) { PostJob.getEmail(); return;}
   if(!User.fname || !User.lname || !User.zip) { PostJob.getProfile(); return;}
   PostJob.getStart();
   return;
}
Apply = {};
Apply.jobid       = 0;
Apply.message     = "";
Apply.subject     = "";
Apply.email       = "";
Apply.url         = "";
Apply.title       = "";
Apply.company     = "";
Apply.city        = "";
Apply.state       = "";
Apply.resume      = "";
Apply.resname     = "";
Apply.resid       = 0;

Apply.getApplyStart = function(xml) {

   if(!xml) {
      DialogBox.closeAll();
      DialogBox.waitBox();
      Term.get('/jobs-over-50/apply/ajax/get.apply.start.php?jobid=' + escape(Apply.jobid), Apply.getApplyStart);
      return;
   }
   DialogBox.close();
   Apply.parseXML(xml);
}

Apply.saveResume = function(xml) {
   var callback = '';
   if(xml && xml.match(/^Apply\./)) {
      callback = xml;
      xml = '';
   }
   if(!xml) {
      var name = Apply.trim(document.getElementById('resume_name').value);
      var text = Apply.trim(document.getElementById('resume_text').value);
      if(!Apply.name && !name) {
         DialogBox.alertBox('Please enter a name for this resume.', "Term.setFocus('resume_name');DialogBox.close();", "Missing Resume Name");
         return;
      }
      if(!text) {
         DialogBox.alertBox('Please copy and paste your text for this resume.', "Term.setFocus('resume_text');DialogBox.close();", "Missing Resume Text");
         return;
      }
      Apply.resname   = name;
      Apply.resume    = text;
      var data = '';
      data    += '&resid='    + escape(Apply.resid); 
      data    += '&resname='  + escape(Apply.resname); 
      data    += '&resume='   + escape(Apply.resume); 
      data    += '&callback=' + escape(callback);

      DialogBox.waitBox();
      Term.post('/jobs-over-50/apply/ajax/set.save.resume.php', data, null, Apply.saveResume);
      return;
   }
   DialogBox.close();
   Apply.parseXML(xml);
}

Apply.reallyGetCoverLetter = function(xml) {
   if(!xml) {
      Apply.resname = Apply.trim(document.getElementById('resume_name').value);
      Apply.resume  = Apply.trim(document.getElementById('resume_text').value);
      DialogBox.closeAll();
      DialogBox.waitBox();
      var url = '/jobs-over-50/apply/ajax/get.cover.letter.php?title=' + escape(Apply.title);
      Term.get(url, Apply.reallyGetCoverLetter);
      return;
   }
   DialogBox.close();
   Apply.parseXML(xml);
   var subject = Apply.trim(document.getElementById('cover_subject').value);
   var message = Apply.trim(document.getElementById('cover_message').value);
   if((!subject && !message) && (Apply.subject && Apply.message)) {
      document.getElementById('cover_subject').value = Apply.subject;
      document.getElementById('cover_message').value = Apply.message;
   }
}


Apply.getCoverLetter = function() {
   var name = Apply.trim(document.getElementById('resume_name').value);
   var text = Apply.trim(document.getElementById('resume_text').value);
   if(!text) {
      DialogBox.alertBox('Please copy and past your resume.', "Term.setFocus('resume_text');DialogBox.close();", "Missing Resume");
      return;
   }
   if(text != Apply.resume || name != Apply.resname) {
      DialogBox.confirmBox("Unsaved Changes", "There are unsaved changes. Do you want to save changes permanently?",
      "DialogBox.close();Apply.saveResume('Apply.reallyGetCoverLetter();');", "DialogBox.close();Apply.reallyGetCoverLetter();");
      return;
   }
   Apply.reallyGetCoverLetter();
}

Apply.getResume = function(xml) {
   if(!xml) {

      var subject = document.getElementById('cover_subject');
      var message = document.getElementById('cover_message');
      if(subject && message) {
         Apply.subject = Apply.trim(subject.value);
         Apply.message = Apply.trim(message.value);
      }

      var data = '';
      data    += '&jobid=' + escape(Apply.jobid);
      data    += '&resid=' + escape(Apply.resid);
      data    += '&title=' + escape(Apply.title);
      data    += '&city='  + escape(Apply.city);
      data    += '&state=' + escape(Apply.state);

      DialogBox.closeAll();
      DialogBox.waitBox();
      Term.post('/jobs-over-50/apply/ajax/get.resume.php', data, null, Apply.getResume);
      return;
   }
   DialogBox.closeAll();
   DialogBox.close();
   Apply.parseXML(xml);
   var resume = CommonLib.parseElement(xml, 'resume');
   if(resume) { Apply.resume = resume; }
   var resname = CommonLib.parseElement(xml, 'resname');
   if(resname) { Apply.resname = resname; }
}

Apply.maybeGetSelectResume = function() {
   var name   = Apply.trim(document.getElementById('resume_name').value)
   var text = Apply.trim(document.getElementById('resume_text').value)
   if(name != Apply.resname || text != Apply.resume) {
      DialogBox.confirmBox("Unsaved Changes", "There are unsaved changes. Do you want to save changes permanently?",
      "DialogBox.close();Apply.saveResume('Apply.getSelectResume();');", "DialogBox.close();Apply.getSelectResume();");
      return;
   }
   Apply.getSelectResume();
}

Apply.getSelectResume = function(xml) {
   Apply.resid   = 0;
   Apply.resume  = '';
   Apply.resname = '';
   if(!xml) {
      //alert('fetching select resume');
      if(document.getElementById('resumelist')) {
         //alert('found id resumelist');
         var resid = 0;
         var inputs = document.getElementsByTagName('input');
         for(var i=0; i<inputs.length; i++) {
            if(inputs[i].type != 'radio') { continue; }
            if(inputs[i].name != 'resume') { continue; }
            if(inputs[i].checked) {
               resid = parseInt(inputs[i].value);
               break;
            }
         }
         Apply.resid = resid;
         Apply.getResume();
         return;
      }
      DialogBox.closeAll();
      DialogBox.waitBox();
      Term.get('/jobs-over-50/apply/ajax/get.select.resume.php?jobid=' + escape(Apply.jobid), Apply.getSelectResume);
      return;
   }
   DialogBox.closeAll();
   Apply.parseXML(xml);
   var resume = CommonLib.parseElement('xml', 'resume');
   if(resume) { Apply.resume = resume; }
}

Apply.applyATS = function() {
   DialogBox.closeAll();
   window.open('/jobs-over-50/apply/apply.ats.php?jobid=' + escape(Apply.jobid), '_blank');
}

Apply.reset = function() {
   Apply.jobid       = 0;
   Apply.message     = "";
   Apply.subject     = "";
   Apply.email       = "";
   Apply.url         = "";
   Apply.title       = "";
   Apply.company     = "";
   Apply.city        = "";
   Apply.state       = "";
   Apply.resume      = "";
   Apply.resname     = "";
   Apply.resid       = "";
}


Apply.start = function(jobid) {
   Apply.reset();
   Apply.jobid = jobid;
   if(!User.id) { Apply.getEmail(); return;}
   if(!User.fname || !User.lname || !User.zip) { Apply.getProfile(); return;}
   Apply.getApplyStart();
}

Apply.parseXML = function(xml) {
   var content = CommonLib.parseElement(xml, 'content');
   var script  = CommonLib.parseElement(xml, 'script');
   if(content) {
      var width  = parseInt(CommonLib.parseElement(content, 'width'));
      var html   = CommonLib.parseElement(content, 'html');
      DialogBox.domFormBox(width, 0, html);
   }
   if(script) { eval(script); }
}

Apply.trim = function(str) {
   return str.replace(/^\s+/, '').replace(/\s+$/, '');
}

Apply.setEmail = function(xml) {
   if(!xml) {
      var email_1 = Apply.trim(document.getElementById('apply_email_1').value.toLowerCase());
      var email_2 = Apply.trim(document.getElementById('apply_email_2').value.toLowerCase());
      if(!email_1) {
         DialogBox.alertBox('Please enter your email address.', "Term.setFocus('apply_email_1');DialogBox.close();", "Missing Email Address");
         return;
      }

      if(!email_2) {
         DialogBox.alertBox('Please enter your confirmation email address.', "Term.setFocus('apply_email_2');DialogBox.close();",
         "Missing Confirmation Email Address");
         return;
      }

      if(email_1 != email_2) {
         DialogBox.alertBox("Your email addresses don't match.", "Term.setFocus('apply_email_2');DialogBox.close();",
         "Mismatched Email Addresses");
         return;
      }

      if(!CommonLib.isValidEmail(email_1)) {
         DialogBox.alertBox('Your email address is malformed.', "Term.setFocus('apply_email_1');DialogBox.close();", "Malformed Email Address");
         return;
      }

      Apply.email = email_1;

      var url = '/jobs-over-50/apply/ajax/set.email.php?email=' + escape(Apply.email);

      DialogBox.waitBox();
      Term.get(url, Apply.setEmail);
      return;
   }
   DialogBox.close();
   Apply.parseXML(xml);
}


Apply.getEmail = function(xml) {
   if(!xml) {
      DialogBox.waitBox();
      Term.get('/jobs-over-50/apply/ajax/get.email.php', Apply.getEmail);
      return;
   }
   DialogBox.close();
   Apply.parseXML(xml);
}

Apply.getCheckPassword = function(xml) {
   if(!xml) {
      DialogBox.waitBox();
      Term.get('/jobs-over-50/apply/ajax/get.check.password.php?email=' + escape(Apply.email), Apply.getCheckPassword);
      return;
   }
   DialogBox.close();
   Apply.parseXML(xml);
}

Apply.setCheckPassword = function(xml) {
   if(!xml) {
      var pass = Apply.trim(document.getElementById('apply_password').value);
      if(!pass) {
         DialogBox.alertBox('Please enter your password.', "Term.setFocus('apply_password');DialogBox.close();", "Missing Password");
         return;
      }
      var url = '/jobs-over-50/apply/ajax/set.check.password.php?email=' + escape(Apply.email) + '&pass=' + escape(pass);
      DialogBox.waitBox();
      Term.get(url, Apply.setCheckPassword);
      return;
   }
   DialogBox.close();
   Apply.parseXML(xml);
}

Apply.setProfile = function(xml) {
   if(!xml) {
      var fname = Apply.trim(document.getElementById('apply_fname').value);
      var lname = Apply.trim(document.getElementById('apply_lname').value);
      var zip   = Apply.trim(document.getElementById('apply_zip').value);
      if(!fname) {
         DialogBox.alertBox('Please enter your first name.', "Term.setFocus('apply_fname');DialogBox.close();", "Missing First Name");
         return;
      }
      if(!lname) {
         DialogBox.alertBox('Please enter your last name.', "Term.setFocus('apply_lname');DialogBox.close();", "Missing Last Name");
         return;
      }
      if(!zip) {
         DialogBox.alertBox('Please enter your Zip Code.', "Term.setFocus('apply_zip');DialogBox.close();", "Missing Zip Code");
         return;
      }
      if(zip.length != 5 || !zip.match(/^[0-9]+$/)) {
         DialogBox.alertBox('Please enter your five digit Zip code.', "Term.setFocus('apply_zip');DialogBox.close();", "Malformed Zip Code");
      }

      Apply.fname = fname;
      Apply.lname = lname;
      Apply.zip   = zip;

      DialogBox.waitBox();

      var url = '/jobs-over-50/apply/ajax/set.profile.php';
      url += User.email ? '?email=' + escape(User.email) : '?email=' + escape(Apply.email);
      url += '&fname=' + escape(Apply.fname);
      url += '&lname=' + escape(Apply.lname);
      url += '&zip='   + escape(Apply.zip);
      Term.get(url, Apply.setProfile);

      return;
   }

   DialogBox.close();
   Apply.parseXML(xml);
}


Apply.getProfile = function(xml) {
   if(!xml) {
      DialogBox.waitBox();
      Term.get('/jobs-over-50/apply/ajax/get.profile.php', Apply.getProfile);
      return;
   }
   DialogBox.close();
   Apply.parseXML(xml);
}

Apply.setCoverLetter = function() {
   var subject = Apply.trim(document.getElementById('cover_subject').value);
   var message = Apply.trim(document.getElementById('cover_message').value);
   if(!subject) {
      DialogBox.alertBox('Please write a subject line.', "DialogBox.close();Term.setFocus('cover_subject');", 'Missing Subject Line');
      return;
   }
   if(!message) {
      DialogBox.alertBox('Please write a cover letter', "DialogBox.close();Term.setFocus('cover_message');", 'Missing Cover Letter');
      return;
   }
   DialogBox.close();
   Apply.subject = subject;
   Apply.message = message;
   Apply.setEmailApply();
}

Apply.setEmailApply = function(xml) {
   if(!xml) {
      DialogBox.closeAll();
      data  = '';
      data += "&subject=" + escape(Apply.subject);
      data += "&message=" + escape(Apply.message);
      data += "&email="   + escape(Apply.email);
      data += "&resume="  + escape(Apply.resume);
      data += "&jobid="   + escape(Apply.jobid);
      data += "&title="   + escape(Apply.title);
      data += "&city="    + escape(Apply.city);
      data += "&state="   + escape(Apply.state);
      data += "&company=" + escape(Apply.company);

      DialogBox.waitBox();
      Term.post('/jobs-over-50/apply/ajax/set.email.apply.php', data, null, Apply.setEmailApply);
      return;
   }
   DialogBox.close();
   Apply.parseXML(xml);
}
Alert = {};
Alert.parseXML = function(xml) {
   var content = CommonLib.parseElement(xml, 'content');
   var script  = CommonLib.parseElement(xml, 'script');
   if(content) {
      var width  = parseInt(CommonLib.parseElement(content, 'width'));
      var html   = CommonLib.parseElement(content, 'html');
      DialogBox.domFormBox(width, 0, html);
   }
   if(script) { eval(script); }
}

Alert.trim = function(str) {
   return str.replace(/^\s+/, '').replace(/\s+$/, '');
}

Alert.closeAlert = function(id) {
   DialogBox.close();
   (document.getElementById('category_select')).style.display    = 'block';
   (document.getElementById('category_select')).style.visibility = 'visible';
   if(id) {
      var el = document.getElementById(id);
      if(el) { el.focus(); }
   }
}

Alert.setAlert = function(xml) {
   if(!xml) {
      var zip        = document.getElementById('alert_zip').value;

      var freq  = 'weekly';
      var freqs = document.getElementsByTagName('input');
      for(var i=0; i<freqs.length; i++) {
         if(freqs[i].type != 'radio')     { continue; }
         if(freqs[i].name != 'frequency') { continue; }
         if(freqs[i].checked) {
            freq = freqs[i].value;
            break;
         }
      }

      if(!zip) {
         DialogBox.alertBox('Please enter a Zip Code.', "Alert.closeAlert('alert_zip');", 'Missing Zip Code');
         return;
      }

      if(!zip.match(/^[0-9][0-9][0-9][0-9][0-9]$/)) {
         DialogBox.alertBox('Please enter a five digit Zip Code.', "Alert.closeAlert('alert_zip');", 'Malformed Zip Code');
         return;
      }

      var category   = '';
      var categories = (document.getElementById('category_select')).options;
      for(var i=0; i<categories.length; i++) {
         if(categories[i].selected && categories[i].value != '') {
            category = categories[i].value;
            break;
         }
      }
      if(!category) {
         DialogBox.alertBox('Please select a job category.', "Alert.closeAlert();", 'Missing Job Category');
         return;
      }

      DialogBox.waitBox();
      var url  = '/jobs-over-50/alert/ajax/set.alert.php';
      var data = '';
      data += '&zip='        + escape(zip);
      data += '&frequency='  + escape(freq);
      data += '&category='   + escape(category);

      Term.post(url, data, null, Alert.setAlert);
      return;
   }

   DialogBox.close();
   Alert.parseXML(xml);
}

Alert.getAlert = function(xml) {
   if(!xml) {
      if(!User.id) { LoginUtils.getLogin(); return; }
      DialogBox.waitBox();
      Term.get('/jobs-over-50/alert/ajax/get.alert.php', Alert.getAlert);
      return;
   }

   DialogBox.close();
   Alert.parseXML(xml);
}

Term.tick = function(xml) {
   if(!xml) {
      Term.ticks++;
      if(Term.ticks > 0 && !(Term.ticks % 2)) { Term.get('/jobs-over-50/ajax/update.php', Term.tick); }
      if(Term.ticks >= 1 &&  Term.todo) { eval(Term.todo); Term.todo = ''; }
      setTimeout('Term.tick()', 2000);
   } else {
      var script = CommonLib.parseElement(xml, 'script');
      eval(script);
   }
}

if(document.location.href.match(/^https/) && !Term.todo) {
   DialogBox.waitBox();
   document.location.href = document.location.href.replace(/^https/, 'http');
}

 Term.tick(); 
