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="/images/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="/images/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="/images/video.swf?video='+src+'&duration='+totalTime+'" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><embed src="/images/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="/images/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(id)
	{
	l=(screen.availWidth-890)/2
	t=(screen.availHeight-500)/2
	a=window.open('/Functions/ProductComparison.aspx?hid='+id,'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(id)
	{
	
	l=(screen.availWidth-890)/2
	t=(screen.availHeight-500)/2

	a=window.open('/Functions/ProductComparison.aspx?hid='+id,'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.forms[0].__VIEWSTATE.value = "";
	document.mainform.searchMain.value = searchStr;
	document.mainform.method="post";
	//document.mainform.action="/functions/search.aspx?search="+searchStr+"&site="+site;
	document.mainform.action="/search.aspx?q="+encodeURI(searchStr);//+"&site="+site;
	document.mainform.submit();
}
else{
	return false
}
}


function postSearchIdleSurf(searchStr,site){
if(searchStr != ""){
    if(document.forms[0].__VIEWSTATE){
	    document.forms[0].__VIEWSTATE.enabled = false;

	}
	
	document.mainform.searchMain.value = searchStr;
	document.mainform.method="post";
	//document.mainform.action="/functions/search2.aspx?search="+searchStr+"&site="+site;
	document.mainform.action="/search.aspx?q="+encodeURI(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");
    }*/
});

$(document).ready(function(){
						   
	$("#NavigationContainer > li").hover(function() {
			$("#NavigationContainer li").removeClass("sfHover");
			$(this).addClass("sfHover");
		},function() {
			$(this).removeClass("sfHover");
//			alert("mouse out");
		}
	);					   
						   
						   
						   
    $("#header_mini_nav li").hover(
		function(){ $("ul", this).slideDown("fast"); }, 
		function() { } 
    );
    if (document.all) {
        $("#header_mini_nav li").hoverClass ("sfHover");
    }    
});

$.fn.hoverClass = function(c) {
    return this.each(function(){
        $(this).hover( 
            function() { $(this).addClass(c);  },
            function() { $(this).removeClass(c); }
        );
    });
};

function go(loc) {
// the function is used when submitting the Variants on the product techspec and Accessories pages
window.location.href = loc;
}

function doSearch(){

    document.forms[0].__VIEWSTATE.disabled = true;
    document.forms[0].quickSearchBtn.disabled = true;
    document.forms[0].btnG.disabled = true;
    document.mainform.method="get";

    
    var q = '?q=';
    if(qBox != null){
        q += encodeURI(qBox.value);
    }
    var url = '';
    
    // check if it's advanced search or not
    var el = document.getElementById("advancedSearch");
    var display = el.style.display;
    
    // simple search
    if(display == "none"){
        // the query words
        var qBox = document.getElementById('q');
        
        if(qBox != null){
            q += encodeURI(qBox.value);
        }
       
        url += q;
        // HACK, dont show files in normal search
       //url += '&as_filetype=pdf&as_filetype=doc&as_filetype=ps&as_filetype=ppt&as_filetype=xls&as_filetype=rtf'
        
        document.location = url;
        return;
    }
    
    // advanced search takes search words from as_q
    var as_q = document.getElementById('as_q');
    
    q += encodeURI(as_q.value);
    url += q;    
    
    // exact words
    var as_epq = document.getElementById('as_epq');
    if(as_epq != null && as_epq.value != ''){
        url += '&as_epq=' + encodeURI(as_epq.value);
    }
    
    // one of the words at least
    var as_oq = document.getElementById('as_oq');  
    if(as_oq != null && as_oq.value != ''){
        url += '&as_oq=' + encodeURI(as_oq.value);
        
    }
    // and without the words
    var as_eq = document.getElementById('as_eq');
    if(as_eq != null && as_eq.value != ''){
        url += '&as_eq=' + encodeURI(as_eq.value);
    }
    // filetype filtering
    var as_ft = document.getElementById('as_ft');
    if(as_ft != null && as_ft.value != ''){
        url += '&as_ft=' + encodeURI(as_ft.value);
    }
    
    var as_filetype = document.getElementById('as_filetype');
    if(as_filetype != null && as_filetype.value != ''){
        url += '&as_filetype=' + encodeURI(as_filetype.value);
    }
  
    
    // the number of results in page
    var num = document.getElementById('num');
    if(num != null){
        url += '&num=' + num.value;
    }
   
    
    document.location = url;
    
//    document.mainform.submit();
}

function gotoURL(pUrl,indexNum) {
		if (pUrl != '') { 
			url = new String(pUrl);
			window.location.href = url;
	}
}


function changeMZProductsByBrand(ddlID,customerBrand) 
{

	var select = document.getElementById(ddlID);
	
	if (select != null) 
	{
		for (i=0; i<3; i++) 
		{
			if (i == select.selectedIndex) 
			{
				document.getElementById(customerBrand + i).style.display = "inline";
				document.getElementById(customerBrand + i).selected = "selected";	
						
			}
			else 
			{
				document.getElementById(customerBrand + i).style.display = "none";
			}
			
		}
	}

}


function changeMZDiscountPrice(selectID, productSitecoreID) 
{
	var select = document.getElementById(selectID);
	if (select != null) 
	{
		for (i=0; i<6; i++) 
		{
			if (i == select.selectedIndex) 
			{
				document.getElementById(productSitecoreID + i).style.display = "inline";
			}
			else 
			{
				document.getElementById(productSitecoreID + i).style.display = "none";
			}
			
		}
	}
}

function productsLoading(){
	document.getElementById('load').style.display = 'block';
}
