/* Convert string to number format */
function numberFormat(nStr)
{
  nStr += '';
  x = nStr.split('.');
  x1 = x[0];
  x2 = x.length > 1 ? '.' + x[1] : '';
  var rgx = /(\d+)(\d{3})/;
  while (rgx.test(x1)) {
    x1 = x1.replace(rgx, '$1' + ',' + '$2');
  }
  return x1 + x2;
}

var selectedMenuItem = null;
var t = null;
var sRoleForInvite = 'Hobbyist';

function setCookie (name, value, expires, path, domain, secure) {
      document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function getCookie(name) {
	var cookie = " " + document.cookie;
	var search = " " + name + "=";
	var setStr = null;
	var offset = 0;
	var end = 0;
    
	if (cookie.length > 0) {
		offset = cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) {
				end = cookie.length;
			}
			setStr = unescape(cookie.substring(offset, end));
		}
	}
	return(setStr);
}


$(document).ready(function () {

    $('.js_search_by_name').focus (function() { $(this).addClass('focus'); } );
    $('.js_search_by_name').blur (function() { $(this).removeClass('focus'); } );

//    selectedMenuItem = $('a.active');

//    $('div.submenu').map(function(){
//        $(this).children(':last').addClass("last");
//    });

//    $('.tab').hover(
//        function () {
//            clearTimeout(t);
//            hideMenu();
////            var oSubmenu = $(this).children('div.submenu');
//
//            $(this).children('a').addClass('active');
//
////            if(oSubmenu.length) {
////                oSubmenu.stop(true, true)
////                .show();
////            }
//        }
//    );

//    $('.tab div.submenu').hover(function () {return false});

    $('.registred_pads .pads').click(function() {
        prevPad = $('.registred_pads > div.active');
        prevPad.removeClass('active');
        $(this).addClass('active');

        $('div.reg_tab.active').removeClass('active');

        switch ($(this).text()) {
        case 'Escorts':
            sRoleForInvite = 'Escort';
            $('#js_escort_tab').addClass('active');
            break;

        case 'Assistants':
            sRoleForInvite = 'Agency-Assistant';
            $('#js_assistant_tab').addClass('active');
            break;

        case 'Hobbyists':
        default:
            sRoleForInvite = 'Hobbyist';
            $('#js_hobbyist_tab').addClass('active');
            break;
        }
    });

    $('#js_get_invite').click(function() {
        location.assign('/get-invite/'+sRoleForInvite);
    });

    $('#js_btn_register').click(function(){
        $('#js_show_get_invite_filter').click();
        return false;
    });



    if ($('#search_by_name').val().length > 0) {
        $('#search_by_name').addClass('filled');

    } else {
        $('#search_by_name').removeClass('filled');
        $('#search_by_name').addClass('with_caption');
    }
    
    $('#search_by_name').blur(function() {
        if ($(this).val().length > 0) {
            $(this).addClass('filled');
        } else {
            $(this).removeClass('filled');
            $(this).addClass('with_caption');
        }
    });
    
});

//function returnSelection () {
//    clearTimeout(t);
//
//    hideMenu();
//    var oSubmenu = selectedMenuItem.parent().children('div.submenu');
//
//    selectedMenuItem.addClass('active');
//    oSubmenu.show();
//}

//function hideMenu() {
//    var oMainmenu = $('div.tab').children('a.active');
////    var oSubmenu = oMainmenu.parent().children('div.submenu');
////
////    oSubmenu.stop(true, true)
////        .removeClass('display_block')
////        .hide();
////
//    oMainmenu.removeClass('active');
//}



