function addLoadEvent(func) { var oldonload = window.onload; if (typeof window.onload != 'function') { window.onload = func; } else { window.onload = function() { oldonload(); func(); } } } /** * Add stylesheets and javascript files dynamicly, * but in a way that does not crash IE6 * @see */ function loadjscssfile(filename, filetype) { if (filetype=="js"){ //if filename is a external JavaScript file var fileref=document.createElement('script') fileref.setAttribute("type","text/javascript") fileref.setAttribute("src", filename) } else if (filetype=="css"){ //if filename is an external CSS file var fileref=document.createElement("link") fileref.setAttribute('rel', 'stylesheet'); fileref.setAttribute('type', 'text/css'); fileref.setAttribute('href', filename); } // append the child if (typeof fileref!="undefined") { document.getElementsByTagName("head")[0].appendChild(fileref); } } // since jQuery is required before the script in addLoadEvent, we can't load the script the same way we load the javascript, on // ALSO, we cannot use the loadjscssfile in the HEAD of a document, IE6 crash's since we try to append into an element that is not finished writing document.write(''); document.write(''); addLoadEvent(function(){ loadjscssfile("http://platform.mongooseresearch.com/Client/jquery.fancybox/jquery.fancybox.css", "css"); loadjscssfile("http://platform.mongooseresearch.com/Client/mg-connect.css", "css"); loadjscssfile("http://platform.mongooseresearch.com/Client/mg-connect_org3.css", "css"); // Look for the element that will hold our content. if($("#mg-connect")){ // define our default phone number var default_phone_number = '555-555-1212'; // define urls var frameSource = 'http://platform.mongooseresearch.com/FrontEnd/MobileNumber'; var buttonSource = 'http://platform.mongooseresearch.com/Client/images/btn_next_org3.gif'; // define markup for input box var code = ''; code += ''; code += ''; code += ''; $('#mg-connect').append('
'); $('#mg-mobileinput').append(code); // init the pop-up javascript window $("a.iframe").fancybox({ 'frameWidth': 620, 'frameHeight': 225, 'overlayOpacity': 0.6, 'centerOnScroll': false, 'padding': 0 }); // on focus of our mobile number input box $('#mg-number').focus(function(){ if($('#mg-number').val() == default_phone_number) { // clear the value $(this).val(''); // remove the helper class (the helper class is used for display purposes) $(this).removeClass('helper'); } }); // on blur, if the text field is empty, return the default value to the box, and add our helper class back $('#mg-number').blur(function(){ if($('#mg-number').val() == '') { // add the default value back $(this).val(default_phone_number); // add the helper class $(this).addClass('helper'); } }); // on keypress of the input box for the phone number $('#mg-number').keypress(function(e) { if(e.which == 13){ $('#mg-submit').trigger('click'); } }); // on click event for the sutmit button $('#mg-submit').click(function(e){ e.preventDefault(); // remove the error state if there is one if($('.mg-error')){ $('.mg-error').remove(); } // on submit hide that number if it is the default so we don't submit it if($('#mg-number').val() == default_phone_number){ $('#mg-number').val(''); } // set the iframe url to include the 'm' GET variable to equal the phone number $('#mg-fb-trigger').attr('href', frameSource + '?o=0F66E820-6FD3-480E-B5A7-B911FCDDEA2F&comm=http://www.sjfc.edu/global/files/mg-comm.html&s=Web&m='+$('#mg-number').val()); // check the value to see if it is a valid phone number if(validPhone($('#mg-number').val())){ // trigger events to submit the form $('#mg-fb-trigger').trigger('click'); $('#mg-number').val(''); $('.mg-error').remove(); } else { // not a valid phone number in the input box, add an error message $('#mg-mobileinput').prepend('
Please enter your mobile number in the format: '+default_phone_number+'
'); } }); /** * Validates a phone number * @param {String} A value to be checked as a valid phone number * @return {Boolean} True if a valid phone number, False if not. */ function validPhone(ph) { var stripped = ph.replace(/[\s()+-]|ext\.?/gi, ""); var regPhone = new RegExp(/^\d{10}$/); if (!regPhone.test(stripped)){ return false; } return true; } } }); // these functions are called from the iframe spawned by behaviors.js.aspx // closes the the frame function closeFrame(){ $.fn.fancybox.close(); } // sets the frame height function setFrameHeight(contentHeight){ if(contentHeight > 50){ //alert('change frame height to '+contentHeight); $('#fancy_outer').stop(false,true).animate( {height: contentHeight+"px"}, 500); } }