var newWind = null;
var tmpImage;
var listingImage;

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function hideDolWindow() {
    document.getElementById('abc123456').style.display = 'none';
}

function checkListingImageSize(){

	setTimeout('resizeListingPageImage()',50);
}
function SetListingImageSize(){

	setTimeout('ResizeImageOnPageLoad()',50);
}
function ResizeImageOnPageLoad(){

	var MaxWidth = 300;
	var MaxHeight = 225;
	var listingImage = document.getElementById('imgListingImage')
	var newWidth //= listingImage.width ;
	var newHieght //= listingImage.height;
    //document.getElementById('imgListingImage').style.visibility = "hidden"
    if (listingImage.width> MaxWidth )
   {
        listingImage.style.visibility = "hidden"
        widthRatio = listingImage.width / MaxWidth;
        heightRatio = listingImage.height / MaxHeight;
        ratio = Math.max(widthRatio, heightRatio);
        newWidth = listingImage.width / ratio;
        newHieght = listingImage.height / ratio;
        //return " width=" + newWidth + " height=" + newHeight;
        listingImage.width = newWidth;
	    listingImage.height = newHieght;
	    listingImage.style.visibility = "visible"
	    return			        	 
  }
   if (listingImage.height > MaxHeight)
   {
        listingImage.style.visibility = "hidden"
        widthRatio = listingImage.width / MaxWidth;
        heightRatio = listingImage.height / MaxHeight;
        ratio = Math.max(widthRatio, heightRatio);
        newWidth = listingImage.width / ratio;
        newHieght = listingImage.height / ratio;
        //return " width=" + newWidth + " height=" + newHeight;
        listingImage.width = newWidth;
	    listingImage.height = newHieght;
	    listingImage.style.visibility = "visible"
  }
       //document.getElementById('imgListingImage').style.visibility = "visible"        
}

function HandleImageSwap(source) {
    tmpImage = new Image();
    tmpImage.src = source;
    var MaxWidth = 300;
    var MaxHeight = 225;
    var reset = false;
    var listingImage = document.getElementById('imgListingImage')
    var newWidth = null
    var newHieght = null

    if (tmpImage.width > MaxWidth || tmpImage.height > MaxHeight) {
        widthRatio = tmpImage.width / MaxWidth;
        heightRatio = tmpImage.height / MaxHeight;
        ratio = Math.max(widthRatio, heightRatio);
        newWidth = tmpImage.width / ratio;
        newHeight = tmpImage.height / ratio;
        tmpImage.width = newWidth;
        tmpImage.height = newHeight;

    }
    document.getElementById('imgListingImage').style.visibility = "hidden"
    setTimeout('imgDisplay(tmpImage)', 100);
    document.getElementById('imgListingImage').style.visibility = "visible"
}
function HandleImageSwap1(source, lstImgID) {
	tmpImage = new Image();
    tmpImage.src = source;
    var MaxWidth = 300;
    var MaxHeight = 225;
    var reset = false;
    listingImage = document.getElementById(lstImgID)
    var newWidth = null
    var newHieght = null

    if (tmpImage.width > MaxWidth || tmpImage.height > MaxHeight) {
        widthRatio = tmpImage.width / MaxWidth;
        heightRatio = tmpImage.height / MaxHeight;
        ratio = Math.max(widthRatio, heightRatio);
        newWidth = tmpImage.width / ratio;
        newHeight = tmpImage.height / ratio;
        tmpImage.width = newWidth;
        tmpImage.height = newHeight;
    }
    document.getElementById(lstImgID).style.visibility = "hidden"
    setTimeout('lstImgDisplay(tmpImage)', 100);
    document.getElementById(lstImgID).style.visibility = "visible"
 }
function lstImgDisplay(img)
{
    listingImage.style.width=img.width
    listingImage.style.height=img.height
    listingImage.src = img.src;
    listingImage.width=img.width;
    listingImage.height=img.height;
}

function HandleImageSwap_New(source,imgListingImageID) {

    tmpImage = new Image();
    tmpImage.src = source;
    // document.getElementById('imgListingImage').style.display = "none"
    //document.getElementById('imgListingImage').src = tmpImage.src;	
    var MaxWidth = 300;
    var MaxHeight = 225;
    var reset = false;
    var listingImage = document.getElementById(imgListingImageID);//'imgListingImage')
    var newWidth = null
    var newHieght = null

    if (tmpImage.width > MaxWidth || tmpImage.height > MaxHeight) {
        widthRatio = tmpImage.width / MaxWidth;
        heightRatio = tmpImage.height / MaxHeight;
        ratio = Math.max(widthRatio, heightRatio);
        newWidth = tmpImage.width / ratio;
        newHeight = tmpImage.height / ratio;
        tmpImage.width = newWidth;
        tmpImage.height = newHeight;

    }
    document.getElementById(imgListingImageID).style.visibility = "hidden"
    setTimeout('imgDisplay(tmpImage)', 100);
    document.getElementById(imgListingImageID).style.visibility = "visible"
    //document.getElementById('imgListingImage').src = tmpImage.src;   
    /*document.getElementById('imgListingImage').width=tmpImage.width;	
    document.getElementById('imgListingImage').height=tmpImage.height;
    document.getElementById('imgListingImage').src = tmpImage.src;*/


}

function imgDisplay(img)
{
  
    document.getElementById('imgListingImage').style.width=img.width
    document.getElementById('imgListingImage').style.height=img.height
    document.getElementById('imgListingImage').src = img.src;
    document.getElementById('imgListingImage').width=img.width;
    document.getElementById('imgListingImage').height=img.height;
	//style="filter:RevealTrans(Duration=1.0, Transition=23)" 
	//document.getElementById('imgListingImage').style.filter.RevealTrans(Duration=1.0, Transition=23)
	/*if(document.getElementById('imgListingImage').filters) {
	document.getElementById('imgListingImage').filters.revealTrans.apply(); 
	document.getElementById('imgListingImage').filters(0).Transition =1
	document.getElementById('imgListingImage').filters(0).Duration =1
	document.getElementById('imgListingImage').src = tmpImage.src;
    document.getElementById('imgListingImage').filters.revealTrans.play(); }
    else {*/
    
   // }
   // document.getElementById('imgListingImage').style.display = "block" 
}


function ResizeImageOnPageLoad_Old(){
//Added - June 26, 2006 - RR
//To handle Image Resize on first Page Load - listings page
    //alert('hello');
	var danewWidth = 300;
	var danewHeight = 225;
	
	if (document.getElementById('imgListingImage').width>300) {
		danewHeight = document.getElementById('imgListingImage').height*(300/document.getElementById('imgListingImage').width);
		danewWidth = 300;
	} else if (document.getElementById('imgListingImage').height>225) {
		danewWidth = document.getElementById('imgListingImage').width*(225/document.getElementById('imgListingImage').height);
		danewHeight = 225;
	}

		document.getElementById('imgListingImage').width = danewWidth;
		document.getElementById('imgListingImage').height = danewHeight;

}

function HandleImageSwap_Old(source){

    //alert('HI');
    //Accepts a new source for the main listing image on the page
    //handles resizing the image proportionally
    //RR - June 16 2006
    //alert(source+","+width+","+height+","+ImgName);
    
    tmpImage = new Image();
    tmpImage.src = source;
    //alert(tmpImage.width);

	document.getElementById('ctl00_ctl00_BaseContent_BaseContent_imgListingImage').src = tmpImage.src;
	document.getElementById('ctl00_ctl00_BaseContent_BaseContent_imgListingImage').width=tmpImage.width;	
	document.getElementById('ctl00_ctl00_BaseContent_BaseContent_imgListingImage').height=tmpImage.height;		

	var danewWidth = 300;
	var danewHeight = 225;
	
	if (document.getElementById('ctl00_ctl00_BaseContent_BaseContent_imgListingImage').width>300) {
		danewHeight = document.getElementById('imgListingImage').height*(300/document.getElementById('imgListingImage').width);
		danewWidth = 300;
		//alert('wide');
	} else if (document.getElementById('ctl00_ctl00_BaseContent_BaseContent_imgListingImage').height>225) {
		danewWidth = document.getElementById('ctl00_ctl00_BaseContent_BaseContent_imgListingImage').width*(225/document.getElementById('imgListingImage').height);
		danewHeight = 225;
	}
	//if (danewWidth != 300 || danewHeight != 225) {
		document.getElementById('ctl00_ctl00_BaseContent_BaseContent_imgListingImage').width = danewWidth;
		document.getElementById('ctl00_ctl00_BaseContent_BaseContent_imgListingImage').height = danewHeight;
	//}
     
}

function ResizeImagesForPopup(source){
    //Accepts a new source for the main listing image on the page
    //handles resizing the image proportionally
    //RR - June 16 2006
    //alert(source+","+width+","+height+","+ImgName);
    
    tmpImage = new Image();
    tmpImage.src = source;
    //alert(tmpImage.width);

	document.getElementById('imgListingImage').src = tmpImage.src;
	document.getElementById('imgListingImage').width=tmpImage.width;	
	document.getElementById('imgListingImage').height=tmpImage.height;		

	var danewWidth = 300;
	var danewHeight = 225;
	
	if (document.getElementById('imgListingImage').width>300) {
		danewHeight = document.getElementById('imgListingImage').height*(300/document.getElementById('imgListingImage').width);
		danewWidth = 300;
	} else if (document.getElementById('imgListingImage').height>225) {
		danewWidth = document.getElementById('imgListingImage').width*(225/document.getElementById('imgListingImage').height);
		danewHeight = 225;
	}
	if (danewWidth != 300 || danewHeight != 225) {
		document.getElementById('imgListingImage').width = danewWidth;
		document.getElementById('imgListingImage').height = danewHeight;
	}
     
}

//Error Handling Block
function GetHoodMapUrl(HoodCode) {
    var w = 660, h = 580;
	var popW = 660, popH = 580;
	var leftPos = (w-popW)/2, topPos = (h-popH)/2;
	//window.open('http://limo.elliman.com/MapQuest/cgi-bin/mqlocator.exe?icontitles=yes&level=8&state=NY&Zip=' + HoodZip);
	window.open('/Mainsite/Popups/NeighborhoodMapAndDescription.aspx?HoodCode=' + HoodCode, 'RealPing', 'toolbar=no,location=no,scrollbars=yes,width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos);
}

//Real Ping
function GetRealPing() {
	
	var w = 585, h = 580;
	var popW = 585, popH = 580;
	var leftPos = (w-popW)/2, topPos = (h-popH)/2;
	window.open('http://www.realping.com/accts/connect.cfm?id=1337&tz=0&src=web', 'RealPing', 'toolbar=no,location=no,scrollbars=yes,width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos );
	//window.open('http://www.realping.com/accts/connect.cfm?id=1337&tz=0&src=web', 'width=580');
}

//Error Handling Block
function handleError() {
	//alert('an error has occurred.');
	//return true;
}

window.onerror = handleError;

function WindowTakeFocus() {
	window.focus();
}

//Break out of frames
function CheckFrames() {

	if (top.location != self.location) {
	top.location = self.location.href
	}

}

//End Error Handling Block
function linkRedirect(url) {
	document.location.href = url;
}

function ListimgImageZoom(imagePath) {
	window.open(imagePath, 'Zoom');
}

// Modified by Woo : 6/1/2006 : For Save listing --> Popup Window
// var redirURL = '/MainSite/MyPDE/default.aspx?ListingID=' + ListingID;
// document.location = redirURL;
function AddToMyFavorites(UpdateListingID,ListingID,rentalperiod) {
	var w = 480, h = 340;
	if (document.all || document.layers) {
		w = screen.availWidth;
		h = screen.availHeight;
	}

	var popW = 825, popH = 600;
	var leftPos = (w-popW)/2, topPos = (h-popH)/2;
    //if(newWind && !newWind.closed) newWind.focus()
	//newWind = 
	window.open('/mainsite/popups/SaveThisListing.aspx?ListingID=' + ListingID + "&UpdateListingID=" + UpdateListingID + "&rentalperiod=" + rentalperiod, 'My Listings' & ListingID, 'toolbar=no,location=no,scrollbars=yes,width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos );
}

function BrokerFullBio(BID) {
	var w = 480, h = 340;

	if (document.all || document.layers) {
		w = screen.availWidth;
		h = screen.availHeight;
	}

	var popW = 400, popH = 500;
	var leftPos = (w-popW)/2, topPos = (h-popH)/2;

	window.open('/MainSite/PopUps/BrokerFullBIO.aspx?BID=' + BID, 'BrokerFullBIO' + BID, 'toolbar=no,location=no,scrollbars=yes,width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos );
}

function NoAgentPhoto(PhotoID){
	document.getElementById(PhotoID).style.display='none';
}
	
function AddToOutlook(StartDate, EndDate, ListingID) {
	var w = 480, h = 340;

	if (document.all || document.layers) {
		w = screen.availWidth;
		h = screen.availHeight;
	}

	var popW = 10, popH = 10;
	var leftPos = (w-popW)/2, topPos = (h-popH)/2;
	window.open('/MainSite/PopUps/OpenHouse.aspx?S=' + StartDate + '&E=' + EndDate + '&ListingID=' + ListingID, 'AddToOutlook' & ListingID, 'toolbar=no,location=no,scrollbars=yes,width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos );
}

function NeighborhoodInfo(Neighborhood, ListingID) {
	var w = 480, h = 340;

	if (document.all || document.layers) {
		w = screen.availWidth;
		h = screen.availHeight;
	}

	var popW = 600, popH = 525;
	var leftPos = (w-popW)/2, topPos = (h-popH)/2;

	window.open('/mainsite/PopUps/Neighborhood.aspx?Neighborhood=' + Neighborhood + '&ListingID=' + ListingID, 'NeighborhoodInfo', 'toolbar=no,location=no,scrollbars=yes,width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos );
}

function RequestMoreInformation(ListingID,RentalPeriod,EmailID) {
	var w = 480, h = 340;

	if (document.all || document.layers) {
		w = screen.availWidth;
		h = screen.availHeight;
	}

	var popW = 500, popH = 525;
	var leftPos = (w-popW)/2, topPos = (h-popH)/2;

	window.open('/mainsite/popups/RequestMoreInfo.aspx?ListingID=' + ListingID + '&rentalperiod=' + RentalPeriod+ '&EmailID=' + EmailID, 'RequestMoreInfo' & ListingID, 'toolbar=no,location=no,scrollbars=yes,width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos );
}

//Woo : 6/27/2006: For "Send this listing to my phone" popup: 
function SendToPhone(ListingID,RentalPeriod) {
	var w = 480, h = 340;

	if (document.all || document.layers) {
		w = screen.availWidth;
		h = screen.availHeight;
	}

	var popW = 500, popH = 525;
	var leftPos = (w-popW)/2, topPos = (h-popH)/2;

	window.open('/mainsite/popups/SendThisListingToPhone.aspx?ListingID=' + ListingID + '&rentalperiod=' + RentalPeriod, 'SendThisListingToMyPhone', 'toolbar=no,location=no,scrollbars=yes,width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos );
}

//Woo : 6/27/2006: For "Compare Listings" popup: 
function CompareListings(ListingID) {
	var w = 480, h = 340;

	if (document.all || document.layers) {
		w = screen.availWidth;
		h = screen.availHeight;
	}

	var popW = 740, popH = 575;
	var leftPos = (w-popW)/2, topPos = (h-popH)/2;
    //+ '&rentalperiod=' + RentalPeriod
	window.open('/mainsite/popups/CompareListings.aspx?ListingID=' + ListingID, 'CompareListings', 'toolbar=no,location=no,scrollbars=yes,width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos );
}

function SendLiringsTocompare() {
var repeaterDIV = document.getElementById("repeaterCont");
var params = "";
var elements = repeaterDIV.getElementsByTagName('*');	
var count = 0;
if (elements.length>0) {			
	for(var i=0; i<elements.length;i++){ 
		if(elements[i].type == 'checkbox' && elements[i].checked == true) {
		    count+=1;
		    if (count>4) {
		        alert("Please select 4 or fewver listings to compare");
		    return; }
			if(params=="") {
			    params +=elements[i].id;
			 } else {
			        params = params + "," + elements[i].id;
			 }	
		}			
	}
}
if (count==0) {
    alert("Please select listing to compare!");
return;
}
    CompareListings(params);
}

function ScheduleViewing(ListingID, RentalPeriod) {
	var w = 480, h = 340;

	if (document.all || document.layers) {
		w = screen.availWidth;
		h = screen.availHeight;
	}

	var popW = 500, popH = 575;
	var leftPos = (w-popW)/2, topPos = (h-popH)/2;

	window.open('/mainsite/popups/ScheduleViewing.aspx?ListingID=' + ListingID + '&rentalperiod=' + RentalPeriod, 'ScheduleViewing' & ListingID, 'toolbar=no,location=no,scrollbars=yes,width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos );
}

function EmailThisListing(ListingID,RentalPeriod) {
	var w = 480, h = 340;

	if (document.all || document.layers) {
		w = screen.availWidth;
		h = screen.availHeight;
	}

	var popW = 500, popH = 525;
	var leftPos = (w-popW)/2, topPos = (h-popH)/2;

	window.open('/mainsite/popups/EmailToAFriend.aspx?ListingID=' + ListingID + '&rentalperiod=' + RentalPeriod, 'EmailThisListing' & ListingID + '&rentalperiod=' + RentalPeriod, 'toolbar=no,location=no,scrollbars=yes,width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos );
}

// Woo : 5/9/06
function EmailToMe(ListingID,RentalPeriod) {
	var w = 500, h = 400;

	if (document.all || document.layers) {
		w = screen.availWidth;
		h = screen.availHeight;
	}

	var popW = 500, popH = 400;
	var leftPos = (w-popW)/2, topPos = (h-popH)/2;

	window.open('/mainsite/popups/EmailToMe.aspx?ListingID=' + ListingID + '&rentalperiod=' + RentalPeriod + '&emailtome=1', 'EmailThisListing' & ListingID, 'toolbar=no,location=no,scrollbars=yes,width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos );
}


//Images is the list of images 

function SetImageInvisible(ctrl){
	var image = document.getElementById(ctrl)
	image.style.visibility = "hidden";
	
}



function ListingImageChange(ListingID, BuildingID, ImagePath, BuildingPath, imageObj, newimageObj, CurrentCountObj, MaxCountObj, MaxBuildingCountObj, NumImgPerPage, NextPrev, lblName, IsTownhouse) {
	//If ListingType is Not townhouse then Pic #1 is a building Pic.
	var GlobalImagePath = ImagePath;
	var arrImgs = PropImgs;
	var hasBuildingPic = false;
	
	if (IsTownhouse == 'True') {
		GlobalImagePath = BuildingPath;
		arrImgs = BldgImgs;
	}
	
	//If NextPrev is 0 then just swap the main image with the "newimageObj"
	if (NextPrev == 0) {
		if (newimageObj.src.indexOf('/images/spacer.gif') > 0) {
			//Do Nothing
		}
		else {
			imageObj.src = newimageObj.src.replace('/Thumbs','').replace('/88x65','/de');
			//alert(imageObj.src);
		}
	}
	else {
		//Otherwise bring up the next or previous page of images
		//NextPrev 1 is Next ;  NextPrev -1 is Previous
		var PageAttempt = (parseInt(NextPrev) + parseInt(CurrentCountObj.value));
		if (IsTownhouse == 'True') {
			var MaxImages = parseFloat(MaxBuildingCountObj.value);
		}
		else {
			var MaxImages = parseFloat(MaxCountObj.value);
			if (parseFloat(MaxBuildingCountObj.value) > 0) {
				hasBuildingPic = true;
				MaxImages += 1;
			}
		}
		
		var MaxPages = Math.ceil(MaxImages / NumImgPerPage);
		
		if (PageAttempt > MaxPages) {
			//If pressing next on last page, goto first page
			PageAttempt = 1;
			CurrentCountObj.value = 0;
		}
			
		if (PageAttempt < 1) {
			//If pressing previous on first page, goto last page
			PageAttempt = MaxPages;
			CurrentCountObj.value = parseInt(MaxPages) - 1;
			NextPrev = 1;
		}
		
		//now display all images in the current page
		if ((PageAttempt <= MaxPages) && (PageAttempt >= 1)) {
			document.getElementById(lblName).innerHTML = PageAttempt + ' of ' + MaxPages;
			
			CurrentCountObj.value = parseInt(NextPrev) + parseInt(CurrentCountObj.value);
			var PosVal = 0;
			var PagePicMax = MaxImages - CurrentCountObj.value * NumImgPerPage;
			var offSet = 0;
			
			if (hasBuildingPic)	{
				//PagePicMax += 1;
				offSet = -1;
			}
				
			if ((hasBuildingPic) && (CurrentCountObj.value == '1')) {
			}

			// if only use 4 images in the page
			if (NumImgPerPage == 4) {
				if (PagePicMax + NumImgPerPage >= 1) {
					PosVal = (CurrentCountObj.value * NumImgPerPage) - 3 + offSet;
					if ((hasBuildingPic) && (CurrentCountObj.value == '1'))	{
						document.images['imgPicThumb01'].src = BuildingPath + BldgImgs[0];
					}
					else {
						document.images['imgPicThumb01'].src = GlobalImagePath + arrImgs[PosVal - 1];
					}
				}
				else document.images['imgPicThumb01'].src = '/images/spacer.gif';
					
				if (PagePicMax + NumImgPerPage >= 2) {
					PosVal = (CurrentCountObj.value * NumImgPerPage) - 2 + offSet;
					document.images['imgPicThumb02'].src = GlobalImagePath + arrImgs[PosVal - 1];
				}
				else document.images['imgPicThumb02'].src = '/images/spacer.gif';
					
				if (PagePicMax + NumImgPerPage >= 3) {
					PosVal = (CurrentCountObj.value * NumImgPerPage) - 1 + offSet;
					document.images['imgPicThumb03'].src = GlobalImagePath + arrImgs[PosVal - 1];
				}
				else document.images['imgPicThumb03'].src = '/images/spacer.gif';
					
				if (PagePicMax + NumImgPerPage >= 4) {
					PosVal = (CurrentCountObj.value * NumImgPerPage) - 0 + offSet;
					document.images['imgPicThumb04'].src = GlobalImagePath + arrImgs[PosVal - 1];
				}
				else document.images['imgPicThumb04'].src = '/images/spacer.gif';
			}
			else if (NumImgPerPage == 5) {
				PosVal = (CurrentCountObj.value * NumImgPerPage) - 4 + offSet;
				if (document.images['imgOH']) {
					if ((hasBuildingPic) && (CurrentCountObj.value == '1'))	{
						document.images['imgOH'].src = BuildingPath + BldgImgs[0];
					}
					else {
						document.images['imgOH'].src = GlobalImagePath + arrImgs[PosVal - 1];
					}
				}
				else {
					if ((hasBuildingPic) && (CurrentCountObj.value == '1')) {
						document.images['imgFloorplan'].src = BuildingPath + BldgImgs[0];
					}
					else {
						document.images['imgFloorplan'].src = GlobalImagePath + arrImgs[PosVal - 1];
					}
				}

				if (PagePicMax + NumImgPerPage >= 2) {
					PosVal = (CurrentCountObj.value * NumImgPerPage) - 3 + offSet;
					document.images['imgPicThumb01'].src = GlobalImagePath + arrImgs[PosVal - 1];
				}
				else document.images['imgPicThumb01'].src = '/images/spacer.gif';
					
				if (PagePicMax + NumImgPerPage >= 3) {
					PosVal = (CurrentCountObj.value * NumImgPerPage) - 2 + offSet;
					document.images['imgPicThumb02'].src = GlobalImagePath + arrImgs[PosVal - 1];
				}
				else document.images['imgPicThumb02'].src = '/images/spacer.gif';
					
				if (PagePicMax + NumImgPerPage >= 4) {
					PosVal = (CurrentCountObj.value * NumImgPerPage) - 1 + offSet;
					document.images['imgPicThumb03'].src = GlobalImagePath + arrImgs[PosVal - 1];
				}
				else document.images['imgPicThumb03'].src = '/images/spacer.gif';
					
				if (PagePicMax + NumImgPerPage >= 5) {
					PosVal = (CurrentCountObj.value * NumImgPerPage) - 0 + offSet;
					document.images['imgPicThumb04'].src = GlobalImagePath + arrImgs[PosVal - 1];
				}
				else document.images['imgPicThumb04'].src = '/images/spacer.gif';
			}
			else if (NumImgPerPage == 6) {
				PosVal = (CurrentCountObj.value * NumImgPerPage) - 5 + offSet;
				if ((hasBuildingPic) && (CurrentCountObj.value == '1')) {
					document.images['imgOH'].src = BuildingPath + BldgImgs[0];
				}
				else
				{
					document.images['imgOH'].src = GlobalImagePath + arrImgs[PosVal - 1];
				}
				if (PagePicMax + NumImgPerPage >= 2) {
					PosVal = (CurrentCountObj.value * NumImgPerPage) - 4 + offSet;
					document.images['imgFloorplan'].src = GlobalImagePath + arrImgs[PosVal - 1];
				}
				else document.images['imgFloorplan'].src = '/images/spacer.gif';

				if (PagePicMax + NumImgPerPage >= 3) {
					PosVal = (CurrentCountObj.value * NumImgPerPage) - 3 + offSet;
					document.images['imgPicThumb01'].src = GlobalImagePath + arrImgs[PosVal - 1];
				}
				else document.images['imgPicThumb01'].src = '/images/spacer.gif';
					
				if (PagePicMax + NumImgPerPage >= 4) {
					PosVal = (CurrentCountObj.value * NumImgPerPage) - 2 + offSet;
					document.images['imgPicThumb02'].src = GlobalImagePath + arrImgs[PosVal - 1];
				}
				else document.images['imgPicThumb02'].src = '/images/spacer.gif';
					
				if (PagePicMax + NumImgPerPage >= 5) {
					PosVal = (CurrentCountObj.value * NumImgPerPage) - 1 + offSet;
					document.images['imgPicThumb03'].src = GlobalImagePath + arrImgs[PosVal - 1];
				}
				else document.images['imgPicThumb03'].src = '/images/spacer.gif';
					
				if (PagePicMax + NumImgPerPage >= 6) {
					PosVal = (CurrentCountObj.value * NumImgPerPage) - 0 + offSet;
					document.images['imgPicThumb04'].src = GlobalImagePath + arrImgs[PosVal - 1];
				}
				else document.images['imgPicThumb04'].src = '/images/spacer.gif';
			}
		}
	}
}

function imgerr(ctrl)
{
	ctrl.src = "/images/spacer.gif";
}

function imgerrHide(ctrl)
{
	ctrl.style.display = "none";
}

function imgerrReplace(ctrl)
{
	src='/images/PropertyListing/NoPics.gif';
}

function ListingImageErr(ctrl)
{
	ctrl.src = "/images/global/listing_nophoto.gif";
}

function SearchResultsImageErr(ctrl)
{
	ctrl.src = "/images/spacer.gif";
}

function BrokerImageErr(ctrl)
{
	ctrl.src = "/images/spacer.gif";
}

function findStyleRule(styleName) {
	if (!document.styleSheets) return;

	for (i = 0; i < document.styleSheets.length; i++) {
		if (document.styleSheets[0].cssRules) {// Mozilla
			for (j = 0; j < document.styleSheets(i).cssrules.length; j++) {
				if (document.styleSheets(i).cssrules(j).selectorText == styleName) {
					return document.styleSheets(i).cssrules(j);
				}
			}     
		}
		else {// IE
			for (j = 0; j < document.styleSheets(i).rules.length; j++) {
				if (document.styleSheets(i).rules(j).selectorText == styleName) {
					return document.styleSheets(i).rules(j);
				}
			}     
		}
	}
}
	
//Popup Window Functions
function OpenHousePop(page, Description) {
	window.open(page, Description, 'toolbar=yes,location=no,scrollbars=yes,width=290,height=315');
	//window.open(page, Description, 'toolbar=yes,location=no,scrollbars=yes,width=607,height=' + eval(window.screen.height*.80).toString());
}

function ManhattanMortgageArticlePop(page, Description) {
	window.open(page, Description, 'toolbar=yes,location=no,scrollbars=yes,width=800,height=550');
	//window.open(page, Description, 'toolbar=yes,location=no,scrollbars=yes,width=607,height=' + eval(window.screen.height*.80).toString());
}

function ViewAllPhotos(ListingID,search) {
    var w = 620, h = 500;

	if (document.all || document.layers) {
		w = window.screen.availWidth;
		h = window.screen.availHeight;
	}

	var popW = 620, popH = 500;
	var leftPos = (w-popW)/2, topPos = (h-popH)/2;
	window.open('/mainsite/popups/ListingImages.aspx?ListingID=' + ListingID + '&search=' + search, 'ViewAllPhotos', 'toolbar=no,resizable=1,location=no,scrollbars=yes,width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos);
}

function ViewAllFloorplans(ListingID) {
    var w = 480, h = 340;

	if (document.all || document.layers) {
		w = screen.availWidth;
		h = screen.availHeight;
	}

	var popW = eval(window.screen.width*.75).toString(), popH = eval(window.screen.height *.75).toString();
	var leftPos = (w-popW)/2, topPos = (h-popH)/2;

    window.open('/mainsite/popups/ListingFloorplans.aspx?ListingID=' + ListingID, 'ViewAllFloorplans', 'toolbar=no,resizable=1,location=no,scrollbars=yes,width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos );
}

function ViewAllBuildingFloorplans(BuildingID, Address) {
	var w = 480, h = 340;

	if (document.all || document.layers) {
		w = screen.availWidth;
		h = screen.availHeight;
	}

	var popW = eval(window.screen.width*.75).toString(), popH = eval(window.screen.height *.75).toString();
	var leftPos = (w-popW)/2, topPos = (h-popH)/2;

	window.open('/mainsite/popups/ListingFloorplans.aspx?BuildingID=' + BuildingID + '&Address=' + Address, 'ViewAllFloorplans' + BuildingID, 'toolbar=no,location=no,scrollbars=yes,width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos );
}
                
function ViewAllNHDBuildingFloorplans(BuildingID, Address) {
	var w = 480, h = 340;

	if (document.all || document.layers) {
		w = screen.availWidth;
		h = screen.availHeight;
	}

	var popW = eval(window.screen.width*.75).toString(), popH = eval(window.screen.height *.75).toString();
	var leftPos = (w-popW)/2, topPos = (h-popH)/2;

	window.open('/mainsite/popups/ListingFloorplans.aspx?NHDBuildingID=' + BuildingID + '&Address=' + Address, 'ViewAllFloorplans' + BuildingID, 'toolbar=no,location=no,scrollbars=yes,width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos );
}

function ListingPrinterFriendly(ListingID) {
var _rentalPeriod = ''

if(!window.opener)
{
    if(rentalPeriod)  _rentalPeriod = rentalPeriod
}
if(!window.opener)
{
    if(rentalPeriod)  _rentalPeriod = rentalPeriod
}
	var w = 480, h = 340;

	if (document.all || document.layers) {
		w = screen.availWidth;
		h = screen.availHeight;
	}

	//var popW = eval(window.screen.width*.75).toString(), popH = eval(window.screen.heighth*.75).toString();
	var popW = 660, popH = 550;

	var leftPos = (w-popW)/2, topPos = (h-popH)/2;
	if (ListingPrinterFriendly.arguments.length == 2) {
		if (ListingPrinterFriendly.arguments[1] != '1') {
			var oh = ListingPrinterFriendly.arguments[1];
			window.open('/mainsite/popups/ListingPrinterFriendly.aspx?ListingID=' + ListingID + '&OHDate=' + oh + '&rentalperiod=' + _rentalPeriod, 'ListingPrinterFriendly' , 'toolbar=yes,location=no,scrollbars=yes,width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos );
		}
		else window.open('/mainsite/popups/ListingPrinterFriendly.aspx?ListingID=' + ListingID + '&PrintFlag=1' + '&rentalperiod=' + _rentalPeriod, 'ListingPrinterFriendly', 'toolbar=yes,location=no,scrollbars=yes,width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos );
	}
	else {
		window.open('/mainsite/popups/ListingPrinterFriendly.aspx?ListingID=' + ListingID + '&rentalperiod=' + _rentalPeriod, 'ListingPrinterFriendly', 'toolbar=yes,location=no,scrollbars=yes,width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos );
	}
}

function FloorplanPrinterFriendly(ListingID) {
	var w = 480, h = 340;

	if (document.all || document.layers) {
		w = screen.availWidth;
		h = screen.availHeight;
	}

	var popW = eval(window.screen.width*.75).toString(), popH = eval(window.screen.height *.75).toString();
	var leftPos = (w-popW)/2, topPos = (h-popH)/2;

	window.open('/mainsite/popups/FloorplanPrinterFriendly.aspx?ListingID=' + ListingID, 'FloorplanPrinterFriendly', 'toolbar=yes,location=no,scrollbars=yes,width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos );
}

function BrokerContact(BID) {
	var w = 480, h = 340;

	if (document.all || document.layers) {
		w = screen.availWidth;
		h = screen.availHeight;
	}

	var popW = 5, popH = 5;
	var leftPos = (w-popW)/2, topPos = (h-popH)/2;

	window.open('/mainsite/popups/BrokerContactDL.aspx?BID=' + BID, 'BrokerContactDownload' + BID, 'toolbar=no,location=no,scrollbars=no,width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos );
}
	
function OnlineMortgageApplication() {
	window.open('http://www.pemconline.com/', 'PEMCO');
}
function RedirectToMyListings()
{
   
    var que = unescape(location.search);
    var que = que.substring(1, que.length);
    var que = que.split("&");
    var querystring = new Array();
    var loop = 0;
    
   if(que[0].indexOf("BrokerID")>-1) window.location.href = "/mainsite/agents/Agents.aspx?BID=" + que[0].split("=")[1] + "#Mylistings"
    
    if (que.length > 1)
    {
        if ((que[1].indexOf("teaminfo")>-1 || que[1].indexOf("content")>-1))
        {
         
            var bid=que[0].split("=")[1]
            if(document.getElementById("A1")) document.getElementById("A1").style.display="none"
            window.location.href = "/mainsite/agents/Agents.aspx?BID=" + bid + "#Mylistings"
        } else {
        
        window.location.href = "#Mylistings"
       }
   }
}
function GenericPopup(strURL, strName, Width, Height) {
	var w = 480, h = 340;

	if (document.all || document.layers) {
		w = screen.availWidth;
		h = screen.availHeight;
	}

	var popW = Width, popH = Height;
	var leftPos = (w-popW)/2, topPos = (h-popH)/2;

	window.open(strURL, strName,'toolbar=no,location=no,scrollbars=yes,width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos );
}

function BrokerPageLink(BID) {
	//document.location = '/MainSite/Agents/Agent.aspx?BID=' + BID;
	document.location = '/MainSite/Agents/Agents.aspx?BID=' + BID;
}
	
function ShowHideListingDescription(objName, Show) {
	var objToShowHide = findObj(objName, null)
	if (Show == true) {
		objToShowHide.style.display = 'inline';
	}
	else {
		objToShowHide.style.display = 'none';
	}
}

//Function for array creation       
function definearray(x) {
	this.length = x;
    for(var t = 1; t <= x; t++)
		this[t] = 0;
	return this;
}
//Form Function
function do_select(which,form_name,prefix) {
	which = parseInt(which);
	if (document.forms[form_name].elements[prefix+which].value == 0) {
		document.forms[form_name].elements[prefix+which].value = 1;
	}
	else {
		document.forms[form_name].elements[prefix+which].value = 0;
	}
}

function hidden_box_init(form_name) {
	//reset the hidden form 'temp' to 0    We put this here because ie3 should leave states persistent!
	for (i=0; i<document.forms[form_name].length; i++) {
		document.forms[form_name].elements[i].value=0;
	}
}

// Example: obj = findObj("image1");
function findObj(theObj, theDoc) {
	var p, i, foundObj;

	if(!theDoc) theDoc = document;
	if( (p = theObj.indexOf("?")) > 0 && parent.frames.length) {
		theDoc = parent.frames[theObj.substring(p+1)].document;
		theObj = theObj.substring(0,p);
	}
	if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
	for (i=0; !foundObj && i < theDoc.forms.length; i++) 
		foundObj = theDoc.forms[i][theObj];
	for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
		foundObj = findObj(theObj,theDoc.layers[i].document);
	if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);

	return foundObj;
}

function EmailContactPopup(EmailContactID) {
	var w = 480, h = 340;

	if (document.all || document.layers) {
		w = screen.availWidth;
		h = screen.availHeight;
	}

	var popW = 650, popH = 550;

	var leftPos = (w-popW)/2, topPos = (h-popH)/2;

    window.open('/MainSite/Popups/Email_General.aspx?' + EmailContactID, 'EmailContact', 'toolbar=no,location=no,scrollbars=yes,width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos );
}
	
function AttorneyReferralPopUp() {
	var w = 480, h = 340;

	if (document.all || document.layers) {
		w = screen.availWidth;
		h = screen.availHeight;
	}

	var popW = 650, popH = 600;
	var leftPos = (w-popW)/2, topPos = (h-popH)/2;

    window.open('/MainSite/Agents/Attorney_Referrals.aspx', 'yahoo', 'toolbar=no,location=no,scrollbars=yes,width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos );
}

function VideoClippingsPopUp(clip) {
	var w = 480, h = 340;

	if (document.all || document.layers) {
		w = screen.availWidth;
		h = screen.availHeight;
	}

	var popW = 340, popH =310;
	var leftPos = (w-popW)/2, topPos = (h-popH)/2;

	if (clip==1)
		window.open('/MainSite/PopUps/VideoClippings.aspx?clip=1', 'yahoo', 'toolbar=no,location=no,scrollbars=0,width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos );
	else
		window.open('/MainSite/PopUps/VideoClippings.aspx?clip=2', 'yahoo', 'toolbar=no,location=no,scrollbars=0,width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos );
}
	
	
function printWindow(x) {
	if (x==1) {
		document.all['maybeprint'].style.display="None";
	} else {
		document.all['maybeprint'].style.display="Block";
	}
	bV = parseInt(navigator.appVersion)
	if (bV >= 4) window.print()
}

function toggle(ctrlName, targetName) {
	var e = document.getElementById(targetName);
	var yes = document.getElementById(ctrlName + '_0');
	var no = document.getElementById(ctrlName + '_1');
	if (yes.checked) {
		e.disabled = 'disabled';
		e.checked = false;
	} else {
		e.disabled = false;
		e.checked = true;
	}
}

function ValidateHoods() {
	elements = document.getElementById("test").getElementsByTagName('*');	
		for(var i=0; i<elements.length;i++){ 
			if( elements[i].type == 'checkbox' && elements[i].checked == true){
				return true	} 
		}
		alert('Please select at least one neighborhood');
		return false}

function ValidateCountries(flag) {
	elements = document.getElementById("countriesList").getElementsByTagName('*');	
		for(var i=0; i<elements.length;i++){ 
			if( elements[i].type == 'checkbox' && elements[i].checked == true){
				return true	} 
		}
		if (ValidateCountries.arguments.lnegth=0) 
		{
		alert('Please select at least one Country!');
		} else {
		alert('Please select at least one neighborhood!');
		}
		
		return false}		
//POPUP DIV
isIE=document.all;
isNN=!document.all&&document.getElementById;
isN4=document.layers;
isHot=false;

function ddInit(e){
  topDog=isIE ? "BODY" : "HTML";
  whichDog=isIE ? document.all.theLayer : document.getElementById("theLayer");  
  hotDog=isIE ? event.srcElement : e.target;  
  while (hotDog.id!="titleBar"&&hotDog.tagName!=topDog){
    hotDog=isIE ? hotDog.parentElement : hotDog.parentNode;
  }  
  if (hotDog.id=="titleBar"){
    offsetx=isIE ? event.clientX : e.clientX;
    offsety=isIE ? event.clientY : e.clientY;
    nowX=parseInt(whichDog.style.left);
    nowY=parseInt(whichDog.style.top);
    ddEnabled=true;
    document.onmousemove=dd;
  }
}

function dd(e){
  if (!ddEnabled) return;
  whichDog.style.left=isIE ? nowX+event.clientX-offsetx : nowX+e.clientX-offsetx; 
  whichDog.style.top=isIE ? nowY+event.clientY-offsety : nowY+e.clientY-offsety;
  return false;  
}

function ddN4(whatDog){
  if (!isN4) return;
  N4=eval(whatDog);
  N4.captureEvents(Event.MOUSEDOWN|Event.MOUSEUP);
  N4.onmousedown=function(e){
    N4.captureEvents(Event.MOUSEMOVE);
    N4x=e.x;
    N4y=e.y;
  }
  N4.onmousemove=function(e){
    if (isHot){
      N4.moveBy(e.x-N4x,e.y-N4y);
      return false;
    }
  }
  N4.onmouseup=function(){
    N4.releaseEvents(Event.MOUSEMOVE);
  }
}

function hideMe(){
  //if (isIE||isNN) whichDog.style.visibility="hidden";
  if (isIE||isNN) document.getElementById("theLayer").style.display="none";
  else if (isN4) document.theLayer.visibility="hide";
}

function showMe(ind){
//alert(BuildDecs[ind-1] + ' Description ')
//alert(BuildDecs[ind-1] + ' Description ' + ind-1)
document.getElementById('buildDesc').innerHTML = BuildDecs[ind-1]  //BuildDecs[ind-1]
//BuildDecs
  //if (isIE||isNN) whichDog.style.visibility="visible";
  if (isIE||isNN) document.getElementById("theLayer").style.display="block";
  else if (isN4) document.theLayer.visibility="show";
}

function wopen(url, name, w, h)
{
  //w += 32;
  //h += 96;
  
  wleft = (screen.width - w) / 2;
  wtop = (screen.height - h) / 2;
  // IE5 and other old browsers might allow a window that is
  // partially offscreen or wider than the screen. Fix that.
   if (wleft < 0) {
    w = screen.width;
    wleft = 0;
  }
  if (wtop < 0) {
    h = screen.height;
    wtop = 0;
  }
  var win = window.open(url,
    name,
    'width=' + w + ', height=' + h + ', ' +
    'left=' + wleft + ', top=' + wtop + ', ' +
    'location=no, menubar=no, ' +
    'status=no, toolbar=no, scrollbars=yes, resizable=no');
  // Just in case width and height are ignored
  win.resizeTo(w, h);
  // Just in case left and top are ignored
  win.moveTo(wleft, wtop);
  win.focus();
}
//document.onmousedown=ddInit;
//document.onmouseup=Function("ddEnabled=false");

////Agents 

function parseQueryStrng() {
var query = window.location.search.substring(1) + "";
	if(query!="") {
		var params=query.split("&");
		var pageParam=null;
		for(var i=0;i<params.length;i++){
			if(params[i].toLowerCase().indexOf("letter")>-1){
				pageParam=params[i];
				document.getElementById("labelsep").style.display="none"
				break;
			}
			if(params[i].toLowerCase().indexOf("first")>-1 || params[i].toLowerCase().indexOf("last")>-1){
				pageParam=params[i];
				document.getElementById("searchalpha").style.display="none"
				document.getElementById("searchlang").style.display="none"
				document.getElementById("searchoffice").style.display="none"
				clearSeparator(); 				
				/*var elem = document.getElementById("labelsep").getElementsByTagName("div")
				for (var i=0; i<elem.length; i++)
				{
					if (elem[i].className == "sep") elem[i].style.display='none';
				}*/
				break;
			}
			if(params[i].toLowerCase().indexOf("language")>-1){
				pageParam=params[i];
				document.getElementById("searchalpha").style.display="none";
				document.getElementById("searchoffice").style.display="none";
				document.getElementById("searchname").style.display="none";
				clearSeparator();
				break;
			}
			if(params[i].toLowerCase().indexOf("oid")>-1 || params[i].toLowerCase().indexOf("oid2")>-1 || params[i].toLowerCase().indexOf("oid3")>-1 ){
				pageParam=params[i];
				document.getElementById("searchalpha").style.display="none";
				document.getElementById("searchname").style.display="none";
				document.getElementById("searchlang").style.display="none"
				document.getElementById("searchoffice").style.display="none";
				clearSeparator();
				break;
			}
			if(params[i].toLowerCase().indexOf("region")>-1){
			
			}
		}
	}
	if(pageParam!=null){
			var param=pageParam.split("=")[1];	
	}

}
function pageRedirect(selectObj) {
var idx = selectObj.selectedIndex;
var which = selectObj.options[idx].value;
if(which!="-1") {
	window.location.href = "/MainSite/Agents/ByLanguage.aspx?Language=" + which
	window.location.href = "/MainSite/Agents/default.aspx?Language=" + which
}
}
function clearSeparator(oDiv) {
var elem = document.getElementById("labelsep").getElementsByTagName("div")
for (var i=0; i<elem.length; i++) {
	if (elem[i].className == "sep") elem[i].style.display='none';
}

}
