﻿var poto = window.setTimeout('slide()', 5100);
var gto = window.setTimeout('empty()', 0);
var slideptr = 1;
var sbase = 947;
$(document).ready(function() {
    sbase = $("#slidecontainer").width();
    $("#slidetabs>span.tab").live("click", function() {
        window.clearTimeout(poto);
        var i = $(this).attr("class").substring(2, 3);
        $("#slidetabs>span.tab").removeClass("active");
        $(this).addClass("active");
        slide(i);
    });

    $("form.formwrapper input[type='submit']").live("click", function() {
        var val = $(this).attr("name");
        var entity = $(this).parents("form").find("input[name='formentity']").attr("value");
        clearExamples();
        postForm(entity, val);
        return false;
    });

    $(".releasePop").live("click", function() {
        var tag = $(this).attr("ref");
        if (tag == '' || tag == undefined) { tag = $(this).html() };
        tag = tag.replace("»", "");
        $(".cpop h3").html(tag);
        $.get("emailus.ajax", "target=" + tag + "&" + salt(), popForm);

    });
    $(".cpop span").live("click", function() {
        $(".cpop").hide();
        $(".modal").hide();
    });

    yumyum();
    $(".num").keypress(function(e) { return numbersOnly(e); });
    $("ul.error").live("click", function() { $(this).hide(); });
    setExamples();
    gotfocus();
});

function yumyum() {
    $("input").focus(function() {
        var ex = $(this).attr("example");
        if (ex == $(this).val()) {
            $(this).val("");
            $(this).removeClass("example");

        }
        $("input").removeClass("activef");
        $(this).addClass("activef");
    });
    $("input").blur(function() {
        if ($(this).val() == "") {
            $(this).val($(this).attr("example"));
            $(this).addClass("example");
        }
        $(this).removeClass("activef");
    });
}
function slide(sn) {
    window.clearTimeout(poto);
    if (sn == undefined) {
        slideptr = slideptr + 1
    } else {
    slideptr = sn;
}
    if (slideptr > 4) { slideptr = 1; }

    var margin= (slideptr-1)*sbase;
    var i = slideptr;
    if (i > 3) { i = 1 }
    $("#slides").animate({ marginLeft: -margin + "px" }, 1000, pop);
    $("#slidetabs>span.tab").removeClass("active");
    $(".no" + i).addClass("active");
    };


function pop() {
    poto = window.setTimeout('slide()', 4600);
    if (slideptr > 3) {
        slideptr = 1;
        $("#slides").css("margin-left", "0px");
    }

 }
 function popForm(r) {
     var ra = r.split("||");
     if (ra[0] == "OK") {
         $(".cpop>div").html(ra[1]);
         $(".cpop").centerInClient();
         $(".modal").show();
         $(".cpop").show();
         focus();
     }
 }
 function empty() { }

 function postForm(theToken, val) {
     $("#submitID").css("font-size", ".8em");
     $("#submitID").val("Working...");
     $("#submitID").attr("disabled", "true");

     var f = $("#" + theToken);
     var sf = f.serialize();
     sf += "&submit=" + val;
     sf += salt();
     var action = "formprocessor.aspx";
     $.post(action, sf, pbHandler);
 }
 function pbHandler(r) {
     var ra = r.split("||");
     if ((ra[0] == "OK") || (ra[0] == "HASERRORS")) {
         if ((ra[2].charAt(0) == "@") && (ra[0] == "OK")) {
             window.location.href = ra[2].substr(1) + "?" + ra[1];
         } else {
         var f = "#" + ra[1]
         var chtml = $(f).html();
         $(f).remove();
         $("#ieisevil").append(ra[2]);
             //$(f).html(ra[2]);
             //location = f;

             //do we have any options?
             if (ra.length > 3) {
                 var i = ra[3].indexOf('fade')
                 if (i > -1) {
                     gto = window.setTimeout(function() {
                         $(".cpop").hide();
                         $(".modal").hide();
                     }, 6500);
                 }
                    
             }
             setExamples();
             yumyum();
             gotfocus();
         }
     }
     return false;
 }

 function setExamples() {

     $("input").each(function(e) {
         var ex = $(this).attr("example");
         if ($(this).val() == '' || $(this).val() == ex) {
             $(this).val(ex);
             if (ex != '') {$(this).addClass("example"); }
         }
     });
 }

 function clearExamples() {

     $("input").each(function(e) {
         var ex = $(this).attr("example");
         if ($(this).val() == ex) {
             $(this).val('');
             $(this).removeClass("example");
         }
     });
 }
