// default setting
var s_webkitSetting={
	 AcceptLanguage:""
	,UserAgent:""
	,StandardFontFamily:""
	,FixedFontFamily:""
	,SerifFontFamily:""
	,SansSerifFontFamily:""
	,CursiveFontFamily:""
	,FantasyFontFamily:""
	,DefaultFontSize:0
	,DefaultFixedFontSize:0
	,Sockets:true
	,Notifications:false
	,Geolocation:false
	,FileSystem:true
	,TextAreasAreResizable:true
	,AllowScriptsToCloseWindows:true
	,RemoteFontsEnabled:true
	,JavascriptCanAccessClipboard:true
	,SmoothScroll:false
	,enablePpapiFlash:false
	,enableWebFont:true
	,webFont:true
	,dnsPrefetching:true
	,directWrite:true
	,navigateOnDragDrop:true
	,mockScrollbar:false
},s_fonts;
function getWebKitSettingPath(){
	var	fso=getFSO();
	return fso.BuildPath(getSettingDirPath(),"WebKit.json");
}
var STR_DEFAULT_FONT_VALUE="<規定のフォント>";
var STR_DEFAULT_FONT_SIZE_VALUE="<規定のサイズ>";
function fillSelectFontName(select){
	var	options=select.options;
	if(!s_fonts){
		s_fonts=parseJson(external.enumFont);
	}
	options.length=0;
	if(s_fonts){
		addOption(options,"",STR_DEFAULT_FONT_VALUE);
		for(idx in s_fonts){
			var	name=s_fonts[idx];
			var	item=addOption(options,name,name);
			//item.style.fontFamily=name;
		}
	}
}
function doFillFontSelect(){
	var	elem=window.event.srcElement;
	if(!elem.afilled){
		elem.afilled=true;
		var	v=getSelectedValue(elem.options);
		fillSelectFontName(elem);
		if(!v){
			v="";
		}
		selectOption(elem.options,v);
	}
}
var	s_fontsizes=[6,7,8,9,10,11,12,13,14,15,16,17,18,20,22,24,26,28,30,32,34,36,40,44,48,56,64,72];
function fillFontSizeSelect(select){
	var	options=select.options;
	var	v=getSelectedValue(options);
	options.length=0;
	addOption(options,0,STR_DEFAULT_FONT_SIZE_VALUE);
	for(idx in s_fontsizes){
		addOption(options,s_fontsizes[idx],s_fontsizes[idx]);
	}
	if(!v){
		v=0;
	}
	selectOption(options,v);
}
function fontSelectChange(){
 elem=window.event.srcElement;
 var v=getSelectedValue(elem.options);
 var type=elem.form.name;
 external.fontPreview(type,v);
 external.reloadBlinkSetting();
}
function attachFillFontSelectEvent(elem){
	elem.onmousedown=doFillFontSelect;
	elem.onfocus=doFillFontSelect;
	elem.onchange=fontSelectChange;
}
function loadWebKitSetting(){
	var	obj=parseJsonFile(getWebKitSettingPath());
	if(!obj){
		obj=s_webkitSetting;
	}else{
		for(val in s_webkitSetting){
			if(undefined===obj[val])	obj[val]=s_webkitSetting[val];
		}
	}
	for(s in obj){
		var	f=document[s];
		if(f){
			if("select"===f.v.tagName.toLowerCase()){
				var	val=obj[s],name;
				if("string"===typeof val){
					if(val.length){
						name=val;
					}else{
						name=STR_DEFAULT_FONT_VALUE;
					}
					
				}else{
					if(!val){
						name=STR_DEFAULT_FONT_SIZE_VALUE;
					}
				}
				addOption(f.v.options,val,name).selected=true;
				//f.v.options.selectedIndex=0;
			}else if("checkbox"===f.v.type){
				f.v.checked=obj[s];
			}else if("text"===f.v.type){
				f.v.value=obj[s];
			}
		}
	}
	attachFillFontSelectEvent(document["StandardFontFamily"].v);
	attachFillFontSelectEvent(document["FixedFontFamily"].v);
	attachFillFontSelectEvent(document["SerifFontFamily"].v);
	attachFillFontSelectEvent(document["SansSerifFontFamily"].v);
	attachFillFontSelectEvent(document["CursiveFontFamily"].v);
	attachFillFontSelectEvent(document["FantasyFontFamily"].v);
	fillFontSizeSelect(document["DefaultFontSize"].v);
	fillFontSizeSelect(document["DefaultFixedFontSize"].v);
}
function saveWebKitSetting(){
	var	setting=s_webkitSetting;
	for(s in setting){
		var	f=document[s];
		if(f){
			if("select"===f.v.tagName.toLowerCase()){
				setting[s]=getSelectedValue(f.v.options);
			}else if("checkbox"===f.v.type){
				setting[s]=f.v.checked;
			}else if("text"===f.v.type){
				setting[s]=f.v.value;
			}
		}
	}
	var	json=JSON.stringify(setting,undefined," ");
	writeUnicodeTextFile(getWebKitSettingPath(),json);
}
