// JavaScript Document
var objAjax = new ajaxFunction();

function submitthis(startval){
	document.pagination.start.value=startval;
	document.pagination.submit();
}

function shortbysubmit(bywhat,order){
	document.shortform.sortby.value=bywhat;
	document.shortform.sortorder.value=order;
	document.shortform.submit();
}

function delete_property(building_id) {
  if (building_id) {
    if (confirm ('Are you sure! you want to DELETE this propery?')) {
      appear('id_message_div')
      html = '<font>Processing...</font>';
      inner_html('id_message_div',html);
      
      var file_url = adminurl+"ajax_serverPage.php?case=delete_property&building_id="+building_id+"&sid="+Math.random();
      
      objAjax.open("GET",file_url,true);
      objAjax.onreadystatechange=function() {
      if (objAjax.readyState==3) {
        html = '<font>Deleting...</font>';
        inner_html('id_message_div',html);
      }
      if(objAjax.readyState==4) {
        //alert(objAjax.responseText);
        result_str = objAjax.responseText;
        if (result_str == 'Deleted') {
          document.getElementById('tr_property_'+building_id).style.display='none';
        }
        var html = "&nbsp;";
        inner_html('id_message_div',html);
      }
      }
      objAjax.send(null);
      disappear('id_message_div');          
    }
    else {
      return false;
    }
  }
}

function delete_selected_images() {
  var form = window.document.propadd;
  var comma=building_id='';
  for (var f=0; f<form.length; f++){
    if (form[f].type=='checkbox')
    {
      if(form[f].checked ) {
        building_id +=comma+form[f].value;
        comma=',';
      }
    }
  }
  if (building_id) {
      document.getElementById('id_p').value=building_id;
      var file_url = adminurl+"ajax_serverPage.php?case=admin_delete_prop_image&building_id="+building_id+"&sid="+Math.random();
      
      objAjax.open("GET",file_url,true);
      objAjax.onreadystatechange=function() {
        if(objAjax.readyState==4) {
          //alert(objAjax.responseText);
          result_str = objAjax.responseText;
          if (result_str=='success') {
            var prop_ides = building_id.split(',');
            for (var i=0; i<prop_ides.length; i++)
            {
              var img=new Image();
              
              img = document.getElementById('imgid'+prop_ides[i]);
              img.src="../images/no_image_icon_sm.gif";
              document.getElementById('chk'+prop_ides[i]).checked=false;
            }
          }
        }
      }
      objAjax.send(null);
  }
  else {
    alert('Please select any property then click Delete');
    return false;
  }
  

}

function set_uploaded_image() {
  var form = window.document.propadd;
  var comma=building_id='';
  for (var f=0; f<form.length; f++){
    if (form[f].type=='checkbox')
    {
      if(form[f].checked ) {
        building_id +=comma+form[f].value;
        comma=',';
      }
    }
  }
  
  var imagename=document.getElementById('id_selected_image').value;
  //alert('imagename: '+imagename+' building_id: '+building_id);
  if (building_id) {
      document.getElementById('id_p').value=building_id;
      var file_url = adminurl+"ajax_serverPage.php?case=admin_prop_image&imagename="+imagename+"&building_id="+building_id+"&sid="+Math.random();
      
      objAjax.open("GET",file_url,true);
      objAjax.onreadystatechange=function() {
        if(objAjax.readyState==4) {
          //alert(objAjax.responseText);
          result_str = objAjax.responseText;
          if (result_str=='success') {
            var prop_ides = building_id.split(',');
            for (var i=0; i<prop_ides.length; i++)
            {
              img = document.getElementById('imgid'+prop_ides[i]);
              img.src="../resize.php?pic="+imagename+"&folder=buildings&width=100&height=200";
              document.getElementById('chk'+prop_ides[i]).checked=false;
            }
          }
        }
      }
      objAjax.send(null);
  }
  else {
    alert('Please select any property and upload image');
    return false;
  }
}
