/*************** OPEN IMAGE WINDOW ***************/
var resizableImageWindowURL = "/_javascript/images/resize/view.html"
function openImageWindow(src, width, height){
	width = (width)?width:600
	height = (height)?height:400
	
	openWindow(resizableImageWindowURL + "?" + src, "imageWindow", centerWindow(width, height) + "width=" + width + ",height=" + height + ",status,resizable,scrollbars")
	return false
}

/*************** RESIZE DIALOGUE ***************/
function resizeDialog(){
	if(window.dialogHeight && document.body.scrollHeight)
		window.dialogHeight = (parseInt(document.body.scrollHeight)+45) + "px"
	else if(window.outerHeight && document.body.offsetHeight)
		window.outerHeight = document.body.offsetHeight+45
	else
		return
}

/*************** GET WINDOW TOP ***************/
function getWindowTop(win){
	if(!win) win = window

	if(win.screenTop)
		return win.screenTop - 20
	if(win.screenY)
		return win.screenY
	return 0
}

/*************** GET WINDOW LEFT ***************/
function getWindowLeft(win){
	if(!win) win = window

	if(win.screenLeft)
		return win.screenLeft
	if(win.screenX)
		return win.screenX
	return 0
}

/*************** CENTER WINDOW ***************/
function centerWindow(width, height){
	var offset = 25

	var leftPosition = Math.round( (screen.availWidth - width)/2 )
	var topPosition = Math.round( (screen.availHeight - height)/2 )

	if(getWindowLeft(top) > leftPosition)
		leftPosition = getWindowLeft(top) + offset
	if(getWindowTop(top) > topPosition)
		topPosition = getWindowTop(top) + offset

	return "left=" + leftPosition  + ",top=" + topPosition  + ",";
}


/*************** OPEN WINDOW ***************/
function openWindow(URL, windowName, windowFeatures){
	if(windows[windowName]){
		if(!windows[windowName].closed){
			windows[windowName].location = URL
		} else {
			windows[windowName] = window.open(URL, windowName, windowFeatures);
		}
	} else{
		windows[windowName] = window.open(URL, windowName, windowFeatures);
	}
	windows[windowName].focus();
	return windows[windowName]
}

/*************** IS WINDOW OPEN ***************/
function isWindowOpen(windowName){
	if(!windows[windowName]) 
		return false
	else if(windows[windowName].closed) 
		return false
	else
		return true
}

/*************** CLOSE WINDOW ***************/
function closeWindow(windowName){
	if(windows[windowName])
		if(!windows[windowName].closed)
			windows[windowName].close()
}

/*************** OPEN MODAL DIALOG ***************/
function openModalDialog(URL, windowName, windowFeatures){
	var win = openWindow(URL, windowName, windowFeatures);
	dialogs[windowName] = true;
	return win
}

/*************** OPENER ONFOCUS ***************/
function opener_onfocus(){
	return false
	if(navigator.platform.indexOf("Mac") != -1 ) return false

	var each;
	for(each in windows){
		if(windows[each] && dialogs[each]){
				setTimeout("if(!windows['" + each + "'].closed)windows['" + each + "'].focus()",10)
				return true;
		}
	}
}

/*************** OPENER ONUNLOAD ***************/
function opener_onunload(){
	var each;
	for(each in windows){
		if(!windows[each].closed){windows[each].close()}
	}
}

/*************** GET WINDOW WIDTH ***************/
function getWindowWidth(win){
	if(!win) win = this
	if(typeof win.innerWidth != "undefined"){return win.innerWidth-20} 
	if(win.document.body){return win.document.body.clientWidth} 
	return 0
}

var windows = new Object();
var dialogs = new Object();

window.onfocus = opener_onfocus;
window.onunload = opener_onunload;
	
/*************** SET WINDOW FEATURES ***************/
function setWindowFeatures(width, height, attributes){
	return centerWindow(width, height) + "width=" + width + ",height=" + height + ((attributes)?"," + attributes:"")
}

// attributes
var dialogAttributes = "resizable=1,status=1,scrollbars=0,menubar=0,location=0,toolbar=0"
var windowAttributes = "resizable=1,status=1,scrollbars=1,menubar=0,location=0,toolbar=0"
var browserAttributes = "resizable=1,status=1,scrollbars=1,menubar=1,location=1,toolbar=1,directories=1"

// 790 x 520
var dialog790x520 = "left=0,top=0,width=790,height=520," + dialogAttributes
var browser790x520 = "left=0,top=0,width=790,height=520," + browserAttributes

var dialog700x500 = setWindowFeatures(700, 500, dialogAttributes) 
var window700x500 = setWindowFeatures(700, 500, windowAttributes) 

var dialog640x480 = setWindowFeatures(640, 480, dialogAttributes) 
var window640x480 = setWindowFeatures(640, 480, windowAttributes) 
var browser640x480 = setWindowFeatures(640, 480, browserAttributes)

var dialog600x400 = setWindowFeatures(600, 400, dialogAttributes) 

var dialog480x480 = setWindowFeatures(480, 480, dialogAttributes) 
var window480x480 = setWindowFeatures(480, 480, windowAttributes) 

var dialog400x400 = setWindowFeatures(400, 400, dialogAttributes) 
var window400x400 = setWindowFeatures(400, 400, windowAttributes) 

var dialog400x300 = setWindowFeatures(400, 300, dialogAttributes) 
var window400x300 = setWindowFeatures(400, 300, windowAttributes) 
var dialog400x150 = setWindowFeatures(400, 150, dialogAttributes) 
var dialog400x100 = setWindowFeatures(400, 100, dialogAttributes) 

var dialog300x400 = setWindowFeatures(300, 400, dialogAttributes) 
var window300x400 = setWindowFeatures(300, 400, windowAttributes) 

var dialog300x300 = setWindowFeatures(300, 300, dialogAttributes) 

var dialog300x150 = setWindowFeatures(300, 150, dialogAttributes) 

var dialog300x100 = setWindowFeatures(300, 100, dialogAttributes)

