/*
 * Created Date : 11/22/2007
 *
 * Author : Saitkuu
 */

/*
 * global variables
 */
var linkBlock;    // to store the element object whose id is 'links' and which includes the links to go by onclick of images
var applicationImages;   // this is an array to store the image tag object which are included in 'applicationForm'
var httpRequest;    // to store the XMLHttpRequest object
var links;    // this is an array to store links
var linksImagesBind = new Array();    // this is an array which bind links and images

var repeat=0 //enter 0 to not repeat scrolling after 1 run, othersise, enter 1
var title= document.title;
var start=1;

/*
 * This enumeration performs to change the content of page by clicking one of application form
 * images.
 */
var ApplicationForm = {


    /*
     * This function will be called and it performs the required initialization and binding the document's
     * element and window's event.
     */
    init: function() {   
         titleMove();
        /*
         * this must be div object whose id is 'links' and it is a block which contains the <a href=> tags
         * to go by clicking the images.
         */
        linkBlock = document.getElementById('links');
        /*
         * get the 'a' element objs which will be go by clicking images
         */
        links = linkBlock.getElementsByTagName( 'a' );
        /*
         * get the img element obj which are included under the element whose
         * id is 'applicationForm'
         */         
        applicationImages = document.getElementsByName( 'images' ); 

        for ( i = 0;  i < applicationImages.length; i++ ) {
            linksImagesBind[ applicationImages[ i ].id ] = links [ i ];
            addEvent( applicationImages[ i ], 'click', ApplicationForm.pageImport, false);
        }   // end while

    },    // end init function


    pageImport: function(event) {

        // initialize httpRequest object 
        httpRequest = getRequestHttpRequest();
        if( window.event ) {       
                httpRequest.open( 'get', linksImagesBind[ event.srcElement.id ].href, false);
                title = linksImagesBind[ event.srcElement.id ].href.substring( linksImagesBind[ event.srcElement.id ].href.lastIndexOf('/')+1);
                titleMove();
        } else {
                httpRequest.open( 'get', linksImagesBind[ this.id ].href, false);
                title = linksImagesBind[ this.id ].href.substring( linksImagesBind[ this.id ].href.lastIndexOf('/')+1);
                titleMove();
        }    // end if
        httpRequest.send( null );
        document.getElementById( 'enterData' ).innerHTML =  httpRequest.responseText;
        
    }    // end pageImport function
    
}    // end ApplicationForm enum


/*
 * return XMLHttpRequest object
 */
function getRequestHttpRequest() {

    //return  new XMLHttpRequest();
    if (window.XMLHttpRequest) {
        return new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        try {
            return new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                return new ActiveXObject("Microsoft.XMLHTTP");
            } catch (E) {
                return null;
            }
        }
    } else {
        return null;
    }

}  // end getRequestObj function


/*
 * performs moving title text
 */
function titleMove() {

    var leng = title.length;
    titl=title.substring( start, leng ) + title.substring( 0, start );
    document.title = titl;
    start++;
    if ( start == leng+1 ) {
        start = 0;
        if ( repeat == 0 )
            return;
    }  // end outer if
    setTimeout( "titleMove()", 200 );

}    // end titleMove function


function addEvent(elm, evType, fn, useCapture){

    /* cross-browser event handling for IE5+, NS6+, and Mozilla/Gecko */
    if( elm.addEventListener ) {
        elm.addEventListener(evType, fn, useCapture);
        return true;
    }else if(elm.attachEvent){
        var r = elm.attachEvent('on' + evType, fn);
        return r;
    }else{
        elm['on' + evType] = fn;
    }    // end if

}    // end addEvent function
addEvent( window , 'load', ApplicationForm.init, false);