//----------------------Library containing all the functions used in this tutorial

// Added by JZA to ensure the first question is always loaded first.
var sPath = document.location.pathname;
sPath = sPath.toLowerCase();
if ( ( sPath.indexOf('tp') != -1 ) && ( sPath.indexOf('/1tp') == -1 ) ) { // Found "tp" but were not at first page

	var q=getCookie("increment"+tut); // Try getting a cookie for this tutorial
	if (q==null){ // OH DEAR - no cookie set!
		alert ('You must start Tutorial ' + tut + ' at Question 1, please wait while we load Question 1 for you.');
		document.location = '1tp' + tut + '.htm'; //redirect to the start page for that tutorial
	}

}


// nametut : array with all the names of the tutorials
var nametut = new Array("Forces and Moments","Bending Moments",
"Shear Forces","Bending Moment Diagrams","Basic Beam Design","Columns","Shear in Beams","Arches and Portal Frames","Portal Frames, Continuity, Joints","Pitched Roofs","Lateral Stability of Buildings",
"Lateral Instability of Beams","Torsion");

var pop;

function afficheImage(empl) {
	affichage = '';
	affichage += '<html><head><title>OXFORD BROOKES UNIVERSITY</title></head><body onLoad="window.focus();">';
	affichage += '<img src="./Pictures/' +empl+'">';
  affichage += '<br><a href="#" onclick="window.close()">close window</a>'
	affichage += '</body></html>';
	pop = window.open('','pop','width=700,height=550,status=no,directories=no,toolbar=no,location=no,menubar=no,scrollbars=yes,resizable=no');
	pop.document.close();
  pop.document.write(affichage);
	}


function launch(name){
window.location.href=name
}
function OLDlaunch(name){
// function wich create a new window fitting the screen
var width = screen.width;
var res =(((!(640-width))*1)+
((!(800-width))*2)+((!(1024-width))*3)+
((!(1152-width))*4)+((!(1280-width))*5)+((!(1600-width))*6));

var WindowName="Tutorial";
var settings=
"toolbar=no,location=no,directories=no,"+
"status=no,menubar=no,scrollbars=yes,"+
"resizable=yes,";

if(!(res)) res = 1;if (res=='1') {settings += "width=590,height=340"}
if (res=='2')  {settings += "width=790,height=540"}
if (res=='3') {settings += "width=1014,height=710"}
if (res!='1' && res!='2' && res!='3') {settings += "width=640,height=480"}

w1 = window.open(name,WindowName,settings);
w1.moveTo(0,0);
}



function getValue()
{

   var check = 0;
   for (var i = 0; i < document.quiz.question1.length; i++)
   {

      if (document.quiz.question1[i].checked)
      {
         gradeit(document.quiz.question1[i].value) ;
         check = 1;
      }
   }

   if (check != 1)
   {
   alert ("No value was selected.");
   }

}


function gradeit(ans){ //function which direct to the answer's pages and increase the cookie
var q=getCookie("increment"+tut)
if (q==null){setCookie("increment"+tut,1, 1);q=1}
if (ans!=correctchoices[q]){ //process an incorrect choice
    window.location="wrong.htm"
    }
else window.location="right.htm"
}

function getans(){//function which give the correct answer
var r=getCookie("increment"+tut)
if (r==null)setCookie("increment"+tut,1, 1)
document.write('<p>'+answer[r]+'</p>');
}



function qcorrect(){//function which give the number of answered question
var q=getCookie("increment"+tut)
if (q==null){setCookie("increment"+tut,1, 1);q=1}
document.write('<p style=margin:2%><font size=2>You answered '+parseInt(q)+' question(s) out of '+totalquestions);
}

function percentage(){//function which direct to the next tutorial
w=parseInt(tut)+1;
if(tut<13){
document.write('<p class="next"><b>Go to tutorial '+w+'</b><a href="../tp'+w+'/1tp'+w+'.htm"><img src="../img/button7b.gif" alt="tp'+w+'" border="0" style="left:50%;"></a></p>');
}

}



function next(){//function which direct to the next question
var s=getCookie("increment"+tut)
if (s==null){setCookie("increment"+tut,1, 1)}
else {
t=parseInt(s)+1
if (t <= totalquestions){
setCookie("increment"+tut,t, 1)
document.write('<p class="next"><P style="margin:2%"><a href="'+t+'tp'+tut+'.htm"><img src="../img/nextbutton.jpg" alt="next" border="0"></a></p>');
}

else{
document.write('<p class="next"><P style="margin:2%"><a href="end.htm"><img src="../img/nextbutton.jpg" alt="next" border="0"></a></p>');
}
}
}


function reset(){//function which delete the cookie
delCookie("increment"+tut)
}

// ********************design functioms****************************

//<SCRIPT LANGUAGE=JavaScript>
//<!--
//var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
//function myFlash_DoFSCommand(command, args)                {
//  var myFlashObj = InternetExplorer ? myFlash : document.myFlash;
//  alert (args);
//}
//if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 &&
//  navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
//  document.write('<SCRIPT LANGUAGE=VBScript\> \n');
//  document.write('on error resume next \n');
//  document.write('Sub myFlash_FSCommand(ByVal command, ByVal args)\n');
//  document.write(' call myFlash_DoFSCommand(command, args)\n');
//  document.write('end sub\n');
//  document.write('</SCRIPT\> \n');
//}
//-->

//</SCRIPT>






function top()//function which draw the top of each page
{

document.write('  <table border="0" class="head" cellspacing=0>');
document.write('    <tr>');
document.write('      <td width="50%"style="vertical-align: bottom">');
document.write('            <a href="../index.html" class="head">Index</a> |');
document.write('            <a href="../title.html" class="head">Home</a> |');
document.write('            <a href="../Pictures.html" class="head">Pictures</a> |');
document.write('            <a href="../HELP.HTM" class="head">Help</a> |');
document.write('            <a href="http://www.architecturalresources.info/" class="head">Architectural Resources Home</a>');
document.write('      </td>');
document.write('      <td width="50%">');
document.write('          <img src="../img/Combinelogo.jpg" border="0" class="head" style="vertical-align:super" align="right">');
document.write('      </td>');
document.write('    </tr>');
document.write('    <tr>');
document.write('      <TD style="VERTICAL-ALIGN: bottom" width="100%" bgColor=#404040>');
document.write('          <b class="head"><p style=margin:2%><font size=3 color="white">'+nametut[tut-1]+'</b></td>');
document.write('       <td width="100%" align="right" valign="middle" bgcolor="#404040">');
document.write('           <form name="SearchForm" target="_top" action="http://www.architecturalresources.info/search/ATRsearch.asp">');
document.write('           		<input type="text" name="q" value="Search" style="width:200px; font-family: arial">');
document.write('           		<input type="hidden" name="application" value="Tutorial">');
document.write('           		<input type="image" src="../Img/SearchGo.gif" alt="Search" align="top">');
document.write('           </form>');
document.write('      </td>');
document.write('    </tr>');
document.write('  </table>');
}

function bottom()//function which draw the bottom of each page
{
document.write('  <table border="0" width="100%" class="head">');
document.write('    <tr>');
document.write('      <td height="20" valign="top" align="right">');
//document.write('          <p>');
document.write('             <font size="2" color="#C0C0C0"><a>Content of teaching programs is copyright of Oxford Brookes University </a>');
//document.write('          </p>');
document.write('      </td>');
document.write('    </tr>');
document.write('  </table>');
}


// ********************cookies functions****************************
function getCookie(NameOfCookie){
	if (document.cookie.length > 0){
		begin = document.cookie.indexOf(NameOfCookie+"=");
		if (begin != -1){
			begin += NameOfCookie.length+1;
			end = document.cookie.indexOf(";", begin);
			if (end == -1) end = document.cookie.length;
			st=/\</g;
			gt=/\>/g;
		 	document.cookie=document.cookie.replace(st,'&lt;');
		 	document.cookie=document.cookie.replace(gt,'&gt;');
			return unescape(document.cookie.substring(begin, end));
		}
	}
	return null;
}


function setCookie(NameOfCookie, value, expiredays)
{
var ExpireDate = new Date ();
ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
document.cookie = NameOfCookie + "=" + escape(value) +
((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString()+";");
}

function delCookie (NameOfCookie){
if (getCookie(NameOfCookie)) {
document.cookie = NameOfCookie + "=" +
"; expires=Thu, 01-Jan-70 00:00:01 GMT";
}
}
