﻿// JScript File
var _windowWidth = 0;
var _windowHeight = 0;
var _windowId = 0;
var _speed = 40;

function showPopupWindow(windowId, closeImage, closeOverImage, url, width, height, top, left, speed) {
    var features = 'height=' + height + ',width=' + width;
    window.open(url, windowId, features +',location=no');
}

function showPopupWindowFrame( windowId, closeImage, closeOverImage, url, width, height, top, left, speed )
{
    if( document.getElementById( windowId ) ) return;
    _windowId = windowId;
    _height = height;
    _width = width;
    _speed = speed;
    
    var shadow = document.createElement( 'div' );
    var frame = document.createElement( 'div' );
    var title = document.createElement( 'div' );
    var close = document.createElement( 'img' );
    var iframe = document.createElement( 'iframe' );
    
    shadow.className = 'window-shadow';
    shadow.style.zIndex = '1';
    shadow.style.top = top + 'px';
    shadow.style.left = left + 'px';
    shadow.id = windowId;
    
    frame.className = 'window';
    title.style.textAlign = 'right';
    title.style.padding = '2px';
    close.src = closeImage;
    close.alt = 'Close';
    close.style.cursor = 'hand';
    close.onclick = function() { hidePopupWindow( windowId ); };
    close.onmouseover = function() { close.src = closeOverImage; };
    close.onmouseout = function() { close.src = closeImage; };
    iframe.src = url;
    iframe.style.width = 0 + 'px';
    iframe.style.height = 0 + 'px';
    iframe.id = windowId + 'Frame';
    iframe.frameBorder = 'no';
    
    title.appendChild( close );
    frame.appendChild( title );
    frame.appendChild( iframe );
    shadow.appendChild( frame );
    document.body.appendChild( shadow );
    
    sizePopupWindow();
    
    return true;
}

function sizePopupWindow()
{
    var iframe = document.getElementById( _windowId + 'Frame' );
    var width = iframe.clientWidth;
    var height = iframe.clientHeight;
    var resize = false;
    
    if( width < _width-_speed )
    {
        width = width+_speed;
        resize = true;
    }
    else
        width = _width;
    
        
    if( height < _height-_speed )
    {
        height = height+_speed;
        resize = true;
    }
    else
        height = _height;
    
    iframe.style.width = width + 'px';
    iframe.style.height = height + 'px';
    
    if( resize )
        setTimeout( 'sizePopupWindow()', 1 );
        
}

function hidePopupWindow( windowId )
{
    var win = document.getElementById( windowId );
    
    while( win.childNodes[0] )
        win.removeChild( win.childNodes[0] );
        
    document.body.removeChild( win );
}

function hidePopupWindowByFrameId( frameId )
{
    alert( frameId );
    var windowId = frameId.substr( 0, frameId.length-5 );
    alert( windowId );
    hidePopupWindow( windowId );
}

function getMangledObject( id, tag )
{
    var elems = document.getElementsByTagName(tag);
    
    for( var i = 0; i < elems.length; i++ )
    {
        if( elems[i].id != null )
        {
            if( elems[i].id == id )
                return elems[i];
            if( elems[i].id.length > id.length &&
                elems[i].id.substring( elems[i].id.length - ( id.length + 1 ) ) == ( '_' + id ) )
                return elems[i];
            if( elems[i].id.length > id.length &&
                elems[i].id.substring( elems[i].id.length - ( id.length + 1 ) ) == ( '$' + id ) )
                return elems[i];
        }
    }
    
    return null;
}

function getObject( obj ) {

  // step 1
  if ( document.getElementById ) {
    obj = document.getElementById( obj );

  // step 2
  } else if ( document.all ) {
    obj = document.all.item( obj );

  //step 3
  } else {
    obj = null;
  }

  //step 4
  return obj;
}

function moveObject( obj, e ) {

  // step 1
  var tempX = 0;
  var tempY = 0;
  var offset = 5;
  var objHolder = obj;

  // step 2
  obj = getObject( obj );
  if (obj==null) return;

  // step 3
  if (document.all) {
    tempX = event.clientX + document.body.scrollLeft;
    tempY = event.clientY + document.body.scrollTop;
  } else {
    tempX = e.pageX;
    tempY = e.pageY;
  }

  // step 4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}

  // step 5
  obj.style.top  = (tempY + offset) + 'px';
  obj.style.left = (tempX + offset) + 'px';

  // step 6
  displayObject( objHolder, true );
}

function displayObject( obj, show ) {
  // step 1
  obj = getObject( obj );
  if (obj==null) return;

  // step 2
  obj.style.display = show ? 'block' : 'none';
  obj.style.visibility = show ? 'visible' : 'hidden';
}

function findPos(obj)
{
    var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function removeChilderen( elem )
{
	if( elem != null )
	{
		while( elem.firstChild )
		{
			elem.removeChild( elem.firstChild );
		}
	}	
}

function validateABA( aba )
{
    if( aba.length != 9 )
        return false;
        
    var n = 0;
    for( var i = 0; i < aba.length; i += 3 )
    {
        n += parseInt( aba.charAt(i), 10 ) * 3 + parseInt( aba.charAt(i+1), 10 ) * 7 + parseInt( aba.charAt(i+2), 10 );
    }
    
    if( n != 0 && n % 10 == 0 )
        return true;
    else
        return false;
}









