window.name = 'Nilfisk-Advance';
function resetForms() {
	for (i=0; i < document.forms.length; i++) {
		document.forms[i].reset();
	}
}

function openProductComparison(){
	window.open('/Functions/ProductComparison.aspx','productComparator', 'width=890,height=500,location=no,menubar=no,status=no,toolbar=no,scrollbars=yes,resizable=yes');
}


/*
Bookmark script
*/
var url = window.location;
var who = document.title;
function bookMark(){
	var ver = navigator.appName
	var num = parseInt(navigator.appVersion)
	if ((ver == "Microsoft Internet Explorer")&&(num >= 4)) {
		document.write('<td>')
		document.write('<a href="javascript:window.external.AddFavorite(url,who);" class="tools">');
		document.write('<img src="/gfx/icons/bookmark.gif" style="width:20; height:20; border:0px;" alt="'+txt+'" /></a>')
		document.write('</td>')
		document.write('<td>')
		document.write('<a href="javascript:window.external.AddFavorite(url,who);" class="tools">');
		document.write(txt + '</a>')
		document.write('</td>')
	}else{
		txt += "  (Ctrl+D)"
		document.write('<td>')
		document.write('<img src="/gfx/icons/bookmark.gif" style="width:20; height:20; border:0px;" alt="" />')
		document.write('</td>')
		document.write('<td class="tools">')
		document.write(txt)
		document.write('</td>')
	}
}


/*
Change Picture (Product Introduction page)
*/

function changePicture(src){
	var path = src;
	var image = '<div class="productMedia"><img id="productPicture" src='+path+' alt="" class="" /></div>';
	document.getElementById('productMedia').innerHTML = image;
}

/*
Adobe Flash detector
*/
// -----------------------------------------------------------------------------
// Globals
// Major version of Flash required
var requiredMajorVersion = 7;
// Minor version of Flash required
var requiredMinorVersion = 0;
// Minor version of Flash required
var requiredRevision = 0;
// -----------------------------------------------------------------------------
// Version check based upon the values entered above in "Globals"
var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
// -----------------------------------------------------------------------------
/*
/ Adobe Flash detector
*/

function changeVideo(src,duration){
	var totalTime	= duration;
	var path		= src;
	if (hasReqestedVersion) {
	var video = '&#160;<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0"  width="266" height="280" id="flashvideo" align="middle" VIEWASTEXT><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="/gfx/video.swf?video='+src+'&duration='+totalTime+'" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><embed src="/gfx/video.swf?video='+src+'&duration='+totalTime+'" quality="high" bgcolor="#ffffff"  width="266" height="280" name="flashvideo" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';
	}
	else{

	var video = '<div style="width:240px; height:240px; text-align:center;"><a href="http://www.adobe.com/go/getflashplayer"><img src="/gfx/get_flash_player.gif" border="0" alt="" /></a></div>';
	}

	document.getElementById('productMedia').innerHTML = video;

}




/*
Cookies for countrySelector
*/

var expDays = 100;
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function getCookieVal (offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
	endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
	var j = i + alen;
	if (document.cookie.substring(i, j) == arg)
	return getCookieVal (j);
	i = document.cookie.indexOf(" ", i) + 1;
	if (i == 0) break;
}
return null;
}
function SetCookie (name, value) {
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) +
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
	((path == null) ? "" : ("; path=" + path)) +
	((domain == null) ? "" : ("; domain=" + domain)) +
	((secure == true) ? "; secure" : "");

}

function DeleteCookie (name) {
	var exp = new Date();
	exp.setTime (exp.getTime() - 1);
	var cval = GetCookie (name);
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

function productFinderStep(obj) {
	if(mainform.productfinderurl != null){
		mainform.productfinderurl.value = obj.value;
	}
	mainform.productfindersubmit.disabled = "";
}



// Product overview comparator

function frmCompareSubmit()
	{
	l=(screen.availWidth-890)/2
	t=(screen.availHeight-500)/2
	a=window.open('/Functions/ProductComparison.aspx','productComparator','width=890,height=500, resizable=1, left='+l+',top='+t);
	document.getElementById("comparator").target = 'productComparator';
	//document.getElementById("comparator").action = '/Functions/ProductComparison.aspx';
	//mainform.__VIEWSTATE.name = 'NOVIEWSTATE';
	document.getElementById("comparator").submit();


}
// for product comparator on left menu
function fntCompareSubmit()
	{

	l=(screen.availWidth-890)/2
	t=(screen.availHeight-500)/2

	a=window.open('/Functions/ProductComparison.aspx','productComparator','width=890,height=500,scrollbars=yes,resizable=yes,left='+l+',top='+t);
	if(document.getElementById("fntComparator")){
	document.getElementById("fntComparator").target = 'productComparator';
	document.getElementById("fntComparator").submit();

	}


}
function frmTickToCompare(id){
	var prod1 = document.getElementById("products1");
	var prod2 = document.getElementById("products2");
	var prod3 = document.getElementById("products3");
	// empty fields
	if (prod1.value == id){
		prod1.value = prod2.value;
		prod2.value = prod3.value;
		return false
	}
	if (prod2.value == id){
		prod2.value = prod3.value;
		prod3.value = "";
		return false
	}
	if (prod3.value == id){
		prod3.value = "";
		handleUncheckedCheckboxes(false);
		return false
	}

	// fill fields
	if (prod1.value == ""){
		prod1.value = id;
	}

	else if (prod2.value == ""){
		prod2.value = id;
	}
	else{
		prod3.value = id;
		handleUncheckedCheckboxes(true);
// for (var i = 1; i <= form.count; i++) {
	}

}

function handleUncheckedCheckboxes(state){
var formelement = comparator;
var allInputs = formelement.getElementsByTagName("input");
var checkboxcount = 0
for (var i = 0; i < allInputs.length; i++) {
if (allInputs[i].type == 'checkbox' && allInputs[i].checked == false) {
	checkboxcount++
	allInputs[i].disabled = state;
	}
}
}








/*
Extra menu for se,dk,no
*/
function fixDate (date) {
    var base = new Date(0);
    var skew = base.getTime();
    if (skew > 0)
        date.setTime(date.getTime() - skew);
}


function setCookie2 (name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
	document.cookie = curCookie;
}


function checkEnter(e,caller) //e is event object passed from function invocation
{
	var characterCode //literal character code will be stored in this variable

	if(e && e.which)
	{ //if which property of event object is supported (NN4)
		e = e
		characterCode = e.which //character code is contained in NN4's which property
	}
	else
	{
		e = event
		characterCode = e.keyCode //character code is contained in IE's keyCode property
	}

	if(characterCode == 13)//if generated character code is equal to ascii 13 (if enter key)
	{
		document.getElementById(caller).click();
		return false
	}
	else
	{
		return true
	}
}





/*Marketing Zone*/

function mzImagePreview(url){
if(document.getElementById('mzImagePreview')){
var previewDiv = document.getElementById('mzImagePreview');
var l= getWindowPosition("width")-250;
var t= getWindowPosition("height")-150;

	html ='<img src="'+url+'" onclick="mzImagePreviewClose();" style="cursor:pointer; padding:10px;"/><br/>';

	previewDiv.style.left = l+"px";
	previewDiv.style.top = t+"px";
	previewDiv.innerHTML = html;
	previewDiv.style.display = "block";
	previewDiv.style.zIndex=100;

return false
}
}

function mzImagePreviewClose(){
	document.getElementById('mzImagePreview').style.display = "none";
}


function getWindowPosition(dim){
  var myWidth = 0, myHeight = 0;
// a little check cos IE doens't support window innerWidth

  if(typeof( window.innerWidth ) == 'number' ) {
    //Non-IE

    theTop = document.documentElement.scrollTop;
    theHeight = window.innerHeight/2;

	theLeft = document.documentElement.scrollLeft;
    theWidth  = window.innerWidth/2;

    myWidth = theLeft+theWidth;
    myHeight = theTop+theHeight;

  }
  else if( document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight )) {
    //IE 6+ in 'standards compliant mode'
    theTop = document.documentElement.scrollTop;
    theHeight = document.documentElement.clientHeight/2;

	theLeft = document.documentElement.scrollLeft;
    theWidth  = document.documentElement.clientWidth/2;

    myWidth = theLeft+theWidth;
    myHeight = theHeight+theTop;

  } else if( document.body && (document.body.clientWidth || document.body.clientHeight )) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }

  if(dim == 'width'){
	return myWidth;
  }
  else{
	return myHeight;
  }

}

function AddItem(path)
{
  var width = Math.min(750, screen.availWidth);
  var height = Math.min(550, screen.availHeight);
  var left = Math.floor((screen.availWidth-width)/2);
  var top = Math.floor((screen.availHeight-height)/2);

  //contentdot_win = window.open("/sitecore/client/editors/content.aspx?path=" + sItemID + "&revision=" + sRevision, "contentdot_editor", "width=" + width + ",height=" + height + ",left=" + left + ",top=" + top + ",resizable=yes");
  contentdot_win = window.open("/sitecore modules/addition/marketingzone/catalog/marketingzone.item.add.aspx?Path=" + path, "contentdot_editor", "width=" + width + ",height=" + height + ",left=" + left + ",top=" + top + ",resizable=yes,status=yes");

  contentdot_win.focus();

}


// MZ

/*
string NextButtonURL = "mainform.action='" + SitecoreHelper.GetFullUrl() + ".aspx';";
NextButton.Attributes.Add("onclick",NextButtonURL);
*/
function gotoMZPage(nextProductToShow, url){
	document.forms[0].general_content_marketingzone0_MarketingZone_Catalog_Products3_txtNextProductToShow.value = nextProductToShow;
	document.forms[0].action = url+".aspx";
	document.forms[0].submit();
}


function postSearch(searchStr,site){
if(searchStr != ""){
	//document.mainform.__VIEWSTATE.value = "";
	document.mainform.searchMain.value = searchStr;
	document.mainform.method="post";
	document.mainform.action="/functions/search.aspx?search="+searchStr+"&site="+site;
	document.mainform.submit();
}
else{
	return false
}
}

// function calls moved from init to jquery below
function init(){}

/*
jp@addition.dk new menu with jquery
- with jQuery methods added, of course
*/



$(document).ready(function(){
	resetForms();
    $("#NavigationContainer li").hover(
		function(){ $("ul", this).slideDown("fast"); },
		function() { }
    );
    if (document.all) {
        $("#NavigationContainer li").hoverClass ("sfHover");
    }

});

$.fn.hoverClass = function(c) {
    return this.each(function(){
        $(this).hover(
            function() { $(this).addClass(c);  },
            function() { $(this).removeClass(c); }
        );
    });
};





