function VirtualPath(strFilePath)
{
	var intPos;
	
	if ((intPos = strFilePath.lastIndexOf("/")) > -1)
	{
		return strFilePath.substring(0, intPos);
	}
}

function SwapImage(objImg, strPath)
{
	objImg.src = strPath;
}

function HighLight(objRow)
{
	objRow.className = "Hover";
}

function UnHighLight(objRow)
{
	objRow.className = "Inactive";
}

function OnBrowse(strUrl)
{
	if (strUrl.indexOf("http://") == -1)
	{
		window.open("http://" + strUrl);
	}
	else
	{
		window.open(strUrl);
	}
}

function OnClose()
{
	window.close();
}

function ZoomImage(strTitle, strImagePath)
{
	var objImage = new Image();
	
	objImage.src = strImagePath;
	objImage.onload = function()
	{
		ShowImage(strTitle, objImage);
	}
	if (objImage.complete)
	{
		ShowImage(strTitle, objImage);
	}
}

function ShowImage(strTitle, objImage)
{
	if (objImage.width > 800)
	{
		objImage.height = objImage.height * 800 / objImage.width;
		objImage.width = 800;
	}

	if (objImage.height > 600)
	{
		objImage.width = objImage.width * 600 / objImage.height;
		objImage.height = 600;
	}
	
	var intLeft = (screen.availWidth / 2) - (objImage.width / 2);
	var intTop = (screen.availHeight / 2) - (objImage.height / 2);
	var strSettings = "toolbar=no,status=no,help=no,resizable=no,left=" + intLeft + ",top="+ intTop + ",width=" + objImage.width + ",height=" + objImage.height;
	var objWindow = window.open(objImage.src, "", strSettings);
	var strHtml = "<html><head><title>" + strTitle + "</title></head><body style='margin: 0 0 0 0'><img src='" +
		objImage.src + "' width=" + objImage.width + "height=" + objImage.height + "></body></html>";
		
	objWindow.document.write(strHtml);
	objWindow.resizeBy(objImage.width - objWindow.document.body.clientWidth, objImage.height - objWindow.document.body.clientHeight);
	objWindow.focus();
}

function OnKeyDown(e, btnButton)
{ 
    var intKey = -1; 

    if (e && e.which)
    {
        intKey = e.which;    // NS
    }
    else 
    {
        if (window.event && window.event.keyCode)
        {
            intKey = window.event.keyCode;  // IE
        }
    }
    
    if (intKey == 13) 
    { 
         document.getElementById(btnButton).click(); 
         return false; 
    } 

    return true; 
}

function Popup(strUrl, strName, intWidth, intHeight)
{
    return XPopup(strUrl, strName, intWidth, intHeight, "no");
}

function XPopup(strUrl, strName, intWidth, intHeight, strScrollbars)
{
    var str = "menubar=no,status=no,scrollbars=" + strScrollbars + ",toolbar=no,location=no,directories=no,resizable=no," +
        "height=" + intHeight + ",innerHeight=" + intHeight +
        ",width=" + intWidth + ",innerWidth=" + intWidth;
    
    if (window.screen)
    {
        var ah = screen.availHeight - 30;
        var aw = screen.availWidth - 10;

        var xc = (aw - intWidth) / 2;
        var yc = (ah - intHeight) / 2;

        str += ",left=" + xc + ",screenX=" + xc;
        str += ",top=" + yc + ",screenY=" + yc;
    }
    
    return window.open(strUrl, strName, str);
}

function IsMaxLength(objTextBox, intMaxLength, e)
{
    var strKey = window.event ? e.keyCode : e.which;
    var strValidKeys = "8,33,34,35,36,37,38,39,40,46";
    
    if (strValidKeys.indexOf(strKey) == -1)
    {
        return objTextBox.value.length <= intMaxLength;
    }
    
    return true;
}

function TruncTextBoxValue(objTextBox, intMaxLength)
{
    if (objTextBox.value.length > intMaxLength)
    {
	    objTextBox.value = objTextBox.value.substring(0, intMaxLength);
	    objTextBox.scrollTop = objTextBox.scrollHeight;
    }
}

function SetCaretPosition(strTextBox, intPosition)
{
    var objTextBox = document.getElementById(strTextBox);

    if (objTextBox != null)
    {
        if(objTextBox.createTextRange)
        {
            var objRange = objTextBox.createTextRange();
            objRange.move('character', intPosition);
            objRange.select();
        }
        else
        {
            if (objTextBox.selectionStart)
            {
                objTextBox.focus();
                objTextBox.setSelectionRange(intPosition, intPosition);
            }
            else
            {
                objTextBox.focus();
            }
        }
    }
}

String.prototype.trim = function ()
{
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

