function preloadImages()
{
   var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function FormErrorMarkUp(field_id, error_caption)
{
    Event.observe(window, 'load', function(){_formErrorMarkDraw(field_id,error_caption)}, true);
    //_formErrorMarkDraw(field_id,error_caption);
    $(field_id).style.border = "1px solid red";
    //document.write("<img src='/img/btn/warning.gif'>");
}

function _formErrorMarkDraw(field_id, error_caption)
{
    var objErrorCaptionContainer = document.createElement("div");
    objErrorCaptionContainer.setAttribute('id',field_id+'_error_hint');
    objErrorCaptionContainer.innerHTML = error_caption;
    var objBody = document.getElementsByTagName("body").item(0);
    objErrorCaptionContainer.style.top = getY($(field_id)) + 'px';
    objErrorCaptionContainer.style.left = (getX($(field_id)) + $(field_id).offsetWidth + 5) + 'px';
    objBody.appendChild(objErrorCaptionContainer);
    objErrorCaptionContainer.className = 'errorhint';
    Event.observe($(field_id), 'change', function(){_formErrorMarkOut(field_id)}, true);
}

//turns field/object to fixed mode
function _formErrorMarkOut(field_id)
{
    field = $(field_id);
    $(field_id + '_error_hint').hide();
    field.style.border = "1px solid red";
}

/*
 * Makes an visiblity of object dependet on form field value
 */
function depvis(srcObjID, dstObjID, show_on_value)
{
    srcObj = $(srcObjID);
    dstObj = $(dstObjID);
    Event.observe(srcObjID, 'click' , function() { _depvis_redraw(srcObjID, dstObjID, show_on_value) }, false);
    Event.observe(srcObjID, 'change', function() { _depvis_redraw(srcObjID, dstObjID, show_on_value) }, false);
    _depvis_redraw(srcObjID, dstObjID, show_on_value);
}

function _depvis_redraw(srcObjID, dstObjID, show_on_value)
{
    srcObj = $(srcObjID);
    dstObj = $(dstObjID);
    if (srcObj.type == 'checkbox' || srcObj.type == 'radio')
    {
        value = srcObj.checked;
    }
    else
    {
        value = srcObj.value;
    }
    if (show_on_value === true)
    {
        if (value)
        {
            dstObj.show();
        }
        else
        {
            dstObj.hide();
        }
    }
    else if (show_on_value === false)
    {
        if (value)
        {
            dstObj.hide();
        }
        else
        {
            dstObj.show();
        }
    }
    else
    {
        if (value == show_on_value)
        {
            dstObj.hide();
        }
        else
        {
            dstObj.show();
        }
    }
}

function stickTo(srcObj, dstObj, srcCorner, dstCorner)
{
    y = getY(srcObj);
    x = getX(srcObj);
    dstObj.show();
    if (srcCorner == 'tl')
    {
    	toX = x; toY = y;
    }
    else if (srcCorner == 'tr')
    {
    	toX = x + srcObj.offsetWidth; toY = y;
    }
    else if (srcCorner == 'bl')
    {
    	toX = x; toY = y + srcObj.offsetTop;
    }
    else if (srcCorner == 'br')
    {
    	toX = x + srcObj.offsetWidth; toY = y + srcObj.offsetHeight;
    }
    if (dstCorner == 'tl')
    {
    	offsetX = 0; offsetY = 0;
    }
    else if (dstCorner == 'tr')
    {
    	offsetX = dstObj.offsetWidth; offsetY = 0;
    }
    else if (dstCorner == 'bl')
    {
    	offsetX = 0; offsetY = dstObj.offsetHeight;
    }
    else if (dstCorner == 'br')
    {
    	offsetX = dstObj.offsetWidth; offsetY = dstObj.offsetHeight;
    }
    dstX = toX - offsetX;
    dstY = toY - offsetY;
    dstObj.style.top = dstY + 'px';
    dstObj.style.left = dstX + 'px';
}

function getY(oElement)
{
    var iReturnValue = 0;
    while( oElement != null )
    {
	    iReturnValue += oElement.offsetTop;
	    oElement = oElement.offsetParent;
    }
    return iReturnValue;
}

function getX(oElement)
{
    var iReturnValue = 0;
    while(oElement != null)
    {
	    iReturnValue += oElement.offsetLeft;
	    oElement = oElement.offsetParent;
    }
    return iReturnValue;
}

//go to url with comfirmation
function sure(URL, Message)
{
    if (typeof(Message) == 'undefined')
    {
        Message = 'Are you sure?';
    }
    if (confirm(Message))
    {
        document.location.href = URL;
    }
}
//go to url
function go(URL)
{
    document.location.href = URL;
}

//mmflash licensing flash
function write_flash(arg, w, h, bgcolor)
{
    document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH="'+w+'" HEIGHT="'+h+'" id="'+arg+'" ALIGN=""><PARAM NAME=bgcolor VALUE="'+bgcolor+'"><PARAM NAME=movie VALUE="'+arg+'"> <PARAM NAME=quality VALUE=high> <PARAM NAME=bgcolor VALUE=#333333> <EMBED src="'+arg+'" quality=high bgcolor=#333333  WIDTH="'+w+'" HEIGHT="'+h+'" NAME="'+arg+'" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED></OBJECT>');
}

function getPageSize(){

	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY)
	{
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	}
	else if
	(document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	}
	else
	{ // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight)
	{	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
	{ // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	}
	else if (document.body)
	{ // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if (yScroll < windowHeight)
	{
		pageHeight = windowHeight;
	}
	else
	{
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if (xScroll < windowWidth)
	{
		pageWidth = windowWidth;
	}
	else
	{
		pageWidth = xScroll;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}

