
function jsMycart(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.LayerX = objDiv.offsetLeft;
	this.LayerY = objDiv.offsetTop;
	this.LayerStartY = objDiv.offsetTop;
	this.myCartHTML = '<div id=mycart onClick="if(objMycart != null) objMycart.Draw()"></div>'
	
	this.PadOpenHTML = '' 
	
	this.PadCloseHTML = '';
						
	this.PadHTML = this.myCartHTML + this.PadOpenHTML + this.PadCloseHTML;
	
	// methods
	
	this.AddListing = NPAddListing;
	this.DeleteListing = NPDeleteListing;
	this.GenContentHTML = NPGenContentHTML;

	this.SaveToCookie = NPSaveToCookie;
	this.LoadFromCookie = NPLoadFromCookie;
	this.Minimize = NPMinimize;
	this.Hide = NPHide;
	this.Draw = NPDraw;
	this.Toggle = NPToggle;
	this.WriteLayer = NPWriteLayer;
//	this.OnScroll = NPOnScroll;
	//this.LoadFromCookie('A');
	this.LoadFromCookie('L')
	switch(this.DisplayMode) {
		case 1:
			this.Minimize();
			break;
		case 2:
			this.Draw();
			break;
		default:
			this.Hide();  
			break;
	}

	window.blnNotePadJSLoaded = true;
	
}

// --- BEGIN OBJECT METHODS ---
function NPAddListing(strMLNUM, strAddress, strAName, strOfficeName) {
	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 >= 5)
		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;
	//	objListing.ListingPrice = strListingPrice;
	//	objListing.Subdivision = strSubdivision;
		objListing.AName = strAName;
		objListing.OfficeName= strOfficeName;
		this.Listings[this.Listings.length] = objListing;
	}
//	this.SaveToCookie('L');
	if (this.DisplayMode == 1) {
		this.Minimize();
	}
	else {
		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.SaveToCookie('L');
	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_grey.gif"> <span class="lgTextBold blue">MyCart</span></div>' +
							'<div style="text-align:center"><img id="noimg" name="noimg" src="../images/display/no0.gif"></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_grey.gif"> <span class="lgTextBold blue">MyCart</span></div>' +
							'<div style="text-align:center"><img id="noimg" name="noimg" src="../images/display/no' + this.Listings.length +'.gif"></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) + '...';
			}
			strListAgent = objListing.AName;
			strListOffice = objListing.OfficeName;
			
			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/>' +	strListAgent+ '<br/>' +	strListOffice+'</span>' +'</div>\n' +
						'<div class="spacer1"></div>' +
					'</div>' 
		} 
		
		strLinkHTML =
					'<div class="leftSectionmenu"><a href="javascript:DoListingFunction(1);"><img src="../images/lineart/lineart_compare.gif" border="0" align="absbottom"/> Compare Listings</a></div>' +
					 '<div class="leftSectionmenu"><a href="javascript:DoListingFunction(2);"><img src="../images/lineart/lineart_Emailafriend.gif" align="absbottom"> Email Listings</a></div>' +
					 '<div class="leftSectionmenu"><a href="javascript:DoListingFunction(5);"><img src="../images/lineart/lineart_bookmark2.gif" align="absbottom"> Bookmark All</a></div>' +
					 '<div class="leftSectionmenu"><a href="javascript:DoListingFunction(4);"><img src="../images/lineart/lineart_email.gif" align="absbottom"> Email Agents</a></div>' ;
		this.PadHTML = this.myCartHTML + this.PadOpenHTML  + strHTML +  strLinkHTML + this.PadCloseHTML;
	}
}

/*
function NPOnScroll() {
	if  (screen.availWidth <=800) {
		//this.LayerX = document.body.scrollLeft + 500;
		this.LayerX =  600;
	}
	else	{
		//this.LayerX = document.body.scrollLeft + screen.availWidth/2 + 340;
		this.LayerX =  screen.availWidth/2 + 320;
	}
	
	if(document.body.scrollTop < this.LayerStartY)
		this.LayerY = this.LayerStartY
	else
		this.LayerY = document.body.scrollTop + 50;

	this.Layer.style.posLeft = this.LayerX;
	this.Layer.style.posTop = this.LayerY;

}
*/

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 id=mycart onClick="if(objMycart != null) objMycart.Draw()">' +
							'<div><img id="noimg" name="noimg" src="../images/display/no' + this.Listings.length +'.gif"></div>';
							
	this.Layer.innerHTML = 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() {
	//alert("np - x: " + this.LayerX)
	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();
	
			if(document.images) {
				imgPreloads = new Array(8);
				for(var i = 0;  i < 6;  i++) {
					imgPreloads[i] = new Image();
					imgPreloads[i].src = "../images/display/no" + i + ".gif";
				//	alert(i);
				}
			}
		}
	}
	
	
function loadNotePadObj() {
	if(window.blnNotePadJSLoaded) {
		objMycart = new jsMycart(divSP);
	}
	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 = '';
}