// JavaScript Document

function setActionAndSubmit(action, inForm){
//function setActionAndSubmit(){
	//alert(action);
	document.getElementById(inForm).action = action;
	document.getElementById(inForm).submit();
}

function getObject(obj) {
  var theObj;
  if(document.all) {
    if(typeof obj=="string") {
      return document.all(obj);
    } else {
      return obj.style;
    }
  }
  if(document.getElementById) {
    if(typeof obj=="string") {
      return document.getElementById(obj);
    } else {
      return obj.style;
    }
  }
  return null;
}

/*
	saveNewsStoryForm
	-this attempts to save and redirect to story edit page
*/
function saveBoatForm(next_value, formName){
	var bErrors = false;
	var bErrorStr = '';
	
	var xform = getObject(formName);

	//error checking
	//if(xform.clist_title){
	//	if(edit_form.boat_title.value==''){
	//		bErrors = true;
	//		bErrorStr = 'The Title 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 deleteBoat(survey_id){
	//alert('yo');
	url = "/account/index.php?m=boat&cm=delete&cid="+survey_id;
	message = "Are you sure you want to delete this ad?";
	confirmAction(url,message);
}
function deleteBoatCat(survey_id){
	
	url = "/account/index.php?m=boat&cm=s_cdelete&ccid="+survey_id;
	message = "Are you sure you want to delete this ad?";
	confirmAction(url,message);
}


function confirmAction(url,message){
	var box = confirm(message);
	if(box){
		window.location = url;
	}
}

function deletePhotoBlockItem(pb_id){
	url = "/access/account.php?m=pblock&nm=delete&sid="+pb_id;
	message = "Are you sure you want to delete this photo?";
	confirmAction(url,message);
}

function toggleCommentsButton(xform){
	xform.nm_update_comments.value="true";
	xform.submit();
}

function deleteUser(user_id){
	url = "/access/account.php?m=users&nm=delete&uid="+user_id;
	message = "Are you sure you want to delete this user?";
	confirmAction(url,message);
}

function setFormValue(field,n_value){
	document.getElementById(field).value = n_value;
}

function toggleEditThumbnail(){
	//alert('thumb');
	hideAllEditPhotoDisplay();
	showXDiv('EditPhotoThumbnail');
}

function toggleEditSmall(){
	//alert('small');
	hideAllEditPhotoDisplay();
	showXDiv('EditPhotoSmall');
}

function toggleEditMedium(){
	//alert('small');
	hideAllEditPhotoDisplay();
	showXDiv('EditPhotoMedium');
}

function toggleEditSource(){
	//alert('small');
	hideAllEditPhotoDisplay();
	showXDiv('EditPhotoSource');
}

function hideAllEditPhotoDisplay(){

	hideXDiv('EditPhotoThumbnail');
	hideXDiv('EditPhotoSmall');
	hideXDiv('EditPhotoMedium');
	hideXDiv('EditPhotoSource');

}

function hideXDiv(div_name){
	eSmall = getObject(div_name);
	if(eSmall){
		eSmall.style.visibility = 'hidden'; 
		eSmall.style.display = 'none';
	}
}

function showXDiv(div_name){
	eSmall = getObject(div_name);
	if(eSmall){
		eSmall.style.visibility = 'visible'; 
		eSmall.style.display = 'block';
	}
}

