//2005/10/18変更
function err(form_object, input_object, object_value, error_message)
{
    alert(error_message);
           return false;    
}

function hasValue(obj, obj_type)
{
    if (obj_type == "TEXT" || obj_type == "PASSWORD")
    {
        if (obj.value.length == 0) 
              return false;
        else 
              return true;
        }
    else if (obj_type == "SELECT")
    {
        for (i=0; i < obj.length; i++)
            {
        if (obj.options[i].selected)
            return true;
        }

           return false;    
    }
    else if (obj_type == "SINGLE_VALUE_RADIO" || obj_type == "SINGLE_VALUE_CHECKBOX")
    {

        if (obj.checked)
            return true;
        else
               return false;    
    }
    else if (obj_type == "RADIO" || obj_type == "CHECKBOX")
    {
        for (i=0; i < obj.length; i++)
            {
        if (obj[i].checked)
            return true;
        }
           return false;    
    }
}

function checkEmail(emailValue)
{
    object_value=emailValue;
    var start_format = "@.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-";
    var check_char;
    var DOT = '.';
    var ATMARK = '@';
    //var atmark = '@';
    
    var atmark_chk = false;
    var dot_chk=false;
    var atmark_position = 0;
    var dot_position=0;
    
    for (var i = 0; i < object_value.length; i++)
    {
        check_char = start_format.indexOf(object_value.charAt(i));
        
        //start_formatに文字列がない場合Falseを返す
        if (check_char < 0)
            return false;
                
        //＠があるかどうか判別
        if (check_char == 0 && !atmark_chk)
        {
            atmark_chk = true;
            //＠のある位置+1
            atmark_position=object_value.indexOf(ATMARK)+1;
        }
        
        //＠が２つ以上ある
        else if (check_char == 0 && atmark_chk)
            return false;
        
        // .(dot)の条件
        // .(dot)は＠の後ろに必ず1つ以上ある
        else if (atmark_position != 0 && check_char == 1 && object_value.charAt(atmark_position) != DOT)
        {
            dot_chk=true;
            // .(dot)がある位置+1
            dot_position=object_value.indexOf(DOT)+1;

            // .(dot)が連続した文字列ではない　
            //または、最後の文字が .(dot)ではない
            if (object_value.charAt(dot_position) == DOT || object_value.charAt(object_value.length-1) == DOT)
                return false;
        }
    }
    //すべてOK
    if (atmark_chk && dot_chk)
        return true    
}

function creditok(order_this){
//全てのラジオボタンをスキャン
//チェックされていたら
//それが基数
    for(i = 0; i < document.order.bill_meth.length; i++)
        if(document.order.bill_meth[i].checked) {
            paymeth = document.order.bill_meth[i].value;
            break;
        }

    if(paymeth=='9'){
    cre1=document.order.cre1.value;
    //cre2=document.order.cre2.value;
    //cre3=document.order.cre3.value;
    //cre4=document.order.cre4.value;
    creName=document.order.cre_name.value;
    credit=document.order.credit.value;
    //obj=document.chumon;

        if(credit!=0){
            //if(cre1=='' && cre2=='' && cre3=='' && cre4==''){
            if(cre1==''){
                alert("クレジット番号を正しく入力してください。");
                return false
            }
            if(creName==""){
                alert("クレジット名義を正しく入力してください。");
                return false
            }
            return true
        }
        else
            alert("クレジット会社名を選択してください。");
    }
    else

        return true
}

function  checkorder(_CF_this)
{
    
    if  (!hasValue(_CF_this.name, "TEXT" )) 
    {
        if  (!err(_CF_this, _CF_this.name, _CF_this.name.value, "お名前を入力してください。"))
            {
                return false; 
            }
    }

    if  (!hasValue(_CF_this.name_f, "TEXT" )) 
    {
        if  (!err(_CF_this, _CF_this.name_f, _CF_this.name_f.value, "ふりがなを入力してください。"))
            {
                return false; 
            }
    }

    if  (!hasValue(_CF_this.zip, "TEXT" )) 
    {
        if  (!err(_CF_this, _CF_this.zip, _CF_this.zip.value, "郵便番号を入力してください。"))
            {
                return false; 
            }
    }

    if(_CF_this.pref.value=="都道府県未選択")
    {
        alert("都道府県を選んでください")
        return false; 
    }

    if  (!hasValue(_CF_this.add, "TEXT" )) 
    {
        if  (!err(_CF_this, _CF_this.add, _CF_this.add.value, "住所を入力してください。"))
            {
                return false; 
            }
    }

    if  (!hasValue(_CF_this.tel, "TEXT" )) 
    {
        if  (!err(_CF_this, _CF_this.tel, _CF_this.tel.value, "電話番号を入力してください。"))
            {
                return false; 
            }
    }

    if  (!hasValue(_CF_this.email, "TEXT" )) 
    {
        if  (!err(_CF_this, _CF_this.email, _CF_this.email.value, "E-mailアドレスを入力してください。"))
            {
                return false; 
            }
    }
    else
    {
        if (checkEmail(_CF_this.email.value)!=true){
            alert("Emailアドレスを正しく入力してください。");
            return false
           }
    }
    
    if  (!hasValue(_CF_this.age, "TEXT" )) 
    {
        if  (!err(_CF_this, _CF_this.age, _CF_this.age.value, "年齢を入力してください。"))
            {
                return false; 
            }
    }

    if  (!hasValue(_CF_this.job, "TEXT" )) 
    {
        if  (!err(_CF_this, _CF_this.job, _CF_this.job.value, "職業を入力してください。"))
            {
                return false; 
            }
    }

    if  (!hasValue(_CF_this.site, "TEXT" )) 
    {
        if  (!err(_CF_this, _CF_this.site, _CF_this.site.value, "サイト名を入力してください。\n例）ＹＡＨＯＯ"))
            {
                return false; 
            }
    }


return true;
}
