function popup( url )
{
  win = window.open( url, '','width=800,height=500,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,left=50,top=50,screenX=50,screenY=50' );
  win.focus();
}

function popupClear()
{
var x = window.open('','','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=auto,resizable=no,copyhistory=no,width=250,height=100,left=200,top=300,screenX=200,screenY=300');
x.document.open('text/html');
x.document.write('<html>');
x.document.write('<head>');
x.document.write('<title>Confirm</title>');
x.document.write('<body topmargin="0" marginheight="0" marginwidth="0" leftmargin="0"><div align="center" valign="middle"><font face="arial, helvetica" size="-1"><p>Are you sure you want to clear your entry?<p><a href="javascript:window.opener.ClearEntry();window.close();">Yes</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:window.close();">No</a></font></div></body>');
x.document.write('</html>');
}

function ClearEntry()
{
for(count=0;count<document.entry.elements.length;count++)
	{
//	alert(document.entry.elements[count].type+'='+document.entry.elements[count].value);
	if((document.entry.elements[count].type.indexOf('text')==0) || (document.entry.elements[count].type.indexOf('file')==0))
	document.entry.elements[count].value = '';	
	}
//window.opener.document.entry.reset();

}

function popupCancel()
{
var x = window.open('','','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=auto,resizable=no,copyhistory=no,width=250,height=100,left=200,top=300,screenX=200,screenY=300');
x.document.open('text/html');
x.document.write('<html>');
x.document.write('<head>');
x.document.write('<title>Confirm</title>');
x.document.write('<body topmargin="0" marginheight="0" marginwidth="0" leftmargin="0"><div align="center" valign="middle"><font face="arial, helvetica" size="-1"><p>Are you sure you want to cancel your listing?<p><a href="javascript:void(window.opener.document.location.href=\'http://www.washingtonpost.com/wp-adv/merchandise\');window.close();">Yes</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:window.close();">No</a></font></div></body>');
x.document.write('</html>');
}

function chkLength()
{
  if( ! document.layers )
  {
    if(document.entry.AD_TEXT.value.length > document.entry.maxChars.value)
    {
      document.entry.AD_TEXT.value=document.entry.AD_TEXT.value.substring(0,document.entry.maxChars.value);
    }
    document.entry.charsTyped.value = document.entry.AD_TEXT.value.length;
  }
}
function resetForm( )
{
  if( confirm( "Are you sure you want to erase all the data you've entered?" ) )
  {
    return true;
  }
  else return false;
}	
function copyDescription()
{
  if( document.all )
  {
    document.selection.clear;
    var adText=document.forms.entry.AD_TEXT.createTextRange();
    adText.execCommand("Copy");
  }
}
// THE FOLLOWING JAVASCRIPT FUNCTIONS ARE USED ON THE MERCHANDISE AD ENTRY PAGE

//==============================//
//------------------------------//
// GOAL: to prefill PRICE with 'N/A' if a user selects a multi-item category from the category list
function checkClass(form)
{

	var classes = form.CLASS;
	
	// loop through select CLASS elements to determine which one was selected
	for(j = 0; j < classes.length; j++)
	{
		var thisClass = classes.options[j];
		if (thisClass.selected)
		{
			var selectedClass = thisClass.value;
			break;
		}
	}
	// if a multi-item class is selected, prefill PRICE with 'NA'.
	//
	if(selectedClass == "345")	{form.LISTING_STATE.selectedIndex = 0;}
	if(selectedClass == "350")	{form.LISTING_STATE.selectedIndex = 1;}
	if(selectedClass == "355")	{form.LISTING_STATE.selectedIndex = 3;}
	if(selectedClass == "1515")	{
		if(form.PRICE.value >= 251) {alert('Please enter a price below $250.00.\nThe maximum amount for Great Deals under $250 is $250.00');}
	}
	// if PRICE contains 'N/A' and a single-item class is selected, empty the PRICE field. 
	if(selectedClass == "338" || selectedClass == "345" || selectedClass == "350" ||
	   selectedClass == "355" || selectedClass == "358" || selectedClass == "360" ||
	   selectedClass == "250" ||  selectedClass == "365")
	{
		form.PRICE.value = "N/A";
		form.PRICE.disabled=true; // DISABLE THE FIELD AFTER DISPLAYING N/A
	}
	else {
		if(form.PRICE.value == "N/A")
		{
			form.PRICE.value = "";
			form.PRICE.disabled = false; // ENABLE THE FIELD AFTER CLEARING 'N/A' FROM IT
		}
	}
	
	// make sure the default selection isn't selected
	if (selectedClass == "novalue" || selectedClass == "-1")
	{
		alert("Please select a valid category from the Category field.");
		form.CLASS.focus();
		return false;
	}
	
	return selectedClass;
}
//==============================//
//------------------------------//
// GOAL: to determine what ad price should be displayed to the user
function checkPrice(form)
{
	var priceEntered = form.PRICE.value;

	if (!IsNumeric(priceEntered) || priceEntered=="0") 
	{ 
		// only alert the user if they enter data other than "N/A" or a number
		if (priceEntered != prefilledPrice && priceEntered != "0")
		{
  			alert("Please enter only numbers or decimal points in the Item Price field"); 
  		}
		else if (priceEntered == "0")
		{
			alert("Please enter a dollar amount greater than zero.");
			//form.PRICE.value = "";
			form.PRICE.focus();
			return false;
		}
		
	  	return 0; 
	}
	else // get the value from the Item Price field
	{
		return priceEntered;
	}
}