﻿//*
//* --- Copyright 2010 Public Edge Inc. and Fumia, Fumiaki Takahashi --
//*
//*
WN_HTTP_ARG = function(arg_url, arg_mod)
	{
	this.PG = top.WN.GET_CGI_DIR(arg_url);
	this.ARGS = "";
	this.ID = 1;
	//*
	//*
	this.ADD_S = function(arg_ary)
		{
		var	as_i = 0;
		while(as_i < arg_ary.length)
			{
			if( this.ARGS.length > 0 ) { this.ARGS += "&" }
			this.ARGS += "Q"+ this.ID + "=";
			this.ARGS += encodeURIComponent(arg_ary[as_i++]);
			this.ID++;
			}
		}
	//*
	//*
	this.ADD_W = function(arg_ary)
		{
		var	as_i = 0;
		while(as_i < arg_ary.length)
			{
			if( this.ARGS.length > 0 ) { this.ARGS += "&" }
			this.ARGS += arg_ary[as_i++] + "=";
			this.ARGS += encodeURIComponent(arg_ary[as_i++]);
			}
		}
	}
//*
//*
WN_HTTP_DATA = function(arg)
//*
//*
	{
	var as_data = arg.getElementsByTagName('code').item(0).firstChild.data;
	this.CODE = parseInt(as_data);
	this.DATA = arg;
	this.GET = function(arg)
		{
		try
			{
			as_data =  this.DATA.getElementsByTagName(arg).item(0).firstChild.data;
			}
		catch(e) { as_data = ""; }
		return  as_data;
		}
	this.GETLIST = function(arg)
		{
		as_data = this.GET(arg);
		if( as_data.length > 0 ) return as_data.split("|");
		else return new Array();
		}
	this.SHOW_ERR = function()
		{
		if( this.CODE > 0 )
			{
			alert("ERROR!!:\n"+ top.WN_LANG.GET_MSSG(this.CODE) +
				"\n"+this.GET("mssg")._toInput());
			}
		}
	}
//*
//*
WN_HTTP = function(arg)
//*
//*
	{
	this.AJAX = false;
	this.ARRAY = null;
	this.PG = "";
	if(window.XMLHttpRequest) 
		{
　　　		this.AJAX = new XMLHttpRequest();
		} 
	else if(window.ActiveXObject) 
		{
　		try 
			{
　　			this.AJAX = new ActiveXObject("Msxml2.XMLHTTP");
			} 
		catch(e) { this.AJAX = new ActiveXObject("Microsoft.XMLHTTP"); }
		}
	this.AJAX.FNC = new Object();
	this.AJAX.FNC.REF = arg;
	//*
	//*
	this.EVENT = function()
		{
		if (this.readyState == 4 )
			{
			if( (this.status == 200) &&(this.FNC.REF != null) )
				{
				var	as_f = this.FNC.REF;
				as_f(new WN_HTTP_DATA(this.responseXML));
				}
			else  if( this.status != 200 ) { alert("Connection Error!!"); }
			}
		}	
	//*
	//*
	this.SEND = function(arg_dat)
		{
		//* --- ソケットのオープン
		var	as_mode = ( this.AJAX.FNC.REF != null ) ? true : false;
		this.AJAX.open("POST", arg_dat.PG, as_mode);
		this.AJAX.setRequestHeader("content-type", 
				"application/x-www-form-urlencoded;charset=UTF-8");
		//* --- データの送信
	//*	this.AJAX.onreadystatechange = this.EVENT; *//
		this.AJAX.send(arg_dat.ARGS);
		if( !as_mode ) { return new WN_HTTP_DATA(this.AJAX.responseXML); }
		}
	}
//*
//*
MY_check_input = function(arg_min, arg_max)
//*
//*
	{
	this.MAX = arg_max;
	this.MIN = arg_min;
	this.CHECK = function(arg_val)
		{
		if( this.MIN > 0 ) { arg_val = arg_val.Trim(); }	
		var	as_len = encodeURI(arg_val).length;
		if( as_len.length == 0 ) { return "No data was inputted in the field."; }
		else if( as_len < arg_min ) { return "Too few letters are inputted in the field."; }
		else if( as_len > arg_max ) { return "Too much letters are inputted in the field."; }
		return "";
		}
	}
//*
//*
function __CHECK(arg_imp)
//*
//*
	{
	if( arg_imp.MY_FUNC )
		{
		var	as_mssg = arg_imp.MY_FUNC.CHECK(arg_imp.value);
		if( as_mssg.length > 0 )
			{
			alert(as_mssg);
			arg_imp.style.backgroundColor = "#EE82EE"; 
			return false;
			}
		else { arg_imp.style.backgroundColor = "#98fb98"; }
		}
	return true;
	}
//*
//*
function __FORM_CHECK(arg_frm)
//*
//*
	{
	var	as_elem = arg_frm.elements;
	var	as_i = 0;
	while( as_i < as_elem.length )
		{
		if( __CHECK( as_elem[as_i++]) == false ) return false;
		}
	return true;
	}
