var in_ie_hell=false;
var debug=false;
window.addEvent('domready', function() {
	// CHECK BROWSER
	if(Browser.Engine.trident) {
		in_ie_hell=true;
		document.ondragstart = function () { return false; };
	}
	// FABRIC SCROLLER
	if(document.body.id=='image_zoom') {
		init_image_zoomer();
	}
	// INTRO PAYOFF DOEN ?
	if($('intro_payoff')!=null) {
		init_intro_payoff();
	}
	// MENU ANIMEREN
	if($('main_options')!=null) {
		init_menu();
	}
	// CLOSE OUTPUT
	if($('output_closer')!=null) {
		check_output_display();
	}
	check_modal_links();
	init_print_links();
	init_tips();
	check_add_to_mh_links();
	if(document.body.id!='mijn_histoire') { 
		check_del_from_mh_links();
	}
	check_login_links();
	check_newsletter_links();
	check_subscribe_form_submit();
	check_search_form_submit();
	// ITEM GALS?
	var item_galleries = $$('.item_gallery_holder');
	if(item_galleries.length>0) {
		init_item_galleries();
	}
	// DRAGGABLES?
	var draggables = $$('.draggable_to_mh');
	if(draggables.length>0) {
		init_drag_to_mh();
	}
	// IMAGE GRID NEXT PREV ?
	if($('img_grid_next')!=null) {
		init_image_grid_nav();
	}
	// THANK YOU MAM?
	if($('thank_you')!=null) {
		launch_modal('thank_you');
	}
});

///////////////////////////////////////////////////////////////////////
///////////// GET WINDOW & PAGE-DIMS /////////////////////////////////
/////////////////////////////////////////////////////////////////////
var array_page_size;
var overlay_div;
var scroll_x, scroll_y, window_w, window_h;

function get_page_size(){
	var scroll_position = window.getScroll();
	scroll_x = scroll_position.x;
	scroll_y = scroll_position.y;

	var body_size =  $(document.body).getScrollSize();
	body_w = body_size.x;
	body_h = body_size.y;
	
	var window_size = window.getSize();
	window_w = window_size.x;
	window_h = window_size.y;
	
	// for small pages with total height less then height of the viewport
	if(body_h < window_h) {
		page_h = window_h;
	} else { 
		page_h = body_h;
	}

	// for small pages with total width less then width of the viewport
	if(scroll_x < window_w){	
		page_w = window_w;
	} else {
		page_w = body_w;
	}
	array_page_size = new Array(page_w, page_h, window_w, window_h);
	return array_page_size;
}

////////////////////////////////////////////////////////////////////////////////////////////////
///////////// NEWSLETTER FORM /////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
function check_subscribe_form_submit() {
	if($('histoire_nb_subscriber')!=null) {
		subscribe_form=$('histoire_nb_subscriber');
		subscribe_form.onsubmit=function() {
			var email_field = this.YMP0;
			if (echeck(email_field.value)==false){
				email_field.focus();
		        email_field.style.borderColor='#ff0000';
				return false;
			} else {
		        email_field.style.borderColor='#666';
			}
			return true;
		}
	}
}
function check_search_form_submit() {
	if($('search_histoire_form')!=null) {
		search_form=$('search_histoire_form');
		search_form.onsubmit=function() {
			//return false;
			if(!default_check(this.search_h_term)) { return false; }
		}
	}
}
function validate_question(the_form) {
	/*
	var question_type = the_form.question_type;
	var type_checked = validate_radio_button(question_type);
	var question_ta = the_form.question;
	if((question_ta.value=='') && (type_checked==null)) {
		alert('Please choose a type of question, or fill out a question | type_checked ='+type_checked);
		return false;
	}
	*/
	if(!default_check(the_form.AQ_name)) { return false; }
	if(!default_check(the_form.AQ_street)) { return false; }
	if(!default_check(the_form.AQ_pc)) { return false; }
	if(!default_check(the_form.AQ_city)) { return false; }
	if(!default_check(the_form.AQ_phone_1)) { return false; }
	var email_field = the_form.AQ_email;
	if (echeck(email_field.value)==false){
			email_field.focus();
	        email_field.style.borderColor='#ff0000';
			return false;
		} else {
	        email_field.style.borderColor='#666';
		}	
	return true;
}
function validate_send_friend(the_form) {

	if(!default_check(the_form.SF_sender_name)) { return false; }
	var email_field = the_form.SF_sender_email;
	if (echeck(email_field.value)==false){
			email_field.focus();
	        email_field.style.borderColor='#ff0000';
			return false;
		} else {
	        email_field.style.borderColor='#666';
		}	
	if(!default_check(the_form.SF_receiver_name)) { return false; }
	var email_field = the_form.SF_receiver_email;
	if (echeck(email_field.value)==false){
			email_field.focus();
	        email_field.style.borderColor='#ff0000';
			return false;
		} else {
	        email_field.style.borderColor='#666';
		}	
	return true;
}
function validate_transport_eng(the_form) {

	if(!default_check(the_form.TRA_name)) { return false; }
	if(!default_check(the_form.TRA_street)) { return false; }
	if(!default_check(the_form.TRA_pc)) { return false; }
	if(!default_check(the_form.TRA_city)) { return false; }
	if(!default_check(the_form.TRA_phone_1)) { return false; }

	var email_field = the_form.TRA_email;
	if (echeck(email_field.value)==false){
			email_field.focus();
	        email_field.style.borderColor='#ff0000';
			return false;
		} else {
	        email_field.style.borderColor='#666';
		}	

	return true;
}

function validate_mh_login(the_form) {

	var email_field = the_form.mh_user_email;
	if (echeck(email_field.value)==false){
		email_field.focus();
        email_field.style.borderColor='#ff0000';
		return false;
	} else {
        email_field.style.borderColor='#666';
	}	
	if(!default_check(the_form.mh_user_password)) { return false; }

	return true;
}
function validate_new_pass(the_form) {
	var email_field = the_form.forgot_email;
	if (echeck(email_field.value)==false){
		email_field.focus();
        email_field.style.borderColor='#ff0000';
		return false;
	} else {
        email_field.style.borderColor='#666';
	}	
	return true;
}
function validate_mh_account(the_form) {
	if(!default_check(the_form.full_name)) { return false; }
	var email_field = the_form.email;
	if (echeck(email_field.value)==false){
		email_field.focus();
        email_field.style.borderColor='#ff0000';
		return false;
	} else {
        email_field.style.borderColor='#666';
	}	
	// ACCOUNT ACTION
	var account_action = the_form.mh_account_action;
	if(account_action.value=='insert_new') {
		if(!default_check(the_form.pass)) { return false; }
	}
	if(!default_check(the_form.street)) { return false; }
	if(!default_check(the_form.postcode)) { return false; }
	if(!default_check(the_form.city)) { return false; }
	if(!default_check(the_form.phone)) { return false; }
	return true;	
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
///////////// MENU ANIMATION ////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
function init_menu() {
	
	var menu_list = $$('ul#main_options li.main_option_li');
	var submenuus = $$('ul#main_options li.main_option_li ul.sub_options');
	submenuus[0].his_state='closed';
	// PAK HUN DEFAULT HOOGTES
	submenuus.each(function(sub_menu, index) {
		// alert('submenu'+sub_menu.className);
		if(sub_menu.className=='sub_options set_height') {
			sub_menu.his_full_height = '125px';
		} else {
			sub_menu.setStyles({ height: 'auto'});
			var el_size = sub_menu.getSize();
			sub_menu.his_full_height = el_size.y;
			sub_menu.setStyles({ height: '0px'});
		}
	});
	
	// MOUSE OVER SHOW
	menu_list.each(function(li, index) { li.addEvent('mouseover', function() {
			mousemove_checking(true);
			if(submenuus[0].his_state=='closed') {
				submenuus.each(function(sub_menu, index) {
					animate_menu(sub_menu, 0, sub_menu.his_full_height, 'down');
				});
			}
		});
	});
	var DEL_recheck_on_menu;
	// MOUSE OUT HIDE
	menu_list.each(function(li, index) { li.addEvent('mouseout', function() {
			var on_menu = has_parent_tag_and_id(cur_mouse_target, 'ul', 'main_options');
			if(on_menu==true) {
				DEL_recheck_on_menu = recheck_on_menu.delay(500);
			}
		});
	});
	function recheck_on_menu() {
		if(submenuus[0].his_state=='opened') {
			var on_menu = has_parent_tag_and_id(cur_mouse_target, 'ul', 'main_options');
			if(on_menu==false) {
				$clear(DEL_recheck_on_menu);
				close_sub_menuus();
				mousemove_checking(false);
			}
		}
	}
	function close_sub_menuus() {
		if(submenuus[0].his_state=='opened') {
			submenuus.each(function(sub_menu, index) {
				animate_menu(sub_menu, sub_menu.his_full_height, 0, 'up')
			});	
		}
	}	
	function animate_menu(element, start, end, direction) {
		if(direction=='down') { 
			element.his_state='opened'; 
		} else {
			element.his_state='closed'; 
		}
		element.setStyle('overflow, visible');
		var myFx = new Fx.Tween(element, { duration: 200});
		myFx.start('height', start, end);
	}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
///////////// INTRO PAYOFF //////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
var clicked_away=false;
var intro_payoff_div;
function init_intro_payoff() {
	var payoff_slider = new Fx.Slide('intro_payoff', {duration: 500, mode: 'horizontal'});
	payoff_slider.hide();
	payoff_slider.element.setStyle('display', 'block');
	payoff_slider.slideIn();
	// CLOSE BUTTON
	var pay_off_closer = $('pay_off_close');
	pay_off_closer.addEvent('click', function() {
		payoff_slider.toggle();
		return false;
	});
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
///////////// TOOL TIPS /////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
function init_tips(retrigger) {
	if(retrigger==undefined) {
		retrigger = false;
	} else if(retrigger==true) {
		clean_up_other_tips('tip_histoire_wit');
	}
	
	var check_cur_pos_delay;
	var active_tip = null;
	
	function store_tip_data(element) {
		// STORE INFO
		element.store('tip:title', element.get('title'));
		var element_text = element.get('rel');
		var element_text_safe = unescape(element_text);
		element_text_safe = element_text_safe.replace(/\+/g, ' ');
		element.store('tip:text', element_text_safe);
	}	
	function init_standard_tip(element_id, x_offset, y_offset) {
		var new_tip = new Tips(element_id,{
			className: 'tip_histoire',
			fixed: true,
			hideDelay: 50,
			showDelay: 50,
			offsets: {'x': x_offset, 'y': y_offset},
			onShow: function(tip, el) {
				if((active_tip) && (active_tip.className!=tip.className)) { clean_up_other_tips(active_tip.className); output('clean up your mess!'+tip.className); }
	        	active_tip = tip;
				mousemove_checking(true);
				tip.setStyles({
	                visibility: 'visible',
	                display: 'block'
	            });
			},
	        onHide: function(tip, el) { 
				check_cur_pos_delay = check_mouse_on_tip.delay(1000);
	        }		
		});
		
	}
	// STANDAARD TIPS	
	if(retrigger==false) {
		// VINTAGE NEW
		if($('new_vintage_selector')!=null) {
			var new_vintage_selector = $('new_vintage_selector');
			store_tip_data(new_vintage_selector);
			init_standard_tip('#new_vintage_selector', 110, -20);
		}
		// MH UITLEG
		if($('mh_status')!=null) {
			var mh_status = $('mh_status');
			store_tip_data(mh_status);
			init_standard_tip('#mh_status', -160, -150);
		}
		// MEMORY LANE - memory_lane_dd
		if($('memory_lane_dd')!=null) {
			var memory_lane_dd = $('memory_lane_dd');
			store_tip_data(memory_lane_dd);

			//create the tooltips
			var memory_tip = new Tips('#memory_lane_dd',{
				className: 'tip_histoire',
				fixed: true,
				hideDelay: 50,
				showDelay: 50,
				offsets: {'x': 120, 'y': -80}
			});
		}
		/* TEGELIJK
		// Store titles and text
		$$('.activate_tip').each(function(element,index) {
			element.store('tip:title', element.get('title'));
			var element_text = element.get('rel');
			var element_text_safe = unescape(element_text);
			element_text_safe = element_text_safe.replace(/\+/g, ' ');
			element.store('tip:text', element_text_safe);
			// element.store('tip:offsets', {'x': -160, 'y': -80});
		});
		
		
		//create the tooltips
		var tipz = new Tips('.activate_tip',{
			className: 'tip_histoire',
			fixed: true,
			hideDelay: 50,
			showDelay: 50,
			offsets: {'x': -160, 'y': -80},
			onShow: function(tip, el) {
				if((active_tip) && (active_tip.className!=tip.className)) { clean_up_other_tips(active_tip.className); output('clean up your mess!'+tip.className); }
	        	active_tip = tip;
				mousemove_checking(true);
				tip.setStyles({
	                visibility: 'visible',
	                display: 'block'
	            });
			},
	        onHide: function(tip, el) { 
				check_cur_pos_delay = check_mouse_on_tip.delay(1000);
	        }		
		});
		*/

	}
	
	//store titles and text
	$$('.activate_wit_tip').each(function(element,index) {
		element.store('tip:title', element.get('title'));
		var element_text = element.get('rel');
		var element_text_safe = unescape(element_text);
		element_text_safe = element_text_safe.replace(/\+/g, ' ');
		element.store('tip:text', element_text_safe);
	});
	

	var tipz_wit = new Tips('.activate_wit_tip',{
		className: 'tip_histoire_wit',
		fixed: true,
		hideDelay: 50,
		showDelay: 50,
		offsets: {'x': -10, 'y': -10},
		onShow: function(tip, element) {
			if((active_tip) && (active_tip.className!=tip.className)) { clean_up_other_tips(active_tip.className); }
        	active_tip = tip;
			mousemove_checking(true);
			tip.setStyles({
                visibility: 'visible',
                display: 'block'
            });
            check_add_to_mh_links();
		},
        onHide: function(tip, el) { 
			check_cur_pos_delay = check_mouse_on_tip.delay(1000);
        }
	});

	function clean_up_other_tips(tip_class) {
		$$('.'+tip_class).each(function(element, index) { element.setStyle('display', 'none'); })
	}

	function check_mouse_on_tip() {
		var on_tip, on_activate_tip, direct_on_active_tip, div_check_1, div_check_2;
		if(active_tip!=null) {
			var cur_tip_class = active_tip.className;
			if(cur_tip_class=='tip_histoire') {
				div_check_1 = 'tip_histoire';
				div_check_2 = 'activate_tip';
				element_tag_to_check='div';
			} else {
				div_check_1 = 'tip_histoire_wit';
				div_check_2 = 'activate_wit_tip';
				element_tag_to_check='a';
			}
			if((cur_mouse_target.tagName!='HTML') && (cur_mouse_target.parentNode!=undefined)) {
				if((cur_mouse_target!=undefined) && (cur_mouse_target.parentNode!=undefined) && (cur_mouse_target.parentNode.tagName!='HTML')) {
					on_tip = has_parent_tag_and_class(cur_mouse_target, 'div', div_check_1);
					on_activate_tip = has_parent_tag_and_class(cur_mouse_target, element_tag_to_check, div_check_2);
				} else {
					on_tip = false;
					on_activate_tip = false;
				}
			} else {
				on_tip = false;
				on_activate_tip = false;
				direct_on_active_tip = false;
			}
		} else {
			on_tip = false;
			on_activate_tip = false;
			direct_on_active_tip = false;
		}
		if((on_tip==false) && (on_activate_tip==false)) {
			hide_tip();
			$clear(check_cur_pos_delay);
			mousemove_checking(false);
		} else {
			check_cur_pos_delay = check_mouse_on_tip.delay(1000);		
		}
	}
	function hide_tip() {
		if(active_tip!=null) {
			active_tip.setStyle('display', 'none');
		}
	}
}
///////////// CUR MOUSE TARGET //////////////////////////////////////////////////////////////////////////
var cur_mouse_target;
function get_mouse_target(e){ 
	cur_mouse_target = $(e.target);
	//output('e');
}
var checking_mousemove=false;
function mousemove_checking(on_off) {
	if(on_off==true) {
		if(checking_mousemove==false) {
			// output('---- START mousemove');
			$(document.body).addEvent('mousemove', get_mouse_target);
		}
		checking_mousemove=true;
	} else if(on_off==false) {
		// output('-- QUIT mousemove');
		checking_mousemove = false;
		$(document.body).removeEvent('mousemove', get_mouse_target);
		cur_mouse_target='';
	}
}

///////////// CLOSE OUTPUT //////////////////////////////////////////////////////////////////////////
function check_output_display() {
	var this_output_div = $('output');
	var output_closer = $('output_closer');
	/*
	var READ_output_state = Cookie.read('output_state');
	if(READ_output_state!=null) {
		output(READ_output_state);
	} else { 
		output('no cookie');
	}
	*/
	output_closer.addEvent('click', function() {
		/*
		//if(output_w==300) {
		var output_sizes = this_output_div.getSize();
		var output_w = output_sizes.x;
		var new_width;
		var new_link_text;
		if(output_w==45) {
			new_width = '280px';
			new_link_text="&gt;&gt;";
		} else {
			new_width = '25px';
			new_link_text="&lt;&lt;";
		}
		this_output_div.setStyle('width', new_width);
		output_closer.innerHTML=new_link_text;
		//var cookie  = Cookie.write('output_state', new_width, {duration: 30, domain: '.mediamogul.nl'}); //save for a month
		//output('cur_display_w'+output_w);
		*/
		return false;
	});
	/*
	*/
}


//////////////////////////////////////////////////////////////////////////////////////////////////////
///////////// PRINT POP-UP LINKS ////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
function init_print_links() {
	var pop_up_w = 850;
	var pop_up_h = 350;

	var print_popup_links = $$('a.print_page');
	print_popup_links.addEvent('click', function() {
		var pop_up_url = this.href;
		newwindow=window.open(pop_up_url,'Print_product_item', 'height=650,width=860');
		return false;
	});
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
///////////// FABRIC FOCUS //////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
var fabric_focus_img, fabric_focus_name, fabric_focus_desc, fabric_focus_link, fabric_focus_link_h;
function init_show_fabric_focus() {
	fabric_focus_img= $('fabric_focus_img');
	fabric_focus_name= $('fabric_focus_name');
	fabric_focus_desc= $('fabric_focus_desc');
	fabric_focus_link= $('show_even_larger');
	fabric_focus_link_h = $('show_even_larger_h3');

	fabric_thumb_links.each(function(fabric_link, index) {
		fabric_link.onclick=function() {
			show_fabric_zoom(this);
			return false;
		}
	});
}
function show_fabric_zoom(the_link) {
	var fabric_focus_settings = the_link.rev;
	var fabric_settings_array = get_fabric_focus_settings(fabric_focus_settings);
	
	var img_to_show = the_link.href;
	var img_orientation = fabric_settings_array[0];
	var fabric_name = fabric_settings_array[1];
	if(fabric_name!='') {
		fabric_name = unescape(fabric_name);
		fabric_name = fabric_name.replace(/\+/g, ' ');
	}
	var fabric_desc = fabric_settings_array[2];
	if(fabric_desc=='') { 
		fabric_desc='&nbsp;'; 
	} else {
		fabric_desc = unescape(fabric_desc);
		fabric_desc = fabric_desc.replace(/\+/g, ' ');
	}
	var fabric_url = fabric_settings_array[3];
	// SHOW LOADING
	toggle_opacity(the_link, 'transparent');
	
	// PRELOAD IMAGE
	var load_img = new Image();
	load_img.onload = function() {
		fabric_focus_img.src=img_to_show;
		fabric_focus_img.className=img_orientation;
		toggle_opacity(the_link, 'full');
		// SET URL, NAME & CAPTION
		fabric_focus_link.href = fabric_url;
		fabric_focus_link_h.href = fabric_url;
		fabric_focus_link_h.innerHTML=fabric_name;
		fabric_focus_desc.innerHTML=fabric_desc;
	}
	load_img.src=img_to_show;	
}
function get_fabric_focus_settings(img_settings) {
	// {orientation: landscape###name: eiken - lak blank###caption: ''}
	var fabric_array = img_settings.split('###');
	// WIDTH
	var img_orient_raw = fabric_array[0]; //  '{orientation: 315'
	var img_orientation = img_orient_raw.split('{orientation: ')[1];	
	// HEIGHT
	var fabric_name_raw = fabric_array[1]; //  name: 445
	var fabric_name = fabric_name_raw.split('name: ')[1];	
	// CAPTION
	var img_caption_raw = fabric_array[2]; // caption: ''
	var img_caption = img_caption_raw.replace("caption: '", "");
	img_caption = img_caption.replace("'", "");
	// URL	// url: 
	var fabric_full_url_raw = fabric_array[3]; // url: }
	var fabric_full_url = fabric_full_url_raw.replace("url: ", "");
	fabric_full_url = fabric_full_url.replace("}", "");

	var fabric_settings_array = new Array(img_orientation, fabric_name, img_caption, fabric_full_url);
	return fabric_settings_array;
}

/////////////////////////////////////////////////////////////////////
///////////// TOGGLE MORE CLOTH /////////////////////////////////////
/////////////////////////////////////////////////////////////////////
function enable_cloth_toggling() {
	var show_more_cloth = $('fabric_show_more');
	var more_cloth_ul = $('fabric_more_cloth');
	show_more_cloth.onclick=function() {
		if((more_cloth_ul.style.display=='') || (more_cloth_ul.style.display=='none')) {
			more_cloth_ul.style.display='block';	
		} else {
			more_cloth_ul.style.display='none';
		}
		return false;
	}
}
/////////////////////////////////////////////////////////////////////
///////////// VALIDATE STUFF ////////////////////////////////////////
/////////////////////////////////////////////////////////////////////

function validate_add_comment(theform) {
	// NAME
	var poster_name=theform.poster_name;
	if(!default_check(poster_name)) { return false; }
	// EMAIL
	var poster_email=theform.poster_email;
	if (echeck(poster_email.value)==false){
		poster_email.focus();
        poster_email.style.borderColor='#ff0000';
		return false;
	} else {
        poster_email.style.borderColor='#777';
	}
	// COMMENT
	var comment_add=theform.comment_add;
	if(!default_check(comment_add)) { return false; }
	
	return true;

}

function default_check(input) {
	if(input!=undefined) {
		if ((input.value==null)||(input.value=="")){
    		input.style.borderColor="#ff0000";
			input.focus()
			return false;
		} else {
	    	input.style.borderColor="#777";
    	    return true;
		}
	} else {
		return true;
	}
}
function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Please fill out a valid email address")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Please fill out a valid email address")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Please fill out a valid email address")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Please fill out a valid email address")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Please fill out a valid email address")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Please fill out a valid email address")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Please fill out a valid email address")
		    return false
		 }

    return true;
}
function validate_radio_button(btn) {
    var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) {
        if (btn[i].checked) {
            cnt = i; 
            i = -1;
        }
    }
    if (cnt > -1) { 
        return btn[cnt].value;
    } else {
        return null;
    }
}

var op_i=0;
var output_div_available;
var output_div;
function output(string) {
	if(output_div_available==undefined) {
		if($('output')!=null) {
			output_div_available=true;
			output_div = $('output');
		} else {
			output_div_available=false;		
		}
	}
	if(output_div_available==true) {
	//$('output').appendText("<br />"+string);	
		var cur_content = output_div.innerHTML;
		output_div.innerHTML = cur_content+'<br />'+string;
	}
	return false;
}

// if(debug==true) output('showing_counter = '+showing_counter);
function output_V1(text) {
	op_i++;
	var cur_val = js_output_ta.value;
	js_output_ta.value = cur_val+'\n'+op_i+'.'+text;
}

// PARENT TARGET CHECKERS
function has_parent_tag_and_id(theTarget, theTag, theId) {
	var theTarget = $(theTarget);
	is_correct_parent = false;
	if(theTarget!=null) {
		theTag = theTag.toUpperCase();
		
		// CHECK OF ER AL NIET OP ZIT
		if((theTarget.tagName==theTag) && (theTarget.getProperty('id')==theId)) {
			is_correct_parent = true;
		} else {
		    // output('theTarget = '+theTarget+' TAG: '+theTarget.get('tag')+' - parentNode: '+theTarget.parentNode);
			theTarget.getParents().each(function(el) {
			    if(el.tagName== theTag) {
		        	if(el.getProperty('id') == theId) {
		            	is_correct_parent = true;
			        }
		    	}	
			});
		}
	}
	return( is_correct_parent );
}
function has_parent_tag_and_class(theTarget, theTag, theClass) {
	is_correct_parent = false;
	theTag = theTag.toUpperCase();
	// CHECK OF ER AL NIET OP ZIT
	if((theTarget.tagName==theTag) && (theTarget.hasClass(theClass))) {
		is_correct_parent = true;
	} else {
		theTarget.getParents().each(function(el) {
	    	//output('theTarget = '+theTarget+' CLASS: '+el.className+' TAG: '+el.get('tag')+' - searcing for: '+theClass);
		    if(el.tagName== theTag) {
		    	//output(' CLASS: '+el.className);
		        if(el.hasClass(theClass)) {
		            is_correct_parent = true;
		        }
	    	}
		});
	}
	return( is_correct_parent );
}
