// Copyright by Malte Stær Nissen
// Thoose scripts are a part of "ShaggO cms"
// For more information visit: www.shaggo.net

// Mus koordinater
var musPosX = 0;
var musPosY = 0;
document.onmousemove = musPos;
function musPos(e) {
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) {
		musPosX = e.pageX;
		musPosY = e.pageY;
	} else if (e.clientX || e.clientY) {
		musPosX = e.clientX + document.body.scrollLeft;
		musPosY = e.clientY + document.body.scrollTop;
	}
}
// Skift texteditor redigering
function skiftredigering(rId, vle, mode) {
	var rElm = document.getElementById("mode_"+rId);
	var Delm = document.getElementById("faneblad_D_"+rId);
	var Aelm = document.getElementById("faneblad_A_"+rId);
	if (mode != rElm.value) {
		rElm.value = mode;
		if (mode == 0) {
			Aelm.className = 'faneblad';
			Delm.className = 'faneblad_active';
			
		} else {
			Aelm.className = 'faneblad_active';
			Delm.className = 'faneblad';
		}
		toggleHTMLSrc(rId, 'true');
	}
}
function vaelgbruger(vle,vId) {
	var vEle = document.getElementById(vId+"_input");
	vEle.value = vle;
	hidebox(vId);
}
function rulstatus(obj, status) {
	obj.src = obj.src.substring(0, (obj.src.length-1)*1)+status;
}
function rollmenu(rId, pixels) {
	var iDiv = document.getElementById(rId+"Div");
	var iImg = document.getElementById(rId+"Img");
	var iStLeft = document.getElementById(rId+"StLeft");
	if (iDiv) {
		if (iStLeft.value == "") {
			iStLeft.value = iDiv.style.left.substring(0, (iDiv.style.left.length-2))*1;
		}
		var StLeft = iDiv.style.left.substring(0, (iDiv.style.left.length-2))*1;
		for(x = 0; x <= pixels; x++) {
			if (StLeft != iStLeft.value) {
				var timeout = setTimeout("roll('" + rId + "Div', '" + (StLeft-x) + "')", x*2);
				if (x == pixels) {
					iImg.src = 'cms/rul.php?v=ud&s=1';
				}
			} else {
				var timeout = setTimeout("roll('" + rId + "Div', '" + (StLeft + x) + "')", x*2);
				if (x == pixels) {
					iImg.src = 'cms/rul.php?v=ind&s=1';
				}
			}
		}
	}
}

function roll(rId, pixels) {
	var div = document.getElementById(rId);
	div.style.left = pixels+"px";
}
function slet(table, g_row, sId) {
	var iDiv = document.getElementById('slet_box');
	document.getElementById('slet_table').value = table;
	document.getElementById('slet_row').value = sId;
	document.getElementById('slet_getrow').value = g_row;
	iDiv.style.left = musPosX + 'px';
	iDiv.style.top = musPosY + 'px';
	if (iDiv.style.display == 'none') {
		iDiv.style.display = '';
	}
}
function hidebox(bId) {
	document.getElementById(bId).style.display = 'none';
}
function showbox(bId) {
	document.getElementById(bId).style.display = '';
}
function maxlength(tTxt, tId, mlen) {
	var ml = document.getElementById(tId);
	var mc = document.getElementById(tId+"_count");
	// if (ml.value.length > mlen) {
		// ml.value = ml.value.substr(0,mlen);
		// mc.innerHTML = "( "+ml.value.length+" / "+mlen+" )";
		// return false
	// }
	mc.innerHTML = tTxt+" ( "+ml.value.length+" / "+mlen+" ):";
	return true
}
function showpic(pic, display, imgwidth) {
	var iDiv = document.getElementById('img_box');
	var iDivImg = document.getElementById('img_src');
	var iDivTbl = document.getElementById('img_table');
	var iDivSlink = document.getElementById('img_startlink');
	var iDivLink = document.getElementById('img_link');
	iDivTbl.style.width = (imgwidth * 1) + 10 + 'px';;
	iDiv.style.left = musPosX + 'px';
	iDiv.style.top = musPosY + 'px';
	iDivImg.src = pic;
	iDivLink.value = iDivSlink.value + pic;
	iDivLink.style.width = ((imgwidth * 1) - 27) + 'px';
	if (iDiv.style.display == 'none') {
		iDiv.style.display = '';
	}
}
function omdob(sti, pic) {
	var iDiv = document.getElementById('omdob_box');
	document.forms['omdob_form'].omdob_pic.value = pic;
	document.forms['omdob_form'].omdob_pic.value = pic;
	document.forms['omdob_form'].omdob_oldall.value = sti+pic;
	document.forms['omdob_form'].omdob_oldsti.value = sti;
	document.forms['omdob_form'].omdob_pic.focus();
	iDiv.style.left = musPosX + 'px';
	iDiv.style.top = musPosY + 'px';
	if (iDiv.style.display == 'none') {
		iDiv.style.display = '';
	}
}
function omdobsubmit(formname) {
	error = 0;
	str = document.forms[formname].omdob_pic.value
	if ((str.match(/[\\|\/|:|\*|\?|"|<|>|\|]/) != null) && (error == 0)) {		
		alert('Filnavnet må ikke indeholde: \\ / : * ? " < > |');
		document.forms[formname].omdob_pic.focus();
		error = 1;		
	}
	if (error == 0) {
		document.forms[formname].submit();
	}
}

function birthday(iField, vle, iN) {
	var monthF = document.getElementById(iN+'_month');
	var yearF = document.getElementById(iN+'_year');
	var dayF = document.getElementById(iN+'_day');
	if (iField == "year") {
		if (vle != "") {
			monthF.options[0].text = 'Januar';
			monthF.options[0].value = '01';
			monthF.options[1].text = 'Februar';
			monthF.options[1].value = '02';
			monthF.options[2].text = 'Marts';
			monthF.options[2].value = '03';
			monthF.options[3].text = 'April';
			monthF.options[3].value = '04';
			monthF.options[4].text = 'Maj';
			monthF.options[4].value = '05';
			monthF.options[5].text = 'Juni';
			monthF.options[5].value = '06';
			monthF.options[6].text = 'Juli';
			monthF.options[6].value = '07';
			monthF.options[7].text = 'August';
			monthF.options[7].value = '08';
			monthF.options[8].text = 'September';
			monthF.options[8].value = '09';
			monthF.options[9].text = 'Oktober';
			monthF.options[9].value = '10';
			monthF.options[10].text = 'November';
			monthF.options[10].value = '11';
			monthF.options[11].text = 'December';
			monthF.options[11].value = '12';
		} else {
			monthF
		}
	} else if (iField = "month") {
	}
}
function checkmessages(cId) {
	for(x = 1; document.getElementById('message_'+x); x++) {
		if (cId.checked) {
			document.getElementById('message_'+x).checked = true;
		} else {
			document.getElementById('message_'+x).checked = false;
		}
	}
}
