/////////////////////////////////////////////////

//

//  buildIQ_shared.js

//

//  This file is included in the following pages:

//      assessment1.html

//      assessment2.html

//      assessment3.html

//      conclusion.html

//      introduction.html

//      university-overview.html

//      catalog-overview.html

//      gloss-<term>.html

//      module<n>-lesson<n>.html

//      module<n>.html

//      roster.html (old one)

//      syllabus

//      university (old one)

//      hidden





// if (NN & verFour)    window.onresize = location.reload;

// Global variables for environment info.

var NN = false, IE = false, Mac = false, PC = false, ver4 = false;



if (navigator.appName == 'Netscape') NN = true;

if (navigator.appName == 'Microsoft Internet Explorer') IE = true;

if (navigator.platform == 'MacPPC') Mac = true;

if (navigator.platform.search(/win/i)) PC = true;

if (parseInt(navigator.appVersion) == 4) ver4 = true;



var imgArr = new Array('next','back','left','right','nextg','backg');

var cacheArr = new Array();

var tempCacheArr = new Array();

var curCookie = new Cookie(document, "buildIQ_cookie", '/', 1);

cacheImgs();



//var syllabus_win = false;



// called form "onLoad" on every content page

function init() 

{

    //curCookie.load();

    //curCookie.currentpage = server.session.currentpage;

    //curCookie.store();

    //parent.hidden.updateSyllabus();

}



// called from this file and from clickthru objects



function cacheImgs(moreImgArr) 

{

    // Cache the arrey of images passed in

    // Used for click throughs

    if (arguments[0]) {

        for (var j=0; j<moreImgArr.length; j++){

            tempCacheArr[j] = new Image();

            tempCacheArr[j].src =    moreImgArr[j];

        }

    } else {

        // Otherwise cache the usual rollover buttons

        var k = imgArr.length;

        // cache the rollover images

        // 3 states: off, over, on

        for (var j=0; j<imgArr.length; j++) {

            cacheArr[k+3*j] = new Image();

            cacheArr[k+3*j+1] = new Image();

            cacheArr[k+3*j+2] = new Image();

            cacheArr[k+3*j].src = '../img/' + imgArr[j] + '_on.gif';

            cacheArr[k+3*j+1].src = '../img/' + imgArr[j] + '_off.gif';

        }

    }

}



// called from everywhere.



function imgSwap() 

{

    /*

     * imgSwap() : An image source swap function

     * Usage: imageSwap('imgName1','imgSrc1','imgName2','imgSrc2',...,'imgNameN','imgSrcN');

     * Author: Ed Shin (AgnewMoyerSmith) Sept 2000

     *

     * Takes multiple arguments, alternate the image namd and the associated image source:

     */

    var imgObj;

    for (var j=0; j < (arguments.length/2); j++) {

        imgObj = document.images[arguments[2*j]];

        imgObj.src = arguments[2*j + 1];

    }

}



// called from gloss-entry resize handler, syllabus resize handler

function fixWindow() 

{

    if (NN) {

        null;

//      window.location.reload(true);

    }

}




// opens demonstration/buy the course window
function openanotherwindow(param)
{
window.open(param,"my_new_window","toolbar=no,location=yes,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width=450,height=450")
}

//  called from everypage that has a link to the syllabus

function launchSyllabus(nolinks)

{

    parent.hidden.realLaunchSyllabus( nolinks);

}



// called from click-thru object



function totalClickSteps(id, total) 

{

//  alert(id + ', ' + total);

    var numImg = new Object();

    numImg[0] = '<img height="11" width="11" src="../img/0.gif">';

    numImg[1] = '<img height="11" width="11" src="../img/1.gif">';

    numImg[2] = '<img height="11" width="11" src="../img/2.gif">';

    numImg[3] = '<img height="11" width="11" src="../img/3.gif">';

    numImg[4] = '<img height="11" width="11" src="../img/4.gif">';

    numImg[5] = '<img height="11" width="11" src="../img/5.gif">';

    numImg[6] = '<img height="11" width="11" src="../img/6.gif">';

    numImg[7] = '<img height="11" width="11" src="../img/7.gif">';

    numImg[8] = '<img height="11" width="11" src="../img/8.gif">';

    numImg[9] = '<img height="11" width="11" src="../img/9.gif">';



    if (total < 10) {

        document.writeln(numImg[total]);

    }

    

    if (total >= 10) {

        var tempval = total-(Math.floor(total/10)*10);

        document.writeln( numImg[Math.floor(total/10)] + numImg[tempval] + '<img height="11" width="5" src="../img/x.gif">');

    }

}



// called from anyplace that opens a gloss term window

function launchGlossary(term) 

{

    var glossaryWin = window.open(term,"glossary","width=400,height=350,scrollbars=yes,left=50,top=50,screenx=50,screeny=50,resizable=no,toolbar=no,status=yes,location=no");

    glossaryWin.focus();

}



// called from click-thru objects to open a transcript



function launchTranscript() 

{

    var transcriptWin = window.open("./transcript.html","transcript","width=645,height=500,scrollbars=yes,left=50,top=50,screenx=50,screeny=50,resizable=yes,toolbar=no,status=yes,location=no,menubar=yes");

    transcriptWin.focus();

}



// called from anywhere the terms window needs to be opened from



function launchTerms() 

{
    //jmj 20080515 - pointed to university site terms and conditions
    //var termsWin = window.open("./terms.html","terms","width=645,height=500,scrollbars=yes,left=50,top=50,screenx=50,screeny=50,resizable=yes,toolbar=no,status=yes,location=no,menubar=yes");
    var termsWin = window.open("http://university.buildiq.com/terms-and-conditions.aspx","disclaimer","");

    termsWin.focus();

}



// called from anywhere the privacy window needs to be opened from



function launchPrivacy() 

{
    //jmj 20080515 - pointed to university site privacy policy
    //var privacyWin = window.open("./privacy.html","privacy","width=645,height=500,scrollbars=yes,left=50,top=50,screenx=50,screeny=50,resizable=yes,toolbar=no,status=yes,location=no,menubar=yes");
    var privacyWin = window.open("http://university.buildiq.com/privacy-policy.aspx","disclaimer","");
    
    privacyWin.focus();

}



function launchRem(index) 

{

    var privacyWin = window.open("./remediation.html?" + index,"rem","width=645,height=500,scrollbars=yes,left=50,top=50,screenx=50,screeny=50,resizable=yes,toolbar=no,status=yes,location=no,menubar=yes");

    privacyWin.focus();

}





// called from anyplace the zoom image window is opened from



function zoomImage(da_img)

{

    var zoomWin = window.open("../img/"+da_img,"zoom","width=610,height=470,scrollbars=yes,left=50,top=50,screenx=50,screeny=50,resizable=yes,toolbar=no,status=yes,location=no,menubar=yes");

    zoomWin.focus();

}



// call from clickthrus



function nextstep(direction,num)

{

    if (direction == 'right'){

        if (eval('clickindex'+num) >= eval('clickImage'+num+'.length-1')) {

            null;

        } else {

            eval('clickindex'+num+'++');

            imgSwap('clickImage'+num,eval('clickImage'+num+"[eval('clickindex'+num)]"));

            if ((eval('clickindex'+num)+1) < 10) {

                imgSwap('curones'+num,'../img/'+(eval('clickindex'+num)+1)+'.gif');

            }

            

            if ((eval('clickindex'+num)+1) >= 10) {

                imgSwap('curtens'+num,'../img/1.gif','curones'+num,'../img/' + ((eval('clickindex'+num)+1)-10) + '.gif');

            }

            document.forms['clickthru'+num].descript.value = eval("clickContent"+num+"[eval('clickindex'+num)]");

        }

    } else {

        if ((eval('clickindex'+num)+1) <= 1) {

            null;

        } else {

            eval('clickindex'+num+'--');

            imgSwap('clickImage'+num,eval('clickImage'+num+"[eval('clickindex'+num)]"));

            if ((eval('clickindex'+num)+1) < 10) {

                imgSwap('curtens'+num,'../img/x.gif','curones'+num,'../img/'+(eval('clickindex'+num)+1)+'.gif');

            }

            

            if ((eval('clickindex'+num)+1) >= 10) {

                imgSwap('curtens'+num,'../img/1.gif','curones'+num,'../img/' + ((eval('clickindex'+num)+1)-10) + '.gif');

            }

            

            document.forms['clickthru'+num].descript.value = eval("clickContent"+num+"[eval('clickindex'+num)]");

        }

    }

    

    if(IE){

        document.forms['clickthru'+num].descript.scrollTop = 0;

    }

}



// Used in the real & practice assessment:

// Throws an alert popup if the user tries to submit the test

// with missing answers



// called from the assessment page to check the completeness of the answers



function checkAnswers(num)

{

    var misArr = new Array();

    var test = document.assessment;

    // loop through all the questions

    for (var j=1; j<=num; j++){

        // loop through all the radio buttons in a question

        var missing = true;

        //alert("test['Q'+ "+j+"] : " + test['Q'+j]);

        for (var k=0; k<test['Q'+j].length; k++){

            // check if one has been selected.

            if (test['Q'+j][k].checked) {

                missing = false;

            }

        }

        if (missing) {

            misArr[misArr.length] = j;

        }

    }

    // Show alert if they missed some questions

    if (misArr.length > 0){

        var answerStr = 'answer';

        var questionStr = 'question';

        if (misArr.length > 1) {

            answerStr = 'answers';

            questionStr = 'questions';

        }

        alert(

            'You must answer all questions before your score can be calculated. ' +

            'Please fill in the missing ' + answerStr + ' to '+ questionStr + ' ' + misArr.toString() +

            ' and click the Submit button to receive your score.'

        );

        return false;

    } else {

        return true;

    }

}





function CheckTryItAnswers(theForm)

{

    var gotOne = false;

    for(index = 0 ; index < theForm.elements.length ; index++){

        if(theForm.elements[index].name == 'answer'){

            if(theForm.elements[index].checked){

                gotOne = true;

            }

        }

    }

    

    if(!gotOne){

        alert("Please select one of the answers and try again.");

    }

    

    return gotOne;    

}





/*

 * THESE SET OF FUNCTIONS ARE USEFUL BECAUSE THEY ALLOW YOU TO CREATE

 * AN INDIVIDUAL COOKIE OBJECT WHICH CAN READ AND WRITE TO A SINGLE COOKIE.

 * YOU CAN DISTINGUISH BETWEEN OTHER COOKIES WITHOUT HAVING TO LOOK INTO

 * THE COOKIE 'name=value'.

 */

 

//  I don't understand these functions and don't know where they are called from

//  It almost seems like these are overriding something related to the "Cookie" objects

//  that are used by other places in the code



function Cookie (document, name, path, hours) 

{

    this.$document = document;

    this.$name = name;

    if (path) {

        this.$path = path;

    } else {

        this.$path = null;

    }

    

    if (hours) {

        this.$expiration = new Date((new Date()).getTime() + hours*3600000);

    } else {

        this.$expiration = null;

    }

}



/*

 * THIS PLACES VALUES FROM THE COOKIE OBJECT INTO THE ACTUAL COOKIE

 */

function _Cookie_store () 

{

    var cookieval = "";

    for (var prop in this) {

        if ((prop.charAt (0) == '$') || ((typeof this[prop]) == 'function')) {

            continue;

        }

        

        if (cookieval != "") {

            cookieval += '&&&';

        }

        

        cookieval += prop + ':::' + escape(this[prop]);

    }



    var cookie = this.$name + '=' + cookieval;

    if (this.$path) {

        cookie += '; path=' + this.$path;

    }

    

    if (this.$expiration) {

        cookie += '; expires=' + this.$expiration.toGMTString();

    }



    this.$document.cookie = cookie;

}



/*

 * THIS FUNCTION WILL CHECK TO SEE THAT COOKIE EXISTS AND YOU ARE ABLE

 * TO ASSIGN THE VALUES OF THE COOKIE INTO THE CORRESPONDING COOKIE OBJECT

 */

function _Cookie_load () 

{

    var allcookies = this.$document.cookie;

    if (allcookies == "") {

        return false;

    }



    var start = allcookies.indexOf(this.$name + '=');

    if (start == -1) {

        return false;

    }        



    start += this.$name.length + 1;

    var end = allcookies.indexOf(';', start);



    if (end == -1) {

        end = allcookies.length;

    }

    

    var cookieval = allcookies.substring (start, end);



    var a = cookieval.split('&&&');



    for(var i=0; i < a.length; i++) {

        a[i] = a[i].split(':::');

    }



    for(var i=0; i < a.length; i++) {

        this[a[i][0]] = unescape(a[i][1]);

    }

    

    return true;

}



/*

 * THIS WILL EXPIRE THE COOKIE

 */

function _Cookie_remove() {

    var cookie;

    cookie = this.$name + '=';

    if (this.$path) {

        cookie += '; path=' + this.$path;

    }

    

    cookie += '; expires=Fri, 02-Jan-1970 00:00:00 GMT';



    this.$document.cookie = cookie;

}



new Cookie();

Cookie.prototype.store = _Cookie_store;

Cookie.prototype.load = _Cookie_load;

Cookie.prototype.remove = _Cookie_remove;


