function submitLogin(){
    document.getElementById('loginError').style.display="none";
    document.getElementById('loginLoader').style.display="block";
    var user=document.getElementById('loginUsername').value;
    var pass=document.getElementById('loginPassword').value;
    var rememberLogin=$("#rememberLogin").is(':checked');
    login(user,pass,rememberLogin);
}


function loginSuccess(xmlHttp) 
{ 
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    { 
        var xmlDoc = xmlHttp.responseXML;

        var errorArray = xmlDoc.getElementsByTagName('error');
        var userArray = xmlDoc.getElementsByTagName('user');

        s=errorArray[0].firstChild.data;
        if(s=="OK")
        {
            var username=userArray[0].firstChild.data;
            $("#loggedUsername").text(username);
            $('#loginLoader').hide();
            $("#loginForm").animate({
                left:'-=356'
            }, 600,'easeInExpo', function() {
                // alert('complete');
                });
        //window.location="default.php?page=my_cp";
        }
        else
        {
            document.getElementById('loginLoader').style.display="none";
            document.getElementById('loginError').style.display="block";
            document.getElementById('loginError').innerHTML=s;
        }

    } 
 
}


jQuery(document).ready(function() {
	
    //countDownTimer();
	
    $("#indexSlides").visualslide({
        width:630,
        height:266,
        slideSelector:".indexSlide",
        currentSlide:0,
        afterLoading:function(){
        //alert("slide loaded");
        }
    });
    
    
    var defaultTemplate={
        firstStep:{
            current:"<div style=\"float:left; cursor:pointer; width:${width}px; height:18px; background-image:url('img/index/selected_slide_background.png'); background-repeat: repeat-x; border-left:1px solid #e5e5e5; border-top:1px solid #e5e5e5; border-bottom:1px solid #e5e5e5;\"><div style=\"font-family:'sans-serif'; font-size:12px; color:#727272; text-align:center;\">${title}</div></div>",
            marked:"<div onclick=\"${click}\" style='float:left; cursor:pointer; width:${width}px; height:18px; background-color:#f7f5f5; border-left:1px solid #e5e5e5; border-top:1px solid #e5e5e5; border-bottom:1px solid #e5e5e5;'><div style=\"font-family:'sans-serif'; font-size:12px; color:#727272; text-align:center;\">${title}</div></div>",
            unmarked:"<div onclick=\"${click}\" style='float:left; cursor:pointer; width:${width}px; height:18px; background-color:#f7f5f5; border-left:1px solid #e5e5e5; border-top:1px solid #e5e5e5; border-bottom:1px solid #e5e5e5;'><div style=\"font-family:'sans-serif'; font-size:12px; color:#727272; text-align:center;\">${title}</div></div>"
        },
        lastStep:{
            current:"<div style=\"float:left; cursor:pointer; width:${width}px; height:18px; background-image:url('img/index/selected_slide_background.png'); background-repeat: repeat-x; border:1px solid #e5e5e5;\"><div style=\"font-family:'sans-serif'; font-size:12px; color:#727272; text-align:center;\">${title}</div></div>",
            marked:"<div onclick=\"${click}\" style='float:left; cursor:pointer; width:${width}px; height:18px; background-color:#f7f5f5; border:1px solid #e5e5e5;'><div style=\"font-family:'sans-serif'; font-size:12px; color:#727272; text-align:center;\">${title}</div></div>",
            unmarked:"<div onclick=\"${click}\" style='float:left; cursor:pointer; width:${width}px; height:18px; background-color:#f7f5f5; border:1px solid #e5e5e5;'><div style=\"font-family:'sans-serif'; font-size:12px; color:#727272; text-align:center;\">${title}</div></div>"
        },
        middleStep:{
            current:"<div style=\"float:left; cursor:pointer; width:${width}px; height:18px; background-image:url('img/index/selected_slide_background.png'); background-repeat: repeat-x; border-left:1px solid #e5e5e5; border-top:1px solid #e5e5e5; border-bottom:1px solid #e5e5e5;\"><div style=\"font-family:'sans-serif'; font-size:12px; color:#727272; text-align:center;\">${title}</div></div>",
            marked:"<div onclick=\"${click}\" style='float:left; cursor:pointer; width:${width}px; height:18px; background-color:#f7f5f5; border-left:1px solid #e5e5e5; border-top:1px solid #e5e5e5; border-bottom:1px solid #e5e5e5;'><div style=\"font-family:'sans-serif'; font-size:12px; color:#727272; text-align:center;\">${title}</div></div>",
            unmarked:"<div onclick=\"${click}\" style='float:left; cursor:pointer; width:${width}px; height:18px; background-color:#f7f5f5; border-left:1px solid #e5e5e5; border-top:1px solid #e5e5e5; border-bottom:1px solid #e5e5e5;'><div style=\"font-family:'sans-serif'; font-size:12px; color:#727272; text-align:center;\">${title}</div></div>"
        },
        header:"<div id=\"barTimer\" style='height:1px; width:1px; background-color:#f67e2a;'><!-- --></div><div style='height:2px;'><!-- --></div>",
        footer:"<div style='clear:both; height:0px;'><!-- --></div>"
    };
         
    var defaultStep={
        width:153,
        beforeLoading:function(){
            this.wizard("lock");

            this.wizard("unlock");
        },
        afterLoading:function(){
            $("#indexSlides").visualslide("goToSlide",this.wizard("currentStep"));
        }
    };
    
    $("#indexSteps").wizard(defaultTemplate,defaultStep);
    
    $("#indexSteps").wizard("addStep",{
        title:"Beta 7 - released",
        description:"Beta 7 + Chat Widget 1.1 released: up to 350% faster",
        line:0,
        click:"$('#barTimer').stop();$('#indexSteps').wizard('goToStep',0);"
    });      
    $("#indexSteps").wizard("addStep",{
        title:"Beta 6 - released",
        description:"Beta 6 has been released",
        line:1,
        click:"$('#barTimer').stop();$('#indexSteps').wizard('goToStep',1);"
    });   
    $("#indexSteps").wizard("addStep",{
        title:"Beta 5 - released",
        description:"Beta 5 has been released",
        line:2,
        click:"$('#barTimer').stop();$('#indexSteps').wizard('goToStep',2);"
    });    
    $("#indexSteps").wizard("addStep",{
        title:"Beta 4 - released",
        description:"Beta 4 has been released",
        line:3,
        click:"$('#barTimer').stop();$('#indexSteps').wizard('goToStep',3);"
    });

    
    $("#indexSteps").wizard("updatedCompleted",function(){
        $('#barTimer').stop().animate({
            width: '+=617'
        }, 15000, function() {
            var currentSlide=$("#indexSteps").wizard("currentStep");
            var slideNumber=$("#indexSteps").wizard("stepsNumber");
            if(currentSlide==slideNumber-1)
                $('#indexSteps').wizard('goToStep',0);
            else
                $('#indexSteps').wizard('next');
        });	  
    });
    
    $("#indexSteps").wizard("update",0);
	
    //setInterval("changeStep()",3000);

    $("#loginUsername").keypress(function(e) {
        if(e.keyCode == 13) {
            e.preventDefault();
            submitLogin();
        }
    });
    
    $("#loginPassword").keypress(function(e) {
        if(e.keyCode == 13) {
            e.preventDefault();
            submitLogin();
        }
    });



});



function goChatboard(){
    window.location="default.php?page=my_cp";
}

function changeStep(){
    $('#indexSteps').wizard('next');
}




function countDownTimer(){
    var flashvars = {
        sf:"default.php?action=slide_beta_timer"
    };
    var params = {
        allowScriptAccess:"always",
        menu:"false",
        wmode:"transparent"
    };
    var attributes = {
        id: "operatorFlash",
        name: "operatorFlash"
    };
	
    swfobject.embedSWF("swf/beta_timer_simple.swf", "betaTimerAnimationSWF", "410px", "75px", "9.0.0","", flashvars, params, attributes);
	
    $("#betaTimerAnimation").css("position","absolute");   
    $("#betaTimerAnimation").css("left","10px");
    $("#betaTimerAnimation").css("top","185px");

}
