

function numericSort(x,y) {
    var a = new Number(x) ;
    var b = new Number(y) ;
    return (a - b) ;
}

function QuartileProblem(x) {
    this.data = new List() ;
    this.quartile2top = new Number() ;
    this.quartile3bottom = new Number() ;
    this.quartilelower = new Number() ;
    this.quartileupper = new Number () ;
    this.quartilemiddle= new Number () ;

    this.quartilelower = "" ;
    this.quartileupper = "" ;
    this.quartilemiddle= "" ;
    this.count = new Number() ;

    if ((x == undefined) || (x == null) ) {
        x = "" ;
    }
    (this.data).assign(x) ;
}

QuartileProblem.prototype.assign = function (x) {
    (this.data).assign(x) ;
}

QuartileProblem.prototype.lower = function () {
    return this.quartilelower ;
}

QuartileProblem.prototype.upper = function() {

    return this.quartileupper ;
}

QuartileProblem.prototype.median = function() {
   return this.quartilemiddle ;
}

QuartileProblem.prototype.smallest = function() {
    return (this.data).item(0) ;
}

QuartileProblem.prototype.largest = function() {
    var length = new Number() ;
    length =(this.data.listArray).length ;
    return (this.data).item((length-1)) ;
}

QuartileProblem.prototype.evaluate = function() {
    var length = new Number() ;
    var middex = new Number() ;
    var value  = new Number() ;
 
    var lower  = new Number() ;
    var upper  = new Number() ;
    var median = new Number() ;
    var llength = new Number() ;
    
    length = (this.data.listArray).length ;
    (this.data).sort(numericSort)
     
    if ((length % 2) > 0) {
        middex = Math.floor(length/2) ;
        this.quartilemiddle = (this.data).item(middex)  ;
        this.quartile3bottom = middex + 1 ;
        this.quartile2top = middex - 1 ;

    } else {
        middex = Math.floor(length/2) ;
        value = parseInt((this.data).item(middex-1)) + parseInt((this.data).item(middex)) ;
        this.quartilemiddle = value/2 ;
        this.quartile3bottom = middex ;
        this.quartile2top = middex - 1 ;
    }

    llength = middex ;

    if (llength%2 > 0) {
        lower = Math.floor(llength/2) ;
	this.quartilelower = (this.data).item(lower) ;
    } else {
        lower = (llength)/2 - 1;
	this.quartilelower = parseInt((this.data).item(lower+1)) + parseInt((this.data).item(lower));
	this.quartilelower = this.quartilelower/2 ;
    }

    ulength = llength ;
    if (ulength%2 > 0) {
        upper = this.quartile3bottom + Math.floor(ulength/2) ;
	this.quartileupper = (this.data).item(upper) ;
    } else {
        upper = ulength/2 + this.quartile3bottom - 1 ;
	this.quartileupper = parseInt((this.data).item(upper+1)) + parseInt((this.data).item(upper)) ;	
	this.quartileupper = this.quartileupper/2 ;
    }


//    document.write("q1="+this.lower + " : " + this.median + " : "+"q3=" + this.upper +"<BR>") ;
    return ;
}


