/**
 * @fileOverview defines popup windows: PopupWindow, CollegeChancePopup, CollegeChanceDetailPopup, EfcPopup.
 * @author neal.fu, ray.chen
 * @version 1.0
 * @since 6.80, 2011-05-23
 */

/**
 * Creates an instance of PopupWindow.
 *
 * @constructor
 * @this {PopupWindow}
 * @param {String}      url                 The url of the popup window.
 * @param {String}      mainPageName        The name of the source page.
 * @param {String}      popupName           The name of the popup window.
 */
function PopupWindow(url, mainPageName, popupName) {
    this.url = url;
    this.mainPageName = mainPageName;
    this.popupName = popupName;
}

/**
 * Creates an instance of CollegeChancePopup window.
 *
 * @constructor
 * @this {CollegeChancePopup}
 * @param {String}      url                 The url of the popup window.
 * @param {String}      mainPageName        The name of the source page.
 * @param {String}      popupName           The name of the popup window.
 * @example
 *                             var collegeChancePopup = new CollegeChancePopup();
 *                             collegeChancePopup.open();
 */
function CollegeChancePopup(url, mainPageName, popupName) {
    PopupWindow.apply(this, arguments);

    /**
     * Displays the popup window.
     *
     * @this {CollegeChancePopup}
     */
    this.open = function(parentWindow) {
        setCookie('mainpage', this.mainPageName);
        collegeChancePopup = window.open(this.url, this.popupName, "left=0,top=0,height=673,width=330,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no");
        collegeChancePopup.focus();
        
        if (parentWindow != null) {
        	if (parentWindow.collegeChanceDetailPopup != null) {
        		collegeChancePopup.collegeChanceDetailPopup = parentWindow.collegeChanceDetailPopup;
			}
		}
    }
}

/**
 * Makes CollegeChancePopup inheriting PopupWindow.
 */
CollegeChancePopup.prototype = ( function() {
    return new PopupWindow();
} )();

/**
 * Creates an instance of CollegeChanceDetailPopup window.
 *
 * @constructor
 * @this {CollegeChanceDetailPopup}
 * @param {String}      url                 The url of the popup window.
 * @param {String}      mainPageName        The name of the source page.
 * @param {String}      popupName           The name of the popup window.
 * @example
 *                             var collegeChanceDetailPopup = new CollegeChanceDetailPopup();
 *                             collegeChanceDetailPopup.open();
 */
function CollegeChanceDetailPopup(url, mainPageName, popupName) {
    PopupWindow.apply(this, arguments);

    /**
     * Displays the popup window.
     *
     * @this {CollegeChanceDetailPopup}
     */
    this.open = function(parentWindow) {
        setCookie('mainpage', this.mainPageName);
        collegeChanceDetailPopup = window.open(this.url, this.popupName, "left=400,top=0,height=673,width=517,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no");
        collegeChanceDetailPopup.focus();
        
        if (parentWindow != null) {
        	parentWindow.collegeChanceDetailPopup = collegeChanceDetailPopup;
		}

        CookieUtil.setCookie("chances_result_portable_opener_url", parentWindow.location.href);
        CookieUtil.setCookie("chances_result_portable_mainPageName", this.mainPageName);
    }
}

/**
 * Makes CollegeChanceDetailPopup inheriting PopupWindow.
 */
CollegeChanceDetailPopup.prototype = ( function() {
    return new PopupWindow();
} )();

/**
 * Creates an instance of EfcPopup window.
 *
 * @constructor
 * @this {EfcPopup}
 * @param {String}      url                 The url of the popup window.
 * @param {String}      mainPageName        The name of the source page.
 * @param {String}      popupName           The name of the popup window.
 * @param {String}      requestFromUrl      The url of the previews page.
 * @example
 *                             var efcPopup = new EfcPopup();
 *                             efcPopup.open();
 */
function EfcPopup(url, mainPageName, popupName, requestFromUrl) {
    this.requestFromUrl = requestFromUrl;

    PopupWindow.apply(this, arguments);

	this.height = 244;
	this.width = 380;
	
	this.resize = function (height, width) {
		this.height = height;
		this.width = width;
		return this;
	} 

    /**
     * Displays the popup window.
     *
     * @this {EfcPopup}
     */
    this.open = function () {
        setCookie("request_from_url", this.requestFromUrl);
        setCookie("mainpage", this.mainPageName);
        setCookie("protocol", window.location.protocol);
        efcPopup = window.open(this.url, this.popupName, "left=0,top=0,height=" + this.height + ",width=" + this.width + ",status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no");
        efcPopup.focus();
    }
}

/**
 * Makes EfcPopup inheriting PopupWindow.
 */
EfcPopup.prototype = ( function() {
    return new PopupWindow();
} )();

