
$(function() {
    $('.blink').
    focus(function() {if(this.value==this.title) this.value = '';}).
    blur(function() {if(this.value=='') this.value = this.title;}).
    parents('form').submit(function() { // Asure search query is not "search..." or empty string
        var search_field = $(this).find('.blink');
        if(search_field.attr('value')==search_field.attr('title') || search_field.attr('value')=='') {
            alert("Please, enter search query");
            return false;
        }
    });
    
    $('.fontsizectrl a').click(function() {
        var fontsize = this.href.replace(/.*#/, '');
        $(document.body).css({fontSize: fontsize + 'px'});
        set_cookie('fontsize', fontsize, 365, '/');
        return false;
    });
    if(get_cookie('fontsize')) {
        $(document.body).css({fontSize: get_cookie('fontsize') + 'px'});
    }
});
$(function(){
    var hspace_imgs = $('img[hspace]');
    for (var i=0; i<hspace_imgs.length; i++) {
        var img = hspace_imgs[i];
        $(img).css({
            'margin-left': $(img).attr('hspace'),
            'margin-right': $(img).attr('hspace')
        });
    }

    var vspace_imgs = $('img[vspace]');
    for (var i=0; i<vspace_imgs.length; i++) {
        var img = vspace_imgs[i];
        $(img).css({
            'margin-top': $(img).attr('vspace'),
            'margin-bottom': $(img).attr('vspace')
        });
    }    
});
function set_cookie(cookieName, cookieValue, expires, refreshPage) {
  expires = expires || 365;
  refreshPage = refreshPage || false;
  var cookie = {name: cookieName, value: cookieValue, lifeTime: expires, path: '/'};
  var expires_date = new Date( (new Date).getTime() + (cookie.lifeTime * 1000 * 60 * 60 * 24) );
  document.cookie = cookie.name + "=" + escape( cookie.value ) + ";expires=" + expires_date.toGMTString() + ";path=" + cookie.path;
}
function get_cookie( check_name ) {
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false;
	for ( i = 0; i < a_all_cookies.length; i++ ) {
		a_temp_cookie = a_all_cookies[i].split( '=' );
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
		if ( cookie_name == check_name ) {
			b_cookie_found = true;
			if ( a_temp_cookie.length > 1 ) {
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			return cookie_value;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found ) {
		return null;
	}
}		
