


var focusLkInput = function(id,text,tcon){
    
    if($("#"+id).val() == text)$("#"+id).val("");
    
    resetFocusLk(id);
    if( ! $("#"+id).hasClass("step_next") ){
        $("#"+id).addClass("step_next")
        if(id=="tech_req_start")
            doCTAReq(id,"",true);
        if(id=="tech_off_start")
            doCTAOff(id,"",true);
    }
    
}

var focusLkInputRegistered = function(id,text,tcon){
    if($("#"+id).val() == text)$("#"+id).val("");
    resetFocusLk(id);
}


var blurLkInput = function(id,text){
    if($("#"+id).val() == '')$("#"+id).val(text);
}

var resetFocusLk = function(sid){
    
}


var doCTAOff = function(id, value, check){
    if( check ){
        //if (( $("#"+ id ).val() != value ) && ($("#"+ id ).val() != "" )){
            $("#"+id+"_prebutton").hide("slow",function(){
                homeLoginOff();
            });
            
        //}else{
            $("#"+id).focus();
        //}
    }else{
        $("#"+id+"_prebutton").hide("slow",function(){
                homeLoginOff();
        });
        
    }
}

var doCTAOffRegistered = function(id, value, check){
    window.location.replace($("#redirect_login_off").val().concat($("#tech_off_start").val()));
}

var doCTAReq = function(id, value, check){
    if( check ){
        //if (( $("#"+ id ).val() != value ) && ($("#"+ id ).val() != "" )){
            $("#"+id+"_prebutton").hide("slow",function(){
                homeLoginReq();
            });
            
        //}else{
            $("#"+id).focus();
        //}
    }else{
        $("#"+id+"_prebutton").hide("slow",function(){
                homeLoginReq();
        });
        
    }
}

var doCTAReqRegistered = function(id, value, check){
    window.location.replace($("#redirect_register_req").val().concat($("#tech_req_start").val()));
}

var doHelperUI = function(){
    $(".helperUI").each(function(){
        var id = $(this).attr("id");
        if($("#"+id+"_content").html() == ""){
            $(this).remove();
        }else{
            $(this).show();
            $(this).qtip({
               content: $("#"+id+"_content").html(),
               position: {
                  corner: {
                     target: 'bottomMiddle',
                     tooltip: 'topMiddle'
                  }
               },
               style: { 
                  width: 350,
                  padding: 5,
                  background: '#F2F5F4',
                  color: 'black',
                  border: {
                     width: 1,
                     radius: 5,
                     color: '#58585A'
                  },
                  tip: 'topMiddle'
               }
            });
        }
    })
    
}


var doSliderStart = function(){
    // Set starting slide to 1
    var startSlide = 1;
    var d = new Date();
    var s = d.getSeconds();
    if(s < 20){
        startSlide=1;
    }
    if((s > 20)&&(s < 40 )){
        startSlide=2;
    }
    if(s > 40){
        startSlide=3;
    }
    // Initialize Slides
    $('#slides').slides({
            preload: true,
            preloadImage: '/images/loading.gif',
            generatePagination: true,
            paginationClass: 'pagination_slide',
            play: 8000,
            pause: 4000,
            hoverPause: true,
            autoHeight: false,
            slideSpeed: 600,
            fadeEasing: "linear",
            slideEasing: "linear",
            // Get the starting slide
            //start: startSlide,
            animationComplete: function(current){
                    // Set the slide number as a hash
                    window.location.hash = '#' + current;
           }
    });
};

var homeRegisterReq=function(){
    $(".subgreyreq").hide();
    $("#tech_req_start_postbutton").hide("slow"); 
    $("#lkinHomeRegisterReq").show("slow");
    if ( ! $(".lkinHomeRight",".box_input_seeker").hasClass("lkinHomeRightRegReqForm") )
        $(".lkinHomeRight",".box_input_seeker").addClass("lkinHomeRightRegReqForm");
}

var homeLoginReq=function(){
    $(".subgreyreq").hide();
    $("#lkinHomeRegisterReq").hide("slow");
    $("#tech_req_start_postbutton").show("slow"); 
    if ( $(".lkinHomeRight",".box_input_seeker").hasClass("lkinHomeRightRegReqForm") )
        $(".lkinHomeRight",".box_input_seeker").removeClass("lkinHomeRightRegReqForm");
}


var homeRegisterOff=function(){
    $(".subgreyreq").hide();
    $("#tech_off_start_postbutton").hide("slow"); 
    $("#lkinHomeRegisterOff").show("slow");
    if ( ! $(".lkinHomeRight",".box_input_seller").hasClass("lkinHomeRightRegOffForm") )
        $(".lkinHomeRight",".box_input_seller").addClass("lkinHomeRightRegOffForm");
}

var homeLoginOff=function(){
    $(".subgreyreq").hide();
    $("#lkinHomeRegisterOff").hide("slow");
    $("#tech_off_start_postbutton").show("slow"); 
    if ( $(".lkinHomeRight",".box_input_seller").hasClass("lkinHomeRightRegOffForm") )
        $(".lkinHomeRight",".box_input_seller").removeClass("lkinHomeRightRegOffForm");
}


var setupFormsHome=function(){

    
    $('#myformRegisterReq').unbind();
    $('#myformRegisterReq').bind("submit",function(){
        var options = { 
            target:         '#lkinHomeRegisterReq',
            replaceTarget: false,
            success:       checkRegisterResponseReq,
            beforeSubmit: function(arr, $form, options) { 
                // The array of form data takes the following form: 
                // [ { name: 'username', value: 'jresig' }, { name: 'password', value: 'secret' } ] 
                var id = 'tech_req_start';
                var value = $("#tech_req_start_textholder").val();
                if (( $("#"+ id ).val() != value ) && ($("#"+ id ).val() != "" )){
                    return true;
                }else{
                    $("#"+ id ).focus();
                    return false;
                }
                // return false to cancel submit                  
            }
            // other available options: 
            //url:       url         // override for form's 'action' attribute 
            //type:      type        // 'get' or 'post', override for form's 'method' attribute 
            //dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
            //clearForm: true        // clear all form fields after successful submit 
            //resetForm: true        // reset the form after successful submit 

            // $.ajax options can be used here too, for example: 
            //timeout:   3000 
       }; 
       $(this).ajaxSubmit(options);
       return false;
    });
    
    $('#myformRegisterOff').unbind();
    $('#myformRegisterOff').bind("submit",function(){
        var options = { 
            target:         '#lkinHomeRegisterOff',
            replaceTarget: false,
            success:       checkRegisterResponseOff,
            beforeSubmit: function(arr, $form, options) { 
                // The array of form data takes the following form: 
                // [ { name: 'username', value: 'jresig' }, { name: 'password', value: 'secret' } ] 
                var id = 'tech_off_start';
                var value = $("#tech_off_start_textholder").val();
                if (( $("#"+ id ).val() != value ) && ($("#"+ id ).val() != "" )){
                    return true;
                }else{
                    $("#"+ id ).focus();
                    return false;
                }
                // return false to cancel submit                  
            }
            // other available options: 
            //url:       url         // override for form's 'action' attribute 
            //type:      type        // 'get' or 'post', override for form's 'method' attribute 
            //dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
            //clearForm: true        // clear all form fields after successful submit 
            //resetForm: true        // reset the form after successful submit 

            // $.ajax options can be used here too, for example: 
            //timeout:   3000 
       }; 
       $(this).ajaxSubmit(options);
       return false;
    });
   
    
    $('#myformLoginReq').unbind();
    $('#myformLoginReq').bind("submit",function(){
        var options = { 
            target:         '#tech_req_start_postbutton',
            replaceTarget: false,
            success:       checkLoginResponseReq,
            beforeSubmit: function(arr, $form, options) { 
                // The array of form data takes the following form: 
                // [ { name: 'username', value: 'jresig' }, { name: 'password', value: 'secret' } ] 
                var id = 'tech_req_start';
                var value = $("#tech_req_start_textholder").val();
                if (( $("#"+ id ).val() != value ) && ($("#"+ id ).val() != "" )){
                    return true;
                }else{
                    $("#"+ id ).focus();
                    return false;
                }
                // return false to cancel submit                  
            }
            // other available options: 
            //url:       url         // override for form's 'action' attribute 
            //type:      type        // 'get' or 'post', override for form's 'method' attribute 
            //dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
            //clearForm: true        // clear all form fields after successful submit 
            //resetForm: true        // reset the form after successful submit 

            // $.ajax options can be used here too, for example: 
            //timeout:   3000 
       }; 
       $(this).ajaxSubmit(options);
       return false;
    });
    
    $('#myformLoginOff').unbind();
    $('#myformLoginOff').bind("submit",function(){
        var options = { 
            target:         '#tech_off_start_postbutton',
            replaceTarget: false,
            success:       checkLoginResponseOff,
            beforeSubmit: function(arr, $form, options) { 
                // The array of form data takes the following form: 
                // [ { name: 'username', value: 'jresig' }, { name: 'password', value: 'secret' } ] 
                var id = 'tech_off_start';
                var value = $("#tech_off_start_textholder").val();
                if (( $("#"+ id ).val() != value ) && ($("#"+ id ).val() != "" )){
                    return true;
                }else{
                    $("#"+ id ).focus();
                    return false;
                }
                // return false to cancel submit                  
            }
            // other available options: 
            //url:       url         // override for form's 'action' attribute 
            //type:      type        // 'get' or 'post', override for form's 'method' attribute 
            //dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
            //clearForm: true        // clear all form fields after successful submit 
            //resetForm: true        // reset the form after successful submit 

            // $.ajax options can be used here too, for example: 
            //timeout:   3000 
       }; 
       $(this).ajaxSubmit(options);
       return false;
    });
    
}

var checkLoginResponseReq=function(responseText, statusText, xhr, $form){
    setupFormsHome();
        // set tooltips if needed
    $('.qtiperror',"#myformLoginReq").each( function(index,element){
            
            
            $(this).qtip({
                content: $(this).attr("rel"),
                position: {
                    corner: {
                        target: 'rightMiddle',
                        tooltip: 'leftMiddle'
                    }
                },
                style: {
                    border: {
                        width: 1,
                        radius: 3
                    },
                    tip: 'leftMiddle',
                    name: 'red' // Inherit the rest of the attributes from the preset dark style
                   }
            });
    });
    if( responseText.indexOf("REDIRECT-FROM-CONTROLLER") > 0 ){
        window.location.replace($("#redirect_login_req").val().concat($("#tech_req_start").val()));
    }
    
}

var checkLoginResponseOff=function(responseText, statusText, xhr, $form){
    setupFormsHome();
        // set tooltips if needed
    $('.qtiperror',"#myformLoginOff").each( function(index,element){
            
            
            $(this).qtip({
                content: $(this).attr("rel"),
                position: {
                    corner: {
                        target: 'rightMiddle',
                        tooltip: 'leftMiddle'
                    }
                },
                style: {
                    border: {
                        width: 1,
                        radius: 3
                    },
                    tip: 'leftMiddle',
                    name: 'red' // Inherit the rest of the attributes from the preset dark style
                   }
            });
    });
    if( responseText.indexOf("REDIRECT-FROM-CONTROLLER") > 0 ){
        window.location.replace($("#redirect_login_off").val().concat($("#tech_off_start").val()));
    }
    
}

var checkRegisterResponseReq=function(responseText, statusText, xhr, $form){
    setupFormsHome();
    
    // set tooltips if needed
    $('.qtiperror',"#myformRegisterReq").each( function(index,element){
            $(this).qtip({
                content: $(this).attr("rel"),
                position: {
                    corner: {
                        target: 'rightMiddle',
                        tooltip: 'leftMiddle'
                    }
                },
                style: {
                    border: {
                        width: 1,
                        radius: 3
                    },
                    tip: 'leftMiddle',
                    name: 'red' // Inherit the rest of the attributes from the preset dark style
                   }
            });
    });
    if( responseText.indexOf("REDIRECT-FROM-CONTROLLER") > 0 ){
        window.location.replace($("#redirect_register_req").val().concat($("#tech_req_start").val()));
    }
}

var checkRegisterResponseOff=function(responseText, statusText, xhr, $form){
    setupFormsHome();
    
    // set tooltips if needed
    $('.qtiperror',"#myformRegisterOff").each( function(index,element){
            $(this).qtip({
                content: $(this).attr("rel"),
                position: {
                    corner: {
                        target: 'rightMiddle',
                        tooltip: 'leftMiddle'
                    }
                },
                style: {
                    border: {
                        width: 1,
                        radius: 3
                    },
                    tip: 'leftMiddle',
                    name: 'red' // Inherit the rest of the attributes from the preset dark style
                   }
            });
    });
    if( responseText.indexOf("REDIRECT-FROM-CONTROLLER") > 0 ){
        window.location.replace($("#redirect_register_off").val().concat($("#tech_off_start").val()));
    }
}

var setupComingSoon= function(){
    $(".cooming_soon").each(function(){
        var id = $(this).attr("id");
        if($("#"+id+"_content").html() == ""){
            $(this).remove();
        }else{
            $(this).show();
            $(this).qtip({
                content: $("#"+id+"_content").html(),
                position: {
                    corner: {
                        target: 'rightBottom',
                        tooltip: 'topLeft'
                    }
                },
                style: {
                  width: 350,
                  padding: 5,
                    border: {
                        width: 4,
                        radius: 8,
                        color: '#08509a'
                    },
                    tip: 'topLeft',
                    name: 'blue', // Inherit the rest of the attributes from the preset dark style
                    classes: {
                        content: 'myqtipsoon'
                    }
                   }
            });
        }
    })
}

$(document).ready(function(){
    doHelperUI();
    doSliderStart();
    setupFormsHome();
    setupComingSoon();
});



