﻿/* SLIDE DOWN */
function slideDown(eid_OUT, eid_IN, elementSize, speed){
	animate_out(eid_OUT, eid_IN, elementSize, 0, speed);
}
function animate_out(eid_OUT, eid_IN, elementSize, OUT_Position, speed){
	if(OUT_Position < elementSize){
		OUT_Position = parseInt(OUT_Position) + parseInt(speed);
		document.getElementById(eid_OUT).style.top = OUT_Position;
		var t=setTimeout("animate_out('" + eid_OUT + "', '" + eid_IN + "', '" + elementSize + "','" + OUT_Position + "', '" + speed + "')",10);
	} else {
		animate_in(eid_OUT, eid_IN, elementSize, elementSize, speed);
	}
}
function animate_in(eid_OUT, eid_IN, elementSize, IN_Position, speed){
	if(IN_Position > 0){
		IN_Position = parseInt(IN_Position) - parseInt(speed);
		document.getElementById(eid_IN).style.top = IN_Position;
		var t=setTimeout("animate_in('" + eid_OUT + "', '" + eid_IN + "', '" + elementSize + "','" + IN_Position + "', '" + speed + "')",10);
	}
}

/* CHANGE VISIBILITY */
function changeVisibility(eid){
	if(document.getElementById(eid).style.visibility == 'hidden'){
		document.getElementById(eid).style.visibility = 'visible';
		document.getElementById(eid).style.height = 'auto';
		document.getElementById(eid).style.display = 'inline';
	} else {
		document.getElementById(eid).style.visibility = 'hidden';
		document.getElementById(eid).style.height = '0';
		document.getElementById(eid).style.display = 'none';
	}
}

/* HIDE ELEMENT */
function hideElement(eid){
	document.getElementById(eid).style.visibility = 'hidden';
	document.getElementById(eid).style.height = '0px';
	document.getElementById(eid).style.display = 'none';
}

/* HIDE ELEMENT */
function showElement(eid){
	document.getElementById(eid).style.visibility = 'visible';
	document.getElementById(eid).style.height = 'auto';
	document.getElementById(eid).style.display = 'inline';
}

/* CURSOR CHANGE */
function cursor_pointer(){
	document.body.style.cursor = 'pointer';
}
function cursor_auto(){
	document.body.style.cursor = 'auto';
}

/* NEWS */
function news(catName){
	var allButtons = document.getElementById('collectetCats').value.split(';');

	/* SET ACTIVE CAT*/
	document.getElementById('activeCat').value = catName;
	
	/* UNACTIVATE ALL OTHERS*/
	for(i=0; i<allButtons.length-1; i++){
		for(x=1; x<=10; x++){
			document.getElementById(allButtons[i] + '_' + x).style.visibility = 'hidden';
			document.getElementById(allButtons[i] + '_thumb' + x).style.border = '1px solid #777';
			document.getElementById(allButtons[i] + '_thumb' + x).style.margin = '0px 10px 0px 0px';
		}
	}

	/* ALL BUTTONS */
	for(i=0; i<allButtons.length-1; i++){
          document[allButtons[i]].src = 'images/layout/news/buttons/' + allButtons[i] + '.jpg';
	  document.getElementById('content' + allButtons[i]).style.visibility = 'hidden';
	}

	/* SET ACTIVE */
	document[catName].src = 'images/layout/news/buttons/' + catName + '_active.jpg';
	document.getElementById('content' + catName).style.visibility = 'visible';
}

/* NEWS SLIDE */
function newsSlide(count){
  if(document.getElementById('newsSlidePause').value=='false'){
    if(count > 10){ count = 1; }
    newsSlideUnactivateAll();
    newsSlideActive(count);
    count = count + 1;
  }
  setTimeout('newsSlide(' + (count) + ')', 3000);
}

function newsSlideActive(count){
  newsSlideUnactivateAll();
  document.getElementById(document.getElementById('activeCat').value + '_' + count).style.visibility = 'visible';
  document.getElementById(document.getElementById('activeCat').value + '_thumb' + count).style.border = '3px solid #a10000';
  document.getElementById(document.getElementById('activeCat').value + '_thumb' + count).style.margin = '-2px 8px -2px 0px';
}

function newsSlideUnactivateAll(){
  for(i=1; i<=10; i=i+1){
    document.getElementById(document.getElementById('activeCat').value + '_' + (i)).style.visibility = 'hidden';
    document.getElementById(document.getElementById('activeCat').value + '_thumb' + (i)).style.border = '1px solid #777';
    document.getElementById(document.getElementById('activeCat').value + '_thumb' + (i)).style.margin = '0px 10px 0px 2px';
  }
}

/* VALIDATE YOUTUBE CLIP LINK */
function validateYoutube(form){
  var x=form.linkValue.value;
  var linkPos=x.indexOf("youtu.be/");
  if (linkPos<1){
    alert("Linket til youtube er ikke korrekt");
    return false;
  }
}

/* VALIDATE USER REGISTRATION */
function userRegValidate(form){
	returnValue = 'true';
	
	if(form.image.value == ''){
		form.image.style.border = '1px solid red'; returnValue = 'false'; slideTo = '6';
	}
	if(form.username.value == ''){
		form.username.style.border = '1px solid red'; returnValue = 'false'; slideTo = '5';
	}
	if(form.password.value == ''){
		form.password.style.border = '1px solid red'; returnValue = 'false'; slideTo = '5';
	}
	if(form.favoriteCat.value == ''){
		returnValue = 'false'; slideTo = '3';
	}
	if(form.favoriteTeam.value == ''){
		returnValue = 'false'; slideTo = '3';
	}
	if(form.street.value == 'Gadenavn' || form.street.value == ''){
		form.street.style.border = '1px solid red'; returnValue = 'false'; slideTo = '2';
	}
	if(form.no.value == 'Nr.' || form.no.value == ''){
		form.no.style.border = '1px solid red'; returnValue = 'false'; slideTo = '2';
	}
	if(form.zip.value == 'Postnr.' || form.zip.value == ''){
		form.zip.style.border = '1px solid red'; returnValue = 'false'; slideTo = '2';
	}
	if(form.city.value == 'By' || form.city.value == ''){
		form.city.style.border = '1px solid red'; returnValue = 'false'; slideTo = '2';
	}
	if(form.name.value == 'Navn' || form.name.value == ''){
		form.name.style.border = '1px solid red'; returnValue = 'false'; slideTo = '1';
	}
	if(form.lastname.value == 'Efternavn' || form.lastname.value == ''){
		form.lastname.style.border = '1px solid red'; returnValue = 'false'; slideTo = '1';
	}
	if(form.birthYear.value == ''){
		returnValue = 'false'; slideTo = '1';
	}
	if(form.email.value == 'E-mail' || form.email.value == ''){
		form.email.style.border = '1px solid red'; returnValue = 'false'; slideTo = '1';
	}

	slideDown('newUserBox_step6', 'newUserBox_step'+slideTo, '88', '5');

	if(returnValue == 'true'){
		alert('Tillykke');
		return true;
	} else {
		alert('Du mangler at udfylde påkrævede felter!');
		return false;
	}

}

function checkIfImage(){
  var x=document.forms["harDuSet_image"]["link"].value;
  var jpgPos=x.indexOf("jpg");
  var gifPos=x.indexOf("gif");
  var pngPos=x.indexOf("png");
  var needPos = x.length-3;
  if (parseInt(jpgPos)==parseInt(needPos) || parseInt(gifPos)==parseInt(needPos) || parseInt(pngPos)==parseInt(needPos)){
    return true;
  } else {
    alert('Du skal linke direkte til et billede');
    return false;
  }
}

/* POPDOWN MENU */
function hideAllButtonAttach(){
  var allButtonAttach = document.getElementById('popdownMenuIds').value.split(';');

  /* UNACTIVATE ALL */
  for(i=0; i<allButtonAttach.length-1; i++){
    hideElement('buttonAttach_'+allButtonAttach[i]);
  }
}

function buttonAttach(visibleId){
  hideAllButtonAttach();
  showElement('buttonAttach_'+visibleId);
}

/* ADMIN popdown MENU */
function updateLevel1(menuId, active){
  setTimeout( function() { updateLevel1Function(menuId, active); }, 200 );
}
function updateLevel1Function(menuId, active){
  ajaxChange('popdownMenu_level1', 'source/popdownMenu/level1.php?menuId='+menuId+'&active='+active);
}
function updateLevel2(menuId, parentId){
  setTimeout( function() { updateLevel2Function(menuId, parentId); }, 200 );
}
function updateLevel2Function(menuId, parentId){
  ajaxChange('popdownMenu_level2', 'source/popdownMenu/level2.php?menuId='+menuId+'&parentId='+parentId);
}
function updateContent(parentId){
  setTimeout( function() { updateContentFunction(parentId); }, 200 );
}
function updateContentFunction(parentId){
  ajaxChange('popdownMenu_content', 'source/popdownMenu/content.php?parentId='+parentId);
}
