jQuery(document).ready(function() {
    jQuery.jGrowl.defaults.position = "center";
    jQuery.jGrowl.defaults.life = 4000;
    jQuery(".srchtxt").search();
	jQuery("#multisearch").search();
});

function gSearch() {
    
    popUpColorBoxIframe("http://sermitsiaq.ag/template/ver3-0/direct/search/gSearch.jsp?q=" + document.getElementById("googleq").value, 800, 600);
	
    return false;
    
}

function changeLanguage(lang, returnUrl, title, description) {
    createCookie("lang", lang, 365);
    jQuery.jGrowl(description, {
        header: title,
        beforeClose: function() {
            location.href = returnUrl;
        }                
    
    }); 
}



function popUpColorBoxIframe(url, width, height) {
    jQuery.fn.colorbox({
    width:width,
    height:height,
    iframe:true,
	href:url,
    open:true
    });
    return false;
}


function popUpColorBox(html, width, height) {
    jQuery.fn.colorbox({
    width:width,
    height:height,
    html:html,
    open:true
    });
    return false;
}

function popUpColorBoxInline(sel, width, height) {
    jQuery.fn.colorbox({
    width:width,
    height:height,
    inline:true,
    href:sel,
    open:true
    });
    return false;
}



function pickCity(city, returnUrl, title, description) {
    createCookie("sermcity", city, 365);
    jQuery.fn.colorbox.close();
    
    jQuery.jGrowl(description, {
        header: title,
        beforeClose: function() {
            location.href = returnUrl;
        }                
    
    }); 
  
}

function getExtNewsFeed(provider, url, sel) {

    jQuery.get(url, function(data) {
        jQuery(sel).html(data);
    });

}


function changeLocation(loc) {
    createCookie("XXXloc", loc, 365);
}


jQuery.fn.search = function() {
    return this.focus(function() {
		if( this.value == this.defaultValue ) {
			this.value = "";
		}
	}).blur(function() {
		if( !this.value.length ) {
			this.value = this.defaultValue;
		}
	});
};


function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}


function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}


function eraseCookie(name) {
	createCookie(name,"",-1);
}

function initMenus() {
	$('ul.menu ul').hide();
	$.each($('ul.menu'), function(){
		$('#' + this.id + '.expandfirst ul:first').show();
	});
	$('ul.menu li a').click(
		function() {
			var checkElement = $(this).next();
			var parent = this.parentNode.parentNode.id;

			if($('#' + parent).hasClass('noaccordion')) {
				$(this).next().slideToggle('normal');
				return false;
			}
			if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
				if($('#' + parent).hasClass('collapsible')) {
					$('#' + parent + ' ul:visible').slideUp('normal');
				}
				return false;
			}
			if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
				$('#' + parent + ' ul:visible').slideUp('normal');
				checkElement.slideDown('normal');
				return false;
			}
		}
	);
}
$(document).ready(function() {initMenus();});