var puWinID = null;

function popupWindow(u,n,h,w,sb) {
	if (puWinID != null) {
		puWinID.close();
	}
	//center the window opening
	if (h==0) { h=450; } else { h=h +20; }
	if (w==0) { w=750; } else { w=w +20; }
	// if the window is to be opened bigger than the screen then reduce it 80px less than the screen,
	// move it up 15 px and add a scrollbar and increase the width by 10 px
	if(h>(screen.height-80)) { hp=5; h= screen.height - 80; w+=10; sb="yes";} else {hp=(screen.height-h)/2;}
	if(w>(screen.width-20)) { hw=5; w= screen.width - 20; sb="yes";} else {hw=(screen.width-w)/2;}
	puWinID = window.open(u, n,'toolbar=no,status=yes,menubar=no,location=no,scrollbars='+sb+',resizable=yes,height='+h+',width='+w+',top='+hp+',left='+hw+',screenY='+hp+',screenX='+hw+'');
	if (puWinID.opener == null) {
		puWinID.opener = self; // this is here to make sure that the particular frame cell is referenced as the opener of this window
	}
	try {
		puWinID.focus();
	} catch (e) {
		alert("The correct control or window is not displaying.\nThe problem may be caused by a 'popup blocker', or the window you wish to view may be behind the active window.\nPlease turn off all popup blockers (including blockers in security software) and try again,\nor locate the correct window behind the active window.");
	}
}

function writeImg(u) {
	var thisWriteImg="";
	var basePath = window.location.href;
	basePath = basePath.replace(/\?.*$/,"");
	basePath = basePath.replace(/^(.*)index\.cfm.*$/,"$1");
	thisWriteImg += '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"\n';
   thisWriteImg += '	"http://www.w3.org/TR/html4/loose.dtd">\n';
	thisWriteImg += '<html><head><title>Image</title></head><body>\n';
	thisWriteImg += '<table border="0" cellspacing="0" cellpadding="0"><tr><td>';
	if (u.match(/^http/)) {
	  thisWriteImg+='<img src="'+encodeURI(u)+'" alt="">';
	} else {
	  thisWriteImg+='<img src="'+basePath+encodeURI(u)+'" alt="">';
	}
	thisWriteImg+='</td></tr></table>\n';
	thisWriteImg+='</body></html>\n';

	doc = puWinID.document;
	doc.open('text/html');
	doc.write(thisWriteImg);
	doc.close();
}

function openWindowImg(u,n,h,w,sb) {
	// if h and width is greater than 800x600 then modify adding scrollbars
	if(h>570) { h=570;sb=1;}
	if(w>800) { w=800;sb=1;}
	if (puWinID != null) {
		puWinID.close();
	}
	//center the window opening 
	if (h==0) { h=450; } else { h=h +20; }
	if (w==0) { w=750; } else { w=w +20; }
	// if the window is to be opened bigger than the screen then reduce it 80px less than the screen, 
	// move it up 15 px and add a scrollbar and increase the width by 10 px
	if (h>(screen.height-80)) { hp=5; h= screen.height - 80; w+=10; sb="yes";} else {hp=(screen.height-h)/2;} 
	if(w>(screen.width-20)) { hw=5; w= screen.width - 20; sb="yes";} else {hw=(screen.width-w)/2;} 
	puWinID =  window.open(u, n,'toolbar=no,status=yes,menubar=no,location=no,scrollbars='+sb+',resizable=yes,height='+h+',width='+w+',top='+hp+',left='+hw+',screenY='+hp+',screenX='+hw+'');
	if (puWinID.opener == null) {
		puWinID.opener = self; // this is here to make sure that the particular frame cell is referenced as the opener of this window
	}
	try {
		puWinID.focus();
	} catch(e) {
		alert("The correct control or window is not displaying.\nThe problem may be caused by a 'popup blocker', or the window you wish to view may be behind the active window.\nPlease turn off all popup blockers (including blockers in security software) and try again,\nor locate the correct window behind the active window."); 
	}
	writeImg(u);
}

function addEvent( obj, type, fn ) {
   if (obj.addEventListener){
      obj.addEventListener( type, fn, false );
   } else if (obj.attachEvent) {
      obj["e"+type+fn] = fn;
      obj[type+fn] = function(){obj["e"+type+fn](window.event);}
      obj.attachEvent("on"+type, obj[type+fn]);
   }
}

function addOnLoadEvent(onloadToAdd){
	var prevOnLoad = window.onload;
	if (typeof window.load != 'function') {
		window.onload = onloadToAdd;
	} else {
		window.onload = function() {
			if (prevOnLoad) {
				prevOnLoad();
			}
			onloadToAdd();
		}
	}
}

function confirmation(message,url) {
	if (confirm(message)) {
		document.location.href=url
	}
}

function confirmOnClick(msg) {
	if (confirm(msg)) {
		return true;
	} else {
		return false;
	}
}

function refresh(theTime) {
	setTimeout('history.go(0)',theTime);
}

function refreshWindow() {
	this.location.reload(true);
}

function raiseWindow(winObj) {
	if (winObj === undefined) {
		winObj = puWinID;
	}
	if (winObj != null) {
		if (!winObj.closed) {
			winObj.focus();
		}
	}
}

function check(winObj) {
	if (winObj === undefined) {
		winObj = puWinID;
	}
	if (winObj != null) {
		if (!winObj.closed) {
			winObj.focus();
		}
	}
}

function reloadWindow(winObj) {
	if (winObj === undefined) {
		winObj = puWinID;
	}
	if (winObj != null) {
		if (winObj.closed) {
			winObj.location.reload(true);
		}
	}
}

var WGdc="."; var WGgc=""; var WGnc="";
function FormatMoney(A,W) {
  if(A<0){neg=1;}else{neg=0;}
  var N=Math.abs(Math.round(A*100));
  var S=((N<10)?"00":((N<100)?"0":""))+N;
  S=((A<0)?WGnc:"")+Group(S.substring(0,(S.length-2)))+WGdc+
    S.substring((S.length-2),S.length)+((A<0&&WGnc=="(")?")":"");
  return (S.length>W)?"over":(neg)?"-"+S:S;
}

function Group(S) {
  return (S.length<4)?S:(Group(S.substring(0,S.length-3))+WGgc+S.substring(S.length-3,S.length));
}
