/*
<!-- -->
<!-- The copyright in the work that is PublicAccess is the exclusive -->
<!-- property of CAPS Solutions Ltd, and its respective copyright owners, and is -->
<!-- protected under United Kingdom copyright law and other international copyright -->
<!-- treaties and conventions. 
<!-- © 2004. CAPS Solutions Ltd and its licensor(s). All rights reserved. -->
*/

var szcURL_DM_APPROOT = szcURL_APPROOT + "/do/dodocument";

function btnAssocDoc_Click(){

	var szCaseRecordType =  document.getElementById('CaseRecordType').value;
	var szCaseRecordID =  document.getElementById('CaseRecordID').value;
	var szCasSys = document.getElementById('CaseModuleCode').value;
	var szRefVal = document.getElementById('RefVal').value;

	document.location= szcURL_DM_APPROOT + '/document_uploadform.asp?caseno=' + szCaseRecordID + '&refval=' + szRefVal + '&casetype=' + szCaseRecordType + '&cassys=' + szCasSys;

}


function btnOpenDocPopUp(btn){
	
	//var bFileExists = getAttributeFromElement(btn,'filefound').value;
	var bFileExists = getAttributeFromElement(btn,'filefound');
	if (checkFileExists(bFileExists)){
	
	//	var szPopUpURL = getAttributeFromElement(btn,'path').value;
	//	var szMimeType = getAttributeFromElement(btn,'mime').value;
		
		var szPopUpURL = getAttributeFromElement(btn,'path');
		var szMimeType = getAttributeFromElement(btn,'mime');
	
		var szWinFeatures = "height=400,width=300,help=No,resizable=yes,status=yes";

		//open image files in pop up window
		if (szMimeType.indexOf("image/") != -1 && szMimeType.indexOf(".tif") !=1){
			
			//var rReturnVal ;
			
			szPopUpURL = szcURL_DM_APPROOT + '/document_imageview.aspx?path=' + szPopUpURL;
			var docWindow = window.open (szPopUpURL, 'document', szWinFeatures);
			docWindow.document.getElementById('assocdoc');
			
			//#todo: find a non-IE-specific way of returning values from windows
			//if (rReturnVal == -1)
			//	alert("The document could not be found.\nIt may have been deleted or moved.")
			
		}
		//file is not an image. let browser do the work
		else{
			lookupWin = window.open (szPopUpURL, '', "toolbar=no,menubar=no,scrollbars=yes,status=yes,resizable=yes");
			lookupWin.focus();
		}
	}
}

function btnGoToDetailView(btn){
	var bFileExists = getAttributeFromElement(btn,'filefound');
	var szDocID	= btn.docid;
	
	document.location = szcURL_DM_APPROOT + "/document_detailview.asp?docid=" + szDocID + "&found=" + bFileExists;
	
}


function checkFileExists(szFileFound){


	if (szFileFound.toLowerCase() == 'false'){
		alert("The document could not be found.\nIt may have been deleted or moved.");
		return false;
	}
	else 
		return true;
	
}



