// JavaScript Document

function setActionAndSubmit(action, inForm){
//function setActionAndSubmit(){
	//alert(action);
	document.getElementById(inForm).action = action;
	document.getElementById(inForm).submit();
}

/*
	saveNewsStoryForm
	-this attempts to save and redirect to story edit page
*/
function saveClassifiedForm(next_value, formName){

	var bErrors = false;
	var bErrorStr = '';
	
	var xform = getObject(formName);

	//error checking
	if(xform.clist_title){
		if(edit_form.clist_title.value==''){
			bErrors = true;
			bErrorStr = 'The Headline field is required.';
			xform.clist_title.className = 'jserror';
		}
	}

	//this value tells the form where to redirect after saving
	//edit_form.cm_next.value = next_value;
	//document.getElementById("cm_next").value = next_value;
	
	//TODO: do some error checking
	
	//submit xform POST
	if(bErrors){
		alert(bErrorStr);
	}else{
		//disable all the news story form buttons
		//disableNewsStoryButtons(xform);
	
		//alert('submit');
		xform.submit();
	}

}

function deleteClassified(survey_id){
	url = "/account/index.php?m=classifieds&cm=delete&cid="+survey_id;
	message = "Are you sure you want to delete this ad?";
	confirmAction(url,message);
}
function deleteClassifiedCat(survey_id){
	url = "/access/account.php?m=classifieds&cm=s_cdelete&ccid="+survey_id;
	message = "Are you sure you want to delete this ad?";
	confirmAction(url,message);
}


/* 	###############################
	place ad forms
	############################## */
	
/*
	saveNewsStoryForm
	-this attempts to save and redirect to story edit page
*/
function savePlaceAdForm(next_value){

	var bErrors = false;
	var bErrorStr = '';
	
	var xform = getObject('edit_form');

	//error checking
	if(xform.news_title){
		if(xform.news_title.value==''){
			bErrors = true;
			bErrorStr = 'The Headline field is required.';
			xform.news_title.className = 'jserror';
		}
	}

	//this value tells the form where to redirect after saving
	xform.nm_next.value = next_value;
	
	//TODO: do some error checking
	
	//submit xform POST
	if(bErrors){
		alert(bErrorStr);
	}else{
		//disable all the news story form buttons
		//disableNewsStoryButtons(xform);
	
		//alert('submit');
		xform.submit();
	}

}

//Contador de caracteres.
function Contar(source_field,target_update,texto,max_characters) {
  var entradaObj=getObject(source_field);
  var salidaObj=getObject(target_update);
  var longitud=max_characters - entradaObj.value.length;
  if(longitud <= 0) {
    longitud=0;
    texto='<span class="disable"> '+texto+' </span>';
    entradaObj.value=entradaObj.value.substr(0,max_characters);
  }
  salidaObj.innerHTML = texto.replace("{CHAR}",max_characters-longitud);
}


