//get the user browser
var uA = navigator.userAgent;
var browserType = "unknown";

   //Check Browsers so we know to make changes for offsets
if (uA.indexOf("Opera") > -1) {
	browserType = "Opera";
} else if (uA.indexOf("Safari") > -1) {
	browserType = "Safari";
} else if (uA.indexOf("Konqueror") > -1) {
	browserType = "Konqueror";
} else if (uA.indexOf("Gecko") > -1) {
	browserType = "Mozilla";
} else if (uA.indexOf("MSIE") > -1) {
	browserType = "IE";
}

//Function to open div
function OpenDiv(DivId){
	document.getElementById(DivId).style.zIndex = "1";	
	document.getElementById(DivId).style.display = "block";	
}
//Function to close div
function CloseDiv(DivId){
	document.getElementById(DivId).style.zIndex = "0";
	document.getElementById(DivId).style.display = "none";
}

//Find the position of the element sending the request
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
	    	curtop += obj.offsetTop;
	    } while (obj = obj.offsetParent);
		return [curleft,curtop];
	}
}

//Open and reposition the div
function ViewReceipt(DivId,blDivOpen,loc,loff){
	
	//if 99 is for close button within tag
	if(loc != 99){
	obj = document.getElementById(loc);

    var location = new Array();
    location = findPos(obj);

    if(browserType == "IE"){
        offsetY = 23;
		offsetX = -30;
        if(loff){
            offsetY = offsetY - 5;
            offsetX = 260;
        }
    }else if (browserType == "Mozilla"){
        offsetY = 22;
		offsetX = -30;
        if(loff){
          offsetY = offsetY - 3;
          offsetX = 258;
        }
    }else if (browserType == "Safari"){
        offsetY = 22;
		offsetX = -30;
        if(loff){
          offsetY = offsetY - 3;
          offsetX = 260;
        }
    }
    
    //if clicking the what's this link we need to offset the div
    if(loff){
      location[0] = location[0] - offsetX;
      location[1] = location[1] + offsetY;
    }else{
    location[1] = location[1] + offsetY;
	location[0] = location[0] - offsetX;
    }
    
    
    //change the location of the div
    document.getElementById(DivId).style.left = location[0] + "px";
    document.getElementById(DivId).style.top = location[1] + "px";
    }
    
    //perform the open or close command
    if(blDivOpen == 0){
		CloseDiv(DivId);
	}else{
		OpenDiv(DivId);
	}
}


//Function to only allow numeric keypresses. Also allows backspace/delete key.
function isNumberKey(event) {
	var charCode = (event.which) ? event.which : event.keyCode;
	if (charCode > 31 && (charCode < 48 || charCode > 57))  //less than 31 allows backspace/delete key and cursor left/right. 48-57 are 0 through 9.
		return false;
		
	return true;
}