// JScript File

var count = 0;

function openStandardWindow(url, width, height, name)
{
    var theName = "";
    var theWidth = 600;
    var theHeight = 500;
    
    if(name)
        theName = name;
    if(width)
        theWidth = width;
    if(height)
        theHeight = height;
    
    window.open(url,theName+'unique_name'+(count++),'scrollbars=yes,resizable=1, toolbar=no,width='+theWidth+',height='+theHeight);
};

function openXmlBrowserWindow(url, width, height, name)
{
    var theName = "PopWindow";
    var theWidth = 600;
    var theHeight = 500;
    
    if(name)
        theName = name;
    if(width)
        theWidth = width;
    if(height)
        theHeight = height;
    
    window.open(url,theName,'scrollbars=no,resizable=0, status=no, left=5, top=5, toolbar=no,width='+theWidth+',height='+theHeight);
};

function scrollToBottom() {
    var scrollH = document.body.scrollHeight;
    var offsetH = document.body.offsetHeight;
    if (scrollH > offsetH) window.scrollTo(0, scrollH);
    else window.scrollTo(0, offsetH);
};

function numericCheck(evt)
{
    if (event.keyCode < 46 || event.keyCode > 57) 
        event.returnValue = false;
};

function dateCheck(evt)
{
    if ((event.keyCode < 47 || event.keyCode > 57) && event.keyCode != 47) 
        event.returnValue = false;
};

function autoFormAjaxCall(servicePath, serviceMethod, contextKey, onComplete, onError) 
{                     
    Sys.Net.WebServiceProxy.invoke(servicePath, serviceMethod, false, {"contextKey":contextKey}, onComplete, onError);
};

function showMessage(position_element, message, posX, posY)
{    
    var location = Sys.UI.DomElement.getLocation(position_element);        
    x = location.x + 25;
    if(posX)
        x = x + posX;
    y = location.y - 25;
    if(posY)
        y = y + posY;
    $get('messageBox').style.top =  y + 'px';
    $get('messageBox').style.left =  x + 'px';    
    $get('messageText').innerHTML = message;
    //$get('messageBtn').click();
    $find('messageAnimation').playAppear();
};

function hideAjaxLoadingImg()
{
    var anim = document.getElementById("ajaxLoadingImage");    
    anim.style.display = 'none';
};

function setAjaxLoadingImg(control)
{
    var anim = document.getElementById("ajaxLoadingImage");
    var pos = findPos(control);
    anim.style.top = (pos[1] - 20) + 'px';
    anim.style.left = pos[0] + 'px';
};

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
};


function moveEditForm(rowId, formId, headerRowId)
{
    var editTable = document.getElementById(formId);
    var form = document.getElementById(formId);
    var header = document.getElementById(headerRowId);
    header.style.display = "none";
    form.style.display = "block";
    var editRow = document.getElementById(rowId).firstChild;    
    editRow.appendChild(editTable);       
};

function confirmDelete()
{
    return confirm('Are you sure you want to delete this row?');
};

function getTextWidth(element)
{
    if(element.nodeType==1 && (element.tagName.toLowerCase() == "a" || element.tagName.toLowerCase() == "span" || element.tagName.toLowerCase() == "img"))
        return element.scrollWidth;
    var wd = 0;
    for(var i=0;i<element.childNodes.length;i++)
    {
        wd += getTextWidth(element.childNodes[i]);
    }
    return wd;       
};