/*
WAIT_GIF
<div id="indidiv"></div>
RES
<div id="output1"><?php require_once("./echo.php")?></div>
EX_SET
<a><img src="active_star.gif" value= "Ajax_Send" onclick="send4()"></a>
<a><img src="active_star.gif" value= "Ajax_Send" onclick="send5(123,'e')"></a>
<input type="submit" onclick="send5()">
*/
//AJAX_SET
function chkAjaBrowser()
{
	var a,ua=navigator.userAgent;
	this.bw=
	{
		safari:((a=ua.split('AppleWebKit/')[1])?a.split('(')[0]:0)>=124,
		konqueror:((a=ua.split('Konqueror/')[1])?a.split(';')[0]:0)>=3.3,
		mozes:((a=ua.split('Gecko/')[1])?a.split(" ")[0]:0)>=20011128,
		opera:(!!window.opera)&&((typeof XMLHttpRequest)=='function'),
		msie:(!!window.ActiveXObject)?(!!createHttpRequest()):false
	};

	return( this.bw.safari||this.bw.konqueror||this.bw.mozes||this.bw.opera||this.bw.msie )
};

function createHttpRequest()
{
	if( window.XMLHttpRequest )
	{
		return new XMLHttpRequest();
	}
	else
	if( window.ActiveXObject )
	{
		try
		{
			return new ActiveXObject( "Msxml2.XMLHTTP" );
		}
		catch( e )
		{
			try
			{
				return new ActiveXObject( "Microsoft.XMLHTTP" );
			}

			catch( e2 )
			{
				return null;
			}
		}
	}
	else
	{
		return null;
	}
};

function sendRequest( callback,data,method,url,async,sload,user,password )
{
	var oj=createHttpRequest();

	if( oj == null )
	return null;

	var sload=( !!sendRequest.arguments[5] )?sload:false;

	if( sload||method.toUpperCase()=='GET' )url+="?";
	if( sload )url=url+"t="+( new Date() ).getTime();

	var bwoj=new chkAjaBrowser();
	var opera=bwoj.bw.opera;
	var safari=bwoj.bw.safari;
	var konqueror=bwoj.bw.konqueror;
	var mozes=bwoj.bw.mozes;

	if( typeof callback=='object' )
	{
		var callback_onload=callback.onload;
		var callback_onbeforsetheader=callback.onbeforsetheader
	}
	else
	{
		var callback_onload=callback;
		var callback_onbeforsetheader=null;
	};

	if( opera||safari||mozes )
	{
		oj.onload=function()
		{
			callback_onload( oj );
		}
	}
	else
	{
		oj.onreadystatechange=
		function()
		{
			if( oj.readyState==4 )
			{
				callback_onload( oj );
			}
		}
	};

	data=uriEncode( data, url );

	if( method.toUpperCase()=='GET' )
	{
		url+=data
	};

	oj.open( method,url,async,user,password );

	if( !!callback_onbeforsetheader )

	callback_onbeforsetheader( oj );
	setEncHeader( oj );
	oj.send( data );

	function setEncHeader(oj)
	{
		var contentTypeUrlenc='application/x-www-form-urlencoded; charset=UTF-8';

		if( !window.opera )
		{
			oj.setRequestHeader('Content-Type',contentTypeUrlenc);
		}
		else
		{
			if( ( typeof oj.setRequestHeader )=='function' )
			oj.setRequestHeader( 'Content-Type', contentTypeUrlenc );
		};
			return oj
		};

		function uriEncode( data, url )
		{
			var encdata=( url.indexOf( '?' )==-1 )?'?dmy':'';
			if( typeof data=='object' )
			{
				for( var i in data )encdata+='&'+encodeURIComponent( i )+'='+encodeURIComponent( data[i] );
			}
			else
			if( typeof data=='string' )
			{
				if( data=="" )
				return"";

				var encdata='';
				var datas=data.split( '&' );

				for( i=1;i<datas.length;i++ )
				{
					var dataq=datas[i].split( '=' );encdata+='&'+encodeURIComponent( dataq[0] )+'='+encodeURIComponent( dataq[1] );
				}
			};

			return encdata;
		};

	return oj
}

function jsgt_Indicator( src )
{
	this.div=s( src );
	this.indi_append=a;
	this.indi_start=t;
	this.indi_stop=o;
	this.img=new Image();
	this.img.src=src;

	function s( src )
	{
		id="_indicator"+( new Date() ).getTime();
		this.div=document.createElement( "DIV" );

		with( this.div.style )
		{
			position="relative";
			top="0px";
			left="0px";
			width="0px";
			height="0px";
			margin='0px';
			padding='0px';
		};
			return this.div
	};

	function a( id )
	{
		var d=document.getElementById( id );

		if( typeof d!='object' )
		return;

		d.appendChild( this.div );
	};

	function t()
	{
		this.div.style.height="500px";
		this.div.style.width="auto";
		//this.div.innerHTML='<img src="'+this.img.src+'">';
		this.div.innerHTML='';
	};

	function o()
	{
		this.div.style.width="0px";
		this.div.style.height="0px";
		this.div.innerHTML='';
	};

	return this
}
//LOAD_IMAGE_SET
var indi = new jsgt_Indicator( 'http://www.portalgraphics.net/images/common/loading.gif' );

//インジケータを追加するDIVを指定
window.onload =
function()
{
	indi.indi_append( "indidiv" );
}

//AjaxSEND&WAIT_1
function inquiry_bbs( value0, value1, value2, value3 )
{
	indi.indi_start();

	document.getElementById( "output" ).innerHTML="";
	sendRequest( on_loaded,
	{
		key_hash			:value0,
		inquiry_id			:value1,
		inquiry_unique_id	:document.getElementById( "inquiry_name_key" ).value,
		inquiry_bbs_text	:document.getElementById( "inquiry_bbs_value" ).value,
		set_res_id			:document.getElementById( "set_res_id" ).value,
		ip					:document.getElementById( "ip" ).value,
		spam_check			:document.getElementById( "spam_check" ).checked,
		ctrl				:value2
	},
	'POST', 'https://www.portalgraphics.net/inquiry/inquiry_detail_bbs.php', true, true );
}

//AjaxSEND&WAIT_2
function inquiry_bbs_res_del( value0, value1, value2, value3 )
{
	indi.indi_start();
	document.getElementById( "output" ).innerHTML="";
	sendRequest( on_loaded,
	{
		bbs_id     :value0,
		res_exc_id :value1,
		ctrl	   :value3
	},
	'POST', 'https://www.portalgraphics.net/inquiry/inquiry_detail_bbs.php', true, true );
}

//AjaxSEND&WAIT_3
function tag_input( value1, value2, value3, value4 )
{
	if( location.hostname == '115.146.50.91' )
	{
		indi.indi_start();
		document.getElementById( "output" ).innerHTML="";
		sendRequest( on_loaded_inner,
		{
			tag_text   :document.getElementById( "add_tag" ).value,
		    tag_all    :document.getElementById( "tag_all" ).value,
			image_id   :value1,
			user_id    :value2,
			auth_user  :value3,
			action     :value4
		},
		'POST', 'http://115.146.50.91/read_php/tag_structure.php', true, true );
	}
	else
	{
		indi.indi_start();
		document.getElementById( "output" ).innerHTML="";
		sendRequest( on_loaded_inner,
		{
			tag_text   :document.getElementById( "add_tag" ).value,
		    tag_all    :document.getElementById( "tag_all" ).value,
			image_id   :value1,
			user_id    :value2,
			auth_user  :value3,
			action     :value4
		},
		'POST', 'http://www.portalgraphics.net/read_php/tag_structure.php', true, true );
	}
}

//AjaxSEND&WAIT_4
function tag_delete( value1, value2, value3, value4 )
{
	if( location.hostname == '115.146.50.91' )
	{
		indi.indi_start();
		document.getElementById( "output" ).innerHTML="";
		sendRequest( on_loaded_inner,
		{
			del_tag    :document.getElementById( "del_tag" ).value,
		    tag_all    :document.getElementById( "tag_all" ).value,
			image_id   :value1,
			user_id    :value2,
			auth_user  :value3,
			action     :value4
		},
		'POST', 'http://115.146.50.91/read_php/tag_structure.php', true, true );
	}
	else
	{
		indi.indi_start();
		document.getElementById( "output" ).innerHTML="";
		sendRequest( on_loaded_inner,
		{
			del_tag    :document.getElementById( "del_tag" ).value,
		    tag_all    :document.getElementById( "tag_all" ).value,
			image_id   :value1,
			user_id    :value2,
			auth_user  :value3,
			action     :value4
		},
		'POST', 'http://www.portalgraphics.net/read_php/tag_structure.php', true, true );
	}
}

function star_rating_send( value1, value2, value3, value4, value5 )
{
	if( location.hostname == '115.146.50.91' )
	{
		indi.indi_start();
		document.getElementById( "output_star" ).innerHTML="";
		sendRequest( on_loaded_star,
		{
			pt      :value1,
			imgid   :value2,
			c       :value3,
			d       :value4,
			lang	:value5
		},
		'POST', 'http://115.146.50.91/read_php/rating_structure.php', true, true );
	}
	else
	{
		indi.indi_start();
		document.getElementById( "output_star" ).innerHTML="";
		sendRequest( on_loaded_star,
		{
			pt      :value1,
			imgid   :value2,
			c       :value3,
			d       :value4,
			lang	:value5
		},
		'POST', 'http://www.portalgraphics.net/read_php/rating_structure.php', true, true );
	}
}

function search_data_send( value1, value2 )
{
	if( location.hostname == '115.146.50.91' )
	{
		indi.indi_start();
		document.getElementById( "loaded_search_res" ).innerHTML="";
		sendRequest( on_loaded_search_res,
		{
			res_id  :document.getElementById( "res_id" ).value,
			user_id :value1,
			action  :value2
		},
		'POST', 'http://115.146.50.91/read_php/img_search_structure.php', true, true );
	}
	else
	{
		indi.indi_start();
		document.getElementById( "loaded_search_res" ).innerHTML="";
		sendRequest( on_loaded_search_res,
		{
			res_id  :document.getElementById( "res_id" ).value,
			user_id :value1,
			action  :value2
		},
		'POST', 'http://www.portalgraphics.net/read_php/img_search_structure.php', true, true );
	}
}

function search_data_send_add( value1, value2, value3 )
{
	if( location.hostname == '115.146.50.91' )
	{
		indi.indi_start();
		document.getElementById( "loaded_search_res" ).innerHTML="";
		sendRequest( on_loaded_search_res,
		{
			res_id  :document.getElementById( "res_id" ).value,
			user_id :value1,
			action  :value2,
			own_img :value3
		},
		'POST', 'http://115.146.50.91/read_php/img_search_structure_add.php', true, true );
	}
	else
	{
		indi.indi_start();
		document.getElementById( "loaded_search_res" ).innerHTML="";
		sendRequest( on_loaded_search_res,
		{
			res_id  :document.getElementById( "res_id" ).value,
			user_id :value1,
			action  :value2,
			own_img :value3
		},
		'POST', 'http://www.portalgraphics.net/read_php/img_search_structure_add.php', true, true );
	}
}

function ap_beta_messages_send( value1 )
{
	sendRequest( on_loaded_messages,
	{
		res_flag	: value1,
		res_text	: document.getElementById( "res_text" ).value,
		res_sbmt	: document.getElementById( "uComment" ).value
	},
	'POST', 'http://www.portalgraphics.net/beta/index.php', true, true );
}

function sendAlert( value )
{
	if( window.confirm( value ) )
	{
		return true;
	}
	else
	{
		return false;
	}
}

function on_loaded_messages( oj )
{
	//NONE
	true;
}

function on_loaded_inner( oj )
{
	indi.indi_stop();
	//レスポンスを取得
	var res  =  decodeURIComponent(oj.responseText);
	document.getElementById( "output" ).innerHTML=res;
}

function on_loaded( oj )
{
	indi.indi_stop();
	//レスポンスを取得
	var res  =  decodeURIComponent(oj.responseText);
	//var res  =  decodeURIComponent(oj.responseText);
	document.getElementById( "output" ).innerHTML=res;
}

function on_loaded_star( oj )
{
	indi.indi_stop();
	//レスポンスを取得
	var res  =  decodeURIComponent(oj.responseText);
	//var res  =  decodeURIComponent(oj.responseText);
	document.getElementById( "output_star" ).innerHTML=res;
}

function on_loaded_search_res( oj )
{
	indi.indi_stop();
	//レスポンスを取得
	var res  =  decodeURIComponent(oj.responseText);
	//var res  =  decodeURIComponent(oj.responseText);
	document.getElementById( "loaded_search_res" ).innerHTML=res;
}

function s()
{
	alert();
}

