var changes=0;

function setfancy()
{

			$("a.zoom").fancybox({
				'overlayOpacity'	:	0.7,
				'overlayColor'		:	'#FFF',
				'hideOnContentClick': false,
			    'transitionIn'		: 'elastic',
				'transitionOut'		: 'elastic',
				'easingIn'		    : 'swing',
				'easingOut'		    : 'swing',
				'autoDimensions'    : true,
   				onComplete:function(){

   						setfancy();
						if($("#simple_editor").size()>0) {
   						setTinySimple();
						}
   						tinyMCE.execCommand('mceAddControl',false,'simple_editor');
						if($("#advanced_editor").size()>0) {
   						setTimeout(function(){setTinyAdvanced();tinyMCE.execCommand('mceAddControl',false,'advanced_editor');},50);
						}
						if($("#extra_simple_editor").size()>0) {
   						setTimeout(function(){setTinyExtraSimple();tinyMCE.execCommand('mceAddControl',false,'extra_simple_editor');},50);
						}
						if($("#kurse_editor").size()>0) {
						setTimeout(function(){setTinyKurse();tinyMCE.execCommand('mceAddControl',false,'kurse_editor');},50);
						}
   						setTimeout(function(){$("#fancybox-inner,#fancybox-wrap").height($("#ajax-frame").height()+50)},50);


   				},
				onCleanup:function(){

						tinyMCE.execCommand('mceRemoveControl',false,'simple_editor');

						tinyMCE.execCommand('mceRemoveControl',false,'advanced_editor');

						tinyMCE.execCommand('mceRemoveControl',false,'extra_simple_editor');

						tinyMCE.execCommand('mceRemoveControl',false,'kurse_editor');

						if(changes==1) window.location.reload();

					}});

				$("a[rel=lightbox]").fancybox({
				'autoScale'     	: false,
		        'transitionIn'		: 'fade',
				'transitionOut'		: 'fade',
				'easingIn'		    : 'swing',
				'easingOut'		    : 'swing',
				'cyclic'			: true,
				'opacity'			: false,
				'autoDimensions'    : true,
				'showNavArrows'     : true,
				'titleShow'         : false
	});


}

$(document).ready( function() {

		setfancy();

});

function setTinySimple()
{

tinyMCE.init({
		// General options

		mode: "textareas",

    	editor_selector:"simple_editor",

		theme : "advanced",

		plugins : "safari",

		// Theme options

		plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,visualchars,nonbreaking,xhtmlxtras,template,wordcount",

		theme_advanced_buttons1 : "fontselect,fontsizeselect,bold,italic,underline,bullist,numlist,outdent,indent,link,removeformat",

		theme_advanced_toolbar_location : "bottom",

		theme_advanced_toolbar_align : "left",

		theme_advanced_resizing : false,

		auto_reset_designmode : true,

 		width : "300",

 		height : "100"
		// Drop lists for link/image/media/template dialogs

});

}

var loaded=false;

function setTinyAdvanced()
{

	tinyMCE.init({

		mode: "textareas",

    	editor_selector:"advanced_editor",

		theme : "advanced",

		// Theme options
		plugins : "filemanager,safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,visualchars,nonbreaking,xhtmlxtras,template,wordcount",

		theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,fontselect,fontsizeselect,moveforward,movebackward,absolute,",

		theme_advanced_buttons2 : "cut,copy,paste,|,search,replace,|,bullist,numlist,|,outdent,indent,|,undo,redo,|,link,unlink,image,code,|,forecolor,backcolor",

		theme_advanced_buttons3 : "tablecontrols,|,removeformat,|,sub,sup,|,charmap,iespell,media,advhr,|,print,",

		theme_advanced_toolbar_align : "left",

		theme_advanced_toolbar_location : "top",

		theme_advanced_toolbar_align : "left",

		theme_advanced_resizing : false,

		auto_reset_designmode : true,



		// Example content CSS (should be your site CSS)

 		width : "400",

 		height : "300"

		// Drop lists for link/image/media/template dialogs

	});
}

function setTinyExtraSimple()
{

tinyMCE.init({
		// General options

		mode: "textareas",

    	editor_selector:"extra_simple_editor",

		theme : "advanced",

		plugins : "safari",

		// Theme options

		plugins : "safari,advhr,advlink,iespell,paste,directionality,,,nonbreaking,xhtmlxtras,wordcount",

		theme_advanced_buttons1 : "",

		theme_advanced_toolbar_location : "bottom",

		theme_advanced_toolbar_align : "left",

		theme_advanced_resizing : false,

		auto_reset_designmode : true,

 		width : "300",

 		height : "100"
		// Drop lists for link/image/media/template dialogs

});

}
function setTinyKurse()
{

tinyMCE.init({
		// General options

		mode: "textareas",

    	editor_selector:"simple_editor",

		theme : "advanced",

		plugins : "safari",

		// Theme options

		plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,visualchars,nonbreaking,xhtmlxtras,template,wordcount",

		theme_advanced_buttons1 : "styleselect,italic",

		theme_advanced_toolbar_location : "bottom",

		theme_advanced_toolbar_align : "left",

		theme_advanced_resizing : false,

		auto_reset_designmode : true,

		content_css : "css/tiny.css",

		theme_advanced_source_editor_wrap : false,

 		width : "100",

 		height : "200"
		// Drop lists for link/image/media/template dialogs

});

}


function closefancy() {

	$.fancybox.close();

}

function  IsEmail(email)

{


	var reg = new RegExp(/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/);



   if(reg.test(email) == false)


   {


      return false;


   }


   return true;


}

function check_email (data)

{
	var re = new RegExp("successfully", "gi");

  if (data.match(re)) {
    return true;
  } else {
    return false;
  }

}

function validate_newsletter() {

var checked;

$("input[type=checkbox]:checked").each(

    function() {

       checked=true;
    }
);

 if ($('#name').val()!='' && $('#email').val()!='' && checked)
 	{

 	if(IsEmail($('#email').val()))
 	{
 		$.fancybox.showActivity();

 		return true;
 	}

 	else

 	{
 		window.alert('Email is in wrong format!');

 		$('#email').focus();

 		return false;

 	}
 }

 else

 {
 	if(!checked)

 		{window.alert('Select at least one checkbox!'); }

 	else

 		{window.alert('You must fill all fields');}

 		return false;
 }

}

function message_close(){

	setTimeout(function(){$.fancybox.close();},1000);
}

function message(content){

	$("<a id='testing'></a>").fancybox(
	{'transitionIn': 'fade',
	'transitionOut':'fade',
	'easingIn':'swing',
	'easingOut': 'swing',
	'autoDimensions':true,
	'onComplete':message_close,
	'hideOnOverlayClick':true ,
	'hideOnContentClick':true ,
	'showCloseButton':false,
	'content':"<div style='padding:10px 20px;color:#000'>"+content+"</div>",
	'enableEscapeButton':true}).trigger("click").remove();

}
