<?php
//选择Logo样式 
if(file_exists('output/choosebanner.png'))
{
	$pic_src = 'output/choosebanner.png';
}

list($banner_width, $banner_height, $type, $attr) = getimagesize($pic_src);


$js = <<<js
<link rel="stylesheet" href="css/colorpicker.css" type="text/css" />
<script type="text/javascript" src="../../script/jquery-ui.custom.min.js"></script>
<script type="text/javascript" src="../../script/colorpicker.js"></script>
<script type="text/javascript" src="../../script/helper.js"></script>
<script type="text/javascript" src="../../script/thickbox.js"></script>
<script type="text/javascript">
var bannertext_left;
var bannertext_top;
$(document).ready(function(){
	$('#banner_text').draggable().hover(
		function(){
			$(this).css('cursor','move');
		},function(){
			$(this).css('cursor','default');
			bannertext_left = $(this).css('left');
			bannertext_top  = $(this).css('top');
		}
	);
	
	$('#banner_text').css({'color':$('#logo_color').val()});
	$('#font_size').val('40');
	$('#font_family').val('simsun');
	
	$.ajax({
	   type: "POST",
	   url: "server.php",
	   data: {id:"useOutput",flag:"yes"},
	   success: function(msg){
			
   	   },
   	   error: function(msg){
   	   	 	
   	   }
	});
	
});

function changeFontFamily(src)
{
	var param;
	param = $('#'+src).val();
	if(param == 'simkai')
	{
		param = 'KaiTi_GB2312';
	}
	if(param == 'simli')
	{
		param = '隶书';
	}
	if(param == 'simfang')
	{
		param = 'FangSong_GB2312';
	}
	$('#banner_text').css('font-family',param);
}

function showColor(src)
{
	$('#'+src).ColorPicker({
		onSubmit: function(hsb, hex, rgb, el) {
			colorValue = '#'+hex;
    		$(el).val(colorValue);
    		$(el).ColorPickerHide();
    		$('#banner_text').css('color',colorValue);
		},
		onBeforeShow: function () {
    		$(this).ColorPickerSetColor(this.value);
    	}
	}).bind('keyup', function(){
    	$(this).ColorPickerSetColor(this.value);
    });
}

function ajaxSend()
{
	$.ajax({
	   type: "POST",
	   url: "server.php",
	   data: {id:"chooseBanner",logo_text:$("#logo_text").val(),logo_color:$("#logo_color").val(),font_family:$("#font_family").attr('value'),font_size:$("#font_size").attr('value'),bannertext_left:bannertext_left,bannertext_top:bannertext_top},
	   beforeSend:function(msg){
	   		$('#pict').remove();
	   		$('#wait').append("<img id='show_img' src='images/loadingAnimation.gif'/>");
		},
	   success: function(msg){
	   		if(msg.substr(0,6) == 'notice')
	   		{
	   			msg = msg.substring(6);
	   			$('#notice').empty();
	   			$('#notice').css('display','block').append(msg);
	   			$("#wait").remove();
	   		}
	   		else
	   		{
				window.location.reload();
			}
   	   },
   	   error: function(msg){
   	   	 	alert(msg);
   	   }
	});
}

function validate(oNum)
{
	if(!oNum)
	{ 
		$('#font_size').attr('value','');
		return false; 
	}
  	var strP=/^\d+(\.\d+)?$/; 
  	if(!strP.test(oNum)) 
  	{
		$('#font_size').attr('value',''); 
		return false; 
	}
  	try
  	{ 
  		if(parseFloat(oNum)!=oNum)
		{
			$('#font_size').attr('value','');
  			return false;
  		}
  	} 
  	catch(ex) 
  	{ 
  	 	$('#font_size').attr('value','');
  		return false;
  	} 
  	return true; 
}
</script>
<link rel="stylesheet" type="text/css" href="../../script/thickbox.css" />
js;

$html = <<<html
<div style="text-align:left;font-size:18px;font-family:'microsoft yahei';color:#006ec6;">挑选您喜欢的Banner</div>
<div class="tabstyle1" id="aaa"></div>
<div class="divsettings">	
	<table cellspacing="10" cellpadding="5" width="100%" border="0">
		<tbody>
			<tr>
				<td valign="top" nowrap><span><input type="button" value="选择Banner" onclick="show_iframe_win('BannerPopup.php?page=1', '', 732, 303);"/></span></td>
				<td>
				</td>
			</tr>
			<tr>
				<td valign="top" nowrap><span>Banner文本:</span></td>
				<td>
					<div class="tdstyle">
                    	<input onblur="$('#banner_text').html($(this).val());" name="logo_text" type="text" value="请输入文字" id="logo_text"  style="width:125px;" maxlength="12"/>
                    </div>
				</td>
			</tr>
			<tr>
				<td valign="top" nowrap><span>文本颜色:</span></td>
				<td>
					<div class="tdstyle">
                    	<input onclick="showColor('logo_color');" onkeyup="$(this).attr('value','');" name="logo_color" type="text" value="#000000" id="logo_color"  style="width:125px;" maxlength="12"/>
                    </div>
				</td>
			</tr>
			<tr>
				<td valign="top" nowrap><span>文字大小:</span></td>
				<td>
					<div class="tdstyle">
                    	<input onblur="$('#banner_text').css('font-size',$(this).val()+'px');" onkeyup="validate($(this).attr('value'));" name="font_size" type="text" value="12" id="font_size"  style="width:125px;" maxlength="12"/>像素
                    </div>
				</td>
			</tr>
			<tr>
				<td valign="top" nowrap><span>文本字体:</span></td>
				<td>
					<div class="tdstyle">
                    	<select name="font_family" id="font_family" style="width:130px;" onchange="changeFontFamily('font_family');">
							<option value="simfang">仿宋</option>
							<option selected="selected" value="simsun">宋体(默认)</option>
							<option value="simkai">楷体</option>
							<option value="simhei">黑体</option>
							<option value="simli">隶书</option>
							<option value="simyou">幼圆</option>
							<option value="msyh">微软雅黑</option>
							<option value="msyhbd">微软雅黑加粗</option>
							<option value="sthupo">华文琥珀</option>
							<option value="stxihei">华文细黑</option>
							<option value="stxinwei">华文新魏</option>
							<option value="stxingka">华文行楷</option>
							<option value="fzstk">方正舒体</option>
							<option value="sursong">方正超大字体</option>
						</select>&nbsp;&nbsp;<div id="notice" style="display:none;margin-top:10px;"></div>
					</div>
				</td>
			</tr>
			<tr>
				<td></td>
				<td class="tdstyle"><input onclick="ajaxSend();" type="button" value="创建我的Banner >>" style="width:244px;" /></td>
			</tr>
		</tbody>
	</table>
</div>

<div id="pict" style="background:url($pic_src) no-repeat;width:{$banner_width}px;height:{$banner_height}px;">
	<div id="banner_text" style="position:relative;top:50px;left:50px;text-align:left;padding:0px;font-size:40px;font-family:SimSun;">请输入文字</div>
</div>
<div style="text-align:left;margin-top:12px;">宽*高{$banner_width}px*{$banner_height}px</div>
<div id="wait"></div>
html;
?>