// header.js - this file contains create_header which builds the header
//             navigaton bar at the top of each of our web pages.
//
//             It is implemented in JavaScript so that if we need to
//             change the content, we only need to do that once,
//             and here, rather than on each individual page.
//
//             UniSoft Corporation, 8 September 2010, with some help from
//             the web.
//
//             We use x.className = "value"; etc. rather than
//             x.setAttribute("class", "value"); to accommodate IE7.

// colours table, used by both create_home_header() and
// create_main_header()

var	colours = new Array("#003300", "#9900CC", "#660033",
			"#FF6633", "#6666CC", "#FF0000",
			"#FF00FF", "#990000", "#CC66FF",
			"#CC0066", "#663399", "#FF6666",
			"#660066", "#6600FF", "#FF0033",
			"#330033", "#000066", "#333366",
			"#999966", "#006699", "#330066",
			"#990066", "#993300", "#000099",
			"#996633", "#CC00CC", "#FFCC33",
			"#00CCFF", "#FF6600", "#009900",
			"#330099", "#000000");

var	months = new Array("January", "February", "March", "April",
			"May", "June", "July", "August", "September",
			"October", "November", "December");

// This is the prompt for all request-more-information forms

var	form_msg = "Please enter e-mail address for more info.";


//  set_hdr_background -	sets the background colour referenced by id
//				to a certain colour according to the day of
//				the week.

function set_hdr_background(id) {
	var	elem = document.getElementById(id);
	var     d = new Date();
        var     index = d.getDate();

	if(elem == "")
		elem = document.all.getElementById(id);

	elem.style.background = colours[index];
}


// Header navigation bar, text followed by the links,
// usually not changed that often.

var header_text = new Array("Home", "OCAP", "ETV-EBIF", "TSBroadcaster",
			    "TSDeveloper", "TSProcessor", "TSMonitor",
			    "XAV");

var header_links = new Array("/index.html",
                             "/ocap/main.html",
                             "/ocap/ETV.html",
                             "/ocap/TSBroadcaster-ETV.html",
                             "/ocap/TSDeveloper.html",
                             "/etv/TSProcessor.html",
                             "/etv/TSMonitor.html",
			     "/ocap/XAV.html"
);

// creat_main_header - generates most page headers and is intended to be
// called with the following arguments:
//
// id0		- the id which indicates where in the document the
//		  header should be inserted, using marked with a <span id>
// title	- the main page title text, in a large font
// ltext1..5	- text of the links in column two of the header
// lref1..5	- matching link URLs of the above
// filename	- name of the calling html file (so we know from which
//		  page the request-for-information was sent).
 
function create_main_header(id0, title,
	ltext1, lref1,
	ltext2, lref2,
	ltext3, lref3,
	ltext4, lref4,
	ltext5, lref5,
	 filename) {
        // get the reference within the body, usually an <a> tag with id.
        var place = document.getElementById(id0);
        // creates a <table> element and a <tbody> element
        var tbl     = document.createElement("table");
        var tblBody = document.createElement("tbody");
	// var	elem = document.getElementById("header_col2");
	var	linktext = new Array(ltext1, ltext2, ltext3, ltext4, ltext5);
	var	linkrefs = new Array(lref1, lref2, lref3, lref4, lref5);
	var     d = new Date();
        var     index = d.getDate();

        
	// sets the <table> attributes;
        tbl.className = "htable1";
        tbl.border  = "0";
	tbl.cellSpacing = "0";
	tbl.cellPadding = "0";
        
	// create just one row
        var row = document.createElement("tr");
	// row.className = "bluebox";
        
	// Create the first <td> element, blank space
	var cell0 = document.createElement("td");
	var cellText0 = document.createTextNode("");
	cell0.className = "hcol0";
	cell0.appendChild(cellText0);
       	row.appendChild(cell0);
	
	// Create the second <td> element, the title
	var cell1 = document.createElement("td");
	var cellText1 = document.createTextNode(title);
	cell1.className = "hcol1";
	cell1.appendChild(cellText1);

	// fingers crossed, here's the form stuff...
	var form1 = document.createElement("form");
	form1.action = "http://ws3.unisoft.com/cgi-bin/mailform.cgi";
	form1.method = "post";
	var tbl0 = document.createElement("table");
	var tbody0 = document.createElement("tbody");

	tbl0.width = "320px";
	
	var tbl0_row1 = document.createElement("tr");
	var tbl0_row2 = document.createElement("tr");
	var tbl0_row3 = document.createElement("tr");

	tbl0_row1.className = "whitetext2";

	var tbl0_row1_cell1 = document.createElement("td");

	var input1 = document.createElement("input");	
	input1.type = "hidden";
	input1.name = "first";
	input1.value = "Unused";
	var input2 = document.createElement("input");	
	input2.type = "hidden";
	input2.name = "first";
	input2.value = "Unused";
	var input3 = document.createElement("input");	
	input3.className = "maintext8";
	input3.type = "text";
	input3.name = "email";
	input3.value = "";
	var input4 = document.createElement("input");	
	input4.type = "hidden";
	input4.name = "message";
	input4.value = filename;
	var input5 = document.createElement("input");	
	input5.className = "formtext2";
	input5.type = "submit";
	input5.name = "message";
	input5.value = "Send";

       	tbl0_row1_cell1.appendChild(input1);
       	tbl0_row1_cell1.appendChild(input2);
       	tbl0_row1_cell1.appendChild(input3);
       	tbl0_row1_cell1.appendChild(input4);
       	tbl0_row1_cell1.appendChild(input5);
	tbl0_row1.appendChild(tbl0_row1_cell1);
	tbody0.appendChild(tbl0_row1);

	var tbl0_row2 = document.createElement("tr");
	var tbl0_row2_cell1 = document.createElement("td");
	var tbl0_row2_cellText1 = document.createTextNode(form_msg);
	tbl0_row2_cell1.className="whitetext2";
	tbl0_row2_cell1.appendChild(tbl0_row2_cellText1);
	tbl0_row2.appendChild(tbl0_row2_cell1);
	tbody0.appendChild(tbl0_row2);

	tbl0.appendChild(tbody0);
	form1.appendChild(tbl0);
	cell1.appendChild(form1);

	row.appendChild(cell1);
 
	// Create the third <td> element, the links table
	var cell2 = document.createElement("td");
 
	// links table in column2
	var tbl1     = document.createElement("table");
	var tbody1   = document.createElement("tbody");
	// IE often needs a <tbody> element

	for (var i = 0; i < 5; i++) {
		// Create each <tr> element.
		var tbl1_row = document.createElement("tr");
		var tbl1_cell = document.createElement("td");
		var cellText = document.createTextNode(linktext[i]);
		var link = document.createElement("a");
		link.className = "hwhitelinks";
		link.href = linkrefs[i];
		link.appendChild(cellText);
		tbl1_cell.appendChild(link);
		tbl1_row.appendChild(tbl1_cell);
		tbody1.appendChild(tbl1_row);
	}

	tbl1.appendChild(tbody1);
	cell2.className = "hcol2";
	cell2.style.background = colours[index];
	cell2.appendChild(tbl1);
	row.appendChild(cell2);

	// Create the fourth <td> element, UniSoft logo
	var cell3 = document.createElement("td");
	var cellimg3 = document.createElement("img");
	cellimg3.src = "/images/UniSoft-White-DB-140.jpg";
	cellimg3.border = 0;
	cellimg3.alt = "UniSoft Logo";
	cell3.className = "hcol3";
	var logolink = document.createElement("a");
	logolink.className = "hwhitelinks";
	logolink.href = "/index.html";
	logolink.appendChild(cellimg3);
	cell3.appendChild(logolink);
	
       	row.appendChild(cell3);
	
	// add the row to the end of the table body
	tblBody.appendChild(row);

	// put the <tbody> in the <table>
        tbl.appendChild(tblBody);
        
        // appends <table> into <body>
        place.appendChild(tbl);
	create_header(id0);
}

function create_header(id3) {
        // get the reference within the body, usually an <a> tag with id.
        var place = document.getElementById(id3);
        // creates a <table> element and a <tbody> element
        var tbl     = document.createElement("table");
        var tblBody = document.createElement("tbody");

        // sets the <table> attributes;
        tbl.className = "navbar4";
        tbl.border  = "0";
        
	// create just one row
        var row = document.createElement("tr");
	row.className = "bluebox";
        
	for (var i = 0; i < 8; i++) {
             // Create each <td> element.
             var cell = document.createElement("td");
             var cellText = document.createTextNode(header_text[i]);
             cell.className = "navbar1-cell";
             var link = document.createElement("a");
             link.className = "tablinks";
             link.href = header_links[i];
             link.appendChild(cellText);
             cell.appendChild(link);
             row.appendChild(cell);
             if(i < 7) {
                     cell = document.createElement("td");
		     //cellText = document.createTextNode("");
                     //cell.appendChild(cellText);
                     cell.className = "whitevertical";
                     row.appendChild(cell);
             }
        }
        
	// add the row to the end of the table body
	tblBody.appendChild(row);

	// put the <tbody> in the <table>
        tbl.appendChild(tblBody);
        
        // appends <table> into <body>
        place.appendChild(tbl);
}




