/**
	Id:$
*/

function alternateWindow(NM,ATR) {

// ATTRIBUTES;
	this.location = new String("");
	this.name = NM;
	this.attributes = ATR;
	this.browsField = new Object();

// PUBLIC_METHODS;
	this.setLocation = public_setLocation;
	this.setWindowName = public_setWindowName;
	this.setNewWindow = public_setNewWindow;
	this.setAttributes = public_setAttributes;
	//for compatibility
		this.setName = public_setWindowName;
		this.setWindowFocus = setWindowFocus;
		this.setAltWindowClose = setAltWindowClose;
		
		


	function public_setLocation() {
		if (!!arguments[0]) this.location = arguments[0];
	}
	function public_setWindowName() {
		if (!!arguments[0]) this.name = arguments[0];
	}
	function setAltWindowClose() {
		if (!!this.browsField) {
				this.browsField.close();
		}
	}
	function public_setNewWindow(_LOCATION, _NAME, _ATTRIBUTES) {
		if (!!this.name) {
			if (!!!this.attributes && getPlatform()=="mac" && document.all) this.attributes = 'toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,resizable=yes,favorites=yes';
			this.browsField = (!!this.attributes)? window.open(this.location, this.name, this.attributes) : window.open(this.location, this.name);
			setWindowFocus(this.browsField);
		}
	}
	function public_setAttributes() {
		var result = new String();
		var tmp = new Object();

		for (var item=0; item<arguments.length; item++) {
			if (arguments[item].substring(0,3) == "wid") tmp["width"] = getValue(arguments[item]);
			if (arguments[item].substring(0,3) == "hei") tmp["height"] = getValue(arguments[item]);
			if (arguments[item].substring(0,3) == "lef") tmp["left"] = getValue(arguments[item]);
			if (arguments[item].substring(0,3) == "top") tmp["top"] = getValue(arguments[item]);
			if (arguments[item].substring(0,3) == "dir") tmp["directories"] = getValue(arguments[item]);
			if (arguments[item].substring(0,3) == "loc") tmp["location"] = getValue(arguments[item]);
			if (arguments[item].substring(0,3) == "men") tmp["menubar"] = getValue(arguments[item]);
			if (arguments[item].substring(0,3) == "res") tmp["resizable"] = getValue(arguments[item]);
			if (arguments[item].substring(0,3) == "scr") tmp["scrollbars"] = getValue(arguments[item]);
			if (arguments[item].substring(0,3) == "sta") tmp["status"] = getValue(arguments[item]);
			if (arguments[item].substring(0,3) == "too") tmp["toolbar"] = getValue(arguments[item]);
			if (!!tmp["left"]) tmp["screenX"] = tmp["left"];
			if (!!tmp["top"])  tmp["screenY"] = tmp["top"];
		}

		if (!!tmp["top"]) {
			tmp["top"] = (!!tmp["height"])? getWindowTop(tmp["top"],tmp["height"]) : tmp["top"] ;
			tmp["screenY"] = tmp["top"];
		}
		if (!!tmp["width"]) {
			tmp["width"] = (tmp["scrollbars"]=="yes" && getPlatform()=="mac" && document.all)? tmp["width"] : new String(parseInt(tmp["width"])+16) ;
		}
		if (!!tmp["height"]) {
			tmp["height"] = (tmp["scrollbars"]=="yes" && getPlatform()=="mac" && document.all)? tmp["height"] : new String(parseInt(tmp["height"])+16) ;
			tmp["height"] = (!!tmp["height"])? getWindowHeight(tmp["height"]) : tmp["height"] ;
			tmp["height"] = (tmp["toolbar"]=="yes")? new String(parseInt(tmp["height"])-90) : tmp["height"] ;
		}

		for (var item in tmp) {
			result = (result=="")? new String(result+item+"="+tmp[item]) : ((!!tmp[item])? new String(result+","+item+"="+tmp[item]) : "") ;
		}

		this.attributes = result;
	}

// PRIVATE_METHODS;
	function getAgentType() {
		if (navigator) {
			if ( window.opera ) {
				if (navigator.appVersion.indexOf("Win",0) != -1) return "opera_win";
				else if (navigator.appVersion.indexOf("Mac",0) != -1) return "opera_mac";
				else return "opera";
			} else if ( document.all && document.getElementById ) {
				if (navigator.appVersion.indexOf("Win",0) != -1) return "ms5_win";
				else return "ms5_mac";
			} else if ( document.all && !document.getElementById ) {
				if (navigator.appVersion.indexOf("Win",0) != -1) return "ms4_win";
				else return "ms4_mac";
			} else if ( document.getElementById && !document.all ) {
				if (navigator.appVersion.indexOf("Win",0) != -1) return "stnrd_win";
				else if (navigator.appVersion.indexOf("Mac",0) != -1) return "stnrd_mac";
				else return "stnrd";
			} else if ( document.layers ) {
				if (navigator.appVersion.indexOf("Win",0) != -1) return "nn4x_win";
				else if (navigator.appVersion.indexOf("Mac",0) != -1) return "nn4x_mac";
				else return "nn4x";
			} else {
				return "else";
			}
		}
	}
	function getPlatform() {
		var result = "";
		if (navigator.platform.indexOf("Win") != -1) {
			result = "win";
		} else if (navigator.platform.indexOf("Mac") != -1) {
			result = "mac";
		} else {
			result = "els";
		}
		if (!!arguments[0]) {
			result = (arguments[0] == result)? true : false;
		}
		return result;
	}
	function getValue() {
		return arguments[0].substring(parseInt(arguments[0].indexOf("=", 0)) + 1, arguments[0].length);
	}
	function getWindowHeight() {
		return (!!screen && arguments[0]>=screen.availHeight)? new String(screen.availHeight-32) : arguments[0] ;
	}
	function getWindowTop() {
		return (!!screen && arguments[1]>=screen.availHeight)? new String("0") : arguments[0] ;
	}
	function setWindowFocus(targetWindow) {
		if ( getAgentType() != "ms4_win" ) {
			if ( getAgentType() != "ms4_mac" ) {
				targetWindow.focus();
			}
		}
	}
}
