
// var used for storing select box values 
var arrOldValues;


function openWindow(url, name, width, height, features) {
	var win;
	var top = 0;
	var left = 0;

	if (screen.width > width) left = (screen.width - width) / 2;
	if (screen.height > height) top = (screen.height - height) / 2;

	if (typeof(features) == "undefined") win = window.open(url, '_blank', 'left='+left+',top='+top+',screenX='+left+',screenY='+top+',width='+width+',height='+ height);
	else win = window.open(url, '_blank', 'left='+left+',top='+top+',screenX='+left+',screenY='+top+',width='+width+',height='+ height +', ' + features);

	if (navigator.appName != 'Microsoft Internet Explorer')  { if ( window.focus )  win.focus()};
}


function showlink(url) {
	opener.location.href = url;
}


function openCalculator(url) {
	openWindow(url,'',600,'450','scrollbars=yes,status=yes');
}


function openMoreInfo(url) {
	openWindow(url,'',550,'480','status=yes,scrollbars=yes');
}


function openEmailFriend(url) {
	openWindow(url,'',430,'280','status=yes');
}

function openEmailFacts(url) {
	openWindow(url,'',640,'430','status=yes');
}

function openAdditionalPhotos(url) {
	openWindow(url,'',690,'500','status=yes,scrollbars=yes');
}


function openSales(url) {
	openWindow(url,'',850,'450','status=yes,scrollbars=yes');
}

			
function TogglePost(postID) {
	preview = document.getElementById(postID + '-Preview');
	post = document.getElementById(postID + '-Post');

	if (post.style.visibility == "hidden") {

		// Hide the preview
		preview.style.visibility = "hidden";
		preview.style.position = "absolute";

		// Show the post
		post.style.visibility = "visible";
		post.style.position = "relative";
		post.style.top = "0";
		post.style.left = "0";

	} else {
		// Hide the post
		post.style.visibility = "hidden";
		post.style.position = "absolute";
		post.style.top = "-10000";
		post.style.left = "-10000";

		// Show the preview
		preview.style.visibility = "visible";
		preview.style.position = "relative";

	}
	window.event.returnValue = false;
}


function ShowTxPrice(ShowPrice) {
	post = document.getElementById('price');

	if (ShowPrice) {
		// Show the post
		post.style.visibility = "visible";
		post.style.position = "relative";
		post.style.top = "0";
		post.style.left = "0";

	} else {
		// Hide the post
		post.style.visibility = "hidden";
		post.style.position = "absolute";
		post.style.top = "-10000";
		post.style.left = "-10000";
	}

	window.event.returnValue = false;
}

			
function SaveCompare(action) {
	if(action != null && action != "") {
		if(action == 'save') {
			document.frmSaveCompare.action = "/myewm/inbox.aspx";
			document.frmSaveCompare.submit();
			
		} else if(action == 'saveresults') {
			document.frmListings.action = "/myewm/inbox.aspx";
			document.frmListings.submit();
			
		} else if(action == 'compresults') {
			document.frmListings.action = "/properties/compare.aspx";
			document.frmListings.submit();
			
		} else {			
			document.frmSaveCompare.action = "/properties/compare.aspx";						
			document.frmSaveCompare.submit();
		}
					
	}
		
}


function ExportExcel() {
	document.frmResults.action = "xlsresults.aspx";	
	document.frmResults.submit();
}


function TogglePhotos(photos) {
	if(photos == '1') {
		document.frmResults.view.value = "1";
		
	} else {
		document.frmResults.view.value = "2";
	}
	document.frmResults.submit();
}


function Filter(page) {
	document.frmResults.action = page;
	document.frmResults.page.value = "1";
	document.frmResults.submit();
}


function SendEmail(frm) {
	frm.mail.value = "Send";
	frm.submit();	
}



// Code to Select multiple choices without having to hold down the control key
// for select boxes.
//
// Usage:
//		onMouseDown="GetCurrentListValues(this);"
//		onchange="FillListValues(this);"
//
// The select all and deselect all links need to pass a reference to the control 
// so that code will have to be altered to give the precise id of your control.
//
// <a href="javascript:SelectAllList(document.theForm.Your_Control);">


function SelectAllList(CONTROL) {
	for (var i = 0;i < CONTROL.length;i++) {
		CONTROL.options[i].selected = true;
	}
}


function DeselectAllList(CONTROL) {
	for (var i = 0;i < CONTROL.length;i++) {
		CONTROL.options[i].selected = false;
	}
}


function FillListValues(CONTROL) {
	var arrNewValues;
	var intNewPos;
	var strTemp = GetSelectValues(CONTROL);
	arrNewValues = strTemp.split(",");

	for (var i=0;i<arrNewValues.length-1;i++) {
		if(arrNewValues[i]==1){
			intNewPos = i;
		}
	}

	for(var i=0;i<arrOldValues.length-1;i++){
		if (arrOldValues[i]==1 && i != intNewPos) {
			CONTROL.options[i].selected= true;
		} else if (arrOldValues[i]==0 && i != intNewPos) {
			CONTROL.options[i].selected= false;
		}

		if(arrOldValues[intNewPos]== 1) {
			CONTROL.options[intNewPos].selected = false;
		} else {
			CONTROL.options[intNewPos].selected = true;
		}
	}
}


function GetSelectValues(CONTROL) {
	var strTemp = "";

	for (var i = 0;i < CONTROL.length;i++) {
		if (CONTROL.options[i].selected == true) {
			strTemp += "1,";
		} else {
			strTemp += "0,";
		}
	}
	return strTemp;
}


function GetCurrentListValues(CONTROL) {
	var strValues = "";
	strValues = GetSelectValues(CONTROL);
	arrOldValues = strValues.split(",")
}