// JavaScript Document
function switchTab(id_block)
{
	if ( $('#'+id_block).css('display') == 'block' ) {
		$('#'+id_block).hide();
	} else {
		$('#'+id_block).show();
	}
}

function switchTabs(off_link, h_div, on_link, s_div, classname)
{
	$('#'+on_link).addClass(classname);
	$('#'+off_link).removeClass();
	$('#'+h_div).hide();
	$('#'+s_div).show();
}

function ShowHideMenu(is_show, id_menu, id_dd)
{
	if(is_show == 1){
		$('#'+id_dd).show(); 
		$('#'+id_menu).removeClass();
		$('#'+id_menu).addClass('mm-active');
	}else{
		$('#'+id_dd).hide(); 
		$('#'+id_menu).removeClass();
		$('#'+id_menu).addClass('mm');
	}
}

function changeLink()
{
	if(this.id == 'img_1'){
		$('#links_1').show();
		$('#links_2, #links_3, #links_4, #links_5').hide();
	}else if(this.id == 'img_2'){
		$('#links_2').show();
		$('#links_1, #links_3, #links_4, #links_5').hide();
	}else if(this.id == 'img_3'){
		$('#links_3').show();
		$('#links_2, #links_1, #links_4, #links_5').hide();
	}else if(this.id == 'img_4'){
		$('#links_4').show();
		$('#links_2, #links_3, #links_1, #links_5').hide();
	}else if(this.id == 'img_5'){
		$('#links_5').show();
		$('#links_2, #links_3, #links_4, #links_1').hide();
	}
}

function getText(id_from, id_where)
{
	var text      = $('#'+id_from).html();
	var user_text = $('#'+id_where).html();
	
	text = jQuery.trim(text);
	
	$('#'+id_where).html(user_text+'[quote]'+text+'[/quote]');
}

function showForm(id_show, id_hide, spec_param)
{
	$('#'+id_hide).hide('slow');
	$('#'+id_show).show('slow');
}

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 eraseCookie(name) 
{
	createCookie(name,"",-1);
}

function makeTabActive(id_on, id_off, redirect_path)
{
	eraseCookie(id_off);
	eraseCookie(id_on);
	
	createCookie(id_on, 1, 1);
	window.location = redirect_path;
}

function editQuestion(id_answer, id_textfield)
{
	$('#'+id_textfield).removeClass();
	$('#'+id_textfield).addClass('va-textarea2_l');
	$('#'+id_textfield).attr("disabled", true);
	var new_text = $('#'+id_textfield).val();
	$.post(
			"/specialist/editanswer/id_answer/"+id_answer+"/", 
			{ answer_text : new_text },
			function(data){
				if(data){
					$('#edit-form-'+id_answer).hide('slow');
					$('#vci-text-'+id_answer).html(new_text);
					$('#edit-'+id_answer).show();
					$('#'+id_textfield).attr("disabled", false);
					$('#'+id_textfield).removeClass();
					$('#'+id_textfield).addClass('va-textarea2');
				}else{
				 alert('error');
				}
			});
}

var modalWindow = {
		parent:   "body",
		windowId: null,
		content:  null,
		width:    null,
		height:   null,
		close:    function()
		{
			$("#modal-overlay").remove();
			$("#"+this.windowId).remove();
			
		},
		open:function()
		{
			var modal = "";
			modal += "<div id=\"modal-overlay\" class=\"modal-overlay\">&nbsp;</div>";
			modal += "<div id=\"" + this.windowId + "\" class=\"modal-window\" style=\"width:" + this.width + "px; height:" + this.height + "px; margin-top:-" + (this.height / 2) + "px; margin-left:-" + (this.width / 2) + "px;\">";
			modal += this.content;
			modal += "</div>";	

			$(this.parent).append(modal);

			$(".modal-window").append("<a class=\"close-window\"></a>");
			$(".close-window").click(function(){modalWindow.close();});
			$(".modal-overlay").click(function(){modalWindow.close();});
		}
	};

	var openMyModal = function(source)
	{
		modalWindow.windowId = "myModal";
		modalWindow.width = 700;
		modalWindow.height = 700;
		modalWindow.content = "<iframe width='700' height='700' align='middle'  frameborder='0' scrolling='no' allowtransparency='true' src='" + source + "'></iframe>";
		modalWindow.open();
	};

	var closeMyModal = function(id)
	{
		modalWindow.windowId = id;
		modalWindow.close();
	};
