function openPopup (urlToPopup, height, width)
{
	var x = (screen.availWidth - width) / 2;
      var y = (screen.availHeight - height) / 2;

	var popup = window.open(urlToPopup,
                              "pnPopup",
					"scrollbars=yes" + "," +
					"width=" + width + "," +
					"height=" + height + "," +
					"left=" + x + ", top=" + y + "," + //IE
					"screenX=" + x + ", screenY=" + y   //netscape
					);
      popup.resizeTo(width,height);
	// bring the popup (if one already exists) to the top.
	popup.focus();
}

function closePopup(windowRef)
{
	// close the popup when the user clicks the button
	if (windowRef && !windowRef.closed)
		windowRef.close();
}


function glossary(term,def)
{
	gloss_popup = window.open("","gloss","width=500,height=150,scrollbars=no");
	gloss_popup.document.write("<html><head><title>" + term + "</title><style>body{margin:00;margin-left:0;margin-top:0;background-color:#ffffff;font-family:Arial,Helvetica,Verdana,sans-serif;}td{font-family:Arial,Helvetica,Verdana,sans-serif;font-size:12px;}.boldBodyText{font-size:12px;font-weight:bold;color:#000000;text-align:left;}.yellowBg{background-color:#F8BC48;}.yellowBg2{background-color:#FEA827;}</style></head><body><table border='0' cellpadding='0' cellspacing='0' width='100%'><tr><td class='yellowBg' colspan='3'><img src='/eknec/transform/images/spacer.gif' alt='' width='1' height='14' border='0' /></td></tr><tr><td class='yellowBg2' colspan='3'><img src='/eknec/transform/images/spacer.gif' alt='' width='1' height='7' border='0' /></td></tr><tr><td rowspan='5' width='10'><img src='/eknec/transform/images/spacer.gif' alt='' width='10' height='1' border='0' /></td><td align='right'><a href='#' onclick='window.close()'>close</a></td><td rowspan='5' width='10'><img src='/eknec/transform/images/spacer.gif' alt='' width='10' height='1' border='0' /></td></tr><tr><td><br /></td></tr><tr><td class='boldBodyText'>" + term + "</td></tr><tr><td><img src='/eknec/transform/images/spacer.gif' alt='' width='1' height='10' border='0' /></td></tr><tr><td>" + def + "</td></tr></table></body></html>");
	gloss_popup.document.close();
	gloss_popup.focus();
}

window.offscreenBuffering = true;

var prename2 ="image";
var counter2 = 0;

function preloader(pqsource,pqhspace,pqvspace,pqalign){
var fullname2 = prename2 + (counter2++);
	preload=new Image();
	preload.src=pqsource;

	var tag = '<table border="0" cellpadding="0" cellspacing="0"><tr><td><div><img src="' + pqsource + '"';
	var iwidth, iheight;
	iwidth = 0;
	iheight = 0;

	if((navigator.appName.indexOf('Internet Explorer') != -1) && (navigator.appVersion.indexOf('Mac') == -1)){
		var count = 0;
		do{
			iwidth = preload.width;
			iheight = preload.height;
			count++;

			if(((iwidth == 0) && (iheight == 0)) && (count == 100)){
				preload2 = new Image();
				preload2.src = pqsource;
				var count2 = 0;
				do{
					iwidth = preload2.width;
					iheight = preload2.height;
					count2++;
					}while(((iwidth == 0) && (iheight == 0)) && (count2 < 100))
				}

			}while(((iwidth == 0) && (iheight == 0)) && (count < 100))

		if(iwidth != 0){
			tag += ' width="' + iwidth + '" height="' + iheight + '"';
	//		tag += ' onload="this.width=' + iwidth + ';this.height=' + iheight + ';"';
	//		tag += ' onload="this.width=document.'+fullname2+'.width;this.height=document.'+fullname2+'.height;"';
			}
	//	else{alert('image hang: width=' + iwidth + ', height=' + iheight);}
		}

	if(pqalign){tag = tag + ' align="' + pqalign + '"';}
	if(pqhspace){tag = tag + ' hspace="' + pqhspace + '"';}
	if(pqvspace){tag = tag + ' vspace="' + pqvspace + '"';}
	tag += ' border="0" alt=""' + ' name="' + fullname2 + '" /></div></td></tr></table>';

	document.write(tag);
	eval ('document.'+fullname2+'.src = preload.src;');
//	eval ('document.'+fullname2+'.onload = sizeit("'+fullname2+'",'+iwidth+','+iheight+');');
	}

function sizeit(ident,iw,ih){
	eval ('document.'+ident+'.width = '+iw+';');
	eval ('document.'+ident+'.height = '+ih+';');
	}

function callIC(){
	if(fmr_onload){fmr_onload();}
	setTimeout("imagecheck()",1000);
	}


fmr_onload = window.onload;
window.onload = callIC;

function imagecheck(){
	if(navigator.appName.indexOf('Internet Explorer') != -1){
		for(i=0;i<document.images.length;i++){

// && (document.images[i].width > 84) && (document.images[i].height > 0) && (document.images[i].width != 134))

			if(document.images[i].src.indexOf('.jpg') > -1){
				var postload = new Image();
				postload.src = document.images[i].src;
				do{}while(postload.complete == 'false');
				document.images[i].src = postload.src;

//begin debug
				if(location.href.indexOf('t=hahaha') > -1){alert(document.images[i].src + "-(BEFORE): height:" + document.images[i].height + ", width:" + document.images[i].width);}
//end debug
				if (document.images[i].src.indexOf('potd.jpg') == -1) {
					if((postload.width > 0) && (postload.height > 0)){
						document.images[i].width = 200;
						document.images[i].height = 200;

						document.images[i].width = postload.width;
						document.images[i].height = postload.height;
					}
				}

//begin debug
				if(location.href.indexOf('t=hahaha') > -1){alert(document.images[i].src + ":-(AFTER) height:" + document.images[i].height + ", width:" + document.images[i].width);}
//end debug

				}
			}
		}
	}



  function writeCookie (name, value, expiry) {
    var exp = new Date();
    var s = name + '=' + escape (value);
    if (expiry) {
      exp.setTime (exp.getTime() + (expiry * 60000));
      s += '; expires=' + exp.toGMTString();
      }
    document.cookie = s;
    }

  function readCookie (name) {
    var s = document.cookie;
    var cset = s.split (';');
    var size = cset.length;
    var pieces;
    var ret = '';
    var x = 0;
    for (x = 0 ; ((x < size) && (ret == '')) ; x++) {
      pieces = cset[x].split ('=');
      if (pieces[0].substring (0,1) == ' ') {
        pieces[0] = pieces[0].substring (1, pieces[0].length);
        }
      if (pieces[0] == name) {
        ret = pieces[1];
        }
      }
    return ret;
    }
