// JScript File

var MenuMaxHeight = null;
var MenuRunning = false;
var MenuTimerId = null;
var MenuNavigateTo = null;
var MenuClose = false;
var MenuOpen = false;

function menuFoldOut()
{
    if(MenuTimerId)
		clearTimeout(MenuTimerId);
		
    MenuTimerId = setTimeout(menuFoldOutTimer, 500);
}

function menuFoldOutTimer()
{
    MenuClose = false;
	if(MenuTimerId)
		clearTimeout(MenuTimerId);
	
	var _menu = $('navtop');
	
	if(MenuMaxHeight == null)
	{	    
	    var _liList = _menu.getElementsByTagName("li");
	    var MenuMaxHeight = 0;
	
	    for (var i = 0; i < _liList.length; i++)
	    {
	        var h = $(_liList[i]).getDimensions().height;
	        if (h > MenuMaxHeight)
	            MenuMaxHeight = h;
	    }
	    MenuMaxHeight += 5;
	    MenuMaxHeight += "px"; 
	    $("backgroundHolder").style.height = MenuMaxHeight;
	}
	
	if(MenuRunning == true)
	    MenuOpen = true;
	else if(_menu.style.height != MenuMaxHeight)
	{
	    MenuOpen = false;
		MenuRunning = true;
		var _newHeight = "height:" + MenuMaxHeight;
		new Effect.Morph(_menu,{
						  style:_newHeight,
						  duration: 0.75,
						  afterFinish: menuFold_Callback
						});
	}
}

function menuFoldIn()
{
    if(MenuTimerId)
		clearTimeout(MenuTimerId);
		
    MenuTimerId = setTimeout(menuFoldInTimer, 100);
}

function menuFoldInTimer()
{
    MenuOpen = false;
	var _menu = $('navtop');	
	if(MenuRunning == true)
		MenuClose = true;
	else if(_menu.style.height != "39px")
	{
		MenuClose = false;
		MenuRunning = true;
		new Effect.Morph(_menu,{
						  style:'height:39px',
						  duration: 0.5,
						  afterFinish: menuFold_Callback
						});
	}
}

function menuFold_Callback()
{
    MenuRunning = false;
	if(MenuNavigateTo)
		window.open(MenuNavigateTo, "_self");	
	else if(MenuClose == true)
		menuFoldInTimer();
	else if(MenuOpen == true)
		menuFoldOut();
}

function navigateToUrl(s)
{
    if(s)
		s.blur();
		
    MenuNavigateTo = s.href;
	menuFoldInTimer();
	return false;
}


function contactFold(s)
{
	if(s)
		s.blur();
		
	var _contact = $('contactForm');
	var _contactMap = $('googleMaps');
	var _contactA = $('contactFormA');
	var _contactMapA = $('googleMapsA');
	
	if(_contact.style.height=='0px')
	{
		new Effect.Morph(_contact,{
						  style:'height:250px'
						});	
		
		new Effect.Morph(_contactMap,{
						  style:'height:0px'
						});	
		
		_contactA.className = 'min';
		_contactMapA.className = 'plus';
	}
	else
	{
		new Effect.Morph(_contact,{
						  style:'height:0px'
						});
		
		new Effect.Morph(_contactMap,{
						  style:'height:262px'
						});	
		
		_contactA.className = 'plus';
		_contactMapA.className = 'min';
	}
	
}

function closePopUp(s)
{
	if(s)
		s.blur();
	
	var _popUpReserveer = $('popUpReserveer');	
	_popUpReserveer.style.display = 'none';
	_popUpReserveer.style.height = '0px';
	
	ProductPopUp.Hide();
}


function closeImagePopUp(s)
{
	if(s)
		s.blur();
		
	ImagePopUp.Hide();
}

function popUpOpenReserveer(s)
{
	if(s)
		s.blur();
	
	var _popUpReserveer = $('popUpReserveer');	
	_popUpReserveer.style.display = '';
	if(_popUpReserveer.style.height == '0px')
	{
		new Effect.Morph(_popUpReserveer,{
					    style:'height:200px',
				        duration: 0.75
					});
	}
	else
	{
		new Effect.Morph(_popUpReserveer,{
					    style:'height:0px',
				        duration: 0.5
					});
	}
}

function swapProduct(id, titel, tekst, afbeelding, afmetingen, prijs, afhalen)
{
    $('inputProductTitel').value = titel;
    $('productTitel').innerHTML = titel;
    $('productTekst').innerHTML = tekst;
    //$('productAfbeelding').src = afbeelding.replace(/&amp;/gi, "&");
    
    $('productAfmetingen').innerHTML = afmetingen;
    var _afmetingenBox = $('productAfmetingenBox');    
    if(afmetingen && afmetingen != '')
        _afmetingenBox.style.display = '';
    else
        _afmetingenBox.style.display = 'none';        
    
    $('productPrijs').innerHTML = prijs;    
    var _prijsBox = $('productPrijsBox');
    if(prijs && prijs != '')
        _prijsBox.style.display = '';
    else
        _prijsBox.style.display = 'none';

    var afhalenLabel = $('AfhalenLabel');
    var afhalenLeeuwarden = $('AfhalenLeeuwarden');
    var leeuwarden = $('Leeuwarden');
    var afhalenStadskanaal = $('AfhalenStadskanaal');
    var stadskanaal = $('Stadskanaal');
    
    switch(afhalen)
    {
       case 'Leeuwarden':
            afhalenLabel.style.display = '';
            afhalenLeeuwarden.style.display = '';
            leeuwarden.style.display = 'none';
            leeuwarden.checked = true;
            afhalenStadskanaal.style.display = 'none';
            stadskanaal.style.display = 'none';
            stadskanaal.checked = false;
            break;
        case 'Stadskanaal':
            afhalenLabel.style.display = '';        
            afhalenLeeuwarden.style.display = 'none';
            leeuwarden.style.display = 'none';
            leeuwarden.checked = false;
            afhalenStadskanaal.style.display = '';
            stadskanaal.style.display = 'none';
            stadskanaal.checked = true;
            break;
        case 'Beide':
            afhalenLabel.style.display = ''; 
            afhalenLeeuwarden.style.display = '';
            leeuwarden.style.display = '';
            leeuwarden.checked = false;
            afhalenStadskanaal.style.display = '';
            stadskanaal.style.display = '';
            stadskanaal.checked = false;
            break;
        default:            
            afhalenLabel.style.display = 'none'; 
            afhalenLeeuwarden.style.display = 'none';
            leeuwarden.style.display = 'none';
            leeuwarden.checked = true;
            afhalenStadskanaal.style.display = 'none';
            stadskanaal.style.display = 'none';
            stadskanaal.checked = false;
            break;
    }
        
    ProductPopUp.Show(); 
}


// functie voor IMG pop Up
var _imageToPopUp;
function swapImage(s, afbeelding, film)
{   
    ImagePopUp.ShowBackground(s);
    _imageToPopUp = afbeelding;
    var _movie = $('productFilm');
    var _image = $('productImgAfbeelding');
    
    if(film)
    {
        var FO = { movie:"S_Proxy.axd?f=Custom/Components/FrontEnd/flash/movie_player.swf&v=1", width:"330", height:"300",majorversion:"6", build:"40", wmode:"transparent", flashvars:"movieUrl=" + film };
        UFO.create(FO, "productFilm");
    
        _movie.style.display = "";
        _image.style.display = "none";
        
        ImagePopUp.Show();
    }
    else
    {
        Event.observe(_image, 'abort', function() { loadImage(_image) }); 
        Event.observe(_image, 'load', function() { ImagePopUp.Show(); }); 
        loadImage(_image);
        
        _image.style.display = "";
        _movie.style.display = "none";
    }    
}

function loadImage(o)
{
    o.src = _imageToPopUp;
}

// Einde functie IMG

function contactSend(o, h)
{
    $('Verzenden').blur();
    
    $('AjaxImage').src = 'Custom/Components/FrontEnd/images/ajax.gif';
    $('AjaxImage').style.display = '';
    $('Verzenden').style.display = 'none';
        
    WebService.ContactSend(o, h, contactSend_Response);
}

function contactSend_Response(response)
{   
    alert(response);
    
    $('AjaxImage').style.display = 'none';
    $('Verzenden').style.display = '';
    
    $('Bedrijfsnaam').value = '';
    $('Naam').value = '';
    $('Telefoon').value = '';
    $('Email').value = '';
    $('Bericht').value = '';
}

function reserveerSend(o, h)
{
    $('Verzenden').blur();

    $('AjaxImage').src = 'Custom/Components/FrontEnd/images/ajax.gif';
    $('AjaxImage').style.display = '';
    $('Verzenden').style.display = 'none';
        
    WebService.ReserveerSend(o, h, reserveerSend_Response);
}

function reserveerSend_Response(response)
{   
    var img = document.createElement("img");
    img.style.height = "1px";
    img.style.width = "1px";
    img.style.border = "0";
    img.src = "http://www.googleadservices.com/pagead/conversion/1059987784/?label=t0wmCObASRDIwrj5Aw&amp;script=0";
    document.body.appendChild(img);
    
    alert(response);
    
    $('AjaxImage').style.display = 'none';
    $('Verzenden').style.display = '';
    
    $('Bedrijfsnaam').value = '';
    $('Naam').value = '';
    $('Telefoon').value = '';
    $('Email').value = '';
    $('Adres').value = '';
    $('Postcode').value = '';
    $('Plaats').value = '';
    $('Bericht').value = '';
    
    popUpOpenReserveer();
}

function showHelpText(s)
{
    var _topMove = 10;        
    var _imgs = s.getElementsByTagName('img');
    var _img = _imgs[0];
    
    if (_img)
    {
        var v = "<b>" + s.id.replace("_Validator", "") + "</b><br/><br/>" + _img.alt.replace("\"", "'");
        var _div = $("HelpTekst");
        $("HelpTekstTarget").innerHTML = v;
        _div.style.display = 'block';
        _div.style.top = (S_General.Position.Top(s) + 5) + 'px';
        _div.style.left = (S_General.Position.Left(s) + 20) + 'px';
        _img.title = "";
    }
}

function initFlash()
{
    var FO = { movie:"Custom/Components/FrontEnd/flash/logo.swf", width:"375", height:"180",majorversion:"6", build:"40", wmode:"transparent", flashvars:"homeUrl=Default.aspx" };
    UFO.create(FO, "logo");

    var FOBottle = { movie:"Custom/Components/FrontEnd/flash/bottle_popping.swf", width:"319", height:"189" ,majorversion:"6", build:"40", wmode:"transparent" };
    UFO.create(FOBottle, "bottle");

    var FOBalloon = { movie:"Custom/Components/FrontEnd/flash/balloon_print.swf", width:"319", height:"189",majorversion:"6", build:"40", wmode:"transparent" };
    UFO.create(FOBalloon, "baloon");

    var FOBalloons = { movie:"Custom/Components/FrontEnd/flash/balloons_floating.swf", width:"319", height:"189",majorversion:"6", build:"40", wmode:"transparent" };
    UFO.create(FOBalloons, "baloons");
}

function initContactSjabloon()
{
    if (GBrowserIsCompatible()) 
    {
        var map = new GMap2(document.getElementById("googleMaps"));
        map.addControl(new GSmallMapControl());
        map.setCenter(new GLatLng(53.196728, 5.851872), 13);
        var icon = new GIcon();
        icon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
        icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
        icon.iconSize = new GSize(12, 20);
        icon.shadowSize = new GSize(22, 20);
        icon.iconAnchor = new GPoint(6, 20);
        icon.infoWindowAnchor = new GPoint(5, 1);
        var point = new GLatLng(53.200625, 5.835797);
        map.addOverlay(new GMarker(point, icon));
    }
    
    initValidatorCells();
}

function initProductgroepSjabloon()
{
    initValidatorCells();
}

function initBallondrukkerijSjabloon()
{
    initValidatorCells();
}

function initValidatorCells()
{
    var _tds = document.getElementsByTagName('td');
	
    for(var i=0;i<_tds.length;i++)
    {
        var _td = _tds[i];
        if(_td.id.indexOf('_Validator') >= 0)
        {
            _td.onmouseover = new Function("showHelpText(this);");
            _td.onmouseout = new Function("$('HelpTekst').style.display = 'none';");
            _td.alt = "";
        }
    }	  
}

//      ************************************
//
//			van pagina naar action.js
//
//     ************************************

    

function drukkerijOpenVraagOfferteAan(s)
{
	if(s)
		s.blur();
	
	var _popUpReserveer = $('prijsCalcOfferte');	
	_popUpReserveer.style.display = '';
	if(_popUpReserveer.style.height == '0px')
	{
		new Effect.Morph(_popUpReserveer,{
					    style:'height:300px',
				        duration: 0.75
					});
	}
	else
	{
		new Effect.Morph(_popUpReserveer,{
					    style:'height:0px',
				        duration: 0.5
					});
	}
}

function drukkerijOpenVraagOfferteSend(o, h)
{
    $('Verzenden').blur();

    $('AjaxImage').src = 'Custom/Components/FrontEnd/images/ajax.gif';
    $('AjaxImage').style.display = '';
    $('Verzenden').style.display = 'none';
    
    WebService.DrukkerijOfferteSend(o, h, drukkerijOpenVraagOfferte_Response);
}

function drukkerijOpenVraagOfferte_Response(response)
{   
    alert(response);
    
    $('AjaxImage').style.display = 'none';
    $('Verzenden').style.display = '';
    
    drukkerijOpenVraagOfferteAan();
}

function selectColor(colorName, thumbURL, category) {
	var colorTxt = document.getElementById('colorTxt');
	if(colorTxt)
	{
		var dirs = new Array('afbeeldingen_pastel','afbeeldingen_metallic','afbeeldingen_crystal');
		colorTxt.innerHTML = "U heeft gekozen voor de kleur: <img src='Custom/Components/FrontEnd/images/" + dirs[category] + "/thumbnails/" + thumbURL + "' /> " + colorName;

		document.forms.calculatorForm.color[category].checked = true;
		$('Kleur').value = colorName;

		calculatePrice();
		
		AjaxValidation_ValidateControl(_Validator1_ValidationGroup, null, "Categorie", null);
		AjaxValidation_ValidateControl(_Validator1_ValidationGroup, null, "Kleur", null);		
	}
}

function changeHoeveelheid()
{
	selectedIndex = document.getElementById('Hoeveelheid').selectedIndex;
	
	var doublesided = document.getElementById('dubbelside');
	var singlesided = document.getElementById('enkelside');
	
	var print1logo1 = document.getElementById('print1logo1');
	var print1logo2 = document.getElementById('print1logo2');
	var print1logo3 = document.getElementById('print1logo3');

	var print2logo2 = document.getElementById('print2logo2');
	var print2logo3 = document.getElementById('print2logo3');


	if(selectedIndex == 1)
	{
		//disable the doublesided-option
		doublesided.disabled = true;
		singlesided.checked = true;
		changeSides();

		//disable singlesided logo colours 2 & 3
		print1logo2.disabled = true;
		print1logo3.disabled = true;

		if(print1logo2.checked || print1logo3.checked)
		{
			print1logo1.checked = true;
		}
	}
	else if ( selectedIndex < 7 && selectedIndex > 0)
	{
		//disable logo colour 3
		print1logo3.disabled = true;
		print2logo3.disabled = true;

		if(print1logo3.checked)
		{
			print1logo2.checked = true;
		}
		if(print2logo3.checked)
		{
			print2logo2.checked = true;
		}

		doublesided.disabled = false;
		print1logo2.disabled = false;

	}
	else
	{
		document.getElementById('dubbelside').disabled = false;
		document.getElementById('print1logo2').disabled = false;
		document.getElementById('print1logo3').disabled = false;
		document.getElementById('print2logo3').disabled = false;
	}
	calculatePrice();
}

function changeSides()
{
	var sidesRB = document.calculatorForm.sides;
	var blockPrint2 = document.getElementById('block_print2');
	if(sidesRB[0].checked)
	{
		//when singlesided selected, disable the print for side 2
		blockPrint2.style.display = "none";
	}
	else if ( sidesRB[1].checked )
	{
		//when doublesided selected, enable the print for side 2
		blockPrint2.style.display = "";
	}

	calculatePrice();
}

function calculatePrice()
{
    var priceColorMetallicPer100 = 3;
    var priceColorCrystalPer100 = 3;

    var priceDoubleSided = 14;

    var priceOneColor = 45;
    var priceTwoColors = 90;
    var priceTwoColorsPer1000 = 9.5;
    var priceThreeColors = 135;
    var priceThreeColorsPer1000 = 19;

    var pricesBalloons = new Array(
					    81, //500
					    99, //1000
					    139, //1500
					    189, //2000
					    269, //3000
					    359, //4000
					    429, //5000
					    519, //6000
					    599, //7000
					    689, //8000
					    769, //9000
					    799 //10000
					    );
					
	var showCalculation = document.getElementById('showCalculation');

	var HoeveelheidList = document.getElementById('Hoeveelheid');
	var Hoeveelheid = HoeveelheidList.options[HoeveelheidList.selectedIndex].value;
	
	var totalPrice = 0;
	var priceHoeveelheid = 0;
	var priceColor = 0;
	var priceSides = 0;
	var pricePrint1 = 0;
	var pricePrint2 = 0;

	showCalculation.innerHTML = "";

	//first calculate Hoeveelheid
	totalPrice += pricesBalloons[HoeveelheidList.selectedIndex -1];
	showCalculation.innerHTML += "<b>Hoeveelheid</b>: " + pricesBalloons[HoeveelheidList.selectedIndex -1] + "<br/>";

	//calculate colors
	var colorRB = document.calculatorForm.color;

	if(colorRB[1].checked)
	{
		priceColor = priceColorMetallicPer100 * (Hoeveelheid/100);
	}
	else if(colorRB[2].checked)
	{
		priceColor = priceColorCrystalPer100 * (Hoeveelheid/100);
	}
	showCalculation.innerHTML += "<b>Color</b>: " + priceColor + "<br/>";
	totalPrice += priceColor;

	//calculate single or double sided
	var sidesRB = document.calculatorForm.sides;
	if(sidesRB[1].checked)
	{
		priceSides = priceDoubleSided * (Hoeveelheid/1000);
	}
	showCalculation.innerHTML += "<b>Sides</b>: " + priceSides + "<br/>";
	totalPrice += priceSides;

	//calculate print side 1
	var print1RB = document.calculatorForm.print1;
	if(print1RB[0].checked)
	{
		pricePrint1 = priceOneColor;
	}
	else if(print1RB[1].checked)
	{
		pricePrint1 = priceTwoColors;
		pricePrint1 += priceTwoColorsPer1000 * (Hoeveelheid/1000);
	}
	else if(print1RB[2].checked)
	{
		pricePrint1 = priceThreeColors;
		pricePrint1 += priceThreeColorsPer1000 * (Hoeveelheid/1000);
	}
	totalPrice += pricePrint1;
	showCalculation.innerHTML += "<b>Print side 1</b>: " + pricePrint1 + "<br/>";

	//calculate print side 2, if doublesided is checked
	if(sidesRB[1].checked)
	{
		var print2RB = document.calculatorForm.print2;

		if(print2RB[0].checked)
		{
			pricePrint2 = priceOneColor;
		}
		else if(print2RB[1].checked)
		{
			pricePrint2 = priceTwoColors;
			pricePrint2 += priceTwoColorsPer1000 * (Hoeveelheid/1000);
		}
		else if(print2RB[2].checked)
		{
			pricePrint2 = priceThreeColors;
			pricePrint2 += priceThreeColorsPer1000 * (Hoeveelheid/1000);
		}
		totalPrice += pricePrint2;
	}
	showCalculation.innerHTML += "<b>Print side 2</b>: " + pricePrint2 + "<br/>";
	
    if(isNaN(totalPrice))
        document.getElementById('totalPrice').innerHTML = "&euro; -";
    else
	    document.getElementById('totalPrice').innerHTML = "&euro; " + totalPrice.toString().replace(".", ",");
	   
	document.getElementById('totalPriceInput').value = document.getElementById('totalPrice').innerHTML; 	
}