/* vim: set tabstop=4 shiftwidth=4 foldmethod=marker expandtab : */
/*
 | Browser object
 */
function plx_Browser() {
 d=document;
 this.agt=navigator.userAgent.toLowerCase();
 this.major = parseInt(navigator.appVersion);
 this.dom=(d.getElementById)?1:0; // true for ie6, ns6
 this.ns=(d.layers);
 this.ns4up=(this.ns && this.major >=4);
 this.ns6=(this.dom&&navigator.appName=="Netscape");
 this.op=this.agt.indexOf('opera')!=-1;
 this.ie=(d.all);
 this.ie4=(d.all&&!this.dom)?1:0;
 this.ie4up=(this.ie && this.major >= 4);
 this.ie5=(d.all&&this.dom);
 this.win=((this.agt.indexOf("win")!=-1) || (this.agt.indexOf("16bit")!=-1));
 this.mac=(this.agt.indexOf("mac")!=-1);
 this.gecko=(this.agt.indexOf("gecko")!=-1);
 this.safari=(this.agt.indexOf("safari")!=-1);
 this.sp2=(this.agt.indexOf('sv1')!=-1);
}

var brz = new plx_Browser();

// Emulation of array push/pop for those who lack it (IE 5.0/4.0)
function Array_push() {
  var A_p = 0;
  for (A_p = 0; A_p < arguments.length; A_p++) {
   this[this.length] = arguments[A_p];
  }
  return this.length
}

function Array_pop() {
  var response = this[this.length - 1];
  this.length--;
  return response;
}

function Array_unshift() {
  this.reverse();
  for(var i=arguments.length-1;i>=0;i--) this[this.length]=arguments[i];
  this.reverse();
  return this.length;
}

if (typeof(Array.prototype.unshift) == "undefined") {
  Array.prototype.unshift = Array_unshift;
}

if (typeof(Array.prototype.pop) == "undefined") {
  Array.prototype.pop = Array_pop;
}

if (typeof Array.prototype.push == "undefined") {
  Array.prototype.push = Array_push;
}

function String_trim(trimset) {
  if (this.length == 0) return this; // nothing to do
  if (!trimset) trimset = " \t\r\n"; // default: trim on whitespace
    
  var start=0;
  while(start<this.length && trimset.indexOf(this.charAt(start)) != -1)
    start++;

  var end=this.length-1;
  while(end>start && trimset.indexOf(this.charAt(end)) != -1)
    end--;

  if(start>0 || end<this.length-1) {
    return this.substring(start, end + 1);
  } else return this; // already trimmed
}

if (typeof String.prototype.trim == "undefined") {
  String.prototype.trim = String_trim;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

/**
 * MM_showHideLayers('layerid','show'|'hide',....)
 *	Show or hide a HTML object. To show multiple layers call them in pairs.
 */
function MM_showHideLayers() { //v6.0
	var p,v,obj;
	var args=MM_showHideLayers.arguments;
	for (var i=0; i<(args.length-1); i+=2) {
		if ((obj=MM_findObj(args[i]))!=null) {
			v=args[i+1];
			//alert('setting '+args[i]+' to '+v);
			if (obj.style) {
				obj=obj.style;
				v=(v=='show')?'visible':(v=='hide')?'hidden':v;
			}
			obj.visibility=v;
		}
	}
	// don't follow links...
	return false;
}

function changeDiv(the_div,the_change)
{
  var the_style = getStyleObject(the_div);
  if (the_style != false)
  {
    the_style.display = the_change;
  }
}

function getStyleObject(objectId) {
  if (getObject(objectId)) return getObject(objectId).style;
  else return false;
}

function getObject(objectId) {
  if (document.getElementById) {
    return document.getElementById(objectId);
  } else if (document.all && document.all(objectId)) {
    return document.all(objectId);
  } else {
    return false;
  }
}

function hideObject(objectId) {
    var obj = getObject(objectId);

    if (obj && obj.style) {
	obj.style.display = "none";
	return true;
    }
    return false;
}

function showObject(objectId) {
    var obj = getObject(objectId);

    if (obj && obj.style) {
	obj.style.display = "";
	return true;
    }
    return false;
}

// call this to require a that a text field not be empty.
// e.g. if(!requireField("You must enter your name",document.form.name)) return false;
function requireField(message,elem)
{
  if(elem && (!elem.value || elem.value.length==0 || elem.value=="NULL" || elem.value=="Please Select"))
    return fail(message,elem);
  return true;
}

function fail(message,elem) 
{ 
    alert(message); 
    if(elem)
    {
      if(elem.select) elem.select();
      elem.focus();
    }
    return(false); 
}

// Returns a deep copy of the given object
function makeCopy(obj)
{
  var newObj=new Object();
  for(var prop in obj)
    newObj[prop]=obj[prop];

  return newObj;
}


/**
 * Create a popup window but within dimensions of screen.
 */
function popup(url, title, width, height)
{
	var numArgs = popup.arguments.length;
	var windowParams;
	var ht;
	var windowObj;	// window object that is returned.

	if (numArgs > 4) {
		windowParams = popup.arguments[4];
	} else {
		windowParams = 'statusbar=no,menubar=no,toolbar=no,scrollbars=yes,resizable=yes,top=0';
	}

	if (screen.height) { // window
		ht = screen.height;
	} else if (window.document.body.clientHeight) {  // IE
		ht = window.document.body.clientHeight;
	} else if (window.innerHeight) { // Netscape
		ht = window.innerHeight;
	} else if (document.documentElement.clientHeight) { // IE 6+
		ht = document.documentElement.clientHeight;
	} else {
		ht = 580;
	}

	if ((height != 0) && (height > ht)) {
		height = ht;
	}

	if (height != 0 && width != 0) {
		windowParams = windowParams + ',top=0,height=' + height + ',width=' +width;;
	} else if (width != 0) {
		windowParams = windowsParams + ',top=0,width=' + width;
	} 
	windowObj = window.open(url, title, windowParams, false);
    if (windowObj) {
    	windowObj.focus(); // bring to front if window already open
    }
	return windowObj;
}

// privacy statement popups
function showPrivacy(host) { popup((host?host:'')+'/privacypop','privacy_statement_non_members','540','635'); }
function showPrivacyNonMembers(host) { popup((host?host:'')+'/privacypop','privacy_statement_non_members','540','635'); }

/* --- BEGIN VERISIGN CODE - based on http://www.verisign.com/seal/secure/install.html --- */

function popupVerisign(url) {
    sealWin=window.open(url,"win",'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=500,height=450');
    self.name = "mainWin";
    return false;
}

// {{{ new vs code 
dn="WWW.PLAXO.COM";
lang="en";
aff="VeriSignCACenter";
tpt="transparent";
vrsn_style="WW";
splash_url="https://seal.verisign.com";
seal_url="https://seal.verisign.com";
u1=splash_url+"/splash?form_file=fdf/splash.fdf&dn="+dn+"&lang="+lang;

function vrsn_splash() {
tbar = "location=yes,status=yes,resizable=yes,scrollbars=yes,width=560,height=500";
sw = window.open(u1,'VRSN_Splash',tbar);
sw.focus();
}

// }}}

/* --- END VERISIGN CODE --- */
// {{{ popupTrustE(url)
/**
 *  based on http://www.verisign.com/seal/secure/install.html
 *  url should be 'www.plaxo.com'
 */
function popupTrustE(url)
{
    //sealWin=popup('https://www.truste.org/ivalidate.php?url='+url,'privacy_truste',800,400);
    //self.name = "mainWin";
    showPrivacy('http://' + url);
    return false;
}
// }}}

/* -- BEGIN EMAIL SYNAX CHECKER CODE -- */
// note: this list of top-level domains should be periodically updated
var tld="(?:aero|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|arpa|ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|ee|eg|eh|er|es|et|fi|fj|fk|fm|fo|fr|ga|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)";
var validEmail="^[\\w.-]+@(([\\w-]+\\.)+"+tld+"|(\\d{1,3}\\.){3}\\d{1,3})$";
// RK: Commented out due to IE 5 bugs
//var validEmailPattern=new RegExp(validEmail);

/* Returns whether the given email address is valid. */
/* // js: now use EmailSyntax.js
function isValidEmail(email)
{
  if(email.length==0) return(true);
  if(email.indexOf('@')==-1 || email.indexOf('.')==-1) return(false);

  //return true;
  return(validEmailPattern.test(email)); // full regexp check
}
*/
/* -- END EMAIL SYNAX CHECKER CODE -- */

// **********************************************************************
// *  BEGIN MODAL DIALOG CODE
// **********************************************************************

// Global for brower version branching.
var Nav4 = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) == 4));

// One object tracks the current modal dialog opened from this window.
var dialogWin = new Object();

// Generate a modal dialog.
// Parameters:
//    url -- URL of the page/frameset to be loaded into dialog
//    width -- pixel width of the dialog window
//    height -- pixel height of the dialog window
//    returnFunc -- reference to the function (on this page)
//                  that is to act on the data returned from the dialog
//    args -- [optional] any data you need to pass to the dialog

function openModalDialog(url, width, height, returnFunc, args) {
	if (!dialogWin.win || (dialogWin.win && dialogWin.win.closed)) {
		// Initialize properties of the dialog object.
		dialogWin.returnFunc = returnFunc;
		dialogWin.returnedValue = "";
		dialogWin.args = args;
		dialogWin.url = url;
		dialogWin.width = width;
		dialogWin.height = height;
		// Keep name unique so Navigator doesn't overwrite an existing dialog.
		dialogWin.name = (new Date()).getSeconds().toString();
		// Assemble window attributes and try to center the dialog.
		if (Nav4) {
			// Center on the main window.
			dialogWin.left = window.screenX + 
			   ((window.outerWidth - dialogWin.width) / 2);
			dialogWin.top = window.screenY + 
			   ((window.outerHeight - dialogWin.height) / 2);
			var attr = "screenX=" + dialogWin.left + 
			   ",screenY=" + dialogWin.top + ",resizable=no,width=" + 
			   dialogWin.width + ",height=" + dialogWin.height;
		} else {
			// The best we can do is center in screen.
			dialogWin.left = (screen.width - dialogWin.width) / 2;
			dialogWin.top = (screen.height - dialogWin.height) / 2;
			var attr = "left=" + dialogWin.left + ",top=" + 
			   dialogWin.top + ",resizable=no,width=" + dialogWin.width + 
			   ",height=" + dialogWin.height;
		}
		// Generate the dialog and make sure it has focus.
		dialogWin.win=window.open(dialogWin.url, dialogWin.name, attr);
		if (dialogWin.win)
			dialogWin.win.focus();
		else
			alert("Error - unable to open new window.");
	} else {
		if (dialogWin.win)
			dialogWin.win.focus();
	}
}

/**
 * Obfuscate.
 *	(0-1):  guess. make sure this is obfuscated
 *	2: content line. If false, it uses 0-1
 *	3: subject: The subject line to use.
 *	4: title: The link title text to use. If false it generates
 */
function ob_male(usr, hst) {
	var place = usr + '&#64' + hst;
	var content = place;
	var subject = false;
	if ((ob_male.arguments.length > 2) && (ob_male.arguments[2])) {
		content = ob_male.arguments[2];
	}
	if ((ob_male.arguments.length > 3) && (ob_male.arguments[3])) {
		subject = ob_male.arguments[3];
	}
	if ((ob_male.arguments.length > 4) && (ob_male.arguments[4])) {
		var title = ob_male.arguments[4];
	} else {
		var title = 'Send e-mail to ' + place;
		if (subject) {
			title += ' about ' + subject;
		}
	}
	document.write('<span class="personEm' + 'ail"><' + 'a class="ema' + 'il" h' + 'ref="ma' + 'ilto:' + place);
	if (subject) {
		document.write('&amp;Sub' + 'ject=' + escape(subject));
	}
	document.write('" title="' + title + '">' + content + '</' + 'a></span>');
}


function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}
userAgent = window.navigator.userAgent;
browserVers = parseInt(userAgent.charAt(userAgent.indexOf("/")+1),10);
mustInitImg = true;
function initImgID() {var di = document.images; if (mustInitImg && di) { for (var i=0; i<di.length; i++) { if (!di[i].id) di[i].id=di[i].name; } mustInitImg = false;}}
function findElement(n,ly) {
	var d = document;
	if (browserVers < 4)		return d[n];
	if ((browserVers >= 6) && (d.getElementById)) {initImgID; return(d.getElementById(n))}; 
	var cd = ly ? ly.document : d;
	var elem = cd[n];
	if (!elem) {
		for (var i=0;i<cd.layers.length;i++) {
			elem = findElement(n,cd.layers[i]);
			if (elem) return elem;
		}
	}
	return elem;
}
function changeImagesArray(array) {
	if (preloadFlag == true) {
		var d = document; var img;
		for (i=0;i<array.length;i+=2) {
			img = null; var n = array[i];
			if (d.images) {
				if (d.layers) {img = findElement(n,0);}
				else {img = d.images[n];}
			}
			if (!img && d.getElementById) {img = d.getElementById(n);}
			if (!img && d.getElementsByName) {
				var elms = d.getElementsByName(n);
				if (elms) {
					for (j=0;j<elms.length;j++) {
						if (elms[j].src) {img = elms[j]; break;}
					}
				}
			}
			if (img) {img.src = array[i+1];}
		}
	}
}
function changeImages() {
	changeImagesArray(changeImages.arguments);
}

/* target earlier browsers with array.splice */
function Array_splice(index, delTotal) {
	var temp = new Array();
	var response = new Array();
	var A_s = 0;
	for (A_s = 0; A_s < index; A_s++) { temp[temp.length] = this[A_s] }
	for (A_s = 2; A_s < arguments.length; A_s++) { temp[temp.length] = arguments[A_s] }
	for (A_s = index + delTotal; A_s < this.length; A_s++) { temp[temp.length] = this[A_s] }
	for (A_s = 0; A_s < delTotal; A_s++) { response[A_s] = this[index + A_s] }
	this.length = 0;
	for (A_s = 0; A_s < temp.length; A_s++) { this[this.length] = temp[A_s] }
	return response;
}
if (typeof Array.prototype.splice == "undefined") {
	Array.prototype.splice = Array_splice
}

// {{{ getIframeDocument(iframeObj)
/**
 *	Returns a document object related to a given iFrame. This can be useful
 *	for <code>
 *		var iframedoc = getIframeDocument(iframeobj);
 *		if (iframedoc) {
 *			iframedoc.location.replace(url);
 *		}
 *	</code>
 *
 * @param iframeObj the iFrame object
 * @return may be false if there is no document object for a given iframe.
 */
function getIframeDocument(iframeObj)
{
    if (!iframeObj) { return false; }
	if (iframeObj.contentDocument) {
		// For NS6
		return iframeObj.contentDocument;
	} else if (iframeObj.contentWindow) {
		// For IE5.5 and IE6
		return iframeObj.contentWindow.document;
	} else if (iframeObj.document) {
		// For IE5
		return iframeObj.document;
       }
	return false;
}
// }}}
// returns href with name=? removed (if it was there)
function removeQueryParam(href,name)
{
  var last=0;
  while(true)
  {
    var start=href.indexOf(name,last);
    if(start==-1) return href; // bail out
    if((start==0 || href.charAt(start-1)=='&' || href.charAt(start-1)=='?') && start+name.length<href.length)
    {
      var newHref=href.substring(0,start);
      var end=href.indexOf('&',start+name.length);
      if(end!=-1) newHref+=href.substring(end+1); // copy to the end
      else if(start>0) newHref=newHref.substring(0,newHref.length-1); // cut off the & or ? before this param, since there's nothing after it
      return newHref;
    }
    last = start+1;
  }
}

// appends query to href, inserting ? or & as necessary (e.g. to append "t=2" to location.href)
function appendQuery(href,query)
{
  if(href.indexOf('?')==-1)
    return href+'?'+query;
  return href+'&'+query;
}

// replaces the query string name in href with value (adds it if it wasn't there before)
// e.g. replaceQueryParam(xxx?a=b&c=d,a,e) -> xxx?a=e&c=d
function replaceQueryParam(href,name,value)
{
  return appendQuery(removeQueryParam(href,name),name+'='+value);
}

// Date functions {{{
/**
 * Patch some broken parts of Javascript date functions.
 *
 * @author terry chay
 */

Date.prototype.getDayString = function()
{
	switch (this.getDay()) {
		case 0: return 'Sunday'; break;
		case 1: return 'Monday'; break;
		case 2: return 'Tuesday'; break;
		case 3: return 'Wednesday'; break;
		case 4: return 'Thursday'; break;
		case 5: return 'Friday'; break;
		case 6: return 'Saturday'; break;
	}
}
Date.prototype.getMonthString = function()
{
	switch (this.getMonth()) {
		case 0: return 'January'; break;
		case 1: return 'February'; break;
		case 2: return 'March'; break;
		case 3: return 'April'; break;
		case 4: return 'May'; break;
		case 5: return 'June'; break;
		case 6: return 'July'; break;
		case 7: return 'August'; break;
		case 8: return 'September'; break;
		case 9: return 'October'; break;
		case 10: return 'November'; break;
		case 11: return 'December'; break;
	}
}
Date.prototype.getMonthAbbr = function()
{
	switch (this.getMonth()) {
		case 0: return 'Jan'; break;
		case 1: return 'Feb'; break;
		case 2: return 'Mar'; break;
		case 3: return 'Apr'; break;
		case 4: return 'May'; break;
		case 5: return 'Jun'; break;
		case 6: return 'Jul'; break;
		case 7: return 'Aug'; break;
		case 8: return 'Sep'; break;
		case 9: return 'Oct'; break;
		case 10: return 'Nov'; break;
		case 11: return 'Dec'; break;
	}
}
/**
 * getFullYear() may or may not be used.
 */
Date.prototype.getYearFull = function()
{
	var y = this.getYear();
	if (y<1000) y += 1900;
	return y;
}
// }}}
