function subMeny(kategori){
	var x;
	var submenus = new Array();
	submenus[0] = "hundar";
	submenus[1] = "valpar";
	for(x in submenus){
		document.getElementById(submenus[x]).style.display = 'none';
	}
	if(kategori !== ''){
		document.getElementById(kategori).style.display = 'block';
	}
}

function popupGallery(url, x, y){
	var popup = window.open(url, 'showBild', 'scrollbars=no, width='+x+', height='+y+'').focus();
}

function activateReference(id){
	if(document.getElementById('reference_'+id).style.display !== 'block'){
		document.getElementById('reference_'+id).style.display = 'block';
		disableChildren(id, 'disable');
	}else{
		document.getElementById('reference_'+id).style.display = 'none';
		disableChildren(id, 'enable');
	}
}

function disableChildren(id, state){
	var close_down = [14, 6, 3, 2, 3, 6, 5, 6, 14, 10, 9, 10, 13, 12, 13];	
	var fields = ['box', 'name', 'number', 'extra', 'reference']
	if(state == 'disable'){
		for(x = id; x <= close_down[id]+1; x++){
			for(a in fields){
				if(x == id){
					document.getElementById('name_'+x).disabled = true;
					document.getElementById('number_'+x).disabled = true;
					document.getElementById('extra_'+x).disabled = true;
				}else{
					document.getElementById(fields[a]+'_'+x).disabled = true;
				}
			}
		}
	}else{
		for(x = id; x <= close_down[id]+1; x++){
			if(document.getElementById('box_'+x).checked == true){
				document.getElementById('box_'+x).disabled = false;
				document.getElementById('reference_'+x).disabled = false;
				x = close_down[x]+1;
			}else{
				for(a in fields){
					document.getElementById(fields[a]+'_'+x).disabled = false;
				}
			}
		}
	}
}

function addBild() {
	window.open('picture_add.php', 'popupWin', 'scrollbars=yes,height=250,width=350')
	return;
}

function showHelp() {
	window.open('help.php', 'popupWin', 'scrollbars=yes,height=250,width=350')
	return;
}

function addFil() {
	window.open('file_add.php', 'popupWin', 'scrollbars=yes,height=250,width=350')
	return;
}

function addLink() {
	window.open('link_add.php', 'popupWin', 'scrollbars=no,height=350,width=350')
	return;
}

function addIntern() {
	window.open('intern_add.php', 'popupWin', 'scrollbars=no,height=350,width=350')
	return;
}

function showButtons() {
	document.getElementById('onBild').style.display='inline'; 
	document.getElementById('onFil').style.display='inline';
	return;
}

var cPos, 
    fObj, 
    ieC = Boolean(document.selection && document.selection.createRange); 
 
function addButt(str1, str2) { 
   if (typeof str2 == "undefined") { 
      if(ieC) { 
         if (typeof cPos != "undefined") 
            cPos.text = str1; 
         else 
            fObj.value = str1; 
      } else if (typeof window.HTMLTextAreaElement != "undefined") 
         fObj.value = fObj.value.substring(0, fObj.selectionStart) + str1 + fObj.value.substring(fObj.selectionEnd); 
      else 
         fObj.value += str1; 
   } else { 
      if(ieC) { 
         if (typeof cPos != "undefined") 
            cPos.text = str1 + cPos.text + str2; 
         else 
            fObj.value += str1 + str2; 
      } else if (typeof window.HTMLTextAreaElement != "undefined") 
         fObj.value = fObj.value.substring(0, fObj.selectionStart) + str1 + 
            fObj.value.substring(fObj.selectionStart, fObj.selectionEnd) + str2 + fObj.value.substring(fObj.selectionEnd); 
      else 
         fObj.value += str1 + str2; 
   } 
} 
 
function sC() { 
    cPos = document.selection.createRange().duplicate(); 
} 
 
window.onload = function() { 
	 if(!document.forms["form"]) 
        return; 
    fObj = document.forms["form"].elements["text"]; 
 
    if (ieC) { 
   fObj.onclick  = function() { sC(); } 
   fObj.onkeyup  = function() { sC(); } 
   fObj.onselect = function() { sC(); } 
    } 
} 

function textLimit(what) {
	if (what.value.length > 250){
		what.value = what.value.substring(0, 250);
		alert('Du får högst använda 250 tecken!');
	}
}