﻿function convertEntities(strIn){
	strOut = strIn.replace(/\n/g,"<br />");
	return (strOut);
}
function altercontent(strHtml){
if (strHtml == 'large') {
	strHtml = document.getElementById("productLargeDesc").value;
	strHtml = convertEntities(strHtml);
}
//if IE 4+
if (document.all){
dcontent.innerHTML=strHtml;
}
//else if NS 4
else if (document.layers){
document.ns4dcontent.document.ns4dcontent2.
document.write(strHtml);
document.ns4dcontent.document.ns4dcontent2.
document.close();
}
//else if NS 6 (supports new DOM)
else if (document.getElementById){
rng = document.createRange();
el = document.getElementById("dcontent");
rng.setStartBefore(el);
htmlFrag = rng.createContextualFragment(strHtml);
while (el.hasChildNodes())
el.removeChild(el.lastChild);
el.appendChild(htmlFrag);
}
}
//-------------------------------------------------------------------------------------
function show(objId,imgtype) {
	if(objId.substr(0,3) == "Dtn" || objId.substr(0,3) == "Mtn") {
		objId = objId.substr(3);
	}
	if(document.getElementsByTagName){
		var objImages = document.getElementsByTagName("a");   
		for(i = 0; i < objImages .length; i++){
			strID = objImages[i].id;
			if (strID != "") {
				strClassName = document.getElementById(strID).className;
				elm = document.getElementById(strID);			
				if(strClassName == "shopTNactive"){
					document.getElementById(strID).className = "";
				}
			}
		}
	}  
	if (imgtype == "d") {
		strAnchorPrefix = "Dtn";
	} else {
		strAnchorPrefix = "Mtn";
	}
	if (document.getElementById) {
		if (document.getElementById(strAnchorPrefix + objId)) {
    		document.getElementById(strAnchorPrefix + objId).className = "shopTNactive";
		}
	}
	if (document.images["productLarge"]){
		imSrc = "files/billeder/dansaniLarge/" + objId + ".jpg";
		document.images["productLarge"].src="files/system/wait.gif";
		document.images["productLarge"].src=imSrc;
	}
	strDescID = "desc" + objId;
	desc = document.getElementById(strDescID).value;
	desc = convertEntities(desc);
	altercontent(desc);
	document.strActiveID = objId;
}
//--------------------------------------------------------------------------
function next_prevImage(direction,imgtype){
	strLargeID = document.strActiveID;
	if (imgtype == "m") {
		aryTest = document.arySmallimage_M_IDs;
	}
	if (imgtype == "d") {
		aryTest = document.arySmallimage_D_IDs;
	}
if (aryTest) {
	intTest = aryTest.length;
	if ( direction == "n" ) {
		intMove = 1;
	} else {
		intMove = -1;
	}
	blnFound = false;
	for(i=0; i<intTest; i++) {
		if ( aryTest[i] == strLargeID ) {
			j = i+intMove;
			if ( j < 0) {
				j = intTest-1;
			}
			if ( j >= intTest ) {
				j = 0;
			}
			strSmallIDnext = aryTest[j];
			blnFound = true;
			break;
		}
	}
	if (blnFound == false) {
		strSmallIDnext = aryTest[0];
	}
	show(strSmallIDnext,imgtype);
}
}
//-----------------------------------------------------------------------------------
function makeTnActive (intID) {
	if (document.getElementById("Mtn" + getLargeId())) {
		document.getElementById("Mtn" + getLargeId ()).className = "shopTNactive";
	}
}
function getLargeId() {
	strLargeID = "";
	if (document.images["productLarge"]) {
		strLargesrc = document.images["productLarge"].src;
		intPos = strLargesrc.lastIndexOf("/");
		strFilename = strLargesrc.substr(intPos+1);
		strLargeID = strFilename.substring(0,strFilename.indexOf(".jpg"));
	}
	return strLargeID ;
}
function GetElementsWithClassName(elementName,className) {
	var allElements = document.getElementsByTagName(elementName);
	var elemColl = new Array();
	for (i = 0; i < allElements.length; i++) {
		if (allElements[i].className == className) {
			elemColl[elemColl.length] = allElements[i];
		}
	}
	return elemColl;
}
function showHideElement(elementName,className,mode) {
	aryElm = GetElementsWithClassName(elementName,className);
	for (i = 0; i < aryElm.length; i++) {
		aryElm[i].style.visibility = mode;
	}
}
//----------------------------------------------------------------------------------------
function initDansani() {
	var strSmallimage_M_IDs = "";
	var strSmallimage_D_IDs = "";
	if(document.getElementsByTagName){
		var objImages = document.getElementsByTagName("a");   
		for(i = 0; i < objImages .length; i++){
			strID = objImages[i].id;
			if ( strID.indexOf("Mtn") >= 0 ){
				strSmallimage_M_IDs = strSmallimage_M_IDs + ";" + strID.substr(3);
			}
			if ( strID.indexOf("Dtn") >= 0 ){
				strSmallimage_D_IDs = strSmallimage_D_IDs + ";" + strID.substr(3);
			}
		}
		strSmallimage_M_IDs = strSmallimage_M_IDs.substr(1);
		document.arySmallimage_M_IDs = strSmallimage_M_IDs.split(";");
		strSmallimage_D_IDs = strSmallimage_D_IDs.substr(1);
		document.arySmallimage_D_IDs = strSmallimage_D_IDs.split(";");
	}
	showHideElement('div','arrows','visible');
	strLargeID = getLargeId();
	document.strActiveID = strLargeID;
	makeTnActive (strLargeID )
}