﻿
    DocInfoDiv     = document.createElement("div");
var DocInfo        = new Object();
var DocInfoControl = new Object();


DocInfo.GetData = function() {

	this.title           = document.title;
	this.contentType     = "";
	this.contentLanguage = "";
	this.language        = "";
	this.keywords        = "";
	this.description     = "";
	this.author          = "";
	this.editor          = "";
	this.sources         = "";
	this.translation     = "";
	this.proofreading    = "";
	this.approval        = "";
	this.status          = "";
	this.created         = "";
	this.modified        = "";

	var Attribute = new String( "" );
	var MetaTag  = new Object();
	var MetaTags = document.getElementsByTagName( "meta" );

	for ( k=0;k<MetaTags.length;k++) {

		MetaTag = MetaTags[k];
		Attribute = "";
		if ( MetaTag.httpEquiv ) Attribute = MetaTag.httpEquiv;
		if ( MetaTag.name      ) Attribute = MetaTag.name;

		switch( Attribute.toLowerCase() ) {
			case "content-type"     : this.contentType     = MetaTag.content; break;
			case "content-language" : this.contentLanguage = MetaTag.content; break;
			case "language"         : this.language        = MetaTag.content; break;
			case "keywords"         : this.keywords        = MetaTag.content; break;
			case "sources"          : this.sources         = MetaTag.content; break;
			case "author"           : this.author          = MetaTag.content; break;
			case "editor"           : this.editor          = MetaTag.content; break;
			case "translation"      : this.translation     = MetaTag.content; break;
			case "proofreading"     : this.proofreading    = MetaTag.content; break;
			case "approval"         : this.approval        = MetaTag.content; break;
			case "description"      : this.description     = MetaTag.content; break;
			case "status"           : this.status          = MetaTag.content; break;
			case "created"          : this.created         = MetaTag.content; break;
			case "modified"         : this.modified        = MetaTag.content; break;
		}
	}
}

DocInfoDiv.NewTableRowHTML = function( parameterName, parameterValue ) {

	var str = new String("");
	
	if ( parameterValue != "" ) {

		str += '		<tr>\n';
		str += '			<td valign="top"><i>' + parameterName  + '</i></td>\n';
		str += '			<td valign="top">' + parameterValue + '</td>\n';
		str += '		</tr>\n';

	}

	return( str );
}

DocInfoDiv.GetHTML = function() {

	if ( !DocInfo.hasData ) DocInfo.GetData();

	var str = new String("");

	str += '<h3>Document Info</h3>\n';
	str += '<table>\n';
	str += 		this.NewTableRowHTML( 'name'        , DocInfo.title        );
	str += 		this.NewTableRowHTML( 'Description'  , DocInfo.description  );
	str += 		this.NewTableRowHTML( 'Keywords'     , DocInfo.keywords     );
	str += 		this.NewTableRowHTML( 'Sources'      , DocInfo.sources      );
	str += 		this.NewTableRowHTML( 'Author'       , DocInfo.author       );
	str += 		this.NewTableRowHTML( 'Editor'       , DocInfo.editor       );
	str += 		this.NewTableRowHTML( 'Translation'  , DocInfo.translation  );
	str += 		this.NewTableRowHTML( 'Proofreading' , DocInfo.proofreading );
	str += 		this.NewTableRowHTML( 'Approval'     , DocInfo.approval     );
	str += 		this.NewTableRowHTML( 'Status'       , DocInfo.status       );
	str += 		this.NewTableRowHTML( 'Created'      , DocInfo.created      );
	str += 		this.NewTableRowHTML( 'Modified'     , DocInfo.modified     );
	str += '</table>\n';

	this.innerHTML = str;	
	this.hasHTML   = true;
	
}

DocInfoDiv.Init = function () {

	this.style.visibility ='hidden';
	this.id               ='DocInfoDivID';
	this.innerHTML        ='';
	this.hasHTML          = false;
	
	document.getElementsByTagName('body')[0].appendChild(this);
}

DocInfo.Show = function() {

	if ( !DocInfoDiv.hasHTML ) DocInfoDiv.GetHTML();
	
	DocInfoDiv.style.visibility ='visible';
	DocInfoDiv.style.display    ='block';
	this.displayed              = true;
	DocInfoControl.innerHTML    ='Dölj info';
	setCookie('docinfo', '1', '', '/')	
}

DocInfo.Hide = function() {

	DocInfoDiv.style.visibility ='hidden';
	DocInfoDiv.style.display    ='none';
	this.displayed              = false;	
	DocInfoControl.innerHTML    ='Visa info';
	setCookie('docinfo', '0', '', '/')
}

DocInfo.OnOff = function () {
	if ( DocInfo.displayed ) DocInfo.Hide();
	else                     DocInfo.Show();	
}

DocInfo.Init = function() {

	if ( document.getElementById('DocInfoControlID') ) {
		DocInfoDiv.Init();
		this.hasData      = false;
		DocInfoControl = document.getElementById('DocInfoControlID');
		if ( getCookie('docinfo') && getCookie('docinfo') == '1' ) this.Show();
		else this.Hide();
	}
}
