function viewAdvanceCriteria(isView) {
	if (isView) {
		$('showIcon').style.display = "none";
		$('hideIcon').style.display = "block";
		$('advanceCriteriaDiv').style.display = "block";
	} else {
		if($('advanceCriteriaDiv') != null){
			$('advanceCriteriaDiv').style.display = "none";
			$('showIcon').style.display = "block";
			$('hideIcon').style.display = "none";
		}
	}
}

function getRequirement(reqId, count) {
	showWaiting();
	var ajaxRequest = new Ajax.Request('dashboardRequirement.action', {
		method :'post',
		parameters :reqId + '&isAjax=true',
		onSuccess : function(transport) {
			if (transport.responseText == "exception") {
				hideWaiting();
				openModalWindow('errorModalWindow');
			} else if (transport.responseText == "sessionOut") {
				sendTo("sessionError");
			} else {
				$('buyerReqDiv').innerHTML = transport.responseText;
				selectReqTab(count);
				var address="";
				if($("SpcPro")!=null){
				 address=$("SpcPro").innerHTML;
				}
				if(!(strTrimmer(address)=="")){
					mapAddress(address, 'reqMap');
					
				}else{
					mapAddress($("cityStateZip").innerHTML, "reqMap");
				}				
				initalizetooltip();
				hideWaiting();
			}
		},
		onFailure : function(transport) {
			hideWaiting();
			openModalWindow('errorModalWindow');
		},
		onException : function(transport) {
			hideWaiting();
			openModalWindow('errorModalWindow');
		}
	});
}

function getProperty(propertyId, count) {
	showWaiting();
	var ajaxRequest = new Ajax.Request('dashboardProperty.action', {
		method :'post',
		parameters :propertyId + '&isAjax=true',
		onSuccess : function(transport) {
			if (transport.responseText == "exception") {
				hideWaiting();
				openModalWindow('errorModalWindow');
			} else if (transport.responseText == "sessionOut") {
				sendTo("sessionError");
			} else {
				$('propertyDiv').innerHTML = transport.responseText;
				selectPropertyTab(count);
				if($('mkOfferBRId').value != "" && $('mkOfferBRId').value != "null"){
					if($('isPropActive').value == "1"){
						$('mkOfferBtn').style.display = 'block';
					}
				}
				var address="";
				if($("proAddress")!=null){
					 address=$("proAddress").innerHTML;
					 address=address + ",";
				}
				if($("proCityState")!=null && address!=""){
					 address=address + $("proCityState").innerHTML + ",";
				}
				
				if(!(strTrimmer(address)=="")){		
						address=strCommaTrimmer1(address);
						address=address+ ", " + $("zipcode").innerHTML;	
						mapAddress(address, "propMap", 1);						
					}else{
						mapAddress($("zipcode").innerHTML, "propMap", 1);
				}
				hideWaiting();
			}
		},
		onFailure : function(transport) {
			hideWaiting();
			openModalWindow('errorModalWindow');
		},
		onException : function(transport) {
			hideWaiting();
			openModalWindow('errorModalWindow');
		}
	});
}

function selectReqTab(count) {
	if ($('profileCompleteDiv') != null) {
		$('profileCompleteDiv').innerHTML = $('profileComplete').value;
		$('percBar').style.width = $('profileCompleteDiv').innerHTML + "%";
	}
	if ($('bidsRecvdDiv') != null) {
		$('bidsRecvdDiv').innerHTML = $('bidsRecvd').value;
	}
	var size = $('noOfReq').value;
	for ( var i = 1; i <= size; i++) {
		if (count == i) {
			$('req' + i).className = "tabsI_2";
		} else {
			$('req' + i).className = "";
		}
	}
}

function selectPropertyTab(count) {
	if ($('bidsSentDiv') != null) {
		$('bidsSentDiv').innerHTML = $('bidsSent').value;
	}
	var size = $('noOfProperty').value;
	for ( var i = 1; i <= size; i++) {
		if (count == i) {
			$('prop' + i).className = "tabsI_2";
		} else {
			$('prop' + i).className = "";
		}
	}
}
function openNotificationWindow(notificationId, index, bidId) {
	notificationType = $('ntfType' + index).innerHTML;
	user = $('usr' + index).innerHTML;
	notification = $('ntf' + index).innerHTML;;
	if (notificationType == "Offer Held" || notificationType == "Offer Accepted" || notificationType == "Offer Rejected") {
		openBidNtfWindow(notificationType, notificationId, index);
	} else if (notificationType == "New Offer") {
		viewBid(bidId, false, notificationId, index);
	} else {
		$('notifyType').innerHTML = notificationType;
		$('notifyUser').innerHTML = user;
		$('notifyMessage').innerHTML = notification;
		openModalWindow('NotificationModalWindow');
		changeNtfStatus(index, notificationId);
	}
}

function changeNtfStatus(index, notificationId){
	if ($('status' + index).value == "1") {
		var ajaxRequest = new Ajax.Request('notification.action', {
			method :'post',
			parameters :'notificationId=' + notificationId,
			onSuccess : function(transport) {
			},
			onFailure : function(transport) {
			},
			onException : function(transport) {
			}
		});
		changeNtfStyle(index);
	}
}

function changeNtfStyle(index){
	if ($('status' + index).value == "1") {
		$('status' + index).value = "0";
		$('msgTr' + index).style.fontWeight = "normal";

		$('newAlert').innerHTML = $('newAlert').innerHTML - 1;
		if ($('newAlert').innerHTML == "0") {
			$('newNotificationDiv').style.display = "none";
		}
		if ($('newAlert').innerHTML == "1") {
			$('ntfText').innerHTML = "notification";
		}
	}
}

function openBidNtfWindow(notificationType, notificationId, index) {
	showWaiting();
	changeNtfStyle(index);
	if (notificationType == "Offer Held") {
		actionName = 'holdNtf.action'
	} else if (notificationType == "Offer Accepted") {
		actionName = 'acceptNtf.action'
	} else if (notificationType == "Offer Rejected") {
		actionName = 'rejectNtf.action'
	}
	var ajaxRequest = new Ajax.Request(actionName, {
		method :'post',
		parameters :'notificationId=' + notificationId + '&isAjax=true',
		onSuccess : function(transport) {
			if (transport.responseText == "exception") {
				hideWaiting();
				openModalWindow('errorModalWindow');
			} else if (transport.responseText == "sessionOut") {
				sendTo("sessionError");
			} else {
				$('bidNtfModalWindow').innerHTML = transport.responseText;
				openModalWindow('bidNtfModalWindow');
				hideWaiting();
			}
		},
		onFailure : function(transport) {
			hideWaiting();
			openModalWindow('errorModalWindow');
		},
		onException : function(transport) {
			hideWaiting();
			openModalWindow('errorModalWindow');
		}
	});
}

function editBR() {
	$('editRequirement').submit();
}

function confirmDeleteBR(){
	$('confirmMsg').innerHTML = "Are you sure you want to delete this requirement?";
	openModalWindow('confirmModalWindow');
	$('yesBtn').href = "javascript:closeModalWindow('confirmModalWindow');deleteBR();";
}

function deleteBR() {
	$('editRequirement').action = "/deleteRequirement";
	$('editRequirement').submit();
}

function editProp() {
	$('editProperty').submit();
}

function confirmDeleteProp(){
	$('confirmMsg').innerHTML = "Are you sure you want to delete this property?";
	openModalWindow('confirmModalWindow');
	$('yesBtn').href = "javascript:closeModalWindow('confirmModalWindow');deleteProp();";
}

function deleteProp() {
	$('editProperty').action = "/deleteProperty";
	$('editProperty').submit();
}

function viewBid(bidId, isSeller, notificationId, ntfIndex) {
	var otherNewBidMsg = "Please respond to your previous offers before viewing this offer. Offers must be acted on in the order they are received.";
	var actionName = '';
	if(isSeller){
		actionName = 'viewOffer.action';
	}else{
		actionName = 'newBid.action';
	}
	
	showWaiting();
		var ajaxRequest = new Ajax.Request(actionName, {
			method :'post',
			parameters :'encBidId=' + bidId + '&isAjax=true',
			onSuccess : function(transport) {
				if (transport.responseText == "exception") {
					hideWaiting();
					openModalWindow('errorModalWindow');
				} else if (transport.responseText == "sessionOut") {
					sendTo("sessionError");
				} else if (transport.responseText == "newBidExists") {
					$('popupMsgDiv').innerHTML = otherNewBidMsg;
					openModalWindow('popupMsgModalWindow');
				} else {
					$('newOfferModalWindow').innerHTML = transport.responseText;
					openModalWindow('newOfferModalWindow');
					initalizetooltip();
					$('encBidId').value = bidId;
					if(isSeller){
						$('statusDivId').value = "";
						$('rejectOfferImg').src = "content/Images/btn_profile_03_fade.png";
						$('holdOfferImg').src = "content/Images/btn_profile_05_fade.png";
						$('acceptOfferImg').src = "content/Images/btn_profile_07_fade.jpg";
						$('reportAbuseImage').src = "content/Images/inappropriate_use_fade.gif";
						$('reportAbuseImg').onclick = "";
					}
					if(notificationId != 0 && notificationId != '0'){
						changeNtfStatus(ntfIndex, notificationId);
					}
				}
				hideWaiting();
			},
			onFailure : function(transport) {
				hideWaiting();
				openModalWindow('errorModalWindow');
			},
			onException : function(transport) {
				hideWaiting();
				openModalWindow('errorModalWindow');
			}
		});
}

function openBidActionWindow(status) {
	var actionName;
	var bidStatus = $('statusDivId').value;
	if (bidStatus != "" && (bidStatus == "New"
			|| (bidStatus == "Held" && status != "hold"))) {
		showWaiting();
		if (status == "reject") {
			actionName = 'rejectOffer.action'
		} else if (status == "hold") {
			actionName = 'holdOffer.action'
		} else if (status == "accept") {
			actionName = 'acceptOffer.action'
		}
		var ajaxRequest = new Ajax.Request(actionName, {
			method :'post',
			parameters :'&isAjax=true',
			onSuccess : function(transport) {
				if (transport.responseText == "sessionOut") {
					sendTo("sessionError");
				}else{
					$('OfferStatusModalWindow').innerHTML = transport.responseText;
					closeModalWindow('newOfferModalWindow');
					openModalWindow('OfferStatusModalWindow');
					hideWaiting();
				}
			},
			onFailure : function(transport) {
				hideWaiting();
				openModalWindow('errorModalWindow');
			},
			onException : function(transport) {
				hideWaiting();
				openModalWindow('errorModalWindow');
			}
		});
	}
}

function changeBidStatus(status) {
	var acceptOfferMsg = "e.g. This looks like a great offer, let's chat. I can be reached at 510-555-1234. My email is barrybuyer@gmail.com. Or, you can speak to my agent, Andy Agent, at 510-555-4321.";
	var holdOfferMsg = "e.g. Can you clarify the size of the yard? When can I view the property?";
	var rejectOfferMsg = "e.g. I'd like to live closer to public transportation.";
	
	if(status == "hold" && $("bidDto.statusText").value == holdOfferMsg){
		$('offerErrorDiv').innerHTML = "All the fields are mandatory!";
	}else if(status == "accept" && $("bidDto.statusText").value == acceptOfferMsg){
		$('offerErrorDiv').innerHTML = "All the fields are mandatory!";
	}else if(status == "reject" && $("bidDto.statusText").value == rejectOfferMsg){
		$('offerErrorDiv').innerHTML = "All the fields are mandatory!";
	}else if (strTrimmer($("bidDto.statusText").value) == "") {
		$('offerErrorDiv').innerHTML = "All the fields are mandatory!";
	}else if (($("bidDto.statusText").value).length >500) {
		$('offerErrorDiv').innerHTML = "Max 500 characters allowed!";
	}else {
		showWaiting();
		var ajaxRequest = new Ajax.Request($('updateBidStatus').action, {
			method :'post',
			parameters :Form.serialize($('updateBidStatus'), false)
					+ '&encBidId=' + $('encBidId').value + '&bidStatus='
					+ status + '&notificationDto.toUserId='
					+ $('sellerId').value + '&isAjax=true',
			onSuccess : function(transport) {
				if (transport.responseText == "exception") {
					hideWaiting();
					closeModalWindow('OfferStatusModalWindow');
					openModalWindow('errorModalWindow');
				} else if (transport.responseText == "sessionOut") {
					sendTo("sessionError");
				} else {
					var currentUrl = window.location.toString();
					if(currentUrl.indexOf("dashboard") != -1) {
						sendTo("dashboard");
					} else if(currentUrl.indexOf("buyingClient") != -1) {
						sendTo("buyingClient");
					} else if(currentUrl.indexOf("sellingClient") != -1) {
						sendTo("sellingClient");
					}
				}
			},
			onFailure : function(transport) {
				hideWaiting();
				closeModalWindow('OfferStatusModalWindow');
				openModalWindow('errorModalWindow');
			},
			onException : function(transport) {
				hideWaiting();
				closeModalWindow('OfferStatusModalWindow');
				openModalWindow('errorModalWindow');
			}
		});
	}
}

function openNewMsgWindow(msgTo) {
	if (msgTo == 'buyerAgent') {
		$("recipient").value = $("buyerAgent").value;
		$("ntfToUserId").value = $("buyerAgentId").value;
	} else if (msgTo == 'myAgent') {
		$("recipient").value = $("myAgent").value;
		$("ntfToUserId").value = $("myAgentId").value;
	} else if (msgTo == 'buyer') {
		$("recipient").value = getEightCharString($("buyerId").value);
		$("ntfToUserId").value = $("buyerId").value;
	}
	closeModalWindow('bidNtfModalWindow');
	openModalWindow('newMsgModalWindow');
}

function sendMessage() {
	if (strTrimmer($("notificationDto.notification").value) == "") {
		$('msgErrorDiv').innerHTML = "All the fields are mandatory!";
	} else {
		showWaiting();
		var ajaxRequest = new Ajax.Request('sendNtf.action', {
			method :'post',
			parameters :$('notificationDto.notification').serialize(true)
					+ '&notificationDto.toUserId=' + $('ntfToUserId').value
					+ '&isAjax=true',
			onSuccess : function(transport) {
				if (transport.responseText == "exception") {
					hideWaiting();
					closeModalWindow('newMsgModalWindow');
					openModalWindow('errorModalWindow');
				} else if (transport.responseText == "sessionOut") {
					sendTo("sessionError");
				} else {
					$('notificationDto.notification').value = "";
					$('msgErrorDiv').innerHTML = "";
					closeModalWindow('newMsgModalWindow');
					hideWaiting();
				}
			},
			onFailure : function(transport) {
				hideWaiting();
				closeModalWindow('newMsgModalWindow');
				openModalWindow('errorModalWindow');
			},
			onException : function(transport) {
				hideWaiting();
				closeModalWindow('newMsgModalWindow');
				openModalWindow('errorModalWindow');
			}
		});
	}
}

function closeNewMsgWindow() {
	$('notificationDto.notification').value = "";
	$('msgErrorDiv').innerHTML = "";
	closeModalWindow('newMsgModalWindow');
	if($('bidNtfModalWindow')){
		openModalWindow('bidNtfModalWindow');
	}
}
function authResponse(authStr) {
	showWaiting();
	var ajaxRequest = new Ajax.Request('authResponse.action',
	{
		method: 'post',
		parameters: {authId:authStr, isAjax:true},
		onSuccess:function(transport){
			sendTo("dashboard");
		},
		onFailure:function(transport){
			closeModalWindow('NotificationModalWindow');
			openModalWindow('errorModalWindow');
			hideWaiting();
		},
		onException:function(transport){
			closeModalWindow('NotificationModalWindow');
			openModalWindow('errorModalWindow');
			hideWaiting();
		}
	});
}

function activateBR(brId, authBuyer) {
	closeModalWindow('NotificationModalWindow');
	showWaiting();
	var ajaxRequest = new Ajax.Request('activateReq.action', {
		method :'post',
		parameters :'bRDto.encBuyerReqId='+brId + '&authBuyer='+authBuyer + '&isAjax=true',
		onSuccess : function(transport) {
			if (transport.responseText == "exception") {
				hideWaiting();
				openModalWindow('errorModalWindow');
			} else if (transport.responseText == "sessionOut") {
				sendTo("sessionError");
			} else {
				sendTo("dashboard");
			}
		},
		onFailure : function(transport) {
			hideWaiting();
			openModalWindow('errorModalWindow');
		},
		onException : function(transport) {
			hideWaiting();
			openModalWindow('errorModalWindow');
		}
	});
}

function activatePD(pdId) {
	closeModalWindow('NotificationModalWindow');
	showWaiting();
	var ajaxRequest = new Ajax.Request('activateProp.action', {
		method :'post',
		parameters :'propertyDto.encPropertyId='+pdId + '&isAjax=true',
		onSuccess : function(transport) {
			if (transport.responseText == "exception") {
				hideWaiting();
				openModalWindow('errorModalWindow');
			} else if (transport.responseText == "sessionOut") {
				sendTo("sessionError");
			} else {
				sendTo("dashboard");
			}
		},
		onFailure : function(transport) {
			hideWaiting();
			openModalWindow('errorModalWindow');
		},
		onException : function(transport) {
			hideWaiting();
			openModalWindow('errorModalWindow');
		}
	});
}

function viewBidToConfirm(bidId) {
	closeModalWindow('NotificationModalWindow');
	showWaiting();
	var ajaxRequest = new Ajax.Request('viewOffer.action', {
		method :'post',
		parameters :'encBidId=' + bidId + '&isAjax=true',
		onSuccess : function(transport) {
			if (transport.responseText == "exception") {
				hideWaiting();
				openModalWindow('errorModalWindow');
			} else if (transport.responseText == "sessionOut") {
				sendTo("sessionError");
			} else {
				$('newOfferModalWindow').innerHTML = transport.responseText;
				$('offerActionDiv').style.display = 'none';
				$('confirmOfferDiv').style.display = 'block';
				openModalWindow('newOfferModalWindow');
				$('encBidId').value = bidId;
				hideWaiting();
			}
		},
		onFailure : function(transport) {
			hideWaiting();
			openModalWindow('errorModalWindow');
		},
		onException : function(transport) {
			hideWaiting();
			openModalWindow('errorModalWindow');
		}
	});
}

function activateBid() {
	bidId = $('encBidId').value;
	closeModalWindow('newOfferModalWindow');
	showWaiting();
	var ajaxRequest = new Ajax.Request('activateBid.action', {
		method :'post',
		parameters :'encBidId='+bidId + '&isAjax=true',
		onSuccess : function(transport) {
			if (transport.responseText == "exception") {
				hideWaiting();
				openModalWindow('errorModalWindow');
			} else if (transport.responseText == "sessionOut") {
				sendTo("sessionError");
			} else {
				sendTo("dashboard");
			}
		},
		onFailure : function(transport) {
			hideWaiting();
			openModalWindow('errorModalWindow');
		},
		onException : function(transport) {
			hideWaiting();
			openModalWindow('errorModalWindow');
		}
	});
}

function addAgent(agentEmail) {
	closeModalWindow('NotificationModalWindow');
	showWaiting();
	var ajaxRequest = new Ajax.Request('addAgent.action', {
		method :'post',
		parameters :'agentEmail='+agentEmail + '&isAjax=true',
		onSuccess : function(transport) {
			if (transport.responseText == "exception") {
				hideWaiting();
				openModalWindow('errorModalWindow');
			} else if (transport.responseText == "sessionOut") {
				sendTo("sessionError");
			} else {
				sendTo("dashboard");
			}
		},
		onFailure : function(transport) {
			hideWaiting();
			openModalWindow('errorModalWindow');
		},
		onException : function(transport) {
			hideWaiting();
			openModalWindow('errorModalWindow');
		}
	});
}


function delReq(brId) {
	closeModalWindow('NotificationModalWindow');
	showWaiting();
	var ajaxRequest = new Ajax.Request('deleteRequirement.action', {
		method :'post',
		parameters :'encBuyerReqId='+brId + '&isAjax=true',
		onSuccess : function(transport) {
			if (transport.responseText == "exception") {
				hideWaiting();
				openModalWindow('errorModalWindow');
			} else if (transport.responseText == "sessionOut") {
				sendTo("sessionError");
			} else {
				hideWaiting();
				sendTo("dashboard");
			}
		},
		onFailure : function(transport) {
			hideWaiting();
			openModalWindow('errorModalWindow');
		},
		onException : function(transport) {
			hideWaiting();
			openModalWindow('errorModalWindow');
		}
	});
}

function delProp(pdId) {
	closeModalWindow('NotificationModalWindow');
	showWaiting();
	var ajaxRequest = new Ajax.Request('deleteProperty.action', {
		method :'post',
		parameters :'encPropertyId='+pdId + '&isAjax=true',
		onSuccess : function(transport) {
			if (transport.responseText == "exception") {
				hideWaiting();
				openModalWindow('errorModalWindow');
			} else if (transport.responseText == "sessionOut") {
				sendTo("sessionError");
			} else {
				hideWaiting();
				sendTo("dashboard");
			}
		},
		onFailure : function(transport) {
			hideWaiting();
			openModalWindow('errorModalWindow');
		},
		onException : function(transport) {
			hideWaiting();
			openModalWindow('errorModalWindow');
		}
	});
}

function addAgentAndBR(agentEmail, brId, authBuyer) {
	closeModalWindow('NotificationModalWindow');
	showWaiting();
	var ajaxRequest = new Ajax.Request('addAgentBR.action', {
		method :'post',
		parameters :'encBuyerReqId='+brId+'&agentEmail='+agentEmail + '&authBuyer='+authBuyer + '&isAjax=true',
		onSuccess : function(transport) {
			if (transport.responseText == "exception") {
				hideWaiting();
				openModalWindow('errorModalWindow');
			} else if (transport.responseText == "sessionOut") {
				sendTo("sessionError");
			} else {
				hideWaiting();
				sendTo("dashboard");
			}
		},
		onFailure : function(transport) {
			hideWaiting();
			openModalWindow('errorModalWindow');
		},
		onException : function(transport) {
			hideWaiting();
			openModalWindow('errorModalWindow');
		}
	});
}

function addAgentAndPD(agentEmail, pdId) {
	closeModalWindow('NotificationModalWindow');
	showWaiting();
	var ajaxRequest = new Ajax.Request('addAgentPD.action', {
		method :'post',
		parameters :'encPropertyId='+pdId+'&agentEmail='+agentEmail + '&isAjax=true',
		onSuccess : function(transport) {
			if (transport.responseText == "exception") {
				hideWaiting();
				openModalWindow('errorModalWindow');
			} else if (transport.responseText == "sessionOut") {
				sendTo("sessionError");
			} else {
				hideWaiting();
				sendTo("dashboard");
			}
		},
		onFailure : function(transport) {
			hideWaiting();
			openModalWindow('errorModalWindow');
		},
		onException : function(transport) {
			hideWaiting();
			openModalWindow('errorModalWindow');
		}
	});
}
function viewAdvanceCriteria1(isView) {
	if (isView) {
		$('showIcon1').style.display = "none";
		$('hideIcon1').style.display = "block";
		$('advanceCriteriaDiv1').style.display = "block";
	} else {
		$('advanceCriteriaDiv1').style.display = "none";
		$('showIcon1').style.display = "block";
		$('hideIcon1').style.display = "none";
	}
}
function viewAdvanceCriteriaOffer(isView) {
	if (isView) {
		$('showIconOffer').style.display = "none";
		$('hideIconOffer').style.display = "block";
		$('modalBackgroundDiv').style.height = 
			(getTotalWinHeight()+Element.getDimensions($('advanceCriteriaDivOffer')).height) + 'px';
		$('advanceCriteriaDivOffer').style.display = "block";
	} else {
		$('advanceCriteriaDivOffer').style.display = "none";
		$('modalBackgroundDiv').style.height = getTotalWinHeight() + 'px';
		$('showIconOffer').style.display = "block";
		$('hideIconOffer').style.display = "none";
	}
}

function addMyClient(agentEmail, usrId) {
	closeModalWindow('NotificationModalWindow');
	showWaiting();
	var ajaxRequest = new Ajax.Request('addClient.action', {
		method :'post',
		parameters :'agentEmail='+agentEmail+'&encUserId=' + usrId + '&isAjax=true',
		onSuccess : function(transport) {
			if (transport.responseText == "exception") {
				hideWaiting();
				openModalWindow('errorModalWindow');
			} else if (transport.responseText == "sessionOut") {
				sendTo("sessionError");
			} else {
				sendTo("dashboard");
			}
		},
		onFailure : function(transport) {
			hideWaiting();
			openModalWindow('errorModalWindow');
		},
		onException : function(transport) {
			hideWaiting();
			openModalWindow('errorModalWindow');
		}
	});
}

function unlinkTheAgent(){
	$('confirmMsg').innerHTML = "Are you sure you want to unlink this Agent?";
	openModalWindow('confirmModalWindow');
	$('yesBtn').href = "/unlinkAgent";
}

function unlinkTheLender(){
	$('confirmMsg').innerHTML = "Are you sure you want to unlink this Lender?";
	openModalWindow('confirmModalWindow');
	$('yesBtn').href = "/unlinkLender";
}

function viewBid(bidId, isSeller, notificationId, ntfIndex,role) {
	var otherNewBidMsg = "Please respond to your previous offers before viewing this offer. Offers must be acted on in the order they are received.";
	var newMsgLender = "You can view this offer once your buying client responds to the previous offers";
	var actionName = '';
	if(isSeller){
		actionName = 'viewOffer.action';
	}else{
		actionName = 'newBid.action';
	}
	
	showWaiting();
		var ajaxRequest = new Ajax.Request(actionName, {
			method :'post',
			parameters :'encBidId=' + bidId + '&isAjax=true',
			onSuccess : function(transport) {
				if (transport.responseText == "exception") {
					hideWaiting();
					openModalWindow('errorModalWindow');
				} else if (transport.responseText == "sessionOut") {
					sendTo("sessionError");
				} else if (transport.responseText == "newBidExists") {
				    if(role == "4")
					  $('popupMsgDiv').innerHTML = newMsgLender;
					else
					  $('popupMsgDiv').innerHTML = otherNewBidMsg;
					  openModalWindow('popupMsgModalWindow');
				} else {
					$('newOfferModalWindow').innerHTML = transport.responseText;
					openModalWindow('newOfferModalWindow');
					initalizetooltip();
					$('encBidId').value = bidId;
					if(isSeller){
						$('statusDivId').value = "";
						if($('rejectOfferImg')!=null){
						$('rejectOfferImg').src = "content/Images/btn_profile_03_fade.png";
						}
						if($('holdOfferImg')!=null){
						$('holdOfferImg').src = "content/Images/btn_profile_05_fade.png";
						}
						if($('acceptOfferImg')!=null){
						$('acceptOfferImg').src = "content/Images/btn_profile_07_fade.jpg";
						}
						if($('reportAbuseImage')!=null){
						$('reportAbuseImage').src = "content/Images/inappropriate_use_fade.gif";
						}
						if($('reportAbuseImg')!=null){
						$('reportAbuseImg').onclick = "";
						}
					}
					if(notificationId != 0 && notificationId != '0'){
						changeNtfStatus(ntfIndex, notificationId);
					}
				}
				hideWaiting();
			},
			onFailure : function(transport) {
				hideWaiting();
				openModalWindow('errorModalWindow');
			},
			onException : function(transport) {
				hideWaiting();
				openModalWindow('errorModalWindow');
			}
		});
}