var _isIE_ 				= (navigator.userAgent.indexOf("MSIE") > 0);
var _isMozilla_ 		= (navigator.userAgent.indexOf("Gecko") > 0);
//var expiration = new Date("December, 31, 2049");
//expiration = expiration.setTime (expiration.getTime()+(24 * 60 * 60 * 1000 * 365));
var expiration = new Date();
var expiration = expiration.setTime (expiration.getTime()+(24));


function el(obj) {	return document.getElementById(obj); }
function $(element) { if (document.getElementById) element = document.getElementById(element); else if (document.all) element = document.all[element]; return element; }
function getCookie(ckname) { var cname = ckname + "="; var dc = document.cookie; if (dc.length > 0) { cbegin = dc.indexOf(cname); if (cbegin != -1) { cbegin += cname.length; cend = dc.indexOf(";", cbegin); if (cend == -1) cend = dc.length; return unescape(dc.substring(cbegin, cend));	} } return null; }
function setCookie(cname, value, expires, path, domain, secure) {  document.cookie = cname + "=" + escape(value) + ((expires == null) ? "" : "; expires=" + expires.toGMTString()) +  ((path == null) ? "" : "; path=" + path) + ((domain == null) ? "" : "; domain=" + domain) +  ((secure == null) ? "" : "; secure"); }
function deleteCookie (cname,path,domain) { if (getCookie(cname)) document.cookie = cname + "=" + ((path == null) ? "" : "; path=" + path) + ((domain == null) ? "" : "; domain=" + domain) + "; expires=Thu, 01-Jan-70 00:00:01 GMT"; }
function countCheckboxes(frm, checkbox_name) { var obj = document.forms[frm]; var count = 0; for(var i=0; i < obj.length; i++)  { if (obj[i].type != undefined && obj[i].type == "checkbox" && obj[i].name.substring(0,checkbox_name.toString().length) == checkbox_name && obj[i].checked) { count++; } } return count; }
function progressBar(msgBox, msg) { var obj = el(msgBox); if (obj) { obj.innerHTML = '<img src="images/progress.gif" alt="" border="0" /> '+msg; } }
function show_hide(item) { var obj = document.getElementById(item); if (obj)  { (obj.style.display == "none") ? obj.style.display = 'block' : obj.style.display = 'none'; } }
function reset_datebox(item) { var obj = document.getElementById(item+'month'); obj.selectedIndex = 0; var obj = document.getElementById(item+'day'); obj.selectedIndex = 0; var obj = document.getElementById(item+'year'); obj.selectedIndex = 0; }
function trim(s) { while (s.substring(0,1) == ' ') { s = s.substring(1,s.length); } while (s.substring(s.length-1,s.length) == ' ') { s = s.substring(0,s.length-1); } return s; }
function str_replace(oldS,newS,fullS) { for (var i=0; i<fullS.length; i++) { if (fullS.substring(i,i+oldS.length) == oldS) { fullS = fullS.substring(0,i)+newS+fullS.substring(i+oldS.length,fullS.length); } } return fullS; }
function getConnection() { try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {} try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} try { return new XMLHttpRequest(); } catch(e) {} }
function openWin(url) { var newwin = window.open(url, 'Samples', config='height=700,width=750,toolbar=yes,menubar=no,scrollbars=yes,resizable=yes,location=no,directories=no,status=no'); if (newwin) { newwin.focus(); } }
function hilite(obj, color) { if (document.getElementById) document.getElementById(obj).style.background = color; }
function removeItems(frm, checkbox_name) { if (countCheckboxes(frm, checkbox_name)) { if (el('action')) { el('action').value = 'delete'; } el(frm).submit(); } }
function getParsed(_symbol, _string) {
	var _tmp;
	if (_string.indexOf(_symbol) != -1) { // if split symbol is within the string
		 _tmp = _string.split(_symbol);
		return _tmp[_tmp.length-1];
	}
	return -1;
}

//checks or unchecks all checkboxes 'name' in a form
//accepts 1 optional parameter, which is the name of a func to execute for each chkbox
function checker(frm, name, check, exec) {
	var obj = document.forms[frm];
	if (obj) 
	{

		for(var i=0; i <  obj.elements.length; i++) 
		{

			if (obj.elements[i].type != undefined && obj.elements[i].type == "checkbox" && obj.elements[i].name.substring(0, name.length) == name)
			{
			
				obj.elements[i].checked = check;
				if (exec)
				{
					obj.elements[i].onclick();
				}
			}
		}

	}
}

function doDeletionMsg(txt, url) {
	var bg = '';
	if (arguments.length == 3)
	{	//hilite line
		//alert(argument[2]);
		bg = el(arguments[2]).style.background;
		//alert(bg);
		el(arguments[2]).style.background = '#ff6600';
	}
	
	if (confirm("Delete "+txt+".\nAre you sure?"))
	{

		document.location.href = url + '&confirm=Y';

	}
	else if (arguments.length == 3)
	{
		el(arguments[2]).style.background = bg;
	}

}

//hide/show the SELECT element on a page
//IE <=6 only bug. might be fixed in IE7
var last_toggle_element_state = 'visible';
function toggleSelect(hide_show) { 
	if (document.all) {
		state = (hide_show) ? 'hidden' : 'visible';
		if (last_toggle_element_state == state) return;

		var obj = document.getElementsByTagName('SELECT');
		if (!obj) return;
	
		for(i = 0; i < document.all.tags("SELECT").length; i++) {
			var _te_obj = document.all.tags("SELECT")[i];
			_te_obj.style.visibility = state;
		}
		last_toggle_element_state = state;

	}

}
