/******************************************************************************* 
 * @(#)js/popups.js
 *  Rev:         C
 *  Created:     Mon. Saturday 19, 2005, 08:00:00
 *  Author:      media-roayal
 *  mailto:      support@media-royal.com
 *
 *  Copyright by "media-royal.com"
 *
 *  The copyright to the computer program(s) herein
 *  is the property of "media-royal.com", Germany.
 *  The program(s) may be used and/or copied only with
 *  the written permissions of "media-royal.com"
 *  or in accordance with the terms and conditions
 *  stipulated  in the agreement/contract under which
 *  the  program(s) have been supplied.
 *
 * CopyrightVersion 2.0
 *
 ********************************************************************************
 *
 * This site represents an the ultimate media-royal solution for popups
 *
 * @author  Daniel Beckert
 * @version 2.0, Sat, 2005-11-19
 * @since   
 *
 *******************************************************************************/
 
 
/**************************************** !!! IMPORTANT !!! *******************************************
 *
 * !!! Set some standarte values !!!
 * This values are set if some parameters/values are not or wrong set
 *
 */
 var standardWinURL           = new String(topPath+"popups/popupfailure.php"); //<<--- url
 var standardWinID            = new String("dot_cube_pop");                    //<<--- id
 var standardWinXPos          = new Number(0);                                 //<<--- xPos
 var standardWinYPos          = new Number(0);                                 //<<--- yPos
 var standardWinWidth         = new Number(400);                               //<<--- width
 var standardWinHeight        = new Number(400);                               //<<--- height
 var standardWinIsResizeable  = new String("no");                              //<<--- resizeable
 var standardWinHasScrollbar  = new String("no");                              //<<--- scrollbar
 var standardWinHasAdressline = new String("no");                              //<<--- location (adressline)
 var standardWinHasMenubar    = new String("no");                              //<<--- menubar
 var standardWinHasToolbar    = new String("no");                              //<<--- toolbar
 var standardWinHasStatusline = new String("no");                              //<<--- status
 var standardWinCanUseHotkeys = new String("yes");                             //<<--- hotkeys
 var standardWinIsDependent   = new String("no");                              //<<--- depentend
 var standardWinHasDirectories= new String("yes");                             //<<--- directories


//----------------------------------------------------------------------------------------------------



/*
 *-----------------------------------------------------------------------------------------------------
 *
 *           openWinMain
 *
 * ----------------------------------------------------------------------------------------------------
 *
 * This function opens the popup window 
 *
 * @param objWindowParams:Array
 *      |
 *      + ---> ["url"]
 *      |
 *      + ---> ["id"]
 *      |
 *      + ---> ["xPos"]
 *      |
 *      + ---> ["yPos"]
 *      |
 *      + ---> ["width"]
 *      |
 *      + ---> ["height"]
 *      |
 *      + ---> ["isResizeable"]
 *      |
 *      + ---> ["hasScrollbar"]
 *      |
 *      + ---> ["hasAdressline"]
 *      |
 *      + ---> ["hasMenubar"]
 *      |
 *      + ---> ["hasToolbar"]
 *      |
 *      + ---> ["hasStatusline"]
 *      |
 *      + ---> ["canUseHotkeys"]
 *      |
 *      + ---> ["isDependent"]
 *      |
 *      + ---> ["hasDirectories"]
 *
 */ 
 function openWin(objWindowParams){
	 //---------- Parameters ----------
    var windowURL           = new String(); // The url of the window
    var windowID            = new String(); // The id of the window
    var windowXPos          = new Number(); // The xPosition of the window
    var windowYPos          = new Number(); // The yPosition of the window
    var windowWidth         = new Number(); // The width of the window
    var windowHeight        = new Number(); // The height of the window
    var windowIsResizeable  = new String(); // The resizeablestate of the window 
    var windowHasScrollbar  = new String(); // The scrollbarstate of the window 
    var windowHasAdressline = new String(); // The adressline state of the window
    var windowHasMenuBar    = new String(); // The menubarstate of the window
    var windowHasToolBar    = new String(); // The toolbarstate of the window
    var windowHasStatusLine = new String(); // The statuslinestate of the window
    var windowCanUseHotkeys = new String(); // The menubarstate of the window
    var windowIsDependent   = new String(); // The depend state of the window
    var windowHasDirectories= new String(); // The directories state of the window
	 

	 
	/**
	 * Checking the url for the new window
	 *  If the url is not set - the standart value must beeing defined in the variable "standardWinURL" (top of this document)
	 *
	 */
	 windowURL = (objWindowParams["url"] == null || objWindowParams["url"] == "undefined" || objWindowParams["url"].length <= 1) ? standardWinURL : objWindowParams["url"];
	 //alert("url: "+windowURL);


	/**
	 * Checking the id for the new window
	 * If there is no id - the standart value must beeing defined in the variable "standardWinID" (top of this document)
	 *
	 */
	 windowID = (objWindowParams["id"] == null || objWindowParams["id"] == "undefined" || objWindowParams["id"].length <= 1) ? standardWinID : objWindowParams["id"];
	 //alert("id: "+windowID);
	 
	 
	/**
	 * Checking the xPos state of the new window 
	 * 
	 * If this value is not set - the standart value must beeing defined in the variable "standardWinXPos" (top of this document)
	 *
	 */
	 windowXPos = (objWindowParams["xPos"] != null) ? objWindowParams["xPos"] : standardWinXPos;	
	 //alert("xPos: "+windowXPos);
	 
	 
	/**
	 * Checking the yPos state of the new window 
	 * 
	 * If this value is not set - the standart value must beeing defined in the variable "standardWinYPos" (top of this document)
	 *
	 */
	 windowYPos = (objWindowParams["yPos"] != null) ? objWindowParams["yPos"] : standardWinYPos;		 
	 //alert("yPos: "+windowYPos);
	 
	 
	/**
	 * Checking the width state of the new window 
	 * 
	 * If this value is not set - the standart value must beeing defined in the variable "standardWinWidth" (top of this document)
	 *
	 */
	 var neededWidth = (objWindowParams["width"] != null) ? objWindowParams["width"] : standardWinWidth;
	 neededWidth = (neededWidth > screen.availWidth) ? screen.availWidth : neededWidth;
	 
	 //Check the browser ()
	 switch(getBrowserName()){
		 case "msie":
		 	 windowWidth = (objWindowParams["hasScrollbar"] == "yes") ? (neededWidth+16) : neededWidth;
		 	 break;
		 default:
		 	 windowWidth = (objWindowParams["hasScrollbar"] == "yes") ? (neededWidth+16) : neededWidth;
		 	 break;
	 }//--> end switch
	 //alert("width: "+windowWidth);
	 
	/**
	 * Checking the width state of the new window 
	 * 
	 * If this value is not set - the standart value must beeing defined in the variable "standardWinHeight" (top of this document)
	 *
	 */
	 var neededHeight = (objWindowParams["height"] != null) ? objWindowParams["height"] : standardWinHeight;
	 neededHeight = (neededHeight>screen.availHeight) ? screen.availHeight : neededHeight;
	 
	 //Check the browser ()
	 switch(getBrowserName()){
		 case "msie":
		 	 windowHeight = neededHeight;
		 	 break;
		 default:
		 	 windowHeight = neededHeight+1;
		 	 break;
	 }//--> end switch
	 //alert("height: "+windowHeight);
	 

	/**
	 * Checking the resizeabe state of the new window 
	 *      - "yes" means the window is resizeable
	 *      - "no" means the window is resizeabel
	 * 
	 * If this value is not set - the standart value must beeing defined in the variable "standardWinIsResizeable" (top of this document)
	 *
	 */
	 windowIsResizeable = (objWindowParams["isResizeable"] == "yes" || objWindowParams["isResizeable"] == "no" ) ? objWindowParams["isResizeable"]  : standardWinIsResizeable;
	 //alert("get- isResizeable: "+objWindowParams["isResizeable"]+" - type: "+ typeof objWindowParams["isResizeable"]+"\nset - isResizebale: "+windowIsResizeable);


	/**
	 * Checking the scrollbar state of the new window 
	 *      - "yes" means the window has a scrollbar
	 *      - "no" means the window hasnīt a scrollbar
	 * 
	 * If this value is not set - the standart value must beeing defined in the variable "standardWinHasScrollbar" (top of this document)
	 *
	 */
	 windowHasScrollbar = (objWindowParams["hasScrollbar"] == "yes" || objWindowParams["hasScrollbar"] == "no" ) ? objWindowParams["hasScrollbar"] : standardWinHasScrollbar;
	 //alert("get- hasScrollbar: "+objWindowParams["hasScrollbar"]+" - type: "+ typeof objWindowParams["hasScrollbar"]+"\nset - hasScrollbar: "+windowHasScrollbar);
	 

	/**
	 * Checking the adressline state of the new window 
	 *      - "yes" means the window has an adressline
	 *      - "no" means the window hasnīt an adressline
	 * 
	 * If this value is not set - the standart value must beeing defined in the variable "standardWinHasAdressline" (top of this document)
	 *
	 */
	 windowHasAdressline = (objWindowParams["hasAdressline"] == "yes" || objWindowParams["hasAdressline"] == "no" ) ? objWindowParams["hasAdressline"] : standardWinHasAdressline;
	 //alert("get- hasAdressline: "+objWindowParams["hasAdressline"]+" - type: "+ typeof objWindowParams["hasAdressline"]+"\nset - hasAdressline: "+windowHasAdressline);
	 
	 
	/**
	 * Checking the menubar state of the new window 
	 *      - "yes" means the window has a menubar
	 *      - "no" means the window hasnīt a menubar
	 * 
	 * If this value is not set - the standart value must beeing defined in the variable "standardWinHasMenubar" (top of this document)
	 *
	 */
	 windowHasMenubar = (objWindowParams["hasMenubar"] == "yes" || objWindowParams["hasMenubar"] == "no" ) ? objWindowParams["hasMenubar"] : standardWinHasMenubar;
	 //alert("get- hasMenubar: "+objWindowParams["hasMenubar"]+" - type: "+ typeof objWindowParams["hasMenubar"]+"\nset - hasMenubar: "+windowHasMenubar);
	 
	 
	/**
	 * Checking the toolbar state of the new window 
	 *      - "yes" means the window has a toolbar
	 *      - "no" means the window hasnīt a toolbar
	 * 
	 * If this value is not set - the standart value must beeing defined in the variable "standardWinHasToolbar" (top of this document)
	 *
	 */
	 windowHasToolbar = (objWindowParams["hasToolbar"] == "yes" || objWindowParams["hasToolbar"] == "no" ) ? objWindowParams["hasToolbar"] : standardWinHasToolbar ;
	 //alert("get- hasToolbar: "+objWindowParams["hasToolbar"]+" - type: "+ typeof objWindowParams["hasToolbar"]+"\nset - hasToolbar: "+windowHasToolbar);
	 
	 
	/**
	 * Checking the statusline state of the new window 
	 *      - "yes" means the window has a statusline
	 *      - "no" means the window hasnīt a statusline
	 * 
	 * If this value is not set - the standart value must beeing defined in the variable "standardWinHasStatusline" (top of this document)
	 *
	 */
	 windowHasStatusline = (objWindowParams["hasStatusline"] == "yes" || objWindowParams["hasStatusline"] == "no" ) ? objWindowParams["hasStatusline"] : standardWinHasStatusline;
	 //alert("get- hasStatusline: "+objWindowParams["hasStatusline"]+" - type: "+ typeof objWindowParams["hasStatusline"]+"\nset - hasStatusline: "+windowHasStatusline);
	 
	/**
	 * Checking the hotkeys state of the new window 
	 *      - "yes" means the window can use hotkeys
	 *      - "no" means the window canīt use hotkeys
	 * 
	 * If this value is not set - the standart value must beeing defined in the variable "standardWinHasMenubar" (top of this document)
	 *
	 */
	 windowCanUseHotkeys = (objWindowParams["canUseHotkeys"] == "yes" || objWindowParams["canUseHotkeys"] == "no" ) ? objWindowParams["canUseHotkeys"] : standardWinCanUseHotkeys;
	 //alert("get- canUseHotkeys: "+objWindowParams["canUseHotkeys"]+" - type: "+ typeof objWindowParams["canUseHotkeys"]+"\nset - canUseHotkeys: "+windowCanUseHotkeys);


    /**
	 * Checking the depentend state of the new window 
	 *      - "yes" means the window will be closed if the callerwindow will be closed 
	 *      - "no" means the window stay open if the callerwindow will be closed
	 * 
	 * If this value is not set - the standart value must beeing defined in the variable "standardWinIsDependent" (top of this document)
	 *
	 */
	 windowIsDependent = (objWindowParams["isDependent"] == "yes" || objWindowParams["isDependent"] == "no" ) ? objWindowParams["isDependent"] : standardWinIsDependent;
	 //alert("get- isDependent: "+objWindowParams["isDependent"]+" - type: "+ typeof objWindowParams["isDependent"]+"\nset - isDependent: "+windowIsDependent);
	 
	 

    /**
	 * Checking the directories state of the new window 
	 *      - "yes" means the window has a directoriestate 
	 *      - "no" means the window hasnīt a directoriestate 
	 * 
	 * If this value is not set - the standart value must beeing defined in the variable "standardHasDirectoies" (top of this document)
	 *
	 */
	 windowHasDirectories = (objWindowParams["hasDirectories"] == "yes" || objWindowParams["hasDirectories"] == "no" ) ? objWindowParams["hasDirectories"] : standardWinHasDirectories;
	 //alert("get- hasDirectories: "+objWindowParams["hasDirectories"]+" - type: "+ typeof objWindowParams["hasDirectories"]+"\nset - hasDirectories: "+windowHasDirectories);
	  
	  
	 var windowParams = new String("");
	
	//Different browser different positions and sizes ;-)
	 switch(browserName){
		 case "msie":
		 	 windowParams += "left="+windowXPos;
			 windowParams += ",top="+windowYPos;
		 	 break;
		 default:
		 	 windowParams += "screenX="+windowXPos;
			 windowParams += ",screenY="+windowYPos;
		 	 break;
	 }//--> end switch
	
	 //Setting the other parameters to open the window;
	 windowParams += ", width="+windowWidth;
	 windowParams += ", height="+windowHeight;
	 windowParams += ", resizable="+windowIsResizeable;
	 windowParams += ", scrollbars="+windowHasScrollbar;
	 windowParams += ", location="+windowHasAdressline;
	 windowParams += ", menubar="+windowHasMenubar;
	 windowParams += ", toolbar="+windowHasToolbar;
	 windowParams += ", status="+windowHasStatusline;
	 windowParams += ", hotkeys="+windowCanUseHotkeys;
	 windowParams += ", dependent="+windowIsDependent;
	 windowParams += ", directories="+windowHasDirectories;
	 
	 //Debugmode
	 //alert("window parameters:\n"+windowParams);
	 
	 //Open the newWindow
	 newWindow = window.open(windowURL, windowID, windowParams);
	 
	 //Set the focus to the new windows
	 newWindow.focus();
	
 }//--> end openWinMain 
 
 

//----------------------------------------------------------------------------------------------------



/* 
 *----------------------------------------------------------------------------------------------------
 *
 *           openWinMain (see function above)
 *                |
 *                +-- openWinCentered
 *
 * ----------------------------------------------------------------------------------------------------
 *
 *
 * This function opens an popup window centered
 *
 * @param objWindowParams:Array
 *      |
 *      + ---> ["url"]
 *      |
 *      + ---> ["id"]
 *      |
 *      + ---> ["width"]
 *      |
 *      + ---> ["height"]
 *      |
 *      + ---> ["isResizeable"]
 *      |
 *      + ---> ["hasScrollbar"]
 *      |
 *      + ---> ["hasAdressline"]
 *      |
 *      + ---> ["hasMenubar"]
 *      |
 *      + ---> ["hasToolbar"]
 *      |
 *      + ---> ["hasStatusline"]
 *      |
 *      + ---> ["canUseHotkeys"]
 *      |
 *      + ---> ["isDependent"]
 *      |
 *      + ---> ["hasDirectories"]
 *
 */ 
 function openWinCentered(objWindowParams){

	 var objWindowCenteredParams = new Object();
	 objWindowCenteredParams = objWindowParams;
	 
	 if (screen.width <= 800){
		 if((objWindowCenteredParams["width"] + 10) > screen.availWidth){
			 objWindowCenteredParams["width"] = new Number(screen.availWidth - 10);
		 }//--> end if 
		
		 if((objWindowCenteredParams["height"] + 29) > screen.availHeight){
			 objWindowCenteredParams["height"] = new Number(screen.availHeight - 29);
		 }//--> end if
	 }//--> end if
	
	 objWindowCenteredParams["xPos"] = new Number((screen.availWidth  - objWindowCenteredParams["width"] - 10) / 2);
	 objWindowCenteredParams["yPos"] = new Number((screen.availHeight - objWindowCenteredParams["height"] - 29) / 2);
	 
	 
	 
	 // Now call the function "openWinMain" with the centered xPos and yPos values
	 openWin(objWindowCenteredParams);
	 
 }//--> end openWinCenter()



//----------------------------------------------------------------------------------------------------
  
 



/********************************************************************************
 * EOF
 *******************************************************************************/
