<?//php echo $cropwidth."X".$cropheight;?>
<script type="text/javascript" src="<?php echo GLOBAL_ADMIN_JS_PATH?>jquery/jquery-1.4.2.js"></script>
<script type="text/javascript" src="<?php echo $configObj->currentModulePath?>html/js/jquery.Jcrop.min.js"></script>
<link rel="stylesheet" type="text/css" href="<?php echo $configObj->currentModulePath;?>html/css/jquery.Jcrop.css" />

<script type="text/javascript">

$(function(){
	$('#jcrop_target').Jcrop({
		setSelect: [0,0,<?=$cropwidth;?>,<?=$cropheight;?>],
		allowResize:false,
		minSize:[<?=$cropwidth;?>,<?=$cropheight;?>],
		maxSize:[<?=$cropwidth;?>,<?=$cropheight;?>],
		onSelect: updateCoords,
		onChange: updateCoords
	});

});

function updateCoords(c)
{
	$('#x').val(c.x);
	$('#y').val(c.y);
	$('#w').val(c.w);
	$('#h').val(c.h);
};

function checkCoords()
{
	if (parseInt($('#w').val())) return true;
	alert('Please select a crop region then press submit.');
	return false;
};



function makecrop(val)
{
	
	if(val == "Crop")
	{
		var x = document.getElementById('x').value;
		var y = document.getElementById('y').value;
		var w = document.getElementById('w').value;
		var h = document.getElementById('h').value;
		var filename = document.getElementById('hdfilename').value;
		
		if(x == 0 && y == 0 && w == 0 && h == 0)
		{
			alert("Please select a crop region");
			return;
		}
        else
        {
            alert("Image Cropped Successfully");
			
        }
		
		var params= '&eid=<?php echo $_REQUEST['eid']; ?>&x='+x+'&y='+y+'&w='+w+'&h='+h+'&file='+filename+'&pid=<?php echo $_REQUEST['pid'];?>'+'&cropitem=<?php echo $cropitem;?>';
	//alert("<?=$homebanner->urlwithpara?>&view=<?php echo $_REQUEST['view'];?>&action=realcrop&cropaction=crop&ajax=Y&isgallery=<?php echo $_REQUEST['isgallery'];?>");
    //alert(params);exit;
		$.ajax({
		  type: 'GET',
		  url:  '<?=$homebanner->urlwithpara?>&view=<?php echo $_REQUEST['view'];?>&action=realcrop&cropaction=crop&ajax=Y&isgallery=<?php echo $_REQUEST['isgallery'];?>',

        data:  params,
          async: false,
		  dataType: "html",
		  //start : loader_in_new('<?php echo CURRENT_THEME?>','gridbody'),
		  success: function(str){
                //alert('sss'+str);
			 
				if(str)
				{
					///alert('Image successfully cropped');
                   
					window.location.href =str;
					
					
				}
			  }
		});
	}
}

function chkvalid()
{
	if(document.getElementById('hid_cropimage').value!='')
	{
		document.getElementById('h_save').value ='T';
		document.frmPhoto.submit();
		return true;
	}else
		{
			alert('Please apply Crop before submit');
			document.getElementById('Crop').focus();
			return false;
		}
}

function gotophotolisting(url)
{
	//alert(url);return false;
	location.href = url;
}
</script>

<div class="web-booking-main">
    <div class="clear"></div>
    <div class="add-new-user-title">
      <h2><img src="<?=GLOBAL_ADMIN_IMAGES_PATH?>add-new-listing-icon.png"/>Crop Photo</h2>
    </div>
    <form name="coordfrm" id="coordfrm" method="post" onSubmit="return checkCoords();">
        <input type="hidden" id="x" name="x" />
        <input type="hidden" id="y" name="y" />
        <input type="hidden" id="w" name="w" />
        <input type="hidden" id="h" name="h" />
    </form>
    
    <form  name="frmPhoto" action="<?=$homebanner->urlwithpara?>&view=<?php echo $_REQUEST['view'];?>&action=<?php echo $_REQUEST['action'];?>&eid=<?php echo $_REQUEST['eid'];?>&pid=<?php echo $pid;?>&cropitem=<?php echo $cropitem;?>&isgallery=<?=$_REQUEST['isgallery']?>" method="post"  id="frmPhoto" onsubmit="return chkvalid();" enctype="multipart/form-data">
    
      <div class="add-new-user-subtitle-bg" onClick="javascript:expandcollapsepanel('id_photoupload');" >Photo Cropping Canvas</div>
      <div class="information-white-bg" id="id_photoupload" style="padding-left:5px;">
        <div class="clear"></div>
        <div class="dverrorcustom">
          <?=$messagebox;?>
        </div>
        <input type="hidden" name="hdfilename" id="hdfilename" value="<?=$filename?>" />
        <input type="hidden" name="isgallery" id="isgallery" value="<?=$_REQUEST['isgallery']?>" />
        <table width="100%" border="0" cellspacing="0" cellpadding="2" align="center">
          <tr valign="top" id="crop_form">
            <td width="15%" align="left" valign="middle"><img src="<?=$configObj->currentModulePath."html/uploads/images/".$filename?>" id="jcrop_target" name="jcrop_target"/></td>
          </tr>
          <tr valign="top" id="cropbutton">
            <td width="15%" align="left" valign="middle"><input type="button" class="blue-button" id="Crop" name="Crop" value="Crop" onclick="makecrop('Crop')" />  <input type="button" class="blue-button" id="Cancel" name="Cancel" value="Cancel" 
            onclick="gotophotolisting('<?=$backurl?>')"   />

                 <?php if($cropstatus=='Y'){?>
                <input type="button" class="blue-button" id="useoriginal" name="useoriginal" value="Use Original" onclick="updatecropimagestatus('<?=DB_PREFIX?>banner_mst','chr_cropphoto','N','<?=$_REQUEST['eid']?>');" />
                <?php } ?>
            


            
             </td>
          </tr>
          <tr valign="top" id="croppedimage" style="display:none;">
            <td width="15%" align="left" valign="middle"><img src="" id="cropimage1" /></td>
          </tr>
          <tr valign="top" id="backbutton" style="display:none;">
            <td width="15%" align="left" valign="middle"> 
       <input name="h_save" type="hidden" id="h_save" value="F" />
       <input type="hidden" name="hid_cropimage" id="hid_cropimage" value="<?=$var_cropimage?>" /></td>
          </tr>
        </table>
      </div>  
      <br />
          
<div class="clear"></div>
    
    </form>
  </div>