function swapPicture(newImage)
{
    if (document.getElementById("mainpic"))
    {
      target=document.getElementById("mainpic");
    } else {
      target=document.images.mainpic;
    }
    
    target.src=newImage;
}

function showtour(url) {
	// need to see if contains http...
	turl = url.toLowerCase();
	if (turl.match('http://')  ) {
		window.open(url,'virtualtour');
	} else {
		window.open('http://' + url,'virtualtour');
	}
	return;
}

function showemailrequest(mlsno) {
	document.getElementById("ajax_action").value = "showemailrequest";
	popup('emailrequestdiv');
	// hidediv('loginformdiv');
	document.getElementById("txttext").value = "I would like more information on listing number: " + mlsno;

	// ztext=document.getElementById("txttext").value;
}

function showshowing(mlsno) {
	document.getElementById("ajax_action").value = "showshowing";
	popup('showingrequestdiv');
	// hidediv('loginformdiv');
	document.getElementById("txttext").value = "I would like to set up a showing on listing number: " + mlsno;

	// ztext=document.getElementById("txttext").value;
}

function showrmi(mlsno,logged_in) {
	document.getElementById("ajax_action").value = "showrmi";
	if (logged_in != 0) {
		showdiv('rmidiv');
		hidediv('loginformdiv');
	} else {
		// need to log in first... save the listing number and the action - saved in global var
		document.getElementById("emailbutton").style.display='block';
		showdiv('loginformdiv');
		// alert('Logged IN: ' + document.getElementById('ajax_logged_in').value);
	}
		
	document.getElementById("rmitext").value = "I would like more information on listing number: " + mlsno;

	showdiv('popup');
}

function showrs(mlsno,logged_in) {
	document.getElementById("ajax_action").value = "showrs";
	if (logged_in != 0) {
		showdiv('rsdiv');
		hidediv('loginformdiv');
	} else {
		// need to log in first... save the listing number and the action - saved in global var
		document.getElementById("emailbutton").style.display='block';
		showdiv('loginformdiv');
		// alert('Logged IN: ' + document.getElementById('ajax_logged_in').value);
	}
		
	document.getElementById("rstext").value = "I would like to set up a showing for this property: " + mlsno;

	showdiv('popup');
}

function dosomething(what) {
	alert(what);
}

function waitforit() {
	var finished=false;
	var ct=0;
	while (!finished)
	{
		ct=ct+1;
    	//code to be executed
    	// checkit = document.getElementById("ajax_status").value;
    	if (ajax_status !=0) {
    		finished=true;
    	}
    	// alert(checkit);
	}
}

function logout() {
	ajax_action="logout";
	doajax('logout');
	msg = "You have been logged out.";
	document.getElementById("ajaxmessage").innerHTML = "<p>" + msg + "</p>";
	showdiv('ajaxmessage');
}



function closermi() {
	myDiv = getRefToDiv('rmidiv');
	if( myDiv.style ) { myDiv= myDiv.style; }
	myDiv.display = 'none';
	document.getElementById("ajax_rmi").style.display = "none";
}


function printlisting() {
	hidediv('popup');
	hidediv('ajaxmessage');
	window.print();
}

// setStyleById: given an element id, style property and 
// value, apply the style.
// args:
//  i - element id
//  p - property
//  v - value
//
function setStyleById(i, p, v) {
	alert("V: " + v);
	var n = document.getElementById(i);
	n.style[p] = v;
}