/*
	Determine whether or not the useris using a suck-ass MSIE festering pile of steaming dog
	dropping web browser.  This will come in handy later on - trust me.

	I reeeeeaaaaallllly hope msnbot indexes this!
*/
if(window.ActiveXObject){
	var isIE=true; // this is a crappy MSIE web browser.
}else{
	var isIE=false; // Oh Goodie! Things should actually work as expected!
}


/*
	Determine which CSS method is needed to toggle the display of any hidden rows/rowgroups properly.

	Use "table-row" or "table-row-group" for every browser EXCEPT MSIE which requires us to use
	"inline" - because Microsoft refuses to adhere to standards ... gah! don't get me started ...

	Using "inline" in other browsers causes display problems (AS IT SHOULD - 'CUZ IT'S FECKIN' WRONG!!!!!)
*/
var row_display;
var row_group_display;
if(isIE){
	row_display='inline';
	row_group_display='inline';
}else{
	row_display='table-row';
	row_group_display='table-row-group';
}




/*
	AJAX CODE

	This is a basic AJAX function set. Give it a URL to query, and a page item id and the
	function will attempt to set the "innerHTML" value of "id" to the reulting text/html of "url".

	If the id parameter is omitted, the script will still execute the code on the server-side
	page (the url parameter), but no feedback will be displayed on screen.

	Every instance where I have used the ajax() function, I am using it to request documents
	contained in the /www/ajax/ directory. The function can request files from elsewhere as well
	(but only from your domain). I have used this location simply to help keep track of what files
	do what tasks.
*/
var req;
function ajax(url,id){
	var ajax_target_id=id;
	if(window.XMLHttpRequest){
		req = new XMLHttpRequest();
		req.onreadystatechange = processReqChange;
		req.open("GET", url, true);
		req.send(null);
	}else if(isIE){
		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (req){
			req.onreadystatechange = processReqChange;
			req.open("GET", url, true);
			req.send();
		}
	}
	function processReqChange(){
		if(req.readyState == 4){
			if(req.status == 200){
				if(document.getElementById(ajax_target_id)){
					document.getElementById(ajax_target_id).innerHTML = req.responseText;
					return true;
				}else{
					return true;
				}
			}
		}
		return false;
	}
}

function swap_photo(pid,feed){
	var url = "get_photo.php?pid="+pid+"&feed="+feed;
	if(window.XMLHttpRequest){
		req = new XMLHttpRequest();
		req.onreadystatechange = processReqChange;
		req.open("GET", url, true);
		req.send(null);
	}else if(isIE){
		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (req){
			req.onreadystatechange = processReqChange;
			req.open("GET", url, true);
			req.send();
		}
	}
	function processReqChange(){
		if(req.readyState == 4){
			if(req.status == 200){
				if(document.getElementById("photo")){
					document.getElementById("photo").innerHTML = req.responseText;
					return true;
				}else{
					return true;
				}
			}
		}
		return false;
	}
}

// drop/remove a "shade" over the screen
function shade(x){
	if(x==1){
		// display the "shade" element (the transluscent black overlay which covers
		// everything on the screen when a user enters the message_center).
		document.getElementById('shade').style.display='block';
		scroll(0,0);
	}else{
		// Hide the shade element, the message_center element, and set the message_center's
		// innerHTML value to display a "loading" message.
		document.getElementById('shade').style.display='none';
		document.getElementById('message_center').style.display='none';
		document.getElementById('message_center').InnerHTML="Loading Data &#133;";
	}
}

// Open access to the message center for sending meesages to item owners.
function send_message(id){
	shade(1);
	document.getElementById('message_center').style.display='block';
	ajax('/ajax/message_center.php?id='+id+'&'+Math.random(),'message_center');
}

// Open access to the message center for sending meesages to item owners.
function send_message_reply(id){
	shade(1);
	document.getElementById('message_center').style.display='block';
	ajax('/ajax/message_reply.php?id='+id+'&'+Math.random(),'message_center');
}

// Send a message to site admins about an inappropriate listing
function flag_listing(id){
	//alert("This feature is not yet enabled.");
	shade(1);
	document.getElementById('message_center').style.display='block';
	ajax('/ajax/flag_item.php?id='+id+'&'+Math.random(),'message_center');
}




// initiate the message_center element for use later
document.write("<DIV ID='message_center' STYLE='text-align:center;vertical-align:middle;border:1px solid #000000;padding:10px;width:40%;height:75%;background:#ffffff;display:none;position:absolute;top:18%;left:30%;z-index:20;overflow:auto;'>Loading Data &#133;</DIV>");

// initiate the shade element for use later
document.write("<DIV ID='shade' ONCLICK='shade(0);' STYLE='width:100%;height:1000%;background:#000000;display:none;position:absolute;top:0px;left:0px;z-index:10;'>&nbsp;</DIV>");
// Set the alpha transparency level for the shade & message_center elements
if(window.ActiveXObject){
	// IE's values are 0-100
	document.write("<STYLE>#shade{filter:alpha(opacity=80);}<\/STYLE>");
	document.write("<STYLE>#message_center{filter:alpha(opacity=90);}<\/STYLE>");
}else{
	// NON-IE browsers use values in the 0.01 - 1.0 range
	// NOTE: You've got to set the value in two places - one for mozilla, one for khtml-based browsers (Safari, Konqueror, Opera)
	document.write("<STYLE>#shade{opacity:0.8;-moz-opacity:0.8;}<\/STYLE>");
	document.write("<STYLE>#message_center{opacity:0.9;-moz-opacity:0.9;}<\/STYLE>");
}




// This checks to make sure that all required fields have been filled out before submitting a message that alerts site admins to an offensive listing.
function flag_listing_formCheck(form){
	if((!form.name.value)||(!form.email.value)||(!form.reason.selectedIndex)){
		alert("ERROR:\n\nRequired information is missing. Please fill in all required fields.");
		return false;
	}else{
		return true;
	}
}

// This checks to make sure that all required fields have been filled out before submitting a message_center message to another user.
function message_formCheck(form){
	if((!form.name.value)||(!form.email.value)){
		alert("ERROR:\n\nRequired information is missing. Please fill in all required fields.");
		return false;
	}else{
		return true;
	}
}


/*
	Determine the selected option in a set of radio buttons
*/
function radio_check(x){
	for(var i = 0 ; i < x.length ; i++){
		if(x[i].checked){
			// We found a match, so we return that VALUE
			return x[i].value;
		}
	}
	// apparently no radio buttons have been selected, so we return FALSE
	return false;
}

/*
	Strip all non-digits from a user input field
*/
function numbers_only(x){
	var mystring=x.value.toString();
	var output='';
	for(var i = 0 ; i < mystring.length ; i++ ){
		if((mystring.charAt(i) == '.')||(mystring.charAt(i) == '0')||(mystring.charAt(i) == '1')||(mystring.charAt(i) == '2')||(mystring.charAt(i) == '3')||(mystring.charAt(i) == '4')||(mystring.charAt(i) == '5')||(mystring.charAt(i) == '6')||(mystring.charAt(i) == '7')||(mystring.charAt(i) == '8')||(mystring.charAt(i) == '9')){
			output= output +""+mystring.charAt(i);
		}
	}
	x.value=output;
	return output;
}
function digits_only(x){
	var mystring=x.value.toString();
	var output='';
	for(var i = 0 ; i < mystring.length ; i++ ){
		if((mystring.charAt(i) == '0')||(mystring.charAt(i) == '1')||(mystring.charAt(i) == '2')||(mystring.charAt(i) == '3')||(mystring.charAt(i) == '4')||(mystring.charAt(i) == '5')||(mystring.charAt(i) == '6')||(mystring.charAt(i) == '7')||(mystring.charAt(i) == '8')||(mystring.charAt(i) == '9')){
			output= output +""+mystring.charAt(i);
		}
	}
	x.value=output;
	return output;
}

function contact_seller(id){
	shade(1);
}


function confirmSubmit()
{
var agree=confirm("Are you sure you wish to delete this record?");
if (agree)
	return true ;
else
	return false ;
}

var popbackground="lightskyblue"
var windowtitle="Image Window"

function detectexist(obj){
return (typeof obj !="undefined")
}

function jkpopimage(imgpath, popwidth, popheight, textdescription){

function getpos(){
leftpos=(detectexist(window.screenLeft))? screenLeft+document.body.clientWidth/2-popwidth/2 : detectexist(window.screenX)? screenX+innerWidth/2-popwidth/2 : 0
toppos=(detectexist(window.screenTop))? screenTop+document.body.clientHeight/2-popheight/2 : detectexist(window.screenY)? screenY+innerHeight/2-popheight/2 : 0
if (window.opera){
leftpos-=screenLeft
toppos-=screenTop
}
}

getpos()
var winattributes='width='+popwidth+',height='+popheight+',resizable=yes,left='+leftpos+',top='+toppos
var bodyattribute=(popbackground.indexOf(".")!=-1)? 'background="'+popbackground+'"' : 'bgcolor="'+popbackground+'"'
if (typeof jkpopwin=="undefined" || jkpopwin.closed)
jkpopwin=window.open("","",winattributes)
else{
//getpos() //uncomment these 2 lines if you wish subsequent popups to be centered too
//jkpopwin.moveTo(leftpos, toppos)
jkpopwin.resizeTo(popwidth, popheight+30)
}
jkpopwin.document.open()
jkpopwin.document.write('<html><title>'+textdescription+'</title><body><img src="'+imgpath+'" style="margin-bottom: 0.5em"><br><font face=arial size=2>'+textdescription+'</font></body></html>')
jkpopwin.document.close()
jkpopwin.focus()
}
