/**
 * namedWindow(theParam)
 * This function opens a new, empty window. Note that if you want Google, Yahoo! and MSN spiders to follow the link,
 * you should always use a link of the form <a href="myLink" onclick="!namedWindow(theParam)">Link text</a> -- this will
 * also allow JavaScript-disabled clients and ones with popup prevention to follow the link (although in the launching window).
 * (You don't want to have your onclick event simply return false because if a popup prevention plugin like Google's prevents
 * the window from opening, you want the link to be able to open regardless.)
 * By default, the new window created by namedWindow()is named (i.e., multiple calls will appear in the same window),
 * but this property can be overridden (see below). 
 * Legal syntaxes:
 * <a href="http://goventure.net/myFirst/" onclick = "return !namedWindow('http://goventure.net/myFirst/')">Link text</a>
 * (opens a full-sized window with default featureset -- see function definition, below)
 * <a href="http://goventure.net/myFirst/"
 *     onclick = "return !namedWindow({url:'http://goventure.net/myFirst/',name:'MyFirst',width:300,height:300})">Link text</a>
 * (Note that in this second syntax, any default variables not overridden in the object literal passed as a parameter
 * to this function will retain the values assigned when objProps is first created in the first line of the function body.)
 * **** IMPORTANT: **** The value for the 'name' parameter in this function must ONLY include alphanumeric characters or underscore,
 * or else the function will break!!! (Specified by the second parameter restrictions of JavaScript's window.open() method)
 * **********************************
 * If you want to create a new window without a variable name so that it opens a new window each time (i.e., window.open(myLink, '', featureList),
 * then include the pair name: '' (empty string) in the object literal, i.e.,
 * onclick="namedWindow({url: 'http://some.url', name: '', width: 750, height:400})"
 * By default the window featureset is the same as that for the old newWindow_full function
 * ('toolbar=yes,location=yes,directories=yes,menubar=yes,scrollbars=yes,width=800,height=600') with left and top (or screenX and screenY)
 * each set to 50.
 * For replacing legacy calls:
 * newWindow featureset = 'toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes'
 * newPdfWindow featureset =
 * 'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=auto,resizable=no,width=780,height=590,left=50,top=50'
 * and a specified windowName.
 * newWindow_contact featureset = 'toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes' with left and top each set to 40,
 * default width 560, and default height 420.
 * newWindow_movie featureset =
 * 'toolbar=no,location=no,directories=no,menubar=no,scrollbars=no,resizable=yes,status=no' with default width 639 and default height 477,
 * and width and height explicitly called, in that order. (Left and top are both set to 100.)
 * newWindow_help featureset = 'toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes' with width and height explicitly specified
 * and no left/top settings.
 * newWindow_newsletter featureset = 'toolbar=yes,location=no,directories=no,menubar=no,scrollbars=yes,resizable=yes,width=620,height=500'
 * with no left/top settings. Make the URL into a GET request to http://www.goventure.net/site/products/live/fwd.cfm and append
 * "?d=" + the issue's URL + "&i=" + the page name you want the Activity Tracker to record for hit-count purposes.
 * newWindow_trial featureset = 'toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,width=620,height=420'
 * with left and top set to 40.
 * newWindow_tools featureset = 'toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes' with left, top, width, and height
 * explicitly passed as args in that order.
 * For all VOwindow functions (see newWindow_VO) the featureset is
 * 'toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,resizable=no,width=640,height=480'
 * (the original script had the resizable label misspelled as "resizeable" so it didn't work)
 */
function namedWindow() {
    if(namedWindow.arguments.length < 1) {
        return false;
    }
    var propertiesObjectOrUrl = namedWindow.arguments[0];
    var defaultObject = null;
    
    if(namedWindow.arguments.length > 1) {
        if(typeof(namedWindow.arguments[1]) == "object") {
            defaultObject = namedWindow.arguments[1];
        }
    }
    var objProps = {
        url         :   'about:blank',
        name        :   'fullWindow',
        toolbar     :   'yes',
        location    :   'yes',
        directories :   'yes',
        menubar     :   'yes',
        scrollbars  :   'yes',
        width       :   800,
        height      :   600
    };
    var arrWindowFeatures = new Array("toolbar", "location", "directories", "menubar", "scrollbars", "width", "height");
    
    if (navigator.appName.indexOf("Microsoft") > -1) {
        isMSIE = true;
        objProps.leftName = 'left';
        objProps.topName = 'top';
//    	winStats=winStats+'left=50,top=50';
    } else {
        isMSIE = false;
        objProps.leftName = 'screenX';
        objProps.topName = 'screenY';
//		winStats=winStats+'screenX=50,screenY=50';
    }
    arrWindowFeatures.splice(arrWindowFeatures.length, 0, objProps.leftName, objProps.topName);
    objProps.leftVal = '50';
    objProps.topVal = '50';
    if(defaultObject != null) {
        for(defProp in defaultObject) {
            if(defProp == "screenX") {
                continue; // skip remainder of the current loop and move on to the next iteration: this case will be handled later
            }
            objProps[defProp] = defaultObject[defProp];
        }
    }
    
    var strWindowFeatures = "";

    if(typeof(propertiesObjectOrUrl) == "string") {
        // treat as URL
        objProps.url = propertiesObjectOrUrl;
        
    } else if(typeof(propertiesObjectOrUrl) == "object") {
        // treat as properties object
        objProps.url = propertiesObjectOrUrl.url;
        for(var x = 0; x < arrWindowFeatures.length; x++) {
            if(eval("propertiesObjectOrUrl." + arrWindowFeatures[x])) {
                eval("objProps." + arrWindowFeatures[x] + " = propertiesObjectOrUrl." + arrWindowFeatures[x]);
            }
        }
        if(propertiesObjectOrUrl.screenX && typeof(propertiesObjectOrUrl.screenX) != "undefined") {
            objProps.leftVal = propertiesObjectOrUrl.screenX;
        } else if (propertiesObjectOrUrl.left && typeof(propertiesObjectOrUrl.left) != "undefined") {
            objProps.leftVal = propertiesObjectOrUrl.left;
        } else if(defaultObject != null && defaultObject.screenX && typeof(defaultObject.screenX) != "undefined")
        {
            objProps.leftVal = defaultObject.screenX;
        } else if(defaultObject != null && defaultObject.left && typeof(defaultObject.left) != "undefined")
        {
            objProps.leftVal = defaultObject.left;
        }
        if(propertiesObjectOrUrl.screenY && typeof(propertiesObjectOrUrl.screenY) != "undefined") {
            objProps.topVal = propertiesObjectOrUrl.screenY;
        } else if (propertiesObjectOrUrl.top && typeof(propertiesObjectOrUrl.top) != "undefined") {
            objProps.topVal = propertiesObjectOrUrl.top;
        } else if(defaultObject != null && defaultObject.screenY && typeof(defaultObject.screenY) != "undefined")
        {
            objProps.topVal = defaultObject.screenY;
        } else if(defaultObject != null && defaultObject.top && typeof(defaultObject.top) != "undefined")
        {
            objProps.topVal = defaultObject.top;
        }
        objProps[objProps.leftName] = objProps.leftVal;
        objProps[objProps.topName] = objProps.topVal;
        if(propertiesObjectOrUrl.name) {
            objProps.name = propertiesObjectOrUrl.name;
        }
    }
    for(var x = 0; x < arrWindowFeatures.length; x++) {
        strWindowFeatures += (objProps[arrWindowFeatures[x]] === '' ? '' :
                                (strWindowFeatures.length == 0 ? '' : ',') + arrWindowFeatures[x] + '=' + objProps[arrWindowFeatures[x]]);
    }
    if(objProps.hasOwnProperty('status')) {
        strWindowFeatures += (objProps['status'] === '' ? '' :
                                (strWindowFeatures.length == 0 ? '' : ',') + 'status=' + objProps['status']);
    }
    var windowRef = window.open(objProps.url, objProps.name, strWindowFeatures);
    return windowRef;
}

function minimalWindow(objProps) {
    var strWindowFeatures = '';
	if(typeof(objProps) == 'string') {
		return window.open(objProps, 'minimalWindow', '');
	}
    for (prop in objProps) {
        if(prop == 'url' || prop == 'name') {
            continue;
        }
        strWindowFeatures += (strWindowFeatures.length == 0 ? '' : ',') + prop + '=' + objProps[prop];
    }
    var url = objProps.url;
    var name = (objProps.name == '' ? 'minimalWindow' : objProps.name);
    var windowRef = window.open(url, name, strWindowFeatures);
    return windowRef;
}

function namedPdfWindow(propertiesObjectOrUrl) {
    var objWindow = {'name': 'PdfWindow', 'width': 800, 'height': 600, 'toolbar': 'no', 'location': 'no', 'directories': 'no', 'menubar': 'no', 'scrollbars': 'yes'};
    if (typeof(propertiesObjectOrUrl) == 'string') {
        objWindow.url = propertiesObjectOrUrl;
    } else if (typeof(propertiesObjectOrUrl) == 'object') {
        for(var item in propertiesObjectOrUrl) {
            objWindow[item] = propertiesObjectOrUrl[item];
        }
    }
    var windowRef = namedWindow(objWindow);
    return windowRef;
}

function namedWindow_movie(propertiesObjectOrUrl) {
    var defaultObject = {toolbar : 'no', location: 'no', directories: 'no', menubar: 'no', scrollbars: 'no',
        resizable: 'yes', status: 'no', width: 639, height: 477, left: 100, top: 100};
    return namedWindow(propertiesObjectOrUrl, defaultObject);
}

function namedWindow_contact(propertiesObjectOrUrl) {
    var defaultObject = {toolbar: 'no', location: 'no', directories: 'no', menubar: 'no', scrollbars: 'yes', left: 40, top: 40,
        width: 560, height: 420};
    return namedWindow(propertiesObjectOrUrl, defaultObject);
}

function namedWindow_gv(propertiesObjectOrUrl) {
	return namedWindow(propertiesObjectOrUrl, {width: 600, height: 750});
	/**
	 * second object in the preceding call contains default values which are used if the
	 * corresponding named properties in the first argument aren't explicitly set
	 */
}

function namedWindow_activities(propertiesObjectOrUrl) {
	return namedWindow(propertiesObjectOrUrl,
		{left: 100, top: 100, width: 500, height: 400, toolbar: 'no', directories: 'no',
			scrollbars: 'no', menubar: 'no', location: 'no'});
	/**
	 * second object in the preceding call contains default values which are used if the
	 * corresponding named properties in the first argument aren't explicitly set
	 */
}

function namedWindowFullWidth(propertiesObjectOrUrl) {
	var obj = {};
	var w = 980;
    if(typeof(propertiesObjectOrUrl) == 'string') {
		obj = {url: propertiesObjectOrUrl, width: w};
	} else if(typeof(propertiesObjectOrUrl) == 'object') {
		obj = propertiesObjectOrUrl;
		obj.width = w;
	}
    return namedWindow(obj);
}

