function changeCategory(cat_id, url_prefix) {
    showNonAttachmentFields(true);

	if(undefined == cat_id || cat_id.length == 0) {
		return;
	}

	entry_id = $j("#EntryId").attr('value');
	if(undefined == entry_id || entry_id == '') {
		entry_id = '0';
	}

    var url = url_prefix + 'categories/get_options/' + cat_id + '/' + entry_id + '/' + new Date().getTime();

	$j.get(url, function (data) {
		if(undefined != data) {
			//var alreadyExists = $j('#EntryOptions').html().length > 0 ? true : false;
			$j('#EntryOptions').html(data);
			//$j('#EntryOptions').backgroundFlash("#FFFFCC");
		}
	});

	return;
}


function changeCategoryNew(cat_id, url_prefix) {
    showNonAttachmentFields(true);

	if(undefined == cat_id || cat_id.length == 0) {
		return;
	}

	entry_id = $j("#EntryId").attr('value');
	if(undefined == entry_id || entry_id == '') {
		entry_id = '0';
	}

    var url = url_prefix + 'categories/get_options_new/' + cat_id + '/' + entry_id + '/' + new Date().getTime();

	$j.get(url, function (data) {
		if(undefined != data) {
			//var alreadyExists = $j('#EntryOptions').html().length > 0 ? true : false;
			$j('#EntryOptions').html(data);
			//$j('#EntryOptions').backgroundFlash("#FFFFCC");
		}
	});

	return;
}


function showAttachmentsHelp() {
	//$j("#AttachmentHelpTxt").toggle();
	$j("#AttachmentHelpTxt").fadeToggle(1000);
}


function changeDivision(division_id, ignore_entries, url_prefix, circ_group_id) {
    showNonAttachmentFields(true);

	if(undefined == division_id || division_id.length == 0) {
  		return;
  	}
	
	if(typeof(circ_group_id) == 'undefined'){
		circ_group_id = 0;
	}
  
	$j.get(url_prefix + 'entries/get_categories/' + division_id + '/' + circ_group_id + '/' + ignore_entries + '/' + new Date().getTime(), function (data) {
		if(undefined != data) {
			$j('#CategoryWrapper').html(data);
			//$j('#EntryCategoryWrapper').backgroundFlash("#FFFFCC");
			$j("#CategoryDescription").html('');
			$j("#CategoryDescription").hide();
		}
	});
}


function changeDivisionNew(division_id, ignore_entries, url_prefix, circ_group_id) {
    showNonAttachmentFields(true);

	if(undefined == division_id || division_id.length == 0) {
  		return;
  	}
	
	if(typeof(circ_group_id) == 'undefined'){
		circ_group_id = 0;
	}
  
	$j.get(url_prefix + 'entries/get_categories_new/' + division_id + '/' + circ_group_id + '/' + ignore_entries + '/' + new Date().getTime(), function (data) {
		if(undefined != data) {
			$j('#CategoryWrapper').html(data);
			//$j('#EntryCategoryWrapper').backgroundFlash("#FFFFCC");
			$j("#CategoryDescription").html('');
			$j("#CategoryDescription").hide();
		}
	});
}



function hideNonAttachmentFields(hideReqFlds) {	
    if(typeof hideReqFlds != 'undefined') {
        $j('#EntryReqFldsWrapper').hide();
    }
	$j('#EntryCreditsWrapper').hide();
	$j('#EntryCommentWrap').hide();
    $j('#EntryUrlWrap').hide();
    $j('#EntryPagesWrap').hide();
    //$j('#existing-attachments-wrapper').hide();
	$j('.submit').hide();
}

function showNonAttachmentFields(hideAttachment){
    if(typeof hideAttachment != 'undefined') {
        $j('#upload-wrapper').hide();
    }
    $j('#EntryReqFldsWrapper').show();
	$j('#EntryCreditsWrapper').show();
	$j('#EntryCommentWrap').show();
    $j('#EntryUrlWrap').show();
    $j('#EntryPagesWrap').show();
    //$j('#existing-attachments-wrapper').show();
	$j('.submit').show();
}

function prepareAttachmentsForm(gotOneAttachment) {
	if(gotOneAttachment == true) {
		//$j('#upload-button').attr('value', 'Upload Another');
		$j('#continue-wrapper').show();
	}
	$j('#upload-wrapper').show();
	$j('#progress-wrapper').hide();
    $j('#EntryReqFldsWrapper').show();
    //$j('#existing-attachments-wrapper').show();

    $j("#EntryAttachmentFilename").replaceWith('<input type="file" id="EntryAttachmentFilename" value="" name="data[EntryAttachment][filename]"/>');
}

var fileCount=1;

function addMore()
{
	var limit;
	var attachmentCount;
	var remainCount;
	limit=parseInt($j('#EntryAttachmentLimit').val());
	attachmentCount=parseInt($j('#EntryAttachmentCount').val());
	remainCount=limit-attachmentCount;	
	 if(fileCount < remainCount){
	 $j("#upload_attachment").append('<div id="file'+fileCount+'" style="width:365px"><input type="file" id="EntryAttachmentFilename" value="" name="data[EntryAttachment][filename'+fileCount+']"/><span style="float:left;cursor:pointer;" onclick=removefile("file'+fileCount+'")>[Remove]</span></div>');
	 fileCount=fileCount+1;
	 }
}


function removefile(divId)
{
	$j('#'+divId).remove();
	fileCount=fileCount-1;
}





function continueEntry(noMoreAttachments) {
	$j('#upload-wrapper').hide();
	$j('#progress-wrapper').hide();
	if (typeof noMoreAttachments == "undefined") {
        $j('#upload-another-wrapper').show();
    }
	showNonAttachmentFields();
}


function randomString(numChars) {
	if (typeof numChars == "undefined") {
		numChars = 8;
	}
	
	var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
	var ranStr = '';
	for(var i=0; i < numChars; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		ranStr += chars.substring(rnum,rnum+1);
	}
	return ranStr;
}

function getData(formName)
{
$j('#'+formName.id).submit();
}

function ApplyallPrice()
{
	var basePrice;
	basePrice=$j('#EntryFeeBasePrice').val();
	
	$j(".text").each(function(){
							  $j(this).attr('value',basePrice);
							  });	
	
	return false;
	
	
}

function printReprt()
{
	var content = document.getElementById("NewspaperHome");
	var pri = document.getElementById("ifmcontentstoprint").contentWindow;
	pri.document.open();
	pri.document.write(content.innerHTML);
	pri.document.close();
	pri.focus();
	pri.print();
}

