	var autosizewh = true;
	var makecut = false;

	function setautosize(obj)
	{
		if (autosizewh)
		{
			obj.src='../images/ysbl2.gif';
			autosizewh = false;	
		}
		else
		{
			obj.src='../images/ysbl.gif';
			autosizewh = true;		
			$('cWidth').value = parseInt(parseInt($('srcWidth').value) * (parseInt($('cHeight').value) / parseInt($('srcHeight').value)))
	
		}
	}	
	
	function getsize(avale)
	{
		if (autosizewh)
		{
			if (avale==0) 
				$('cHeight').value = parseInt(parseInt($('srcHeight').value) * (parseInt($('cWidth').value) / parseInt($('srcWidth').value)))
			else
				$('cWidth').value = parseInt(parseInt($('srcWidth').value) * (parseInt($('cHeight').value) / parseInt($('srcHeight').value)))
		}
	}
	
	
	function Make(mfile)
	{
		var ashxfile= "../ashx/Make/ImgTool.ashx";
		var err = false;
		if ($('txtInput1')){
			if ($('txtInput1').value.length>30) {alert("抱歉，您输入的文字太多了"); err=true;}
			}

		if (!err)
		{		
			var param_url =  Form.serialize('form1') + "&mtype=" + mfile;
			if ($('divbtn')!=null) Form.disable('divbtn');
			new Ajax.Request(
					ashxfile,
					{
							method: 'post',
							postBody: param_url,
							onComplete: function(response){
								
								if (response.responseText != "-1")
								{
									 Form.enable('divbtn');
									 MakeCallBack('ok',response.responseText);
								}
							}
					}
			);  
		}
	}
	function MakeCallBack(type, mpic)
	{
	  if (type == 'ok')
	  {
		makecut = false;
		if ($('MakeImg')) $('MakeImg').src = mpic;
		if ($('CutDemoImg')) $('CutDemoImg').src = mpic;
		if ($('txtSplit')) $('txtSplit').innerHTML = mpic;
		//$('hdbgImg').value = mpic;
		$('BtnMake').disabled = true;
		$('BtnReset').disabled = false;
		if ($('CutAreaOuter')) $('CutAreaOuter').style.display='none';
		if ($('demoTab')) $('demoTab').style.display='none';
		$('BtnReset').disabled = true;
		wait = 10;
		updateinfo();
	  }
	  else
		alert('抱歉，图片生成失败，请重新操作!');
	}
	
	// Reset the form
	function MakeReset()
	{
		//$('CutDemoImg').src="../images/noPic.gif";
		if ($('CutDemoImg')) $('CutDemoImg').src = $('hdbgImg').value;
		if ($('MakeImg')) $('MakeImg').src = $('hdbgImg').value;
		if ($('CutAreaOuter')) $('CutAreaOuter').style.display = '';
		if ($('demoTab')) $('demoTab').style.display='';
		$('BtnReset').disabled = true;
		$('BtnMake').disabled = false;
	}
		
      function submitArea(form)
      {
        var image = $('CutDemoImg');
        var area = $('CutAreaOuter');
        
        $('xpos').value = getOffset(area, 'offsetLeft') - getOffset(image, 'offsetLeft');
        $('ypos').value = getOffset(area, 'offsetTop') - getOffset(image, 'offsetTop');
        var width = parseInt(area.style.width);
        var height = parseInt(area.style.height);
        if (width > parseInt(image.width)) width = image.width;
        if (height > parseInt(image.height)) height = image.height;
        $('dwidth').value = width;
        $('dheight').value = height;
        return true;
      }