/*
 * Clear Default Text: functions for clearing and replacing default text in
 * <input> elements.
 *
 * by Ross Shannon, http://www.yourhtmlsource.com/
 */

Event.observe(window, 'load', init);
function init() {
    var formInputs = document.getElementsByTagName('input');
    for (var i = 0; i < formInputs.length; i++) {
        var theInput = formInputs[i];
        
        if (theInput.type == 'text' && theInput.className.match(/\bcleardefault\b/)) {  
            /* Add event handlers */          
         Event.observe(theInput,'focus', clearDefaultText);
                Event.observe(theInput,'blur', replaceDefaultText);            
            /* Save the current value */
            if (theInput.value != '') {
                theInput.defaultText = theInput.value;
            }
        }
    }
}

function clearDefaultText(e) {
    var target = window.event ? window.event.srcElement : e ? e.target : null;
    if (!target) return;
    
    if (target.value == target.defaultText) {
        target.value = '';
    }
}

function replaceDefaultText(e) {
    var target = window.event ? window.event.srcElement : e ? e.target : null;
    if (!target) return;
    
    if (target.value == '' && target.defaultText) {
        target.value = target.defaultText;
    }
}
/*
EINDE CLEAR TEXT SCRIPT
*/

AIM = {
        rdiv : "",
        frame : function(c) {

                var n = 'f' + Math.floor(Math.random() * 99999);
                var d = document.createElement('DIV');
                d.innerHTML = '<iframe style="display:none" src="about:blank" id="'+n+'" name="'+n+'" onload="AIM.loaded(\''+n+'\')"></iframe>';
                document.body.appendChild(d);

                var i = document.getElementById(n);
                if (c && typeof(c.onComplete) == 'function') {
                        i.onComplete = c.onComplete;
                }

                return n;
        },

        form : function(f, name) {
                f.setAttribute('target', name);
        },

        submit : function(f, c, resdiv) {
                AIM.rdiv = resdiv;
                AIM.form(f, AIM.frame(c));
                if (c && typeof(c.onStart) == 'function') {
                        return c.onStart();
                } else {
                        return true;
                }
        },

        loaded : function(id) {
                var i = document.getElementById(id);
                if (i.contentDocument) {
                        var d = i.contentDocument;
                } else if (i.contentWindow) {
                        var d = i.contentWindow.document;
                } else {
                        var d = window.frames[id].document;
                }
                if (d.location.href == "about:blank") {
                        return;
                }

                if (typeof(i.onComplete) == 'function') {
                        // var resp = new dummyResponse(d.body.innerHTML);
                        var resp = new Object()

                        resp.responseText = d.body.innerHTML;
                        i.onComplete(resp,AIM.rdiv);
                }
        }

}

winkelwagen.addProduct = function(k,frm)
{

        var arr =$(frm).getInputs('text');
   arr.each(function(item) {
      if (item.defaultValue == item.value)
        item.value = '';
   });


        var pars = Form.serialize(frm)+"&winkelwagen=addProduct";
        winkelwagen.submitFunction(pars,null,function(resp,res) {  document.location.href='/cart'; } );

}

account.loginReply = function(frm,resp,re)
{
	if (resp.responseText=="FOUT")
	{
		alert("Ongeldige login");
		document.location.href="/index.php?p=account&page=login";
	} else if (resp.responseText.substring(0,5) == "REDIR") {
		document.location.href = resp.responseText.substring(5).unescapeHTML();
	} else {
		alert(resp.responseText);
	}
}

function verstuurNotificatie()
{
/*      var pars = Form.serialize($('gf'));
        var myAjax = new Ajax.Request(
                '/data.php',
                {
                        method: 'post',
                        parameters: pars,
                        onComplete: verwerkBericht
                })      */
//                $('knop').disabled=true;
}
function verwerkNotificatie(resp)
{
        if (resp.responseText=="OK")
        {
                $('pndiv').hide();
                $('pnmelding').show();
        } else {
                alert(resp.responseText);
        }
}

