﻿var baseURL = '/';

function OpenPopUp(width, height, name, url)
{
	win_width = width;
	win_height = height;
	top_x = (screen.width - win_width) / 2;
	top_y = (screen.height - win_height) / 2 - 30;
	var win = window.open(url, name, 'scrollbars=yes,status=no,resizable=no,left='+top_x+',top='+top_y+',width='+win_width+',height='+win_height+'');	
	win.focus();
}

function SelectAllCheckboxes(mainbox, GroupName)
{
	var elems = mainbox.form.elements;
	var elemnum = elems.length;

	for (i = 0; i < elemnum; i++)
		if (elems[i].name.substr(0, GroupName.length) == GroupName)
			elems[i].checked = mainbox.checked;
}

function AdminEdit(id)
{
	if (id == 0)
		OpenPopUp(400, 350, 'admin', baseURL + 'admin/AdminEdit.aspx');
	else
		OpenPopUp(400, 350, 'admin' + id, baseURL + 'admin/AdminEdit.aspx?item=' + id);
}

function EditTextBlock(id)
{
	OpenPopUp(800, 600, 'Text' + id, baseURL + 'blacknight/TextEdit.aspx?block=' + id);
}

function PageAdd()
{
	OpenPopUp(550, 600, 'admin', baseURL + 'blacknight/PageEdit.aspx');
}

function EditPage(id)
{
	win_width = 550;
	win_height = 600;
	top_x = (screen.width - win_width) / 2;
	top_y = (screen.height - win_height) / 2 - 30;
	window.open(baseURL + 'blacknight/PageEdit.aspx?id=' + id, 'page' + id, 'scrollbars=yes,status=no,resizable=no,left=' + top_x + ',top=' + top_y + ',width=' + win_width + ',height=' + win_height + '');	
}

function PhraseAdd(lang)
{
	win_width = 500;
	win_height = 250;
	top_x = (screen.width - win_width) / 2;
	top_y = (screen.height - win_height) / 2 - 30;
	window.open(baseURL + 'blacknight/PhraseEdit.aspx?lang=' + lang, 'phrasenew', 'scrollbars=yes,status=no,resizable=no,left=' + top_x + ',top=' + top_y + ',width=' + win_width + ',height=' + win_height + '');	
}

function PhraseDiscover(name)
{
	win_width = 500;
	win_height = 250;
	top_x = (screen.width - win_width) / 2;
	top_y = (screen.height - win_height) / 2 - 30;
	window.open(baseURL + 'blacknight/PhraseEdit.aspx?lang=' + lang, 'phrasenew', 'scrollbars=yes,status=no,resizable=no,left=' + top_x + ',top=' + top_y + ',width=' + win_width + ',height=' + win_height + '');	
}

function EditPhrase(id)
{
	win_width = 500;
	win_height = 250;
	top_x = (screen.width - win_width) / 2;
	top_y = (screen.height - win_height) / 2 - 30;
	window.open(baseURL + 'blacknight/PhraseEdit.aspx?id=' + id, 'phrase' + id, 'scrollbars=yes,status=no,resizable=no,left=' + top_x + ',top=' + top_y + ',width=' + win_width + ',height=' + win_height + '');	
}

function ManagePageSet(group_id, lang_name)
{
	win_width = 800;
	win_height = 600;
	top_x = (screen.width - win_width) / 2;
	top_y = (screen.height - win_height) / 2 - 30;
	window.open(baseURL + 'blacknight/ManagePageSet.aspx?group=' + group_id + '&lang=' + lang_name, 'group' + group_id, 'scrollbars=yes,status=no,resizable=no,left=' + top_x + ',top=' + top_y + ',width=' + win_width + ',height=' + win_height + '');	
}

function OrdersManagement(ItemID) {
	OpenPopUp(600, 500, 'om' + ItemID, baseURL + 'admin/blacknight/OrderManagement.aspx?item=' + ItemID);
}

function SortingProperties(ItemID) {
	OpenPopUp(400, 200, 'sp' + ItemID, baseURL + 'admin/blacknight/SortingEdit.aspx?item=' + ItemID);
}

function ManageItemFiles(ItemID) {
	OpenPopUp(640, 480, 'if' + ItemID, baseURL + 'admin/blacknight/ItemFiles.aspx?item=' + ItemID);
}

//function ClassifierEdit(ClassifierName)
//{
//	win_width = 400;
//	win_height = 500;
//	top_x = (screen.width - win_width) / 2;
//	top_y = (screen.height - win_height) / 2 - 30;
//	window.open(baseURL + 'admin/ClassifierEdit.aspx?name=' + ClassifierName, 'name' + ClassifierName, 'scrollbars=yes,status=no,resizable=no,left='+top_x+',top='+top_y+',width='+win_width+',height='+win_height+'');	
//}

function HighlightRow(theRow, theRowNum, theAction, theDefaultColor, thePointerColor)
{
	var theCells = null;

	// 1. Pointer and mark feature are disabled or the browser can't get the
	//    row -> exits
	if (thePointerColor == '' || typeof(theRow.style) == 'undefined')
		return false;

	// 2. Gets the current row and exits if the browser can't get it
	if (typeof(document.getElementsByTagName) != 'undefined')
	{
		theCells = theRow.getElementsByTagName('td');
		//alert(theRow);
	}
	else if (typeof(theRow.cells) != 'undefined')
	{
		theCells = theRow.cells;
	}
	else
	{
		return false;
	}

	// 3. Gets the current color...
	var rowCellsCnt  = theCells.length;
	var domDetect    = null;
	var currentColor = null;
	var newColor     = null;
	// 3.1 ... with DOM compatible browsers except Opera that does not return
	//         valid values with "getAttribute"
	if (typeof(window.opera) == 'undefined'	&& typeof(theCells[0].getAttribute) != 'undefined')
	{
		currentColor = theCells[0].getAttribute('bgcolor');
		domDetect    = true;
	}
	// 3.2 ... with other browsers
	else
	{
		currentColor = theCells[0].style.backgroundColor;
		domDetect    = false;
	} // end 3

	// 4. Defines the new color
	// 4.1 Current color is the default one
//	if (currentColor == '' || currentColor.toLowerCase() == theDefaultColor.toLowerCase())
//	{
		if (theAction == 'over')
			newColor = thePointerColor;
//	}
//	// 4.1.2 Current color is the pointer one
//	else if (currentColor.toLowerCase() == thePointerColor.toLowerCase())
//	{
		if (theAction == 'out')
		{
			newColor = theDefaultColor;
		}
//	}
	// end 4
//alert(newColor);
	// 5. Sets the new color...
	if (newColor)
	{
		var c = null;
		// 5.1 ... with DOM compatible browsers except Opera
		if (domDetect)
		{//alert(rowCellsCnt);
			for (c = 0; c < rowCellsCnt; c++)
			{
				theCells[c].style.backgroundColor = newColor;
				//theCells[c].setAttribute('bgcolor', newColor, 0);
			} // end for
		}
		// 5.2 ... with other browsers
		else
		{
			for (c = 0; c < rowCellsCnt; c++)
			{
				theCells[c].style.backgroundColor = newColor;
			}
		}
	} // end 5

	return true;
} // end of the 'HighlightRow()' function
 
function HighlightCell(theCell, theRowNum, theAction, theDefaultColor, thePointerColor)
{
	var domDetect    = null;
	var currentColor = null;
	var newColor     = null;
	// 3.1 ... with DOM compatible browsers except Opera that does not return
	//         valid values with "getAttribute"
	if (typeof(window.opera) == 'undefined'	&& typeof(theCell.getAttribute) != 'undefined')
	{
		currentColor = theCell.getAttribute('bgcolor');
		domDetect    = true;
	}
	// 3.2 ... with other browsers
	else
	{
		currentColor = theCell.style.backgroundColor;
		domDetect    = false;
	} // end 3

	// 4. Defines the new color
	// 4.1 Current color is the default one
//	if (currentColor == '' || currentColor.toLowerCase() == theDefaultColor.toLowerCase())
//	{
		if (theAction == 'over')
			newColor = thePointerColor;
//	}
//	// 4.1.2 Current color is the pointer one
//	else if (currentColor.toLowerCase() == thePointerColor.toLowerCase())
//	{
		if (theAction == 'out')
		{
			newColor = theDefaultColor;
		}
//	}
	// end 4
//alert(newColor);
	// 5. Sets the new color...
	if (newColor)
	{
		var c = null;
		// 5.1 ... with DOM compatible browsers except Opera
		if (domDetect)
		{
			theCell.style.backgroundColor = newColor;
		}
		// 5.2 ... with other browsers
		else
		{
			theCell.style.backgroundColor = newColor;
		}
	} // end 5

	return true;
} // end of the 'HighlightCell()' function

//====================================================================================================================================================================
var utils = new Object();
utils.viewportWidth = function () {
	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	if (typeof window.innerWidth != 'undefined')
		return window.innerWidth;
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0)
		return document.documentElement.clientWidth;
	// older versions of IE
	else
		return document.getElementsByTagName('body')[0].clientWidth;
}

utils.viewportHeight = function () {
	if (typeof window.innerWidth != 'undefined')
		return window.innerHeight;
	else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0)
		return document.documentElement.clientHeight;
	else
		return document.getElementsByTagName('body')[0].clientHeight;
}	
