var ipage = 1;
var oldfrm;
var currentab = 0;
function changeBg(imgurl)
{
	$('MakeImg').src=imgurl;
	$('hdbgImg').value = imgurl;

}
function SelectQTextbg(imgurl,ioi)
{
	if (ioi==7)
	{
		$("MakeImg").src = imgurl;

	}
	else
		$('demoText' + ioi).innerHTML="<img src='" + imgurl + "' border=0>";
	$('hdtab' + ioi).value=imgurl;
	closebg();
}
function SelectQTextx(imgurl,ioi)
{
	$('demoText' + ioi).style.background="url("+imgurl+") no-repeat";
	$('hdtab' + ioi).value=imgurl;
	closebg();
}
function SelectQTextmb(imgurl)
{
	$('tab6img').src=imgurl;
	$('hdtab6').value=imgurl;
	closebg();
}
function showtxtfrm()
{
	$('txtfrm').style.display= $('txtfrm').style.display==''?'none':'';
	$('demoText1').innerText = $('txtInput1').value;
	$('demoTab1').style.display = ''
	$('hdtab1').value = $('txtInput1').value;
	
	$('addtab6').disabled = false;
	$('uploadtab6').disabled = false;
	$('deltab6').disabled = false;
}
function MakeImgSzie()
{
	if ($('cWidth').value>640 || $('cWidth').value>480)
	{
		$('MakeImg').style.width = "640px";
		$('MakeImg').style.height = "480px";	
		$('cWidth').value = "640";
		$('cHeight').value = "480";
	}
	else
	{
		$('MakeImg').style.width = $('cWidth').value + "px";
		$('MakeImg').style.height = $('cHeight').value + "px";
	}
}

function upfileIOI(itab)
{
	$('tdupload').style.display =  $('tdupload').style.display==''?'none':'';
	currentab = itab;
}

function showbgfrom(obj,mdir,itab)
{

	if ($('demoTab' + itab)) $('demoTab' + itab).style.display = '';

	 var msgstyle;
	 msgstyle=document.createElement("div");
		
	 var s =msgstyle.style;
		with(s)
		{			
		try{
			width=document.body.scrollWidth;
			height=document.body.clientHeight+document.body.scrollTop;
			}
		catch(e)
			{}
		}	 
	msgstyle.className="disabled";
	msgstyle.id="coverPage";
	try{document.body.appendChild(msgstyle);}
	catch(e){}
			
	var ix = getoffset(obj, 'offsetLeft');
	var iy = getoffset(obj, 'offsetTop');;
	$('BgForm').style.left =  (ix - 400) + 'px';
	$('BgForm').style.top =  (iy-310) + 'px';
	$('BgForm').style.display='';
	$('frmcolor').style.pixelLeft=$('BgForm').style.pixelLeft;
	$('frmcolor').style.pixelTop=$('BgForm').style.pixelTop;
	$('frmcolor').style.width = $('BgForm').style.width;
	$('frmcolor').style.height = '300px';
	$('frmcolor').style.display=$('BgForm').style.display;
	
	if (oldfrm!=itab) 
	{
		getBgList(1,mdir,itab);
		oldfrm = itab;
	}

}

function showmbfrm(obj,itab)
{

	 var msgstyle;
	 msgstyle=document.createElement("div");
		
	 var s =msgstyle.style;
		with(s)
		{			
		try{
			width=document.body.scrollWidth;
			height=document.body.clientHeight+document.body.scrollTop;
			}
		catch(e)
			{}
		}	 
	msgstyle.className="disabled";
	msgstyle.id="coverPage";
	try{document.body.appendChild(msgstyle);}
	catch(e){}
			
	var ix = getoffset(obj, 'offsetLeft');
	var iy = getoffset(obj, 'offsetTop');;
	$('BgForm').style.left =  (ix - 400) + 'px';
	$('BgForm').style.top =  (iy-310) + 'px';
	$('BgForm').style.display='';
	$('frmcolor').style.pixelLeft=$('BgForm').style.pixelLeft;
	$('frmcolor').style.pixelTop=$('BgForm').style.pixelTop;
	$('frmcolor').style.width = $('BgForm').style.width;
	$('frmcolor').style.height = '300px';
	$('frmcolor').style.display=$('BgForm').style.display;
	oldfrm = itab;
	getMbList(1);
}

function getBgList(currentPage,mDir,iTab)
{
	var ashxfile= "../ashx/QText/BgList.ashx";
    var param_url = "iPage=" + currentPage + "&mDir=" + mDir + "&IOI=" + iTab;
	$('viewFormContent').innerHTML="&nbsp;<img src='../images/spinner_gray.gif' align='absmiddle' /> 载入中...";
   	new Ajax.Request(
			ashxfile,
			{
				method: 'post',
				postBody: param_url,
				onComplete: function(response){
					if (response.responseText != "-1")
					{
						$("viewFormContent").innerHTML = response.responseText;
					}
				}
			}
        );  	
}

function getMbList(currentPage)
{
	var ashxfile= "../ashx/QText/MbList.ashx";
    var param_url = "iPage=" + currentPage;
	$('viewFormContent').innerHTML="&nbsp;<img src='../images/spinner_gray.gif' align='absmiddle' /> 载入中...";
   	new Ajax.Request(
			ashxfile,
			{
				method: 'post',
				postBody: param_url,
				onComplete: function(response){
					if (response.responseText != "-1")
					{
						$("viewFormContent").innerHTML = response.responseText;
					}
				}
			}
        );  	
}

function delTOI(iTab)
{
	if (iTab == 7)
	{
		$("MakeImg").src = "../Material/QText/bg.gif";
		$('hdtab' + iTab).value='';
		$('cWidth').value = "400";
		$('cHeight').value = "150";
	}
	else if (iTab == 6)
	{
		$('hdtab' + iTab).value='';
		$('tab6img').src = '../Material/QText/bg.gif';
	}	
	else if (iTab == 1)
	{
		$('hdtab' + iTab).value='';
		$('tab6img').src = '../Material/QText/bg.gif';
		$('demoText' + iTab).innerHTML='';
		$('demoTab' + iTab).style.display = 'none'
		$('txtfrm').style.display = 'none';
		$('hdtab' + iTab).value='';		
		$('addtab6').disabled = true;
		$('deltab6').disabled = true;
		$('uploadtab6').disabled = true;		
	}	
	else
	{
		$('demoText' + iTab).innerHTML='';
		$('demoTab' + iTab).style.display = 'none'
		$('hdtab' + iTab).value='';
	}
}

function closebg()
{
	$('BgForm').style.display='none';
	$('frmcolor').style.display='none';
	$("coverPage").removeNode(true);
}

function Make(mfile)
{
    /* px,py 偏移量,fshow要显示的帧用|隔开*/
    var ashxfile
		ashxfile= "../ashx/QText/" + mfile + ".ashx";
	var err = false;
	if ($('txtInput1')){
		if ($('txtInput1').value.length>80) {alert("抱歉，您输入的文字太多了"); err=true;}
		}

	if (!err)
	{		
		var param_url =  Form.serialize('form1');
		if ($('divbtn')) Form.disable('divbtn');
		//$('loading').style.display='';
		$('BtnMake').value = '请稍候...';
		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;
	$('BtnMake').value = '生成闪字';
	$('BtnMake').disabled = true;
    $('BtnCopy').disabled = false;
    $('BtnSave').disabled = false;
	$('BtnUndo').disabled = true;
	for (var i=1; i<8; i++)
	{
		if ($('addtab' + i)) $('addtab' + i).disabled = true;
		if ($('deltab' + i)) $('deltab' + i).disabled = true;
		if ($('uploadtab' + i)) $('uploadtab' + i).disabled = true;
		if ($('demoTab' + i)) $('demoTab' + i).style.display = 'none'
	}
	$('BtnReset').disabled = true;
	wait = 10;
	wait2 = 5;
	updateinfo();
	updateinfo2();
  }
  else
    alert('抱歉，图片生成失败，请重新操作!');

}

// Reset the form
function MakeReset()
{
  	$('BtnCopy').disabled = true;
  	$('BtnSave').disabled = true;
	$('BtnMake').disabled = false;
	$('MakeImg').src="../Material/QText/bg.gif";
	for (var i=1; i<8; i++)
	{
		if ($('addtab' + i)) $('addtab' + i).disabled = false;
		if ($('deltab' + i)) $('deltab' + i).disabled = false;
		if ($('uploadtab' + i)) $('uploadtab' + i).disabled = false;
		if ($('demoText' + i)) $('demoText' + i).innerHTML='';
		$('hdtab' + i).value = '';
	}	
	if ($('addtab6')) $('addtab6').disabled = true;
	if ($('deltab6')) $('deltab6').disabled = true;
	if ($('uploadtab6')) $('uploadtab6').disabled = true;	
}


function MakeUndo()
{
  	$('BtnCopy').disabled = true;
  	$('BtnSave').disabled = true;
	$('BtnMake').disabled = false;
	$('BtnUndo').disabled = true;
	
	for (var i=1; i<8; i++)
	{
		if ($('addtab' + i)) $('addtab' + i).disabled = false;
		if ($('deltab' + i)) $('deltab' + i).disabled = false;
		if ($('uploadtab' + i)) $('uploadtab' + i).disabled = false;
		if ($('hdtab' + i).value !='') 
		{
			if ($('demoTab' + i)) $('demoTab' + i).style.display = ''
		}
	}	
	if ($('hdtab7').value !='')
		$('MakeImg').src=$('hdtab7').value;
	else
		$('MakeImg').src="../Material/QText/bg.gif";

}

function SetAValue(value,obj)
{
	$('AValue').value = value;	
	
	
	var tagElements = $('alist').getElementsByTagName("img");
      for (var j = 0; j < tagElements.length; j++)
        tagElements[j].style.borderColor="#FFF";

	obj.style.borderColor="#F00";
	


}

function MakeQFlash()
{
    /* px,py 偏移量,fshow要显示的帧用|隔开*/
    var ashxfile
		ashxfile= "../ashx/QText/QFlash.ashx";

    var param_url =  Form.serialize('form1');
    if ($('divbtn')) Form.disable('divbtn');
    //$('loading').style.display='';
	$('BtnMake').value = '请稍候...';
   	new Ajax.Request(
                ashxfile,
                {
                        method: 'post',
                        postBody: param_url,
                        onComplete: function(response){
                            
                            if (response.responseText != "-1")
                            {
                                 Form.enable('divbtn');
								 $('MakeImg').src = response.responseText;
								 $('BtnMake').value = '生成闪图';
								 $('BtnCopy').disabled = false;
    							 $('BtnSave').disabled = false;
								//MakeCallBack('ok',response.responseText);
                            }
                        }
                }
        );     
}


function nextpage()
{
	ipage=ipage+1
	EliteList2($("Id").value,ipage); 
		
}

function prevpage()
{
	ipage=ipage-1	
	EliteList2($("Id").value,ipage); 
		
}
