$.fn.centerit = function(show) { var windowHeight = $(window).height(); var contentHeight = $(this).height(); var windowWidth = $(window).width(); var contentWidth = $(this).width(); if(windowHeight > 0 && windowWidth > 0) { var centerTop = ((windowHeight / 2) - (contentHeight / 2)); var centerLeft = ((windowWidth / 2) - (contentWidth / 2)); $(this).css("position", "fixed"); $(this).css("top", centerTop); $(this).css("left", centerLeft); if(typeof(show) != "undefined" && show == true) $(this).css("display", "block"); } else { $(this).css("position", "static"); } return this; }; //checks for control + shift + ?? key combinations $.ctrlCombo = function(key, callback, args) { //attach even handler to the document on a keydown event $(document.documentElement).keydown(function (event) { // handle cursor keys if(!args) args=[]; //IE fluke //check if the specified key and control key is down if (event.keyCode == key.charCodeAt(0) && event.ctrlKey && event.shiftKey) { //call the callback code callback.apply(this, args); return false; } }); }; $.admin = function(showKey, hideKey) { var isAdmin = false; //admin panel is hiden by default, this will put opacity to 0 $("#admin_login").animate({opacity:0.0}, 1).hide(); //show admin panel event $.ctrlCombo(showKey, function() { doAdmin(); }); //hide admin panel event $.ctrlCombo(hideKey, function() { undoAdmin(); }); var doAdmin = function() { if(!isAdmin) { $("#admin_login").animate({opacity:1.0}, 1000).show(); isAdmin = true; } } var undoAdmin = function() { if(isAdmin) { $("#admin_login").animate({opacity:0.0}, 1000).hide(); isAdmin = false; } } } $(document).ready(function() { //control + shift + a to show admin panel //control + shift + x to hide admin panel $.admin('A', 'X'); //ajax request to check if admin is logged in $.ajax( { type: "POST", url: "/users/checkadmin", data: "", dataType: "html", error: function(XMLHttpRequest, textStatus, errorThrown) { }, success: function(str) { if(str == "TRUE") { doAdmin(); } } }); $("#ContactForm").submit(function() { var name = $("#ContactForm input[name='data[Contactus][name]']").val(); var phone = $("#ContactForm input[name='data[Contactus][phone]']").val(); var msg = ""; if(name == "Name:" || name == "") msg += "Please enter your name.\n"; if(phone == "Phone:" || phone == "") msg += "Please enter your phone number.\n"; if(msg.length > 0) { alert(msg); return false; } return true; }); //contact us form message box limit $("textarea.textbox_limit").each(function() { //remove the textbox_limit class $(this).removeClass("textbox_limit"); //the next class in the textbox should be the numerical number of the limit for the box var limit = parseInt($(this).attr("class")) - 1; //after finding the limit from the class, add the textbox_limit classs back on $(this).addClass("textbox_limit"); //capture the keydown on the text box $(this).keydown(function(event) { //get the texbox length var textLen = $(this).val().length; //if textbox length exceeds the limit and backspace was not pressed, prevent key from being entered into textbox if(textLen > limit && event.keyCode != '8') { event.preventDefault(); } }); }); });