//
//                  Copyright Spidel Tech Solutions Inc 2005
//
//------------------- random number ------------------------------------
// The Central Randomizer 1.3 (C) 1997 by Paul Houle (houle@msc.cornell.edu)
// See:  http://www.msc.cornell.edu/~houle/javascript/randomizer.html

rnd.today= new Date();
rnd.seed = rnd.today.getTime();

function rnd() {
        rnd.seed = (rnd.seed*9301+49297) % 233280;
        return rnd.seed/(233280.0);
};


function rand(number) {
        return Math.ceil(rnd()*number);
};

// ------------------ end central randomizer. ---------------------------


function myCalc() {
    var s; 
    var o;
    var d;
    var tmp;

    d = document.f1; 

    // nou*(doos/3600)*lhcou*foopu
       tmp = d.NumberofUsers.value * d.DurationofOperationSeconds.value * 
               d.LoadedHourlyCostofUser.value * d.FrequencyofOperationPerUser.value;
       tmp = tmp / 3600;
      
    s = d.PerInterval;
    o = s.options[s.selectedIndex].text;

    if( o == "minute") { tmp = tmp * 3600 * 8 * 22 * 12; } 
    if( o == "hour")   { tmp = tmp * 8 * 22 * 12; }      
    if( o == "day")    { tmp = tmp * 22 * 12; }        
    if( o == "week")   { tmp = tmp * 52; }           
    if( o == "month")  { tmp = tmp * 12; }           
    if( o == "quarter"){ tmp = tmp * 4; }            

    d.answer.value = tmp.toFixed(2);
}


function screener() {
    var i;
    var res = "";
    var lst = "1bB2cC3eE4fF5gG6hH7jJ8mM9pPqQrRsStTuUvVwWxX";
    
    for( i = 0; i<6; i++ ) {
        res += "" + lst.charAt( rand(43) - 1 );    
    }
    
    document.f1.pat.value = res;
}


function validate( fields, prompts ) {
   // verify that all fields (required in form) are not empty
   var fieldList = []; 
   var promptList = [];
   var idx;

   fieldList = fields.split( " " );
   promptList = prompts.split( "," );

   for( idx=0; idx<fieldList.length; idx++ ) {
       if( fieldList[idx] == "SeePatternTypeit" ) {
           fld = document.f1.blk.value;

           if( fld != document.f1.pat.value ) {
               alert( "Please correct: 'Captcha'" );
               return false;
           }
       } else {
           fld = document.f1[ fieldList[idx] ].value;
       }

       if( fld == "" ) {
           alert( "Please complete: '" + promptList[idx] + "'" );
           return false;
       }
   }

   return true;
}


function zoom( p ) {
    // make picture user just clicked on bigger by scaling
    // a high def photo
    var myPath = location.href;
    
    myPath = myPath.substring( 0, myPath.lastIndexOf( '/' ) );
    var x = window.open( '', 'photo', 'width=800, height=600, resizable=yes' );    
    x.document.writeln( '<html> <head> <title>' + p + 
            '</title> </head> <body> <img src="' + myPath + '/Photos/' + p + 
            '" alt="' + p + '" width="100%" /> </body> </html>' );  
    x.document.close();     
    return true;
}


/* function speak( path, ttl ) {
    // make an audio link show up in popup window
    
    x = window.open( '', 'audio', 'width=400, height=300' );
    x.document.writeln( '<html><head><title>' + ttl + 
        '</title></head><body> <embed src="' + path + 
        '" height=22 width=350><br><span>' + ttl + 
        '</span><p></p></body> </html>' );
    x.document.close();
    return true;    
} */


function fillTemporal() {
    // fill in current date and time on form
    var now = new Date();
    var y = now.getYear();
    if ( y < 2000 ) { y  = y + 1900; }
    var d = document.getElementById('thisdate');
    var t = document.getElementById('thistime'); 
    var dt = ( 1 + now.getMonth() ) + "/" + now.getDate() + "/" + y; 
    var tm = now.getHours() + ":" + now.getMinutes() ;
    d.innerHTML = "Date: " + dt;
    t.innerHTML = "Time: " + tm;
    document.opinion.mydate.value = dt;
    document.opinion.mytime.value = tm;
}



function audify( aud, ttl ) {
    var hst = location.host;
    var x = window.open( '', 'audio', 'width=400,height=100' );
    x.document.writeln( 
            '<html><head><title>World Gospel Church</title>' +
            '<link rel="stylesheet" type="text/css" href="/Public/wgc_style.css" />' +
            '</head><body><embed name="mp3" src="' + 
            aud + '" height=22 width=350 /><br />' +
            '<span class=aud><a href="' + aud + '">' + ttl + '</a></span></body></html>' );
    x.document.close();
    return true;
}


function toggleMe( whm ) {
    // hide or expose a division by name
    var gid = document.getElementById( "g" + whm );
    var mid = document.getElementById( "m" + whm );

    if( gid.style.visibility == "hidden" | gid.style.display == "none" ) {
        gid.style.visibility = "visible";
        gid.style.display = "inline";
        mid.style.color = "#FFF";
    }
    else {
        gid.style.visibility = "hidden";
        gid.style.display = "none";
        mid.style.color = "#000";
    }
}


function showme( whm ) { 
    Realize( whm, true );  
}


 
function hideme( whm ) { 
    Realize( whm, false ); 
}


function Realize( whm, vis ) {
    // hide or expose a division by name
    var gid = document.getElementById( "g" + whm );
    var mid = document.getElementById( "m" + whm );

    if( vis == true ) {
        gid.style.visibility = "visible";
        gid.style.display = "inline";
        mid.style.color = "#FFF";
    }
    else {
        gid.style.visibility = "hidden";
        gid.style.display = "none";
        mid.style.color = "#000";
    }
}



function checkWork() {
    // count up missing answers divide by possible show grade
    var ers = 0;
    var cnt = 0;
    var pct = 0;
    var tot = 0;
    var yourGrade = 'A';
    var itms = 0;
    var possible = 0;
    var missed = 0;
    var missedText;
    var scoreText;
    var s;
    var o;
    var i;
    var j;
    var p;
    var qr;

    s = document.getElementsByTagName( 'select' );

    for( i = 0; i < s.length; i++ ) {
        p = s[i].parentNode.parentNode.style;

        if( p.display == 'inline' || 
                p.visibility == 'visible') {
            tot += 1;
            possible += s[i].options.length; // total points

            if( s[i].selectedIndex == 0 ) {  // did not answer
                missed += 1; 
                ers += s[i].options.length;
                s[i].style.background = "#FF0";
            }
            else { // answered
                o = s[i].options[s[i].selectedIndex];

                if( o.id == "1" ) { // correct answer
                    cnt += 1; 
                    s[i].style.background = "#7F7";
                }
                else { // wrong answer
	     	        s[i].style.background = "#F77";
                    ers += ( o.id - 0 ) ;
                    qr = document.getElementById( 'qr' + s[i].id );
                    qr.style.visibility = 'visible';
                    qr.style.display = 'inline';
                }
            }
        }
    }
 
    pct = ( 100 * ( possible - ers ) ) / possible;
    if      ( pct > 90 ) { yourGrade = 'A' }
    else if ( pct > 80 ) { yourGrade = 'B' }
    else if ( pct > 70 ) { yourGrade = 'C' }
    else if ( pct > 60 ) { yourGrade = 'D' }
    else                 { yourGrade = 'F' };

    missedText = '';

    if( missed > 0 ) {
        missedText = "You didn't answer " + missed + ' questions. '
    }
    
    if( tot > 0 ) {    
        alert( 'Your weighted grade is: ' + yourGrade + 
		    '. You correctly answered ' + cnt + ' out of ' + tot + 
		    ' questions. ' + missedText + 'You scored ' + (possible - ers) + 
   		    ' out of a possible ' + possible + " points." );
    }

    return false;
}


function ReviewThis( o, id ) {
    var d;
    var i;
    var vis;
    var dis;
    var pat;

    if( o == true ) {
        vis = 'visible';
        dis = 'inline';
    } else {
        vis = 'hidden';
        dis = 'none';
    }

//    alert(id);
    pat = 'qg' + id;

    d = document.getElementsByTagName( 'div' );

    for( i = 0; i < d.length; i++ ) {
        if( d[i].className == pat ) {
            d[i].style.visibility = vis;
            d[i].style.display = dis;
        }
    }  
}


for( i = 1; i<200; i++ ) {
    tglSub( false, i );
}

function tglsub( o, idx ) {
    var d;
    var i;
    var vis;
    var dis;

    if( o == true ) {
        vis = 'visible';
        dis = 'inline';
    } else {
        vis = 'hidden';
        dis = 'none';
    }

    i = document.getElementById( 'i' + idx );
    i.style.background = "#B6BFC8";
    d = document.getElementById( 'd' + idx );
    d.style.visibility = vis;
    d.style.display = dis;
}


function wiki( inName, selName ) {
    // copy selname into inName for wikisearch
    var s;
    var o;
    var i;

    s = document.getElementById( selName );
    o = s.options[s.selectedIndex];
    i = document.getElementById( inName );
    i.value = o.text;
}
