// inline-enquete
document.write('<link rel="stylesheet" href="/common/css/form.css" type="text/css" media="all" />');
var inlenq;

function inlenq_init()
{
	var ajax=new AjaxObj;
	if(!ajax.IsReady()) return;

	inlenq=new function()
	{
		this.win=null;
		this.cache=null;

		this.click=function(id)
		{
			this.unloadwin();
			var btn1=document.getElementById(id+'_btn1');
//			var btn2=document.getElementById(id+'_btn2');
			var div=document.getElementById(id+'_div');
			var s=div.style;
			if(s.display=='none') {
				var frm=document.forms[id];
				if(frm.ex.value=='') {
					if(!inlenq.reset(id)) return;
				}
				btn1.style.display='none';
//				btn2.style.display='block';
				s.display='block';
			}
			else {
				btn1.style.display='block';
//				btn2.style.display='none';
				s.display='none';
			}
		};

		this.reset=function(id)
		{
			var frm=document.forms[id];
			frm.method='post';
			frm.action='https://'+location.hostname+'/lib/inlenq/form2.php';
			frm.target='inlenqwindow';
			frm._url.value=document.location.href.replace(/#.*$/,'');
			frm._title.value=document.title;
			frm.ex.value='reset';
			var res=ajax.PostSync('/lib/inlenq/form2.php',frm);
			if(res) {
				frm.onsubmit=function(){return inlenq.submit(id);};
				document.getElementById(id+'_div').innerHTML=res;
				frm.ex.value='ready';
				if(this.cache==null) (this.cache=new Image()).src=document.getElementById(id+'_submit').src.replace(/.gif$/,'_off.gif');
				return true;
			}
			frm.ex.value='';
			return false;
		};

		this.submit=function(id)
		{
			var frm=document.forms[id];
			if(frm.ex.value!='ready') {
				alert('送信済みです。');
				return false;
			}
			document.getElementById(id+'_submit').src=this.cache.src;
			frm.ex.value='submit';
			this.unloadwin();
			var w=open('about:blank','inlenqwindow','width=600,height=320,menubar=no,toolbar=no,location=yes,status=yes');
			this.win=w;
			setTimeout(function(){inlenq.closeform(id);},500);
			return true;
		};

		this.closeform=function(id) {
			var btn1=document.getElementById(id+'_btn1');
			var btn2=document.getElementById(id+'_btn2');
			var div=document.getElementById(id+'_div');
			var frm=document.forms[id];
			frm.ex.value='closed';
			btn1.style.display='block';
			btn2.style.display='none';
			div.style.display='none';
		};

		this.close=function(id,pg)
		{
			inlenq.closeform(id);
			inlenq.unloadwin();
			if(pg) location.href=pg;
		};

		this.unloadwin=function()
		{
			if(this.win==null) return;
			if(!this.win.closed) this.win.close();
			this.win=null;
		};
	};

	(function()
	{
		var oh=window.onunload;
		window.onunload=function()
		{
			if(typeof(oh)!='undefined'&&oh!==null) oh();
			inlenq.unloadwin();
		};
	})();

	(function()
	{
		var i,n=document.forms.length;
		for(i=0;i<n;i++) {
			var f=document.forms[i];
			var m=f.innerHTML.match(/\s*<!\-\-\s*ENQ:(.+?)\s*\-\->/);
			if(!m) continue;
			var res=ajax.PostSync('/lib/inlenq/init2.php','_param='+encodeURIComponent(f.id+':'+m[1]));
			if(res) f.innerHTML=res;
		}
	})();
}


(function()
{
	var oh=window.onload;
	window.onload=function()
	{
		if(typeof(oh)!='undefined'&&oh!==null) oh();
		inlenq_init();
	};
})();


