// JavaScript Document
image1 		= new Image();
image1.src 	= "images/spacer.gif";

image2 		= new Image();
image2.src 	= "images/center_left_top.gif";

image3 		= new Image();
image3.src 	= "images/center_hor_top.gif";

image4 		= new Image();
image4.src 	= "images/center_right_top.gif";

image5 		= new Image();
image5.src 	= "images/center_ver_left.gif";

image6 		= new Image();
image6.src 	= "images/center_ver_right.gif";

image7 		= new Image();
image7.src 	= "images/center_left_bottom.gif";

image8 		= new Image();
image8.src 	= "images/center_hor_bottom.gif";

image9 		= new Image();
image9.src 	= "images/center_right_bottom.gif";

// holds an instance of XMLHttpRequest
var xmlHttp = createXmlHttpRequestObject();

// JavaScript Document
function expand(name) {
	document.getElementById( name ).style.display = "block";
}

function collapse(name) {
	document.getElementById( name ).style.display = "none";
}

function change_color(el, bg1, bg2){
	for (i = 0; i < el.parentNode.childNodes.length; i++)
		if (el.parentNode.childNodes[i].tagName)
		el.parentNode.childNodes[i].style.backgroundImage=bg2
		el.style.backgroundImage=bg1
}

function preview_image(url, text){
	document.photo_img.src 								= url;
	document.getElementById("photo_text").innerHTML 	= text;
}

function print_page(listing) {
	var leftPos = (screen.availWidth-700) / 2;
	var topPos = (screen.availHeight-500) / 2;
	Press1Win = window.open('site_detail_print.php?listing=' + listing,'','width=700,height=500,scrollbars=yes,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);
}

// creates an XMLHttpRequest instance
function createXmlHttpRequestObject() {
	// will store the reference to the XMLHttpRequest object
	var xmlHttp;
	// this should work for all browsers except IE6 and older
	try	{
		// try to create XMLHttpRequest object
		xmlHttp = new XMLHttpRequest();
	}
	catch(e) {
		// assume IE6 or older
		var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
		                                "MSXML2.XMLHTTP.5.0",
		                                "MSXML2.XMLHTTP.4.0",
		                                "MSXML2.XMLHTTP.3.0",
		                                "MSXML2.XMLHTTP",
		                                "Microsoft.XMLHTTP");
		// try every prog id until one works
		for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++) {
			try	{
				// try to create XMLHttpRequest object
				xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
			}
			catch (e) {
			}
		}
	}
	// return the created object or display an error message
	if (!xmlHttp)
		alert("Error creating the XMLHttpRequest object.");
	else
		return xmlHttp;
}

// check username availability;
function addFavoriteListing( id ) {

	// only continue if xmlHttp isn't void
	if (xmlHttp) {
		// try to connect to the server
		try {
			var str = "";
			str = "listingid=" + id;
			str += "&task=addfavoritelisting";
			// initiate the asynchronous HTTP request
			xmlHttp.open("POST", "http://www.usbdt.com/index2.php?option=com_ajax", true);
			xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
			xmlHttp.onreadystatechange = function() {
				// when readyState is 4, we are ready to read the server response
				if (xmlHttp.readyState == 4) {
					// continue only if HTTP status is "OK"
					if (xmlHttp.status == 200) {
				  		try {
				    		// handle the response from the server
							responseText = xmlHttp.responseText;
							alert(responseText);
				  		}
				  		catch(e) {
				    		// display error message
				    		alert("Error reading the response: " + e.toString());
				  		}
					}
					else {
				  		// display status message
				  		alert("There was a problem retrieving the data:\n" + xmlHttp.statusText);
					}
				}
			};
			xmlHttp.send(str);
		}
		// display the error in case of failure
		catch (e) {
			alert("Can't connect to server:\n" + e.toString());
		}
	}
}

// advertise online where container hide/display
function advertiseOnline() {
	if (document.getElementById("contact_advertisingonline").value == 'Yes') {
		document.getElementById("containerwhere").style.display = '';
	}
	else {
		document.getElementById("containerwhere").style.display = 'none';
	}
}
