var ipage = 1;

function changeBg(imgurl)
{
	$('MakeImg').src=imgurl;
	$('hdbgImg').value = imgurl;
}

function changeBg2(imgurl)
{
	$('cmailimg').src=imgurl;
	$('hdbgImg').value = imgurl;
}
function changeBg3(imgurl)
{
	$('hdbgImg').value = imgurl;
	MakeReset();
	$('txtFontColor').value = "#ffffff";
	window.setTimeout("TOI_update();",120);
}

function ckseal(value)
{
	var newurl;
	var txtValue = $('hdbgImg').value;
	if (value==0)
	{
		if ($('MakeImg').src.indexOf("_") !=-1)
			newurl = txtValue.replace("_","");
		else
			newurl = txtValue;
			
		$('MakeImg').src=newurl;
		$('hdbgImg').value=newurl;	
		$('txtFontColor').value = "#ffffff";
	}
	else
	{
		if ($('MakeImg').src.indexOf("_") !=-1)
			newurl = txtValue;
		else
		{
			newurl = txtValue.substring(0,txtValue.lastIndexOf("/")) + "/_" + txtValue.substring(txtValue.lastIndexOf("/") + 1);
		}
		$('MakeImg').src=newurl;
		$('hdbgImg').value=newurl;	
		$('txtFontColor').value = "#ff0000";
	}
	TOI_update();
}

function Make()
{
    var ashxfile= "../ashx/Make/Make.ashx";
	var err = false;
	if ($('txtInput1')){
		if ($('txtInput1').value.length>30) {alert("抱歉，您输入的文字太多了"); err=true;}
		}
	if ($('txtInput2')){
		if ($('txtInput2').value.length>30) {alert("抱歉，您输入的文字太多了"); err=true;}
		}
	if (!err)
	{	
		var param_url =  Form.serialize('form1');
		if ($('divbtn')!=null) Form.disable('divbtn');
		$('loading').style.display='';
		
		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)
{

  // update the image source
  if (type == 'ok')
  {
	$('MakeImg').src = mpic;
	$('loading').style.display='none';
	if ($('demoTab')) $('demoTab').style.display='none';
	if ($("Id").value=="002" || $("Id").value=="006")
		$('BtnReset').disabled = true;
	else
		$('BtnMake').disabled = true;
    $('BtnCopy').disabled = false;
    $('BtnSave').disabled = false;
	$('BtnReset').disabled = true;
	wait = 10;
	updateinfo();
  }
  else
    alert('抱歉，图片生成失败，请重新操作!');

}

// Reset the form
function MakeReset()
{
	$('MakeImg').src=$('hdbgImg').value;
	if ($('demoTab')) $('demoTab').style.display = '';
  	$('BtnCopy').disabled = true;
  	$('BtnSave').disabled = true;

	$('BtnMake').disabled = false;
}


function nextpage()
{
	ipage=ipage+1
	EliteList2($("Id").value,ipage); 
		
}

function prevpage()
{
	ipage=ipage-1	
	EliteList2($("Id").value,ipage); 
		
}
