/* 'MyOrder' JavaScript, version 0.1
* Copyright (c) 2009 Simon Odrich <info@server4voice.de>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
function toggleInfoBox(a){
    for($n=1;$n<=6;$n++){
        if($n==a){
            if(!$('infobox_'+$n).visible()){
                new Effect.toggle('infobox_'+$n,'appear');new Effect.Highlight('infobox_'+$n,{
                    startcolor:'#E42D18',
                    endcolor:'#ffffff'
                })
            }
        }else{
            if($('infobox_'+$n).visible()){
                $('infobox_'+$n).toggle()
            }
        }
    }
}
function getSelectValue(a){
    for(i=0;i<$(a).length;++i){
        if($(a).options[i].selected==true)return $(a).options[i].value
    }
}
function cutNumeric(a){
    if(isNumeric(a)==false)return false;return a.toFixed(2)
}
function isNumeric(a){
    if(a==null||!a.toString().match(/^[-]?\d*\.?\d*$/))return false;return true
}
function priceCalc_ts(){
    var a=getSelectValue("offer_ts");var b=getSelectValue("payment_interval");var c=getSelectValue("payment_type");if(price_array_ts[a]!=null){
        if($('price'))$('price').innerHTML=cutNumeric(price_array_ts[a])+" &#8364;";if(price_array_interval_months[b]!=null&&price_array_interval_text[b]!=null&&price_array_interval[b]!=null&&price_array_payment_type[c]!=null){
            price_interval=((price_array_ts[a]*price_array_interval_months[b]*(1.00-price_array_interval[b]))+price_array_payment_type[c]);price_per_month_reduced=price_interval/price_array_interval_months[b];$('price_dynamic').innerHTML=cutNumeric(price_interval)+" &#8364; / "+price_array_interval_text[b];if(price_array_interval_months[b]!=1.00){
                if($('price_dynamic_subtitle'))$('price_dynamic_subtitle').innerHTML="Im Durchschnitt ca <u>"+cutNumeric(price_per_month_reduced)+" &#8364;</u> pro Monat"
            }else{
                if($('price_dynamic_subtitle'))$('price_dynamic_subtitle').innerHTML=""
            }if($('pricecheck'))new Effect.Highlight('pricecheck',{
                startcolor:'#E42D18',
                endcolor:'#ffffff'
            });if($('price_current'))new Effect.Highlight('price_current',{
                startcolor:'#E42D18',
                endcolor:'#ffffff'
            })
        }else{
            if($('price_dynamic'))$('price_dynamic').innerHTML="Berechnungsfehler";if($('price_current'))new Effect.Highlight('price_current',{
                startcolor:'#E42D18',
                endcolor:'#ffffff'
            })
        }
    }else{
        if($('price'))$('price').innerHTML="Berechnungsfehler.";if($('price_dynamic'))$('price_dynamic').innerHTML="Berechnungsfehler"
    }
}
function initPage(){
    for($n=3;$n<=6;$n++){
        if($('infobox_'+$n)){
            if($('infobox_'+$n).visible()){
                $('infobox_'+$n).toggle()
            }
        }
    }if($('pricecheck')){
        if(!$('pricecheck').visible()){
            new Effect.toggle('pricecheck','appear');new Effect.Highlight('pricecheck',{
                startcolor:'#E42D18',
                endcolor:'#ffffff'
            })
        }
    }if($('price_current')){
        if(!$('price_current').visible()){
            $('price_current').toggle()
        }
    }if($('option_1'))Event.observe('option_1','mouseenter',function(a){
        toggleInfoBox('1')
    });if($('option_2'))Event.observe('option_2','mouseenter',function(a){
        toggleInfoBox('2')
    });if($('option_3'))Event.observe('option_3','mouseenter',function(a){
        toggleInfoBox('3')
    });if($('option_4'))Event.observe('option_4','mouseenter',function(a){
        toggleInfoBox('4')
    });if($('option_5'))Event.observe('option_5','mouseenter',function(a){
        toggleInfoBox('5')
    });if($('option_6'))Event.observe('option_6','mouseenter',function(a){
        toggleInfoBox('6')
    });if($('landingpage_orderbutton')){
        Event.observe('landingpage_orderbutton','mouseenter',function(a){
            document.body.style.cursor='pointer'
        });Event.observe('landingpage_orderbutton','mouseleave',function(a){
            document.body.style.cursor='default'
        })
    }if($('offer_ts'))Event.observe('offer_ts','change',priceCalc_ts);if($('payment_interval'))Event.observe('payment_interval','change',priceCalc_ts);if($('payment_type'))Event.observe('payment_type','change',priceCalc_ts);
}
/* url, formId, targetId */
function form_submit(a,b,c){
    if($(c)&&$(b)){
        var d=document.createElement("input");
        d.setAttribute("type","hidden");
        d.setAttribute("name","ajaxpost");
        d.setAttribute("value","yes");
        $(b).appendChild(d);
        myParameters=$(b).serialize(true);
        $(c).style.height=($(c).offsetHeight-40)+"px";
        $(c).innerHTML='<div style=\"width:100px; height:100px; margin:auto;\"><img src=\"images/ajax-loader.gif\" border=\"0\"/></div>';
        new Ajax.Request(a, {
            method: 'post',
            parameters:myParameters,
            onSuccess: function(transport) {
		$(c).style.height="";
                $(c).innerHTML=transport.responseText;
            }
        });

        /*new Ajax.Updater(
        {
            success:c
        },a,{
            method:'post',
            parameters:myParameters,
            onComplete:function(){
                $(c).style.height=""
            }
        })*/
    }
}
function landingpage_orderbutton(){
    if($('teamspeak-server-infos')){
        $('teamspeak-server-infos').toggle();
    };if($('dvloadpanel')&&!$('dvloadpanel').visible()){
        $('dvloadpanel').toggle();
    }if($('landingpage_orderbutton')){
        $('landingpage_orderbutton').style.background='white';$('landingpage_orderbutton').innerHTML='<img src=\"images/ajax-loader.gif\" height=\"24px\" border=\"0\"/>'
    }targetId='dvleftpanel';if($(targetId)){
        new Ajax.Updater({
            success:targetId
        },'index.html',{
            method:'post',
            parameters:{
                ajaxpost:'yes'
            },
            onComplete:function(){
                initPage();if($('dvloadpanel')&&$('dvloadpanel').visible()){
                    $('dvloadpanel').toggle();
                }if(!$(targetId).visible())new Effect.BlindDown(targetId,{
                    scaleTo:82
                });if ($('dvrightpanel')) {
                    $('dvrightpanel').innerHTML = '<div style=\'font-size:12px;\'><b>Rechenzentrum</b><br>[..] das Datacenter ist eines der modernsten Rechenzentren [..] 100% Gr&uuml;ne Energie im Normalbetrieb [..]. Die Anbindung [..] mit 75 Gbit/s und Direktverbindungen an die Peering-Points [..]<br><a href=\'info.html\'>mehr Infos</a><br><br><b>Serverhardware</b><br>Intel&reg; Xeon&reg; Prozessor E3110 (2x 3.0 GHz), mind. 4096 MB Arbeitsspeicher, Festplatte: [..]<br><a href=\'info.html\'>mehr Infos</a><br><br><b>Support</b><br>Wir bieten nicht nur Support direkt &uuml;ber den Teamspeak Server, sondern auch per Telefon und [..]<br><a href=\'support.html\'>mehr Infos</a><br></div>';$('dvrightpanel').toggle();new Effect.Highlight('dvrightpanel', {
                        startcolor: '#E42D18',
                        endcolor: '#ffffff'
                    });
                }
            }
        })
    }
}


