if($('cam_plan')) {
    jQuery.noConflict();
}
var g_ny;
function getApplication () {
 return 'account';
}

function sendAccount () {
	/*
    if (document.getElementById('terms').checked == false) {
        alert('利用規約に同意した上でお申し込みを行ってください。');
        return false;
    }
	*/
    document.getElementById('send').submit();
    return true;
}

function selectPlanSubmit () {
    // prototype.js
    var plan = Form.serialize($('select-plan')).toQueryParams()['plan'];
    
    if(typeof plan == "undefined"){
        alert('利用するプランを選択してください');
        return false;
    } else {
        return true;
    }
}

//キャンペーン認証ボタン押下時に呼ばれる
function clickCertButton(form) {
    document.cert.campaignCode.value = form.campaignCodeText.value;
    document.cert.submit();
}


function setValue(str) {
    if(str == "set") {
        document.getElementById('select-plan').cflg.value = "1";
    }else{
        document.getElementById('select-plan').cflg.value = "";
    }
}


function getCampaignPlan(value) {
    //認証ボタンを押せなくする
    $('cam_cert').disabled = true;
    document.body.style.cursor = 'wait';
    
    //キャンペーンコードエラーチェック
    if(value == ''){
        document.body.style.cursor = 'default';
        $('cam_cert').disabled = false;
        alert('キャンペーンコードが入力されていません。');
        return;
    }else{
        if(value.length != 16) {
            document.body.style.cursor = 'default';
            $('cam_cert').disabled = false
            alert('入力したキャンペーンコードが正しくありません。');
            return
        }
    }
    
    
    new Ajax.Updater('cam_plan'
             , '/account/campaign'
             , {
                   asynchronous: true
                 , evalScripts:  false
                 , method: 'post'
                 , parameters: 'code=' + value
                 , onComplete: function(request){
                       if(request.responseText.indexOf("fali_count_5") != -1) {
                           document.body.style.cursor = 'default';
                           $('cam_code').disabled = true;
                           $('cam_cert').disabled = true;
                       } else if(request.responseText.indexOf("cert_error") != -1) {
                           document.body.style.cursor = 'default';
                           alert('入力したキャンペーンコードが正しくありません。\n※1日に5回以上認証に失敗するとその日はキャンペーンコードが使用できなくなります。');
                           $('cam_cert').disabled = false;
                       }else{
                           //alert('認証成功');
                           //ブラウザ判定
                           if(navigator.userAgent.indexOf('Safari') != -1) {
                               //Safari Or Chromeは普通に表示
                               $('cam_plan').style.display = 'block';
                           }else{
                               jQuery('#cam_plan').toggle('clip', {direction: 'vertical'}, 2000);
                               //location.href = "#cambottom";
                               scroll();
                               document.body.style.cursor = 'default';
                           }

                       }
                   }
               });
}


function scroll(){
    var speed = 2;
    var move  = 5;
    
    window.scrollBy(0, move); // スクロール処理
    var rep = setTimeout("scroll()", speed);
    var scrollTop  = document.body.scrollTop  || document.documentElement.scrollTop;    
    var y = scrollTop;
    
    
    if(g_ny == y){ // スクロールし終わっていたら処理を終了
        clearTimeout(rep);
    }
    else{
        g_ny = y;
    }
}




