// toggleElement(id) --------------------------------------------------------------------------------------------------------
//
// function below is used to show/hide hidden divs 
// It is called with an href pointing to: javascript:toggleElement('some_div_id');
// the div it creates should have an "id" set to the same name as above
function toggleElement(id) 
{ 
	e = window.document.getElementById(id);
	e.style.display = (e.style.display == "block") ? "none" : "block" ; 
}





// writeDiv(id,contents)
//
// use this function to write Divs that are initially hidden from view and in conjunction
// with the function above can be hidden or shown dynamically
function writeDiv(id,contents,linktext) { 
	if (linktext == undefined)linktext = "Learn More";
	closebox = "To close this window, <a href=\"javascript:toggleElement('" + id + "');\" style='color:#06C' onmouseover=\"this.style.color='#3C0';\" onmouseout=\"this.style.color='#06C';\">click here</a>";
	document.write ("<br /><a href=\"javascript:toggleElement('" + id + "');\" style='color:#06C;font-size:10px;' onmouseover=\"this.style.color='#3C0';\" onmouseout=\"this.style.color='#06C';\">" + linktext + "</a>");
	document.write ("<div id='" + id + "' class='help_div' name='" + id + "'>"+ contents + " "+ closebox + "</div>");
}

function writeDiv2(id,contents,linktext) {
	if (linktext == undefined)linktext = "Learn More";
	closebox = "To close this window, <a href=\"javascript:toggleElement('" + id + "');\" style='color:#06C' onmouseover=\"this.style.color='#3C0';\" onmouseout=\"this.style.color='#06C';\">click here</a>";
	document.write ("<a href=\"javascript:toggleElement('" + id + "');\" style='color:#06C;font-size:10px;' onmouseover=\"this.style.color='#3C0';\" onmouseout=\"this.style.color='#06C';\">" + linktext + "</a><br />");
	document.write ("<div id='" + id + "' class='cat_div' name='" + id + "'>"+ contents + " "+ closebox + "</div>");
}


function writeAboutSearchDiv(id,contents,linktext) { 
	if (linktext == undefined)linktext = "Learn More";
	closebox = "To close this window, <a href=\"javascript:toggleElement('" + id + "');\" style='color:#06C' onmouseover=\"this.style.color='#3C0';\" onmouseout=\"this.style.color='#06C';\">click here</a>";
	document.write ("<a href=\"javascript:toggleElement('" + id + "');\" style='color:#06C;font-size:10px;' onmouseover=\"this.style.color='#3C0';\" onmouseout=\"this.style.color='#06C';\">" + linktext + "</a>");
	document.write ("<div id='" + id + "' class='help_div' name='" + id + "'>"+ contents + " "+ closebox + "</div>");
}



// openWinURL(winURL, winWidth, winHeight, winFeatures, winLeft, winTop) -----------------------------------------------------
//
// window popup function for external files, set height and width in pixels
// for for Features, you have have (set to 1 or 0 generally)
//		status  	The status bar at the bottom of the window.
//		toolbar 	The standard browser toolbar, with buttons such as Back and Forward.
//		location 	The Location entry field where you enter the URL.
//		menubar 	The menu bar of the window
//		directories The standard browser directory buttons, such as What's New and What's Cool
//		resizable 	Allow/Disallow the user to resize the window.
//		scrollbars 	Enable the scrollbars if the document is bigger than the window
//	for winLeft and winTop, send the function 0,0 for top left of "cen", "cen" to make the window centered
function openWinURL(winURL, winWidth, winHeight, winFeatures, winLeft, winTop) 
{
	var popWin = null    // use this when referring to pop-up window
	var winCount = 0
	var winName = "popWinx"
	var d_winLeft = 0  // default, pixels from screen left to window left
	var d_winTop = 0   // default, pixels from screen top to window top
	winName = "popWinx" + winCount++ // unique name for each pop-up window
	// close any previously opened pop-up window
	if (navigator.appName != "Microsoft Internet Explorer" || parseInt(navigator.appVersion) >=4) //do not close if early IE
	{
		if(popWin != null) if(!popWin.closed) popWin.close() 
	}
	if (openWinURL.arguments.length >= 4)  // any additional features? 
	{
		winFeatures = "," + winFeatures
	}
	else 
	{
		winFeatures = "" 
	}
	if (openWinURL.arguments.length == 6)  // location specified
	{
		winFeatures += getLocation(winWidth, winHeight, winLeft, winTop)
	}
	else
	{
		winFeatures += getLocation(winWidth, winHeight, d_winLeft, d_winTop)
	}
	popWin = window.open(winURL, winName, "width=" + winWidth  + ",height=" + winHeight + winFeatures)
}
// function below is part of function above
function getLocation(winWidth, winHeight, winLeft, winTop)
{
  var winLocation = ""
  if (winLeft < 0) 		winLeft = screen.width - winWidth + winLeft
  if (winTop < 0) 		winTop = screen.height - winHeight + winTop
  if (winTop == "cen")  winTop = (screen.height - winHeight)/2 - 20
  if (winLeft == "cen") winLeft = (screen.width - winWidth)/2
  if (winLeft>0 & winTop>0)
  {
    winLocation =  ",screenX=" + winLeft + ",left=" + winLeft + ",screenY=" + winTop + ",top=" + winTop
  }
  else
  {
    winLocation = ""
  }
  return winLocation
}






// openWinTXT(winTXT, winWidth, winHeight, winFeatures, winLeft, winTop) -----------------------------------------------------
//
// this function is identical to the one above but allows you to send it text and it will display the text on 
// the page instead of a URL. Notice that the HTML tags are started (and css files included) so you need to supply something like
//		<title>something</title></head>
//		<body>some text
// you do NOT need to open the head tag or close the body tag or include any html tags
function openWinTXT(winTXT, winWidth, winHeight, winFeatures, winLeft, winTop) 
{
	var popWin = null    // use this when referring to pop-up window
	var winCount = 0
	var winName = "popWinx"
	var d_winLeft = 0  // default, pixels from screen left to window left
	var d_winTop = 0   // default, pixels from screen top to window top
	winName = "popWinx" + winCount++ // unique name for each pop-up window
	// close any previously opened pop-up window
	if (navigator.appName != "Microsoft Internet Explorer" || parseInt(navigator.appVersion) >=4) //do not close if early IE
	{
		if(popWin != null) if(!popWin.closed) popWin.close() 
	}
	if (openWinTXT.arguments.length >= 4)  // any additional features? 
	{
		winFeatures = "," + winFeatures
	}
	else 
	{
		winFeatures = "" 
	}
	if (openWinTXT.arguments.length == 6)  // location specified
	{
		winFeatures += getLocation(winWidth, winHeight, winLeft, winTop)
	}
	else
	{
		winFeatures += getLocation(winWidth, winHeight, d_winLeft, d_winTop)
	}
	popWin = window.open('', winName, "width=" + winWidth  + ",height=" + winHeight + winFeatures)
	popWin.document.write('<html><head>');
	popWin.document.write("<link href='/vl.css' rel='stylesheet' type='text/css'><link href='/vl_anchors.css' rel='stylesheet' type='text/css'><link href='/vl_block_elements.css' rel='stylesheet' type='text/css'>");
	popWin.document.write(winTXT);
	popWin.document.write('</body></html>');
	popWin.document.close();
}


// PhotoUpload()
//
// this function is called on the photo upload page - it disables the buttons and shows the DIV
function photo_submit()
{
	if (window.document.PostForm._qf_Form_photo_upload.value == "Upload") 
	{
		window.document.getElementById("upload_progress").style.display	= "block";
		document.PostForm._qf_Form_photo_back.disabled 	= true;
		document.PostForm._qf_Form_photo_next.disabled 	= true;
		if (document.PostForm._qf_Form_photo_delete) document.PostForm._qf_Form_photo_delete.disabled = true;
	}	
}


// storeDefaultHeadline()
//
// This function sets a variable with the current value of the headline or title
// of a listing/posting/whathave you so that in the future we can check it 
// against a new value.
function setSubject()
{
	var oField = document.getElementsByName("subject")[0];
	global_OldHeadline = oField.value;
}

function alertIfSubjectChanged()
{
	var oField = document.getElementsByName("subject")[0];
	
	if ("" == global_OldHeadline)
	{
		return;
	}
	
	if (global_OldHeadline != oField.value)
	{
		alert('Note: Changing the title of your posting will cause the URL of your listing to change.')
	}
	
	return;
}