/*
 * Copyright (c) 1996-2007 Aplus.Net Internet Services
 * All rights reserved.
 * Reproduction or transmission in whole or in part,
 * in any form or by any means, electronic, mechanical
 * or otherwise, is prohibited without the prior written
 * consent of the copyright owner.
 */
/* Including: core.js, $Id: core.js,v 1.19.2.3 2008/04/02 08:58:59 andreik Exp $ */

var GlobPageHasLoaded = false;
var GlobPanelInstance;
var GlobPanelCurrentBaseUrl;
var GlobPanelPlainBaseUrl;
var GlobPanelSecureBaseUrl;
var GlobPanelInstanceSuffix;
var GlobOnLoadEvents  = new Array();
var GlobMenuBuffer    = new Array();
function GlobRegisterOnLoadEvent( MyEvent, Priority ) {
GlobOnLoadEvents[ GlobOnLoadEvents.length ] = MyEvent;
return GlobOnLoadEvents.length;
}
function GlobLoadOnloadEvents() {
GlobWaitTimeoutID = setTimeout( function () { GlobWaitHide(); }, 0 );
GlobPageHasLoaded = true;
GlobProcessMenuEntries();
for ( var i = 0; i < GlobOnLoadEvents.length; i++ ) {
var x = GlobOnLoadEvents[i];
if ( typeof( x ) == 'function' ) {
eval( x )();
} else {
eval( x );
}
}
}
function GlobIncludeRemoteJS( RemoteFile ) 
{
var remote_file = RemoteFile;
var head;
try {
head = document.getElementsByTagName('head').item(0);
} catch (e) {}
if ( !head || typeof(head) == 'undefined' )
return false;
var js       = document.createElement('script');
js.setAttribute( 'language', 'javascript' );
js.setAttribute( 'type', 'text/javascript' );
js.setAttribute( 'src', remote_file );
head.appendChild( js );
return false;
}
function GlobNewWindow( Url, Width, Height, Attr, PosLeft, PosTop ) 
{
Width  = Width  == null ? 350 : Width;
Height = Height == null ? 200 : Height;
return GlobNewExtWindow( GlobPanelCurrentBaseUrl + Url, Width, Height, Attr, PosLeft, PosTop );
}
function GlobNewExtWindow( Url, Width, Height, Attr, PosLeft, PosTop ) 
{
var leftpos = PosLeft == null ? parseInt( ( screen.width  - Width  ) / 2 ) : PosLeft;
var toppos  = PosTop  == null ? parseInt( ( screen.height - Height ) / 2 ) : PosTop;
var attr    = Attr    == null ? "status=no,toolbar=no,menubar=no,location=no" : Attr;
return window.open( Url, 'CP_Window_' + (new Date()).getTime(), "height=" + Height + ",width=" + Width + ",top=" + toppos + ",left=" + leftpos + "," + attr );
}
function GlobNewExtWindowEx( Url, Width, Height ) 
{
return GlobNewExtWindow( Url, Width, Height, 'status=no,titlebar=no,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes' );
}
function GlobNewIntWindow( Url, Width, Height ) 
{
try {
StickyTooltip_Open( this, window.event, null, Url, Width, Height );
} catch (e) {
}
return false;
}
var isIE  = document.all ? true : false;
var isDOM = document.getElementById ? true : false;
var isNS4 = document.layers ? true : false;
function GlobGetBlock( BlockName )
{
if (isDOM) {
return document.getElementById( BlockName );
} else if (isIE) {
return document.all.BlockName;
} else if (isNS4) {
return document.layers[ BlockName ];
}
return null;
}
function GlobToggleBlock( BlockName, Action)
{
var block  = GlobGetBlock( BlockName );
if ( !block ) 
return false;
if (isDOM)
{
if (Action == 's') {
if ( block ) {
block.style.visibility = 'visible';
}
}
if (Action == 'h') {
if ( block ) {
block.style.visibility = 'hidden';
}
}
}
else if (isIE) {
if (Action == 's') eval( block + ".style.visibility='visible';");
if (Action == 'h') eval( block + ".style.visibility='hidden';");
}
else if (isNS4) {
if (Action == 's') eval( block + ".visibility='show';");
if (Action == 'h') eval( block + ".visibility='hide';");
}
}
function GlobShowBlock( BlockName ) {
GlobToggleBlock( BlockName, 's' );
}
function GlobHideBlock( BlockName ) {
GlobToggleBlock( BlockName, 'h' );
}
function GlobGetLeft( Element ) {
var offset = 0;
while ( Element ) {
offset  += Element.offsetLeft;
Element  = Element.offsetParent;
}
return offset;
}
function GlobGetTop( Element ) {
var offset = 0;
while ( Element ) {
offset  += Element.offsetTop;
Element  = Element.offsetParent;
}
return offset;
}
function GlobWindowWidth () {
return GlobPageSize().windowWidth;
}
function GlobWindowHeight () {
return GlobPageSize().windowHeight;
}
function GlobPopupSize ( ScreenWidth, ScreenHeight, RatioWidth, RatioHeight ) {
var nW = 640, nH = 480;
if ( typeof( ScreenWidth ) == 'undefined' || ScreenWidth == null ) ScreenWidth = screen.width;
if ( typeof( ScreenHeight ) == 'undefined' || ScreenHeight == null ) ScreenHeight = screen.height;
if ( typeof( RatioWidth ) == 'undefined' || RatioWidth == null ) RatioWidth = 0.75;
if ( typeof( RatioHeight ) == 'undefined' || RatioHeight == null ) RatioHeight = 0.75;
nW = parseInt( ScreenWidth * RatioWidth );
nH = parseInt( ScreenHeight * RatioHeight );
return {width:nW,height:nH};
}
function GlobPageSize () {
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 ){ 
xScroll = document.body.scrollWidth;
yScroll = document.body.scrollHeight;
} else { 
xScroll = document.body.offsetWidth;
yScroll = document.body.offsetHeight;
}
var windowWidth, windowHeight;
if ( self.innerHeight ) { 
windowWidth = self.innerWidth;
windowHeight = self.innerHeight;
} else if ( document.documentElement && document.documentElement.clientHeight ) { 
windowWidth = document.documentElement.clientWidth;
windowHeight = document.documentElement.clientHeight;
} else if ( document.body ) { 
windowWidth = document.body.clientWidth;
windowHeight = document.body.clientHeight;
}	
var pageHeight, pageWidth;
if ( yScroll < windowHeight ) {
pageHeight = windowHeight;
} else { 
pageHeight = yScroll;
}
if ( xScroll < windowWidth ) {
pageWidth = windowWidth;
} else {
pageWidth = xScroll;
}
return { pageWidth: pageWidth ,pageHeight: pageHeight , windowWidth: windowWidth, windowHeight: windowHeight };
}
function GlobWindowScroll () {
var w = window;
var d = w.document;
var T, L, W, H;
if ( d.documentElement && d.documentElement.scrollTop ) {
T = d.documentElement.scrollTop;
L = d.documentElement.scrollLeft;
} else if ( d.body ) {
T = d.body.scrollTop;
L = d.body.scrollLeft;
}
if ( w.innerWidth ) {
W = w.innerWidth;
H = w.innerHeight;
} else if ( d.documentElement && d.documentElement.clientWidth ) {
W = d.documentElement.clientWidth;
H = d.documentElement.clientHeight;
} else {
W = d.body.offsetWidth;
H = d.body.offsetHeight
}
return { top: T, left: L, width: W, height: H };
}
function GlobHistoryBack ( URL ) {
if ( URL ) {
GlobChangeLocationWithProgress( URL );
}
else {
window.history.back();
}
return false;
}
function GlobPageURL () {
return window.location.protocol + '/'+'/' + window.location.host + window.location.pathname + window.location.search;
}
function GlobChangeLocation ( URL, ForceRefresh ) {
if ( URL != GlobPageURL() ) {
window.location = URL + ( ForceRefresh ? '#' + (new Date()).getTime() : '' );
}
else {
window.location.assign( URL );
}
return true;
}
function GlobChangeLocationWithProgress ( URL ) {
try {
GlobMkNavi( null );
} catch ( e ) {}
GlobChangeLocation( URL, 1 );
return true;
}
function GlobReloadLocation ( ForceRefresh ) {
window.location.reload( ForceRefresh ? 1 : 0 );
return true;
}
function GlobWindowClose ( myTarget, myEvent ) {
return StickyTooltip_CloseWrapper( myTarget, myEvent );
}
function GlobAttachEvent ( myObject, myEvent, myFunc )
{
if ( myObject.addEventListener ) {
myObject.addEventListener( myEvent, myFunc, false ); 
} else if ( myObject.attachEvent ) {
myObject.attachEvent( 'on' + myEvent, myFunc );
} else {
try {
var funcRef = eval( 'myObject.on' + myEvent );
var callRef = myFunc;
var newRef;
if ( typeof( funcRef ) != 'undefined' && funcRef != null ) {
newRef = function ( event ) { eval( funcRef )( event ); eval( callRef )( event ); };
} else {
newRef = callRef;
}
eval( 'myObject.on' + myEvent + ' = newRef;' );
} catch (e) {}
}
return true;
}
function GlobSerializeForm ( of, ia )
{
var userAgent = navigator.userAgent.toLowerCase();
var msie = ( /msie/.test(userAgent) && !/opera/.test(userAgent) ) ? 1 : 0;
var s = [];
var elms = of.elements;
for (var j=0, max1=elms.length; j < max1; j++) {
var el = elms[j], val = el.value;
var n = el.name, t = el.type, tag = el.tagName.toLowerCase();
if ( 
(!n || el.disabled || t == 'reset' || t == 'button' ||
(t == 'checkbox' || t == 'radio') && !el.checked ||
(t == 'submit' || t == 'image') && el.form && el.form.clk != el ||
tag == 'select' && el.selectedIndex == -1)
) continue;
if (tag == 'select') {
var index = el.selectedIndex;
if (index < 0) continue;
var ops = el.options;
var one = (t == 'select-one');
var max = (one ? index+1 : ops.length);
for(var i=(one ? index : 0); i < max; i++) {
var op = ops[i];
if (op.selected) {
var v = msie && !(op.attributes['value'].specified) ? op.text : op.value;
if (one) {
s.push( encodeURIComponent(el.name) + "=" + encodeURIComponent(v) );
break;
}
s.push( encodeURIComponent(el.name) + "=" + encodeURIComponent(v) );
}
}
continue;
}
s.push( encodeURIComponent(el.name) + "=" + encodeURIComponent(val) );
}
var surl = s.join("&").replace(/\+/g, "%20");
if ( ia ) {
var aurl = of.action || window.location;
aurl = aurl.replace( /\&$/, '' );
aurl = aurl.replace( /\?$/, '' );
aurl += (aurl.indexOf('?') >= 0 ? '&' : '?');
surl = aurl + surl;
}
return surl;
}
function GlobDisableSubmitButton ( formName, EnableFlag ) {
if ( formName ) {
var objForm = document.forms[ formName ];
if ( objForm ) {
var len = objForm.elements.length;
for ( var i = 0; i < len; i++ ) {
var objElem = objForm.elements[ i ];
if ( objElem.type == 'submit' ) {
GlobDisableVisualField( objElem, EnableFlag ? 1 : 0 );
}
}
}
}
return true;
}
function GlobDisableVisualField ( elemObj, enableFlag, bNotDisabled, disableClass )
{
if ( ! disableClass ) disableClass = 'formDisable';
if ( ! elemObj.__oldCssName )  elemObj.__oldCssName  = elemObj.className;
if ( enableFlag == 0 ) {
GlobChangeClassName( elemObj, disableClass );
if ( ! bNotDisabled ) elemObj.disabled  = 'disabled';
} else {
elemObj.className = elemObj.__oldCssName;
if ( ! bNotDisabled ) elemObj.disabled  = '';
}
return 1;
}
function GlobChangeClassName ( oNode, sName, bRemove )
{
var strRegex = '/(^|\\s+)' + sName + '($|\\s+)/g';
var className = oNode.className;
className = className.replace( eval( strRegex ), ' ' );
if ( ! bRemove ) className += ' ' + sName;
className = className.replace( /\s+/, ' ' ).replace( /(^\s|\s$)/, '' );
oNode.className = className;
return true;
}
function GlobGetCookie( NameOfCookie )
{ 
if (document.cookie.length > 0)
{ 
var begin = document.cookie.indexOf(NameOfCookie+"=");
var end;
if (begin != -1) { 
begin += NameOfCookie.length+1;
end    = document.cookie.indexOf(";", begin);
if (end == -1) end = document.cookie.length;
return decodeURIComponent(document.cookie.substring(begin, end)); 
}
}
return null;
}
function GlobSetCookie( NameOfCookie, Value, Expiredays )
{
var ExpireDate = new Date ();
ExpireDate.setTime(ExpireDate.getTime() + (Expiredays * 24 * 3600 * 1000));
document.cookie = NameOfCookie + "=" + encodeURIComponent(Value) + ((Expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
}
function GlobDelCookie ( NameOfCookie )
{ 
if (GlobGetCookie(NameOfCookie)) {
document.cookie = NameOfCookie + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
}
}
function GlobSetCookieEx ( Name, Value, ExpiresMin, Path, Domain, Secure )
{
var ExpireDate = new Date ();
ExpireDate.setTime( ExpireDate.getTime() + ( ExpiresMin * 3600 * 1000 ) );
document.cookie = 
Name + '=' + encodeURIComponent( Value ) + 
( ( ExpiresMin ) ? '; expires=' + ExpireDate.toGMTString() : '' ) +
( ( Path ) ? '; path=' + Path : '' ) +
( ( Domain ) ? '; domain=' + Domain : '' ) +
( ( Secure ) ? '; secure' : '' )
;
}
function GlobMergeCookieValue ( CookieName, CookiePath, MergeValues, CurrentContext )
{
var strContextSeparator = '|';
var strValuesSeparator  = '#';
var numCurrentContext = 0;
var Contexts = [];
var OldCookieValue = GlobGetCookie( CookieName ) || '';
if ( OldCookieValue != '' )
{
Contexts = OldCookieValue.split( strContextSeparator );
numCurrentContext = Contexts.length;
for ( var i = 0; i < Contexts.length; i++ ) {
var ContextValues = Contexts[ i ].split( strValuesSeparator );
var TmpContext = ContextValues[ 0 ];
if ( TmpContext == CurrentContext ) {
numCurrentContext = i;
break;
}
}
}
if ( MergeValues.length > 0 ) {
Contexts[ numCurrentContext ] = CurrentContext + strValuesSeparator + MergeValues.join( strValuesSeparator );
} else {
Contexts[ numCurrentContext ] = '';
}
var TmpContexts = [];
for ( var i = 0; i < Contexts.length; i++ ) {
if ( Contexts[ i ] != '' ) TmpContexts[ TmpContexts.length ] = Contexts[ i ];
}
var CookieValue = TmpContexts.join( strContextSeparator );
GlobSetCookieEx( CookieName, CookieValue, null, CookiePath );
return true;
}
function GlobRegisterMenu ( MenuConfig ) {
GlobMenuBuffer[ GlobMenuBuffer.length ] = MenuConfig;
}
function GlobProcessMenuEntries () {
for ( var i = 0; i < GlobMenuBuffer.length; i++ ) {
MenuCreateMenu( GlobMenuBuffer[ i ] );
}
}
