/**
 * @Name    selectCity 
 * @Desc    指定都道府県市区町村一覧取得
 * @Author  T.Tanaka
 * @Date    2007/08/29
 **/
function selectCity( value )
{
	if( !value.match(/^[1-9]$|^[1-3][0-9]$|^[4][0-7]$/g) )
	{
		select_innerHTML( document.getElementById( "prefecture" ), "<option value=\"0\">市区町村</option>" );
		return false;
	}
	
	var targetFile = "phpscript/src/selectCity.php?StateCode=" + value ;
	
	new Ajax.Request( targetFile + "&cache=" + ( new Date().getTime() ),
	{
		method: "get",
		onComplete: function( httpObj )
		{
			//document.getElementById("prefecture").innerHTML = httpObj.responseText;
			select_innerHTML( document.getElementById( "prefecture" ), httpObj.responseText );
		}
	} );
}



/**
 * @Name    generalityFormCheck 
 * @Desc    資料請求(一般)チェック
 * @Param   
 * @Author  T.Tanaka
 * @Date    2007/08/30
 **/
function generalityFormCheck()
{
	if( !document.getElementById( "family_name" ).value.length > 0 )
	{
		alert( "お名前(姓)を入力してください。" );
		document.getElementById( "family_name" ).focus();
		return false;
	}
	
	if( !document.getElementById( "first_name" ).value.length > 0 )
	{
		alert( "お名前(名)を入力してください。" );
		document.getElementById( "first_name" ).focus();
		return false;
	}
	
	if( !document.getElementById( "family_name_kana" ).value.length > 0 )
	{
		alert( "ふりがな(姓)を入力してください。" );
		document.getElementById( "family_name_kana" ).focus();
		return false;
	}
	
	if( !document.getElementById( "first_name_kana" ).value.length > 0 )
	{
		alert( "ふりがな(名)を入力してください。" );
		document.getElementById( "first_name_kana" ).focus();
		return false;
	}
	
	if( ( document.getElementById( "sex1" ).checked == false ) && ( document.getElementById( "sex2" ).checked == false ) )
	{
		alert( "性別を選択してください" );
		document.getElementById( "sex1" ).focus();
		return false;
	}
	
	if( !document.getElementById( "birth_year" ).value.match(/^([1][9]|[2][0])[0-9]{2}$/g) )
	{
		alert( "生年月日(年)を4桁で入力してください。" );
		document.getElementById( "birth_year" ).focus();
		return false;
	}
	
	if( !document.getElementById( "birth_month" ).value.match(/^([0][1-9]|[1][0-2]$)/g) )
	{
		alert( "生年月日(月)を2桁で入力してください。\r\n1月～9月は頭に【0(ゼロ)】を付けてください。" );
		document.getElementById( "birth_month" ).focus();
		return false;
	}
	
	if( !document.getElementById( "birth_day" ).value.match(/^([0][1-9]|[1][0-9]|[2][0-9]|[3][0-1]$)/g) )
	{
		alert( "生年月日(日)を2桁で入力してください。\r\n1日～9日は頭に【0(ゼロ)】を付けてください。" );
		document.getElementById( "birth_day" ).focus();
		return false;
	}
	
	if( !document.getElementById( "zip1" ).value.match(/^[0-9]{3}$/g) )
	{
		alert( "郵便番号を入力してください。" );
		document.getElementById( "zip1" ).focus();
		return false;
	}
	
	if( !document.getElementById( "zip2" ).value.match(/^[0-9]{4}$/g) )
	{
		alert( "郵便番号を入力してください。" );
		document.getElementById( "zip2" ).focus();
		return false;
	}
	
	if( !document.getElementById( "state_code" ).value.match(/^([1-9]|[1-4][0-9])$/g) )
	{
		alert( "都道府県を選択してください。" );
		document.getElementById( "state_code" ).focus();
		return false;
	}
	
	if( ( !document.getElementById( "prefecture" ).value.length > 0 ) || ( document.getElementById( "prefecture" ).value == 0 ) )
	{
		alert( "市区町村を入力してください。" );
		document.getElementById( "prefecture" ).focus();
		return false;
	}
	
	if( !document.getElementById( "address" ).value.length > 0 )
	{
		alert( "番地（建物名等）を入力してください。" );
		document.getElementById( "address" ).focus();
		return false;
	}
	
	if( !document.getElementById( "tel1" ).value.match(/^[0-9]+$/g) )
	{
		alert( "電話番号を入力してください。" );
		document.getElementById( "tel1" ).focus();
		return false;
	}
	
	if( !document.getElementById( "tel2" ).value.match(/^[0-9]+$/g) )
	{
		alert( "電話番号を入力してください。" );
		document.getElementById( "tel2" ).focus();
		return false;
	}
	
	if( !document.getElementById( "tel3" ).value.match(/^[0-9]+$/g) )
	{
		alert( "電話番号を入力してください。" );
		document.getElementById( "tel3" ).focus();
		return false;
	}
	
	//if( !document.getElementById( "mail" ).value.match(/.+@.+\..+/) )
	if( !document.getElementById( "mail" ).value.match(/^[0-9,A-Z,a-z][0-9,a-z,A-Z,_,\.,-]+@[0-9,A-Z,a-z][0-9,a-z,A-Z,_,\.,-]+\.(af|al|dz|as|ad|ao|ai|aq|ag|ar|am|aw|ac|au|at|az|bh|bd|bb|by|bj|bm|bt|bo|ba|bw|br|io|bn|bg|bf|bi|kh|cm|ca|cv|cf|td|gg|je|cl|cn|cx|cc|co|km|cg|cd|ck|cr|ci|hr|cu|cy|cz|dk|dj|dm|do|tp|ec|eg|sv|gq|er|ee|et|fk|fo|fj|fi|fr|gf|pf|tf|fx|ga|gm|ge|de|gh|gi|gd|gp|gu|gt|gn|gw|gy|ht|hm|hn|hk|hu|is|in|id|ir|iq|ie|im|il|it|jm|jo|kz|ke|ki|kp|kr|kw|kg|la|lv|lb|ls|lr|ly|li|lt|lu|mo|mk|mg|mw|my|mv|ml|mt|mh|mq|mr|mu|yt|mx|fm|md|mc|mn|ms|ma|mz|mm|na|nr|np|nl|an|nc|nz|ni|ne|ng|nu|nf|mp|no|om|pk|pw|pa|pg|py|pe|ph|pn|pl|pt|pr|qa|re|ro|ru|rw|kn|lc|vc|ws|sm|st|sa|sn|sc|sl|sg|sk|si|sb|so|za|gs|es|lk|sh|pm|sd|sr|sj|sz|se|ch|sy|tw|tj|tz|th|bs|ky|tg|tk|to|tt|tn|tr|tm|tc|tv|ug|ua|ae|uk|us|um|uy|uz|vu|va|ve|vn|vg|vi|wf|eh|ye|yu|zm|zw|com|net|org|gov|edu|int|mil|biz|info|name|pro|jp)$/i) )
	{
		alert( "メールアドレスを入力してください。" );
		document.getElementById( "mail" ).focus();
		return false;
	}
	
	if( !document.getElementById( "mail_check" ).value.match(/^[0-9,A-Z,a-z][0-9,a-z,A-Z,_,\.,-]+@[0-9,A-Z,a-z][0-9,a-z,A-Z,_,\.,-]+\.(af|al|dz|as|ad|ao|ai|aq|ag|ar|am|aw|ac|au|at|az|bh|bd|bb|by|bj|bm|bt|bo|ba|bw|br|io|bn|bg|bf|bi|kh|cm|ca|cv|cf|td|gg|je|cl|cn|cx|cc|co|km|cg|cd|ck|cr|ci|hr|cu|cy|cz|dk|dj|dm|do|tp|ec|eg|sv|gq|er|ee|et|fk|fo|fj|fi|fr|gf|pf|tf|fx|ga|gm|ge|de|gh|gi|gd|gp|gu|gt|gn|gw|gy|ht|hm|hn|hk|hu|is|in|id|ir|iq|ie|im|il|it|jm|jo|kz|ke|ki|kp|kr|kw|kg|la|lv|lb|ls|lr|ly|li|lt|lu|mo|mk|mg|mw|my|mv|ml|mt|mh|mq|mr|mu|yt|mx|fm|md|mc|mn|ms|ma|mz|mm|na|nr|np|nl|an|nc|nz|ni|ne|ng|nu|nf|mp|no|om|pk|pw|pa|pg|py|pe|ph|pn|pl|pt|pr|qa|re|ro|ru|rw|kn|lc|vc|ws|sm|st|sa|sn|sc|sl|sg|sk|si|sb|so|za|gs|es|lk|sh|pm|sd|sr|sj|sz|se|ch|sy|tw|tj|tz|th|bs|ky|tg|tk|to|tt|tn|tr|tm|tc|tv|ug|ua|ae|uk|us|um|uy|uz|vu|va|ve|vn|vg|vi|wf|eh|ye|yu|zm|zw|com|net|org|gov|edu|int|mil|biz|info|name|pro|jp)$/i) )
	//if( !document.getElementById( "mail_check" ).value.match(/.+@.+\..+/) )
	{
		alert( "メールアドレス(確認用)を入力してください。" );
		document.getElementById( "mail_check" ).focus();
		return false;
	}
	
	if( document.getElementById( "mail" ).value != document.getElementById( "mail_check" ).value )
	{
		alert( "メールアドレスと、確認用メールアドレスが違います。\r\nもう一度ご確認ください。" );
		document.getElementById( "mail_check" ).focus();
		return false;
	}
	
    if( ( document.getElementById( "job1" ).checked == false ) && 
        ( document.getElementById( "job2" ).checked == false ) && 
        ( document.getElementById( "job3" ).checked == false ) && 
        ( document.getElementById( "job4" ).checked == false ) && 
        ( document.getElementById( "job5" ).checked == false ) && 
        ( document.getElementById( "job6" ).checked == false ) )
    {
        alert( "ご職業を選択してください" );
        document.getElementById( "job1" ).focus();
        return false;
    }
	
    if( ( document.getElementById( "find1" ).checked == false ) && 
        ( document.getElementById( "find2" ).checked == false ) && 
        ( document.getElementById( "find3" ).checked == false ) && 
        ( document.getElementById( "find4" ).checked == false ) && 
        ( document.getElementById( "find5" ).checked == false ) )
    {
        alert( "アンケートを選択してください" );
        document.getElementById( "find1" ).focus();
        return false;
    }
	
    if( ( document.getElementById( "catalog1" ).checked == false ) && 
        ( document.getElementById( "catalog2" ).checked == false ) && 
        ( document.getElementById( "catalog3" ).checked == false ) && 
        ( document.getElementById( "catalog4" ).checked == false ) && 
        ( document.getElementById( "catalog5" ).checked == false ) && 
        ( document.getElementById( "catalog6" ).checked == false ) && 
        ( document.getElementById( "catalog7" ).checked == false ) && 
        ( document.getElementById( "catalog8" ).checked == false ) )
    {
        alert( "ご希望のパンフレットをお選びください" );
        document.getElementById( "catalog1" ).focus();
        return false;
    }
}



/**
 * @Name    traderFormCheck 
 * @Desc    資料請求(業者)チェック
 * @Param   
 * @Author  T.Tanaka
 * @Date    2007/06/12 11:26
 **/
function traderFormCheck()
{
	if( !document.getElementById( "family_name" ).value.length > 0 )
	{
		alert( "お名前(姓)を入力してください。" );
		document.getElementById( "family_name" ).focus();
		return false;
	}
	
	if( !document.getElementById( "first_name" ).value.length > 0 )
	{
		alert( "お名前(名)を入力してください。" );
		document.getElementById( "first_name" ).focus();
		return false;
	}
	
	if( !document.getElementById( "family_name_kana" ).value.length > 0 )
	{
		alert( "ふりがな(姓)を入力してください。" );
		document.getElementById( "family_name_kana" ).focus();
		return false;
	}
	
	if( !document.getElementById( "first_name_kana" ).value.length > 0 )
	{
		alert( "ふりがな(名)を入力してください。" );
		document.getElementById( "first_name_kana" ).focus();
		return false;
	}
	
	if( !document.getElementById( "com_name" ).value.length > 0 )
	{
		alert( "会社名を入力してください。" );
		document.getElementById( "com_name" ).focus();
		return false;
	}
	
	if( !document.getElementById( "com_name_kana" ).value.length > 0 )
	{
		alert( "ふりがな(会社名)を入力してください。" );
		document.getElementById( "com_name_kana" ).focus();
		return false;
	}
	
	if( !document.getElementById( "zip1" ).value.match(/^[0-9]{3}$/g) )
	{
		alert( "郵便番号を入力してください。" );
		document.getElementById( "zip1" ).focus();
		return false;
	}
	
	if( !document.getElementById( "zip2" ).value.match(/^[0-9]{4}$/g) )
	{
		alert( "郵便番号を入力してください。" );
		document.getElementById( "zip2" ).focus();
		return false;
	}
	
	if( !document.getElementById( "state_code" ).value.match(/^([1-9]|[1-4][0-9])$/g) )
	{
		alert( "都道府県を選択してください。" );
		document.getElementById( "state_code" ).focus();
		return false;
	}
	
	if( ( !document.getElementById( "prefecture" ).value.length > 0 ) || ( document.getElementById( "prefecture" ).value == 0 ) )
	{
		alert( "市区町村を入力してください。" );
		document.getElementById( "prefecture" ).focus();
		return false;
	}
	
	if( !document.getElementById( "address" ).value.length > 0 )
	{
		alert( "番地（建物名等）を入力してください。" );
		document.getElementById( "address" ).focus();
		return false;
	}
	
	if( !document.getElementById( "tel1" ).value.match(/^[0-9]+$/g) )
	{
		alert( "電話番号を入力してください。" );
		document.getElementById( "tel1" ).focus();
		return false;
	}
	
	if( !document.getElementById( "tel2" ).value.match(/^[0-9]+$/g) )
	{
		alert( "電話番号を入力してください。" );
		document.getElementById( "tel2" ).focus();
		return false;
	}
	
	if( !document.getElementById( "tel3" ).value.match(/^[0-9]+$/g) )
	{
		alert( "電話番号を入力してください。" );
		document.getElementById( "tel3" ).focus();
		return false;
	}
	
	if( !document.getElementById( "fax1" ).value.match(/^[0-9]+$/g) )
	{
		alert( "ＦＡＸ番号を入力してください。" );
		document.getElementById( "fax1" ).focus();
		return false;
	}
	
	if( !document.getElementById( "fax2" ).value.match(/^[0-9]+$/g) )
	{
		alert( "ＦＡＸ番号を入力してください。" );
		document.getElementById( "fax2" ).focus();
		return false;
	}
	
	if( !document.getElementById( "fax3" ).value.match(/^[0-9]+$/g) )
	{
		alert( "ＦＡＸ番号を入力してください。" );
		document.getElementById( "fax3" ).focus();
		return false;
	}
	
	if( !document.getElementById( "mail" ).value.match(/^[0-9,A-Z,a-z][0-9,a-z,A-Z,_,\.,-]+@[0-9,A-Z,a-z][0-9,a-z,A-Z,_,\.,-]+\.(af|al|dz|as|ad|ao|ai|aq|ag|ar|am|aw|ac|au|at|az|bh|bd|bb|by|bj|bm|bt|bo|ba|bw|br|io|bn|bg|bf|bi|kh|cm|ca|cv|cf|td|gg|je|cl|cn|cx|cc|co|km|cg|cd|ck|cr|ci|hr|cu|cy|cz|dk|dj|dm|do|tp|ec|eg|sv|gq|er|ee|et|fk|fo|fj|fi|fr|gf|pf|tf|fx|ga|gm|ge|de|gh|gi|gd|gp|gu|gt|gn|gw|gy|ht|hm|hn|hk|hu|is|in|id|ir|iq|ie|im|il|it|jm|jo|kz|ke|ki|kp|kr|kw|kg|la|lv|lb|ls|lr|ly|li|lt|lu|mo|mk|mg|mw|my|mv|ml|mt|mh|mq|mr|mu|yt|mx|fm|md|mc|mn|ms|ma|mz|mm|na|nr|np|nl|an|nc|nz|ni|ne|ng|nu|nf|mp|no|om|pk|pw|pa|pg|py|pe|ph|pn|pl|pt|pr|qa|re|ro|ru|rw|kn|lc|vc|ws|sm|st|sa|sn|sc|sl|sg|sk|si|sb|so|za|gs|es|lk|sh|pm|sd|sr|sj|sz|se|ch|sy|tw|tj|tz|th|bs|ky|tg|tk|to|tt|tn|tr|tm|tc|tv|ug|ua|ae|uk|us|um|uy|uz|vu|va|ve|vn|vg|vi|wf|eh|ye|yu|zm|zw|com|net|org|gov|edu|int|mil|biz|info|name|pro|jp)$/i) )
	{
		alert( "メールアドレスを入力してください。" );
		document.getElementById( "mail" ).focus();
		return false;
	}
	
	if( !document.getElementById( "mail_check" ).value.match(/^[0-9,A-Z,a-z][0-9,a-z,A-Z,_,\.,-]+@[0-9,A-Z,a-z][0-9,a-z,A-Z,_,\.,-]+\.(af|al|dz|as|ad|ao|ai|aq|ag|ar|am|aw|ac|au|at|az|bh|bd|bb|by|bj|bm|bt|bo|ba|bw|br|io|bn|bg|bf|bi|kh|cm|ca|cv|cf|td|gg|je|cl|cn|cx|cc|co|km|cg|cd|ck|cr|ci|hr|cu|cy|cz|dk|dj|dm|do|tp|ec|eg|sv|gq|er|ee|et|fk|fo|fj|fi|fr|gf|pf|tf|fx|ga|gm|ge|de|gh|gi|gd|gp|gu|gt|gn|gw|gy|ht|hm|hn|hk|hu|is|in|id|ir|iq|ie|im|il|it|jm|jo|kz|ke|ki|kp|kr|kw|kg|la|lv|lb|ls|lr|ly|li|lt|lu|mo|mk|mg|mw|my|mv|ml|mt|mh|mq|mr|mu|yt|mx|fm|md|mc|mn|ms|ma|mz|mm|na|nr|np|nl|an|nc|nz|ni|ne|ng|nu|nf|mp|no|om|pk|pw|pa|pg|py|pe|ph|pn|pl|pt|pr|qa|re|ro|ru|rw|kn|lc|vc|ws|sm|st|sa|sn|sc|sl|sg|sk|si|sb|so|za|gs|es|lk|sh|pm|sd|sr|sj|sz|se|ch|sy|tw|tj|tz|th|bs|ky|tg|tk|to|tt|tn|tr|tm|tc|tv|ug|ua|ae|uk|us|um|uy|uz|vu|va|ve|vn|vg|vi|wf|eh|ye|yu|zm|zw|com|net|org|gov|edu|int|mil|biz|info|name|pro|jp)$/i) )
	//if( !document.getElementById( "mail_check" ).value.match(/.+@.+\..+/) )
	{
		alert( "メールアドレス(確認用)を入力してください。" );
		document.getElementById( "mail_check" ).focus();
		return false;
	}
	
	if( document.getElementById( "mail" ).value != document.getElementById( "mail_check" ).value )
	{
		alert( "メールアドレスと、確認用メールアドレスが違います。\r\nもう一度ご確認ください。" );
		document.getElementById( "mail_check" ).focus();
		return false;
	}
	
    if( ( document.getElementById( "mode1" ).checked == false ) && 
        ( document.getElementById( "mode2" ).checked == false ) && 
        ( document.getElementById( "mode3" ).checked == false ) && 
        ( document.getElementById( "mode4" ).checked == false ) )
    {
        alert( "業務形態を選択してください" );
        document.getElementById( "mode1" ).focus();
        return false;
    }
	
    if( ( document.getElementById( "find1" ).checked == false ) && 
        ( document.getElementById( "find2" ).checked == false ) && 
        ( document.getElementById( "find3" ).checked == false ) && 
        ( document.getElementById( "find4" ).checked == false ) && 
        ( document.getElementById( "find5" ).checked == false ) )
    {
        alert( "アンケートを選択してください" );
        document.getElementById( "find1" ).focus();
        return false;
    }
	
    if( ( document.getElementById( "catalog1" ).value == "0" ) && 
        ( document.getElementById( "catalog2" ).value == "0" ) && 
        ( document.getElementById( "catalog3" ).value == "0" ) && 
        ( document.getElementById( "catalog4" ).value == "0" ) && 
        ( document.getElementById( "catalog5" ).value == "0" ) && 
        ( document.getElementById( "catalog6" ).value == "0" ) && 
        ( document.getElementById( "catalog7" ).value == "0" ) )
    {
        alert( "ご希望のパンフレットをお選びください" );
        document.getElementById( "catalog1" ).focus();
        return false;
    }
}



function select_innerHTML( objeto,innerHTML ){
/******
* select_innerHTML - innerHTML to add option(s) to select(s)
* Problem: http://support.microsoft.com/default.aspx?scid=kb;en-us;276228
* Creative Commons license
* Versão: 1.0 - 06/04/2006
* Author: Micox - Náiron J.C.G - micoxjcg@yahoo.com.br - elmicoxcodes.blogspot.com
* Parametros:
* objeto(tipo object): the select
* innerHTML(tipo string): the new innerHTML
*******/
    objeto.innerHTML = ""
    //creating phantom element to receive temp innerHTML
    var selTemp = document.createElement("micoxselect")
    var opt;
    selTemp.id="micoxselect1"
    document.body.appendChild(selTemp)
    selTemp = document.getElementById("micoxselect1")
    selTemp.style.display="none"
    if(innerHTML.toLowerCase().indexOf("<option")<0){//if not option, convert do option
        innerHTML = "<option>" + innerHTML + "</option>"
    }
    innerHTML = innerHTML.replace(/<option/g,"<span").replace(/<\/option/g,"</span")
    selTemp.innerHTML = innerHTML
    //transfering childs of phantom element to options
    for(var i=0;i<selTemp.childNodes.length;i++){
        if(selTemp.childNodes[i].tagName){
            opt = document.createElement("OPTION")
            for(var j=0;j<selTemp.childNodes[i].attributes.length;j++){
                opt.setAttributeNode(selTemp.childNodes[i].attributes[j].cloneNode(true))
            }
            opt.value = selTemp.childNodes[i].getAttribute("value")
            opt.text = selTemp.childNodes[i].innerHTML
            if(document.all){ //IEca
                objeto.add(opt)
            }else{
                objeto.appendChild(opt)
            }                    
        }    
    }
    //clear phantom
    document.body.removeChild(selTemp)
    selTemp = null
}
