	
	var winDetail;
	var winCompany;
	var winEmail;
	var winActivity;
	var winHelp;
	var winDate;
	var winSelector;
	var winSpelling;
	var winEdit;
	var winWorkItem;

	
	function openDetail(strID){
	  var strURL = siteRoot + 'secure/person/personpopup.asp?FormMode=View&UserID=' + strID
	  if(winDetail && !winDetail.closed) { // window is open
	    winDetail.location = strURL;
	    winDetail.focus();
	  } else {
	    winDetail = window.open(strURL , 'RWFDetail', 'scrollbars=yes,status=yes,width=400,height=350,resizable=yes')
	  }
	}
	
	function openEdit(strFormName, myField){
		if(winEdit && !winEdit.closed) { // window is open
		  winEdit.execScript("SetNewText('" + strFormName + "','" + myField.name + "')")
		  winEdit.focus();
		} else {
			return openPopup('winEdit', event, myField.name, 600, 400, siteRoot + 'objects/richtext/edit.asp?fieldname=' + myField.name + '&formname=' + strFormName)
		}
	}
	
	function openWorkItemDetail(strQueryString){
		var strURL = siteRoot + 'secure/workitems/propertyworkitemdetail.asp?' + strQueryString + '&popup=yes'
		if(winWorkItem && !winWorkItem.closed) { // window is open
			winWorkItem.location = strURL;
		    winWorkItem.focus();
		} else {
			openPopup('winWorkItem', event, "", 800, 600, strURL, ',scrollbars=yes,status=yes', 'right')
			winWorkItem.focus()
		}
	}
			
	function openCompany(strID){
	  var strURL = siteRoot + 'secure/lendercompanies/default.asp?FormMode=View&LenderCompanyID=' + strID
	  if(winCompany && !winCompany.closed) { // window is open
	    winCompany.location = strURL;
	    winCompany.focus();
	  } else {
	    winCompany = window.open(strURL , 'RWFCompany', 'scrollbars=yes,status=yes,width=750,height=500,resizable=yes')
	  }
	}
				
	function openEmailPopup(strQueryString){
	  var strURL = siteRoot + 'secure/property/emailpopup.asp?' + strQueryString 
	  if(winEmail && !winEmail.closed) { // window is open
	    winEmail.location = strURL;
	    winEmail.focus();
	  } else {
	    winEmail = window.open(strURL , 'RWFEmail', 'scrollbars=yes,status=yes,width=750,height=500,resizable=yes')	
	  }
	}
	
	function openActivityPopup(strQueryString){
	  var strURL = siteRoot + 'secure/workitems/activitypopup.asp?' + strQueryString 
	  if(winActivity && !winActivity.closed) { // window is open
	    winActivity.location = strURL;
	    winActivity.focus();
	  } else {
	    winActivity = window.open(strURL , 'RWFEmail', 'scrollbars=yes,status=yes,width=600,height=500,resizable=yes')	
	  }
	}
		function openHelp(strField){
		var strURL = siteRoot + 'help/help.asp?Field=' + strField
		if(winHelp && !winHelp.closed) { // window is open
			winHelp.location = strURL;
			winHelp.focus();
		} else {
			winHelp = window.open(strURL , 'RWFHelp', 'scrollbars=yes,status=yes,width=400,height=350,resizable=yes')	
		}
	}
	
	function openPopup(strWin, event, thisFieldName, intWidth, intHeight, strURLBase, strOptions, varLocation){ 
		var intXlocation;   
		var intYlocation; 
		var strURL;  
		var oWin;
		switch(strWin){
			case 'winDate': if(winDate){oWin = winDate;}; break;
			case 'winSelector': if(winSelector){oWin = winSelector}; break;
			case 'winSpelling': if(winSpelling){oWin = winSpelling}; break;
			case 'winEdit': if(winEdit){oWin = winEdit}; break;
			return false;
		}
	   
	  	if(event){ 
			if(event.screenX + 5 + intWidth > screen.availWidth) {
	       		intXlocation = event.screenX + 5 - intWidth;
			} else {
	       		intXlocation = event.screenX + 5;
	       	}
			if(event.screenY + 5 + intHeight > screen.availHeight) {
	       		intYlocation = event.screenY - 50 - intHeight;
			} else {
				if(event.screenX + 5 + intWidth > screen.availWidth) {
					intYlocation = event.screenY + 15; 
				} else {
	       			intYlocation = event.screenY + 5; 
	       		}
			}	
		} else {
			if(varLocation == 'right') {
				intXlocation = screen.availWidth - intWidth - 20
				intYlocation = 100;
			} else {
				intXlocation = 100;  
				intYlocation = 100;
			}
		}
						
		if(strURLBase.indexOf("?") > 0){
			strURL = strURLBase  + '&ReturnField=' + thisFieldName  ; 
		} else {
			strURL = strURLBase  + '?ReturnField=' + thisFieldName  ;
		}
		if(oWin && !oWin.closed) { // window is open 
		    oWin.moveTo(intXlocation, intYlocation); 
		    oWin.location = strURL; 
		    oWin.focus(); 
		} else {  
		 	oWin = window.open(strURL , strWin, 'dependent=yes,scrollbars=no,status=no,width=' + intWidth + ',height=' + intHeight + ',resizable=yes,' + 'top=' + intYlocation + ',screenY=' + intYlocation + ', left=' + intXlocation + ',screenX=' + intXlocation + strOptions)	 
		 	switch(strWin){
		 		case 'winDate':  winDate= oWin; break;
		 		case 'winSelector': winSelector= oWin; break;
		 		case 'winSpelling': winSpelling= oWin; break;
		 		case 'winEdit': winEdit= oWin; break;
		 		case 'winWorkItem': winWorkItem= oWin; break;
			}
		} 
	} 
	
	function openwinDate(event, thisFieldName){
		return openPopup('winDate', event, thisFieldName, 175, 175,	siteRoot + 'objects/datepickerpage.asp?termtype=')
	}
	
	function openwinSelector(event, thisFieldName, listName){
		if((listName + '') == ''){listName = thisFieldName}; 
	    var strURL =siteRoot + 'objects/selector.asp?termtype='  + listName 
		return openPopup('winSelector', event, thisFieldName, 175, 175,	strURL)
	} 
	
	function cleanupPopups(){
		if(winSelector && !winSelector.closed){winSelector.close()}
		if(winSpelling && !winSpelling.closed){winSpelling.close()}
		if(winEdit && !winEdit.closed){winEdit.close()}
		if(winDate && !winDate.closed){winDate.close()}
		if(winDetail && !winDetail.closed){winDetail.close()}
		if(winCompany && !winCompany.closed){winCompany.close()}
		if(winEmail && !winEmail.closed){winEmail.close()}
		if(winActivity && !winActivity.closed){winActivity.close()}
		if(winHelp && !winHelp.closed){winHelp.close()}
	}
	window.onunload = cleanupPopups;
	
	
	
	
	
	
	// Go to next page handling
	// nextPage variable is set in js script immediately before this call
	function goNext(){
	  if(checkChanged()){
	    window.location = nextPage;
	    return true; 
	  } else {return false;}
	}

	// check for changed items before moving to next page
	var mintChanged = false;
	function checkChanged(){
	  if(mintChanged){
		  if(confirm('You have not saved your changes. Do you want to continue without saving?'))
			{return true;} 
			else {return false;}
	  } else { return true; }
	}
	

	// ----- DEFAULT HANDLING
	function clearDefault(varField){
		var oForm = varField.form; 
		if(oForm["default_" + varField.name]){
		   if((oForm["default_" + varField.name].value == 1)
		  && (oForm[varField.name].value.length > 0))	{

		     oForm["image_" + varField.name].src = siteRoot + "images/defaultoverridden.gif"
		     oForm["default_" + varField.name].value = 2
		   }
		   else { 
		     if(oForm[varField.name].value.length == 0){
		        oForm["default_" + varField.name].value = 1;
		        oForm["image_" + varField.name].src = siteRoot + "images/default.gif"
		     }
		   }
		} 
	}
	
	