function mycart(objDiv) {
	this.DisplayMode = 2;  // 0 = hide, 1 = min, 2 = max
	this.DisplayType = 'L'; // A is agent L is listing

	this.Layer = objDiv;
	this.Listings = new Array(0);

	this.LayerY = objDiv.offsetTop;
	this.LayerStartY = objDiv.offsetTop>236 ? 236:objDiv.offsetTop ;
	this.myCartHTML = '<div id=mycart onClick="if(objMycart != null) objMycart.Draw()"></div>'
	this.PadHTML = this.myCartHTML ;

	// methods
	this.AddListing = NPAddListing;
	this.DeleteListing = NPDeleteListing;
	this.GenContentHTML = NPGenContentHTML;
	this.OnScroll = NPOnScroll;
	this.Minimize = NPMinimize;
	this.SaveToCookie = NPSaveToCookie;
	this.LoadFromCookie = NPLoadFromCookie;
	this.Draw = NPDraw;
	this.WriteLayer = NPWriteLayer;
	this.LoadFromCookie('L')
	this.Draw();
	window.blnNotePadJSLoaded = true;
}

// --- BEGIN OBJECT METHODS ---
function NPAddListing(strMLNUM, strAddress) {
	var blnAlready = false;
	if(this.Listings.length > 0)
		for(var i = 0;  i < this.Listings.length;  ++i)
			if(this.Listings[i].MLNUM == strMLNUM)
				blnAlready = true;

	if(blnAlready)
		alert('You have already added ' + strAddress + ' to MyCart.\n');
	else if(this.Listings.length >= 8)
		alert('MyCart is full.  You may free up space in MyCart by deleting one or more listings.\n');
	else {
		var objListing = new jsListing();
		objListing.MLNUM = strMLNUM;
		objListing.Address = strAddress;
		this.Listings[this.Listings.length] = objListing;
	}
	this.Draw();
	
}

function NPDeleteListing(strMLNUM) {
	var newListings = new Array();
	if(this.Listings.length > 0) {
		for(var i = 0;  i < this.Listings.length;  ++i)
			if(this.Listings[i].MLNUM != strMLNUM) {
				newListings[newListings.length] = this.Listings[i];
			}
		this.Listings = newListings;
	}
	this.Draw();
}

function NPGenContentHTML() {
	var strAgentTableHTML = '';
	var strListingTableHTML = '';
	
	if(this.Listings.length == 0 ) {
		this.myCartHTML = '<div>' +
							'<div class="sectionHeader" style="text-align:center"><img src="../images/lineart/lineart_addtocart.gif"> <span class="mdTextBold blue">MyCart</span> <span class="smText">( 0 Listings ) </span></div>' +
							'</div>'	
		this.PadHTML = this.myCartHTML;
	}
	else {
		var strHTML = '';
		var strLinkHTML
		var objAgent, strMember_Number, strANAME;
		var objListing, strMLNUM, strAddress, strListingPrice, strListAgent, strListOffice
		
			this.myCartHTML = '<div>' +
							'<div class="sectionHeader" style="text-align:center"><img src="../images/lineart/lineart_addtocart.gif" border="0"><a href="mycartCompare.cfm?menu=1"><span class="mdTextBold blue">MyCart</span></a> ( <span class="smText red">' + this.Listings.length   + '</span><span class="smText"> Listings </span> )  &nbsp; <img src="http://www.har.com/images/lineart/lineart_contract.gif" onClick="objMycart.Minimize();"></div>' +
							'<div class="spacer1"></div>' +
							'</div>';
							
		for(var i = 0;  i < this.Listings.length;  ++i) {
			objListing = this.Listings[i];
			strMLNUM = objListing.MLNUM;
			strAddress = objListing.Address;	
		//	if (strAddress.length > 22) {
		//		strAddress = strAddress.substring(0,19) + '...';
		//	}
			
			strHTML +='<div style="padding:2px;">' +
						'<div class="floatLeft" style="width:20px"><a href="##" onClick="objMycart.DeleteListing(' +strMLNUM + ');"><img src="../images/pointers/delete.gif" border="0"></a></div>'+
						'<div class="floatLeft" style="width:130px"><span class="smText">' + strAddress +  '<br/>MLSNUM: ' + strMLNUM + '</span>' +'</div>\n' +
						'<div class="spacer1"></div>' +
					'</div>' 
		} 
		
		strLinkHTML =
						'<div class="leftSectionmenu"><a href="mycartCompare.cfm?menu=1"><img src="../images/lineart/detail.gif" border="0" align="absbottom"/> View Cart</a> <div class="floatLeft" style="width:20px">&nbsp;</div><div class="gray" style="font-size:10px"> View Cart to Compare, <BR>Map & Email Listings</div> <div class="spacer1"></div></div>'
						this.PadHTML = this.myCartHTML + strLinkHTML + strHTML ;
	}
}


function NPOnScroll() {
	sy = getScrollY();
	if(sy <= this.LayerStartY)
		this.LayerY = this.LayerStartY
	else
		this.LayerY = sy + 50;
	this.Layer.style.top = this.LayerY + 'px';
	//window.status = sy + ',' + this.LayerStartY;
}

function getScrollY() {
  var scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
   
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
   
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
   
  }
  return scrOfY;
}

function NPSaveToCookie(type) {
	var strData = this.DisplayMode 
	
	if (type == 'L') {
		for(var i = 0;  i < this.Listings.length;  ++i) {
			strData  += ('$' + this.Listings[i].MLNUM + '|' + 
							this.Listings[i].Address )
					//		this.Listings[i].AName + '|' + 
					//		this.Listings[i].OfficeName);
							//+ '|' + 
							//this.Listings[i].ListingPrice + '|' + 
							//this.Listings[i].Subdivision + '|' + 
						//	this.Listings[i].AName + '|' + 
						//	this.Listings[i].OfficeName);
		}
		fnSetCookie ("NP_LISTING", strData);
		this.DisplayType = 'L';
	}
	//alert (unescape(document.cookie));
}



function NPLoadFromCookie(type) {
	
	if (type == 'L' ) {
		var strCookie = unescape(fnGetCookie('NP_LISTING'));
		var arrListings = new Array();
		if(strCookie != '') {
			var arrData = strCookie.split('$');
			// --- first elem is DisplayMode ---
			var intDisplayMode = parseInt(arrData[0]);
			if(!isNaN(intDisplayMode))
				this.DisplayMode = intDisplayMode;
				
			// --- third elem is agent-selection statuses ---	
			for(var i = 1;  i < arrData.length;  i++) {
				var arrDataElements = arrData[i].split('|');
				arrListings[i-1] = new jsListing();
				arrListings[i-1].MLNUM = arrDataElements[0];
				arrListings[i-1].Address = arrDataElements[1];
			//	arrListings[i-1].ListingPrice = arrDataElements[2];
			//	arrListings[i-1].Subdivision = arrDataElements[3];
				arrListings[i-1].AName = arrDataElements[2];
				arrListings[i-1].OfficeName = arrDataElements[3];
			}
			this.Listings = arrListings;
		}
	}
}

function NPHide() {
	this.DisplayMode = 0;
	this.SaveToCookie(this.DisplayType);
	this.Layer.style.display = 'none';
}


function NPMinimize() {
	this.DisplayMode = 1 ;
	this.SaveToCookie(this.DisplayType);
	this.myCartHTML = '<div">' +
							'<div class="sectionHeader" style="text-align:center"><img src="../images/lineart/lineart_addtocart.gif"><a href="mycartCompare.cfm?menu=1"><span class="mdTextBold blue">MyCart</span></a> (<span class="smText red"> ' + this.Listings.length   + '</span><span class="smText"> Listings </span>) &nbsp; <img src="http://www.har.com/images/lineart/lineart_expand.gif" onClick="objMycart.Draw();"></div>' +
							'</div>';
	this.Layer.innerHTML = this.myCartHTML;
	this.PadHTML = this.myCartHTML
	this.Layer.style.display = 'Block';
	this.OnScroll();
}

function NPToggle() {
	if (this.DisplayMode == 2) {
		this.Hide();
	}
	else {
		this.Draw()
	}
	//alert(unescape(document.cookie));
}

function NPDraw() {
	this.DisplayMode = 2;
	this.SaveToCookie(this.DisplayType);
	this.GenContentHTML();
	this.WriteLayer();
	//alert(unescape(document.cookie));
}

function NPWriteLayer() {
	this.Layer.style.display = 'block';
	this.Layer.innerHTML = this.PadHTML;
	this.OnScroll();
}

function initNotePad() {
		if(document.getElementById) {
			divSP = document.getElementById('divMycart');
		}
		else if(document.all) {
			divSP = document.all('divMycart');
		}
		else if(document.layers) {
			divSP = document.layers['divMycart'];
		}
		//alert(divSP);
		if(divSP != null) {
			loadNotePadObj();
		}
}
	
	
function loadNotePadObj() {
	if(window.blnNotePadJSLoaded) {
		objMycart = new mycart(divSP);
		//document.onscroll = objMycart.OnScroll;
	}
	else
		setTimeout('loadNotePadObj()', 1111);
}
	
function DoListingFunction(FnNum) {
		if (FnNum == 1) {
			if (objMycart.Listings.length >= 2) {
				//if(objMycart != null) objMycart.Hide();
				window.open ("dispCompare.cfm?Menu=1", "compare", "width=900, height=900, scrollbars=1");
			}
			else {
				alert("Please Select at least 2 listings to comapre.");
			}
		}
		
		if (FnNum == 2) {
			window.open ("dispCompare.cfm?Menu=2", "compare", "width=900, height=900, scrollbars=1");
			//if(objMycart != null) {objMycart.Hide();}
		}
		
		if (FnNum == 3) {
			//if(objMycart != null) objMycart.Hide();
			window.open ("dispShowAgentDtl.cfm?Menu=3", "compare", "width=900, height=900, scrollbars=1");
	
		}
		if (FnNum == 5) {
			//if(objMycart != null) objMycart.Hide();
			window.open ("doParser.cfm?pg=2", "myhar", "width=600, height=500, scrollbars=1");
		}
		if (FnNum == 4) {
			//if(objMycart != null) objMycart.Hide();
			window.open ("dispShowAgentDtl.cfm?Menu=4", "myhar", "width=900, height=900, scrollbars=1");
		}
		
	}



// --- CONSTRUCTOR FOR AGENT JS OBJECT ---
function jsAgent(){
	this.Member_Number = '';
	this.ANAME = '';
	this.OfficeName = '';
	this.Phone = '';
	this.OfficeAddress = '';
	this.PublicID = '';
	
}

function jsListing() {
	this.MLNUM = '';
	this.Address = '';
//	this.ListingPrice = '';
//	this.Subdivision = '';
//	this.AName = '';
//	this.OfficeName = '';
//	this.Status = '';
}




