/**
 *  common.jsBy 2G B.V.
 *  
 *  © copyright 2005 - 2008 2G B.V. All rights reserved.
 *  The computer program(s) is the proprietary information of the original authors. 
 *  and provided under the relevant License Agreement containing restrictions 
 *  on use and disclosure. Use is subject to the License Agreement.
 *
 *  No part of this package may be reproduced and/or published by print, 
 *  photoprint, microfilm, audiotape, electronically, mechanically or any other means, 
 *  or stored in an information retrieval system, without prior permission from 2G B.V. www.2g-it.nl.
 * 
 *  @original authors: jcgeuze
 */
function showMenu(oEvent, oSourceObject, oSubMenu)
{
	//Close other menus.
	closeMenusByBruteForce();
	oSourceObject.className = 'clsNormalMenuBackgroundOver';
	oSubMenu.style.display = "";
	
	oEvent.cancelBubble = true;
}//showMenu

function closeMenusByBruteForce()	{	closeMenu(true);	}//closeMenusByBruteForce
function closeMenu(oEvent)
{
	var bContinue = false;
	
	if (typeof(oEvent) == "boolean" && oEvent == true)
	{
		//by brute force.
		bContinue = true;
	}
	else if (oEvent.y > 352 && oEvent.y < 451 && oEvent.x > 192 && oEvent.x < 747)
	{
		//within menu area
	}
	else
	{
		bContinue = true;
	}
	
	if (bContinue == true)
	{
		for (var iCount = 0; iCount < asSubMenus.length; iCount++)
		{
			var oTableObject = document.getElementById(asSubMenus[iCount]);
			try
			{
				oTableObject.style.display = 'none';
				getTagParent(oTableObject, "TABLE").className = 'clsNormalMenuBackground';
			} 
			catch (e) {}
		}
	}
}//closeMenu

function showPageMenu(oEvent, oSourceObject, oSubMenu, oNumberItem)
{
	//Close other menus.
	closeSubPageMenusByBruteForce();
	
	document.getElementById("divTopMenu").style.postion = 'absolute';
	document.getElementById("divTopMenu").style.left = oEvent.x;
	oSubMenu.style.postion = 'absolute';
	oSubMenu.style.left = oNumberItem.currentStyle.left;
	oSubMenu.style.top = oNumberItem.currentStyle.top;
	oSubMenu.style.left = oNumberItem.currentStyle.left;

	oSourceObject.className = 'clsNormalMenuBackgroundOver';
	oSubMenu.style.display = "";
	
	oEvent.cancelBubble = true;
}//showPageMenu
function closeSubPageMenusByBruteForce()	{	closeSubPageMenu(true);	}//closeSubPageMenusByBruteForce
function closeSubPageMenu(oEvent)
{
	var bContinue = false;
	
	if (typeof(oEvent) == "boolean" && oEvent == true)
	{
		//by brute force.
		bContinue = true;
	}
	else if (oEvent.y > 99 && oEvent.y < 151 && oEvent.x > 192 && oEvent.x < 747)
	{
		//within menu area
	}
	else
	{
		bContinue = true;
	}
	
	if (bContinue == true)
	{
		for (var iCount = 0; iCount < asSubMenus.length; iCount++)
		{
			var oTableObject = document.getElementById(asSubMenus[iCount]);

			//oTableObject.style.display = 'none';
			getTagParent(oTableObject, "DIV").className = 'clsNormalMenuBackground';
		}
	}
}//closeSubPageMenu

function showXY(oEvent)
{
	var sText = "X=" + oEvent.x + "  Y=" + oEvent.y;
	//window.status = sText;
}

function setHomeMenuClassOverByPicture(oEvent) 
{
	try
	{
		var iX = 0;
		if (oEvent.layerX)
		{
			iX = oEvent.layerX;
		}
		else
		{
			iX = oEvent.offsetX;
		}
		
		//window.status = iX;
		closeMenusByBruteForce();
		
		var oSourceObject, oSubMenu;
		if (iX >= 0 && iX < 189) 
		{
			oSourceObject = document.getElementById('headmenu_1');
			oSubMenu = document.getElementById('submenu_1');
		}
		else if (iX >= 190 && iX < 380) 
		{
			oSourceObject = document.getElementById('headmenu_2');
			oSubMenu = document.getElementById('submenu_2');
		}
		else if (iX >= 380 && iX < 570) 
		{
			oSourceObject = document.getElementById('headmenu_3');
			oSubMenu = document.getElementById('submenu_3');
		}
		else if (iX >= 570 && iX < 760) 
		{
			oSourceObject = document.getElementById('headmenu_4');
			oSubMenu = document.getElementById('submenu_4');
		}
	    
		oSourceObject.className = 'clsNormalMenuBackgroundOver';
		oSubMenu.style.display = "";
    }
    catch(e)	{}
    
	oEvent.cancelBubble = true;
}//setHomeMenuClassOverByPicture

function setHomeMenuClassOver(oSourceObject)
{
	oSourceObject.className = 'clsMenuSubItemOver';
	oSourceObject.childNodes[0].style.color = 'white';
	//clsMenuHref
}//setHomeMenuClassOver
 
function setHomeMenuClassOut(oSourceObject)
{
	oSourceObject.className = 'clsMenuSubItemHome';
	oSourceObject.childNodes[0].style.color = 'black';
}//setHomeMenuClassOut

function setMenuClassOver(oSourceObject)
{
	oSourceObject.className = 'clsMenuSubItemOver';
	oSourceObject.childNodes[0].style.color = 'white';
	//clsMenuHref
}//setMenuClassOver
 
function setMenuClassOut(oSourceObject)
{
	//oSourceObject.className = 'clsMenuSubItem';
	oSourceObject.childNodes[0].style.color = 'black';
}//setMenuClassOut

function fixIEScrollBug(divWhichDoesScroll)
{
	var isIE = window.ActiveXObject ? true : false;
	if (isIE == true)
	{
		divInnerProducts.style.right = divWhichDoesScroll.scrollLeft;
	}
}//fixIEScrollBug

/**
 * This method returns the first parent of htmlObj who's tagname is sTagname. If no 
 * parent is found with sTagname null is returned.
 *
 * @param htmlObj 	The HTML-object to start the search.
 * @param sTagname 	The name of the tag to search for.
 *
 * @return The first ancestor in the tree that is the tag which is defined.
 */
function getTagParent(htmlObj, sTagname)
{
	var oReturn = null;
	
	var currElement = htmlObj.parentNode;
	while (currElement != null)
	{
		if (("" + currElement.tagName).toUpperCase() == sTagname.toUpperCase())
		{
			oReturn = currElement;
			break;
		}
		currElement = currElement.parentNode;
	}
	
	return oReturn;
}//getTagParent

function updateCursorPrevious(sSiteURL, iCursor, sHeadCategory, sSubCategory, sSubCategoryDescription)
{
	iCursor = parseInt(iCursor, 10);
	iCursor -= 10;
	if (iCursor < 0)
	{
		iCursor = 0;
	}
	
	fireCursor(sSiteURL, iCursor, sHeadCategory, sSubCategory, sSubCategoryDescription);
}//updateCursorPrevious

function updateCursorNext(sSiteURL, iCursor, iMaxCursor, sHeadCategory, sSubCategory, sSubCategoryDescription)
{
	iCursor = parseInt(iCursor, 10);
	iCursor += 10;
	
	if (iCursor >= iMaxCursor)
	{
		iCursor = 0;
	}
	
	fireCursor(sSiteURL, iCursor, sHeadCategory, sSubCategory, sSubCategoryDescription);
}//updateCursorNext

function fireCursor(sSiteURL, iCursor, sHeadCategory, sSubCategory, sSubCategoryDescription)
{
	//http://www.kuras.nl/producten/Sandwichpanelen/Dak/29/0/Sandwichpanelen_Dak.html
	//http://www.kuras.nl/producten/Sandwichpanelen/Dak/Sandwichpanelen/10/Sandwichpanelen_Dak.html
	var sNewLocation = sSiteURL + 'producten/' + sHeadCategory + '/' + sSubCategoryDescription + '/' + sSubCategory + '/' + iCursor + '/' + sHeadCategory + '_' + sSubCategoryDescription + '.html';
	
	window.location = sNewLocation;
}//fireCursor

function selectText(oSourceObject)
{
	if (oSourceObject.value == "type zoek woord")
	{
		oSourceObject.value = "";
	}
	oSourceObject.createTextRange().select();
	
	try
	{
		oSourceObject.focus();
	}
	catch (eFailedToSetFocus) { /* IGNORE */ }
}//selectText

function keydown_performSearchFromSubPage(oEvent)
{
	var eKey = -1;
	if (typeof(oEvent) == "undefined")
	{
		//IE
		eKey = event.keyCode;
	}
	else
	{
		//Firefox...
		eKey = oEvent.keyCode;
	}
	//var eKey = event.keyCode;
	if (eKey == 13)
	{
		performSearchFromSubPage();
	}
}//keydown_performSearchFromSubPage

function keydown_performSearch(oEvent)
{
	var eKey = -1;
	if (typeof(oEvent) == "undefined")
	{
		//IE
		eKey = event.keyCode;
	}
	else
	{
		//Firefox...
		eKey = oEvent.keyCode;
	}
	//var eKey = event.keyCode;
	if (eKey == 13)
	{
		performSearch();
	}
}//keydown_performSearch

function performSearch()
{
	var oSearchBox = document.getElementById("txtSearch");
	var sValue = oSearchBox.value;
	if (sValue != "" && sValue != " " && sValue != "type zoek woord")
	{
		sValue = sValue.replaceAll(" ", "_S_");
		var sURL = g_sSiteURL  + 'zoeken/' + sValue + '/kuras_zoek_resultaat_' + sValue + '.html';
		window.location = sURL;
	}
}//performSearch

String.prototype.replaceAll = function (sOriginal, sDestination) 
{
	var sReturn = this;
	
	//couldn't find a replaceAll function in the js API, so here it goes:
	while (sReturn.indexOf(sOriginal) >= 0) 
	{
    	sReturn = sReturn.replace(sOriginal, sDestination);
	}
	
	return sReturn;
}//replaceAll

function performSearchFromSubPage()
{
	var oSearchBox = document.getElementById("txtSearch");
	var sValue = oSearchBox.value;
	
	/*
	var sURL ='?page=search&searchtext=' + sValue;
	if (getURLParam("page") != "")
	{
		sURL += "&previouspage=" + getURLParam("page");
		if (getURLParam("cursor") != "")
		{
			sURL += "&cursor=" + getURLParam("cursor");
		}
		if (getURLParam("sub_categorie") != "")
		{
			sURL += "&sub_categorie=" + getURLParam("sub_categorie");
		}
		if (getURLParam("categorie") != "")
		{
			sURL += "&categorie=" + getURLParam("categorie");
		}
	}
	window.location = sURL;
	*/
	if (sValue != "" && sValue != " " && sValue != "type zoek woord")
	{
		sValue = sValue.replaceAll(" ", "_S_");
		var sPreviousURL = window.location.href;
		sPreviousURL = sPreviousURL.substring(g_sSiteURL.length, sPreviousURL.length);
		
		var iHTMLIndex = sPreviousURL.indexOf(".html");
		sPreviousURL = sPreviousURL.substring(0, iHTMLIndex);
		sPreviousURL = sPreviousURL.replaceAll("/", "_H_");
		
		var sURL = g_sSiteURL  + 'sub_zoeken/' + sValue + '/' + sPreviousURL + '/kuras_zoek_resultaat_' + sValue + '.html';
		window.location = sURL;
	}
}//performSearchFromSubPage

/**
 * This method analyzes the URL and returns a parameter.
 *
 * @param strParamName	The name of the param to return.
 *
 * @returns The value of the parameter or an empty string if the parameter was not found.
 */
function getURLParam(strParamName)
{
  var strReturn = "";
  var strHref = window.location.href;
  if ( strHref.indexOf("?") > -1 )
  {
    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
    var aQueryString = strQueryString.split("&");
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ )
	{
      if (aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 )
	  {
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
    }
  }
  return unescape(strReturn);
}//getURLParam


/** This is high-level function; REPLACE IT WITH YOUR CODE.
* It must react to delta being more/less than zero.
*/
function handle(delta) 
{
	if (document.getElementById("divOuterProducts") != null)
	{
		delta = delta * 20;
		var oDiv = document.getElementById("divInnerProducts");
		if (oDiv != null)
		{
			var iOriginalRight = oDiv.style.right;
			if (oDiv.style.right == "" || parseInt(oDiv.style.right, 10) == 0)
			{
				oDiv.style.right = 0;
			}
			var iTemp = parseInt(oDiv.style.right, 10) - delta;
			if (iTemp > 0)
			{
				oDiv.style.right = iTemp;
			}
			
			if (delta < 1 && parseInt(oDiv.style.right, 10) > 2200)
			{
				//Get next 10.
				//debugger
				//document.getElementById("divOuterProducts").scrollLeft = parseInt(oDiv.style.right, 10) + 1300;
				oDiv.style.right = iOriginalRight//iTemp * 100;
				
			}
		}
		if (delta < 1 && parseInt(oDiv.style.right, 10) > 2200)
		{
		}
		else
		{
			document.getElementById("divOuterProducts").scrollLeft = parseInt(oDiv.style.right, 10);
		}
	}
}
 
function wheel(event)
{
        var delta = 0;
        if (!event) event = window.event;
        if (event.wheelDelta) {
                delta = event.wheelDelta/120; 
                if (window.opera) delta = -delta;
        } else if (event.detail) {
                delta = -event.detail/3;
        }
        if (delta)
                handle(delta);
}
 
/* Initialization code. */
if (window.addEventListener)
        window.addEventListener('DOMMouseScroll', wheel, false);
window.onmousewheel = document.onmousewheel = wheel;


function displayContactForm()
{
	document.getElementById("divContactTitle").innerHTML = 'Contact met Kuras';
	document.getElementById("divContactAddress").style.display = "none";
	document.getElementById("divContactForm").style.display = "";
	document.getElementById("contact_name").focus();
}//displayContactForm

function hideContactForm()
{
	document.getElementById("divContactTitle").innerHTML = 'Hoe contact u ons?';
	document.getElementById("divContactAddress").style.display = "";
	document.getElementById("divContactForm").style.display = "none";
}//hideContactForm

function reloadPageAfterSend()
{
	hideContactForm();
}//reloadPageAfterSend

function reloadPageAfterError()
{
	displayContactForm();
}//reloadPageAfterError

function displayRoute()
{
	//var isIE = window.ActiveXObject ? true : false;
	//http://maps.google.nl/maps?hl=en&ie=UTF8&q=kuras+kootwijkerbroek&fb=1&gl=nl&hq=kuras&hnear=Kootwijkerbroek&cid=0,0,2725187714232656810&ei=uwwrTI2cEY-jOKaH6bID&ved=0CBIQnwIwAA&ll=52.149067,5.658174&spn=0.008071,0.018582&z=16&iwloc=A
	//if (isIE)
	//{
		//window.open("http://maps.google.com/maps?f=d&geocode=&saddr=&daddr=De Spil 4 3774 SE Kootwijkerbroek Nederland");
		//window.open("http://maps.google.com/maps?f=d&geocode=&saddr=&daddr=52.150719,5.654547");
		window.open("http://maps.google.nl/maps?hl=en&ie=UTF8&q=kuras+kootwijkerbroek&fb=1&gl=nl&hq=kuras&hnear=Kootwijkerbroek&cid=0,0,2725187714232656810&ei=uwwrTI2cEY-jOKaH6bID&ved=0CBIQnwIwAA&ll=52.149067,5.658174&spn=0.008071,0.018582&z=16&iwloc=A");
	//}
}//displayRoute

function fireClickEvent(oControl)
{ 
    if (document.all) 
    {
		//IE
        oControl.fireEvent("onclick"); 
    } 
    else 
    { 
		//Firefox, etc.
        var clickEvent = window.document.createEvent("MouseEvent"); 
        clickEvent.initEvent("click", false, true); 
        oControl.dispatchEvent(clickEvent); 
    }
}//fireClickEvent

function displayLeveringsVoorwaarden()
{
	// OLD:
	// window.open("http://www.kuras.nl/Algemene_voorwaarden_van_Kuras.pdf");
	
	// New:
	window.open("http://www.hibin.nl/bestanden/pdf/AVLB-digitaal.pdf");
}//displayLeveringsVoorwaarden
