// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

/* insert an address into the top field */
function add_field(address){
    var addresses = $('addresses');
    addresses.insert({top: '<div><a href="#" onclick="remove_address(this); return false;"><img alt="Minus" src="/images/minus.png" /></a><input id="address[]" name="address[]" type="text" readonly="readonly" value="'+address+'"/></div>'});
};

/* read current address_adder value */
function read_and_reset_address(){
    var adr = $('address_adder');
    var elem = adr.findFirstElement();
    var val = elem.value;
    add_field(val);
    elem.value = '';
};

/* delete address placed next to self */
function remove_address(obj){
    var par = obj.parentNode;
    par.remove();
}

/* write an error */
function write_error(msg){
    var cont = $('content');
    cont.insert({top: '<div id="error">'+msg+'</div>'});
};

/* Check prerequisites and hide them */
function hide_requirement_messages(){
    hide_javascript_msg();
    hide_cookie_msg();
}

/* make javascript message disappear */
function hide_javascript_msg(){
    var jsmsg = $('jserror');
    jsmsg.remove();
};

/* make cookie message disappear */
function hide_cookie_msg(){
    var cookiemsg = $('cookieerror');
    Cookie.set('check_cookie', 'y');
    if(Cookie.get('check_cookie') == 'y'){
	    cookiemsg.remove();
	};
};