//### global variable declarations
//### -----------------------------------------------------
var bImagesLoaded		= false;

//### functions & subroutines
//### -----------------------------------------------------

function preLoadImage( id, path, ext )
{
	eval( id + "_on = new Image();" );
	eval( id + "_on.src = '" + path + "_on." + ext + "'" );
	eval( id + "_off = new Image();" );
	eval( id + "_off.src = '" + path + "_off." + ext + "'" );
}

function toggleImage( img, state )
{
	if( bImagesLoaded )
		eval( "img.src = " + img.id + "_" + state + ".src" );
}

function centerElement( element )
{
	var winWidth = document.body.clientWidth;
	var winHeight = document.body.clientHeight;
	var elWidth = element.offsetWidth;
	var elHeight = element.offsetHeight;
	var left = ( winWidth - elWidth ) / 2;
	var top = winHeight / 2;
	element.style.left = left + "px";
	element.style.top = top + "px";
}
function _centerElement2( element )
{
	var winWidth = document.body.clientWidth;
	var winHeight = document.body.clientHeight;
	var elWidth = element.offsetWidth;
	var elHeight = element.offsetHeight;
	var left = ( winWidth - elWidth ) / 2;
	var top = ( winHeight - elHeight ) / 2;
	element.style.left = left + "px";
	element.style.top = top + "px";
}


function centerElement2(elem)
{
     var d = document;  
     var rootElm = (d.documentElement && d.compatMode == 'CSS1Compat') ? d.documentElement : d.body;
       var vpw = self.innerWidth ? self.innerWidth : rootElm.clientWidth; 
     // viewport width  
     var vph = self.innerHeight ? self.innerHeight : rootElm.clientHeight; 
     // viewport height 
     elem.style.left = (rootElm.scrollLeft + (vpw - elem.offsetWidth) / 2) + 'px';   
     elem.style.top = (rootElm.scrollTop + (vph - elem.offsetHeight)/2 ) + 'px';
}


function moveElement(elem, isCentered, left, top, width, height)
{
     elem.style.width = width+'px';
     elem.style.height = height+'px';
     if ( isCentered ) {
        centerElement2(elem);
     } else {
         elem.style.left = left+'px';
         elem.style.top = top+'px';
     }
}


function Close_All_Popups() {
    try {
        if ( typeof(Contact_PopupComplete_Close) === 'function' )
	        Contact_PopupComplete_Close();
        if ( typeof(Contact_CallMeBack_Close) === 'function' )
	        Contact_CallMeBack_Close();
        if ( typeof(Contact_CallMeBack_Close) === 'function' )
		    Contact_CallMeBack_Close();
        if ( typeof(Login_Close) === 'function' )
	        Login_Close();
        if ( typeof(CloseUp_Close) === 'function' )
	        CloseUp_Close();
    } catch (e) {
    }
}
