function showPicChoices(select) {
	var num = select.selectedIndex;
	if (num == 0) {
		var h = select.options[0].value;
		var s = select.options[1].value;
		Element.hide(s);
		Element.show(h);
	}
	if (num == 1) {
		var h = select.options[0].value;
		var s = select.options[1].value;
		Element.hide(h);
		Element.show(s);
	}
}

function updateFileUploadText(txt,field) {
	var rmtext = "JavaScript: resetFileUploadText('" + txt + "');";
	var newText = $(field).value;
	if (newText.indexOf('/') != -1) newText = newText.substring(newText.lastIndexOf('/')+1,newText.length);
	if (newText.indexOf('\\') != -1) newText = newText.substring(newText.lastIndexOf('\\')+1,newText.length);
	if (newText != '') $(txt).innerHTML = '<span class="subdued" title="Click Apply Changes to see updates">' + newText + '</span>'
		+ '&nbsp;&nbsp;<a href="'+rmtext+'">Cancel</a>';
}

function updateExtraPicture(count) {
	var select = 'pictures_selector_' + count;
    var txt = 'img_info_' + count;
    var field = 'item_image_' + count;
    var select_val = 'item_image_upload_' + count;
    var url_txt_field = 'item_image_url_field_' + count;
    
    if ($('pictures_selector_' + count).type == "checkbox") {
        $(select).checked = true;
    } else {
        $(select).value = select_val;
    }
        
	var rmtext = 'JavaScript:resetFileUploadText(\''+txt+'\',\''+select+'\');';
	var newText = $(field).value;
	if (newText.indexOf('/') != -1) newText = newText.substring(newText.lastIndexOf('/')+1,newText.length);
	if (newText.indexOf('\\') != -1) newText = newText.substring(newText.lastIndexOf('\\')+1,newText.length);
	if (newText != '') $(txt).innerHTML = '<span class="subdued" title="Click Create/Update to see changes">' + newText + '</span>'
		+ '&nbsp;&nbsp;<a href="'+rmtext+'">Cancel</a>';
    $(url_txt_field).value = "";       
}

function resetFileUploadText(txt) {
	if ($(txt)) $(txt).innerHTML = '<span class="subdued" title="None selected">None Selected</span>';
}
function deleteFileUploadText(txt) {
	if ($(txt)) $(txt).innerHTML = '<span class="subdued" title="None selected">Pending removal</span>';
}

function setShippingValues() {
	var form_ele = $('item_form');
	var el_check = $('item_shipping_method');
	if (el_check) {
		var val = form_ele.item_shipping_method.options[form_ele.item_shipping_method.selectedIndex].value;
		if (val == 'BUYER') {
			if ($('item_shipping_charge')) Element.show('buyer_pays_fixed_field');
			if ($('item_auto_invoice')) $('item_auto_invoice').disabled = false;
		} else {
			if ($('item_shipping_charge')) Element.hide('buyer_pays_fixed_field');
			if ($('item_auto_invoice')) $('item_auto_invoice').disabled = true;
		}
	}
}
	
function configTinyMCE() {
	tinyMCE.init({
		mode : "exact",
		theme : "advanced",
		elements : "item_description",
		width : "400",
		height : "256",
		plugins : "table",
		theme_advanced_buttons1 : "bold,italic,underline,separator,sub,sup,separator,hr,link,unlink,anchor,separator,forecolor,backcolor,charmap",
		theme_advanced_buttons2 : "table,bullist,numlist,separator,outdent,indent,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,removeformat,cleanup,code",
		theme_advanced_buttons3 : "cut,copy,paste,separator,undo,redo,separator,help"
	});
}

function setKeywordsWith(full_keyword_string) {
	var kw_ar = full_keyword_string.split("\\n");
	if ($('keywords_one')) { $('keywords_one').value = (kw_ar.length > 0) ? kw_ar[0] : ""; }
	if ($('keywords_two')) { $('keywords_two').value = (kw_ar.length > 1) ? kw_ar[1] : ""; }
	if ($('keywords_three')) { $('keywords_three').value = (kw_ar.length > 2) ? kw_ar[2] : ""; }
	if ($('keywords_four')) { $('keywords_four').value = (kw_ar.length > 3) ? kw_ar[3] : ""; }
}