var strBrowser = getBrowser();
var strBrowserTitle = handleTitle();
/*
 * @description Determine browser type.
 * @returns string browser type.
 */
function getBrowser()
{
	var strBrowser = navigator.userAgent.toLowerCase();
	if (strBrowser.indexOf('opera') != -1)
	{
		return 'opera';
	}
	if (strBrowser.indexOf('staroffice') != -1)
	{
		return 'staroffice';
	}
	if (strBrowser.indexOf('webtv') != -1)
	{
		return 'webtv';
	}
	if (strBrowser.indexOf('beonex') != -1)
	{
		return 'beonex';
	}
	if (strBrowser.indexOf('chimera') != -1)
	{
		return 'chimera';
	}
	if (strBrowser.indexOf('netpositive') != -1)
	{
		return 'netpositive';
	}
	if (strBrowser.indexOf('phoenix') != -1)
	{
		return 'phoenix';
	}
	if (strBrowser.indexOf('firefox') != -1)
	{
		return 'firefox';
	}
	if (strBrowser.indexOf('safari') != -1)
	{
		return 'safari';
	}
	if (strBrowser.indexOf('skipstone') != -1)
	{
		return 'skipstone';
	}
	if (strBrowser.indexOf('msie') != -1)
	{
		return 'msie';
	}
	if (strBrowser.indexOf('netscape') != -1)
	{
		return 'netscape';
	}
	if (strBrowser.indexOf('mozilla/5.0') != -1)
	{
		return 'mozilla';
	}
	if (strBrowser.indexOf('\/') != -1)
	{
		if (strBrowser.substr(0, strBrowser.indexOf('\/')) != 'mozilla')
		{
			return navigator.userAgent.substr(0, strBrowser.indexOf('\/'));
		}
		else
		{
			return 'netscape';
		}
	}
	return false;
}
/*
 * @description Set class for an element based on its id.
 * @param strId id of the element to be manipulated.
 * @param strValue the new value of the attribute.
 * @returns bool true or false.
 */
function setIDClass(strId, strValue)
{
	return document.getElementById(strId).className = strValue;
}
/*
 * @description Set an attribute for an element based on its id.
 * @param strId id of the element to be manipulated.
 * @param strAttribute an attribute such as rel or href.
 * @param strValue the new value of the attribute.
 * @returns bool true or false.
 */
function setIDAttribute(strId, strAttribute, strValue)
{
	return document.getElementById(strId).setAttribute(strAttribute, strValue);
}
/*
 * @description Get an attribute from an element based on its id.
 * @param strId id of the element to be manipulated.
 * @param strAttribute an attribute such as rel or href.
 * @returns element attribute or false.
 */
function getIDAttribute(strId, strAttribute)
{
	return document.getElementById(strId).getAttribute(strAttribute);
}
/*
 * @description Determine wether to set or get the value of a css style for an element.
 * @param strId id of the element to be manipulated.
 * @param strAttribute a css attribute such as display or visibility.
 * @param strValue the value of the element to be set.
 * @returns null or the element value.
 */
function handleIDStyle(strId, strAttribute, strValue)
{
	var el = document.getElementById(strId);
	switch (strAttribute)
	{
		case 'display':
			if (strValue !== undefined)
			{
				el.style.display = strValue;
			}
			else 
			{
				return el.style.display;
			}
			break;
		case 'visibility':
			if (strValue !== undefined)
			{
				el.style.visibility = strValue;
			}
			else
			{
				return el.style.visibility;
			}
			break;
		case 'height':
			if (strValue !== undefined)
			{
				el.style.height = strValue + 'px';
			}
			else
			{
				return el.style.height;
			}
			break;
		case 'width':
			if (strValue !== undefined)
			{
				el.style.width = strValue + 'px';
			}
			else
			{
				return el.style.width;
			}
			break;
		case 'zIndex':
			if (strValue !== undefined)
			{
				el.style.zIndex = strValue;
			}
			else
			{
				return el.style.zIndex;
			}
			break;
		case 'opacity':
			var intValue = strValue;
			if (strValue !== undefined)
			{
				if (intValue >= 0 && intValue <= 1)
				{
					el.style.opacity = intValue;
					el.style.filter = 'alpha(opacity=' + (intValue * 100) + ')';
					//el.style.MozOpacity = intValue;
					//el.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(Opacity=' + intValue + ')';
				}
			}
			else
			{
				return el.style.opacity;
			}
			break;
		case 'value':
			if (strValue !== undefined)
			{
				el.value = strValue;
			}
			else
			{
				return el.value;
			}
			break;
		case 'readOnly':
			if (strValue !== undefined)
			{
				el.readOnly = strValue;
			}
			else
			{
				return el.readOnly;
			}
			break;
		case 'marginLeft':
			if (strValue !== undefined)
			{
				el.style.marginLeft = strValue + 'px';
			}
			else
			{
				return el.style.marginLeft;
			}
			break;
		case 'backgroundImage':
			if (strValue !== undefined)
			{
				el.style.backgroundImage = 'url(' + strValue + ')';
			}
			else
			{
				return el.style.backgroundImage;
			}
			break;
		default:
			alert('handleIDStyle: ' + strAttribute + ' not found.');
			break;
	}
	return false;
}
/*
 * @description Toggle an element attribute.
 * @param strId id of the element to be manipulated.
 * @param strAttribute a css attribute such as display or visibility.
 * @param strOptions two values to be toggled between, separated by a pipe '|'.
 * @returns null.
 */
function toggleIDAttribute(strId, strAttribute, strOptions)
{
	var strThisOption = 0;
	var el = handleIDStyle(strId, strAttribute);
	var arrOptions = strOptions.split('|');
	if (el == 'null' || el == arrOptions[1])
	{
		strThisOption = 0;
	}
	else if (el == arrOptions[0])
	{
		strThisOption = 1;
	}
	handleIDStyle(strId, strAttribute, arrOptions[strThisOption]);
}
function toggleIDCheckbox (strId)
{
	var objElement = document.getElementById(strId);
	if (objElement.checked)
	{
		objElement.checked = false;
	}
	else
	{
		objElement.checked = true;
	}
}
/*
 * @description Get the width of the browser window.
 * @returns int x pixels.
 */
function getWindowWidth()
{
	return document.body.clientWidth;
}
/*
 * @description Get the height of the browser window.
 * @returns int x pixels.
 */
function getWindowHeight()
{
	return document.body.clientHeight;
}
/*
 * @description Get the width of the monitor screen.
 * @returns int x pixels.
 */
function getScreenWidth()
{
	return screen.width;
}
/*
 * @description Get the height of the monitor screen.
 * @returns int x pixels.
 */
function getScreenHeight()
{
	return screen.height;
}
/*
 * @description Set the focus on a form element. If the element iteration isn't set, focus on first element.
 * @param strFormId id of the form to be manipulated.
 * @param intElementIteration
 * @returns bool true or false.
 */
function setFormFocus(strFormId, intElementIteration)
{
	if (intElementIteration == undefined)
	{
		var intElementIteration = 0;
	}
	return document.getElementById(strFormId).elements[intElementIteration].focus();
}
/*
 * @description Set the focus on an element.
 * @param strId id of the element to be manipulated.
 * @returns bool true or false.
 */
function setIDFocus(strId)
{
	try
	{
		return document.getElementById(strId).focus();
	} 
	catch (e)
	{
	}
}
/*
 * @description Redirect current window to the specified href.
 * @param strHref link to the url desired.
 * @returns null.
 */
function redirectWindow(strHref)
{
	window.location = strHref;
}
/*
 * @description update the title showing on the browser window.
 * @param strTitle the string title.
 * @returns null.
 */
function handleTitle(strTitle)
{
	if (strTitle !== undefined)
	{
		document.title = strTitle;
	}
	else
	{
		return document.title;
	}
}

function getDateTime()
{
	var objNow = new Date();
	var strYear = objNow.getFullYear();
	var strMonth = checkDateTime((objNow.getMonth() + 1));
	var strDay = checkDateTime(objNow.getDate());
	var strHour = objNow.getHours();
	var strMinute = checkDateTime(objNow.getMinutes());
	var strAP = 'AM';
	if (strHour > 11)
	{
		strAP = 'PM';
	}
	if (strHour > 12)
	{
		strHour = strHour - 12;
	}
	if (strHour == 0)
	{
		strHour = 12;
	}
	return strYear + '-' + strMonth + '-' + strDay + ' ' + strHour + ':' + strMinute + ' ' + strAP;
}

function checkDateTime(intValue)
{
	if (intValue < 10)
	{
		intValue = '0' + intValue;
	}
	return intValue;
}

var objSearchSelectedElement = '';
var strSearchSelectedValue = '';
function doSearchStart(objElement)
{
	objSearchSelectedElement = objElement;
	searchLoading(objSearchSelectedElement, 1);
}
function doSearchStop()
{
	searchLoading(objSearchSelectedElement, 0);
}
function searchLoading(objElement, blnOption)
{
	if (blnOption == 1 && objElement.className != 'search_input_loading' && objElement.value != '' && objElement.value != strSearchSelectedValue)
	{
		objElement.className = 'search_input_loading';
	}
	else if (blnOption == 0)
	{
		objElement.className = 'search_input';
	}
	strSearchSelectedValue = objElement.value;
}
