function g_o(x){return document.getElementById(x);}
function confirmDelete(x){
 ans = window.confirm("Are you sure you want to delete this " + x + "?\n");
 return ans;
}
function confirmUndelete(x){
 ans = window.confirm("Are you sure you want to undelete this " + x + "?");
 return ans;
}
function hideItem(x,y){
 if(document.getElementById(x).style.display == "none"){
  document.getElementById(x).style.display = "inline";
  document.getElementById(y).innerHTML = "Hide Pane";
 }else{
  document.getElementById(x).style.display = "none";
  document.getElementById(y).innerHTML = "Show Pane";
 }
}
function preview(qs){
 window.open("http://www.uslandandhome.com/ssheet.php?ssheet="+qs);
}
function validate_image(){
 if((uplObj = document.getElementById("image_file")) != null){
  if(uplObj.value != ""){
   fname = uplObj.value.toLowerCase();
   index = fname.length;
   ext = fname.substring(index-4,index);
 }}
 return true;
}
function validate_document(){
 if( (uplObj = document.getElementById("pd_path")) != null){
  if(uplObj.value != ""){
   var fname = uplObj.value.toLowerCase();
   var index = fname.length;
   ext = fname.substring(index - 4, index);
   if(ext != ".doc" && ext != ".pdf" && ext != ".jpg" && ext != ".gif" && ext != "jpeg" && ext != ".rtf"){
    alert("The only formats supported are .doc, .pdf, .rtf, .gif, .jpg/.jpeg.  You are attempting to upload a " +
     ext.substring(1).toUpperCase() + " document.");
    return false;
 }}}
 return true;
}
function change_selected_page()
{
	var so = document.getElementById("page_id");
	var pid = so.options[so.selectedIndex].value;
    document.getElementById("meta-form").submit();
    return 0; 
}
function confirm_delete_all_meta(){
 return window.confirm("Are you sure you want to delete all meta tags for this page?");
}
function cancel_edit(){
 document.getElementById("mvid").value = "";
 return true;
}
function delete_meta_tag(){
 return window.confirm("Are you sure you want to delete this meta tag?");
}
function meta_back(){
 g_o("do_this").value = "go-back";
 return true;
}
// DTW 10/11: Added function to manage on/off meta_name input
// and set focus to appropriate field when type specified.
function metaTypeChange(s_o){
 if(s_o.selectedIndex == 0){
  g_o("meta_name").value = "";
  g_o("meta_name").disabled = true;
  g_o("meta_content").focus();
  g_o("meta_content").select();
 }else{
  g_o("meta_name").disabled = false;
  g_o("meta_name").focus();
  g_o("meta_name").select();  
 }
}
function getFeatures(){
 fto = g_o("feat_type");
 fio = g_o("feat_id");
 if(fto.options[fto.selectedIndex].value != ""){
  x_getFeaturesByType(fto.options[fto.selectedIndex].value,featret);
 }else{
  fio.options.length = 0;
  fio.options[fio.options.length] = new Option("Choose Feature Type/Category","");
 }
}
function featret(x){
 var str = "";
 var c = 0;
 var fio = g_o("feat_id");
 var si  = g_o("sel_opt").value;
 fio.options.length = 0;
 for(var i in x) {
  opt = new Option(x[i]);
  opt.value = i;
  fio.options[fio.options.length] = opt;
  if(si == i){
   fio.options[fio.options.length-1].selected = true;
  }
 }
 g_o("sel_opt").value = "";
}
function addNewFeature(){
 var fto = g_o("feat_type");
 if(fto.selectedIndex <= 0){
  alert("Please select a Feature Type/Category first, then click Add New.");
  return;
 }
 g_o("feat_id").selectedIndex = -1;
 var et = g_o("edit_table");
 et.style.display = "block";
 g_o("editfeature").innerHTML = "Adding New Feature";
 g_o("delbtn").style.visibility = "hidden";
 g_o("feat_image").src = "/images/sm_blank.jpg"; 
 g_o("feat_name").value = "";
 g_o("feat_name").focus();
}
function addnewret(x){
 var fio = g_o("feat_id");
}
function editFeature(){
 var fto = g_o("feat_type");
 var fio = g_o("feat_id");
 if(fto.selectedIndex == 0){
  alert("Please select a valid Feature Type/Category first, then a Feature Name.");
  return;
 }
 if(fio.selectedIndex == -1){
  alert("Please select a valid Feature Name or click the Add New button.");
  return;
 }
 var fid = fio.options[fio.selectedIndex].value;
 var feat_name = fio.options[fio.selectedIndex].text;
 var et = g_o("edit_table");
 et.style.display = "block";
 g_o("delbtn").style.visibility = "visible";
 g_o("editfeature").innerHTML = "Editing Feature \"" + feat_name + "\"";
 g_o("feat_name").value = feat_name;
 x_getFeatureImage(fid,fimgret);
}
function fimgret(x){
 var img = g_o("feat_image");
 var fio = g_o("feat_id");
 var fn  = fio.options[fio.selectedIndex].text;
 img.src = "/images/" + x;
 img.title =  fn;
}
function moveUp(){
 var fid;
 var fio = g_o("feat_id");
 if((fid = fio.options[fio.selectedIndex].value) == "")
  return;
 x_updateFeatureOrder(fid,-1,moveret);
}
function moveDown(){
 var fid;
 var fio = g_o("feat_id");
 if((fid = fio.options[fio.selectedIndex].value) == "")
  return;
 x_updateFeatureOrder(fid,1,moveret);
}
function moveret(x){
 var fio = g_o("feat_id");
 var sio = g_o("sel_opt");
 sio.value = fio.options[fio.selectedIndex].value;
 if(x)
  getFeatures();
}
function changeFeatSelect(){
 var fto = g_o("feat_type");
 var fio = g_o("feat_id");
 if(fto.selectedIndex == 0 || fio.selectedIndex == -1){
  g_o("feat_image").src = "/images/sm_blank.jpg";
  return;
 }
 var fid = fio.options[fio.selectedIndex].value;
 // check to see if we're currently editing
 if(g_o("edit_table").style.display == "block")
  cancelFeature();
 x_getFeatureImage(fid,fimgret);
}
function cancelFeature(){
 var et = g_o("edit_table");
 g_o("feat_name").value = "";
 et.style.display = "none";
}
function updateFeature(){
 var fto = g_o("feat_type");
 var fio = g_o("feat_id");
 if(fto.selectedIndex <= 0)
  return;
 if(g_o("feat_name").value != "")
  g_o("feat_form").submit();
}
function deleteFeature(){
 var fto = g_o("feat_type");
 var fio = g_o("feat_id");
 if(fto.selectedIndex <= 0)
  return;
 if(!confirm("Deleting this feature will ALSO remove all listing associations with this feature (if any exist), are you sure?"))
  return;
 var fid = fio.options[fio.selectedIndex].value;
 x_deleteFeature(fid, delret);
}
function delret(x){
 var fio = g_o("feat_id");
 if(x <= 0) return;
 for(i=0;i<fio.options.length;i++)
  if(fio.options[i].value == x)
   fio.options[i] = null;
 fio.selectedIndex = -1;
 g_o("feat_image").src = "/images/sm_blank.jpg";
 cancelFeature();
}

