// Select browser type
//alert(navigator.userAgent);
var ie = false; // Internet Explorer
var nn4 = false; // Netscape4
var nn6 = false; // Netscape6
var op = false; // Opera
var oth = false; // Other browser

if ( window.opera )
{
    op = true;
//    alert('Opera');
}
else if ( document.all )
{
    ie=true;
//    alert('IE');
}
else if( document.layers )
{
    nn4=true;
//    alert('NN4');
}
else
{
    oth=true;
//    alert('Other browser');
}
if (!document.all && document.getElementById)
{
    nn4=false;
    oth=false;
    nn6=true;
//    alert('NN6');
}

function selectElement(id)
{
    if (ie || op)
        return eval( "document.all." + id );
    if (nn6)
        return eval( "document.getElementById('" + id + "')" );
    if (nn4)
        return eval( "document." + id );
    return null;
}

function selectElementStyle(id)
{
    if (ie || op)
        return eval( "document.all." + id + ".style" );
    if (nn6)
        return eval( "document.getElementById('" + id + "').style" );
    if (nn4)
        return eval( "document." + id );
    return null;
}

function setElementStyle(id, style, size)
{
    if (ie || op)
    {
        eval( "document.all." + id + ".style." + style + "='" + size +"px'");
        return;
    }
    if (nn6)
    {
        eval( "document.getElementById('" + id + "').style." + style + " = '" + size +"px'");
        return;
    }
    if (nn4)
    {
        eval( "document." + id + "." + style + " = '" +size +"px'");
        return;
    }
    return;
}

function elementWidth(id)
{
    var width = 0;
    var element = selectElement(id);
    if (element != null)
    {
        if (nn4)
        {
            width=element.document.width;
        }
        else if (ie || nn6 || op)
        {
            if (op)
            {
                // when new submenus added new conditions should be inserted 
                if (id=='submenu1') width = 105;
                else if (id=='submenu2') width = 201;
                else if (id=='submenu3') width = 297;
                else if (id=='submenu4') width = 297;
                else if (id=='submenu6') width = 223;
                else if (id=='submenu8') width = 120;
                else width=element.offsetWidth; // width=0 when id==submenuX, width=<width_of_element> when id==menuX
            }
            else width=element.offsetWidth;
        }
        else // op or oth
        {
            width=element.style.pixelWidth;
        }
    }
    return width;
}

function elementHeight(id)
{
    var height = 0;
    var element = selectElement(id);
    if (element != null)
    {
        if (nn4)
        {
             height = element.document.height;
        }
        else if (ie || nn6 || op)
        {
            height = element.offsetHeight;
        }
        else // op or oth
        {
            height = element.style.pixelHeight;
        }
    }
    return height;
}

function elementLeft(id)
{
    var element = selectElement(id);
    var leftPosition = 0;
    if (nn4) {
        leftPosition = parseInt(element.left);
    }
    else
    {
        if (ie || nn6 || op)
            leftPosition = parseInt(element.offsetLeft);
        else
            leftPosition = parseInt(element.style.left);
    }
    return leftPosition;
}

function elementTop(id)
{
    var element = selectElement(id);
    if (nn4)
    {
        topPosition = parseInt(element.top);
    }
    else
    {
        if (nn6 || op)
            topPosition = parseInt(element.offsetTop);
        else if (ie)
        {
            topPosition = parseInt(element.offsetTop);
            // 310 - 178 ???
            // Change only in older IE (topPosition=266???, in new IE topPosition=136)
            if (topPosition > 200)
            {
                topPosition-= 151;
            }
            if ( topPosition <= 0 ) // set top offset
            {
                 topPosition=158;
            }
        }
        else
            topPosition = parseInt(element.style.top);
    }
    return topPosition;
}


function elementVisible(id, visible)
{
    var element = selectElementStyle(id);
    if ( visible )
    {
        element.display='';
    }
    else
    {
        element.display='none';
    }
    return;
}

function elementVisibleChange(id)
{
    var element = selectElementStyle(id);
    if ( element.display == 'none' )
    {
        element.display='';
    }
    else
    {
        element.display='none';
    }
    return;
}

function changeIcon(divId, iconId, expandIcon, collapseIcon )
{
    var element = selectElementStyle(divId);
    if ( element.display=='none' )
    {
        selectElement( iconId ).src = expandIcon;
    }
    else
    {
        selectElement( iconId ).src = collapseIcon;
    }
    return;
}

function validateFormField( formName, fieldName, message, validatorType )
{
	var result = true;
	var formElement = selectElement(formName);
	eval( "formElement = formElement." + fieldName + ";" );

	if ( validatorType == "not_null" )
	{
		if ( formElement.value == "" )
		{
			result = false;
		}
	}
	
	if ( result == true )
	{
		return true; 
	}
	else
	{
		alert( message );
		return false;
	}
}

function getScreenWidth()
{
    var screenWidth = 0;
    if (window.screen)
    {
        screenWidth = window.screen.availWidth;
    }
    else
    {
        screenWidth = 640;
    }
    return screenWidth;
}

function getScreenHeight()
{
    var screenHeight = 0;
    if(window.screen)
    {
        screenHeight = window.screen.availHeight;
    }
    else
    {
        screenHeight = 480;
    }
    return screenHeight;
}

function showImage( file, width, height )
{
    var imageTop = getScreenHeight()/2 - height/2;
    var imageLeft = getScreenWidth()/2 - width/2;
        
    var imageSettings = "width=" + width + ", height=" + height + ", screenX=" + imageLeft + ", screenY=" + imageTop + ", left=" + imageLeft + ", top=" + imageTop
      + ", toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no";
    // alert(imageSettings);
    var newImage = window.open( "", "", imageSettings );
    newImage.document.open();

    var imageContent = "<html><head><title>www.sp2.sroda.prv.pl - foto</title></head><body style='margin-left: 0px; "
      + "margin-right: 0px; margin-top:0px; margin-bottom: 0px;'><img src='" + file + "' title='' /></body></html>";
    
    newImage.document.write( imageContent );
    newImage.document.close();
    newImage.focus();
}

function showScreenShot( file, width, height )
{
    var imageTop = getScreenHeight()/2 - height/2;
    var imageLeft = getScreenWidth()/2 - width/2;
        
    var imageSettings = "width=" + width + ", height=" + height + ", screenX=" + imageLeft + ", screenY=" + imageTop + ", left=" + imageLeft + ", top=" + imageTop
      + ", toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes";
    // alert(imageSettings);
    var newImage = window.open( "", "", imageSettings );
    newImage.document.open();

    var imageContent = "<html><head><title>Verax Systems</title></head><body style='margin-left: 0px; "
      + "margin-right: 0px; margin-top:0px; margin-bottom: 0px;'><img src='" + file + "'/></body></html>";
    
    newImage.document.write( imageContent );
    newImage.document.close();
    newImage.focus();
}

function showTable( file, width, height )
{
    var imageTop = getScreenHeight()/2 - height/2;
    var imageLeft = getScreenWidth()/2 - width/2;
        
    var imageSettings = "width=" + width + ", height=" + height + ", screenX=" + imageLeft + ", screenY=" + imageTop + ", left=" + imageLeft + ", top=" + imageTop
      + ", toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no";
    window.open( file, "", imageSettings );   
}

function displayFlash( file, width, height )
{
    if (nn6 || nn4)
    {
        document.write('<object');
        document.write(' data="'+file+'"');
        document.write(' pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"');
        document.write(' type="application/x-shockwave-flash"' );
        document.write(' width="'+width+'"' );
        document.write(' height="'+height+'"' );
        document.write(' loop="true"' );
        document.write(' quality="best"' );
        document.write(' bgcolor="#003399">' );
        document.write('</object>' );
    }
    else if (ie || op)
    {
        document.write('<object');
        document.write(' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"');
        document.write(' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0"');
        document.write(' width="'+width+'"');
        document.write(' height="'+height+'">');
        document.write(' <param name="movie" value="'+file+'">');
        document.write(' <param name="menu" value="false">');
        document.write(' <param name="quality" value="high">');
        document.write(' <param name="bgcolor" value="#003399">');
        document.write('</object>');
    }
    else
    {
        document.write('<object');
        document.write(' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"');
        document.write(' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0"');
        document.write(' width="'+width+'" height="'+height+'">');
        document.write(' <param name="movie" value="'+file+'">');
        document.write(' <param name="quality" value="high">');
        document.write(' <embed src="'+file+'" quality="high"');
        document.write(' pluginspage="http://www.macromedia.com/go/getflashplayer"');
        document.write(' type="application/x-shockwave-flash" width="'+width+'" height="'+height+'">');
        document.write(' </embed>');
        document.write(' </object>');
    }
}

function showWhoIs( address )
{
    var height = 600;
    var width = 800;
    var windowTop = getScreenHeight()/2 - height/2;
    var windowLeft = getScreenWidth()/2 - width/2;

    var windowSettings = "width=" + width + ", height=" + height + ", screenX=" + windowLeft + ", screenY=" + windowTop + ", left=" + windowLeft + ", top=" + windowTop
      + ", toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes";
    var newWindow = window.open( "", "", windowSettings );
    newWindow.document.open();

/*    var imageContent = "<html><head><title>Who is?</title></head>" +
        "<body onload=\"document.getElementById('thisform').submit();\">" +
        "<form id='thisform' method='post' action='http://ws.arin.net/cgi-bin/whois.pl'>" +
        "<input type='hidden' Name='queryinput' value='" + address + "'>" +
        "</form>" +
        "</body></html>";
*/
    var windowContent = "<script type='text/javascript'>document.location='http://www.ripe.net/fcgi-bin/whois?form_type=simple&full_query_string=&searchtext=" + address + "&do_search=Search';</script>";
    newWindow.document.write( windowContent );
    newWindow.document.close();
    newWindow.focus();

}

