﻿/*

    Document File:  popupscripts.js
    Created By:     Christopher P. Guintu
    Created Date:   11 February 2009
*/

var WorkAreaBase = "/Workarea/";
var menuSize=275;

function PopupWidth()
{
    var width = screen.availWidth * 0.7;
    return width;
}

function PopupHeight()
{
    var height = screen.availHeight * 0.7;
    return height;
}

function TopPosition()
{
    var top = (screen.availHeight - PopupHeight())/2;
    return top;
}

function LeftPosition()
{
    var left = (screen.availWidth - PopupWidth())/2;
    return left;
}

function openPopupPage(url)
{
    var winName = "_blank";
    window.open(url,winName,"toolbar=0,menu=0,address=0,resizable=1,scrollbars=1,status=1,width="+PopupWidth()+",height="+PopupHeight()+",top="+TopPosition()+",left="+LeftPosition());
}

function openPrintPage(url)
{
    var winName = "_print";
    window.open(url,winName,"toolbar=0,menu=0,address=0,resizable=1,scrollbars=1,status=1,width="+PopupWidth()+",height="+PopupHeight()+",top="+TopPosition()+",left="+LeftPosition());
}

function openUserManagement()
{
    var url = WorkAreaBase+"UserManagement.aspx";
    var winName = "_users";
    window.open(url,winName,"toolbar=0,menu=0,address=0,resizable=1,scrollbars=1,status=1,width="+PopupWidth()+",height="+PopupHeight()+",top="+TopPosition()+",left="+LeftPosition());
}

function openRoleManagement()
{
    var url = WorkAreaBase+"RoleManagement.aspx";
    var winName = "_roles";
    window.open(url,winName,"toolbar=0,menu=0,address=0,resizable=1,scrollbars=1,status=1,width="+PopupWidth()+",height="+PopupHeight()+",top="+TopPosition()+",left="+LeftPosition());
}


function openMenuEditor()
{
    var url = WorkAreaBase+"MenuEditor.aspx?parentID=0";
    var winName = "_menuEditor";
    window.open(url,winName,"toolbar=0,menu=0,address=0,resizable=1,scrollbars=1,status=1,width="+PopupWidth()+",height="+PopupHeight()+",top="+TopPosition()+",left="+LeftPosition());
}

function openFolderEditor()
{
    var url = WorkAreaBase+"FolderEditor.aspx?parentID=0";
    var winName = "_folderEditor";
    window.open(url,winName,"toolbar=0,menu=0,address=0,resizable=1,scrollbars=1,status=1,width="+PopupWidth()+",height="+PopupHeight()+",top="+TopPosition()+",left="+LeftPosition());
}

function openContentList()
{
    var url = WorkAreaBase+"ContentList.aspx";
    var winName="_contentList";
    window.open(url,winName,"toolbar=0,menu=0,address=0,resizable=1,scrollbars=1,status=1,width="+PopupWidth()+",height="+PopupHeight()+",top="+TopPosition()+",left="+LeftPosition());
}

function openCollectionEditor()
{
    var url = WorkAreaBase+"CollectionsEditor.aspx";
    var winName="_collectionEditor";
    window.open(url,winName,"toolbar=0,menu=0,address=0,resizable=1,scrollbars=1,status=1,width="+PopupWidth()+",height="+PopupHeight()+",top="+TopPosition()+",left="+LeftPosition());
}

function openCalendar(controlID,withTime,format)
{
    var currentValue = window.document.getElementById(controlID).value;
    //window.opener.document.getElementById(controlID).value;
    var url = "/Popups/Calendar.aspx?controlID="+controlID+"&withTime="+withTime+"&currentValue="+currentValue+"&format="+format;
    var winName = "_calendar";
    window.open(url,winName,"toolbar=0,menu=0,address=0,resizable=1,scrollbars=1,status=1,height=310,width=285,top=200,left=200");    
}

function openContentBrowser(txtID,txtTitle)
{
    var url = WorkAreaBase+"ContentBrowser.aspx?txtID="+txtID+"&txtTitle="+txtTitle;
    var winName = "_contentBrowser";
    window.open(url,winName,"toolbar=0,menu=0,address=0,resizable=1,scrollbars=1,status=1,width="+PopupWidth()+",height="+PopupHeight()+",top="+TopPosition()+",left="+LeftPosition());
}

function openCollectionBrowser(txtID)
{
    var url = WorkAreaBase+"CollectionsBrowser.aspx?txtID="+txtID;
    var winName = "_collectionsBrowser";
    window.open(url,winName,"toolbar=0,menu=0,address=0,resizable=1,scrollbars=1,status=1,width="+PopupWidth()+",height="+PopupHeight()+",top="+TopPosition()+",left="+LeftPosition());
}

function selectCollectionData(txtID,txtValue)
{
    window.opener.document.getElementById(txtID).value=txtValue;
    window.close();
}

function selectContentData(txtID,IDValue,txtTitle,TitleValue)
{
    window.opener.document.getElementById(txtID).value=IDValue;
    window.opener.document.getElementById(txtTitle).value=TitleValue;
    window.close();
}

function selectDate(txtID,txtValue)
{
    window.opener.document.getElementById(txtID).value=txtValue;
    window.close();
}

function openImageBrowser(textUrl,imagePreview)
{
    var url = WorkAreaBase+"ImageBrowser.aspx?textUrl="+textUrl+"&imagePreview="+imagePreview;
    var winName = "_imageBrowser";
    window.open(url,winName,"toolbar=0,menu=0,address=0,resizable=1,scrollbars=1,status=1,width="+PopupWidth()+",height="+PopupHeight()+",top="+TopPosition()+",left="+LeftPosition());
}

function removeDateValue(controlID)
{
    window.document.getElementById(controlID).value="";
}

function removeCollection(controlID)
{
    window.document.getElementById(controlID).value="0";
}

function closeWindow()
{
    window.close();
}


/***********************************************/
/******* scroll and size functions *************/
/***********************************************/
//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.com
//
function getPageScroll(){

	var xScroll, yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}

	arrayPageScroll = new Array(xScroll,yScroll) 
	return arrayPageScroll;
}

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.com
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
//	console.log(self.innerWidth);
//	console.log(document.documentElement.clientWidth);

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// For small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

//	console.log("xScroll " + xScroll)
//	console.log("windowWidth " + windowWidth)

	// For small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
//	console.log("pageWidth " + pageWidth)

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 

	return arrayPageSize;
}

function GetBrowser() 
{
	var agt=navigator.userAgent.toLowerCase();
	if (agt.indexOf("opera") != -1) return 'Opera';
	if (agt.indexOf("staroffice") != -1) return 'Star Office';
	if (agt.indexOf("webtv") != -1) return 'WebTV';
	if (agt.indexOf("beonex") != -1) return 'Beonex';
	if (agt.indexOf("chimera") != -1) return 'Chimera';
	if (agt.indexOf("netpositive") != -1) return 'NetPositive';
	if (agt.indexOf("phoenix") != -1) return 'Phoenix';
	if (agt.indexOf("firefox") != -1) return 'Firefox';
	if (agt.indexOf("safari") != -1) return 'Safari';
	if (agt.indexOf("skipstone") != -1) return 'SkipStone';
	if (agt.indexOf("msie") != -1) return 'Internet Explorer';
	if (agt.indexOf("netscape") != -1) return 'Netscape';
	if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';
	if (agt.indexOf('\/') != -1) {
	if (agt.substr(0,agt.indexOf('\/')) != 'mozilla') {
	return navigator.userAgent.substr(0,agt.indexOf('\/'));}
	else return 'Netscape';} else if (agt.indexOf(' ') != -1)
	return navigator.userAgent.substr(0,agt.indexOf(' '));
	else return navigator.userAgent;
}

//function resizeLeftNavMenuHeight()
//{
//    var pageDim = getPageSize();
//    var div = window.document.getElementById("divExpander");
//    if(div!=null)
//    {
//        var height=(pageDim[1]-menuSize)
//		div.innerHTML="<div style=\"height: "+height+"px\">&nbsp;</div>";//+height.toString()+"\">&nbsp;</div>";
//    }    
//}
