
//convert 2 year date to four year

function convertDate(dt){
 num = parseFloat(dt);
 if(!isNaN(num)) return null; 
 var yr = dt.getYear();
   if(yr < 50){
     dt.setFullYear(2000 + yr);
     return dt;
   }
   if(yr <= 99){
     dt.setFullYear(1900 + yr);
     return dt;
   } 
 return dt;
 }


function closePreview(){
if(typeof descripWin != 'undefined'){descripWin.close();}
}

//submits to popup window
function popUpSubmit(f,url,wide,tall,left,top) {
popupwin=window.open(url,'win','toolbar=1,location=0,directories=0,status=0,menubar=0,scrollbars=1,width=' + wide + ',height=' + tall + ',left=' + left + ',top=' + top + ', resizable=1');
if (popupwin.opener == null) popupwin.opener = window; 
    popupwin.opener.name = "opener";
 setTimeout("popupwin.focus()",50); 
f.action=url;
f.method="post";
f.target="win";
f.submit();
}

function popHelp(url,wide,tall,left,top) {
popupwin=window.open(url,'helpwin','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,width=' + wide + ',height=' + tall + ',left=' + left + ',top=' + top + ', resizable=1');
if (popupwin.opener == null) popupwin.opener = window; 
    popupwin.opener.name = "helpopener";
setTimeout("popupwin.focus()",100);  
}


function popUp(url,wide,tall,left,top) {
popupwin=window.open(url,'win','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,width=' + wide + ',height=' + tall + ',left=' + left + ',top=' + top + ', resizable=1');
if (popupwin.opener == null) popupwin.opener = window; 
    popupwin.opener.name = "opener";
setTimeout("popupwin.focus()",100);  
}



function confirmDelete(desturl){
  var url=desturl;
  var reason = escape(prompt("Please enter the reason you would like to delete this report:"));
  if (reason != '' && reason != null) { 
  url = eval(url + '?reason=' + reason)
  var hidwin=window.open(url,'hidwin','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,width=1,height=0,left=0,top=3000,resizable=0');
    if (hidwin.opener == null) hidwin.opener = window; 
		    hidwin.opener.name = "opener";
		    }
 }


function FrameBuster(){
if (top !=self)
top.location=self.location;
}


function cntChars(ct,fld){
if(fld.value.length == ct){
alert("You have entered the maximum number of characters for this field.")
}
 if(fld.value.length > ct){
   fld.value = fld.value.slice(0,ct);
}
}


function showProgress(pct){
    
	if (pct == 0){
		for (var i = 1; i <= 20; i++){
			eval("document.sizepic" + i + ".src = 'images/dot_clear.gif'");
			alert("here in clear");
		}
		setTimeout("simulate(" + (pct + 1) + ")", 250);
	} else {
		if (pct <= 20) {
			eval("document.sizepic" + pct + ".src = 'images/dot_red.gif'");
			setTimeout("simulate(" + (pct + 1) + ")", 200);
			alert("here in red");
		}
	}
}


// Code provided from the IMF Site:
// Controlling the behavior of the the dropdown list control
// Hovering over the ddl will give it focus, if the ddl list is clicked it will keep focus
// when the mouse is moved away from the ddl it will lose focus (iff the ddl was not clicked on)
// Usage: OnMouseOver="ddlSetFocus(this);" OnMouseOut="ddlBlur(this);" OnClick="ddlOpen();"
//        OnFocus="do something;" OnBlur="do something;" 

var ddltimeout = 350;
var ddlclosetimer = 0;
var ddlOpened = false;

function ddlSetFocus(ctrl) {
    ddlCancelClose();
    ctrl.focus();
}

function ddlBlur(ctrl) {
    if (ddlOpened == false) {
        var fun = 'ddlClose("' + ctrl.id + '")';
        ddlclosetimer = window.setTimeout(fun, ddltimeout);
    }
    ddlOpened = false
}

function ddlOpen() {
    ddlOpened = true;
}

function ddlClose(elemID) {
    var elem = document.getElementById(elemID);
    elem.blur();
    ddlOpened = false;
}

function ddlCancelClose() {
    if (ddlclosetimer) {
        window.clearTimeout(ddlclosetimer);
        ddlclosetimer = null;
    }
}


function getElementPosition(elemID) {
    var offsetTrail = document.getElementById(elemID);
    var offsetLeft = 0;
    var offsetTop = 0;

    while (offsetTrail) {
        offsetLeft += offsetTrail.offsetLeft;
        offsetTop += offsetTrail.offsetTop;
        offsetTrail = offsetTrail.offsetParent;
    }

    if (navigator.userAgent.indexOf("Mac") != -1 &&
		typeof document.body.leftMargin != "undefined") {
        offsetLeft += document.body.leftMargin;
        offsetTop += document.body.topMargin;
    }

    return { left: offsetLeft, top: offsetTop };
}
function getElementPosition(elemID) {
    var offsetTrail = document.getElementById(elemID);
    var offsetLeft = 0;
    var offsetTop = 0;

    while (offsetTrail) {
        offsetLeft += offsetTrail.offsetLeft;
        offsetTop += offsetTrail.offsetTop;
        offsetTrail = offsetTrail.offsetParent;
    }

    if (navigator.userAgent.indexOf("Mac") != -1 &&
		typeof document.body.leftMargin != "undefined") {
        offsetLeft += document.body.leftMargin;
        offsetTop += document.body.topMargin;
    }

    return { left: offsetLeft, top: offsetTop };
}

function setElementPositionByElementTarget(elemID, elemTargetID) {
    var elemTargetPosition = getElementPosition(elemTargetID);

    var elem = document.getElementById(elemID);

    elem.style.left = eval(elemTargetPosition.left);
    elem.style.top = eval(elemTargetPosition.top);

}
       








