﻿// Returns a reference to the object with given ObjectId
function getObject(objId, win) 
{
  if(win==null)
    win = window;
  if (win.document.layers) { //checks for Netscape 4
     return myObj = eval('document.' + objId);
  }
  else if (win.document.all && !getObject) { //checks for IE 4
     return myObj = eval('document.all.' + objId);
  }
  else if (getObject) { //Checks for Netscape 6 & IE 5
     return myObj = win.document.getElementById(objId);
  }
  else {
     alert('This website uses DHTML. We recommend you upgrade your browser.');
  }
}

function submitForm(evt, btnId)
{   
    var keyCode = evt ? (evt.which ? evt.which : evt.keyCode) : event.keyCode;
    
    if(keyCode == 13)
    {
	    btnObj = getObject(btnId);	
	    btnObj.focus();
	}
}

function ConfirmDelete(object)
{
	return confirm('Do you really want to delete this ' + object + '?');
}

function handleTextBoxClick(txt)
{
    if(txt.clicked==null)
    {
        txt.clicked = true;
        txt.value = "";
    }
}

function moveObj(objectId,xPos,yPos) 
{   
  var object = getObject(objectId);
  if(object==null)
    return;
  if (document.layers) { //checks for Netscape 4
     if(yPos!=null)
        object.top = yPos;
     if(xPos!=null)
        object.left = xPos;
  }
  else if (document.all && !getObject) { //checks for IE 4
     if(yPos!=null)
        object.style.pixelTop = yPos;
     if(xPos!=null)
        object.style.pixelLeft = xPos;
  }
  else if (getObject) { //Checks for Netscape 6 & IE 5
     if(yPos!=null)
        object.style.top = yPos +"px";
     if(xPos!=null)
        object.style.left = xPos + "px";
  }      
}

function getClientWidth() {
	return filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function getClientHeight() {
	return filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function getClientScrollLeft() {
	return filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function getClientScrollTop() {
	return filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}


function centerObjectOnScreen(object)
{
    var scrollTop = getClientScrollTop();
    var scrollLeft = getClientScrollLeft();
    
    var viewPortHeight = getClientHeight();
    var viewPortWidth = getClientWidth();
    
    var topOffset = Math.ceil(viewPortHeight/2 - object.offsetHeight/2);
    var leftOffset = Math.ceil(viewPortWidth/2 - object.offsetWidth/2);

    var top = scrollTop + topOffset - 40;
    var left = scrollLeft + leftOffset - 70;

    object.style.position = "absolute";
    object.style.top = top + "px";
    object.style.left = left + "px";

    object.style.marginLeft = "-" + parseInt(object.offsetWidth / 2) + "px";
    object.style.marginTop = "-" + parseInt(object.offsetHeight / 2) + "px";                     		 
 }

function getObjPosition(objectId) 
{    
  var object = getObject(objectId);
  if(object==null)
    return;
  var pos = new Object();
  pos.xPos = 0;
  pos.yPos = 0;
  if (document.layers) { //checks for Netscape 4
     pos.xPos = object.left;
     pos.yPos = object.top;
  }
  else if (document.all && !getObject) { //checks for IE 4
     pos.xPos = style.pixelLeft;
     pos.yPos = style.pixelTop;
  }
  else if (getObject) { //Checks for Netscape 6 & IE 5
     pos.xPos = object.style.left;
     pos.yPos = object.style.top;     
  } 
  return pos; 
}


function toggleElementVisibility(elementId) {
  return toggleObjectVisibility(getObject(elementId));  
}

function toggleObjectVisibility(o) {
  if(o==null)
	return;
  if(o.style.display=='none'){
    o.style.display='';
    return true;
  }else{
    o.style.display='none';
    return false;
  }
}

function setElementDisabled(elementId, disabled) {
  setObjectDisabled(getObject(elementId), disabled);  
}

function setObjectDisabled(c, disabled) {
  if ((typeof(c) != "undefined") && (c != null))
    c.disabled = disabled;
}

function getElementDisabled(elementId) {
  var elem = getObject(elementId);
  if(elem==null)
	return false;
  return elem.disabled; 
}

function setElementVisibility(elementId, visible) {
  return setObjectVisibility(getObject(elementId), visible);
}

function setObjectVisibility(o, visible) {
  if(o==null)
	return;
  if(visible){
    o.style.display='';
    return true;
  }else{
    o.style.display='none';
    return false;
  }
}

function getElementVisibility(elementId) {
  var o = getObject(elementId);
  if(o==null)
	return false;
  return o.style.display!='none';  
}

function maximizeWindow()
{
    top.window.moveTo(0,0);
    if (document.all) 
    {
        top.window.resizeTo(screen.availWidth,screen.availHeight);
    }
    else if (document.layers||document.getElementById) 
    {
        if (top.window.outerHeight<screen.availHeight||top.window.outerWidth<screen.availWidth)
        {
            top.window.outerHeight = screen.availHeight;
            top.window.outerWidth = screen.availWidth;
        }
    }
}

function openWindow(URL, windowName, width, height, scrollbars, resizable) 
{  
  var winl = (screen.width-width)/2;
  var wint = (screen.height-height)/2;
  if (winl < 0) winl = 0;
  if (wint < 0) wint = 0;
  var settings = 'height=' + height + ',';
  settings += 'width=' + width + ',';
  settings += 'top=' + wint + ',';
  settings += 'left=' + winl + ',';
  settings += ',toolbar=no,directories=no,status=no,menubar=no,scrollbars=' + scrollbars + ',resizable=' + resizable + ',modal=yes'

  newwin = window.open(URL, windowName, settings);
  newwin.focus();
  return true;
}

function popupModalWin(URL, windowName, width, height, scrollbars, resizable) {
    if(windowName==null)
        windowName = 'popup';
    if(width==null)
        width = 250;
    if(height==null)
        height = 250;
    if(scrollbars==null)
        scrollbars = 'no';
    if(resizable==null)
        resizable = 'no';
    if (window.showModalDialog) {
        return window.showModalDialog(URL,windowName, "dialogWidth:" + width + "px;dialogHeight:" + height + "px;resizable:" + resizable + ";scroll:" + scrollbars + ";status:no");
    } else {
        window.open(URL, windowName, 'height=' + height + ',width=' + width + ',toolbar=no,directories=no,status=no,menubar=no,scrollbars=' + scrollbars + ',resizable=' + resizable + ',modal=yes');
    }
    return true;
} 

function getDDValue(dd_id)
{
    var dd = getObject(dd_id);
    if(dd.selectedIndex > -1)
        return dd[dd.selectedIndex].value;   
    else
        return '';     
}

function getDDText(dd_id)
{
    var dd = getObject(dd_id);
    if(dd.selectedIndex > -1)
        return dd[dd.selectedIndex].text;   
    else
        return '';     
}

function fillDD(ddl, values)
{    
    ddl.options.length = 0;
    for(i = 0; i < values.length; i++) 
    {
        var theOption = new Option;
        theOption.text = values[i].text;
        theOption.value = values[i].value;
        ddl.options[i] = theOption;
    }
}

function resizeFrameOnGridSizeChange(gridTableId, initHeight)
{
    if(initHeight==null)
        initHeight = 768;
    var theIFrame = top.getObject("IFRAME1");
    var RadGrid1 = getObject("RadGrid1_ctl01");
    targetHeight = RadGrid1.clientHeight + initHeight;
	theIFrame.style.height = parseInt(targetHeight) + "px";
}

function opacity(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 

    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
} 

//change the opacity for different browsers 
function changeOpac(opacity, id) { 
    var object = getObject(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
    // make object invisible if opacity=0
    if(opacity==0)
       setElementVisibility(id, false);   // make object invisible if opacity = 0
    else
       setElementVisibility(id, true);   // make object visible if opacity > 0        
}

//get the opacity
function getOpac(id) { 
    var object = getObject(id).style; 
    return object.opacity; 
}






