function openApp(urlToOpen, height, width) {
	MM_openBrWindow(urlToOpen,'Rebicare','scrollbars=no,resizable=no,width='+ width+',height='+height+',screenX=200,screenY=50');
}


function showNews(serverNameWithPort, url, page, newsCategory)  
{  
	if(newsCategory!=''&&newsCategory!='none'){
		document.getElementById("newsCategory").value = newsCategory;
	}else{
		if (document.getElementById("newsCategory").value != ''){
			newsCategory = document.getElementById("newsCategory").value;
		}else{
			document.getElementById("newsCategory").value = 'all';
		}
		
	}
	
	newsCategory = document.getElementById("newsCategory").value;

    $('#newsOverview').load('http://'+ serverNameWithPort+'/'+url+'?page='+ page+'&newsCategory='+ newsCategory);
}

function virtuallibrary(serverNameWithPort, url, docCategory, idForChange, newCat)
{
    $('#virutalLibrary').load('http://'+ serverNameWithPort+'/'+url+'?docCategory='+ docCategory);
    $("#"+idForChange).html(newCat);
}


function changeForm()
{
    if(($("#hcptype").val() == 'Nurse') || ($("#hcptype").val() == 'nurse')){
        $("#pcn").parent().hide();
    	$("#pcn").val('null');
    }
    
    if(($("#hcptype").val() == 'Pharmacist') || ($("#hcptype").val() == 'pharmacist')){
        $("#pcn").parent().show();
    	$("#pcn").val('');
    }
    
     if(($("#hcptype").val() == 'Doctor') || ($("#hcptype").val() == 'doctor')){
        $("#pcn").parent().show();
    	$("#pcn").val('');
    }
}

function openWindow(url,width,height,scroll,name,anchor)
{
	//default scrollbars=no;
	if(scroll=='') {
		scroll = 'no';
	}

	url = url + (anchor !== undefined ? anchor : "");
	popWindow = window.open(url,name,"toolbar=no,width="+width+",height="+height+",status=yes,scrollbars="+scroll+",resizable=no,menubar=no,dependent=no");
}

(function($) {
// initialize faq lists
$.fn.faqList = function(options) {
	
	var settings = $.extend({
		questionTags: "dt", // any jQuery selector possible, you can also use span.question, div.title, etc.
		answerTags: "dd .answer-holder",
		animationSpeed: 400
	}, options);


	this.each(function(i, v) {
		var l = $(this);
		var answers = l.find(settings.answerTags).hide();
		
		l.find(settings.questionTags).each(function(i, v) {
			$(this).wrapInner("<a href='#'></a>").find("> a").click(function() {
				l.find(settings.answerTags + ":visible").slideUp(settings.animationSpeed);
				l.find(settings.questionTags + " > a.open").removeClass("open").addClass("closed");
				if (!answers.eq(i).is(":visible")) {
					$(this).removeClass("closed").addClass("open");
					answers.eq(i).slideDown(settings.animationSpeed);
				}
				return false;
			}).addClass("closed");
		});
	});
};

$(document).ready(function() {
	
	$("#faq").faqList();
	
	$('input').keypress(function(evt){
	    evt.stopPropagation();
	    if(evt.keyCode == 13) {	    
	        $(this.form).submit();
	    }
	});
	
	if (typeof $.fn.datepick == "function") {
		$(".form_element_datefield").datepick({
			buttonImageOnly: true,
			buttonImage: '/designs/merck_serono_rebicare/httpd/img/layout/date-picker.png',
			changeYear: false,
			changeMonth: false,
			showOn: 'button',
			showBigPrevNext: true,
			showPrevNext: true,
			showStatus: true
			});
	}
	
	if (typeof $.fn.combobox == "function") {
		var options = {
			comboboxContainerClass: "comboboxContainer",
			comboboxValueContentContainerClass: "comboboxValueContainer",
			comboboxValueContentClass: "comboboxValueContent",
			comboboxDropDownClass: "comboboxDropDownContainer",
			comboboxDropDownButtonClass: "comboboxDropDownButton",
			comboboxDropDownItemClass: "comboboxItem",
			comboboxDropDownItemHoverClass: "comboboxItemHover",
			comboboxDropDownGroupItemHeaderClass: "comboboxGroupItemHeader",
			comboboxDropDownGroupItemContainerClass: "comboboxGroupItemContainer"
		};
		
		$("select.jq-combobox").combobox(options, {
			animationSpeed: 100,
			width: "source",
			animationType: "slide"
		});
			
	}
	
	/* sitemap */
	
	$(".sitemap ul li").addClass("open").find("> a:first").click(function() {
		
		if ($(this).parent().find("ul").size() == 0) {
			return;
		}
		
		var t = $(this).parent();
		if (t.hasClass("closed")) {
			t.removeClass("closed");
		} else {
			t.addClass("closed");
		}
		return false;
	});
	
	/* dropdowns - add further id's comma seperated to string*/
	if ($.fn.initDropdown) {
		$(".gui-select").initDropdown();
		$("form").each(function(){
			this.onreset = function() {
				for(var i=0,item;item = $.allJMMDropDowns[i];i++) {
					if(item.wrapper.parents("form")[0] == $(this)[0]) {
						// todo reset hidden input field
						if(item._activeElement != null) item.reset();
					}
				}
			}
		});
	}
});

})(jQuery);

