jQuery.extend({ URLEncode: function(c) {
    var o = ''; var x = 0; c = c.toString(); var r = /(^[a-zA-Z0-9_.]*)/;
    while (x < c.length) {
        var m = r.exec(c.substr(x));
        if (m != null && m.length > 1 && m[1] != '') {
            o += m[1]; x += m[1].length;
        } else {
            if (c[x] == ' ') o += '+'; else {
                var d = c.charCodeAt(x); var h = d.toString(16);
                o += '%' + (h.length < 2 ? '0' : '') + h.toUpperCase();
            } x++;
        } 
    } return o;
},
    URLDecode: function(s) {
        var o = s; var binVal, t; var r = /(%[^%]{2})/;
        while ((m = r.exec(o)) != null && m.length > 1 && m[1] != '') {
            b = parseInt(m[1].substr(1), 16);
            t = String.fromCharCode(b); o = o.replace(m[1], t);
        } return o;
    }
});


jQuery('.lnk-bookmark a').click(function(evt) {
    evt.preventDefault();
    var bookmarkUrl = this.href;
    var bookmarkTitle = this.title;

    bookmarkUrl = window.location;
    bookmarkTitle = document.title;

    if (window.sidebar) {
        window.sidebar.addPanel(bookmarkTitle, bookmarkUrl, "");
    }
    else if (window.external || document.all) {
        window.external.AddFavorite(bookmarkUrl, bookmarkTitle);
    }
    else if (window.opera) {
        jQuery("a.jQueryBookmark").attr("href", bookmarkUrl);
        jQuery("a.jQueryBookmark").attr("title", bookmarkTitle);
        jQuery("a.jQueryBookmark").attr("rel", "sidebar");
    }
    else {
        alert('Your browser does not support this bookmark action');
        return false;
    }
});
jQuery('.lnk-print a').click(function(evt) {
    evt.preventDefault();
    window.print();
//    alert('print clicked');
});
jQuery('.side-nav > li a').click(function() {
	
	if ( jQuery(this).parent().length > 0 ) {
//		alert('true');
	}
//	else{alert('false')};
	
	jQuery(this).parent().parent().toggleClass("active");
});
jQuery('.side-nav > li a span').click(function() {
    //	alert('span clicked');
});
jQuery('.popup-hold .hold a').click(function()	{
	jQuery(this).parent().parent().parent().parent().parent().find('.modal-close .close').click();
});

/*
jQuery('.search-box .form-actions .submit-search').click(function(evt) {
    evt.preventDefault();
    window.location = '/searchresults.aspx?term=' + jQuery('#search-box').val();
});
*/




jQuery('.lnk-share').click(function()	{
    jQuery('.popup-hold').removeClass("error-message").removeClass("success-message");
    if (!jQuery('#share-page .popup-hold').hasClass('form-shown')) {
		jQuery('.popup-hold').toggleClass("form-shown");
		jQuery('#share-youremail').val('Enter your email address');
		jQuery('#share-toemail').val('Email Address');
		jQuery('#share-message').val('');
	}
});
/*
jQuery('#share-page .form-actions .action-submit').click(function()	{
	submitSharePage(this);
});
*/


jQuery('.bar li a').click(function(evt)
{
    evt.preventDefault();
    cycleBillboards(this);
});
window.aVal = 1;

var cycleBillboards = function(element)
{
	currentVal = window.aVal;
	aVal = jQuery(element).html();
	jQuery('.bar li').removeClass('active');
	jQuery('.bar li a:eq(' + (aVal - 1) + ')').parent().addClass("active");
	jQuery('.page').removeClass('careers' + currentVal).addClass('careers' + aVal);
	window.aVal = aVal;
};


var submitSharePage = function(element) {
    jQuery('.popup-hold').toggleClass("form-shown");
    setTimeout("jQuery('.popup-hold').parent().parent().parent().parent().find('.modal-close .close').click()", 3000)
};
jQuery('#share-page .form-actions .submit-btn').click(function(evt) {
    evt.preventDefault();
    //    alert('submitting share form');
    pageToPost = 'controls/share_handler.ashx';
//    alert(window.location);
    jQuery.post(pageToPost, {
        youremail: jQuery("#shareyouremail").val(),
        toemail: jQuery("#sharetoemail").val(),
        message: jQuery("#sharemessage").val(),
        pageurl: jQuery.URLEncode(window.location),
        pagename: document.title
        
    },
        function(response) {
            //jQuery('#content-write').html(response);
            //alert('RESPONSE\n' + response);
            if (response == 'success') {
                jQuery('.popup-hold').toggleClass("form-shown");
                jQuery('.popup-hold').toggleClass("success-message");
                setTimeout("jQuery('.popup-hold').parent().parent().parent().parent().find('.modal-close .close').click()", 3000)
            }
            else {
                jQuery('.popup-hold').toggleClass("form-shown");
                jQuery('.popup-hold').toggleClass("error-message");
                setTimeout("jQuery('.popup-hold').parent().parent().parent().parent().find('.modal-close .close').click()", 3000)
            }
        });
});
jQuery('#test-form-submit').click(function(evt) {
//jQuery('.form-actions input:submit').click(function(evt) {
//    alert('a');
    evt.preventDefault();
    //alert('test-form');
    var firstname = jQuery('#firstname').val();
    var middlename = jQuery('#middlename').val();

    querystring = 'firstname=' + firstname + '&';
    querystring += 'middlename=' + middlename + '&';
    //alert('querystring: ' + querystring);
    jQuery.ajax({
        type: "POST",
        url: "controls/test_handler.ashx",
        data: "{'firstname':'" + firstname + "','middlename':'" + middlename + "'}",
        contentType: "application/json; charset=utf-8",
        //dataType: "json",
        success: function(response) {
            //alert('posted');
        }
    });

});
var options = {
    method: 'POST',
    url: 'controls/test_handler.ashx',
    data: "{'firstname':'brian','middlename':'christopher'}",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    after: function(response) {
        alert(response);
    }
};



