// Binar Elektronik AB
// Thomas Eriksson
// 2009-04-03

var browser;
var browserversion;
var availableWidth;
var availableHeight;
var mainTop;
var hFooter = 35;
var curr_field;	//EDITERINGSLÄGE: Textfält som specialtecken skall infogas i. 
var measOn = false;

var i, aN;					//iteraction variables
var imgPreloaded = new Image();	//image preloaded
var imgToPreload = new Array();	//array holding images to preload
var aHeight;				//Holds 'main'-height
var columnsTopIs;				//Holds 'columnsDiv'-top
var columnsHeightIs;			//Holds 'columnsDiv'-height

var curr_sel_0;			//Currently selected menuID in database driven column 0 menu
var curr_sel_1;			//Currently selected menuID in database driven column 1 menu
var curr_sel_2;			//Currently selected menuID in database driven column 2 menu
var selBgColor1 = '#F8D87F';	//Bg color of selected items in database driven column menus
var hovBgColor = '#FFAAAA';	//Bg color of hovered items in database driven column menus

var AltkeyPressed = false;


doGetVersion();
curr_field = 'freetext';

// Bestäm browser-typ
// -----------------------------------------------------------------------
function doGetVersion()
	{
	if(navigator.appName.indexOf('Netscape')>-1)
		{browser = 'Netscape';}
		else if ((navigator.appName.indexOf('Microsoft')>-1) || (navigator.appName.indexOf('MSIE')>-1))
		{browser = 'MSIE';}
		else if(navigator.appName.indexOf('Opera')>-1)
		{browser = 'Opera';}
		else
		{browser = navigator.appName;}

	browserversion = parseInt(navigator.appVersion);
	}


//  Justera diverse height-värden
// -----------------------------------------------------------------------
function doAdjustHeight()
	{
	document.getElementById('mainTable').style.height = document.documentElement.clientHeight + 'px';
	document.getElementById('main').style.height = document.documentElement.clientHeight - document.getElementById('main').offsetTop - hFooter + 'px';
	document.getElementById('footerDiv').style.top = document.documentElement.clientHeight - hFooter + 'px';
	}

// Pausera ms millisekunder
// -----------------------------------------------------------------------
function doPause(ms)
	{
	d = new Date(); 		//today's date
	while (1)
		{
		mill=new Date();	// Date Now
		diff = mill-d;	//difference in milliseconds
		if( diff > ms ) {break;}
		}
	}

//  Bekräfta val (add, update, delete, etc...)
// -----------------------------------------------------------------------
function doConfirmAction(confirmType) 
	{ 
	var confirmText = "Säker";
	
	if (confirmType == 'Logout_swe') confirmText = 'Säkert att du vill logga ut?';
	if (confirmType == 'Logout_eng') confirmText = 'Sure you want to log out?';
	if (confirmType == 'Update') confirmText = 'Säkert att du vill UPPDATERA den här posten?';
	if (confirmType == 'Add') confirmText = 'Säkert att du vill LÄGGA TILL den här posten?';
	if (confirmType == 'Delete') confirmText = 'Säkert att du vill RADERA den här posten?';

	var confirmOK = confirm(confirmText); 
	if (confirmOK==true) {return true;} else {return false;}
	}

//  Infoga specialtecken i textfält (form = "edit", fält = curr_field)
// -----------------------------------------------------------------------
function doAddSpecialCharacter(character)
	{
	main.document.edit(curr_field).value = main.document.edit(curr_field).value + character; 
	main.document.edit(curr_field).focus();
	}


//  Generisk preload-funktion
// -----------------------------------------------------------------------
function doPreloadImage(inImg)
	{
	var preLoad = new Image();
	preLoad.src = inImg;
	//alert('preloaded!');
	}

//  
// -----------------------------------------------------------------------
function adjustSubmenuPositions(menuCnt)
	{
	var Left1
	var Width1
	var Width2
	for (i=0; i<menuCnt+1; i++)
		{
		Left1 = document.getElementById('menuMainCell_' + i).offsetLeft; 
		Width1 = document.getElementById('menuMainCell_' + i).offsetWidth; 
		Width2 = document.getElementById('divSubmenu_' + i).offsetWidth; 
		//document.getElementById('divSubmenu_' + i).style.left = 210 + (Left1 + Width1) - Width2;
		//document.getElementById('divSubmenu_' + i).style.left = document.getElementById('menuMainCell_' + i).offsetLeft + 200;
		document.getElementById('divSubmenu_' + i).style.left = document.getElementById('menuMainCell_' + i).offsetLeft + 0 - 1;

		//offset 200 above correspond with the asp variable menuMain_left in asp_common_mainmenu.inc
		}
	}

// 
// -----------------------------------------------------------------------
function doIndMouseOver(cellID)
	{
	if (cellID.substring(0,1) == 0) { if (cellID != curr_sel_0) { document.getElementById(cellID).style.background = hovBgColor; } }
	else if (cellID.substring(0,1) == 1) { if (cellID != curr_sel_1) { document.getElementById(cellID).style.background = hovBgColor; } }
	else if (cellID.substring(0,1) == 2) { if (cellID != curr_sel_2) { document.getElementById(cellID).style.background = hovBgColor; } }
	}

//  
// -----------------------------------------------------------------------
function doIndMouseOut(cellID)
	{
	if (cellID.substring(0,1) == 0) { if (cellID != curr_sel_0) { document.getElementById(cellID).style.background = '#FFFFFF'; } }
	else if (cellID.substring(0,1) == 1) { if (cellID != curr_sel_1) { document.getElementById(cellID).style.background = '#FFFFFF'; } }
	else if (cellID.substring(0,1) == 2) { if (cellID != curr_sel_2) { document.getElementById(cellID).style.background = '#FFFFFF'; } }
	}

//  
// -----------------------------------------------------------------------
function doIndSelected(cellID)
	{
	if (cellID.substring(0,1) == 0) {curr_sel_0 = cellID;}
	else if (cellID.substring(0,1) == 1) {curr_sel_1 = cellID;}
	else if (cellID.substring(0,1) == 2) {curr_sel_2 = cellID;}
	document.getElementById(cellID).style.background = selBgColor1;
	}

//  
// -----------------------------------------------------------------------
function doGetVScrollPos(inID) 
	{
	var posVScroll = 0;
	posVScroll = document.getElementById(inID).scrollTop;
	return posVScroll;
	}

//  
// -----------------------------------------------------------------------
function doAdjustApplicationsPage()
	{
	aHeight = document.getElementById('main').offsetHeight;

	if (document.getElementById('columnsDiv'))
		{
		columnsTopIs = document.getElementById('columnsDiv').offsetTop;
		columnsHeightIs = aHeight - columnsTopIs - 1;

		//if (browser == 'MSIE') columnsHeightIs = columnsHeightIs - 44;
		document.getElementById('columnsDiv').style.height = columnsHeightIs;
		if (document.getElementById('divColumn0')) document.getElementById('divColumn0').style.height = columnsHeightIs + 'px';
		if (document.getElementById('divColumn1')) document.getElementById('divColumn1').style.height = columnsHeightIs + 'px';
		if (document.getElementById('divColumn2')) document.getElementById('divColumn2').style.height = columnsHeightIs + 'px';
		if (document.getElementById('divColumn3')) document.getElementById('divColumn3').style.height = columnsHeightIs + 'px';
		if (document.getElementById('divImageTopMarg')) document.getElementById('divImageTopMarg').style.height = document.getElementById('divHotspots').offsetHeight + document.getElementById('divHotspots').offsetTop + 'px';
		if (document.getElementById('ProductAreas')) document.getElementById('ProductAreas').style.height = columnsHeightIs - 16 + 'px';
		}
	}
//  
// -----------------------------------------------------------------------
function doPrintPage(inArea)
	{

	var thisDate = new Date();

	var theMonth = '' + (thisDate.getMonth()+1);
	if (theMonth.charAt(1) == '') theMonth = '0' + theMonth;
	var theDay = '' + thisDate.getDate();
	if (theDay.charAt(1) == '') theDay = '0' + theDay;
	
	var today = thisDate.getFullYear() + '-' + theMonth + '-' + theDay;

	var firstHTML = '<html><head>' +
		'<title><%=metaTitle%></title>' + 
		'<meta http-equiv="Content-Language" content="<%=metaLang%>">' + 
		'<meta name="description" content="Binar Elektronik - Print-out">' + 
		'<link rel="stylesheet" href="/style/style_binar.css" type="text/css">';

	if (inArea != 'main') {firstHTML = firstHTML + '<link rel="stylesheet" href="/style/style_application.css" type="text/css">';}

	firstHTML = firstHTML + '</head><body style="background-image: none;">' + 
		'<p class="small">' + today +
		'&nbsp;&nbsp;&nbsp;' +
		'© Binar Elektronik AB<br>&nbsp;</p><div style="position: absolute; top: 15px; left: 0px;">';	

	var lastHTML = '</div></body></html>';

	var a = window.open();
	a.document.open("text/html");
	a.document.write(firstHTML + document.getElementById(inArea).innerHTML + lastHTML);
	a.document.close();
	a.print();

	}
 
//  
// -----------------------------------------------------------------------
function dbHotkeys(inEvent)
	{
	if (inEvent.keyCode == 18) AltkeyPressed = true;
	if (inEvent.keyCode == 65 && AltkeyPressed) {document.edit('add').click();} //alt+A
	if (inEvent.keyCode == 66 && AltkeyPressed) {document.edit('cancel').click();} //alt+B
	if (inEvent.keyCode == 85 && AltkeyPressed) {document.edit('update').click();} //alt+U
	if (inEvent.keyCode == 68 && AltkeyPressed) {document.edit('delete').click();} //alt+D

	}


