// JavaScript file //

/**
 * @desc Specialised functions for molas.dk
 */

/**
 * @function init()
 * @desc Setup the opening page
 */
function init() {
  var fp = createXMLHttpRequest();
  var mn = createXMLHttpRequest();
  showTxtReq(fp, "forside","main","intro.jpg");
  showPhpReq( "menu","leftmenu");

/*
  request = new XMLHttpRequest();
*/
}
/**
 * @function mainPrint
 * @desc Print output in a given <div>
 * @param arg Text to print
 * @param section <div>-section to print the arg
 */
function mainPrint( arg, section ) { 
  document.getElementById(section).innerHTML = arg;
}
/**
 * @function showTxtReq(): 
 * @desc	Shows a file in a <div>-section and an image in
 * 				the <div>-section for images
 * @param file 	Only the filename. Extension must be html and file must 
								reside in the ../html directory
 * @param printSection: <div>-section where text is shown.
 * @param: img <div>-section where image is shown.
 */
function showTxtReq( req, file, printSection, img ) {
  var req = createXMLHttpRequest();
  var res = requestData(req, "src/show.php","file=../html/" + file + ".html", printSection );
  if ( img ) {
    picture("images/" + img)
  }
}
/**
 * @function showPhpReq(): 
 * @desc		show the content of the main  menu
 * @param file 	Hardcoded to src/menu.php.
 * @param printSection	Hardcoded to leftmenu.
 * @param  img Not used.
 */
function showPhpReq( file, printSection, img ) {
  var menuReq = createXMLHttpRequest();
  menuReq.open("GET","src/menu.php", true);
  menuReq.send(null);
  menuReq.onreadystatechange = function() {
    if ( menuReq.readyState == 4 && menuReq.status == 200 ) {
			mainPrint(menuReq.responseText, "leftmenu");
      // document.getElementById("leftmenu").innerHTML = menuReq.responseText;
    }
  } 
}
/**
 * @function showTxt(): 
 * @desc	Shows a file in a <div>-section and an image in
 * 				the <div>-section for images
 * @param file 	Only the filename. Extension must be html and file must 
								reside in the ../html directory
 * @param printSection: <div>-section where text is shown.
 * @param: img <div>-section where image is shown.
 */
function showTxt( file, printSection, img ) {
  var res = requestData(req, "src/show.php","file=../html/" + file + ".html", printSection );
  if ( img ) {
    picture("images/" + img)
  }
}
/**
 * @function picture()
 * @desc	Shows a picture in the <div> named "right". 
 *				Fixed size width = 300, height = 400 pixels.
 * @param url Url to the picture to show
 */
function picture( url ) {
  document.getElementById('right').innerHTML = "<img src='" + url + "' width='300' height='400' >";
}
/**
 * @function showResult()
 * @desc	Sends the content of a form to the given program file
 *				and displays the result in a <div> named in the var target
 * @param oForm Pointer to The form object 
 * @param program The name of the file to execute
 * @param target <div> to display result
 */
function showResult( oForm, program, target ) {
    getString = getFormBody( oForm );
  	request = createXMLHttpRequest( );
    requestData(request, program, getString, target, 'GET')
}

