// Javascript methods to be called from flash movies through ExternalInterface
// handles calls made through /flash/iframe.tmpl.
// this js file should be included in /flash/iframe.tmpl
// and the file that contains the flash object

GenericFlash.changeLocation = function (newHref) {
	if (this.framed) {
		parent.window.location.href = newHref;
	} else {
		window.location.href = newHref;
	}
}


/*GenericFlash.changeOpenerLocation = function (newHref) {
	if (this.framed) {
		if (typeof parent.window.opener == "object" && parent.window.opener != null) {
			parent.window.opener.location.href = newHref;
		} else {
			parent.window.location.href = newHref;
		}
	} else {
		if (typeof window.opener == "object" && window.opener != null) {
			window.opener.location.href = newHref;
		} else {
			window.location.href = newHref;
		}
	}
}*/

GenericFlash.changeOpenerLocation = function (newHref) {
	if (this.framed) {
		if (typeof parent.window.opener == "object" && parent.window.opener != null && !parent.window.opener.closed) {
			parent.window.opener.focus();
			parent.window.opener.location.href = newHref;
			parent.window.blur();
		} else {
			GenericFlash.popBlankWindow (newHref);
		}
	} else {
		if (typeof window.opener == "object" && window.opener != null && !window.opener.closed) {
			window.opener.focus();
			window.opener.location.href = newHref;
			window.blur();
		} else {
			GenericFlash.popBlankWindow (newHref);
		}
	}
}

GenericFlash.focusOpener = function() {
	//alert("focus");
	if (this.framed) {
		if (typeof parent.window.opener == "object") {
			parent.window.opener.focus();
		} 
	} else {
		if (typeof window.opener == "object") {
			window.opener.focus();
		} 
	}
}

// @param args - json style object with {} containing the args to be used for the popup
GenericFlash.flashPopUpWindow = function(url, args) {
	var defaults = {
		height: 600,
		width: 475,
		top: 10,
		left: 10,
		resizable: 'yes',
		scrollbars: 'yes',
		status: 'no',
		toolbar: 'no',
		menubar: 'no',
		name: 'pop'
	};
	args = Object.applyDefaults(args, defaults);
	
	var specs =
		'height='+args.height+
		',width='+args.width+
		',top='+args.top+
		',left='+args.left+
		',resizable='+args.resizeable+
		',scrollbars='+args.scrollbars+
		',status='+args.status+
		',toolbar='+args.toolbar+
		',menubar='+args.menubar+
		',location='+url;
	
	if (this.framed) {
		var win = parent.window.open(url, args.name, specs);
		if (!win) {
			parent.window.alert('Please deactivate your popup blocker to view this page.');
		} else {
			win.focus();
		}
	} else {
		var win = window.open(url, args.name, specs);
		if (!win) {
			window.alert('Please deactivate your popup blocker to view this page.');
		} else {
			win.focus();
		}
	}
	
	return;
}

GenericFlash.popBlankWindow = function(url, name) {
	var winName = (name) ? name : 'blank_window';
	
	if (this.framed) {
		var win = parent.window.open(url, winName);
		if (!win) {
			//window.alert('Please deactivate your popup blocker to view this page.');
			return;
		} else {
			win.focus();
		}
	} else {
		var win = window.open(url, winName);
		if (!win) {
			//window.alert('Please deactivate your popup blocker to view this page.');
			return;
		} else {
			win.focus();
		}
	}
	
	return;
}