<?php

/**
* @version 2.8.2
* @package Joomla 2.5
* @subpackage DT Register
* @copyright Copyright (C) 2006 DTH Development
* @copyright contact dthdev@dthdevelopment.com
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
*/

	$document =& JFactory::getDocument();

	$document->addScript( JURI::root(true).'/components/com_dtregister/assets/js/dt_jquery.js');

	$document->addScript( JURI::root(true).'/components/com_dtregister/assets/js/form.js');

    $config = $this->getModel('config');

	$country = $this->getModel('country');

	$row = $this->getModel('location')->location;
    $jusertable = $this->getModel('user')->table->TableJUser;
	$id = JRequest::getVar( 'cid', array(0), 'request', 'array' );

	if($id){

	   $row->load($id[0]);

	}

?>

<script type="text/javascript">
var clicked_button =  '' ;
DTjQuery(document).ready(function(){
  DTjQuery.validator.messages.required;
		
	    DTjQuery(document.adminForm).validate({
                        success: function(label) {
                            label.addClass("success");
                        }
              
                });
	 DTjQuery(".loadpoint").live('blur',function(){
	 	DTjQuery("#lng").addClass('required');
		DTjQuery("#lng").val('');
		if(DTjQuery("#country").val() != "" && DTjQuery("#zip").val() != "") {
			
			 DTjQuery.ajax({
				   url : "index.php?option=com_dtregister&task=getlnglat",
				   data :{country :DTjQuery("#country").val(),zip:DTjQuery("#zip").val(),address:DTjQuery("#address").val(),address2:DTjQuery("#address2").val(),
				          city:DTjQuery("#city").val(),state:DTjQuery("#state").val() },
				   dataType :'json',
				   success : function(data){
				     if(data.success) {
					    DTjQuery("#lng").val(data.location.lng);
						DTjQuery("#lat").val(data.location.lat) ;
						DTjQuery("#lng").removeClass('required');
						if(clicked_button == 'save') {
						    Joomla.submitbutton('save');
						}
					  } else {
					  		 alert(data.errormsg);
					  }
					
				   }
				 });
			
		}
			
	 });
DTjQuery('#imageUpload').click(function(){

    DTjQuery("#task").val("ImageUpload");

     var options = { 

	type :'POST',

	target : '#debug',

    url: 'index.php?no_html=1', 

    iframe : true,

	dataType : 'script',

     success :function(response){

           var $out = DTjQuery('#debug');

            if (typeof response == 'object' && data.nodeType)

                response = elementToString(response.documentElement, true);

            else if (typeof response == 'object')

                response = objToString(response);

               DTjQuery("#task").val("");

                }

   }; 

// pass options to ajaxForm 

  DTjQuery('#adminForm').ajaxSubmit(options);

   return false;

});

 });
Joomla.submitbutton = function(pressbutton) {
    if(pressbutton == "save") {
	  clicked_button = 'save';
	  if(DTjQuery(document.adminForm).valid()){
				
				submitform(pressbutton);
			} 
	} else {
	submitform(pressbutton);
	}

}

</script>

<form action="index.php" method="post" name="adminForm" id="adminForm" enctype="multipart/form-data">

<table width="100%" class="adminform" border="1">

  <tr><td align="left"><?php echo JText::_( 'DT_LOCATION_OWNER' ); ?>:</td>
	
	    <td><?php echo JHTML::_('select.genericlist', DtHtml::options($jusertable->optionslist(),JText::_("DT_SELECT_USER")),'user_id',' ','value','text',$row->user_id)?></td>
	
	    <td align="left">&nbsp;&nbsp;<?php echo JHTML::tooltip((JText::_( 'DT_LOCATION_OWNER_HELP' )), '', 'tooltip.png', '', ''); ?></td>
	
	</tr>  
    
     <tr><td align="left"><?php echo JText::_( 'DT_LOCATION_GLOBAL' ); ?>:</td>
	
	    <td>
        <?php $checked = ($row->public)?'checked':'' ?>
        <input type="hidden" value="0" name="public" class="inputbox" />
		<input type="checkbox" value="1" name="public" <?php echo $checked; ?> class="inputbox" />
		</td>
	
	    <td align="left">&nbsp;&nbsp;<?php echo JHTML::tooltip((JText::_( 'DT_LOCATION_GLOBAL_HELP' )), '', 'tooltip.png', '', ''); ?></td>
	
	</tr>  
   <tr>

      <td><?php echo JText::_( 'DT_NAME'); ?>:</td>
      <td><input type="text" size="40" name="name" value="<?php echo stripslashes($row->name); ?>" /></td>
      <td>&nbsp;</td>

   </tr>

   <tr>

      <td><?php echo JText::_( 'DT_ADDRESS'); ?>:</td>
      <td><input id="address" type="text" size="40" name="address" value="<?php echo stripslashes($row->address); ?>" /></td>
      <td>&nbsp;</td>

   </tr>

     <tr>

      <td><?php echo JText::_( 'DT_ADDRESS2'); ?>:</td>
      <td><input id="address2" type="text" size="40" name="address2" value="<?php echo stripslashes($row->address2); ?>" /></td>
      <td>&nbsp;</td>

   </tr>

    <tr>

      <td><?php echo JText::_( 'DT_CITY'); ?>:</td>
      <td><input id="city" type="text" size="40" name="city" value="<?php echo stripslashes($row->city); ?>" /></td>
      <td>&nbsp;</td>

   </tr>

    <tr>

      <td><?php echo JText::_( 'DT_STATE'); ?>:</td>
      <td><input id="state" type="text" size="40" name="state" value="<?php echo stripslashes($row->state); ?>" /></td>
      <td>&nbsp;</td>

   </tr>

    <tr>

      <td><?php echo JText::_( 'DT_COUNTRY'); ?>:</td><td>

      <?php

        $options=DtHtml::options($country->getCountry());

		echo JHTML::_('select.genericlist', $options,'country',' class =" required loadpoint "', 'value','text',$row->country);

	  ?>

      </td>
      <td>&nbsp;</td>

   </tr>

   <tr>

      <td><?php echo JText::_( 'DT_ZIPCODE'); ?>:</td>
      <td><input id="zip" type="text" size="40"  class =" required loadpoint" name="zip" value="<?php echo $row->zip; ?>" /></td>
      <td>&nbsp;</td>

   </tr>

   <tr>

      <td><?php echo JText::_( 'DT_PHONE'); ?>:</td>
      <td><input type="text" size="40" name="phone" value="<?php echo $row->phone; ?>" /></td>
      <td>&nbsp;</td>

   </tr>

   <tr>

      <td><?php echo JText::_( 'DT_EMAIL'); ?>:</td>
      <td><input type="text" size="40" name="email" value="<?php echo $row->email; ?>" /></td>
      <td>&nbsp;</td>

   </tr>

   <tr>

      <td><?php echo JText::_( 'DT_WEBSITE'); ?>:</td>
      <td><input type="text" size="40" name="website" value="<?php echo $row->website; ?>" />

      &nbsp;&nbsp;&nbsp;&nbsp;<?php echo JText::_( 'DT_INCLUDE_HTTP_HELP'); ?>

      </td>
      <td>&nbsp;</td>

   </tr>
   <tr>

      <td><?php echo JText::_( 'DT_LATITUDE'); ?>:</td>
      <td><input type="text" class ="" id="lat" size="40" name="lat" value="<?php echo $row->lat; ?>" />

      </td>
	  <td align="left">&nbsp;&nbsp;<?php echo JHTML::tooltip((JText::_( 'DT_LATITUDE_HELP' )), '', 'tooltip.png', '', ''); ?></td>

   </tr>

   <tr>

      <td><?php echo JText::_( 'DT_LONGITUDE'); ?>:</td>
      <td><input type="text" class="" id="lng" size="40" name="lng" value="<?php echo $row->lng; ?>" />

      </td>
	  <td align="left">&nbsp;&nbsp;<?php echo JHTML::tooltip((JText::_( 'DT_LONGITUDE_HELP' )), '', 'tooltip.png', '', ''); ?></td>

   </tr>
   
   <tr>

      <td><?php echo JText::_( 'DT_LOCATION_IMAGE'); ?>:</td>

      <td>

      <span id="showimag"><?php 

	  if($row->image!=""){

	  echo "<img src=\"../index.php?option=com_dtregister&w=".$config->getGlobal('location_img_w',150)."&h=".$config->getGlobal('location_img_h',150)."&task=thumb&no_html=1&controller=file&filename=images/dtregister/locations/".basename($row->image)."\" />";

	  }

	  ?>

	  </span><input type="checkbox" <?php echo $row->showimage==1?'checked':'';?> name="showimage" value="1" />

      <input type="file" name="locationimage" /> &nbsp;

      <input type="button" id="imageUpload" value="<?php echo JText::_( 'DT_UPLOAD'); ?>" />

      <input type="hidden" name="image" id="image" value="<?php echo $row->image; ?>" />

      <input type="hidden" name="option" value="com_dtregister" />

      <input type="hidden" name="controller" value="location" />

      <input type="hidden" id="task" name="task" value="" />

      <input type="hidden" name="id" value="<?php echo $row->id; ?>" />

      </td>
	  <td align="left">&nbsp;&nbsp;<?php echo JHTML::tooltip((JText::_( 'DT_LOCATION_IMAGE_CHECKBOX_HELP' )), '', 'tooltip.png', '', ''); ?></td>

   </tr>

</table>

</form>

<div id="debug">

</div>