function textCounter(field, countfield, countbar, maxlimit)
{
/*
alert ("field: " + field);
alert ("field: " + document.getElementById(field).value);
alert ("countfield: " + document.getElementById(countfield).childNodes[0].nodeValue);
alert ("countfield: " + countfield);
alert ("maxlimit: " + maxlimit);
*/
	if (document.getElementById(field).value.length > maxlimit)
	{
		document.getElementById(field).value = document.getElementById(field).value.substring(0, maxlimit);
	}
	else
	{
		width = document.getElementById(field).value.length * 2;
		document.getElementById(countfield).childNodes[0].nodeValue = maxlimit - document.getElementById(field).value.length;
		setStyle (document.getElementById(countbar), "width: " + width + "px;");
	}
}

function setCounterBar(countbar, width)
{
	width = width * 2;
	setStyle (document.getElementById(countbar), "width: " + width + "px;");
}

function changePhotoAccess()
{
	if (document.getElementById('photo').disabled)
		document.getElementById('photo').disabled = false;
	else
		document.getElementById('photo').disabled = true;
}

function checkConfirmation()
{
	if (!document.getElementById('confirm_listing').checked)
	{
		alert ("Please confirm that you have reviewed your listing.\n\nYou will be unable to modify it following this page.");
		document.getElementById('confirm_listing').focus();
		return false;
	}
	
	return true;
}

function checkConfirmationDale()
{
	if (!document.getElementById('confirm_listing').checked)
	{
		alert ("Dale, have you confirmed that you have reviewed this listing.");
		document.getElementById('confirm_listing').focus();
		return false;
	}
	
	return true;
}

function setStyle(object, styleText)
{
	if( object.style.setAttribute )
	{
		object.style.setAttribute("cssText", styleText );
	}
	else
	{
		object.setAttribute("style", styleText );
	}
}

function checkPromoCode()
{
//	alert (document.getElementById('promocode').value);

	var strParams = "";
	var promocode = document.getElementById('promocode').value;

	strParams = 'action=check_promocode&promocode='+promocode;
	var url = 'ajax/actions.php';
	
//	timer = setTimeout("checkPromoCode();", check_delay);

	var loader1 = new net.ContentLoader(url,checkPromoCodeResponse,null,"POST",strParams);
	return false;
}

function checkPromoCodeResponse()
{
//	alert (document.getElementById('promocode').value);

	if (this.req)
	{
		var listing_store = "";
		var xmlDoc = this.req.responseXML.documentElement;

		var promocode = xmlDoc.getElementsByTagName('Promocode')[0].firstChild.nodeValue;
		var validcode = xmlDoc.getElementsByTagName('Validcode')[0].firstChild.nodeValue;
		if (xmlDoc.getElementsByTagName('Listing_store')[0])
			listing_store = xmlDoc.getElementsByTagName('Listing_store')[0].firstChild.nodeValue;

/*		
		alert("Callback Complete."
			  +"\n\npromocode:"+promocode
			  +"\n\nvalidcode:"+validcode
			  +"\n\nreadyState:"+this.req.readyState
			  +"\n\nstatus:"+this.req.status
			  +"\n\nheaders:"+this.req.getAllResponseHeaders()
			  +"\n\n"+this.req.responseText
			  );
*/
		document.getElementById("listing_store").value = listing_store;

		if (validcode=="Y")
		{
			
			document.getElementById("paypal_link").className = "hide";
			document.getElementById("promocode_link").className = "show";
		}
		else
		{
			document.getElementById("paypal_link").className = "show";
			document.getElementById("promocode_link").className = "hide";
		}
	}
}

function redeemPromoCode()
{

	if (!document.getElementById('confirm_listing').checked)
	{
		alert ("Please confirm that you have reviewed your listing.\n\nYou will be unable to modify it following this page.");
		document.getElementById('confirm_listing').focus();
		return false;
	}

	var strParams = "";
	var promocode = document.getElementById('promocode').value;
	var custom = document.getElementById('custom').value;
	var listing_store = document.getElementById('listing_store').value;

	strParams = 'action=redeem_promocode&promocode='+promocode+'&custom='+custom+'&listing_store='+listing_store;
	var url = 'ajax/actions.php';
	
	var loader1 = new net.ContentLoader(url,redeemPromoCodeResponse,null,"POST",strParams);
	return false;
}

function redeemPromoCodeResponse()
{
	if (this.req)
	{
		var xmlDoc = this.req.responseXML.documentElement;

		var promocode = xmlDoc.getElementsByTagName('Promocode')[0].firstChild.nodeValue;
		var listed = xmlDoc.getElementsByTagName('Listed')[0].firstChild.nodeValue;

/*		
		alert("Callback Complete."
			  +"\n\npromocode:"+promocode
			  +"\n\nvalidcode:"+validcode
			  +"\n\nreadyState:"+this.req.readyState
			  +"\n\nstatus:"+this.req.status
			  +"\n\nheaders:"+this.req.getAllResponseHeaders()
			  +"\n\n"+this.req.responseText
			  );
*/

		if (listed=="Y")
		{
			document.getElementById('promocode').disabled = true;
			document.getElementById("promocode_link").className = "hide";
			document.getElementById("reviewed_listing").className = "hide";
			document.getElementById("listing_complete").className = "show";
		}
	}
}

