﻿function fixBreadCrumb() {
	var objBredcrumbItems = document.getElementById("breadcrumb").getElementsByTagName("a");
	var intItems = objBredcrumbItems.length;
	for(var intCount = 1; intCount < intItems; intCount ++) {
		//alert(intCount + "-");
if (objBredcrumbItems[intCount].className == "InPath") {
//alert(intCount);
objBredcrumbItems[intCount-1].className = "InPath";
break;
}
	}
}
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

function setCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function getCookie(c_name) {
	if (document.cookie.length>0) {
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1) { 
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) {
				c_end=document.cookie.length;
			}
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return null;
}

//------------ Shop functions Start
function selectMethodOption() {
	if (document.getElementById("ShopSearchTextMethod")) {
		var strUrl = document.location.href;
		var intMethod = 0;
		if (strUrl.indexOf("ShopSearchTextMethod=1") >= 0) intMethod=0;
		if (strUrl.indexOf("ShopSearchTextMethod=2") >= 0) intMethod=1;
		if (strUrl.indexOf("ShopSearchTextMethod=3") >= 0) intMethod=2;
		document.getElementById("ShopSearchTextMethod").selectedIndex = intMethod;
	}
}
function gotoProduct(strID) {
	var strPageId = "1965";
	var strParagraphId = "4437";
	if (document.strProductPageId != "") {
		strPageId = document.strProductPageId;
	}
	if (document.strProductParagraphId != "") {
		strParagraphId = document.strProductParagraphId ;
	}

//	var strUrl = "/Default.aspx?ID=" + strPageId + "&M=Shop&PID=" + strParagraphId + "&ProductID=" + strID;
	var strUrl = "/Default.aspx?ID=" + strPageId + "&PID=" + strParagraphId + "&ProductID=" + strID;
	document.location.href = strUrl;
}
function add(strProductId) {
	var strNoAmount = "Indtast venligst et tal i feltet 'Antal'";
	if (document.strNoAmount != null && document.strNoAmount != "") {
		strNoAmount = document.strNoAmount;
	}
	var strUrl = eval('document.getElementById("add' + strProductId + '").value');

	var intAmount = eval('document.getElementById("amount' + strProductId + '").value');
	if(isNaN(intAmount) || intAmount == ""){
		alert(strNoAmount);
		eval('document.getElementById("amount' + strProductId + '").focus()');
	} else {
		intAmount = parseInt(intAmount);
		strUrl += "&Amount=" + intAmount;
		document.location.href = strUrl;
	}
	setCookie("shopping","true",1);
}

function add2(strProductId) {
	var strNoAmount = "Indtast venligst et tal i feltet 'Antal'";
	if (document.strNoAmount != null && document.strNoAmount != "") {
		strNoAmount = document.strNoAmount;
	}

	//var strUrl = eval('document.getElementById("add' + strProductId + '").value');

	//var strUrl = "/Admin/Public/Cart.aspx?ProductID=" + strProductId + "&shopping";
	var strUrl = "/Admin/Public/Cart.aspx?ProductID=" + strProductId + "&BackURL=" + document.location.href + "&shopping";

	var intAmount = eval('document.getElementById("amount' + strProductId + '").value');
	var strPrice = document.getElementById('add' + strProductId).value;

	if(isNaN(intAmount) || intAmount == ""){
		alert(strNoAmount);
		eval('document.getElementById("amount' + strProductId + '").focus()');
	} else {
		intAmount = parseInt(intAmount);
		strUrl += "&Amount=" + intAmount;
		if (strPrice != "") {
			strUrl += "&Price=" + strPrice;
		}
		document.location.href = strUrl;
	}
	setCookie("shopping","true",1);
}



//Admin/Public/Cart.aspx?ProductID=125329&BackURL= ... &shopping


if(getCookie("shopping")=="true") {
	setCookie("shopping","false",1);
	document.blnShopping = true;
}
function cartStatus() {
	var strCartstatusMsg = "Varen er lagt i indkøbskurven";
	if (document.strCartstatusMsg != null && document.strCartstatusMsg != "") {
		strCartstatusMsg = document.strCartstatusMsg;
	}
	if (document.blnShopping == true) {
		alert(strCartstatusMsg );
	}
}

function showUserInfo(pageid){

	if ((document.strProductSearchPageId != undefined) && (pageid == "1538" || pageid == "2428" || pageid == "2585" || pageid == "1803")) {
		document.location.href = "/Default.aspx?ID=" + document.strProductSearchPageId;
	} else {
		var strLogonOK = "Du er logget på.";
		var strLogOff = "Log af";
		if (document.strLogonOK != null && document.strLogonOK != "") {
			strLogonOK = document.strLogonOK;
		}
		if (document.strLogOff != null && document.strLogOff != "") {
			strLogOff = document.strLogOff;
		}
		if (document.getElementById("loginStatus")) {
			document.getElementById("loginStatus").innerHTML = ('<p>' + strLogonOK + '<br /><a href="/admin/public/extranetlogoff.aspx?id=' + pageid + '">' + strLogOff + '</a></p>');
		}
		if (document.getElementById("loginForm")) {
			document.getElementById("loginForm").innerHTML = ('<p>' + strLogonOK + '<br /><a href="/admin/public/extranetlogoff.aspx?id=' + pageid + '">' + strLogOff + '</a></p>');
		}

	}

//----------------------------//
//----------------------------//
//----------------------------//

//----------------------------//
//----------------------------//
//----------------------------//
}

function makeItemLinks(strID, strSupplierLink, strProductLink, strSupplierItemNumber, strDwShopProductNumber, strPrice) {
	var strSupplierHome = "Link til leverandørens hjemmeside (nyt vindue)";
	if (document.strSupplierHome != null && document.strSupplierHome != "") {
		strSupplierHome = document.strSupplierHome;
	}
	var strSupplierDesc = "Link til leverandørens beskrivelse (nyt vindue)";
	if (document.strSupplierDesc != null && document.strSupplierDesc != "") {
		strSupplierDesc = document.strSupplierDesc;
	}
	if (strSupplierLink != "") {
		if(document.getElementById("supName" + strID)) {
			if(document.getElementById("supName" + strID).innerHTML) {
				document.getElementById("supName" + strID).innerHTML = '<a href="http://' + strSupplierLink + '" target="_blank" title="' + strSupplierHome + '">' + document.getElementById("supName" + strID).innerHTML + '</a>';
			}
		}
	}
	if(document.getElementById("prodLink" + strID)) {
		if(document.getElementById("prodLink" + strID).innerHTML) {
			if (strProductLink != "") {
				document.getElementById("prodLink" + strID).innerHTML = '<a href="' + strProductLink + '" target="_blank" title="' + strSupplierDesc + '">' + document.getElementById("prodLink" + strID).innerHTML + '</a>';
			} else {
				if (strDwShopProductNumber != "") {
					//document.getElementById("prodLink" + strID).innerHTML = '&nbsp;';
				}
				
				if(document.getElementById("prodLinkRow")) {
					document.getElementById("prodLinkRow").style.display = "none";
				}
			}
		}
	}
	if(document.getElementById("xClone")) {
		if(document.getElementById("xClone").innerHTML.length == 0) {
			document.getElementById("xCloneRow").style.display = "none";
		}
	}
	if(document.getElementById("xBusinessunit")) {
		if(document.getElementById("xBusinessunit").innerHTML.length == 0) {
			document.getElementById("xBusinessunitRow").style.display = "none";
		}
	}
	if(document.getElementById("xSpecForhold")) {
		if(document.getElementById("xSpecForhold").innerHTML.length == 0) {
			document.getElementById("xSpecForholdRow").style.display = "none";
		}
	}
	if (strSupplierItemNumber.toLowerCase() != strDwShopProductNumber.toLowerCase()) {
		if (document.getElementById("ahProductNumber" + strID)) {
			document.getElementById("ahProductNumber" + strID).innerHTML = "(" + strDwShopProductNumber + ")";
		}
	}
//	if (strPrice != null) {
//		strPrice = strPrice.replace(/\./,"");
//		strPrice = strPrice.replace(/\s+/g,"");
//		strPrice = strPrice.replace(/,/,".");
//		var intPrice = parseInt(strPrice);
//		if(strPrice == 999999) {
//			if(document.getElementById("price" + strID)) {
//				document.getElementById("price" + strID).style.display="none";
//			}
//			if(document.getElementById("amount" + strID)) {
//				document.getElementById("amount" + strID).style.display="none";
//			}
//			if(document.getElementById("addLink" + strID)) {
//				if (document.getElementById("addLink" + strID).innerHTML) {
//					var strEmail = "ahdiag@ahdiag.dk";
//					if (document.strInquireEmail != null) {
//						strEmail = document.strInquireEmail;
//					}
//					document.getElementById("addLink" + strID).innerHTML = "<a href=\"mailto:" + strEmail + "?subject=Inquire price prod. " + strSupplierItemNumber + " (" + strDwShopProductNumber  + ")\">Inquire price</a>";
//				}
//			}
//		}
//	}
}

function pagingStatus() {
	if (document.getElementById("pagingbuttonlisttop")) {
		var objPagingButtonListTop = document.getElementById("pagingbuttonlisttop");
		var objPagingButtonListBottom = document.getElementById("pagingbuttonlistbottom");
		var objPagingButtonsTop = objPagingButtonListTop.getElementsByTagName("a");
		var objPagingButtonsBottom = objPagingButtonListBottom.getElementsByTagName("a");
		if (objPagingButtonsTop.length > 0) {
			if (document.location.href.toLowerCase().indexOf("pagenum=") >= 0) {
				var intPageNumber = parseInt(document.location.href.substring(document.location.href.toLowerCase().indexOf("pagenum=")+8));
			}
			if (intPageNumber == undefined) {
				intPageNumber = 1;
			}
			var strSearchStatus = "Søgeresultatet vises på " + objPagingButtonsTop.length + " sider.";
			if (intPageNumber != "") {
				strSearchStatus = "Her vises side " + intPageNumber + " af " + objPagingButtonsTop.length + " sider.";
				objPagingButtonsTop[intPageNumber-1].className = "pagingActive";
				objPagingButtonsBottom[intPageNumber-1].className = "pagingActive";
			}
			document.getElementById("shopsearchstatus").innerHTML = strSearchStatus;
		}
	}
}
function pagingStatus2() {
	if (document.getElementById("pagingbuttonlisttop")) {
		var objPagingButtonListBottom = document.getElementById("pagingbuttonlistbottom");
		var objPagingButtonsBottom = objPagingButtonListBottom.getElementsByTagName("a");
		if (objPagingButtonsBottom .length > 0) {
			if (document.location.href.toLowerCase().indexOf("pagenum=") >= 0) {
				var intPageNumber = parseInt(document.location.href.substring(document.location.href.toLowerCase().indexOf("pagenum=")+8));
			}
			if (intPageNumber == undefined) {
				intPageNumber = 1;
			}
			var strSearchStatus = "Søgeresultatet vises på " + objPagingButtonsBottom.length + " sider.";
			if (intPageNumber != "") {
				strSearchStatus = "Her vises side " + intPageNumber + " af " + objPagingButtonsBottom.length + " sider.";
//				objPagingButtonsTop[intPageNumber-1].className = "pagingActive";
//				objPagingButtonsBottom[intPageNumber-1].className = "pagingActive";
			}
			document.getElementById("shopsearchstatus").innerHTML = strSearchStatus;
			document.getElementById("shopsearchstatusbottom").innerHTML = strSearchStatus;
		}
	}
}

function validateProductSearch() {
	var strNoSearchString = "Indtast venligst en søgetekst.";
	if (document.strNoSearchString != "") {
		strNoSearchString = document.strNoSearchString;
	}
	if (document.getElementById("ShopSearchText")) {
		if (document.getElementById("ShopSearchText").value.length == 0) {
		alert(strNoSearchString);
		return false;
	}
}
return true;
}
//------------ Shop functions End


function styleLeftNavi(strID) {
	var aryID= strID.split(";");
	intPagelevel = 0;
	for (var i = 0; i < aryID.length; i++) {
		if (!isNaN(aryID[i])) {
			intPagelevel = i;
		}
	}
	intPagelevel++;
	var elmLeftNavi = document.getElementById("leftNavi");
	var elmA = elmLeftNavi.getElementsByTagName("a");
	var strClass = "";
	for (var j = 0; j < elmA.length; j++) {
		if (elmA[j].className.substring(1,2) < intPagelevel) {
			if (elmA[j].className.substring(1,2) == intPagelevel - 1 && elmA[j].className.indexOf("Active") >= 0) {
				strClass = "leftHeader";
			} else {
				elmA[j].style.display = "none";
			}
		} else {
			if (elmA[j].className.substring(1,2) == intPagelevel || intPagelevel == 1) {
				strClass = "L2";
			} else {
				strClass = "L3";
			}
			if (elmA[j].className.indexOf("Active") >= 0) {
				strClass += " " + strClass + "_active";
			}
		}
		elmA[j].className = strClass;
	}
}

// Fixes visible dropdownarrow on hiddenpages
function csFixDWDropdownMenus() {
	var aTables = document.getElementsByTagName("table");
	var oTable, t=0;
	while (oTable = aTables[t++]) {
		if (oTable.rows.length == 0) {
			csKillDropdownArrow(oTable.parentNode.id);
		}
	}
}

function csKillDropdownArrow(sID) {
	var oTR = document.getElementById(sID.replace("submenu", ""));	
	if (oTR) {
		var elm = oTR.getElementsByTagName("img");
		if (elm.length > 0) {
			elm[0].style.visibility = "hidden";
		}
	}
}
function goToBasket() {
	if (document.strBasketPageId != "") {
		document.location.href = "/default.aspx?id=" + document.strBasketPageId;
	}
}

// Scanad - TMH - August 2010

function frontSlide(state, obj){
	if(state == 1){
		$(obj).find('h2').css('background-image','url(/files/System/AHD2010/gfx_whiteArrowDown.png)');
		$(obj).find('div.fadedText').fadeIn();
		$(obj).stop().animate({
			height: '121px'
		}, 500, function() {
			// Animation complete.
		});
	}else{
		$(obj).find('h2').css('background-image','url(/files/System/AHD2010/gfx_whiteArrowUp.png)');
		$(obj).find('div.fadedText').fadeOut();		
		$(obj).stop().animate({
			height: '45px'
		}, 500, function() {
			// Animation complete.
		});
	}
	
}
