// Copyright (c) 1997-2006 Accretive Technology Group, Inc. All rights reserved.
// $Id: siteControl.js,v 1.8 2004/08/11 23:35:29 ross Exp $

function SiteControl ( initUrl, nullUrl, localeArray, wantPopups, wantBackwins, backwinExit )
{
	this.localeIdx = -1;
	this.initUrl    = initUrl;
	this.nullUrl    = nullUrl;
	this.localeArray    = localeArray;
	this.exitOk     = 0;
	this.wantPopups = wantPopups;
	this.wantBackwins   = wantBackwins;
	this.backwinExit    = backwinExit;
	this.popOnBackExit  = 1;
	this.haveInitHtml   = 0;
	this.Initialize = SiteControlInitialize;
	this.Finalize   = SiteControlFinalize;
	this.CurrentLocale  = SiteControlCurrentLocale;
	this.ChangeLocale   = SiteControlChangeLocale;
	this.PopupWindows   = SiteControlPopupWindows;
	this.SetSco     = SiteControlSetSco;
	this.PopOnBackExit  = SiteControlPopOnBackExit;
	this.WantInitHtml   = SiteControlWantInitHtml;
	this.ExitOK     = SiteControlExitOK;
}

function SiteLocale ( breakFrame, urlArray )
{
	this.breakFrame    = breakFrame;
	this.displayUrl = urlArray[0];
	this.popupArray = new Array ();
	for ( var i = 1; i < urlArray.length; i++ )
	   this.popupArray[this.popupArray.length] = urlArray[i];
}

function SiteControlChangeLocale ()
{
	if ( this.localeIdx + 1 < this.localeArray.length ) {
	   if ( this.localeIdx >= 0 && ! this.wantBackwins ) {
	       if ( ! this.popOnBackExit ) this.ExitOK() ;
	       //alert(1);
	       return history.go ( -1 );
	   }
       //alert("localeIdx = " + this.localeIdx);
	   this.localeIdx++;

	   if ( this.CurrentLocale().breakFrame && this.backwinExit ) {
	       if ( ! this.popOnBackExit ) this.ExitOK() ;
	       //alert(2);
	       return history.go ( -1 ) ;
	   }

	} else if ( this.backwinExit ) {

	   if ( ! this.popOnBackExit ) this.ExitOK() ;
       //alert(3);
       return history.go ( -1 ) ;
    }

	var locale = this.CurrentLocale();
	var win = locale.breakFrame ? top : window.thetopframe;
	//alert("displayUrl = " + locale.displayUrl);
	win.location.href = locale.displayUrl;
}

function SiteControlPopupWindows ()
{
	if ( this.exitOk || (! this.wantPopups) ) return;
	if ( this.localeIdx+1 == this.localeArray.length && this.backwinExit && this.popOnBackExit )
	   this.localeIdx = ( this.localeIdx > 0 ? this.localeIdx-1 : 0 ) ;

	var locale = this.CurrentLocale();

	for ( var i = 0; i < locale.popupArray.length; i++ ) {
		//alert("SiteControlPopupWindows = " + locale.popupArray[i]);
		var win = window.open ( locale.popupArray[i] );
		if ( i + 1 == locale.popupArray.length ) win.focus();
	}
}

function SiteControlCurrentLocale ()
{
    var i = ( this.localeIdx > 0 ) ? this.localeIdx : 0;
    if ( i >= this.localeArray.length ) i = this.localeArray.length - 1;
    return this.localeArray[i];
}

function SiteControlSetSco ( p, b, e )
{
    if ( this.haveInitHtml ) {
        this.wantBackwins  = b ;
        this.backwinExit   = e ;
	}
    this.wantPopups = p ;
}

function SiteControlPopOnBackExit ( x )
{
    this.popOnBackExit = x ;
}

function SiteControlWantInitHtml ( x )
{
    this.haveInitHtml  = x ;
}

function SiteControlExitOK ()
{
    this.exitOk = 1;
    return true;
}

function SiteControlInitialize ()
{
    if ( parseFloat(navigator.appVersion) >= 3 ) {

        if ( this.wantBackwins || ( this.wantPopups && !this.popOnBackExit ) ) this.haveInitHtml = 1;

        var src = this.haveInitHtml ? this.initUrl : this.localeArray[0].displayUrl ;

        //alert("SiteControlInitialize = " +src);

		document.write ('<FRAMESET ROWS="100%,*" SCROLLING="NO" BORDER="0" FRAMEBORDER="NO" FRAMESPACING="0">');
		document.write ('<FRAME NAME="thetopframe" SRC="'+src+'">');
		document.write ('<FRAME NAME="thenullframe" SRC="'+this.nullUrl+'">');
		document.write ('</FRAMESET>');
		document.write ('<'+'!--');
    }
}

function SiteControlFinalize ()
{

if ( parseFloat(navigator.appVersion) >= 3 )
    document.write ( '--'+'>' ) ;
}