<?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');
    $country = $this->getModel('country');
	$jusertable = $this->getModel('user')->table->TableJUser;
	
?>

<script type="text/javascript">

DTjQuery(document).ready(function(){

  DTjQuery.validator.messages.required;
		
	    DTjQuery(document.adminForm).validate({
                        success: function(label) {
                            label.addClass("success");
                        }
              
                });
	 DTjQuery(".loadpoint").live('blur',function(){
	 	
		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)
					  } 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(data){
       
	   DTjQuery("#task").val("");

	}

   }; 

// pass options to ajaxForm 

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

   return false;

});

 });

Joomla.submitbutton = function(pressbutton) {
    if(pressbutton == "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')?></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>
        
        <input type="hidden" value="0" name="public" class="inputbox" />
		<input type="checkbox" value="1" name="public" 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" /></td>
      <td>&nbsp;</td>

   </tr>

   <tr>

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

   </tr>

   <tr>

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

   </tr>

   <tr>

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

   </tr>

   <tr>

      <td><?php echo JText::_( 'DT_STATE'); ?>:</td>
      <td><input id="state" type="text" size="40" name="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','United States');
	  ?>
      </td>
      <td>&nbsp;</td>

   </tr>
 
   <tr>

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

   </tr>

   <tr>

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

   </tr>

   <tr>

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

   </tr>
    <tr>

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

      &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" size="40" name="lat" id="lat" class="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="lng" id="lng" size="40" name="lng" value="" />

      </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>
      <input type="hidden" name="image" id="image" />

      <input type="hidden" name="option" value="<?php echo DTR_COM_COMPONENT ;?>" />
      <input type="hidden" name="controller" value="location" />

      <input type="hidden" id="task" name="task" value="" />
      <span id="showimag"></span><input type="checkbox" name="showimage" value="1" />

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

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

      </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>