// 都道府県PV合戦 プレビュー用js

var site_id = 0;

function getMovieName(movieName) {
  return document[movieName];
}

function setFaceToFlash(){
	
	var face = '';

	for(i = 0; i < document.getElementsByName("face").length; i ++){
		if(document.getElementsByName("face")[i].checked){
			face = document.getElementsByName("face")[i].value;
		}
	}
	
	return face;
}

function setPrefToFlash(){
	var pref_id = document.form1.pref_id.selectedIndex;
	return pref_id;
}

function previewPb(){
	if(document.form1.pref_id.selectedIndex == 0){
		alert('都道府県を選択してください');
	}else{
		getMovieName("externalpref_battle").callInitFlash();
	}
}

function registSiteId(){
	var f = document.form1;
	
	if(!f.site_url.value){
		alert('設置先サイトのURLを入力してください');
		return 0;
	}
	if(!f.site_name.value){
		alert('設置先サイト名を入力してください');
		return 0;
	}
	
	var site_url = encodeURI(f.site_url.value);
	var site_name = encodeURI(f.site_name.value);
	
	var pref_id = setPrefToFlash();
	var item_id = pref_id + 6;
	
	var face = setFaceToFlash();
	
    new Ajax.Request("http://labs.infoalive.com/product/appeal/xml/site?name="+site_name+"&category_id=1&item_id="+item_id+"&url="+site_url+"&options="+face, { method: 'get', onComplete: setTags });
    

}

function setTags(httpObj){
	var f = document.form1;
	
	var pref_id = setPrefToFlash();
	var face = setFaceToFlash();
	
	// サイトIDチェック
	var siteIdObj = httpObj.responseXML;
	
	var site_id = siteIdObj.getElementsByTagName('id')[0].firstChild.nodeValue;
	
	if(site_id == 0){
		alert('タグの生成処理に失敗しました');
		return 0;
	}
	
	var tags_text = '';
	tags_text = '<script src="http://labs.infoalive.com/product/pref_battle/pref_battle_inc.js" language="javascript"></script>';
	tags_text += '<script language="javascript">';
	tags_text += 'var pref_id="'+ pref_id +'";';
	tags_text += 'var face="'+ face +'";';
	tags_text += 'var site_id="'+site_id+'";';
	tags_text += 'setPbFlash();</script>';
	
	f.tags.value = tags_text;
}

function setPbFlash(){
	
	var width=160;
	var height=200;
	
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0"  width="'+width+'" height="'+height+'" id="externalpref_battle" align="middle" wmode="transparent">');
	document.write('<param name="wmode" value="transparent">');
	document.write('<param name="allowScriptAccess" value="always" />');
	document.write('<param name="allowFullScreen" value="false" />');
	document.write('<param name="movie" value="pref_battle.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" />');
	document.write('<embed src="pref_battle.swf" quality="high" bgcolor="#ffffff" width="'+width+'" height="'+height+'" name="externalpref_battle" align="middle" allowScriptAccess="always" allowFullScreen="false" wmode="transparent" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
}

function setPbMapFlash(){
	
	var width=700;
	var height=700;
	
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0"  width="'+width+'" height="'+height+'" id="externalpref_map" align="middle" wmode="transparent">');
	document.write('<param name="wmode" value="transparent">');
	document.write('<param name="allowScriptAccess" value="always" />');
	document.write('<param name="allowFullScreen" value="false" />');
	document.write('<param name="movie" value="pref_map.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" />');
	document.write('<embed src="pref_map.swf" quality="high" bgcolor="#ffffff" width="'+width+'" height="'+height+'" name="externalpref_map" align="middle" allowScriptAccess="always" allowFullScreen="false" wmode="transparent" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
}

function openRegistBlog(){
	myLightWindow.activateWindow({
	href: 'list.html',
	title: '最近登録されたサイト',
	type: 'page',
	width: 700,
	height:500 });
}

function openBlogPv(){
	myLightWindow.activateWindow({
	href: 'pv.html',
	title: 'ページビューランキング',
	type: 'page',
	width: 700,
	height:500 });
}
