var defaultBackgroundColor;

// -----------------------------------------------------
// Determina daca se face highlight pe lista de menu-uri
var browserName = navigator.appName;
var isIE = (browserName.indexOf("Microsoft") >= 0);

var browserVerDesc = navigator.appVersion;
var iPosSpace = browserVerDesc.indexOf(" ");
var iPosDot = browserVerDesc.indexOf(".");
var iPos = (iPosSpace > iPosDot ? iPosDot : iPosSpace);
var browserVer = parseInt(browserVerDesc.substring(0, iPos));

if (!isBrowserTooOld()) {
	// menu de header
	document.writeln("<STYLE TYPE='text/css'>");
	document.writeln("#Menu { ");
	document.writeln("	border-top: solid;");
	document.writeln("	border-bottom: solid;");
	document.writeln("	border-color: green;");
	document.writeln("	border-width: 2;");
	document.writeln("} </STYLE>");
}

// -----------------------------------------------------

function isBrowserTooOld() {
	return (isIE && browserVer < 4);

}	// isBrowserTooOld

// -----------------------------------------------------
function mouseEnter(thisControl) {
	// pune fundal galben
	// sterg valoarea capacitatii estimate
	if (!isBrowserTooOld()) {
		defaultBackgroundColor = thisControl.style.backgroundColor;
		thisControl.style.backgroundColor = "yellow"; //"CCFF00";
	}

}  // mouseEnter

// -----------------------------------------------------
function mouseLeave(thisControl) {
	// pune fundal galben
	// sterg valoarea capacitatii estimate
	if (!isBrowserTooOld()) {
		thisControl.style.backgroundColor = defaultBackgroundColor;
	}

}  // mouseLeave

// -----------------------------------------------------
/**
 * Scrie un sir de caractere in fereastra curenta
 */ 
function print(sir) {
	document.write(sir);

}	// print

// -----------------------------------------------------
/**
 * Creaza headerul
 */
function createHeader(aKey) {
	var allHeaders = new Array("Login", 
							   "Catalog", 
							   "Index autori",
                               "Anunturi",
							   "Inregistrare",
							   "Contul meu",
							   "Contact");

	var allKeys    = new Array("LOGIN", 
						       "CARTI", 
							   "INDEX_AUTORI",
                               "ANUNTURI",
							   "REGISTER_MANAGER", 
							   "MYACCOUNT",
							   "CONTACT");
	
	var allLinks   = new Array("index.php", 
		                       "../cauta_carti_smpl.php", 
							   "../lista.php",
		                       "../anunturi.php", 
							   "new_manager.php",
							   "contul_meu.php",
							   "contactare.php");

	if (aKey != "") {
		var bGasit = false;
		for (var i = 0; i < allKeys.length; i++) {
			if (allKeys[i] == aKey) {
				bGasit = true;
				break;
			}
		}

		if (!bGasit) {
			alert("Nu se poate creia header pentru " + aKey);
			return;
		}
	}

	print("<center><table " +
		  (isBrowserTooOld() ? "" : " id=Menu ") + 
		  "  width='100%' CELLSPACING='0' cellpadding='0'><tr>" + 
          "<td bgColor='lightblue' align='center'>");
	 
	for (var i = 0; i < allKeys.length; i++) {
		print("&nbsp; "); 

		if (allKeys[i] == aKey) {
			print(allHeaders[i]);
		} else {
			print("<A HREF='" + allLinks[i] + "' onMouseOver='mouseEnter(this)' " +
				  " onMouseOut='mouseLeave(this)'>" + 
				  allHeaders[i] + "</a>");
		}

		print("&nbsp; ");

	}

	print("</tr></table></center>");

}	// createHeader

// -----------------------------------------------------
function createHeaderReadOnly(aKey) {
	var allHeaders = new Array("Cursuri universitare" , 
							   "Catalog", 
							   "Index autori",	
                               "Anunturi", 
							   "Contact",
                               "Statistica");

	var allKeys    = new Array("CURSURI_UNIV", 
							   "CARTI", 
							   "INDEX_AUTORI",
                               "ANUNTURI",
							   "CONTACT", 
                               "STATISTICA");
	
	var allLinks   = new Array("man_univ.php",
							   "cauta_carti_smpl.php", 
							   "lista.php",
							   "anunturi.php",
                               "contact.php",
                               "statistica.php");

	if (aKey != "") {
		var bGasit = false;
		for (var i = 0; i < allKeys.length; i++) {
			if (allKeys[i] == aKey) {
				bGasit = true;
				break;
			}
		}

		if (!bGasit) {
			alert("Nu se poate creia header pentru " + aKey);
			return;
		}
	}

	print("<center><table " +
		  (isBrowserTooOld() ? "" : " id=Menu ") + 
		  "  width='100%' CELLSPACING='0' cellpadding='0'><tr>" + 
          "<td bgColor='lightblue' align='center'>");
	 
	for (var i = 0; i < allKeys.length; i++) {
		print("&nbsp;"); 

		if (allKeys[i] == aKey) {
			print(allHeaders[i]);
		} else {
			print("<A HREF='" + allLinks[i] + "' onMouseOver='mouseEnter(this)' " +
				  " onMouseOut='mouseLeave(this)'>" + 
				  allHeaders[i] + "</a>");
		}

		print("&nbsp; ");

	}

	print("</tr></table></center>");

}	// createHeaderReadOnly

// -----------------------------------------------------
/** 
 * Creaza footerul
 */ 
function createFooter() {
	print("<font size='2'>");
	print("<center><hr>");
	print("Aceasta pagina a fost proiectata pentru ");
	print("rezolutia 800 x 600. <br>");
	print("Pentru comentarii contactati: " + 
		  "<a href='mailto:librarie\@infocarti.ro'>librarie@infocarti.ro</a><br>");
	print("</center>");
	print("</font>");

}	// createFooter

// -----------------------------------------------------
