﻿var DocumentSwfUrl = null;
var DocumentID = 0;
var DocumentUrl = null;
var DocumentFilename = null;
var DocumentTitle = null;
var DocumentOwnerUsername = null;
var DocumentCategoryID=0;
var DocumentSubCategoryID=0;
var DocumentSubSubCategoryID=0;
var CurrentUsername =null;
var MinWorkingTime = 500;
var WorkingTimeout = 0;
var _categoryControl = null;
var ReviewLoaded = false;
var RatingID = 0;
var ReviewSubmited= false;
var AddressBook = null;
var DocumentKeyString="";
var PopupRef = null;
var _popWin = null;	
document.addEvent('keyup', handleEsc);
function handleEsc(e)
{
	var keyPressed;
	if (window.event)
	{
		keyPressed = event.keyCode;
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
		keyPressed = e.which;
	}

	if (keyPressed == 27)
	{
	  parent.HidePopup(); 
	}
}
window.addEvent('load', function() {
	InitPopupWin();
});
function InitPopupWin()
{
	//instantiate document window
	_popWin = new DocstocWindow();
	//set properties
	_popWin.title = '';
	_popWin.height = '250px';
	_popWin.width = '700px';
	_popWin.draggable = false;
	_popWin.centered = true;
	_popWin.closeOnEsc = true;
	_popWin.type = 1;
	_popWin.instanceName = '_popWin';
	_popWin.clearContentOnHide = false;
	//initialize our window
	_popWin.init('popWin');
    _popWin.setContent(document.getElementById('embedPop').innerHTML);
    document.getElementById('embedPop').innerHTML = '';
	
}
function EmbedDoc(docID,title,url,ext) {
    // DocumentType = title.substring(title.lastIndexOf('.')+1,title.length);
    DocumentType = ext;
    DocumentID = docID;
    DocumentUrl = url;
    DocumentFilename = title;
    DocumentTitle = title;
    

    DocumentSwfUrl = "http://viewer.docstoc.com/";
	var fullscreenURL = "http://www.docstoc.com/docs/document-preview.aspx?doc_id=" + DocumentID;
	var keyIX = DocumentUrl.indexOf("?key=");
	if (keyIX > 0) {
		DocumentKeyString = DocumentUrl.substring(keyIX + 1);
		fullscreenURL += '&' + DocumentKeyString;
		DocumentSwfUrl += '?' + DocumentKeyString
	}
	$('txtFullScreen').value = fullscreenURL;

	UpdateEmbedURL();
	ShowEmbedPopup('embed');
}

function UpdateEmbedURL(){
	var width = $('txtWidth').value;
	var height = $('txtHeight').value;
	var url = DocumentSwfUrl




    // Alon 5/7/2009 - Due to Google request we're removing this for now
    var promoText ='';
//	var promoText ='Get more ';
//	switch (DocumentCategoryID)
//	{
//		case 1:
//			promoText += '<a href="http://www.docstoc.com/documents/legal/">Legal Forms</a>';
//			break;
//		case 2:
//			promoText += '<a href="http://www.docstoc.com/documents/business/">Business Plans</a>';
//			break;
//		case 3:
//			promoText += '<a href="http://www.docstoc.com/documents/financial/">Free Tax Forms</a>';
//			break;
//		case 4:
//			promoText += '<a href="http://www.docstoc.com/documents/technology/">Information Technology</a>';
//			break;
//		case 5:
//			promoText += '<a href="http://www.docstoc.com/documents/educational/">College Essays</a>';
//			break;
//		case 6:
//			promoText += '<a href="http://www.docstoc.com/documents/creative/">Creative Writing</a>';
//			break;
//		case 8:
//			promoText += '<a href="http://www.docstoc.com/documents/buzz/">Docstoc Buzz</a>';
//			break;
//		default:
//			promoText ='<a href="http://www.docstoc.com/">Free Legal Forms</a>';
//			break;
//	}
	var docType = parent.DocumentType;
	
	if ($('chkPresentation').checked){docType = 'ppt';}
	
	//build flashvars
	if ($('ef_standard').checked)
	{
	    var fv = '<param name="FlashVars" value="doc_id=' + DocumentID + '&mem_id=' + parent.DocumentOwnerID + "&doc_type=" + docType+ "&fullscreen=0";
    } else
    {
	    var fv = 'doc_id=' + DocumentID + '&mem_id=' + parent.DocumentOwnerID + "&doc_type=" + docType + "&fullscreen=0";
	}
	if ($('chkRelated').checked==false){fv+="&showrelated=0";};
	if ($('chkOtherDocs').checked==false){fv+="&showotherdocs=0";};
//	if ($('chkStats').checked==false){fv+="&showstats=0";};
	//fv+='" />'
	
	//$('txtEmbed').value = '<div style="width:'+ width+'px;height:'+ height +'px; position:absolute;"><object id="_ds_' + DocumentID + '" name="_ds_' + DocumentID + '" width="' + width + '" height="' + height + '" style="position:absolute" type="application/x-shockwave-flash" data="' + url + '" style="position:absolute">' + fv + '<param name="movie" value="' + url + '"/><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="true" /></object></div><br /><font size="1"><a href="' + DocumentUrl + '">' + DocumentTitle + '</a> - ' + promoText + '</font>';
	if ($('ef_standard').checked)
	{
	    $('txtEmbed').value = '<object id="_ds_' + DocumentID + '" name="_ds_' + DocumentID + '" width="' + width + '" height="' + height + '" type="application/x-shockwave-flash" data="' + url + '">' + fv + '" /><param name="movie" value="' + url + '"/><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="true" /></object><br /><font size="1"><a href="' + DocumentUrl + '">' + DocumentTitle + '</a> - ' + promoText + '</font>';
    } else
    {
	    $('txtEmbed').value = '<embed id="_ds_' + DocumentID + '" name="_ds_' + DocumentID + '" width="' + width + '" height="' + height + '" type="application/x-shockwave-flash" src="' + url + '" + FlashVars="' + fv + '" allowScriptAccess="always" allowFullScreen="true"></embed><br /><font size="1"><a href="' + DocumentUrl + '">' + DocumentTitle + '</a> - ' + promoText + '</font>';        
    }
}
function ShowEmbedPopup(tab)
{
	if (_popWin == null) InitPopupWin();
	
	_popWin.center();
	_popWin.onClose = function()
	{
		$('blackbg').setStyle('display','none');
	}
	
	//create translucent background	
	DisableScreen('blackbg','#000000','.7');

	$('blackbg').setStyle('display','block');
	//tell popup which tab to set active
	if (PopupRef!=null){PopupRef.SetActiveTab(null,tab)}
	
	_popWin.show();
	
	return false;
}

function HidePopup(){
	_popWin.hide();
}
