


/**
 * Function to show the availability price popup 
 */
function showToolTipAvail(imagePath, e, status, bookUrl, turn) {
		var div = document.getElementById('availability_table_container');
		var obj = document.getElementById('avail_popup_balloon');
		var center = document.getElementById('avail_popup_balloon_content');
		var center_span = document.getElementById('avail_popup_balloon_content_span');
		var table = document.getElementById('avail_popup_table');
		var btn = document.getElementById('availPopupBookBtn');
		var btn2 = document.getElementById('availPopupBookBtnBookUrl');
		var blankImage = document.getElementById('blankImage');
		var inputs = document.getElementById('checkAvailability:popupHTML');
		var inner = inputs.innerHTML;
		var linkRow = document.getElementById('linkRow');
		var leftArr = document.getElementById('apPopupBorderTopArrow');
		var rightArr = document.getElementById('apPopupBorderTopArrow2');
			
		setBorderColor(status, imagePath);
		center_span.innerHTML = inner;
		
		
		
		if (status != 'BOOK' && status != 'ON REQUEST') {
			btn.style.display = 'none';
			linkRow.style.display = 'none';
		} else {
			btn.style.display = '';
			linkRow.style.display = '';
		}	
		btn2.style.display = 'none';
		if (bookUrl != null && bookUrl != '') {
			btn.style.display = 'none';
			linkRow.style.display = '';
			btn2.style.display = '';
			var onClck = function() {
				window.open(bookUrl,'','toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=1,width=1000,height=800,left=0,top=0');
			}
			btn2.onClick = onClck;
			btn2.onclick = onClck;
		}
				
		if (turn) {
			leftArr.style.display = 'none';
			leftArr.style.visibility = 'hidden';
			rightArr.style.display = '';
			rightArr.style.visibility = 'visible';
		} else {
			leftArr.style.display = '';
			leftArr.style.visibility = 'visible';
			rightArr.style.display = 'none';
			rightArr.style.visibility = 'hidden';
		}	
		
		var spanWidth = calculateWidth();
		var move = 0;
		
		var patternWidth = 127;
		
		if(spanWidth != null && spanWidth > patternWidth){
			move = spanWidth - patternWidth;
		}	
		
		var topPos = e.clientY;
		var leftPos = e.clientX;
		var leftSubPosition = -362;
		
		if(move != null){
			leftSubPosition = leftSubPosition - move;
		}	
		
		obj.style.left = ((turn ? leftSubPosition : -17) + (leftPos + 28)) + 'px';
		obj.style.top = (topPos + 6 + $('pagestart').scrollTop - 90) + 'px';
		if (obj.style.display != 'none') {
			obj.style.display = 'none';
		}
		
		
		Effect.toggle(document.getElementById('avail_popup_balloon'),'appear',{ duration:0.5,queue:'review' });
}
/**
 * Function calculates the real(not css one) width of the popup. 
 */
function calculateWidth(){
	var width = 0;
	var tracklingId = document.getElementById('tracklingIdRow');
	var main_container = document.getElementById('avail_popup_balloon');
	
	if(main_container != null && tracklingId != null){
		var text = tracklingId.innerHTML;
		
		if(text != null){
			main_container.style.visibility = 'hidden';
			main_container.style.display = 'block';
			
			var tempDiv = document.createElement('div');
			var tempSpan = document.createElement('span');
			var textNode = document.createTextNode(text);
			var con = document.getElementById('avContent');
			
			tempDiv.style.display = 'block';
			tempDiv.style.visibility = 'hidden';
			tempSpan.appendChild(textNode);
			tempDiv.appendChild(tempSpan);
			con.appendChild(tempDiv);
			width = tempSpan.offsetWidth;
			con.removeChild(tempDiv);	
					
			main_container.style.display = 'none';
			main_container.style.visibility = 'visible';

		}	
	}	
	
	return width;
	
}
/**
 * Function to set appropriate border colors on popup. 
 */
function setBorderColor(status, imagePath){
	if(status != null && imagePath!= null){
		var borderTDtop = document.getElementById('apPopupBorderTdTop');
		var borderTDleft = document.getElementById('apPopupBorderTdLeft');
		var borderTDright = document.getElementById('apPopupBorderTdRight');
		var borderTDbottom = document.getElementById('apPopupBorderTdBottom');
		var borderTopLeft = document.getElementById('apPopupBorderTopLeft');
		var borderTopRight = document.getElementById('apPopupBorderTopRight');
		var borderBottomLeft = document.getElementById('apPopupBorderBottomLeft');
		var borderBottomRight = document.getElementById('apPopupBorderBottomRight');
		var borderTopArrow = document.getElementById('apPopupBorderTopArrow');
		var borderTopArrow2 = document.getElementById('apPopupBorderTopArrow2');
		var borderLeftLink = document.getElementById('apPopupLeftLink');
		var borderRightLink = document.getElementById('apPopupLinkBack');
		var borderLinkBack = document.getElementById('apPopupRightLink');
		
		if(status != 'BOOK' && status != 'ON REQUEST'){
			if(borderTDtop != null){
				borderTDtop.style.backgroundImage = "url('" + imagePath + "avail_popup/top_gray.gif')";
			}	
			if(borderTDleft != null){
				borderTDleft.style.backgroundImage = "url('" + imagePath + "avail_popup/left_gray.gif')";
			}	
			if(borderTDright != null){
				borderTDright.style.backgroundImage = "url('" + imagePath + "avail_popup/right_gray.gif')";
			}	
			if(borderTDbottom != null){
				borderTDbottom.style.backgroundImage = "url('" + imagePath + "avail_popup/bottom_gray.gif')";
			}
			if(borderLeftLink != null){
				borderLeftLink.style.backgroundImage = "url('" + imagePath + "avail_popup/left_link.gif')";
			}
			if(borderRightLink != null){
				borderRightLink.style.backgroundImage = "url('" + imagePath + "avail_popup/link_back.gif')";
			}
			if(borderLinkBack != null){
				borderLinkBack.style.backgroundImage = "url('" + imagePath + "avail_popup/right_link.gif')";
			}
			if(borderTopLeft != null){
				borderTopLeft.src = imagePath + "avail_popup/top_left_gray.gif";
			}
			if(borderTopRight != null){
				borderTopRight.src = imagePath + "avail_popup/top_right_gray.gif";
			}
			if(borderBottomLeft != null){
				borderBottomLeft.src = imagePath + "avail_popup/bottom_left_gray.gif";
			}
			if(borderBottomRight != null){
				borderBottomRight.src = imagePath + "avail_popup/bottom_right_gray.gif";
			}
			if(borderTopArrow != null){
				borderTopArrow.src = imagePath + "avail_popup/arrow_left_gray.gif";
			}
			if(borderTopArrow2 != null){
				borderTopArrow2.src = imagePath + "avail_popup/arrow_right_gray.gif";
			}
		}else{
			if(borderTDtop != null){
				borderTDtop.style.backgroundImage = "url('" + imagePath + "avail_popup/top.gif')";
			}	
			if(borderTDleft != null){
				borderTDleft.style.backgroundImage = "url('" + imagePath + "avail_popup/left.gif')";
			}	
			if(borderTDright != null){
				borderTDright.style.backgroundImage = "url('" + imagePath + "avail_popup/right.gif')";
			}	
			if(borderTDbottom != null){
				borderTDbottom.style.backgroundImage = "url('" + imagePath + "avail_popup/bottom.gif')";
			}
			if(borderLeftLink != null){
				borderLeftLink.style.backgroundImage = "url('" + imagePath + "avail_popup/left_link.gif')";
			}
			if(borderRightLink != null){
				borderRightLink.style.backgroundImage = "url('" + imagePath + "avail_popup/link_back.gif')";
			}
			if(borderLinkBack != null){
				borderLinkBack.style.backgroundImage = "url('" + imagePath + "avail_popup/right_link.gif')";
			}
			if(borderTopLeft != null){
				borderTopLeft.src = imagePath + "avail_popup/top_left.gif";
			}
			if(borderTopRight != null){
				borderTopRight.src = imagePath + "avail_popup/top_right.gif";
			}
			if(borderBottomLeft != null){
				borderBottomLeft.src = imagePath + "avail_popup/bottom_left.gif";
			}
			if(borderBottomRight != null){
				borderBottomRight.src = imagePath + "avail_popup/bottom_right.gif";
			}
			if(borderTopArrow != null){
				borderTopArrow.src = imagePath + "avail_popup/arrow_left.gif";
			}
			if(borderTopArrow2 != null){
				borderTopArrow2.src = imagePath + "avail_popup/arrow_right.gif";
			}
		}	
	}	
}
/**
 *  Hides the availability price popup.
 */
function hideToolTipAvail(e) {
	if (document.getElementById('avail_popup_balloon').style.display != 'none' && window.dontClosePopup == false) {
		Effect.toggle(document.getElementById('avail_popup_balloon'),'appear',{duration :0.5,queue :'review'});
	}
	window.dontClosePopup = false;
}
/**
 * If true will not hide the price popup
 */
window.dontClosePopup = false;
/**
 * Shows error detail div on the availability popup. 
 */
function showHideErrorDetails() {
	window.dontClosePopup = true;
	if ($('pricePopupErrors').style.display == 'none') {
		$('pricePopupErrors').style.display = '';
		$('pricePopupErrors').previousSibling.innerHTML = '[-] details';
	} else {
		$('pricePopupErrors').style.display = 'none';
		$('pricePopupErrors').previousSibling.innerHTML = '[+] details';
	}
	return false;
}

