var iex     = (document.all);
var nav     = (document.layers);
var old     = (navigator.appName=="Netscape" && !document.layers && !document.getElementById);
var n_6     = (window.sidebar);
var popup_id    = "popup";
var c_popup     = -1;
var last_obj    = 0;
var overpopup   = 0;
var blockpopup  = 0;

function getHeight() {
  var myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
  return myHeight;
}

function lp_getPageSize(){

        var xScroll, yScroll, pageHeight, pageWidth;

        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;
}

function lp_getPageScroll(){

    var yScroll, xScroll;

    if (self.pageYOffset) {
        yScroll = self.pageYOffset;
        xScroll = self.pageXOffset;
    } else if (document.documentElement && document.documentElement.scrollTop){  // Explorer 6 Strict
        yScroll = document.documentElement.scrollTop;
        xScroll = document.documentElement.scrollLeft;
    } else if (document.body) {// all other Explorers
        yScroll = document.body.scrollTop;
        xScroll = document.body.scrollLeft;
    }

    arrayPageScroll = new Array(xScroll,yScroll)
    return arrayPageScroll;
}

function show_popup(e,obj,title,text,width,height) {

        c_popup = obj;
        var x = y = 0;
        //var tag = obj;


       // var tag_offet = Position.positionedOffset(tag);
       // x = tag_offet[0]; y = tag_offet[1];

        var popup = $(popup_id);
        //y += 12;
       // var tag_d = Element.getDimensions(tag);
       // y += tag_d.height+3;
   
        var d = Element.getDimensions( $('page') ); 
        //alert(d.height);
        //alert(y+height);
       /* if ( y+height+30 > d.height ) {
            //y -= (height+tag_d.height+30+ ((ua=='msie')?document.body.scrollTop:0) );\
            y = tag_offet[1] - 34 - height;
        }*/

        if (ua == 'msie') {
            $$("select").each( function(el) {
                Element.setStyle( el, {visibility: 'hidden'} );
            });
        }

//        Element.getElementsByClassName(popup, "title")[0].style.display = (title=='')?'none':'';

        Element.getElementsByClassName(popup, "ptitle")[0].innerHTML = "<div style='float: right;'><a href='/' onclick='hidepopup();return false;'>close</a></div>" + title;
        var p_content = Element.getElementsByClassName(popup, "pcontent")[0];
        Element.update( p_content, "<div id='con-top' class='clear'></div>" + text );


        Element.setStyle( p_content, {height: height+'px'} );

        arr = lp_getPageSize();
        scr = lp_getPageScroll();

    	x = Math.round(arr[2]/2) - Math.round(width/2); 
    	y  = Math.round(arr[3]/2) - Math.round(height/2)+scr[1]; 

//		y = (d.height - height) / 2;
//		x = (d.width - width) / 2;
		
        Element.setStyle( popup, {
                top: y+'px', 
                left: x+'px',
                width: width+'px', 
                visibility: 'visible', 
                //height: height+'px',
                display: 'block'
            });

//        Element.down(p_content, "#con-top",0).scrollIntoView(false);

        obj.blur();
        last_obj = obj;
        e.cancelBubble=true;
        return false;

}

function hidepopup() {

//     if (arguments.length==1 && arguments[0]!=currentJobID && !onpopup) return false;
    if (ua == 'msie') {
        $$("select").each( function(el) {
            Element.setStyle( el, {visibility: 'visible'} );
        });
    }

    if (last_obj!=0) {
        last_obj.blur();
    }
    var popup = $(popup_id);
    if ( !popup ) { return; }
    popup.style.display = "none";
    c_popup = -1;
    last_obj= 0;
    overpopup = 0;
    //currentJobID = -1;
    return true;
}


	function openWin(vUrl,title,obj,event,w,h) {
		wleft = (screen.width - w) / 2;
		wtop = (screen.height - h) / 2;
		videoWindow = window.open(vUrl,'wndpopup',
			"height="+h+",width="+w+",top="+wtop+",left="+wleft+",menubar=no,location=no,resizable=yes,scrollbars=yes,status=yes" );
	}	

/* Copyright 2006 LuckyTeam.co.uk. To use this code on your own site, visit http://luckyteam.co.uk */

/**
 * common things that should be done
 * when the document loaded
 */
function onWindowLoad() {

    $A(document.getElementsByTagName('a')).each(
        function(val, idx) {
            Event.observe(val, 'click', function(e){var o = e.currentTarget || e.srcElement; o.blur();} );
        }
    );


    $A(Selector.findChildElements(document, ["input[type=button]", "input[type=submit]", "input[type=reset]"])).each(
        function(val) {
            Event.observe(val, 'mousedown', function(e){
                    if ( '_msie' != ua ) {
                        var o = e.currentTarget || e.srcElement;
                        if ( o.pushed ) { return; }
                        o.pushed = true;
                        o.style.borderStyle = "inset";
                    }
                });

            Event.observe(val, 'mouseup', function(e){
                    if ( '_msie' != ua ) {
                        var o = e.currentTarget || e.srcElement;
                        if ( !o.pushed ) { return; }
                        o.pushed = false;
                        o.style.borderStyle = "";
                    }
                    o.blur();
                });

            Event.observe(val, 'mouseout', function(e){
                    if ( '_msie' != ua ) {
                        var o = e.currentTarget || e.srcElement;
                        if ( !o.pushed ) { return; }
                        o.pushed = false;
                        o.style.borderStyle = "";
                    }
                    o.blur();
                });
        }
    );
}

Event.observe(window, 'load', onWindowLoad, false);


