$(document).ready(function() {
	// Country drop down
	$("#cc").bind("mouseenter mouseleave", function(e) {
		$("#countries").slideToggle("slow");
	});
	$("div.box_sx h3").bind("click", function(e) {
		// cerco il nome del box da aprire...
	    var find = $(this).attr("class");
	    find = find.substring(0,find.indexOf(" "));
	    if (find!='reg'){ //escluso box di registrazione
		   	// switch classe per icona exp/coll
		    $(this).toggleClass("exp");
		    $(this).toggleClass("col");
		    // toggle visualizzazione 
	    	$("ul#" + find).toggle("slow");
	    }
	});
	$("#more").bind("click",function(e){
		$("#morePanel").toggle("slow");
		$("#more").hide();
		$("#fewer").show();
	});
	$("#fewer").bind("click",function(e){
		$("#morePanel").toggle("slow");
		$("#fewer").hide();
		$("#more").show();
	});
	$('input[name=cmp]').autocomplete('/srvc/companies.php',{loadingClass:'ac_loading'});
	$('input[name=src]').autocomplete('/srvc/sources.php',{ loadingClass:'ac_loading',minChars:1,autoFill:true,delay:200});
	$('input[name=where]').autocomplete('/srvc/places.php',{ loadingClass:'ac_loading',minChars:3,autoFill:true,delay:200});
	$('input[name=kwd]').autocomplete('/srvc/key.php',{ loadingClass:'ac_loading',cacheLength:0,minChars:3,autoFill:true,delay:200});
 });

var options = { domain:'.jobscatalog-canada.com', path: '/'}

function getCookie(name) {
	return $.cookie(name);
}
function deleteCookie(name, path, domain) {
	$.cookie(name, null, options);
}

jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
