﻿var maat = "";
var aantal = "1";
var debug = true;

function AddToCart(productid, currentindex)
{   
    try
    {   
        addtocart = true;
        
        var form = $('aspnetForm');
        var iskleding = form['iskleding'];

        if ($F(iskleding) == "1")
        {
            if (maat.length == 0)
            {                
                $('kiesmaat').show();
                //alert("geen maat gekozen");
                return;
            }
            else
            {
                $('kiesmaat').hide();
            }
        }
                         
        location.href = "/shop.aspx?addtocart=" + productid + "&quantity=" + aantal + "&currentindex=" + currentindex + "&maat=" + maat;        
        return false;
    }
    catch (e)
    {
        alert(e.message);
    }
}
function AdjustQuantity(productid, quantity)
{
    try
    {        
        document.location.href = "/checkout.aspx?changequantity=" + productid + "&quantity=" + quantity;
    }
    catch (e)
    {
        if (debug) alert(e.message);
    }
}
function SendDiscountCode(discountcode)
{
    try
    {        
        document.location.href = "/checkout.aspx?kortingscode=" + discountcode;
    }
    catch (e)
    {
        if (debug) alert(e.message);
    }    
}

function Updatefield(field, val)
{
    try
    {        
        if ($j('#' + field + ':checked').val() != null)        
            document.location.href = "/checkout.aspx?updatefield=" + field + "&val=true";        
        else
            document.location.href = "/checkout.aspx?updatefield=" + field + "&val=false";
    }
    catch (e)
    {
        if (debug) alert(e.message);
    }
}

//function ShowHideInvoice()
//{
//    
//    var form = $('aspnetForm');
//    var cb = form['ctl00_cph_body_content_CreateUserWizard1_cbInvoiceAddressIsSame'];
//    
//    try
//    {
//        if ($F(cb) == null)
//            $('invoiceadres').show();
//        else
//            $('invoiceadres').hide();       
//            
//    }
//    catch (e)
//    {
//        alert(e.message);
//    }
//}

function CheckUser()
{
    var form = $('aspnetForm');
    var user = form['ctl00_cph_body_content_CreateUserWizard1_tbEmailAddress'];
    
    try
    {
        alert('checkuser not implemented yet');
    }
    catch (e)
    {
        if (debug) alert(e.message);
    }    
}

function CreateBookmarkLink() 
{
 
 title = document.title; 
 url = window.location.href;
 
    if (window.sidebar) { // Mozilla Firefox Bookmark
        window.sidebar.addPanel(title, url,"");
    } else if( window.external ) { // IE Favorite
        window.external.AddFavorite( url, title); }
   else if(window.opera && window.print) { // Opera Hotlist
       return true; }
}


function hyvestip(ttle,bdy)
{
    try
    {
        Hyves.connect.tip({title: ttle, body: bdy, category:'9'});
    }
    catch (e)
    {
        if (debug) alert(e.message);
    }
}

var currentOpenId = null;

function Collapse(id)
{
    try
    {        
        if (id == currentOpenId || $(id).getHeight() == 0)
        {
            currentOpenId = null;
            Effect.SlideUp(id); 
        }
        else
        {
            if (currentOpenId != null)
                Effect.SlideUp(currentOpenId);
                
            currentOpenId = id;
            Effect.SlideDown(id); 
        }
        
        return false;    
    }
    catch (e)
    {
        if (debug) alert(e.message);
    } 
}

function DoUpdate(pageid, containerid, pageurl)
{
    try
    {        
        if (containerid != currentOpenId)
        {
          
            UpdateContent(pageid);
        }
        
        Collapse(containerid);
        
        pageTracker._trackPageview(pageurl);         
        return false;
    }
    catch (e)
    {
        if (debug) alert(e.message);
    }
}
function UpdateContent(pageid)
{
    try
    {                
        var url = '/shop.aspx?q=' + pageid;
        
        new Ajax.Request(url, {
                method: 'get',
             onSuccess: function(transport) {                             
                $('content-rt').update(transport.responseText);                
            }
        });    
    }
    catch (e)
    {
       if (debug) alert(e.message);
    }
}

// alle sub cats inklappen
  Event.observe(window, 'load', function() {
    try
    {
        if(!$('main')) return; // bestaat main menu?
        
        var list = $('main').select('[class="subcat"]');	
        var i = 0;
  
        for (i=0; i < list.length;i++)
        {
            Effect.SlideUp(list[i].id, { duration: 0.0 });         
        }
    
        list = $('main').select('[class="selcat"]');
    
        if (list.length == 1)
            currentOpenId = list[0].id;  
        }
    catch (e)
    {
        if (debug) alert(e.message);
    }
});

function PrintOnProductDetail()
{   
    try
    {
        var nodes = $('tabnav_content').select('[class="txt"]');
    
        if (nodes != null)
        {
            Print(nodes[0].innerHTML);
        }    
        else
            alert('nodes empty');    
    }
    catch (e)
    {
        //if (debug) alert(e.message);
    }
}

function Print(TextToPrint)
{
	var a = window.open('','','width=1000,height=1000');
	a.document.open("text/html");
	a.document.write('<link rel="stylesheet" type="text/css" href="/css/print.css" media="All" title="Mediaweb (print)"  />');
	
	a.document.write(TextToPrint);
	a.document.close();
	a.print();
}

var checkout_id = 'ctl00_cph_body_content_';

function ShowLogin()
{
    $('checkout_login').show();
    $(checkout_id + 'checkout_geg_invullen').hide();   
    $(checkout_id + 'id_keuze').hide();   
     
}
function ShowInvulGeg()
{
    
    
    $('checkout_login').hide();
    $(checkout_id + 'checkout_geg_invullen').show();  
    $(checkout_id + 'id_keuze').hide();  
}
function HideLogin()
{
    $('checkout_login').hide();
    $(checkout_id + 'checkout_geg_invullen').show();  
}



// Pakjegemak


// Pakjegemak
var initialAddress;
var srcUrlAddres;
var srcUrl;
var containerid = 'ctl00_cph_body_content_CreateUserWizard1_';

initialAddress = '';

srcUrl = "http://www.locatiekiezer.nl/Default.aspx?apikey=9a2ce75748068773&productlabel=zad&stylesheet=&passdataurl=";

function getAddress(){
	try{	   
		var address = document.getElementById("txtAddress").value;  
	}
	catch(e){
		if (debug) alert(e.message);
	}
	return address;
}
function ShowPopup(){
    var url
	var form = $('aspnetForm');
	var frame;
	var dataPassUrl;
	
	try
	{
	    dataPassUrl = form[containerid + 'hfpjgPassDataUrl'].value;    		
	    srcUrlAddres = "&address=" + initialAddress;
	    url = srcUrl + dataPassUrl + srcUrlAddres;
	    frame = "<iframe id='iFramePopup' name='iFramePopup' src='" + url + "' frameborder='0' scrolling='no'></iframe>";
	    
	    $('divPopup').update(frame);
	    new Dialog.Box('divPopup');	   
	    	     
        $('divPopup').show();	    
	}
	catch (e)
	{
	    if (debug) alert("ShowPopup: " + e.message);
	}
}
function ClosePopup()
{	
	$('divPopup').hide();
}
function checkpjg(){
	if(gebid('txtProductCode').value != ''){
		gebid('txtProductCode').value = '';
		gebid("pakjegemak").innerHTML = 'Wilt u bestellen via PakjeGemak? Open dan de <a href="javascript:ShowPopup();">locatiekiezer</a>.';
	}
}

var Dialog = {};
Dialog.Box = Class.create();
Object.extend(Dialog.Box.prototype, {
  initialize: function(id) {
    this.createOverlay();

    this.dialog_box = $(id);
    this.dialog_box.show = this.show.bind(this);
    this.dialog_box.hide = this.hide.bind(this);

    this.parent_element = this.dialog_box.parentNode;

    var e_dims = Element.getDimensions(this.dialog_box);
    var b_dims = Element.getDimensions(this.overlay);
    this.dialog_box.style.left = '38%';// ((b_dims.width/2) - (e_dims.width/2)) + 'px';
    this.dialog_box.style.top = '250px';
    this.dialog_box.style.position = 'absolute';
   
    
  },

  createOverlay: function() {
    if($('dialog_overlay')) {
      this.overlay = $('dialog_overlay');
    } else {
      this.overlay = document.createElement('div');
      this.overlay.id = 'dialog_overlay';
      Object.extend(this.overlay.style, {
      	position: 'absolute',
      	top: 0,
      	left: 0,
      	zIndex: 90,
      	width: '100%',
      	backgroundColor: '#000',
      	display: 'none'
      });
      document.body.insertBefore(this.overlay, document.body.childNodes[0]);
    }
  },

  moveDialogBox: function(where) {
    Element.remove(this.dialog_box);
    if(where == 'back')
      this.dialog_box = this.parent_element.appendChild(this.dialog_box);
    else
      this.dialog_box = this.overlay.parentNode.insertBefore(this.dialog_box, this.overlay);
  },

  show: function() {
    this.overlay.style.height = '1500px';// $('body').getHeight()+'px';
    this.moveDialogBox('out');
    this.overlay.onclick = this.hide.bind(this);
    this.selectBoxes('hide');
    new Effect.Appear(this.overlay, {duration: 0.1, from: 0.0, to: 0.3});
    this.dialog_box.style.display = ''
  },

  hide: function() {
    this.selectBoxes('show');
    new Effect.Fade(this.overlay, {duration: 0.1});
    this.dialog_box.style.display = 'none';
    this.moveDialogBox('back');
    $A(this.dialog_box.getElementsByTagName('input')).each(function(e){if(e.type!='submit')e.value=''});
  },

  selectBoxes: function(what) {
    $A(document.getElementsByTagName('select')).each(function(select) {
      Element[what](select);
    });

    if(what == 'hide')
      $A(this.dialog_box.getElementsByTagName('select')).each(function(select){Element.show(select)})
  }
});