// Support code for advert upload V1.00
// Also contains one line to activate image upload
var maxtext = 750;						// Limit for textarea. Adjust to keep everything within 1000 char limit.
function kpr(ev){	// ignore return key
	return ((ev.which ? ev.which : ev.keyCode) != '13')
}

function txa(txtarea){	// limit input in textarea
	var l = txtarea.value.length;
	if (l > maxtext)
		{
		txtarea.value = txtarea.value.substring(0, maxtext);	// trim so delete key works
		alert('Maximum number of Description characters exceeded');
		return false;
		}
	return true;
}

function adsub(pid){	// check form and submit
	// Format ID, Short Name, Required
	var allflds = [	'tit', 'Title', 1,
			'des', 'Description', 1,
			'prc', 'Price', 1, 
			'loc', 'Location', 1, 
			'del', 'Delivery Opts.', 1, 
			'pho', 'Phone No.', 1, 
			'ema', 'Email', 1];
	var errs = '';
	var subinf = '';
	for ( var i=0; i<allflds.length; i+=3 )
		{
		// strip any special characters and replace with space
		var fld = document.getElementById(allflds[i] + '$' + pid);
		var name = allflds[i+1];
		var reqd = allflds[i+2];
		fld.value = fld.value.replace(/[¬\¦]/g, ' ');
		// concatenate fields for single form submission entry
		if ( i ) subinf += '¦';
		subinf += name + '¬' + fld.value;
		// warn if any required fields empty
		if ( reqd && (fld.value.length == 0) ) errs += name + ' is required!\r\n';
		}	
	if ( errs != '' )
		{
		alert(errs);
		return false;
		}
	// double-check to see if textarea isn't oversize
	if (! txa(document.getElementById('des$' + pid)) ) return false;
	document.getElementById('adv_' + pid).value = subinf;		// save the values for submitting to Actinic
	// now see if there's an image to be uploaded
	var imgtest = checkoptionalimages(pid,0);			// 0 makes images optional
	return imgtest;	
}		

