
function placeFocus() {
	if (document.forms.length > 0) {
		var field = document.forms[0];
		for (i = 0; i < field.length; i++) {
			if ((field.elements[i].type == "text") || (field.elements[i].type == "textarea") || (field.elements[i].type.toString().charAt(0) == "submit")) {
				document.forms[0].elements[i].focus();
				break;
			}
		}
	}
}
function new_window(mypage, myname, scroll, width, height) {
	LeftPosition = (screen.width) ? (screen.width - width) / 2 : 0;
	TopPosition = (screen.height) ? (screen.height - height) / 2 : 0;
	settings = "height=" + height + ",width=" + width + ",top=" + TopPosition + ",left=" + LeftPosition + ",scrollbars=" + scroll;
	win = window.open(mypage, myname, settings);
}
function new_window_map(mypage) {
	var win_name = Math.round(Math.random() * 1000);
	var w = screen.width;
	var h = screen.height;
	var left_pos = 0;
	var top_pos = 0;
	settings = "height=" + h + ",width=" + w + ",top=" + top_pos + ",left=" + left_pos + ",resizable=yes,toolbar=no,location=no,directories=no,scrollbars=yes,status=yes";
	win = window.open(mypage, win_name, settings);
}
var win = null;
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
	if (init == true) {
		with (navigator) {
			if ((appName == "Netscape") && (parseInt(appVersion) == 4)) {
				document.MM_pgW = innerWidth;
				document.MM_pgH = innerHeight;
				onresize = MM_reloadPage;
			}
		}
	} else {
		if (innerWidth != document.MM_pgW || innerHeight != document.MM_pgH) {
			location.reload();
		}
	}
}
MM_reloadPage(true);
function auto_tab(original, destination) {
	if (original.getAttribute && original.value.length == original.getAttribute("maxlength")) {
		destination.focus();
	}
}
function list_accounts() {
	var item = document.forms["account_list"].account_selection;
	target = item.options[item.selectedIndex].value;
	document.cookie = "accountsPerPage=" + target;
	window.location.reload(false);
}
function init_userlist() {
	document.cookie = "accountsPerPage=-1";
}
function popUp(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=320,height=500,left = 480,top = 190');");
}
function popWindow(wName, winWidth, winHeight, winLeft, winTop, winURL) {
	winFeatures = getLocation(winWidth, winHeight, winLeft, winTop);
	features = "width=" + winWidth + ",height=" + winHeight + winFeatures + ",fullscreen=no, toolbar=no,location=no,directories=no,menubar=no,scrollbars=no,copyhistory=no,status=no,resizable=no";
	pop = window.open(winURL, wName, features);
	if (pop.focus) {
		pop.focus();
	}
	return true;
}
function getLocation(winWidth, winHeight, winLeft, winTop) {
	var winLocation = "";
	if (winLeft < 0) {
		winLeft = screen.width - winWidth + winLeft;
	}
	if (winTop < 0) {
		winTop = screen.height - winHeight + winTop;
	}
	if (winTop == "cen") {
		winTop = (screen.height - winHeight) / 2 - 20;
	}
	if (winLeft == "cen") {
		winLeft = (screen.width - winWidth) / 2;
	}
	if (winLeft > 0 & winTop > 0) {
		winLocation = ",screenX=" + winLeft + ",left=" + winLeft + ",screenY=" + winTop + ",top=" + winTop;
	} else {
		winLocation = "";
	}
	return winLocation;
}
function control_date_filter(enable, form_name, inc_time) {
	document.forms[form_name].start_year.disabled = !enable;
	document.forms[form_name].start_month.disabled = !enable;
	document.forms[form_name].start_day.disabled = !enable;
	document.forms[form_name].end_year.disabled = !enable;
	document.forms[form_name].end_month.disabled = !enable;
	document.forms[form_name].end_day.disabled = !enable;
	if (inc_time) {
		document.forms[form_name].start_hour.disabled = !enable;
		document.forms[form_name].start_minute.disabled = !enable;
		document.forms[form_name].end_hour.disabled = !enable;
		document.forms[form_name].end_minute.disabled = !enable;
	}
}
function showHide(div,toggle,dropDown) 
{
	var dropDown;
	if(toggle == null)
	{
		toggle = 'default';
	}
	if(toggle == 0)
	{
		toggle = 'default';
	}
	if(toggle == '')
	{
		toggle = 'default';
	}
	
	if(document.getElementById) 
	{
		document.poppedLayer = eval("document.getElementById(div)");
	}
	else
	{
		if(document.all) 
		{
			document.poppedLayer = eval("document.all[div]");
		}
		else
		{
			document.poppedLayer = eval("document.layers[div]");
		}
	}
	
	if(toggle == 'default')
	{
		if(document.poppedLayer.style.display == "none")
		{
			document.poppedLayer.style.display = "block";
		}
		else
		{
			if(document.poppedLayer.style.display == "") 
			{
				document.poppedLayer.style.display = "block";
			} 
			else 
			{
				document.poppedLayer.style.display = "none";
			}
		}
	}
	else
	{
		if(toggle == 'false')
		{
			document.poppedLayer.style.display = "none";
		}
		else
		{
			document.poppedLayer.style.display = "block";
		}
	}
}
var cX = 0;
var cY = 0;
var rX = 0;
var rY = 0;
function UpdateCursorPosition(e) {
	cX = e.pageX;
	cY = e.pageY;
}
function UpdateCursorPositionDocAll(e) {
	cX = event.clientX;
	cY = event.clientY;
}
if (document.all) {
	document.onmousemove = UpdateCursorPositionDocAll;
} else {
	document.onmousemove = UpdateCursorPosition;
}
function AssignPosition(d) {
	if (self.pageYOffset) {
		rX = self.pageXOffset;
		rY = self.pageYOffset;
	} else {
		if (document.documentElement && document.documentElement.scrollTop) {
			rX = document.documentElement.scrollLeft;
			rY = document.documentElement.scrollTop;
		} else {
			if (document.body) {
				rX = document.body.scrollLeft;
				rY = document.body.scrollTop;
			}
		}
	}
	if (document.all) {
		cX += rX;
		cY += rY;
	}
	d.style.left = (cX) + "px";
	d.style.top = (cY -10 ) + "px";
}
function HideContent(d) {
	if (d.length < 1) {
		return;
	}
	document.getElementById(d).style.display = "none";
}
function ShowContent(d) {
	if (d.length < 1) {
		return;
	}
	var dd = document.getElementById(d);
	AssignPosition(dd);
	dd.style.display = "block";
}
function ReverseContentDisplay(d) {
	if (d.length < 1) {
		return;
	}
	var dd = document.getElementById(d);
	AssignPosition(dd);
	if (dd.style.display == "none") {
		dd.style.display = "block";
	} else {
		dd.style.display = "none";
	}
}
function checkAll(){
	for (var i=0;i<document.forms[0].elements.length;i++)
	{
		var e=document.forms[0].elements[i];
		if ((e.name != 'allbox') && (e.type=='checkbox') && ( e.name != 'form[video_archives][date_filter]' ) )
		{
			e.checked=document.forms[0].allbox.checked;
		}
	}
}
function displayLoading(){
	//document.getElementById("loadingCameraSettings").className = "loadingCameraSettings-visible";
	//grayOut(true);
	document.getElementById("loadingCameraSettingsImage").className = "loadingCameraSettingsImage-visible";
}
function grayOut( vis, options ){
	// Pass true to gray out screen, false to ungray
	// options are optional.  This is a JSON object with the following (optional) properties
	// opacity:0-100         // Lower number = less grayout higher = more of a blackout 
	// zindex: #             // HTML elements with a higher zindex appear on top of the gray out
  	// bgcolor: (#xxxxxx)    // Standard RGB Hex color code
  	// grayOut(true, {'zindex':'50', 'bgcolor':'#0000FF', 'opacity':'70'});
  	// Because options is JSON opacity/zindex/bgcolor are all optional and can appear
  	// in any order.  Pass only the properties you need to set.
  	
  	var options = options || {};
  	var zindex = options.zindex || 5;
  	var opacity = options.opacity || 50;
  	var opaque = (opacity / 100);
  	var bgcolor = options.bgcolor || '#000000';
  	var dark=document.getElementById('darkenScreenObject');
  	
  	if( !dark ){
	    // The dark layer doesn't exist, it's never been created.  So we'll
	    // create it here and apply some basic styles.
	    // If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917
	    var tbody = document.getElementsByTagName("body")[0];
	    var tnode = document.createElement('div');           // Create the layer.
	        tnode.style.position='absolute';                 // Position absolutely
	        tnode.style.top='0px';                           // In the top
	        tnode.style.left='0px';                          // Left corner of the page
	        tnode.style.overflow='hidden';                   // Try to avoid making scroll bars            
	        tnode.style.display='none';                      // Start out Hidden
	        tnode.id='darkenScreenObject';                   // Name it so we can find it later
	    tbody.appendChild(tnode);                            // Add it to the web page
	    dark=document.getElementById('darkenScreenObject');  // Get the object.
  	}
  	
  	if( vis ){
    	
    	// Calculate the page width and height 
    	if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {
        	var pageWidth = document.body.scrollWidth+'px';
        	var pageHeight = document.body.scrollHeight+'px';
    	}else if( document.body.offsetWidth ) {
      		var pageWidth = document.body.offsetWidth+'px';
      		var pageHeight = document.body.offsetHeight+'px';
    	}else{
       		var pageWidth='100%';
       		var pageHeight='100%';
    	}
	    
	    var browserVersion = isMSIE();

	    if( browserVersion == 0 )
	    {
	    	var pageHeight = document.documentElement.scrollHeight+'px';
	    	var pageWidth = document.documentElement.scrollWidth+'px';
	    }
	    else
	    {
	    	var pageHeight = document.documentElement.offsetHeight+'px';
	    	var pageWidth = document.documentElement.offsetWidth+'px';   	
	    }
	    
	    //set the shader to cover the entire page and make it visible.
	    dark.style.opacity=opaque;                      
	    dark.style.MozOpacity=opaque;                  
	    dark.style.filter='alpha(opacity='+opacity+')';
	    dark.style.zIndex=zindex;        
	    dark.style.backgroundColor=bgcolor;  
	    dark.style.width= pageWidth;
	    dark.style.height= pageHeight;
	    dark.style.display='block';                          
  	}
  	else{
     	dark.style.display='none';
  	}
}
function isMSIE()
{
	var ua = window.navigator.userAgent
   	var msie = ua.indexOf ( "MSIE " )

   	if ( msie > 0 ){      // If Internet Explorer, return version number
         return parseInt (ua.substring (msie+5, ua.indexOf (".", msie )));
  	}
  	else{                 // If another browser, return 0
   		return 0;
   	}
}