var enableCache = false;
var jsCache = new Array();
var AjaxObjects = new Array();
var Images;
var ImageIndex = 0;
var playSlideShow = 0;
var slideshowLap = 3000;
var noofImages;
var sMoveTo;
var networkId = '';
var frompathShare = '';
var iteration = '';
var sBackUrl = '';
var imageFilePattern = "bmp|gif|jpg|jpeg|png|ico";
var windowsMediaFilePattern = "asf|wma|avi|mp3|mp2|mpa|mid|midi|rmi|aif|aifc|aiff|au|snd|wav|cda|wmv|wm|dvr'-'ms|mpe|mpeg|mpg|m1v|vob";
var realMediaFilePattern = "rm|ra|ram|rt|rp|mp3|swf|smil|smi|mpg|mpeg|mid|midi|rmi";
var quicktimeMediaFilePattern = "mov|mpeg'-'1|mpeg'-'2|mpeg'-'4|3gpp|3gpp2|avi|mqv";
var flashMediaFilePattern = "swf|flv|fla";
var documentFilePattern = "doc|txt|pdf|xls|xlsx|docx|ppt";
var maxImageWidth = 25;
var maxImageHeight = 25;
var displayWidth = 425;
var displayHeight = 350;
var maxColumnsEmbeds = 4;
var columnsEmbeds = 0;
var rowsEmbeds = 0;
var boolPreview = false;
var noOfImages = 0;
var ns4 = document.layers;
var op5 = (navigator.userAgent.indexOf("Opera 5")!=-1) ||(navigator.userAgent.indexOf("Opera/5")!=-1);
var op6 = (navigator.userAgent.indexOf("Opera 6")!=-1) ||(navigator.userAgent.indexOf("Opera/6")!=-1);
var agt=navigator.userAgent.toLowerCase();
var mac = (agt.indexOf("mac")!=-1);
var ie = (agt.indexOf("msie") != -1); 
var mac_ie = mac && ie;
var thumbnailWidth = 25;
var thumbnailHeight = 25;
var currentDisplayingEmbed = 0;
var isYouTube_embed = 0;
var isPBimages = 0;
var isPBvideos = 0;
var isEmbedsFromCSO = 0;
var totalEmbeds = 0;
var isPBimages = 0;
var isPBvideos = 0;
var MAX_IMAGES = 20;
var MAX_DOCUMENTS = 5;
var MAX_AUDIOVIDEO = 5;
var MAX_TOTAL = 30;

//------------------------------------------- Plug-in detector -----------------------------------------------------------
var agt=navigator.userAgent.toLowerCase();
var ie  = (agt.indexOf("msie") != -1);
var ns  = (navigator.appName.indexOf("Netscape") != -1);
var win = ((agt.indexOf("win")!=-1) || (agt.indexOf("32bit")!=-1));
var mac = (agt.indexOf("mac")!=-1);

if (ie && win) {	pluginlist = detectIE("Adobe.SVGCtl","SVG Viewer") + detectIE("SWCtl.SWCtl.1","Shockwave Director") + detectIE("ShockwaveFlash.ShockwaveFlash.1","Shockwave Flash") + detectIE("rmocx.RealPlayer G2 Control.1","RealPlayer") + detectIE("QuickTimeCheckObject.QuickTimeCheck.1","QuickTime") + detectIE("MediaPlayer.MediaPlayer.1","Windows Media Player") + detectIE("PDF.PdfCtrl.5","Acrobat Reader"); }
if (ns || !win) {
		nse = ""; for (var i=0;i<navigator.mimeTypes.length;i++) nse += navigator.mimeTypes[i].type.toLowerCase();
		pluginlist = detectNS("image/svg-xml","SVG Viewer") + detectNS("application/x-director","Shockwave Director") + detectNS("application/x-shockwave-flash","Shockwave Flash") + detectNS("audio/x-pn-realaudio-plugin","RealPlayer") + detectNS("video/quicktime","QuickTime") + detectNS("application/x-mplayer2","Windows Media Player") + detectNS("application/pdf","Acrobat Reader");
}

function detectIE(ClassID,name) { result = false; document.write('<SCRIPT LANGUAGE=VBScript>\n on error resume next \n result = IsObject(CreateObject("' + ClassID + '"))</SCRIPT>\n'); if (result) return name+','; else return ''; }
function detectNS(ClassID,name) { n = ""; if (nse.indexOf(ClassID) != -1) if (navigator.mimeTypes[ClassID].enabledPlugin != null) n = name+","; return n; }

pluginlist += navigator.javaEnabled() ? "Java," : "";
if (pluginlist.length > 0) pluginlist = pluginlist.substring(0,pluginlist.length-1);

//------------------------------------------- Plug-in detector -----------------------------------------------------------

//------------------------------------------- web path to make video and audio streams compatible with all browsers -------------------------------------
function GetResourceBasePath()
{
	var url = window.location.href.toLowerCase();

	csoBasePath = url.substring(0, url.indexOf("codr")-1);

	if(csoBasePath.lastIndexOf("/") == csoBasePath.length-1)
	{
		csoBasePath = csoBasePath.substring(0, csoBasePath.lastIndexOf("/"));
	}
	return csoBasePath;
}
//----------------------------------------------------------------------------------------------------------------------------------------------------------------------

function SetTheBrowser(iIndex)
{
    var response = AjaxObjects[iIndex].response;

	if(response != "")
		document.getElementById("filebrowser").innerHTML = response;
	else
		document.location = "../CODR/Security.asp";
}

function EmbedFromCSO()
{
	DialogShare("embedfromcso/filebrowser/default.asp?command=golocation&path=/");
}

function DialogShare( url )
{
	displayMessage(url, 700, 500);	
}

function SendRequest(requestURL, requestMethod, functionPointer, args)
{
    var ajaxIndex = AjaxObjects.length;
    AjaxObjects[ajaxIndex] = new sack();
	AjaxObjects[ajaxIndex].method = requestMethod;	
	AjaxObjects[ajaxIndex].requestFile = requestURL;
	AjaxObjects[ajaxIndex].onCompletion = function(){functionPointer(ajaxIndex, args);};
	AjaxObjects[ajaxIndex].runAJAX();
}

function CancelShare()
{
	closeMessage();
}

function ShareSelect( sName )
{
	var sFileType = document.getElementById('mcl' + sName).getAttribute("embed");

	if(sFileType != "true")
	{
		return;
	}

	if((sMoveTo != null && sMoveTo != "") || (sMoveTo == sName))
    {
        document.getElementById("mcl" + sMoveTo).className = "imagefile";
        document.getElementById("mt" + sMoveTo).className = "filetitle";
    }    
   
    if(sMoveTo != sName)
    {    
        sMoveTo = sName;
        document.getElementById("mcl" + sName).className = "imagefilesel";
        document.getElementById("mt" + sName).className = "selfiletitle";
    }
    else
    {
        sMoveTo = "";
    }
}

function GetMoveLocation( sFolderName )
{
    var sLocation = document.getElementById("hdMoveLocation").value;
    
    if(sLocation == "")
    {
        sLocation = sFolderName;
    }
    else
    {
        sLocation = document.getElementById("hdMoveLocation").value + "/" + sFolderName;
    }
    
    return sLocation;
}

function GetExistingAttachmentCount()
{
	var existingAttachmentCount;

	var arraExistingFilesColl = document.getElementById("hdAttachments").value.split("|");
	existingAttachmentCount = arraExistingFilesColl.length - 1;

	return existingAttachmentCount;
}

function GetEmbedAudioVideo()
{
	var noOfMediaFiles = 0;
	if(document.getElementById("txtNoteSummary").value != "")
		noOfMediaFiles++;
	
	if(document.getElementById("hdNoOfVideoAudioCSOIntf").value != "" && document.getElementById("hdNoOfVideoAudioCSOIntf").value != "0")
		noOfMediaFiles += eval(document.getElementById("hdNoOfVideoAudioCSOIntf").value);

	if(document.getElementById("hdPBvideoAttachments").value != "")
		noOfMediaFiles += GetPBvideoCount();

	return noOfMediaFiles;
}

function GetPBvideoCount()
{
	var sPBvideos = document.getElementById("hdPBvideoAttachments").value;
	var arrVideoColl = sPBvideos.split("|");
	var noOfPBvideoEmbeds = 0;

	for(i = 0;i < arrVideoColl.length; i++)
	{
		if(arrVideoColl[i] != "")
			noOfPBvideoEmbeds++;
	}

	return noOfPBvideoEmbeds;
}

function GetPBimageCount()
{
	var sPBimages = document.getElementById("hdPBimgAttachments").value;
	var arrImageColl = sPBimages.split("|");
	var noOfPBimageEmbeds = 0;

	for(i = 0;i < arrImageColl.length; i++)
	{
		if(arrImageColl[i] != "")
			noOfPBimageEmbeds++;
	}

	return noOfPBimageEmbeds;
}

function GetEmbedImages()
{
	var noOfImages = 0;
	
	if(document.getElementById("hdNoOfImagesCSOIntf").value != "" && document.getElementById("hdNoOfImagesCSOIntf").value != "0")
		noOfImages += eval(document.getElementById("hdNoOfImagesCSOIntf").value);

	if(document.getElementById("hdPBimgAttachments").value != "")
		noOfImages += eval(GetPBimageCount());

	return noOfImages;
}

function GetEmbedDocs()
{
	var noOfDocs = 0;
	
	if(document.getElementById("hdNoOfDocsCSOIntf").value != "" && document.getElementById("hdNoOfDocsCSOIntf").value != "0")
		noOfDocs += eval(document.getElementById("hdNoOfDocsCSOIntf").value);

	return noOfDocs;
}

function ShareCSOfiles()
{
	var sFromFolder, url;
	var sSelFiles = document.getElementById("hdShareSelFileObjects").value;
	var noOfFilesSelected;
	var arrFilesColl;
	var boolAuthorship = document.getElementById("hdAuthorship").value.toLowerCase();
	var noOfImagesEmbeds, noOfMediaFilesEmbeds, noOfDocsEmbeds;

	arrFilesColl = sSelFiles.split("|");
	noOfFilesSelected = 0;
	for(i=0;i < arrFilesColl.length;i++)
	{
		if(arrFilesColl[i] != "")
			noOfFilesSelected++;
	}
	noOfFilesSelected += eval(GetEmbedAudioVideo()) + eval(GetEmbedImages()) + eval(GetEmbedDocs());

	noOfImagesEmbeds = eval(document.getElementById("hdNoOfImagesCSO").value) + eval(GetEmbedImages());
	noOfMediaFilesEmbeds = eval(document.getElementById("hdNoOfVideoAudioCSO").value) + eval(GetEmbedAudioVideo());
	noOfDocsEmbeds = eval(document.getElementById("hdNoOfDocsCSO").value) + eval(GetEmbedDocs());

	if(noOfFilesSelected > MAX_TOTAL)
	{
		alert("You can embed " + MAX_AUDIOVIDEO + " video/audio, " + MAX_DOCUMENTS + " documents and " + MAX_IMAGES + " images only in a nafnote.");
		return false;
	}
	else if(noOfImagesEmbeds > MAX_IMAGES)
	{
		alert("Maximum " + MAX_IMAGES + " images are allowed to embed.");
		return false;
	}
	else if(noOfDocsEmbeds > MAX_DOCUMENTS)
	{
		if(MAX_DOCUMENTS > 0)
			alert("Maximum " + MAX_DOCUMENTS + " documents are allowed to embed.");
		else
			alert("No documents are allowed to embed.");
		return false;
	}
	else if(noOfMediaFilesEmbeds > MAX_AUDIOVIDEO)
	{
		alert("Maximum " + MAX_AUDIOVIDEO + " video/audio are allowed to embed.");
		return false;
	}

	for(var i = 0;i < noOfFilesSelected;i++)
	{
		AttachFileIntoClient( arrFilesColl[i], i );
	}

	document.getElementById("hdNoOfImagesCSOIntf").value = eval(document.getElementById("hdNoOfImagesCSOIntf").value) + eval(document.getElementById("hdNoOfImagesCSO").value);
	document.getElementById("hdNoOfVideoAudioCSOIntf").value = eval(document.getElementById("hdNoOfVideoAudioCSOIntf").value) + eval(document.getElementById("hdNoOfVideoAudioCSO").value);
	document.getElementById("hdNoOfDocsCSOIntf").value = eval(document.getElementById("hdNoOfDocsCSOIntf").value) + eval(document.getElementById("hdNoOfDocsCSO").value);	
	document.getElementById("hdAttachments").value += document.getElementById("hdShareSelFileObjects").value;

	closeMessage();
}

function CancelEmbeds()
{
	document.getElementById("embedLineUp").innerHTML = "";
	document.getElementById("hdAttachments").value = "";
	document.getElementById("hdNoOfImagesCSOIntf").value = 0;
	document.getElementById("hdNoOfVideoAudioCSOIntf").value = 0;
	document.getElementById("hdNoOfDocsCSOIntf").value = 0;
}

function CancelAttachment(selFile, attachmentpos)
{
	var sSelFiles = document.getElementById("hdAttachments").value;
	var arrFilesColl = sSelFiles.split("|");
	var noOfFilesSelected = arrFilesColl.length - 1;
	document.getElementById("hdAttachments").value = "";
	var boolFileRemoved = false;
	var fileSelection;
	var ind = 0;

	while(ind < noOfFilesSelected)
	{
		if(ind == attachmentpos && arrFilesColl[ind] == selFile)
		{
			ClearAttachment(selFile, attachmentpos);
			fileSelection = "";
		}
		else
		{
			fileSelection = arrFilesColl[ind];
		}

		document.getElementById("hdAttachments").value += fileSelection + "|";
		ind += 1;
	}
}

function ClearAttachment(selfile, attachmentNo)
{
	document.getElementById("attachment" + attachmentNo).innerHTML = "";
	document.getElementById("attachment" + attachmentNo).id = document.getElementById("attachment" + attachmentNo).id + "null";
	var fileExt = GetFileExtension(selfile); 

	if(fileExt == "")
		return;

	var isImage = WebImageCompatible( fileExt );
	if(!isImage)
	{
		document.getElementById("hdNoOfVideoAudioCSOIntf").value = eval(document.getElementById("hdNoOfVideoAudioCSOIntf").value) - 1;
	}
	else
	{
		document.getElementById("hdNoOfImagesCSOIntf").value = eval(document.getElementById("hdNoOfImagesCSOIntf").value) - 1;
	}
}

function LoadPreviewEmbeds()
{
	var sFromFolder, url;
	var sSelFiles = document.getElementById("hdAttachments").value;
	var noOfFilesSelected;
	var arrFilesColl;
	boolPreview = true;

	arrFilesColl = sSelFiles.split("|");
	noOfFilesSelected = arrFilesColl.length - 1;
	document.getElementById("hdAttachments").value = "";

	for(var i = 0;i < noOfFilesSelected;i++)
	{
		if(arrFilesColl[i] == "")
		{
			continue;
		}
		AttachFileIntoClient( arrFilesColl[i], i );
	}

	document.getElementById("hdAttachments").value = sSelFiles;
}

function WebImageCompatible( fileextension )
{
	var regexp = new RegExp(imageFilePattern);

	return regexp.test( fileextension );
}

function WindowsMediaPlayerCompatible( fileextension )
{
	var regexp = new RegExp(windowsMediaFilePattern);

	if (fileextension.match( regexp ))
		return true;
	else
		return false;
}

function QuickTimeCompatible( fileextension )
{
	var regexp = new RegExp(quicktimeMediaFilePattern);

	if (fileextension.match( regexp ))
		return true;
	else
		return false;
}

function RealPlayerCompatible( fileextension )
{
	var regexp = new RegExp(realMediaFilePattern);

	if (fileextension.match( regexp ))
		return true;
	else
		return false;
}


function FlashPlayerCompatible( fileextension )
{
	var regexp = new RegExp(flashMediaFilePattern);

	if (fileextension.match( regexp ))
		return true;
	else
		return false;
}

function DocumentCompatible( fileextension )
{
	var regexp = new RegExp(documentFilePattern);

	if (fileextension.match( regexp ))
		return true;
	else
		return false;
}

function AttachFileIntoClient( selFile, attachNo )
{
	var fileExtension = GetFileExtension( selFile );
	fileExtension = fileExtension.replace(".", "");
	fileExtension = fileExtension.toLowerCase();

	if(fileExtension == "")
		return;

	var isImage = WebImageCompatible( fileExtension );
	var isWindowsMediaPlayerCompatible = WindowsMediaPlayerCompatible( fileExtension );
	var isQuickTimeCompatible = QuickTimeCompatible( fileExtension );
	var isRealPlayerCompatible = RealPlayerCompatible( fileExtension );
	var isFlashPlayerCompatible = FlashPlayerCompatible( fileExtension );
	var isDocument = DocumentCompatible( fileExtension );

	if(isImage)
	{
		AttachImage( selFile, attachNo );
	}
	else if( isWindowsMediaPlayerCompatible && pluginlist.indexOf("Windows Media Player") != -1 )
	{
		AttachWindowsMediaPlayerFile( selFile, attachNo );
		//NonImageFile( selFile, attachNo );
	}
	else if( isQuickTimeCompatible && pluginlist.indexOf("QuickTime") != -1 )
	{
		AttachQuickTimeFile( selFile, attachNo );
		//NonImageFile( selFile, attachNo );
	}
	else if( isRealPlayerCompatible && pluginlist.indexOf("RealPlayer") != -1 )
	{
		AttachRealPlayerFile( selFile, attachNo );
		//NonImageFile( selFile, attachNo );
	}
	else if( isFlashPlayerCompatible && pluginlist.indexOf("Flash") != -1 )
	{
		AttachFlashPlayerFile( selFile, attachNo );
		//NonImageFile( selFile, attachNo );
	}
	else if( isDocument )
	{
		//AttachDocumentFile( selFile, attachNo );
		NonImageFile( selFile, attachNo );
	}
	else
	{
		var filename = selFile.substr(selFile.lastIndexOf("/") + 1);
		alert("The file " + filename.replace('"', '\"') + " is not compatible to display in your client. The selected files are detached.");
	}
}

function AttachImage( selAttachment, attachmentNo )
{
	if(boolPreview == false)
	{
		AttachImageFromCSO( selAttachment, attachmentNo );
	}
	else
	{
		AttachImageInEditMode( selAttachment, attachmentNo );
	}
}

function AttachImageFromCSO( selAttachment, attachmentNo )
{
	var arrFileRef;
	var iWidth, iHeight, selFileRef, imgRefId;
	var imageAttrPreview;
	var iSetWidth, iSetHeight;
	var htmlSrc;

	/*arrFileRef = document.getElementById("hdShareSelFileObjectsRefs").value.split("|");
	selFileRef = arrFileRef[ attachmentNo ];
	imgRefId = "mcl" + selFileRef;
	iWidth = eval(document.getElementById( imgRefId ).getAttribute("owidth"));
	iHeight = eval(document.getElementById( imgRefId ).getAttribute("oheight"));
	
	if(iWidth > maxImageWidth || iHeight > maxImageHeight)
	{
		if(iWidth >= iHeight)
		{
			iSetWidth = maxImageWidth;
			iSetHeight = parseInt(iHeight*maxImageWidth/iWidth);
		}
		else if(iHeight > iWidth)
		{
			iSetWidth = parseInt(iWidth*maxImageHeight/iHeight);
			iSetHeight = maxImageHeight;
		}
	}
	else
	{
		iSetWidth = iWidth;
		iSetHeight = iHeight;
	}*/

	htmlSrc = "<span id=\"attachment" + eval(attachmentNo + GetExistingAttachmentCount()) + "\">";
	htmlSrc += "<span class=\"sanstxt12\"><img src=\"" + GetResourceBasePath() + "/User_Files/Documents/" +  selAttachment + "\" width=\"" + maxImageWidth + "\" height=\"" + maxImageWidth +  "\" alt=\"\" class=\"imgfile\" /></span>";
	if (!boolPreview)
	{
		htmlSrc += "<span class=\"padh10\"><a href=\"javascript:void(0);\" onclick=\"CancelAttachment('" + selAttachment + "', " + eval(attachmentNo + GetExistingAttachmentCount()) + ");\" class=\"smallstandardlink\">Remove</a></span>";
	}
	htmlSrc += "<br/></span>";
	
	AddAttachmentAsHtml( htmlSrc );
}

function AttachWindowsMediaPlayerFile( selAttachment, attachmentNo )
{
	htmlSrc = "<span id=\"attachment" + eval(attachmentNo + GetExistingAttachmentCount()) + "\">";
	htmlSrc += "<OBJECT width=\"" + maxImageWidth + "\" height=\"" + maxImageHeight + "\"" 
    htmlSrc += "  classid='CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95'"; 
    htmlSrc += "  codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701'";
    htmlSrc += "  standby='Loading Microsoft Windows Media Player components...' type='application/x-oleobject'>";
    htmlSrc += "  <param name='fileName' value=\"" + GetResourceBasePath() + "/User_Files/Documents/" + selAttachment + "\">";
    htmlSrc += "  <param name='animationatStart' value='false'>";
    htmlSrc += "  <param name='transparentatStart' value='false'>";
    htmlSrc += "  <param name='autoStart' value='false'>";
    htmlSrc += "  <param name='showControls' value='true'>";
    htmlSrc += "  <param name='loop' value='false'>";
    htmlSrc += "  <EMBED type='application/x-mplayer2'";
    htmlSrc += "    pluginspage='http://microsoft.com/windows/mediaplayer/en/download/'";
    htmlSrc += "    autostart='0' showcontrols='1' ";        
    htmlSrc += "    showtracker='-1' showdisplay='0' showstatusbar='0'  width=\"" + maxImageWidth + "\" height=\"" + maxImageHeight + "\"";
    htmlSrc += "    src=\"" + GetResourceBasePath() + "/User_Files/Documents/" + selAttachment + "\">";
    htmlSrc += "  </EMBED>";
    htmlSrc += "  </OBJECT>";
	if (!boolPreview)
	{
		htmlSrc += "<span class=\"padh10\"><a href=\"javascript:void(0);\" onclick=\"CancelAttachment('" + selAttachment + "', " + eval(attachmentNo + GetExistingAttachmentCount()) + ");\" class=\"smallstandardlink\">Remove</a></span>";
	}
	htmlSrc += "<br/></span>";

	AddAttachmentAsHtml( htmlSrc );
}

function AttachQuickTimeFile( selAttachment, attachmentNo )
{
	htmlSrc = "<span id=\"attachment" + eval(attachmentNo + GetExistingAttachmentCount()) + "\">";
	htmlSrc += "  <EMBED ";
    htmlSrc += "    autoplay='false' ";        
    htmlSrc += "    width=\"" + maxImageWidth + "\" height=\"" + maxImageHeight + "\"";
    htmlSrc += "    src=\"" + GetResourceBasePath() + "/User_Files/Documents/" + selAttachment + "\">";
    htmlSrc += "  </EMBED>";
	htmlSrc += "<noembed>Woops. Need QuickTime Player</noembed>";
	if (!boolPreview)
	{
		htmlSrc += "<span class=\"padh10\"><a href=\"javascript:void(0);\" onclick=\"CancelAttachment('" + selAttachment + "', " + eval(attachmentNo + GetExistingAttachmentCount()) + ");\" class=\"smallstandardlink\">Remove</a></span>";
	}
	htmlSrc += "<br/></span>";
	
	AddAttachmentAsHtml( htmlSrc );
}

function AttachRealPlayerFile( selAttachment, attachmentNo )
{
	htmlSrc = "<span id=\"attachment" + eval(attachmentNo + GetExistingAttachmentCount()) + "\">";
	htmlSrc += "<object width=\"" + maxImageWidth + "\" height=\"" + maxImageWidth + "\" ";
	htmlSrc += "classid=\"clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA\" >";
	htmlSrc += "<param name=\"src\" value=\"" + GetResourceBasePath() + "/User_Files/Documents/" + selAttachment + "\">";
	htmlSrc += "<param name=\"controls\" value=\"ImageWindow\">";
	htmlSrc += "<param name=\"autostart\" value=\"false\">";
	htmlSrc += "<param name=\"loop\" value=\"false\">";
	htmlSrc += "<param name=\"ImageStatus\" value=\"false\">";
	htmlSrc += "<param name=\"type\" value=\"audio/x-pn-realaudio-plugin\">";
	htmlSrc += "<embed src=\"" + GetResourceBasePath() + "/User_Files/Documents/" + selAttachment + "\" width=\"" + maxImageWidth + "\" height=\"" +  maxImageWidth+ "\" type=\"audio/x-pn-realaudio-plugin\" ";
	htmlSrc += "autostart=\"false\" controls=\"ImageWindow\" loop=\"false\" imagestatus=\"false\" />";
	htmlSrc += "</object>";
	if (!boolPreview)
	{
		htmlSrc += "<span class=\"padh10\"><a href=\"javascript:void(0);\" onclick=\"CancelAttachment('" + selAttachment + "', " + eval(attachmentNo + GetExistingAttachmentCount()) + ");\" class=\"smallstandardlink\">Remove</a></span>";
	}
	htmlSrc += "<br/></span>";
	
	AddAttachmentAsHtml( htmlSrc );
}

function AttachFlashPlayerFile( selAttachment, attachmentNo )
{
	htmlSrc = "<span id=\"attachment" + eval(attachmentNo + GetExistingAttachmentCount()) + "\">";
	htmlSrc += "<embed type=\"application/x-shockwave-flash\" src=\"" + GetResourceBasePath() + "/User_Files/Documents/" + selAttachment + "\" width=\"" + maxImageWidth + "\" height=\"" +  maxImageWidth+ "\" ";
	htmlSrc += "pluginspage=\"http://www.adobe.com/go/getflashplayer\"  />";
	htmlSrc += "<noembed>Woops. Need Flash</noembed>";
	if (!boolPreview)
	{
		htmlSrc += "<span class=\"padh10\"><a href=\"javascript:void(0);\" onclick=\"CancelAttachment('" + selAttachment + "', " + eval(attachmentNo + GetExistingAttachmentCount()) + ");\" class=\"smallstandardlink\">Remove</a></span>";
	}
	htmlSrc += "<br/></span>";
	
	AddAttachmentAsHtml( htmlSrc );
}

function AttachDocumentFile( selAttachment, attachmentNo )
{
	htmlSrc = "<span id=\"attachment" + eval(attachmentNo + GetExistingAttachmentCount()) + "\">";
	htmlSrc += "<table width=\"" + maxImageWidth + "\" height=\"" + maxImageHeight + "\" cellpadding=\"0\" cellspacing=\"0\"><tr><td class=\"imgfile\"><img src=\"" + GetResourceBasePath() + "/CSO/images/icons/document.gif\" alt=\"\" /></td></tr></table>";
	htmlSrc += "<span class=\"sanstxt12\">" + GetResourceName( selAttachment ) + "</span>";
	if (!boolPreview)
	{
		htmlSrc += "<span class=\"padh10\"><a href=\"javascript:void(0);\" onclick=\"CancelAttachment('" + selAttachment + "', " + eval(attachmentNo + GetExistingAttachmentCount()) + ");\" class=\"smallstandardlink\">Remove</a></span>";
	}
	htmlSrc += "<br/></span>";
	
	AddAttachmentAsHtml( htmlSrc );
}

function NonImageFile( selAttachment, attachmentNo )
{
	htmlSrc = "<span id=\"attachment" + eval(attachmentNo + GetExistingAttachmentCount()) + "\">";
	htmlSrc += "<span class=\"sanstxt12\">" + GetResourceName( selAttachment ) + "</span>";
	if (!boolPreview)
	{
		htmlSrc += "<span class=\"padh10\"><a href=\"javascript:void(0);\" onclick=\"CancelAttachment('" + selAttachment + "', " + eval(attachmentNo + GetExistingAttachmentCount()) + ");\" class=\"smallstandardlink\">Remove</a></span><br/>";
	}
	htmlSrc += "<br/></span>";
	
	AddAttachmentAsHtml( htmlSrc );
}

function AddAttachmentAsHtml( html )
{
	document.getElementById("embedLineUp").innerHTML +=  html;
	//parent.iFrameHeight();
}

function GetFileExtension( selFile )
{
	var fileExt = "";

	if(selFile.lastIndexOf(".") != -1)
	{
		fileExt = selFile.substr(selFile.lastIndexOf("."));
	}

	return fileExt;
}

function ShareSelected(sName)
{
    if( document.getElementById("hdShareSelFileObjects").value.indexOf(sName) == -1 )
    {
        return false;
    }
    else
    {
        return true;
    }
}

function AddEmbed( filetype)
{	
	if(filetype == "image")
		document.getElementById("hdNoOfImagesCSO").value = eval(document.getElementById("hdNoOfImagesCSO").value) + 1;
	else if(filetype == "video")
		document.getElementById("hdNoOfVideoAudioCSO").value = eval(document.getElementById("hdNoOfVideoAudioCSO").value) + 1;
	else if(filetype == "document")
		document.getElementById("hdNoOfDocsCSO").value = eval(document.getElementById("hdNoOfDocsCSO").value) + 1;
}

function RemoveEmbed( filetype )
{
	if(filetype == "image")
		document.getElementById("hdNoOfImagesCSO").value = eval(document.getElementById("hdNoOfImagesCSO").value) - 1;
	else if(filetype == "video")
		document.getElementById("hdNoOfVideoAudioCSO").value = eval(document.getElementById("hdNoOfVideoAudioCSO").value) - 1;
	else if(filetype == "document")
		document.getElementById("hdNoOfDocsCSO").value = eval(document.getElementById("hdNoOfDocsCSO").value) - 1;
}

function CheckNoOfEmbeds( filetype )
{
	var boolAuthorship = document.getElementById("hdAuthorship").value.toLowerCase();

	if(eval(GetEmbedAudioVideo()) > MAX_AUDIOVIDEO)
	{
		alert("Only " + MAX_AUDIOVIDEO + " video/audio files are allowed to embed.");
		return false;
	}
	else if(eval(GetEmbedImages()) > MAX_IMAGES)
	{
		alert("Maximum " + MAX_IMAGES + " images are allowed to embed.");
		return false;
	}
	else if(eval(GetEmbedDocs()) > MAX_DOCUMENTS)
	{
		if(MAX_DOCUMENTS > 0)
			alert("Maximum " + MAX_DOCUMENTS + " documents are allowed to embed.");
		else
			alert("No documents are allowed to embed.");
		return false;
	}
	else
	{
		return true;
	}
}

function ShareSelectOrDeselect( sName )
{
	if( sName == "")
		return;
	
	var isEmbed = document.getElementById('mcl' + sName).getAttribute("isembed");
	var sFileType = document.getElementById('mcl' + sName).getAttribute("filetype");
	var sPath = document.getElementById('mcl' + sName).getAttribute("path");
	var sNafType = "";
	
	try{
		sNafType = document.getElementById("hdNafType").value;
	}
	catch(e){}

	if(isEmbed != "true")
	{
		return;
	}

	var sFileSelName = sName + "|";

	var sSelFileType = sFileType + "|";

	var selPath = sPath + "|";
    
    if(!ShareSelected(selPath))
    {
		if(!CheckNoOfEmbeds( sFileType ))
			return false;

		document.getElementById("mcl" + sName).className = "imagefilesel";
        document.getElementById("mt" + sName).className = "selfiletitle";
        document.getElementById("hdShareSelFileObjects").value += selPath;
		document.getElementById("hdShareSelFileObjectsRefs").value += sFileSelName;
		AddEmbed( sFileType );
    }
    else
    {
        document.getElementById("mcl" + sName).className = "imagefile";
        document.getElementById("mt" + sName).className = "filetitle";
        document.getElementById("hdShareSelFileObjects").value = document.getElementById("hdShareSelFileObjects").value.replace((sPath + "|"), ""); 
		document.getElementById("hdShareSelFileObjectsRefs").value = document.getElementById("hdShareSelFileObjectsRefs").value.replace((sName + "|"), ""); 
		RemoveEmbed( sFileType );
    }

	if(IsEmbedExist() == 0)
	{
		document.getElementById("btnMoveOK").disabled = false;
	}
	else
	{
		document.getElementById("btnMoveOK").disabled = true;
	}
}

function IsEmbedExist()
{
	if(document.getElementById("hdNoOfImagesCSO").value > 0 || document.getElementById("hdNoOfVideoAudioCSO").value > 0 ||  document.getElementById("hdNoOfDocsCSO").value > 0 )
		return 0;
	else
		return 1;
}

function GoOneLevelUpShare()
{
    sMoveTo = "";
    var url = "embedfromcso/filebrowser/default.asp?";
    url = url + "command=golocation" + "&path=" + URLencode( GetShareParentFolderPath() );
    DialogShare(url);
}

function ChangeDirectoryShare( sName )
{
    sMoveTo = "";
    var url = "embedfromcso/filebrowser/default.asp?";
    url = url + "command=golocation" + "&path=" + URLencode( GetShareParentFolderPath() + sName );	
    DialogShare(url);
}

function OpenFolderFromShareScreen( sFolderName )
{
    sMoveTo = "";
    var url = "embedfromcso/filebrowser/default.asp?";        
    url = url + "command=golocation" + "&path=" + URLencode( GetMoveLocation( sFolderName ) );	
    DialogShare( url );
}

function GetShareParentFolderPath()
{
    var sLocation = document.getElementById("hdMoveLocation").value;
    
    if(sLocation.lastIndexOf("/") > 0)
    {
       sLocation = sLocation.substring( 0, sLocation.lastIndexOf("/")) + "/";
    }
    else if(sLocation != "")
    {
        sLocation = "";
    }
    
    return sLocation;
}

function Disable(sObjectId)
{
    document.getElementById(sObjectId).disabled = true;
}

function Enable(sObjectId)
{
    document.getElementById(sObjectId).disabled = false;
}

function LoadAttachmentsInEditMode(userid, attachments)
{
	var sFromFolder, url;
	var sSelFiles = document.getElementById("hdAttachments").value;
	var noOfFilesSelected;
	var arrFilesColl, sAttachments;
	
	sAttachments = "";
	arrFilesColl = sSelFiles.split("|");
	noOfFilesSelected = arrFilesColl.length - 1;
	document.getElementById("hdAttachments").value = "";

	for(var i = 0;i < noOfFilesSelected;i++)
	{
		if(arrFilesColl[i] == "")
		{
			continue;
		}

		AttachFileIntoClientEditMode( userid + "/" + arrFilesColl[i], i );
		sAttachments += userid + "/" + arrFilesColl[i] + "|";
	}

	document.getElementById("hdAttachments").value = sAttachments;
}

function AttachFileIntoClientEditMode( selFile, attachNo )
{
	var fileExtension = GetFileExtension( selFile );
	fileExtension = fileExtension.replace(".", "");
	fileExtension = fileExtension.toLowerCase();
	
	if(fileExtension == "")
		return;

	var isImage = WebImageCompatible( fileExtension );
	var isWindowsMediaPlayerCompatible = WindowsMediaPlayerCompatible( fileExtension );
	var isQuickTimeCompatible = QuickTimeCompatible( fileExtension );
	var isRealPlayerCompatible = RealPlayerCompatible( fileExtension );
	var isFlashPlayerCompatible = FlashPlayerCompatible( fileExtension );
	var isDocument = DocumentCompatible( fileExtension );

	if(isImage)
	{
		AttachImageInEditMode( selFile, attachNo );
	}
	else if( isWindowsMediaPlayerCompatible && pluginlist.indexOf("Windows Media Player") != -1 )
	{
		AttachWindowsMediaPlayerFile( selFile, attachNo );
		//NonImageFile( selFile, attachNo );
	}
	else if( isQuickTimeCompatible && pluginlist.indexOf("QuickTime") != -1 )
	{
		AttachQuickTimeFile( selFile, attachNo );
		//NonImageFile( selFile, attachNo );
	}
	else if( isRealPlayerCompatible && pluginlist.indexOf("RealPlayer") != -1 )
	{
		AttachRealPlayerFile( selFile, attachNo );
		//NonImageFile( selFile, attachNo );
	}
	else if( isFlashPlayerCompatible && pluginlist.indexOf("Flash") != -1 )
	{
		AttachFlashPlayerFile( selFile, attachNo );
		//NonImageFile( selFile, attachNo );
	}
	else if( isDocument )
	{
		//AttachDocumentFile( selFile, attachNo );
		NonImageFile( selFile, attachNo );
	}
	else
	{
		var filename = selFile.substr(selFile.lastIndexOf("/") + 1);
		alert("The file " + filename.replace('"', '\"') + " is not compatible to display in your client. The selected files are detached.");
	}
}

function AttachImageInEditMode(selAttachment, attachmentNo)
{
	var iSetWidth, iSetHeight, iWidth, iHeight;
	var htmlSrc;

	/*try{
	iWidth = getImageWidth("tempimg" + attachmentNo);
	}
	catch(e){iWidth = 0;}
	try{
	iHeight = getImageHeight("tempimg" + attachmentNo);
	}
	catch(e){iHeight = 0;}

	if(iWidth > maxImageWidth || iHeight > maxImageHeight)
	{
		if(iWidth >= iHeight)
		{
			iSetWidth = maxImageWidth;
			iSetHeight = parseInt(iHeight*maxImageWidth/iWidth);
		}
		else if(iHeight > iWidth)
		{
			iSetWidth = parseInt(iWidth*maxImageHeight/iHeight);
			iSetHeight = maxImageHeight;
		}
	}
	else
	{
		iSetWidth = iWidth;
		iSetHeight = iHeight;
	}

	if(iSetWidth == 0 && iSetHeight == 0)
	{
		iSetWidth = thumbnailWidth;
		iSetHeight = thumbnailHeight;
	}*/

	htmlSrc = "<span id=\"attachment" + eval(attachmentNo + GetExistingAttachmentCount()) + "\">";
	htmlSrc += "<span><img class=\"imgfile\" src=\"" + GetResourceBasePath() + "/User_Files/Documents/" +  selAttachment + "\" width=\"" + maxImageWidth + "\" height=\"" + maxImageHeight +  "\" border=\"0\" /></span>";
	if (!boolPreview)
	{
		htmlSrc += "<span clas=\"padh10\"><a href=\"javascript:void(0);\" onclick=\"CancelAttachment('" + selAttachment + "', " + eval(attachmentNo + GetExistingAttachmentCount()) + ");\" class=\"smallstandardlink\">Remove</a></span><br/>";
	}
	htmlSrc += "</span>";
	
	AddAttachmentAsHtml( htmlSrc );
}

function getStyleObject(objectId) {
    if(document.getElementById && document.getElementById(objectId)) {
	return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
	return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
		return getObjNN4(document,objectId);
    } else {
	return false;
    } 
} 

function changeObjectVisibility(objectId, newVisibility) {
    var styleObject = getStyleObject(objectId, document);
    if(styleObject) {
	styleObject.visibility = newVisibility;
	return true;
    } else {
	return false;
    }
} 

function findImage(name, doc) {
	var i, img;
	for (i = 0; i < doc.images.length; i++) {
    	if (doc.images[i].name == name) {
			return doc.images[i];
		}
	}
	for (i = 0; i < doc.layers.length; i++) {
    	if ((img = findImage(name, doc.layers[i].document)) != null) {
			img.container = doc.layers[i];
			return img;
    	}
	}
	return null;
}

function getImage(name) {
	if (document.layers) {
    	return findImage(name, document);
	}
	return null;
}

function getObjNN4(obj,name)
{
	var x = obj.layers;
	var foundLayer;
	for (var i=0;i<x.length;i++)
	{
		if (x[i].id == name)
		 	foundLayer = x[i];
		else if (x[i].layers.length)
			var tmp = getObjNN4(x[i],name);
		if (tmp) foundLayer = tmp;
	}
	return foundLayer;
}

function getElementHeight(Elem) {
	if (ns4) {
		var elem = getObjNN4(document, Elem);
		return elem.clip.height;
	} else {
		var elem;
		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} else if (document.all){
			var elem = document.all[Elem];
		}
		if (op5) {
			xPos = elem.style.pixelHeight;
		} else {
			xPos = elem.offsetHeight;
		}
		return xPos;
	} 
}

function getElementWidth(Elem) {
	if (ns4) {
		var elem = getObjNN4(document, Elem);
		return elem.clip.width;
	} else {
		var elem;
		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} else if (document.all){
			var elem = document.all[Elem];
		}
		if (op5) {
			xPos = elem.style.pixelWidth;
		} else {
			xPos = elem.offsetWidth;	
		}
		return xPos;
	}
}

function getElementLeft(Elem) {
	if (ns4) {
		var elem = getObjNN4(document, Elem);
		return elem.pageX;
	} else {
		var elem;
		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} else if (document.all){
			var elem = document.all[Elem];
		}
		xPos = elem.offsetLeft;
		tempEl = elem.offsetParent;
  		while (tempEl != null) {
  			xPos += tempEl.offsetLeft;
	  		tempEl = tempEl.offsetParent;
  		}
		return xPos;
	}
}


function getElementTop(Elem) {
	if (ns4) {
		var elem = getObjNN4(document, Elem);
		return elem.pageY;
	} else {
		if(document.getElementById) {	
			var elem = document.getElementById(Elem);
		} else if (document.all) {
			var elem = document.all[Elem];
		}
		yPos = elem.offsetTop;
		tempEl = elem.offsetParent;
		while (tempEl != null) {
  			yPos += tempEl.offsetTop;
	  		tempEl = tempEl.offsetParent;
  		}
		return yPos;
	}
}


function getImageLeft(myImage) {
	var x, obj;
	if (document.layers) {
		var img = getImage(myImage);
    	if (img.container != null)
			return img.container.pageX + img.x;
		else
			return img.x;
  	} else {
		return getElementLeft(myImage);
	}
	return -1;
}

function getImageTop(myImage) {
	var y, obj;
	if (document.layers) {
		var img = getImage(myImage);
		if (img.container != null)
			return img.container.pageY + img.y;
		else
			return img.y;
	} else {
		return getElementTop(myImage);
	}
	return -1;
}

function getImageWidth(myImage) {
	var x, obj;
	if (document.layers) {
		var img = getImage(myImage);
		return img.width;
	} else {
		return getElementWidth(myImage);
	}
	return -1;
}

function getImageHeight(myImage) {
	var y, obj;
	if (document.layers) {
		var img = getImage(myImage);
		return img.height;
	} else {
		return getElementHeight(myImage);
	}
	return -1;
}

function moveXY(myObject, x, y) {
	obj = getStyleObject(myObject)
	if (ns4) {
		obj.top = y;
 		obj.left = x;
	} else {
		if (op5) {
			obj.pixelTop = y;
 			obj.pixelLeft = x;
		} else {
			obj.top = y + 'px';
 			obj.left = x + 'px';
		}	
	}
}

function changeClass(Elem, myClass) {
	var elem;
	if(document.getElementById) {
		var elem = document.getElementById(Elem);
	} else if (document.all){
		var elem = document.all[Elem];
	}
	elem.className = myClass;
}

function changeImage(target, source) {
	var imageObj;
	
	if (ns4) {
		imageObj = getImage(target);
		if (imageObj) imageObj.src = eval(source).src; 
	} else {
		imageObj = eval('document.images.' + target);
		if (imageObj) imageObj.src = eval(source).src; 
	}
}

function changeBGColour(myObject, colour) {
	if (ns4) {
		var obj = getObjNN4(document, myObject);
		obj.bgColor=colour;
	} else {
		var obj = getStyleObject(myObject);
		if (op5) {
			obj.background = colour;	
		} else {
			obj.backgroundColor = colour;
		}	
	}
}

function FocusEmbed( elementId )
{
	if( document.getElementById( elementId ).className != "selectembed")
		document.getElementById( elementId ).className = "hoverembed";
}

function BlurEmbed( elementId )
{
	if( document.getElementById( elementId ).className != "selectembed")
		document.getElementById( elementId ).className = "embed";
}

function LoadAttachments( displayEmbed )
{
	if(displayEmbed == 0)
	{
		CountAttachments();
		DisplayAttachmentsAsThumbnails();
	}
	DisplayEmbeds( displayEmbed );
}

function CountAttachments()
{
	var sEmbedsFromCSO = document.getElementById("hdAttachments").value;
	var sPBimages = document.getElementById("hdPBimgAttachments").value;
	var sPBvideo = document.getElementById("hdPBvideoAttachments").value;
	var sYouTubeVideo = document.getElementById("hdYouTubeVideo").value;
	var fileExtension;

	if(sYouTubeVideo != "")
		isYouTube_embed = 1;
	else
		isYouTube_embed = 0;

	var arrCSOFileColl, arrPBimgColl, arrPBvideoColl, i, j;
	arrCSOFileColl = sEmbedsFromCSO.split("|");
	arrPBimgColl = sPBimages.split("|");
	arrPBvideoColl = sPBvideo.split("|");
	i = 0;
	j = 0;
	document.getElementById("hdAttachments").value = "";
	while(i <= arrCSOFileColl.length-1)
	{
		if(arrCSOFileColl[i] != "")
		{
			fileExtension = GetFileExtension( arrCSOFileColl[i] );
			fileExtension = fileExtension.toLowerCase();

			if(fileExtension == "")
				return;

			if(!DocumentCompatible( fileExtension ))
			{
				j++;
				document.getElementById("hdAttachments").value = document.getElementById("hdAttachments").value + arrCSOFileColl[i] +  "|";
			}
		}
		i++;
	}
	isEmbedsFromCSO = j;
	i = 0;
	j = 0;
	while(i <= arrPBimgColl.length-1)
	{
		if(arrPBimgColl[i] != "")
			j++;
		i++;
	}
	isPBimages = j;
	i = 0;
	j = 0;
	while(i <= arrPBvideoColl.length-1)
	{
		if(arrPBvideoColl[i] != "")
			j++;
		i++;
	}
	isPBvideos = j;
	totalEmbeds = eval(isYouTube_embed + isEmbedsFromCSO + isPBimages + isPBvideos);
}

function DisplayEmbeds( displayEmbed )
{	
	if(totalEmbeds < 1)
	{
		document.getElementById("browseAttachments").style.display = "none";
		return;
	}
	document.getElementById("browseAttachments").style.display = "block";


	if(displayEmbed < 0)
		displayEmbed = totalEmbeds-1;
	else if(displayEmbed >= totalEmbeds)
		displayEmbed = 0;

	//alert("YouTubeEmbed:" + isYouTube_embed + " EmbedsFromCSO:" + isEmbedsFromCSO + " PBimages:" + isPBimages + " PBvideos:" + isPBvideos);

	if(displayEmbed == 0 && isYouTube_embed > 0)
	{
		NoCommentForTheEmbed();
		DisplayYouTubeVideo( '', 0, false );
	}
	else if(displayEmbed >= eval(isYouTube_embed) && displayEmbed <= eval(isYouTube_embed + isEmbedsFromCSO - 1))
	{
		DisplayEmbedFromCSO( eval(displayEmbed - isYouTube_embed) );
	}
	else if(displayEmbed >= eval(isYouTube_embed + isEmbedsFromCSO) && displayEmbed <= eval(isYouTube_embed + isEmbedsFromCSO + isPBimages - 1))
	{
		NoCommentForTheEmbed();
		DisplayPBimage( eval(displayEmbed - isYouTube_embed - isEmbedsFromCSO) );
	}
	else if(displayEmbed >= eval(isYouTube_embed + isEmbedsFromCSO + isPBimages) && displayEmbed <= eval(isYouTube_embed + isEmbedsFromCSO + isPBimages + isPBvideos - 1))
	{
		NoCommentForTheEmbed();
		DisplayPBvideo( eval(displayEmbed - isYouTube_embed - isEmbedsFromCSO - isPBimages) );
	}
}

function DisplayEmbedFromCSO( displayEmbed )
{
	var sEmbeds = document.getElementById("hdAttachments").value;
	var sUserId = document.getElementById("hdAuthor").value;
	var noOfFilesSelected;
	var arrFilesColl, sAttachments, selFilePath;

	arrFilesColl = sEmbeds.split("|");
	noOfFilesSelected = arrFilesColl.length - 1;

	for(var i = 0;i < noOfFilesSelected;i++)
	{
		if(arrFilesColl[i] == "" || displayEmbed != i)
		{
			continue;
		}

		selFilePath = sUserId + "/" + arrFilesColl[i];
		
		DisplatAttachments( selFilePath, eval(  i + isYouTube_embed ) , false );
		break;
	}
}

function DisplayAttachmentsAsThumbnails()
{
	if(totalEmbeds < 2)
	{
		document.getElementById("embedNav1").style.display = "none";
		document.getElementById("embedNav2").style.display = "none";
		return;
	}

	AttachYouTubeEmbed();
	
	var sEmbeds = document.getElementById("hdAttachments").value;
	var sUserId = document.getElementById("hdAuthor").value;
	var noOfFilesSelected;
	var arrFilesColl, sAttachments, selFilePath;
	var boolThumbnail = true;
	
	arrFilesColl = sEmbeds.split("|");
	noOfFilesSelected = arrFilesColl.length - 1;

	for(var i = 0;i < noOfFilesSelected;i++)
	{
		if(arrFilesColl[i] == "")
		{
			continue;
		}

		selFilePath = sUserId + "/" + arrFilesColl[i];
		
		DisplatAttachments( selFilePath, eval(  i + isYouTube_embed ) , boolThumbnail );
	}
	AttachPBimages();
	AttachPBvideos();
}

function AttachYouTubeEmbed(  )
{
	var youTube_embed = document.getElementById("hdYouTubeVideo").value;
	if (youTube_embed == "")
	{
		return;
	}
	var youTubeVideo, youTubeVideo_thumbnail;
	youTubeVideo_thumbnail = "http://img.youtube.com/vi/<<thumbnail>>/default.jpg";
	youTubeVideo = youTube_embed.substring(youTube_embed.lastIndexOf("src") + 5, youTube_embed.lastIndexOf("type=")-2);
	youTubeVideo = youTubeVideo.substring(youTubeVideo.lastIndexOf("/") + 1);
	youTubeVideo_thumbnail = youTubeVideo_thumbnail.replace("<<thumbnail>>", youTubeVideo);
	DisplayYouTubeVideo( youTubeVideo_thumbnail, 0, true );
}

function AttachPBimages()
{
	var noOfPBimages, arrPBimagesColl, i;
	var PBimagessrc = unescape(document.getElementById("hdPBimgAttachments").value);
	if(PBimagessrc == "")
		return;
	arrPBimagesColl = PBimagessrc.split("|");
	noOfPBimages = 0;
	i = 0;
	while (noOfPBimages < arrPBimagesColl.length)
	{
		if(arrPBimagesColl[noOfPBimages] != "")
		{
			DisplayPBimageThumbnail(arrPBimagesColl[noOfPBimages], eval(i + isYouTube_embed + isEmbedsFromCSO));
			i++;
		}
		noOfPBimages++;
	}
}

function AttachPBvideos()
{
	var noOfPBvideos, arrPBvideosColl, i;
	var PBvideossrc = unescape(document.getElementById("hdPBvideoAttachments").value);
	if(PBvideossrc == "")
		return;
	arrPBvideosColl = PBvideossrc.split("|");
	noOfPBvideos = 0;
	i = 0;
	while (noOfPBvideos < arrPBvideosColl.length)
	{
		if(arrPBvideosColl[noOfPBvideos] != "")
		{
			DisplayPBvideoThumbnail(arrPBvideosColl[noOfPBvideos], eval(i + isYouTube_embed + isEmbedsFromCSO + isPBimages));
			i++;
		}
		noOfPBvideos++;
	}
}

function DisplayPBimageThumbnail( html, attachmentNo)
{
	html = unescape(html);
	html = AlterOrCreateAttribute(html, "width", thumbnailWidth);
	html = AlterOrCreateAttribute(html, "height", thumbnailHeight);
	html = AlterOrCreateAttribute(html, "class", "embed");
	html = AlterOrCreateAttribute(html, "onmouseover", "FocusEmbed(this.id);");
	html = AlterOrCreateAttribute(html, "onmouseout", "BlurEmbed(this.id);");
	html = AlterOrCreateAttribute(html, "id", "embedNo" + attachmentNo);
	html = AlterOrCreateAttribute(html, "align", "bottom");
	html = AlterOrCreateAttribute(html, "onclick", "DisplayEmbeds(" + attachmentNo + ");");
	var htmlSrc = "<span class=\"thumbnail\" id=\"thumbnail" + attachmentNo + "\">";
	htmlSrc += html;
	htmlSrc += "</span>";
	AddAsThumbnail( htmlSrc, attachmentNo );
}

function DisplayPBvideoThumbnail( html, attachmentNo)
{
	var fileName, fileSrc;
	html = unescape(html);
	html = getAttributeVal(html, "src");
	fileSrc = gup(html, "file");
	if(fileSrc == "")
		fileSrc = gup(html, "videoURL");

	fileSrc = fileSrc.replace("//vid", "//th");
	fileName = fileSrc.substring( fileSrc.lastIndexOf("/") + 1 );
	fileName = fileName.replace("." + GetExtension( fileName ), ".jpg");
	fileName = "th_" + fileName;
	fileSrc = fileSrc.substring(0, fileSrc.lastIndexOf("/") + 1);
	fileSrc = fileSrc + fileName;	

	var htmlSrc = "<span class=\"thumbnail\" id=\"thumbnail" + attachmentNo + "\">";
	htmlSrc += "<img id=\"embedNo" + attachmentNo + "\" class=\"embed\" onmouseover=\"FocusEmbed(this.id);\" onmouseout=\"BlurEmbed(this.id);\" src=\"" + fileSrc + "\" align=\"bottom\" width=\"" + thumbnailWidth + "px\" height=\"" + thumbnailHeight +  "px\" border=\"0\" onclick='DisplayEmbeds(" + attachmentNo + ");' />";
	htmlSrc += "</span>";
	AddAsThumbnail( htmlSrc, attachmentNo );
}

function DisplayPBimage( displayEmbed )
{
	var noOfPBimages, arrPBimagesColl, i;
	var PBimagessrc = unescape(document.getElementById("hdPBimgAttachments").value);
	if(PBimagessrc == "")
		return;
	arrPBimagesColl = PBimagessrc.split("|");
	noOfPBimages = 0;
	i = 0;
	while (noOfPBimages < arrPBimagesColl.length)
	{
		if(i == displayEmbed && arrPBimagesColl[noOfPBimages] != "")
		{
			DisplayPBimageIntoClient(arrPBimagesColl[noOfPBimages], eval(i + isYouTube_embed + isEmbedsFromCSO));
			break;
		}

		if(arrPBimagesColl[noOfPBimages] != "")
			i++;

		noOfPBimages++;
	}
}

function DisplayPBvideo( displayEmbed )
{
	var noOfPBvideos, arrPBvideosColl, i;
	var PBvideossrc = document.getElementById("hdPBvideoAttachments").value;
	if(PBvideossrc == "")
		return;
	arrPBvideosColl = PBvideossrc.split("|");
	noOfPBvideos = 0;
	i = 0;
	while (noOfPBvideos < arrPBvideosColl.length)
	{
		if(i == displayEmbed && arrPBvideosColl[noOfPBvideos] != "")
		{
			DisplayPBvideoIntoClient(arrPBvideosColl[noOfPBvideos], eval(i + isYouTube_embed + isEmbedsFromCSO + isPBimages));
			break;
		}

		if(arrPBvideosColl[noOfPBvideos] != "")
			i++;

		noOfPBvideos++;
	}
}

function DisplayPBimageIntoClient( html , attachmentNo )
{
	html = AlterOrCreateAttribute(html, "width", displayWidth);
	html = AlterOrCreateAttribute(html, "height", displayHeight);
	html = AlterOrCreateAttribute(html, "onclick", "ShowFullSize(this.src);");
	html = AlterOrCreateAttribute(html, "alt", "Click to see in full size.");

	var htmlSrc = "<span id=\"displayAtachment" + attachmentNo + "\">";
	htmlSrc += html;
	htmlSrc += "</span>";
	DisplayEmbed( htmlSrc, attachmentNo );
}

function DisplayPBvideoIntoClient( html , attachmentNo )
{
	html = AlterOrCreateAttribute(html, "width", displayWidth);
	html = AlterOrCreateAttribute(html, "height", displayHeight);
	var htmlSrc = "<span id=\"displayAtachment" + attachmentNo + "\">";
	htmlSrc += html;
	htmlSrc += "</span>";
	DisplayEmbed( htmlSrc, attachmentNo );
}

function DisplatAttachments( selFile, attachNo, boolThumbnail )
{
	var fileExtension = GetFileExtension( selFile );
	fileExtension = fileExtension.replace(".", "");
	fileExtension = fileExtension.toLowerCase();

	if(fileExtension == "")
		return;

	var isImage = WebImageCompatible( fileExtension );
	var isWindowsMediaPlayerCompatible = WindowsMediaPlayerCompatible( fileExtension );
	var isQuickTimeCompatible = QuickTimeCompatible( fileExtension );
	var isRealPlayerCompatible = RealPlayerCompatible( fileExtension );
	var isFlashPlayerCompatible = FlashPlayerCompatible( fileExtension );

	if(isImage)
	{
		DisplayImageInClient( selFile, attachNo, boolThumbnail );
	}
	else if( isWindowsMediaPlayerCompatible && pluginlist.indexOf("Windows Media Player") != -1 )
	{
		DisplayWindowsMediaPlayerFile( selFile, attachNo, boolThumbnail );
	}
	else if( isQuickTimeCompatible && pluginlist.indexOf("QuickTime") != -1 )
	{
		DisplayQuickTimeFile( selFile, attachNo, boolThumbnail );
	}
	else if( isRealPlayerCompatible && pluginlist.indexOf("RealPlayer") != -1 )
	{
		DisplayRealPlayerFile( selFile, attachNo, boolThumbnail );
	}
	else if( isFlashPlayerCompatible && pluginlist.indexOf("Flash") != -1 )
	{
		DisplayFlashPlayerFile( selFile, attachNo, boolThumbnail );
	}
	else
	{
		var filename = selFile.substr(selFile.lastIndexOf("/") + 1);
		alert("The file " + filename.replace('"', '\"') + " is not compatible to display in your client.");
	}
}

function DisplayYouTubeVideo( selAttachment, attachmentNo, boolThumbnail )
{
	var iSetWidth, iSetHeight, iWidth, iHeight;
	var htmlSrc;
	var maxdisplayWidth, maxdisplayHeight;

	iWidth = 130;
	iHeight = 97;

	if(boolThumbnail)
	{
		maxdisplayWidth = thumbnailWidth;
		maxdisplayHeight = thumbnailHeight;
	}
	else
	{
		maxdisplayWidth = displayWidth;
		maxdisplayHeight = displayHeight;
	}

	if(iWidth > maxdisplayWidth || iHeight > maxdisplayHeight)
	{
		if(iWidth >= iHeight)
		{
			iSetWidth = maxdisplayWidth;
			iSetHeight = parseInt(iHeight*maxdisplayWidth/iWidth);
		}
		else if(iHeight > iWidth)
		{
			iSetWidth = parseInt(iWidth*maxdisplayHeight/iHeight);
			iSetHeight = maxdisplayHeight;
		}
	}
	else
	{
		iSetWidth = iWidth;
		iSetHeight = iHeight;
	}
	
	if(boolThumbnail)
	{
		htmlSrc = "<span class=\"thumbnail\" id=\"thumbnail" + attachmentNo + "\">";
		htmlSrc += "<img id=\"embedNo" + attachmentNo + "\" class=\"embed\" onmouseover=\"FocusEmbed(this.id);\" onmouseout=\"BlurEmbed(this.id);\" src=\"" +  selAttachment + "\" align=\"bottom\" width=\"" + iSetWidth + "\" height=\"" + iSetHeight +  "\" border=\"0\" onclick='DisplayYouTubeVideo(\"" + selAttachment + "\"," + attachmentNo + ", false);' />";
		htmlSrc += "</span>";
		AddAsThumbnail( htmlSrc, attachmentNo );
	}
	else
	{
		htmlSrc = "<input type=\"text\" style=\"display:none;\"/>";
		htmlSrc += document.getElementById("hdYouTubeVideo").value;
		currentDisplayingEmbed = 0;
		DisplayEmbed( htmlSrc, attachmentNo );
	}
}

function DisplayImageInClient( selAttachment, attachmentNo, boolThumbnail )
{
	var iSetWidth, iSetHeight, iWidth, iHeight;
	var htmlSrc;
	var maxdisplayWidth, maxdisplayHeight;

	try{
	iWidth = getImageWidth("tempimg" + eval(attachmentNo- isYouTube_embed));
	}
	catch(e){iWidth = 0;}
	try{
	iHeight = getImageHeight("tempimg" + eval(attachmentNo - isYouTube_embed));
	}
	catch(e){iHeight = 0;}

	if(boolThumbnail)
	{
		maxdisplayWidth = thumbnailWidth;
		maxdisplayHeight = thumbnailHeight;
	}
	else
	{
		maxdisplayWidth = displayWidth;
		maxdisplayHeight = displayHeight;
	}

	if(iWidth == 0 && iHeight == 0)
	{
		if(boolThumbnail)
		{
			iWidth = thumbnailWidth;
			iHeight = thumbnailWidth;
		}
		else
		{
			iWidth = displayWidth;
			iHeight = displayHeight;
		}
	}

	if(iWidth > maxdisplayWidth || iHeight > maxdisplayHeight)
	{
		if(iWidth >= iHeight)
		{
			iSetWidth = maxdisplayWidth;
			iSetHeight = parseInt(iHeight*maxdisplayWidth/iWidth);
		}
		else if(iHeight > iWidth)
		{
			iSetWidth = parseInt(iWidth*maxdisplayHeight/iHeight);
			iSetHeight = maxdisplayHeight;
		}
	}
	else
	{
		iSetWidth = iWidth;
		iSetHeight = iHeight;
	}

	if(boolThumbnail)
	{
		htmlSrc = "<span class=\"thumbnail\" id=\"thumbnail" + attachmentNo + "\">";
		htmlSrc += "<img id=\"embedNo" + attachmentNo + "\" class=\"embed\" onmouseover=\"FocusEmbed(this.id);\" onmouseout=\"BlurEmbed(this.id);\" src=\"" + GetResourceBasePath() + "/User_Files/Documents/" +  selAttachment + "\" align=\"bottom\" width=\"" + iSetWidth + "px\" height=\"" + iSetHeight +  "px\" border=\"0\" onclick='DisplayImageInClient(\"" + selAttachment + "\"," + attachmentNo + ", false);' />";
		htmlSrc += "</span>";
		AddAsThumbnail( htmlSrc, attachmentNo );
	}
	else
	{
		htmlSrc = "<span id=\"displayAtachment" + attachmentNo + "\">";
		htmlSrc += "<img src=\"" + GetResourceBasePath() + "/User_Files/Documents/" +  selAttachment + "\" alt=\"Click to see in full size.\" width=\"" + iSetWidth + "\" height=\"" + iSetHeight +  "\" border=\"0\" onclick=\"ShowFullSize(this.src);\" />";
		htmlSrc += "</span>";
		DisplayEmbed( htmlSrc, attachmentNo );
		DisplayComment( selAttachment );
	}
}

function DisplayWindowsMediaPlayerFile( selAttachment, attachmentNo, boolThumbnail )
{
	if(boolThumbnail)
	{
		maxdisplayWidth = thumbnailWidth;
		maxdisplayHeight = thumbnailHeight;
	}
	else
	{
		maxdisplayWidth = displayWidth;
		maxdisplayHeight = displayHeight;
	}
	
	htmlSrc = "<span id=\"thumbnail" + attachmentNo + "\""
	htmlSrc += ">";
	htmlSrc += "<OBJECT width=\"" + maxdisplayWidth + "\" height=\"" + maxdisplayHeight + "\" type='application/x-oleobject'";
	if(boolThumbnail)
	{
		htmlSrc += " onmousedown='DisplayWindowsMediaPlayerFile(\"" + selAttachment + "\"," + attachmentNo + ", false);' onclick='DisplayWindowsMediaPlayerFile(\"" + selAttachment + "\"," + attachmentNo + ", false);'";
	}
    htmlSrc += "  >";
    htmlSrc += "  <param name='src' value=\"" + GetResourceBasePath() + "/User_Files/Documents/" + selAttachment + "\">";
    htmlSrc += "  <param name='autoStart' value='False'>";
	htmlSrc += "  <param name='animationStart' value='True'>";
	htmlSrc += "  <param name='transparentStart' value='True'>";
	htmlSrc += "  <param name='enableContextMenu' value='False'>";
	htmlSrc += "  <param name='showStatusbar' value='False'>";
	htmlSrc += "  <param name='showDisplay' value='True'>";
	if(boolThumbnail)
	{
		htmlSrc += "  <param name='showControls' value='False'>";
		htmlSrc += "  <param name='fullScreen' value='True'>";
	}
	else
	{
		htmlSrc += "  <param name='showControls' value='True'>";
		htmlSrc += "  <param name='fullScreen' value='False'>";
	}
    htmlSrc += "  <EMBED type='application/x-mplayer2' ";
	htmlSrc += "    pluginspage='http://microsoft.com/windows/mediaplayer/en/download/'";
	htmlSrc += "    showtracker='-1' showdisplay='1' showstatusbar='0'  width=\"" + maxdisplayWidth + "\" height=\"" + maxdisplayHeight + "\" enableContextMenu='0'";
    htmlSrc += "    autostart='0' displaySize='4' "
	if(boolThumbnail)
	{
		htmlSrc += "    showcontrols='-1' fullScreen='1' ";
	}
	else
	{
		htmlSrc += "    showcontrols='1' fullScreen='0' ";
	}        
	htmlSrc += "    src=\"" + GetResourceBasePath() + "/User_Files/Documents/" + selAttachment + "\"";
	if (boolThumbnail)
	{
		htmlSrc += " onmousedown='DisplayWindowsMediaPlayerFile(\"" + selAttachment + "\"," + attachmentNo + ", false);' onclick='DisplayWindowsMediaPlayerFile(\"" + selAttachment + "\"," + attachmentNo + ", false);'";
	}
	htmlSrc += " >";
    htmlSrc += "  </EMBED>";
    htmlSrc += "  </OBJECT><input type=\"text\" style=\"display:none;\"/>";
	htmlSrc += "</span>";

	if(boolThumbnail)
	{
		AddAsThumbnail( htmlSrc, attachmentNo );
	}
	else
	{
		DisplayComment( selAttachment );
		DisplayEmbed( htmlSrc, attachmentNo );
	}
}

function DisplayQuickTimeFile( selAttachment, attachmentNo )
{
	if(boolThumbnail)
	{
		maxdisplayWidth = thumbnailWidth;
		maxdisplayHeight = thumbnailHeight;
	}
	else
	{
		maxdisplayWidth = displayWidth;
		maxdisplayHeight = displayHeight;
	}
	
	htmlSrc = "<span id=\"thumbnail" + eval(attachmentNo) + "\">";
	htmlSrc += "  <EMBED ";
    htmlSrc += "    autoplay='false' ";        
    htmlSrc += "    width=\"" + maxdisplayWidth + "\" height=\"" + maxdisplayHeight + "\"";
	if (boolThumbnail)
	{
		htmlSrc += " onclick='DisplayQuickTimeFile(\"" + selAttachment + "\"," + attachmentNo + ", false);' onmousedown='DisplayQuickTimeFile(\"" + selAttachment + "\"," + attachmentNo + ", false);'"
	}
    htmlSrc += "    src=\"" + GetResourceBasePath() + "/User_Files/Documents/" + selAttachment + "\">";
    htmlSrc += "  </EMBED>";
	htmlSrc += "<noembed>Woops. Need QuickTime Player</noembed>";
	htmlSrc += "</span>";
	
	if(boolThumbnail)
	{
		AddAsThumbnail( htmlSrc, attachmentNo );
	}
	else
	{
		DisplayComment( selAttachment );
		DisplayEmbed( htmlSrc, attachmentNo );
	}
}

function DisplayRealPlayerFile( selAttachment, attachmentNo )
{
	if(boolThumbnail)
	{
		maxdisplayWidth = thumbnailWidth;
		maxdisplayHeight = thumbnailHeight;
	}
	else
	{
		maxdisplayWidth = displayWidth;
		maxdisplayHeight = displayHeight;
	}

	htmlSrc = "<span id=\"thumbnail" + eval(attachmentNo) + "\">";
	htmlSrc += "<object width=\"" + maxdisplayWidth + "\" height=\"" + maxdisplayHeight + "\" ";
	htmlSrc += " classid=\"clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA\" >";
	htmlSrc += "<param name=\"src\" value=\"" + GetResourceBasePath() + "/User_Files/Documents/" + selAttachment + "\">";
	htmlSrc += "<param name=\"autostart\" value=\"false\">";
	htmlSrc += "<param name=\"loop\" value=\"false\">";
	htmlSrc += "<param name=\"ImageStatus\" value=\"false\">";
	htmlSrc += "<param name=\"type\" value=\"audio/x-pn-realaudio-plugin\">";
	htmlSrc += "<embed src=\"" + GetResourceBasePath() + "/User_Files/Documents/" + selAttachment + "\" width=\"" + maxdisplayWidth + "\" height=\"" +  maxdisplayHeight+ "\" type=\"audio/x-pn-realaudio-plugin\" ";
	if (boolThumbnail)
	{
		htmlSrc += "  onmousedown='DisplayRealPlayerFile(\"" + selAttachment + "\"," + attachmentNo + ", false);'  onclick='DisplayRealPlayerFile(\"" + selAttachment + "\"," + attachmentNo + ", false);' "
	}
	htmlSrc += "autostart=\"false\" loop=\"false\" imagestatus=\"false\" />";
	htmlSrc += "</object>";
	htmlSrc += "</span>";
	
	if(boolThumbnail)
	{
		AddAsThumbnail( htmlSrc, attachmentNo );
	}
	else
	{
		DisplayComment( selAttachment );
		DisplayEmbed( htmlSrc, attachmentNo );
	}
}

function DisplayFlashPlayerFile( selAttachment, attachmentNo )
{
	if(boolThumbnail)
	{
		maxdisplayWidth = thumbnailWidth;
		maxdisplayHeight = thumbnailHeight;
	}
	else
	{
		maxdisplayWidth = displayWidth;
		maxdisplayHeight = displayHeight;
	}

	htmlSrc = "<span id=\"thumbnail" + eval(attachmentNo) + "\">";
	htmlSrc += "<embed type=\"application/x-shockwave-flash\" src=\"" + GetResourceBasePath() + "/User_Files/Documents/" + selAttachment + "\" width=\"" + maxdisplayWidth + "\" height=\"" +  maxdisplayHeight+ "\" ";
	if (boolThumbnail)
	{
		htmlSrc += "  onmousedown='DisplayFlashPlayerFile(\"" + selAttachment + "\"," + attachmentNo + ", false);'  onclick='DisplayFlashPlayerFile(\"" + selAttachment + "\"," + attachmentNo + ", false);'  "
	}
	htmlSrc += "pluginspage=\"http://www.adobe.com/go/getflashplayer\"  />";
	htmlSrc += "<noembed>Woops. Need Flash</noembed>";
	htmlSrc += "</span>";
	
	if(boolThumbnail)
	{
		AddAsThumbnail( htmlSrc, attachmentNo );
	}
	else
	{
		DisplayComment( selAttachment );
		DisplayEmbed( htmlSrc, attachmentNo );
	}
}

function AddAsThumbnail( html, attachmentNo )
{
	document.getElementById("embedLineUp").innerHTML += html;
}

function Debug( html )
{
	document.getElementById("debug").innerHTML += html;
}

function DisplayEmbed( html, attachmentNo )
{
	var i = 0;
	while(i < totalEmbeds)
	{
		try{
			document.getElementById("embedNo" + i).className="embed";
		}
		catch(e){}
		i++;
	}

	document.getElementById("displayAttachments").innerHTML = html;

	try
	{
		currentDisplayingEmbed = attachmentNo;
		document.getElementById("embedNo" + attachmentNo).className="selectembed";
	}
	catch(e)
	{}
}

function ShowFullSize( elementSrc )
{
	displayMessage("embedfromcso/filebrowser/imageoriginalsize.asp?src=" + elementSrc, 1000, 720);
}

function PreviousEmbed()
{
	DisplayEmbeds( eval(currentDisplayingEmbed - 1) );
}

function NextEmbed()
{
	DisplayEmbeds( eval(currentDisplayingEmbed + 1) );
}

function gup( url, name )
{  
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( url );
	if( results == null )
		return "";
	else 
		return results[1];
}

function GetExtension( s )
{
	return s.substring(s.lastIndexOf(".") + 1);
}

function GetResourceName( s )
{
	return s.substring(s.lastIndexOf("/") + 1);
}

function GetResource( s )
{
	var author = document.getElementById("hdNoteAuthor").value;
	var toUrl = "embedfromcso/filebrowser/getresrc.asp?";       
    toUrl = toUrl + "command=getresrc" + "&author=" + author + "&path=" + URLencode( s );
	document.forms["filebrowser"].action = toUrl;
	document.forms["filebrowser"].submit();
}

function URLencode( s )
{
	var encodedHtml = escape(s);
	encodedHtml = encodedHtml.replace(/\//g,"%2F");
	encodedHtml = encodedHtml.replace(/\?/g,"%3F");
	encodedHtml = encodedHtml.replace(/=/g,"%3D");
	encodedHtml = encodedHtml.replace(/&/g,"%26");
	encodedHtml = encodedHtml.replace(/@/g,"%40");

	return encodedHtml;
}

function PopUpload()
{
    document.getElementById("hdBrowseLocation").value = GetMoveLocation('');
	displayMessage("embedfromcso/upload/default.asp", 400, 180);
}

function On_UploadSubmit()
{
	var sCharsNotAllowed = '\\/:*?"<>|';
	if ( document.getElementById('NewFile').value.length == 0 )
	{
		alert( 'Please select a file from your computer' ) ;
		return false ;
	}

	if( !IsValidName(document.getElementById('txtComments').value, sCharsNotAllowed, false) )
	{
		alert( 'Comments should not contain characters \\/:*?"<>|' ) ;
		document.getElementById('txtComments').focus();
		return false ;
	}

	var sUrl = "embedfromcso/upload/asp/connector.asp?Command=FileUpload&path=" + URLencode( document.getElementById("hdBrowseLocation").value );

	document.forms['frmUpload'].action = sUrl;

	document.getElementById('btnUpload').disabled = true ;

	document.getElementById('btnCancel').disabled = true ;

	return true ;
}

function OnEmbedUploadCompleted( errorNumber, data )
{
	// Reset the Upload Worker Frame.
	try{
		this.frames['frmUploadWorker'].src = 'javascript:void(0);';
	}
	catch(e)
	{
	}

	// Reset the upload form (On IE we must do a little trick to avout problems).
	if ( document.all )
	{
		document.getElementById('NewFile').outerHTML = '<input id="NewFile" name="NewFile" size="35" type="file">' ;
	}
	else
		document.forms['frmUpload'].reset() ;

	// Reset the interface elements.
	document.getElementById('btnUpload').disabled = false ;

	document.getElementById('btnCancel').disabled = false ;

	switch ( errorNumber )
	{
		case "0" :
            closeMessage();
			window.setTimeout("ReturnToBrowse();", 500);
			break ;
		case "1" :	// Custom error.
			alert( data ) ;
			break ;
		case "201" :
			DisplayUploadMsg( 'A file with the same name is already exists. The uploaded file has been renamed to "' + data + '"' ) ;
			RestoreTheBrowser();
			break ;
		case "202" :
			alert( 'Invalid file' ) ;
			break ;
		case "-777":
			window.location = "../../CODR/SessionLogout.asp";
			break;
		default :
			alert( 'Error on file upload. Error number: ' + errorNumber ) ;
			break ;
	}
}

function IsValidName(sName, sChars, IsCharsAllowed)
{
    var isValid = true;
    
    if(IsCharsAllowed)
    {
        for(i=0;i<sChars.length;i++)
        {
            if(sName.indexOf(sChars.charAt(i)) == -1)
            {
                isValid = false;
            }
        }
    }
    else
    {
        for(i=0;i<sChars.length;i++)
        {
            if(sName.indexOf(sChars.charAt(i)) != -1)
            {
                isValid = false;
                break;
            }
        }
    }
    
    return isValid;
}

function IsValidLength(sVal, iMax)
{
    var sValLength = sVal.length;
    
    if(sValLength > iMax || sValLength < 0)
    {
        return false;
    }
    else
    {
        return true;
    }
}

function ReturnToBrowse()
{
	DialogShare("embedfromcso/filebrowser/default.asp?command=golocation&path=" + document.getElementById("hdBrowseLocation").value);
}

function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else 
countfield.value = maxlimit - field.value.length;
}

function UploadAndEmbed()
{
	displayMessage("embedfromcso/upload/default.asp?return=embed", 400, 180);
}

function On_UploadEmbedSubmit()
{
	var sCharsNotAllowed = '\\/:*?"<>|';
	if ( document.getElementById('NewFile').value.length == 0 )
	{
		alert( 'Please select a file from your computer' ) ;
		return false ;
	}

	if( !IsValidName(document.getElementById('txtComments').value, sCharsNotAllowed, false) )
	{
		alert( 'Comments should not contain characters \\/:*?"<>|' ) ;
		document.getElementById('txtComments').focus();
		return false ;
	}

	var sUrl = "embedfromcso/upload/asp/connector.asp?return=embed&Command=FileUpload&path=" + URLencode( document.getElementById("hdBrowseLocation").value );

	document.forms['frmUpload'].action = sUrl;

	document.getElementById('btnUpload').disabled = true ;

	document.getElementById('btnCancel').disabled = true ;

	return true ;
}

function EmbedUploaded( errorNumber, data )
{
	// Reset the Upload Worker Frame.
	try{
		this.frames['frmUploadWorker'].src = 'javascript:void(0);';
	}
	catch(e)
	{
	}

	// Reset the upload form (On IE we must do a little trick to avout problems).
	if ( document.all )
	{
		document.getElementById('NewFile').outerHTML = '<input id="NewFile" name="NewFile" size="35" type="file">' ;
	}
	else
		document.forms['frmUpload'].reset() ;

	// Reset the interface elements.
	document.getElementById('btnUpload').disabled = false ;

	document.getElementById('btnCancel').disabled = false ;

	switch ( errorNumber )
	{
		case "0" :
			if(window.confirm(data + " uploaded successfully.\nDo you want to embed this file into your NafNote?") == 1)
			{
				closeMessage();
				ShareUploaded(data);
			}
			else
			{
				closeMessage();
			}
			break ;
		case "1" :	// Custom error.
			alert( data ) ;
			break ;
		case "201" :
			if(window.confirm("A file with the same name is already exists. The uploaded file has been renamed to " + data + ".\nDo you want to embed this file into your NafNote?") == 1)
			{
				closeMessage();
				ShareUploaded(data);
			}
			else
			{
				closeMessage();
			}
			break ;
			break ;
		case "202" :
			alert( 'Invalid file' ) ;
			break ;
		case "-777":
			window.location = "../../CODR/SessionLogout.asp";
			break;
		default :
			alert( 'Error on file upload. Error number: ' + errorNumber ) ;
			break ;
	}
}

function ShareUploaded( sName )
{
	var actualFileName = document.getElementById("hdCSOowner").value + "/" + sName;
	if( sName == "")
		return;
	
	var sFileType = GetEmbedFileType( sName );
	var isEmbed = "false";
	if(sFileType == "image" || sFileType == "document" || sFileType == "video")
		isEmbed = "true";

	if(!isEmbed)
	{
		alert("The uploaded file can not be embeded.");
		return;
	}

	var sPath = "";
	var sNafType = "";
	
	try{
		sNafType = document.getElementById("hdNafType").value;
	}
	catch(e){}

	if(sNafType == "NafThat" && sFileType != "image" && sFileType != "video")
	{
		return;
	}

	if(isEmbed != "true")
	{
		return;
	}

	ShareCSOfileFromUpload( actualFileName, sFileType );
}

function GetEmbedFileType( selFile )
{
	var fileExtension = GetFileExtension( selFile );
	fileExtension = fileExtension.replace(".", "");
	fileExtension = fileExtension.toLowerCase();

	if(fileExtension == "")
		return;

	var isImage = WebImageCompatible( fileExtension );
	var isWindowsMediaPlayerCompatible = WindowsMediaPlayerCompatible( fileExtension );
	var isQuickTimeCompatible = QuickTimeCompatible( fileExtension );
	var isRealPlayerCompatible = RealPlayerCompatible( fileExtension );
	var isFlashPlayerCompatible = FlashPlayerCompatible( fileExtension );
	var isDocument = DocumentCompatible( fileExtension );

	if(isImage)
	{
		return "image";
	}
	else if(isWindowsMediaPlayerCompatible || isQuickTimeCompatible || isRealPlayerCompatible || isFlashPlayerCompatible)
	{
		return "video";
	}
	else if(isDocument)
	{
		return "document";
	}
	else
	{
		return "defaultfile";
	}
}

function ShareCSOfileFromUpload( selFile, sType )
{
	var sFromFolder, url;
	
	if(CheckNoOfEmbeds())
	{
		AttachFileIntoClient( selFile, 0 );
	}

	if(sType == "image")
		document.getElementById("hdNoOfImagesCSOIntf").value = eval(document.getElementById("hdNoOfImagesCSOIntf").value) + 1;
	else if(sType == "video")
		document.getElementById("hdNoOfVideoAudioCSOIntf").value = eval(document.getElementById("hdNoOfVideoAudioCSOIntf").value) + 1;
	else if(sType == "document")
		document.getElementById("hdNoOfDocsCSOIntf").value = eval(document.getElementById("hdNoOfDocsCSOIntf").value) + 1;

	document.getElementById("hdAttachments").value += selFile + "|";
}

function ToggleDownloadsPanel( sPanel )
{
	ResetPanels();
	if(document.getElementById( sPanel + "Panel" ))
	{
		document.getElementById( sPanel + "Arrow" ).innerHTML = "<b>[-]</b>";
		document.getElementById( sPanel + "Panel" ).style.display = "inline";
	}
}

function ResetPanels()
{
	if(document.getElementById("documentsPanel"))
	{
		document.getElementById("documentsArrow").innerHTML = "<b>[+]</b>";
		document.getElementById("documentsPanel").style.display = "none";
	}

	if(document.getElementById("audiovideoPanel"))
	{
		document.getElementById("audiovideoArrow").innerHTML = "<b>[+]</b>";
		document.getElementById("audiovideoPanel").style.display = "none";
	}
	if(document.getElementById("imagesPanel"))
	{
		document.getElementById("imagesArrow").innerHTML = "<b>[+]</b>";
		document.getElementById("imagesPanel").style.display = "none";
	}

	if(document.getElementById("othersPanel"))
	{
		document.getElementById("othersArrow").innerHTML = "<b>[+]</b>";
		document.getElementById("othersPanel").style.display = "none";
	}
}

function loadXML(strXML)
{
	// code for IE
    if (window.ActiveXObject)
    {
        var doc=new ActiveXObject("Microsoft.XMLDOM");
        doc.async="false";
        doc.loadXML(strXML);
    }
    // code for Mozilla, Firefox, Opera, etc.
    else
    {
        var parser=new DOMParser();
        var doc=parser.parseFromString(strXML,"text/xml");
    }
    return(doc);
}

function GetComments( sFile )
{
	var sCommentsXML, boolComment;
	boolComment = false;
	try{
		sCommentsXML = document.getElementById("hdAttachmentsXML").value;
	}
	catch(e)
	{
		sCommentsXML = "";
	}

	var xmlDoc = loadXML( sCommentsXML );

	var xEmbed = xmlDoc.getElementsByTagName("embed");

	for(i=0;i<xEmbed.length;i++)
	{
		if(xEmbed[i].getElementsByTagName("cso_path")[0].childNodes[0].nodeValue == sFile)
		{
			boolComment = true;
			if(xEmbed[i].getElementsByTagName("delete_status")[0].childNodes[0].nodeValue != "1")
			{
				sComment = xEmbed[i].getElementsByTagName("caption")[0].childNodes[0].nodeValue;
			}
			else
			{
				sComment = "The file is deleted by its Owner on " + xEmbed[i].getElementsByTagName("delete_date")[0].childNodes[0].nodeValue;
			}
		}
	}

	if(boolComment)
	{
		return sComment;
	}
	else
	{
		return "undefined";
	}
}

function DisplayComment( selFile )
{
	var sComments = GetComments( selFile );

	if(sComments != "" && sComments != "undefined")
	{
		document.getElementById("embedComments").style.display = "inline";
		document.getElementById("embedComments").innerHTML = sComments; 
	}
	else
	{
		document.getElementById("embedComments").style.display = "none"; 
	}
}

function NoCommentForTheEmbed()
{
	document.getElementById("embedComments").innerHTML = "";
	document.getElementById("embedComments").style.display = "none";
}

function DisplayUploadMsg(msg)
{
    document.getElementById("msgUpload").innerHTML = msg;
}

function ResetEmbedCount()
{
	document.getElementById("hdNoOfImagesCSOIntf").value = "0";
	document.getElementById("hdNoOfVideoAudioCSOIntf").value = "0";
	document.getElementById("hdNoOfDocsCSOIntf").value = "0";
	document.getElementById("hdPBimgAttachments").value = "";
	document.getElementById("hdPBvideoAttachments").value = "";
	document.getElementById("hdAttachments").value = "";
	document.getElementById("txtNoteSummary").value = "";
}

//----------- To add OnLoad events (stack) -------------------
function addDocumentLoadEvent( func ) {
      var oldonload = window.onload;
      if (typeof window.onload != 'function') {
            window.onload = func;
      } else {
            window.onload = function() {
                  oldonload();
                  func();
            }
      }
}