function writePallete(place,n){
	var pallete = document.getElementById(place);
	var source = '<table width="360" height="70" border="0" cellpadding="0" cellspacing="0" bgcolor="#333333" class="color" style="table-layout:fixed"><tbody>';
	var color='';
	var hex = new Array('f','c','9','6','3','0')
	for(j=0;j<6;j++){
		for(k=0;k<6;k++){
			for(l=0;l<6;l++){
				var hexColor = hex[j]+hex[j]+hex[k]+hex[k]+hex[l]+hex[l];
				color+='<td onClick="color'+n+'(\''+hexColor+'\')" bgcolor="#'+hexColor+'" style="font-size: 1px"><div class="pallet1"></div></td>';
			}
		}
		source+='<tr>'+color+'</tr>';
		color='';
	}
	for(i=0;i<6;i++){
		var hexColor = hex[i]+hex[i]+hex[i]+hex[i]+hex[i]+hex[i];
		color+='<td onClick="color'+n+'(\''+hexColor+'\')" bgcolor="#'+hexColor+'" colspan="6" style="font-size: 1px"><div class="pallet1"></div>';
	}
	source+='<tr>'+color+'</tr>';
	source+='</tbody></table>';
	pallete.innerHTML = source;
}
function color1(parts){
	var z = document.getElementById('Tcolor');
	var x = document.getElementById('pallet1');
	z.value = parts;
	x.style.backgroundColor = '#'+parts;
	showHideLayers('Layer1','','hidden');
	Redraw();
}
function color2(parts){
	var z = document.getElementById('BGcolor');
	var x = document.getElementById('pallet2');
	z.value = parts;
	x.style.backgroundColor = '#'+parts;
	showHideLayers('Layer2','','hidden');
	Redraw();
}
function color3(parts){
	var z = document.getElementById('Lcolor');
	var x = document.getElementById('pallet3');
	z.value = parts;
	x.style.backgroundColor = '#'+parts;
	showHideLayers('Layer3','','hidden');
	Redraw();
}
function findObj(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function showHideLayers() {
  var i,p,v,obj,args=showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
function showPallete(parts){
	obj=findObj(parts);
	if(obj.style.visibility=='hidden'){
		showHideLayers(parts,'','show')
	}else{
		showHideLayers(parts,'','hidden')
	}
}
function FCookie(){
	var f = document.getElementById('config_flash');
	var lo = document.getElementById('layout').value;
	if(getCookie('ASID')!=''){f.asid.value=getCookie('ASID');}
	if(getCookie('N')!=''){f.n[getCookie('N')].checked=true;}
	if(getCookie('BGTYPE')!=''){f.BGtype[getCookie('BGTYPE')].checked=true;}
	if(getCookie('BG')!=''){f.bg.value=getCookie('BG');}
	if(lo=='yoko'){
		if(getCookie('SIZE')!=''){f.size[getCookie('SIZE')].checked=true;}
		if(getCookie('WIDTH')!=''){f.width.value=getCookie('WIDTH');}
		if(getCookie('HEIGHT')!=''){f.height.value=getCookie('HEIGHT');}
		if(getCookie('PL')!=''){f.pl.value=getCookie('PL');}
	}else if(lo=='tate'){
		if(getCookie('SIZET')!=''){f.size[getCookie('SIZET')].checked=true;}
		if(getCookie('WIDTHT')!=''){f.width.value=getCookie('WIDTHT');}
		if(getCookie('HEIGHTT')!=''){f.height.value=getCookie('HEIGHTT');}
		if(getCookie('PLT')!=''){f.pl.value=getCookie('PLT');}
	}
	if(getCookie('TCOLOR')!=''){f.Tcolor.value=getCookie('TCOLOR');}
	if(getCookie('BGCOLOR')!=''){f.BGcolor.value=getCookie('BGCOLOR');}
	if(getCookie('LCOLOR')!=''){f.Lcolor.value=getCookie('LCOLOR');}
	if(getCookie('REF')!=''){f.ref.value=getCookie('REF');}
	if(getCookie('TAR')!=''){f.tar.value=getCookie('TAR');}
	if(getCookie('TIME')!=''){f.time.value=getCookie('TIME');}
}
function Redraw(parts){
	var lo = document.getElementById('layout').value;
	var c1 = document.getElementById('pallet1');
	var c2 = document.getElementById('pallet2');
	var c3 = document.getElementById('pallet3');
	var Tc = document.getElementById('Tcolor');
	var BGc = document.getElementById('BGcolor');
	var Lc = document.getElementById('Lcolor');
	var z = document.getElementById('insert_area');
	var f = document.getElementById('config_flash');
	var html = document.getElementById('html');

	c1.style.backgroundColor = '#'+Tc.value;
	c2.style.backgroundColor = '#'+BGc.value;
	c3.style.backgroundColor = '#'+Lc.value;

	var prm = prmSet('swf');
	prm = prm.replace('&','%26');

	var asid = f.asid.value;
	setCookie('ASID', asid);

	if(f.ref.checked){
		var ref = '1';
	}else{
		var ref = '0';
	}

	/*
	if(f.tar.checked){
		var tar = '1';
	}else{
		var tar = '0';
	}
	*/

	var tar = '0';


	if(parts=='h'){
		w = f.height.value * 1.5625;
		f.width.value = w;
		h = f.height.value;
	}else if(parts=='w'){
		h = f.width.value * 0.64;
		f.height.value = h;
		w = f.width.value;
	}else if(parts=='ht'){
		w = f.height.value * 0.64;
		f.width.value = w;
		h = f.height.value;
	}else if(parts=='wt'){
		h = f.width.value * 1.5625;
		f.height.value = h;
		w = f.width.value;
	}else{
		h = f.height.value;
		w = f.width.value;
	}

	for(i =0; i< f.n.length;i++){
		if(f.n[i].checked){var cnt=i;}
	}

	if(lo=='yoko'){
		w = w * parseInt(f.n[cnt].value);
	}else if(lo=='tate'){
		h = h * parseInt(f.n[cnt].value);
	}

	if(f.n[cnt].value=='1'){
		var n = '';
		var n2 = '""';
	}else{
		var n = f.n[cnt].value;
		var n2 = f.n[cnt].value;
	}

	setCookie('N', cnt);

	for(i =0; i< f.BGtype.length;i++){
		if(f.BGtype[i].checked){var cnt=i;}
	}
	if(cnt=='0'){
		f.bg.value = '';
	}else{
		f.bg.value = 'http://amazie.jp/bg/'+f.BGtype[cnt].value+n+'.swf';
	}

	setCookie('BGTYPE', cnt);
	setCookie('BG', f.bg.value);


	for(i =0; i< f.size.length;i++){
		if(f.size[i].checked){var cnt=i;}
	}
	
	if(lo=='yoko'){
		setCookie('SIZE', cnt);
		setCookie('WIDTH', f.width.value);
		setCookie('HEIGHT', f.height.value);
		setCookie('PL', f.pl.value);
	}else if(lo=='tate'){
		setCookie('SIZET', cnt);
		setCookie('WIDTHT', f.width.value);
		setCookie('HEIGHTT', f.height.value);
		setCookie('PLT', f.pl.value);
	}
	setCookie('TCOLOR', f.Tcolor.value);
	setCookie('BGCOLOR', f.BGcolor.value);
	setCookie('LCOLOR', f.Lcolor.value);
	setCookie('REF', f.ref.value);
	setCookie('TAR', 0);
	setCookie('TIME', f.time.value);

	var amazie_ad_prm = prm;
	var amazie_ad_asid = asid;
	var amazie_ad_width = w;
	var amazie_ad_height = h;
	var amazie_ad_type = lo;
	var amazie_ad_n = n;
	var amazie_ad_n2 = n2;
	var amazie_ad_tar = tar;
	var amazie_ad_ref = ref;
	var amazie_ad_pl = f.pl.value;
	var amazie_ad_time = f.time.value;
	var amazie_color_text = Tc.value;
	var amazie_color_bg = BGc.value;
	var amazie_color_line = Lc.value;
	var amazie_ad_bg = f.bg.value;

	var x = '<div class="amazie_ad"><script type="text/javascript"><!--\n';
	x += 'amazie_ad_prm = "'+amazie_ad_prm+'";\n';
	x += 'amazie_ad_asid = "'+amazie_ad_asid+'";\n';
	x += 'amazie_ad_width = '+amazie_ad_width+';\n';
	x += 'amazie_ad_height = '+amazie_ad_height+';\n';
	x += 'amazie_ad_type = "'+amazie_ad_type+'";\n';
	x += 'amazie_ad_n = '+amazie_ad_n2+';\n';
	x += 'amazie_ad_tar = '+amazie_ad_tar+';\n';
	x += 'amazie_ad_ref = '+amazie_ad_ref+';\n';
	x += 'amazie_ad_pl = '+amazie_ad_pl+';\n';
	x += 'amazie_ad_time = '+amazie_ad_time+';\n';
	x += 'amazie_color_text = "'+amazie_color_text+'";\n';
	if(amazie_ad_bg==''){
		x += 'amazie_color_bg = "'+amazie_color_bg+'";\n';
		x += 'amazie_color_line = "'+amazie_color_line+'";\n';
		x += 'amazie_ad_bg = "";\n';
		var bkg = '&Bc='+amazie_color_bg+'&Lc='+amazie_color_line;
	}else{
		x += 'amazie_color_bg = "";\n';
		x += 'amazie_color_line = "";\n';
		x += 'amazie_ad_bg = "'+amazie_ad_bg+'";\n';
		var bkg = '&bg='+amazie_ad_bg;
	}
	x += '//--></script><script type="text/javascript" src="http://amazie.jp/js/show_amz2.js"></script></div>';

	//Flash
	var amz_swf = 'http://amazie.jp/swf/'+amazie_ad_type+amazie_ad_n+'.swf?prm='+amazie_ad_prm+'&id='+amazie_ad_asid+'&ref='+amazie_ad_ref+'&tar='+amazie_ad_tar+'&pl='+amazie_ad_pl+'&time='+amazie_ad_time+'&Tc='+amazie_color_text+bkg;

	var amz_dat = '<div class="amazie_ad"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+amazie_ad_width+'" height="'+amazie_ad_height+'"><param name="movie" value="'+amz_swf+'" /><param name="quality" value="high" /><param name="allowScriptAccess" value="always" /><embed src="'+amz_swf+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+amazie_ad_width+'" height="'+amazie_ad_height+'" allowScriptAccess="always"></embed></object></div>';

	z.innerHTML = amz_dat;
	
	if(parts=='swf'){
		html.value = amz_dat;
	}else{
		//HTMLコードの生成
		html.value = x.replace(/\n/g,'//\n');
	}
	//html.focus();
	html.select();

}
function Sub(){
	if(document.all){
		showHideLayers('Layer1','','show');
		showHideLayers('Layer1','','hidden');
		showHideLayers('Layer2','','show');
		showHideLayers('Layer2','','hidden');
		showHideLayers('Layer3','','show');
		showHideLayers('Layer3','','hidden');
	}
	var f = document.getElementById('config_flash');
}
function showAdvance(){
	var f = document.getElementById('config_flash');
	if(f.adv.value=='show advance'){
		f.adv.value='hide advance';
		var stylename = 'hideAdvance';
		var stylename2 = 'showAdvance';
	}else{
		f.adv.value='show advance';
		var stylename = 'showAdvance';
		var stylename2 = 'hideAdvance';
	}
	for (var i=0,d=document; i<d.getElementsByTagName("span").length; i++) {
		if(d.getElementsByTagName('span')[i].className==stylename){
			d.getElementsByTagName('span')[i].className=stylename2;
		}
	}
}