// JavaScript Document
function showBlock(blockID){
	if(document.getElementById(blockID).style.display=='block'){	
		document.getElementById(blockID).style.display='none';	
	}else{
		document.getElementById(blockID).style.display='block';		
	}
}
function showBlockz(blockID){
	if(document.getElementById(blockID).style.display=='table'){
		document.getElementById(blockID).style.display='none';	
	}else{
		document.getElementById(blockID).style.display='table';
	}
}
function showBlock2(blockID){
	var elem = document.getElementById(blockID);
	if(elem){
		elem.style.display='block';	
	}	
}
function hideBlock(blockID){
	var elem = document.getElementById(blockID);
	if(elem){
		elem.style.display='none';	
	}	
}

function doVote(voteID,voteVal){

        JsHttpRequest.query(
            '/ajaxvote.php', // backend
            {
                'voteID': voteID,
				'ans':voteVal			
            },
            function(result, errors) {
                if (result) {
					if(result["q"]=="no_error"){
					document.getElementById("voteMe").innerHTML=""+result["ans"]+"";
					}
                }
            },
            false  // do not disable caching
        )

}

function doCheckfield(voteID){
if(voteID=='username'){
var fillID='reg_usernamecheckitvalue';	
var type='username';
var valu=document.getElementById('reg_username').value;

}else{
var fillID='reg_emailcheckitvalue';	
var type='email';
var valu=document.getElementById('reg_email').value;

}
        JsHttpRequest.query(
            '/ajaxlogin2.php', // backend
            {
				'name':valu,
                'type':voteID ,
				'checkfield':'1'		
            },
            function(result, errors) {
				//alert(errors);
                if (result) {
					//alert(result['q']);
					if(result["q"]=="no_error"){
						$('#'+fillID).html('<span style="color:#0db100">Ok</span>');
					}else{
						$('#'+fillID).html('<span style="color:red">'+result['mess']+'</span>');
					}
                }
            },
            false  // do not disable caching
        )

}

function senditTomyFriend(){
	if($('#s_emailm')){
		var emval = $('#s_emailm').val();
	}else{
		var emval = '';
	}
	JsHttpRequest.query(
	'/ajaxsend.php', // backend
	{
		'link_id': $('#s_id').val(),
		'email': $('#s_email').val(),
		'mess': $('#s_text').val(),
		'emailm': emval,
		'sendtofriend':'1'
					
	},
	function(result, errors) {
		//alert(errors);
		if (result) {
			if(result["q"]){
				var whatis=$('#showsendto').html();
				$('#showsendto').htlm('<BR><BR><BR><center>'+result['q']+'</center>');
				
				setTimeout(function (){
					$('#showsendto').hide();
					$('#showsendto').html(whatis);
									 },2000);
			//$('notilink').innerHTML=""+result["q"]+"";
			}
		}
	},
	false  // do not disable caching
)
}

function doNotify(link_id){

        JsHttpRequest.query(
            '/ajaxnotify.php', // backend
            {
                'link_id': link_id
							
            },
            function(result, errors) {
                if (result) {
					if(result["q"]){
					$('#notilink').html(""+result["q"]+"");
					}
                }
            },
            false  // do not disable caching
        )

}
function doNotNotify(link_id){

        JsHttpRequest.query(
            '/ajaxnotify.php', // backend
            {
                'link_id': link_id,
				'not':'no'
							
            },
            function(result, errors) {
                if (result) {
					if(result["q"]){
					$('#notilink').html(""+result["q"]+"");
					}
                }
            },
            false  // do not disable caching
        )

}

function getSubscriptionAnswerText(result_code) {
	switch (result_code) {
		case 'OK_SUBSCRIBED': return 'Du er nu tilmeldt vores nyhedsbrev';
		case 'OK_CONFIRM_SUBSCRIPTION': return 'Tak for din tilmelding til vores nyhedsbrev. Din emailadresse skal bekræftes før du kan modtage nyhedsbrevet. Vi har sendt dig en email med instrukser, som du blot skal følge. På forhånd tak.';
		case 'ERR_EXISTS': return 'Denne emailadresse er allerede tilmeldt nyhedsbrevet';
		case 'OK_UNSUBSCRIBE': return 'Du er nu blevet frameldt vores nyhedsbrev';
		case 'ERR_DON_EXIST': return 'Denne email er ikke tilmeldt vores nyhedsbrev';
		case 'ERR_INVALID_EMAIL': return 'Emailadressen er ikke gyldig';
		default: throw 'Invalid result: ' + result_code;
	}
}

function subscribe(form){
	var params = $(form).serializeArray();
	params.push({name: 'type', value: '1'});
	$.post('/ajaxsub.php', params, function(result, text, xhr) {
		if (xhr.status)
			$("#messagesub").text(getSubscriptionAnswerText(result["ans"]));
	});
}
function unsubscribe(form){
  JsHttpRequest.query(
            '/ajaxsub.php', // backend
            {
                'email': form.elements.youremail.value,
				'type':'2'	
            },
            // Function is called when an answer arrives. 
            function(result, errors) {
                if (result) {
                    $("#messagesub").text(getSubscriptionAnswerText(result["ans"]));
                }
            },
            false  // do not disable caching
        )
}

function sendInvitations(){

  JsHttpRequest.query(
            '/ajaxinvite.php', // backend
            {
                'name': $('name').value,
				'safe_name':$('safe_name').value,
				'group_mailer':$('group_mailer').value	
            },
            // Function is called when an answer arrives. 
            function(result, errors) {
			//alert(errors);
             //   if (result) {
					$("messinv").innerHTML = "TAK!";
					$('name').value='';
					$('safe_name').value='';
					$('group_mailer').value='';
					window.location.reload();
					//setTimeout(showBlock,1000,'invitef');
             //   }
            },
            false  // do not disable caching
        )
}



function sendBug(){
var mozno="da";
$('#bugmess').css("border", '');
var bugtype=$('#bugtype').val();
var bugmess=$('#bugmess').val();
var pageloc=window.location;
var browser_info=$('#browser_info').val();
if($('#user_l_id').val()!='' && $('#user_l_id').val()!='0' ){
	var userID=$('#user_l_id').val();
	var userName=$('#user_l_login').val();
}else{
	var bugemail=$('#bugemail').val();
	$('#bugemail').css('border', '');
		if(bugemail=='' || bugemail=='your@email.com'){
			mozno="ne";
			$('#bugemail').css('border', '3px solid #e30121');
		}
}
if(bugmess==''){
	$('#bugmess').css('border', '3px solid #e30121');
	mozno="ne";
}

if(mozno=="da"){
	 JsHttpRequest.query(
				'/ajaxbug.php', // backend
				{
					'bugtype':bugtype,
					'bugmess':bugmess,
					'pageloc':pageloc,
					'browser_info':browser_info,
					'userID':userID,
					'userName':userName,
					'bugemail':bugemail
				},
				// Function is called when an answer arrives. 
				function(result, errors) {
				///alert(errors);
					if (result) {
					$('#bugboxinfo').html('<center>Tak for din tilbagemelding, vi vender tilbage hurtigst muligt</center>');
					setTimeout(function(){
					hideBlock('bugbox');
					$('#bugmess').val('');
					$('#bugboxinfo').html('');
					},1000);
					}
				},
				false  // do not disable caching
			)
	}
}

function sendMessage(){
var mozno="da";
$('#sendmess').css('border', '');
var bugtype=$('#sendtype').val();
var bugmess=$('#sendmess').val();
var pageloc=window.location;
var browser_info=$('#browser_info').val();
if(bugmess==''){
	$('#sendmess').css('border', '3px solid #e30121');
	mozno="ne";
}

if(mozno=="da"){
	 JsHttpRequest.query(
				'/ajaxsend.php', // backend
				{
					'sendtype':bugtype,
					'sendmess':bugmess,
					'pageloc':pageloc,
					'browser_info':browser_info
				},
				// Function is called when an answer arrives. 
				function(result, errors) {
				//alert(errors);
					if (result) {
						
					$('#sendboxinfo').html('<center>Tak for din tilbagemelding, vi vender tilbage hurtigst muligt</center>');
					}
				},
				false  // do not disable caching
			)
	}

}




function checkusers(val){
if(val.length>2){
var mozno='da';	
}
if(mozno=="da"){
	$('#m_user_id').html('loading');
	 JsHttpRequest.query(
				'/ajaxlogin2.php', // backend
				{
					'username':val,
					'getusernames':'1'
				},
				// Function is called when an answer arrives. 
				function(result, errors) {
				///alert(errors);
					if (result) {
					$('#m_user_id').html(result["q"]);
					}
				},
				false  // do not disable caching
			)
	}
}

function deleteFunction(delText,navwhere){
	if (confirm(delText)) {window.location=navwhere;}
}

