var popUp; 
var str = "left=0,screenX=0,top=0,screenY=0";
var str1 = "";
var str2 = "";

if (window.screen) {
  var ah = screen.availHeight - 30;
  var aw = screen.availWidth - 10;
  str += ",height=" + ah;
  str += ",innerHeight=" + ah;
  str += ",width=" + aw;
  str += ",innerWidth=" + aw;
  str += ", scrollbars = 1";
  str2 = str;
  str += ",toolbar =1";
  
} else {
  str += ",resizable=1"; // so the user can resize the window manually
}
  str1 = str +", toolbar =0,fullscreen=yes";

function OpenLoginWindow()
{
   return OpenFullScrnWithToolBar('login.aspx','login');window.opener = top;window.close();
}
function OpenFullScrnWithoutToolbar(url, name)
{
  return window.open(url, name, str2);
}
function launchFull(url, name) {
  return window.open(url, name, str1);
}
function OpenFullScrnWithToolBar(url, name) {
  return window.open(url, name, str);
}

function OpenWindowNomalFullScreen(url, name)
{

 if (navigator.appVersion.indexOf('4') != -1) {
 // Vars for centering the new window on Version 4 Browsers
	xTop = 0;//screen.width/2 - (width/2);
	yTop = 0;//screen.height/2 - (height/2);
	winhandle = OpenWindow(url, name, -1, -1, 'scrollbars=1,resizable=1,menubar=0,toolbar=0,status=1,location=0,directories=0');
	winhandle.moveTo(0,0);
	winhandle.resizeTo(screen.availWidth, screen.availHeight);
	winhandle.focus();
	//window.open(url, nameW, 'height='+screen.height+',width='+screen.width+',scrollbars=1,resizable=1,menubar=0,toolbar=0,status=0,location=0,directories=0,left=' + xTop + ',top=' + yTop + '');
	} 
 else {
 window.open(url, nameW, 'height='+height+',width='+width+',scrollbars=1,resizable=1,menubar=1,toolbar=1,status=1,location=0,directories=0,left=150,top=200');
 }

}
function OpenWindowLeftHalf(url,nameW)
{
	winhandle=window.open(url, nameW, 'height='+screen.height+',width='+screen.width/2+',scrollbars=1,resizable=1,menubar=0,toolbar=0,status=0,location=0,directories=0,left=0,top=0');
	winhandle.moveTo(0,0);
	winhandle.resizeTo(screen.availWidth/2, screen.availHeight);
	winhandle.focus(); 
}

function OpenWindowRightHalf(url, nameW)
{

	winhandle = window.open(url, nameW, 'height=0,width=0,scrollbars=1,resizable=1,menubar=0,toolbar=0,status=0,location=0,directories=0,left=0,top=0');
	winhandle.moveTo(screen.availWidth/2,0);
	winhandle.resizeTo(screen.availWidth/2, screen.availHeight);
	winhandle.focus(); 
}
function newWindow(url, width, height) {
    nameW='feature'
 if (navigator.appVersion.indexOf('4') != -1) {
 // Vars for centering the new window on Version 4 Browsers
 xTop = screen.width/2 - (width/2);
 yTop = 0;//screen.height/2 - (height/2);
 window.open(url, nameW, 'height='+height+',width='+width+',scrollbars=1,resizable=1,menubar=1,toolbar=1,status=1,location=0,directories=0,left=' + xTop + ',top=' + yTop + '');
 } 
 else {
 window.open(url, nameW, 'height='+height+',width='+width+',scrollbars=1,resizable=1,menubar=1,toolbar=1,status=1,location=0,directories=0,left=150,top=200');
 }
}
function OpenWindow( filename, winname, width, height, style )
{
	x = (1280 - width)/2, y = (1024 - height)/2;

	if (screen)
	{
		y = (screen.availHeight - height)/2;
		x = (screen.availWidth - width)/2;
	}
	
	if ( x < 0 || width<0)
	{
		x = 0
		width = screen.availWidth;
	}
	
	if ( y < 0|| height<0 )
	{
		y = 0
		height = screen.availHeight;
	}

	var winhandle=window.open( filename, winname,'width='+width+',height='+height+',screenX='+x+',screenY='+y+',top='+y+',left='+x+','+style);
	if ( winhandle == null || typeof(winhandle)== "undefined" )
	{
		alert( "You must turn off browser popup blocker before you can use this system" );
	}
	winhandle.resizeTo(width,height);
	winhandle.moveTo(x,y);
	//winhandle.focus();
	return winhandle;
}
function MoveWindowToScreenCenter( windowWidth, windowHeight )
{
	x = (1280 - windowWidth)/2, y = (1024 - windowHeight)/2;

	if (screen)
	{
		y = (screen.availHeight - windowHeight)/2;
		x = (screen.availWidth - windowWidth)/2;
	}
	
	if ( x < 0 )
	{
		x = 0
		windowWidth = screen.availWidth;
	}
	
	if ( y < 0 )
	{
		y = 0
		windowHeight = screen.availHeight
	}

	window.moveTo( x, y );
}
function ErrorMsg(url, errMsg)
{
	popUp = OpenWindow(url+'?errMsg='+errMsg, 'ErrMsg', 300,270, '');
}
function popWindow(url, width, height)
{
  popUp = OpenWindow(url, 'popUp', width, height, 'scrollbars=1,resizable=1');
}
function OpenCalendar(idname, postBack)
{
	popUp = OpenWindow('../Calendar.aspx?formname=' + document.forms[0].name + 
		'&id=' + idname + '&selected=' + document.forms[0].elements[idname].value + '&postBack=' + postBack,
		'popupcal', 300, 320,'');
	/*popUp = window.open('../Calendar.aspx?formname=' + document.forms[0].name + 
		'&id=' + idname + '&selected=' + document.forms[0].elements[idname].value + '&postBack=' + postBack, 
		'popupcal', 
		'width=300,height=270,left=300,top=250');*/
}

function OpenCalendarWithAdditionalString(idname, additionalStr, postBack)
{
	popUp = OpenWindow('../Calendar.aspx?formname=' + document.forms[0].name + 
		'&id=' + idname + '&selected=' + document.forms[0].elements[idname].value + '&add=' + additionalStr + '&postBack=' + postBack,
		'popupcal', 300, 320,'');
	/*popUp = window.open('../Calendar.aspx?formname=' + document.forms[0].name + 
		'&id=' + idname + '&selected=' + document.forms[0].elements[idname].value + '&postBack=' + postBack, 
		'popupcal', 
		'width=300,height=270,left=300,top=250');*/
}

function SetDate(formName, id, newDate, postBack)
{
	eval('var theform = document.' + formName + ';');
	popUp.close();
	theform.elements[id].value = newDate;
	if (postBack)
		__doPostBack(id,'');
}
/*function OpenCalDT(idname, id, postBack)
{
	popUp = OpenWindow('../CalDateTime.aspx?formname=' + document.forms[0].name + 
		'&id=' + idname + '&selected=' + document.forms[0].elements[id].value + '&postBack=' + postBack,'popupcal',
		300, 320, '');

}		
*/
function OpenCalDateTime(idname, postBack)
{
/*	popUp = window.open('../CalDateTime.aspx?formname=' + document.forms[0].name + 
		'&id=' + idname + '&selected=' + document.forms[0].elements[idname].value + '&postBack=' + postBack, 
		'popupcal', 
		'width=300,height=320,left=200,top=250');
*/
	popUp = OpenWindow('../CalDateTime.aspx?formname=' + document.forms[0].name + 
		'&id=' + idname + '&selected=' + document.forms[0].elements[idname].value + '&postBack=' + postBack,'popupcal',
		300, 350, '');
}

function Group(idname, postBack)
{
	popUp = OpenWindow('../Administration/GroupAdd.aspx?formname=' + document.forms[0].name + 
		'&id=' + idname + '&selected=' + document.forms[0].elements[idname].value + '&postBack=' + postBack,
		'popupcal', 450, 260, '');
/*
	popUp = window.open('../Administration/GroupAdd.aspx?formname=' + document.forms[0].name + 
		'&id=' + idname + '&selected=' + document.forms[0].elements[idname].value + '&postBack=' + postBack, 
		'popupcal', 
		'width=550,height=300,left=200,top=200');
*/}
function CloseWindow()
{
	self.close();
}
function TextChanged(formName, id, newText, postBack)
{
	eval('var theform = document.' + formName + ';');
	popUp.close();
	theform.elements[id].value = newText;
	if (postBack)
		__doPostBack(id,'');
}

function Guest(idname, postBack)
{
	popUp = window.open('../Administration/GuestAdd.aspx?formname=' + document.forms[0].name + 
		'&id=' + idname + '&selected=' + document.forms[0].elements[idname].value + '&postBack=' + postBack, 
		'popupcal', 
		'width=550,height=400,left=200,top=200');
}


function showLayer(layerName)
{
    if (document.getElementById) // Netscape 6 and IE 5+
    {
        var targetElement = document.getElementById(layerName);
//        var shadowElement = document.getElementById(shadowLayerName);
    //      targetElement.style.top = shadowElement.style.top;
        targetElement.style.visibility = 'visible';
    }
}


function hideLayer(layerName)
{
    if (document.getElementById) 
    {
        var targetElement = document.getElementById(layerName);
        targetElement.style.visibility = 'hidden';
    }
}



function GetClientTimeZoneOffset()
{
	var dt = new Date();
	var offset = dt.getTimezoneOffset()/60 * -1;
	document.forms[0].tbxTimeZoneOffset.value = offset;
}


function TopPopup()
{
	if ( window.popUp )
	{
		if ( !popUp.closed )
		{
			popUp.focus();
		}
	}
}

function sv(sPicURL){
	popUp = window.open( "popup.htm?"+sPicURL, "",  "resizable=1,menubar=1");
	//popUp.document.execCommand('SaveAs');
	//popUp.close();
}
function Save()
{
    var theMapUrl = parent.MapFrame.theImage.src;
    var toAspPage = 'mapimage.asp?mapurl='+theMapUrl;
	alert("To save, simply click “File”, select “Save As” from the drop down menu.");
	sv(theMapUrl);
}

function Done()
{
	window.returnValue = true;
	window.opener.document.forms(0).submit();
	self.close();
	
}
function DoneShowModalDialog()
{
	window.returnValue = true;
	window.close();
	
}
