﻿var TimeTracker = function(opt_bucket) { if (opt_bucket) { this.bucket_ = opt_bucket.sort(this.sortNumber); } else { this.bucket_ = TimeTracker.DEFAULT_BUCKET; } }; TimeTracker.prototype.startTime_; TimeTracker.prototype.stopTime_; TimeTracker.prototype.bucket_; TimeTracker.DEFAULT_BUCKET = [100, 500, 1500, 2500, 5000]; TimeTracker.prototype._getTimeDiff = function() { return (this.stopTime_ - this.startTime_); }; TimeTracker.prototype.sortNumber = function(a, b) { return (a - b); }; TimeTracker.prototype._recordStartTime = function(opt_time) { if (opt_time != undefined) { this.startTime_ = opt_time; } else { this.startTime_ = (new Date()).getTime(); } }; TimeTracker.prototype._recordEndTime = function(opt_time) { if (opt_time != undefined) { this.stopTime_ = opt_time; } else { this.stopTime_ = (new Date()).getTime(); } }; TimeTracker.prototype._track = function(tracker, opt_event_obj_name, opt_event_label) { var eventTracker; if (opt_event_obj_name != undefined && opt_event_obj_name.length != 0) { eventTracker = tracker._createEventTracker(opt_event_obj_name); } else { eventTracker = tracker._createEventTracker('TimeTracker'); } var i; var bucketString; for (i = 0; i < this.bucket_.length; i++) { if ((this._getTimeDiff()) < this.bucket_[i]) { if (i == 0) { bucketString = "0-" + (this.bucket_[0]); break; } else { bucketString = this.bucket_[i - 1] + "-" + (this.bucket_[i] - 1); break; } } } if (!bucketString) { bucketString = this.bucket_[i - 1] + "+"; } eventTracker._trackEvent(bucketString, opt_event_label, this._getTimeDiff()); }; TimeTracker.prototype._setHistogramBuckets = function(buckets_array) { this.bucket_ = buckets_array.sort(this.sortNumber); };
var timeTracker = new TimeTracker();
timeTracker._recordStartTime();

function DocstocWindow() { var me = this; var _container = null; var _body = null; var _iframe = null; var _imgPath = '/i/popup/'; var _largeTableSettings = { imgTop: _imgPath + 'large/T_Main.png', imgBottom: _imgPath + 'large/B_Main.png', imgRight: _imgPath + 'large/R_Main.png', imgLeft: _imgPath + 'large/L_Main.png', imgTopLeft: _imgPath + 'large/TL_Main.png', imgTopRight: _imgPath + 'large/TR_Main.png', imgBottomLeft: _imgPath + 'large/BL_Main.png', imgBottomRight: _imgPath + 'large/BR_Main.png', imgCloseButton: _imgPath + 'large/btn_close.gif', widthTopLeft: '26px', widthTopRight: '30px', widthLeft: '26px', widthRight: '30px', widthBottomLeft: '26px', widthBottomRight: '30px', widthCloseButton: '13px', heightTopLeft: '43px', heightTop: '43px', heightTopRight: '43px', heightBottomLeft: '32px', heightBottom: '32px', heightBottomRight: '32px', heightCloseButton: '15px', topCloseButton: '10px', rightCloseButton: '20px', rightToolTip: '34px' }; var _smallTableSettings = { imgTop: _imgPath + 'small/s_T_main2.png', imgBottom: _imgPath + 'small/s_B_main2.png', imgRight: _imgPath + 'small/s_R_main2.png', imgLeft: _imgPath + 'small/s_L_main2.png', imgTopLeft: _imgPath + 'small/s_TL_main2.png', imgTopRight: _imgPath + 'small/s_TR_main2.png', imgBottomLeft: _imgPath + 'small/s_BL_main2.png', imgBottomRight: _imgPath + 'small/s_BR_main2.png', imgCloseButton: _imgPath + 'small/btn_close2.gif', widthTopLeft: '18px', widthTopRight: '19px', widthLeft: '18px', widthRight: '19px', widthBottomLeft: '18px', widthBottomRight: '19px', widthCloseButton: '20px', heightTopLeft: '28px', heightTop: '28px', heightTopRight: '28px', heightBottomLeft: '19px', heightBottom: '19px', heightBottomRight: '19px', heightCloseButton: '20px', topCloseButton: '5px', rightCloseButton: '5px', rightToolTip: '34px' }; var _browserName = navigator.appName; var _browserVer = new String(navigator.appVersion); var _bodyScrollLeft = 0; var _bodyScrollTop = 0; var _bodyScrollWidth = 0; var _bodyScrollHeight = 0; var _trueHeight = '400px'; var _smallClickMessage = 'esc or '; var _largeClickMessage = 'press escape or click button to close'; this.title = 'New Window'; this.draggable = true; this.width = '400px'; this.height = '400px'; this.top = '20px'; this.left = '20px'; this.zindex = '1000'; this.centered = true; this.closeOnEsc = true; this.type = 1; this.formId = null; this.clearContentOnHide = true; this.preserveContent = false; this.scrollBars = false; this.instanceName = null; this.contentOwnerElement = null; this.divId = null; this.onClose = function() { }; this.displayCloseButton = true; this.init = function(divId) { me.divId = divId; me.setBodyScrolls(); _container = document.createElement('div'); _container.setAttribute('id', divId); _container.setAttribute('style', ''); _container.style.position = 'absolute'; _container.style.visibility = 'hidden'; _container.style.width = me.width; _container.style.top = me.top; _container.style.left = me.left; _container.style.zIndex = me.zindex; var table = ""; switch (me.type) { case 0: table = me.getTable(divId, _largeTableSettings); break; case 1: table = me.getTable(divId, _smallTableSettings); break; } _container.innerHTML = table; if ((_browserName == "Microsoft Internet Explorer") && (_browserVer.indexOf("MSIE 6.0") >= 0)) { var myIFrame = document.createElement('iframe'); myIFrame.setAttribute('id', divId + '_iframe'); myIFrame.setAttribute('src', "javascript:false;"); myIFrame.setAttribute('frameborder', '0'); myIFrame.setAttribute('style', ''); myIFrame.style.position = 'absolute'; myIFrame.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)'; myIFrame.style.zIndex = me.zindex - 1; myIFrame.style.width = me.width; myIFrame.style.height = _trueHeight; myIFrame.style.top = me.top; myIFrame.style.left = me.left; document.body.appendChild(myIFrame); _iframe = document.getElementById(divId + '_iframe'); _iframe.style.visibility = 'visible'; } if (me.formId != null) { document.getElementById(me.formId).appendChild(_container); } else { document.body.appendChild(_container); } _body = document.getElementById(divId + '_docWinBody'); if (me.draggable) Drag.init(_container, null, _bodyScrollLeft, _bodyScrollLeft + _bodyScrollWidth, _bodyScrollTop, _bodyScrollTop + _bodyScrollHeight); if (me.centered) me.center(); if (me.closeOnEsc) me.registerAsKeyListener(); }, this.getTable = function(divId, settings) { _trueHeight = (parseInt(me.height) + parseInt(settings.heightTop) + parseInt(settings.heightBottom) + 10) + 'px'; var bodyWidth = (parseInt(me.width) - parseInt(settings.widthLeft) - parseInt(settings.widthRight)) + 'px'; var cursorStyle = ''; if (me.draggable) cursorStyle = 'cursor:move;'; var clickMessage = ''; if (parseInt(me.width) > 200) { clickMessage = _largeClickMessage; } else { clickMessage = _smallClickMessage; } var closeOnMouseOver = "javascript:document.getElementById(\"" + divId + "_docWinToolTip\").style.visibility=\"visible\";"; var closeOnMouseOut = "javascript:document.getElementById(\"" + divId + "_docWinToolTip\").style.visibility=\"hidden\";"; var closeOnClick = "document.getElementById(\"" + divId + "\").style.visibility=\"hidden\";"; if (me.instanceName != null) closeOnClick = 'javascript:' + me.instanceName + '.hide();'; closeTxt = 'Close'; if (this.displayCloseButton == false) { settings.imgCloseButton = ""; closeOnMouseOver = ""; closeOnMouseOut = ""; closeTxt = ""; } var table = "<table border='0' cellpadding='0' cellspacing='0' style='width:" + me.width + ";'>" + "<tr>" + "<td style='width:" + settings.widthTopLeft + ";height: " + settings.heightTopLeft + ";" + "background:transparent " + me.getImageStyleString(settings.imgTopLeft) + ";" + cursorStyle + "'></td>" + "<td style='background:transparent " + me.getImageStyleString(settings.imgTop) + ";" + "height:" + settings.heightTop + ";" + cursorStyle + "' valign='bottom' align='center'>" + me.title + "<div id='" + divId + "_docWinToolTip' style='display:none;position:absolute;visibility:hidden;" + "top:" + settings.topCloseButton + ";right:" + settings.rightToolTip + ";background:transparent;color:#FFFFFF;'>" + clickMessage + "</div>" + "<div style='font-size:12px;padding:3px 37px 0 0;-padding-right:23px;font-weight:bold;position:absolute;top:" + settings.topCloseButton + ";right:" + settings.rightCloseButton + ";" + "width:" + settings.widthCloseButton + ";height:" + settings.heightCloseButton + ";" + "background-image:url(" + settings.imgCloseButton + ");background-position:right top;background-repeat: no-repeat;cursor:default;' " + "onclick='" + closeOnClick + "' " + "onmouseover='" + closeOnMouseOver + "' " + "onmouseout='" + closeOnMouseOut + "'>" + closeTxt + "</div>" + "</td>" + "<td style='width:" + settings.widthTopRight + ";height: " + settings.heightTopRight + ";" + "background:transparent " + me.getImageStyleString(settings.imgTopRight) + ";" + cursorStyle + "'></td>" + "</tr>" + "<tr>" + "<td style='width:" + settings.widthLeft + ";" + "background: transparent repeat-y " + me.getImageStyleString(settings.imgLeft) + ";'></td>" + "<td style='background-color:#FFFFFF;'>" + "<div id='" + divId + "_docWinBody' style='height:" + me.height + ";width:" + bodyWidth + ";background:#d5d5d5'></div>" + "</td>" + "<td style='width:" + settings.widthRight + ";" + "background:transparent repeat-y top right " + me.getImageStyleString(settings.imgRight) + ";'></td>" + "</tr>" + "<tr>" + "<td style='width:" + settings.widthBottomLeft + ";height: " + settings.heightBottomLeft + ";" + "background:transparent " + me.getImageStyleString(settings.imgBottomLeft) + ";'></td>" + "<td style='background:transparent " + me.getImageStyleString(settings.imgBottom) + ";" + "height:" + settings.heightBottom + ";' valign='bottom'></td>" + "<td style='width:" + settings.widthBottomRight + ";height: " + settings.heightBottomRight + ";" + "background:transparent " + me.getImageStyleString(settings.imgBottomRight) + ";'></td>" + "</tr>" + "</table>"; return table; }, this.getImageStyleString = function(imgSrc) { var imgStyleString = ""; if ((_browserName == "Microsoft Internet Explorer") && (_browserVer.indexOf("MSIE 6.0") >= 0)) { imgStyleString = ';filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + imgSrc + '",sizingMethod="scale")'; } else { imgStyleString = "url(" + imgSrc + ")"; } return imgStyleString; }, this.destroy = function() { document.body.removeChild(_container); if (_iframe != null) document.body.removeChild(_iframe); }, this.registerAsKeyListener = function() { if (document.attachEvent) { document.attachEvent('onkeyup', me.onKeyPress); } else { document.addEventListener('keyup', me.onKeyPress, true); } }, this.onKeyPress = function(e) { var keyPressed; if (window.event) { keyPressed = event.keyCode; } else if (e.which) { keyPressed = e.which; } if (keyPressed == 27) { me.hide(); } }, this.setContent = function(content) { if (content.substr(0, 7) == "<OBJECT") content = "<div style='height:0px;width:0px;'> </div>" + content; _body.innerHTML = content; }, this.setContentOwner = function(el) { me.contentOwnerElement = el; }, this.getContent = function() { return _body.innerHTML; }, this.setUrl = function(url) { var scrollText = "scrolling='auto'"; if (!me.scrollBars) scrollText = "scrolling='no'"; var iframe = "<iframe width='100%' height='100%' src='" + url + "' border='0' frameborder='0' " + scrollText + "></iframe>"; _body.innerHTML = iframe; }, this.setAjaxContent = function(action, url, data) { var oAjax = new AjaxObject101(); oAjax.returnXml = false; oAjax.funcDone = me.OnAjaxReturn; oAjax.sndReq(action, url, data); }, this.OnAjaxReturn = function(data) { me.setContent(data); }, this.show = function() { me.setBodyScrolls(); if (me.centered) me.center(); _container.style.visibility = 'visible'; if (_iframe != null) _iframe.style.visibility = 'visible'; }, this.hide = function() { _container.style.visibility = 'hidden'; document.getElementById(me.divId + "_docWinToolTip").style.visibility = "hidden"; if (_iframe != null) _iframe.style.visibility = 'hidden'; if (me.preserveContent && me.contentOwnerElement != null) { me.contentOwnerElement.innerHTML = me.getContent(); } if (me.clearContentOnHide) me.setContent(''); me.onClose(); }, this.center = function() { _container.style.left = "50%"; _container.style.top = "50%"; var newLeft = _container.offsetLeft; newLeft = (newLeft - _container.offsetWidth / 2) + _bodyScrollLeft; if (newLeft <= 0) newLeft = 1; if (newLeft < _bodyScrollLeft) newLeft = _bodyScrollLeft; newLeft = parseInt(newLeft); newLeft = newLeft.toString() + 'px'; _container.style.left = newLeft; if (_iframe != null) _iframe.style.left = newLeft; var newTop = _container.offsetTop; newTop = (newTop - _container.offsetHeight / 2) + _bodyScrollTop; if (newTop <= 0) newTop = 1; if (newTop < _bodyScrollTop) newTop = _bodyScrollTop; newTop = parseInt(newTop); newTop = newTop.toString() + 'px'; _container.style.top = newTop; if (_iframe != null) _iframe.style.top = newTop; }, this.setLocation = function(top, left) { _container.style.left = left; _container.style.top = top; }, this.setLocationByElement = function(elementId, position) { var top = elementId.offsetTop; var left = elementId.offsetLeft; var offsetParent = elementId.offsetParent; while (offsetParent != null && offsetParent.tagName != 'BODY') { top += offsetParent.offsetTop; left += offsetParent.offsetLeft; offsetParent = offsetParent.offsetParent; } switch (position) { case 'top': top -= parseInt(me.height); break; case 'bottom': top += elementId.offsetHeight; break; case 'left': left -= parseInt(me.width); break; case 'right': left += elementId.offsetWidth; break; } me.setLocation(top + 'px', left + 'px'); }, this.setBodyScrolls = function() { if (_browserVer.indexOf("Safari") != -1) { _bodyScrollLeft = document.body.scrollLeft; _bodyScrollTop = document.body.scrollTop; _bodyScrollWidth = document.body.scrollWidth; _bodyScrollHeight = document.body.scrollHeight; return; } _bodyScrollLeft = document.documentElement.scrollLeft; _bodyScrollTop = document.documentElement.scrollTop; _bodyScrollWidth = document.documentElement.scrollWidth; _bodyScrollHeight = document.documentElement.scrollHeight; return; }; var Drag = { obj: null, init: function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper) { o.onmousedown = Drag.start; o.hmode = bSwapHorzRef ? false : true; o.vmode = bSwapVertRef ? false : true; o.root = oRoot && oRoot != null ? oRoot : o; if (o.hmode && isNaN(parseInt(o.root.style.left))) o.root.style.left = "0px"; if (o.vmode && isNaN(parseInt(o.root.style.top))) o.root.style.top = "0px"; if (!o.hmode && isNaN(parseInt(o.root.style.right))) o.root.style.right = "0px"; if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px"; o.minX = typeof minX != 'undefined' ? minX : null; o.minY = typeof minY != 'undefined' ? minY : null; o.maxX = typeof maxX != 'undefined' ? maxX : null; o.maxY = typeof maxY != 'undefined' ? maxY : null; o.xMapper = fXMapper ? fXMapper : null; o.yMapper = fYMapper ? fYMapper : null; o.root.onDragStart = new Function(); o.root.onDragEnd = new Function(); o.root.onDrag = new Function(); }, start: function(e) { var o = Drag.obj = this; e = Drag.fixE(e); var y = parseInt(o.vmode ? o.root.style.top : o.root.style.bottom); var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right); o.root.onDragStart(x, y); o.lastMouseX = e.clientX; o.lastMouseY = e.clientY; if (o.hmode) { if (o.minX != null) o.minMouseX = e.clientX - x + o.minX; if (o.maxX != null) o.maxMouseX = o.minMouseX + o.maxX - o.minX; } else { if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x; if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x; } if (o.vmode) { if (o.minY != null) o.minMouseY = e.clientY - y + o.minY; if (o.maxY != null) o.maxMouseY = o.minMouseY + o.maxY - o.minY; } else { if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y; if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y; } document.onmousemove = Drag.drag; document.onmouseup = Drag.end; return false; }, drag: function(e) { e = Drag.fixE(e); var o = Drag.obj; var ey = e.clientY; var ex = e.clientX; var y = parseInt(o.vmode ? o.root.style.top : o.root.style.bottom); var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right); var nx, ny; if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX); if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX); if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY); if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY); nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1)); ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1)); if (o.xMapper) { nx = o.xMapper(y); } else if (o.yMapper) { ny = o.yMapper(x); } Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px"; Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px"; Drag.obj.lastMouseX = ex; Drag.obj.lastMouseY = ey; Drag.obj.root.onDrag(nx, ny); return false; }, end: function() { document.onmousemove = null; document.onmouseup = null; Drag.obj.root.onDragEnd(parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"])); Drag.obj = null; }, fixE: function(e) { if (typeof e == 'undefined') e = window.event; if (typeof e.layerX == 'undefined') e.layerX = e.offsetX; if (typeof e.layerY == 'undefined') e.layerY = e.offsetY; return e; } }; }





/* global declartions */
var formPrefix = 'ctl00_ContentPlaceHolder1_'

window.ie6 = navigator.userAgent.toLowerCase().indexOf('msie 6') != -1;

//set up the onkeyup event
document.onkeyup = handleEsc;

var _docWin = null;
var _folderWin = null;
var _inviteWin = null;
var _genWin = null;
var InsideStartDelay = false;
var OkToDisplay = false;
var StartDelay = 1000;
var currentDocId = 0;
var take=false;
var wndAddToFolder;
var _adminUpdateDocWin = null;
var _adimDelDocWin = null;
var _liveChatWin = null;
var _chatWin = null;

function ShowAdminDelDocWin(docId)
{
	if (_adimDelDocWin == null)
	{
		//instantiate window
		_adimDelDocWin = new DocstocWindow();
		//set properties
		_adimDelDocWin.title = '';
		_adimDelDocWin.height = '200px';
		_adimDelDocWin.width = '400px';
		_adimDelDocWin.draggable = true;
		_adimDelDocWin.centered = true;
		_adimDelDocWin.instanceName = '_adimDelDocWin';
		//initialize our window
		_adimDelDocWin.init('adimDelDocWin');
		_adimDelDocWin.onClose = function()
								{
									if ($('flashContainerParent')!=undefined){
										$('blackbg').setStyle('display','none');
									}
								}
		
		//create translucent background	
		DisableScreen('blackbg','#000000','.7');

	}
	if ($('flashContainerParent')!=undefined){
		$('blackbg').setStyle('display','block');
	}
	
	_adimDelDocWin.setUrl("/Docs/DeleteDoc.aspx?doc_id=" + docId);
	_adimDelDocWin.show();
}

function InitGenWin()
{
	//instantiate document window
	_genWin = new DocstocWindow();
	//set properties
	_genWin.title = '';
	_genWin.height = '50px';
	_genWin.width = '300px';
	_genWin.draggable = false;
	_genWin.centered = true;
	_genWin.instanceName = '_genWin';
	//initialize our window
	_genWin.init('genWin');
}

function ShowGenWin(text)
{
	//initialize the window if it hasn't yet been
	if (_genWin == null) InitGenWin();
	
	//set content
	_genWin.setContent("<div style='vertical-align:middle;text-align:center;'>" + text + "</div>");
	_genWin.show();
}

function closePopupWindow()
{
  if (_docWin != null) _docWin.hide();
  if (_folderWin != null) _folderWin.hide();
  if (_inviteWin != null) _inviteWin.hide();
}

function InitDocWin()
{
	//instantiate document window
	_docWin = new DocstocWindow();
	//set properties
	_docWin.title = '';
	_docWin.height = '500px';
	_docWin.width = '900px';
	_docWin.draggable = true;
	_docWin.centered = true;
	_docWin.instanceName = '_docWin';
	//initialize our window
	_docWin.init('docWin');
}

function InitFolderWin()
{
	//instantiate document window
	_folderWin = new DocstocWindow();
	//set properties
	_folderWin.title = '';
	_folderWin.height = '300px';
	_folderWin.width = '416px';
	_folderWin.draggable = false;
	_folderWin.centered = false;
	_folderWin.type = 1;
	_folderWin.instanceName = '_folderWin';
	_folderWin.clearContentOnHide = false;
	//initialize our window
	_folderWin.init('folderWin');
}

function InitInviteWin()
{
	//instantiate document window
	_inviteWin = new DocstocWindow();
	//set properties
	_inviteWin.title = '';
	_inviteWin.height = '358px';
	_inviteWin.width = '430px';
	_inviteWin.draggable = true;
	_inviteWin.centered = true;
	_inviteWin.instanceName = '_inviteWin';
	//initialize our window
	_inviteWin.init('inviteWin');
}


function handleEsc(e)
{
    var keyPressed;
    if (window.event) // IE
    {
        keyPressed = event.keyCode;
    }
    else if(e.which) // Netscape/Firefox/Opera
    {
        keyPressed = e.which;
    }
    
    if (keyPressed == 27)
    {
        closePopupWindow(); 
    }
}

function ShowAdminUpdateDocument(docId)
{
	if (_adminUpdateDocWin == null)
	{
		_adminUpdateDocWin = new DocstocWindow();
		//set properties
		_adminUpdateDocWin.title = '';
		_adminUpdateDocWin.height = '225px';
		_adminUpdateDocWin.width = '500px';
		_adminUpdateDocWin.draggable = true;
		_adminUpdateDocWin.centered = true;
		_adminUpdateDocWin.closeOnEsc = true;
		_adminUpdateDocWin.type = 1;
		_adminUpdateDocWin.instanceName = '_adminUpdateDocWin';
		//initialize our window
		_adminUpdateDocWin.init('adminUpdateDocWin');
		_adminUpdateDocWin.onClose = function()
								{
									//if ($('flashContainerParent')!=undefined){
										$('blackbg').setStyle('display','none');
									//}
								}
		
		//create translucent background	
		DisableScreen('blackbg','#000000','.7');
	}
	//if ($('flashContainerParent')!=undefined){
		$('blackbg').setStyle('display','block');
	//}
	_adminUpdateDocWin.setUrl("/Docs/Document-Edit.aspx?doc_id=" + docId);
	_adminUpdateDocWin.show();
}

function showDocWindow(docId,filename)
{
	OkToDisplay = false;
    this.MyTimer = setTimeout("openPopup('"+docId+"','"+escape(filename)+"')", StartDelay);
	InsideStartDelay = true;
}
function previewDoc(docId)
{
	openPopup(docId,null);
}

function cancelDocWindow() 
{
    clearTimeout(this.MyTimer);    
    InsideStartDelay = false;
    OkToDisplay = true;        
}

function openPopup(docId,filename) 
{
	try 
	{
		clearTimeout(this.MyTimer);

		if(_docWin != null) { _docWin.destroy(); _docWin = null; }
		InitDocWin();

		if (docId == 0)
		{
			_docWin.setUrl(filename);
		}
		else
		{
			_docWin.setUrl('/docs/Document-QuickView.aspx?doc_id=' + docId);
		}

		_docWin.show();

		InsideStartDelay = false;
		OkToDisplay = true;
	}
	catch(e)
	{
		alert(e.message);
		InsideStartDelay = false;
		OkToDisplay = true;
	}
}

function findPos(obj) 
{
	var curleft = curtop = 0;

	if (obj.offsetParent) 
	{
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
	
		while (obj = obj.offsetParent) 
		{
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
	}
	return [curleft,curtop];
}

function hideFolderTreeWindow()
{
	_folderWin.hide();
	return false;
}

function openFolderTreeWindow(docId, evt) 
{
	var elem = evt.target || event.srcElement;
	currentDocId = docId;    
	var coor = findPos(elem);

	try 
	{
		if (_folderWin == null) InitFolderWin();
		
		_folderWin.setUrl("/FolderTreeWindow.aspx?docid=" + docId);
		var posLeft= coor[0]-380;
		if (posLeft<0){posLeft=coor[0];};
		_folderWin.setLocation(coor[1]+15 + "px", posLeft + "px");
		_folderWin.show();
		
		InsideStartDelay = false;
		OkToDisplay = true;
		window.scrollTo(0,coor[1]);
	}
	catch(e)
	{
		alert(e);
		InsideStartDelay = false;
		OkToDisplay = true;
	}
	return false;
}

//open invite to docstoc beta form
function openPop() 
{
	try 
	{
		var contentUrl = document.getElementById('hurl').value;
		
		if (_inviteWin == null) InitInviteWin();
		
		_inviteWin.setUrl(contentUrl);
		_inviteWin.center();
		_inviteWin.show();
		
		InsideStartDelay = false;
		OkToDisplay = true;
	}
	catch(e)
	{
		alert(e);
		InsideStartDelay = false;
		OkToDisplay = true;
	}
}

function defaultbutton(e,objID, isAjax){
	var keyPressed;
	var isFF = false;
    
    if (isAjax=='undefined' || isAjax==null){isAjax=true;}
    
	if (window.event) // IE
	{
		keyPressed = event.keyCode;
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
		keyPressed = e.which;
		isFF = true;
	}
	
	if (keyPressed == 13)
	{
	    var obj = $(objID);
	    if (obj.type=='image' && isFF==true && isAjax==true){
	        //hack for imagebuttons
	        var nameX = obj.name + '.x';
	        var nameY = obj.name + '.y';

            if ($(nameX) ==null || $(nameX) =='undefined'){
                var clickX = document.createElement("input");
                clickX.type = 'hidden';
                clickX.value = '10';
                clickX.name = nameX;
                clickX.id = nameX;
                theForm.appendChild(clickX);
            }
            if ($(nameY) ==null || $(nameY) =='undefined'){
                var clickY = document.createElement("input");
                clickY.type = 'hidden';
                clickY.value = '10';
                clickY.name = nameY;
                clickY.id = nameY;
                theForm.appendChild(clickY);
            }
	    }
        //do the click
        try{obj.click();}catch(e){}

	    return false;
	}
	return true;
}
function KeyDownHandler(btn)    
{  
    // process only the Enter key
    if (event.keyCode == 13) 
    {
        // cancel the default submit
        event.returnValue=true;
        event.cancel = false;
        // submit the form by programmatically clicking the specified button
        btn.click();  
    }
}
function setCookie(name,value,days){
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}


function handleSearchEnter(e,type)
{
    return handleEnter(e,doSearch,type)
}

function handleRequestEnter(e,type)
{
	 return handleEnter(e,doRequest,type)
}

function handleEnter(e, func,arg1)
{
	
	var keyPressed;

	if (window.event) // IE
	{
		keyPressed = event.keyCode;
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
		keyPressed = e.which;
	}
	if (keyPressed == 13)
	{
        e = e || window.event;	
	    targ = e.target || e.srcElement;   
		func(arg1,targ);
	    return false;
	}
	return true;
}
function doSearchHomepage(type){
	return  doSearch(type,'txtSearchDocuments');
}
function doSearch(type, altCntrl){
	var txtCntrl = $('txtSearch');
	if(altCntrl)
	{
		txtCntrl = $(altCntrl);
	}
	var q=escape(txtCntrl.value.replace(/-/g,"--").replace(/ /g,"-"));
	
	if (type=='blog'){
		window.location.href = '/blogs/browseblog.aspx?txtsearch=' + q;
	}else if(type=='store')
	{
	    window.location.href = '/store/search/'+q+'/';
	
	}else{
		window.location.href = '/search/' + q + '/?catfilter=1';
	}
    
}

function doRequest(type, control)
{
	txtCntrl = $(control);
	var q=escape(txtCntrl.value);
	window.location.href ='/handlers/StatTracker.ashx?statisticType=Requests&activityType='+type+'&url=/requests/'+q+'/';
}
function doCategorySearch(){
	var q=escape($('txtSearchWithinCat').value.replace(/-/g,"--").replace(/ /g,"-"));
	window.location.href = '/search/' + q + '/?catID=' + CategoryID + '&subcatID=' + SubCategoryID + '&subsubCID=' + SubSubCategoryID;   
}
//clears the value of the search box if the content is 'search all docs'
function clearValue(el)
{
    if (el.valueCleared){return}
    el.value = "";
    el.valueCleared =true;
}
function clearSearch(el)
{
	if (el.value.indexOf('search all')>-1){el.value = "";}
}		

function SetLanguage(ltype,displayLang)
{
	setCookie("langType",ltype);
	setCookie("displayLang",Base64.encode(displayLang));
	window.location.reload();
	return false;
}
function SetDocType(dtype)
{
	if (dtype=='-1'){dtype="";}
	setCookie("docType",dtype);
	window.location.reload();
	return false;
}
function setItemsPerPage(value){
    setCookie("pageSize",value,3650);
    window.location.reload();
}
function initScrollLayer() {

  // arguments: id of layer containing scrolling layers (clipped layer), id of layer to scroll, 
  // if horizontal scrolling, id of element containing scrolling content (table?)
  var wndo = new dw_scrollObj('wnch', 'lyr1');

  // bSizeDragBar set true by default (explained at www.dyn-web.com/dhtml/scroll/ )
  // wndo.bSizeDragBar = false;
  
  // arguments: dragBar id, track id, axis ("v" or "h"), x offset, y offset
  // (x/y offsets of dragBar in track)
  wndo.setUpScrollbar("dragBarch", "trackch", "v", 1, 1);
  
  // pass id('s) of scroll area(s) if inside table(s)
  // i.e., if you have 3 (with id's wn1, wn2, wn3): dw_scrollObj.GeckoTableBugFix('wn1', 'wn2', 'wn3');
  dw_scrollObj.GeckoTableBugFix('wnch'); 
}

//removes flashing images on the onmouseover command
try{document.execCommand("BackgroundImageCache",false,true);}catch(e){}

function gotoProfile(){ShowGenWin('You need to log in to see your profile!');}

function isValidateEmail(email)
{
	var exp=/^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@(([0-9a-zA-Z])+([-\w]*[0-9a-zA-Z])*\.)+[a-zA-Z]{2,9})$/;
	if (exp.test(email))
	{ 
		return true;
	}
	return false;
}


function AttachScript(url) {
    var head = document.getElementsByTagName('head').item(0);
    var js = document.createElement('script');
    js.setAttribute('language', 'javascript');
    js.setAttribute('type', 'text/javascript');
    js.setAttribute('src', url);
    head.appendChild(js);
    return false;
}

function changeParentUrl(url)
{
	window.location.href = url;
}

function ShowChatPopup() {
	if (_chatWin == null) {
		//instantiate document window
		_chatWin = new DocstocWindow();
		//set properties
		_chatWin.title = '';
		_chatWin.height = '300px';
		_chatWin.width = '245px';
		_chatWin.draggable = true;
		_chatWin.centered = true;
		_chatWin.closeOnEsc = true;
		_chatWin.type = 1;
		_chatWin.instanceName = '_chatWin';
		_chatWin.clearContentOnHide = false;
		//initialize our window
		_chatWin.init('chatWin');
		_chatWin.setUrl("/Purchase/purchase-popup.aspx");
		_chatWin.center();
	}
	_chatWin.show();
	return false;
}
