var editor_dir = '/js/s101_admin/editor/';
var editor_bg = '#ffffff';
var selected_range;


function edit_text(div_id, save_option, current_page, editor_mode, asset_id, asset_type, asset_sub_type, edit_mode, one_link_inside) {

	if (edit_mode != 'on') { return; }

	if (document.getElementById('text_area_editor') != null)
	{
		if (document.getElementById('text_area_editor').parentNode.parentNode.id == div_id)
		{
			return;
		}

		if (document.getElementById('action_window').style.display == 'block')
		{
			resize_image_cancel();
		}

        var cur_open_editor = document.getElementById('text_area_editor').parentNode.parentNode.id;
	    var cur_open_editor_save_option = document.getElementById(cur_open_editor).getAttribute('ondblclick').split(',').pop();
	    var cur_open_editor_save_option_clean = cur_open_editor_save_option.replace(/([^0-9A-Za-z])/g,"");

	save_html(''+cur_open_editor_save_option_clean+'');
	}

	sortable_sections('false');

	if (document.getElementById('page_background_color') != null)
	{
	    editor_bg = '#'+document.getElementById('page_background_color').value;
	}
	
	var text_width = document.getElementById(div_id).clientWidth;
	var text_height = document.getElementById(div_id).clientHeight;
	var html_to_edit = document.getElementById(div_id).innerHTML;
	var text_area_style = 'width:'+text_width+'px;background-color:'+editor_bg+';';
	var spacer_div = '<div style="width:'+text_width+'px;height:'+text_height+'px;">&nbsp;</div>';

	var action_win = '<div id="action_window" style="display:none;">' +
						'	<div id="action_window_text"><b>To resize image,</b><br />enter value between 10 and '+text_width +'</div>' +
						'	<input type="number" name="action_window_size" min="10" max="'+text_width+'" class="action_window_input" id="action_window_input" value="" onkeypress="return disable_enter_key(event, \'i_resize\');" />' +
						'	<div class="action_window_input_buttons">' +
						'		<input type="button" name="cancel" value="cancel" class="action_window_input_but" onclick="resize_image_cancel();" />' +
						'		<input type="button" name="im_submit" value="apply" class="action_window_input_but" onclick="resize_image_make();" />' +
						'	</div>' +
						'</div>';


						var prompt_win = '<div id="prompt_window" style="display:none;">' +
						'<form name="wysiwyg_editor_f" method="post">' +
						'   <div id="link_prompt_sect" class="prompt_window_sect">' +
						'       <div class="margin_bottom_10">' +
						'           link URL: <input type="text" name="prompt_window_text" id="prompt_window_text" value="" onkeypress="return disable_enter_key(event, \'l_apply\');" /><br />' +
						'        </div>' +
						'	    open IN: <select name="editor_link_targ" class="editor_form_sort" onkeypress="return disable_enter_key(event, \'l_apply\');">' +
						'           <option value="same">same window</option>' +
                        '           <option value="blank">new window</option>' +
                        '       </select>' +
						'   </div>' +
						'	<div class="action_window_input_buttons">' +
						'		<input type="button" name="t_ed_cancel" value="cancel" class="action_window_input_but" onclick="prompt_cancel();" />' +
						'		<input type="button" name="t_ed_submit" value="apply" class="action_window_input_but" onclick="link_prompt_apply();" />' +
						'	</div>' +
						'</form>' +
						'</div>';


	var backup_div = '<textarea cols="40" rows="10" name="editor_backup" id="editor_backup" style="display:none;">'+html_to_edit+'</textarea>';

	var text_editor = '<div class="html_editor" id="editor_controls" style="background-color:'+editor_bg+';">' +
					'<a href="javascript:void(0);" onclick="close_editor(\''+div_id+'\');"><img src="'+editor_dir+'img/close.png" alt="" title="Close" class="html_editor_img_close" id="html_editor_img_close" /></a>' +
					'<div class="html_editor_head">' +
					    html_editor(save_option, current_page, editor_mode, asset_id, asset_type, asset_sub_type) +
					'</div>' +
					action_win +
					prompt_win +
					'<div style="'+text_area_style+'" id="text_area_editor" contenteditable="true" onmousedown="clean_all_images();">' +
					html_to_edit +
					'</div>' +
					'<input type="hidden" name="one_link_inside" id="one_link_inside" value="'+one_link_inside+'" />' +
					'</div>' +
					spacer_div +
					backup_div;

	document.getElementById(div_id).innerHTML = text_editor;
	images_edit_mode('on');
	document.execCommand('enableObjectResizing', false, false);
}

function save_html(save_option, current_page, asset_id, asset_type , asset_sub_type) {

	images_edit_mode('off');

	var cur_editor_html = document.getElementById('text_area_editor').innerHTML;
	var cur_editor_holder_id = document.getElementById('text_area_editor').parentNode.parentNode.id;

	if (save_option == 'to_page')
	{

/*save to page
    not removed since we may need some other save option in the future...
*/
	}
    else if (save_option == 'to_php')
    {
//save to php

	    $.ajax({
		    type: 'POST',
		    url: '?page=save_site_text',
		    data: 'zone_id='+cur_editor_holder_id+'&zone_data='+cur_editor_html+'&asset_id='+asset_id+'&asset_type='+asset_type ,

			    success: function(content)
			    {
	                cur_editor_html = cur_editor_html.replace(/#/g, '{{POUND_SIGN}}') ;

	                cur_editor_html = cur_editor_html.replace(/&/g, '{{AMPERSAND}}') ;
              //	alert(cur_editor_html);

	                params = "&current_page=" + current_page + "&zone_id=" + cur_editor_holder_id + "&zone_data=" + cur_editor_html + "&asset_type=" + asset_type + "&asset_id=" + asset_id + "&asset_sub_type=" + asset_sub_type ;

             // 	alert(params);

	                s101Manager.doPopup('save_site_text','save_site_text...',params,'0px') ;
			    }
	    });
	}
	document.getElementById(cur_editor_holder_id).innerHTML = cur_editor_html;

    switch_links(cur_editor_holder_id, 'off');
    sortable_sections('true');
}


function html_editor(save_option, current_page, editor_mode, asset_id, asset_type , asset_sub_type) {

//alert(asset_type);

//	 alert(editor_mode) ;

	var bold_text = '<a href="javascript:void(0);" onclick="document.execCommand(\'Bold\', false, null);"><img src="'+editor_dir+'img/bold.png" alt="" title="Bold Text" class="html_editor_img" /></a>';

	var italic_text = '<a href="javascript:void(0);" onclick="document.execCommand(\'Italic\', false, null);"><img src="'+editor_dir+'img/italic.png" alt="" title="Italic Text" class="html_editor_img" /></a>';

	var underline_text = '<a href="javascript:void(0);" onclick="document.execCommand(\'Underline\', false, null);"><img src="'+editor_dir+'img/text_underline.png" alt="" title="Underline" class="html_editor_img" /></a>';



	var highlight_text = '<a href="javascript:void(0);" onclick="highlight();"><img src="'+editor_dir+'img/highlight.png" alt="" title="Highlight" class="html_editor_img" /></a>';
	
	var un_highlight_text = '<a href="javascript:void(0);" onclick="un_highlight();"><img src="'+editor_dir+'img/highlight_rm.png" alt="" title="Un Highlight" class="html_editor_img" /></a>';


	
	var embed_flash_link = '<a href="javascript:void(0);" onclick="embed_flash(\'Youtube embed code?\');"><img src="'+editor_dir+'img/flash.png" alt="" title="Embed Video" class="html_editor_img" /></a>';

	var insert_link = '<a href="javascript:void(0);" onclick="prompt_window(\'link\');"><img src="'+editor_dir+'img/link_add.png" alt="" title="Insert Link" class="html_editor_img" /></a>';

	var null_link = '<a href="javascript:void(0);" ><img src="/js/s101_admin/images/0.gif" class="html_editor_img" /></a>';

	var edit_content = '<a href="javascript:void(0);" onclick="javascript:s101Manager.doPopup(\'edit_news_db\',\'edit_news_db\',\'&form_mode=edit&NewsID=' + asset_id +'&content_title=&gsg_action=edit&close_mode=refresh&last_page=&ItemType=' + asset_type +'\',\'700px\');"><img src="'+editor_dir+'img/edit_content.png" alt="" title="Edit Content" class="html_editor_img" /></a>';

if (asset_type == 'news') {

	var edit_content = '<a href="javascript:void(0);" onclick="javascript:s101Manager.doPopup(\'edit_news_db\',\'edit_news_db\',\'&form_mode=edit&NewsID=' + asset_id +'&content_title=&gsg_action=edit&close_mode=refresh&last_page=&ItemType=' + asset_type +'\',\'700px\'); init_popup_scripts(\'edit_news_db_news\'); "><img src="'+editor_dir+'img/edit_content.png" alt="" title="Edit Content" class="html_editor_img" /></a>';

}

if (asset_type == 'general') {

	var edit_content = '<a href="javascript:void(0);" onclick="javascript:s101Manager.doPopup(\'edit_news_db\',\'edit_news_db\',\'&form_mode=edit&NewsID=' + asset_id +'&content_title=&gsg_action=edit&close_mode=refresh&last_page=&ItemType=' + asset_type +'\',\'700px\'); init_popup_scripts(\'edit_news_db_general\'); "><img src="'+editor_dir+'img/edit_content.png" alt="" title="Edit Content" class="html_editor_img" /></a>';

}


	var design_content = '<a href="javascript:void(0);" onclick="javascript:showPageEditor(\'demo823\');"><img src="'+editor_dir+'img/edit_design.png" alt="" title="Design" class="html_editor_img" /></a>';

	var design_content_default = '<a href="javascript:void(0);" onclick="javascript:s101Manager.doPopup(\'design_popup\',\'design_popup\',\'&design_mode=site_defaults\',\'700px\'); init_popup_scripts(\'design_site_font\');"><img src="'+editor_dir+'img/edit_design.png" alt="" title="Design" class="html_editor_img" /></a>';

	var design_content_logo = '<a href="javascript:void(0);" onclick="javascript:s101Manager.doPopup(\'design_popup\',\'design_popup\',\'&design_mode=logo\',\'700px\'); init_popup_scripts(\'design_headers\');"><img src="'+editor_dir+'img/edit_design.png" alt="" title="Design" class="html_editor_img" /></a>';

var design_content_header = '<a href="javascript:void(0);" onclick="javascript:s101Manager.doPopup(\'design_popup\',\'design_popup\',\'&design_mode=headers\',\'700px\'); init_popup_scripts(\'design_headers\');"><img src="'+editor_dir+'img/edit_design.png" alt="" title="Design" class="html_editor_img" /></a>';

var design_content_titles = '<a href="javascript:void(0);" onclick="javascript:s101Manager.doPopup(\'design_popup\',\'design_popup\',\'&design_mode=titles\',\'700px\'); init_popup_scripts(\'design_titles\');"><img src="'+editor_dir+'img/edit_design.png" alt="" title="Design" class="html_editor_img" /></a>';




	var align_text_left = '<a href="javascript:void(0);" onclick="document.execCommand(\'justifyLeft\', false, null);"><img src="'+editor_dir+'img/text_align_left.png" alt="" title="Left" class="html_editor_img" /></a>';

	var align_text_center = '<a href="javascript:void(0);" onclick="document.execCommand(\'justifyCenter\', false, null);"><img src="'+editor_dir+'img/text_align_center.png" alt="" title="Center" class="html_editor_img" /></a>';

	var align_text_right = '<a href="javascript:void(0);" onclick="document.execCommand(\'justifyRight\', false, null);"><img src="'+editor_dir+'img/text_align_right.png" alt="" title="Right" class="html_editor_img" /></a>';



	var save_link = '<a href="javascript:void(0);" onclick="save_html(\''+save_option+'\',\'' + current_page + '\',\'' + asset_id + '\',\'' + asset_type + '\',\'' + asset_sub_type + '\'  );"><img src="'+editor_dir+'img/save.png" alt="" title="Save" class="html_editor_img_last" /></a>';


	if (editor_mode == 'logo') {

		var editor_div =  insert_link +
					design_content_logo + 
					save_link;
	}

	else if (editor_mode == 'headers') {

		var editor_div =  align_text_left +
					align_text_center +
					align_text_right +
					insert_link +
					design_content_header + 
					save_link;
	}

	else if (editor_mode == 'title') {

		var editor_div =  insert_link +
					design_content_titles + 
					edit_content + 
					save_link;
	}

	else if (editor_mode == 'basic') {

		var editor_div =  insert_link +
					save_link;
	}

	else if (editor_mode == 'min') {

		var editor_div =  null_link + save_link;
	}

	else if (editor_mode == 'full') {

	    var editor_div =  bold_text +
					italic_text +
					underline_text +
					highlight_text +
					un_highlight_text +
					embed_flash_link +
					insert_link +
					edit_content + 
					design_content_default + 
					align_text_left +
					align_text_center +
					align_text_right +
					save_link;
	}

	else {

	    var editor_div =  bold_text +
					italic_text +
					underline_text +
					embed_flash_link +
					insert_link +
					edit_content + 
					design_content_default + 
					align_text_left +
					align_text_center +
					align_text_right +
					save_link;
	}



	return editor_div;
}

function selection_range_make() {

    if (window.getSelection)
    {
        var selection_range = window.getSelection();
    }
    else if (document.selection)
    {
        var selection_range = document.selection.createRange();
    }

    if (selection_range.isCollapsed)
	{
	    alert('Please select content!');
	}
	else
	{
	    return selection_range;
	}
}


function highlight(prompt_text)
{
    var selection_range = selection_range_make();

    var qq = document.getElementById('logo');
    
    if (qq != null)
    {
        var highlight_color = get_color(qq);
    }
    else
    {
        var highlight_color = 'ff0000';
    }

	document.execCommand('foreColor', false, highlight_color);
}

function un_highlight() {

	var selection_range = selection_range_make();
	document.execCommand('RemoveFormat', false, null);


	//remove heighlited class if needed...
	var node = selection_range.anchorNode;
	var node_class = node.parentNode.className;
	
	if (node_class.indexOf('heighlited') != -1)
	{
		var new_node_class = node.parentNode.className.replace(new RegExp('heighlited'), '');

		node.parentNode.className = new_node_class;
	}
}

function close_editor(div_id) {

	var backup_html = document.getElementById('editor_backup').value;

	if (confirm('Close without saving?'))
	{
		document.getElementById(div_id).innerHTML = backup_html;
		switch_links(div_id, 'off');
		sortable_sections('true');
	}
}

function focus_check() {

    if (window.getSelection)
    {
        var selection_range = window.getSelection();
    }
    else if (document.selection)
    {
        var selection_range = document.selection.createRange();
    }

	var reality_check = selection_range.containsNode(document.getElementById('text_area_editor'), true);
    
    if (reality_check == false)
    {
        document.getElementById('text_area_editor').focus();
        selection_range.collapse(selection_range.anchorNode, selection_range.anchorOffset);
    }
}

function embed_flash(prompt_text) {

    //just in case the fucus is off... (happens often on all broswers)//
    focus_check();

    var flash_code = prompt(prompt_text);
    var embed_width = document.getElementById('text_area_editor').clientWidth;

    if (flash_code.length != 0)
    {
    	//youtu.be link
    	if (flash_code.indexOf('http://youtu.be/') != -1)
    	{
    		alert("Hmm...\nIt looks like you are trying to embed a youtu.be link!\n\rPlease grab the Embed code from youtube.com and try again.");
    		return;
    	}

    	else if (flash_code.indexOf('http://www.youtube.com') != -1)
    	{
    		var flash_width_start = flash_code.toString().split('width="');
    		var flash_width_end = flash_width_start[1].toString().split('"');

    		var flash_height_start = flash_code.toString().split('height="');
    		var flash_height_end = flash_height_start[1].toString().split('"');

    		var flash_height = Math.round(flash_height_end[0] * embed_width / flash_width_end[0]);

    		var new_height = flash_code.toString().replace(new RegExp('="'+flash_height_end[0], 'g'), '="'+flash_height);
    		var new_embed_code = new_height.toString().replace(new RegExp('="'+flash_width_end[0], 'g'), '="'+embed_width);
    	}
    	else
    	{
    		alert("Sorry, only youtube videos are allowed at this time...");
    		return;
    	}

    	embed_code = '<br /><div>'+new_embed_code+'</div>';
    	document.execCommand('insertHTML', false, embed_code);
    }
}

function get_color(element) {

	if (element.currentStyle)
	{
		return element.currentStyle.color;
	}

	else if (document.defaultView)
	{
		return document.defaultView.getComputedStyle(element, '').getPropertyValue('color');
	}
	else
	{
		return '#ff0000';
	}
}

function clean_all_image_tags(img) {

    var max_width = document.getElementById('text_area_editor').clientWidth;

    if (img.className == 'edit_ready')
    {
        //	safari removes ondblclick attribute after each drag, so we set it back...
        img.setAttribute('ondblclick', 'resize_image(this);');
    }
    else
    {
    	for (var i= img.attributes.length; i-->0;)
        {
            if (img.attributes[i].name != 'src')
            {
                img.removeAttributeNode(img.attributes[i]);
                img.setAttribute('alt', '');
                img.setAttribute('style', 'max-width:'+max_width+'px;');
                img.setAttribute('ondblclick', 'resize_image(this);');
                img.setAttribute('class', 'edit_ready');
            }
        }
    }
}


function clean_all_images() {

    var images = document.getElementById('text_area_editor').getElementsByTagName('img');
    var str = '';

    for(i=0; i < images.length; i++)
    {
        img = images[i];
        clean_all_image_tags(img);
    }
}


function images_edit_mode(mode_switch) {

    var images = document.getElementById('text_area_editor').getElementsByTagName('img');

    for(i=0; i < images.length; i++)
    {
        img = images[i];

        if (mode_switch == 'on')
        {
            img.setAttribute('ondblclick', 'resize_image(this);');
        }
        else
        {
            img.removeAttribute('ondblclick');
        }
    }
}


function resize_image(img) {

	var div_height = document.getElementById('editor_controls').clientHeight - 12;
	var div_width = document.getElementById('editor_controls').clientWidth - 12;
	var img_actual_width = image_file_width(img);
	var action_input_full_value = (img_actual_width >= div_width ? div_width : img_actual_width);
	var action_input_value = Math.round(action_input_full_value);

	img.setAttribute('id', 'editor_div_img_resizing');

	document.getElementById('action_window_input').value = action_input_value;
	document.getElementById('action_window').style.height = div_height+'px';
	document.getElementById('action_window').style.minHeight = '170px';
	document.getElementById('action_window').style.width = div_width+'px';
	document.getElementById('action_window_text').style.marginTop = '20px';
	document.getElementById('html_editor_img_close').style.display = 'none';
	document.getElementById('action_window').style.display = 'block';
	document.getElementById('action_window_input').select();
}

function resize_image_make() {

	var min_width = 10;
	var max_width = document.getElementById('text_area_editor').clientWidth;
	var im_width = document.getElementById('action_window_input').value;
	var img = document.getElementById('editor_div_img_resizing');

	if (im_width.length != 0)
    {
        var new_width_qq = (im_width <= max_width ? im_width : max_width);
        var new_width = (im_width >= min_width ? im_width : min_width);
        img.setAttribute('width', new_width+'px');
        img.setAttribute('style', 'max-width:'+max_width+'px;');
    }

    img.removeAttribute('id');

	document.getElementById('action_window').style.display = 'none';
	document.getElementById('html_editor_img_close').style.display = 'block';
}

function resize_image_cancel() {

	var img = document.getElementById('editor_div_img_resizing');
	img.removeAttribute('id');
	document.getElementById('action_window').style.display = 'none';
	document.getElementById('html_editor_img_close').style.display = 'block';
}

function disable_enter_key(e, func) {

	var key;
	if (window.event)
	{
		key = window.event.keyCode;
	}
	else
	{
		key = e.which;
	}

	if (key == 13)
	{
		if (func == 'i_resize')
		{
		    resize_image_make();
		}
		else if (func == 'l_apply')
		{
		    link_prompt_apply();
		}

	return false;
	}

	return true;
}

function image_file_width(img) {
    var t = new Image();
    t.src = (img.getAttribute ? img.getAttribute('src') : false) || img.src;
    return t.width;
}


function save_selection() {

    if (window.getSelection)
    {
        var sel = window.getSelection();

        if (sel.getRangeAt && sel.rangeCount)
        {
            return sel.getRangeAt(0);
        }
    }
    else if (document.selection && document.selection.createRange)
    {
        return document.selection.createRange();
    }
    return null;
}

function restore_selection(range) {

    if (range)
    {
        if (window.getSelection)
        {
            var sel = window.getSelection();
            sel.removeAllRanges();
            sel.addRange(range);
        }
        else if (document.selection && range.select)
        {
            range.select();
        }
    }
}

function prompt_window(window_part) {

    if (document.getElementById('one_link_inside').value=='on')
    {
        //here we select everything...
        var editor_div = document.getElementById('text_area_editor');
        var new_sel, new_range;

        if (window.getSelection && document.createRange)
        {
            new_range=document.createRange();
            new_range.selectNodeContents(editor_div);
            new_sel=window.getSelection();
            new_sel.removeAllRanges();
            new_sel.addRange(new_range);
        }
        else if (document.body.createTextRange)
        {
            new_range = document.body.createTextRange();
            new_range.moveToElementText(editor_div);
            new_range.select();
        }
    }


    var selection_range = selection_range_make();

    var div_height = document.getElementById('editor_controls').clientHeight - 20;
	var div_width = document.getElementById('editor_controls').clientWidth - 20;

	document.getElementById('prompt_window').style.height = div_height+'px';
	document.getElementById('prompt_window').style.minHeight = '100px';
	document.getElementById('prompt_window').style.width = div_width+'px';


    if (window_part=='link')
    {
        var node = selection_range.anchorNode;
	    var node_href = node.parentNode.href;
	    var node_target = node.parentNode.getAttribute('target');
	    //var attribute_name = node.parentNode.nodeName;

	    if (node_href == null)
	    {
	        var link_href = 'http://www.';
	    }
	    else
	    {
	        var link_href = node_href;
	    }

	    if (node_target)
	    {
	        document.wysiwyg_editor_f.editor_link_targ.value='blank';
	    }

	    document.getElementById('prompt_window_text').value=link_href;

	    selected_range = save_selection();
        document.getElementById('html_editor_img_close').style.display='none';
        document.getElementById('link_prompt_sect').style.display='block';
        document.getElementById('prompt_window').style.display='block';
        document.getElementById('prompt_window_text').focus();
    }
}

function prompt_window_clean() {

    document.getElementById('prompt_window').style.display='none';
    document.getElementById('link_prompt_sect').style.display='none';
    document.getElementById('prompt_window_text').value='';
    document.wysiwyg_editor_f.editor_link_targ.value='same';
    document.getElementById('html_editor_img_close').style.display='block';
}

function link_prompt_apply() {

    var l_targ = '';
    var text = document.getElementById('prompt_window_text').value;

    restore_selection(selected_range);

	if (document.wysiwyg_editor_f.editor_link_targ.value=='blank')
    {
        l_targ = 'target="_blank"';
    }

    if (text.length == 0)
    {
    	document.execCommand('unlink', false, null);
    }
    else
    {
        document.execCommand('insertHTML', false, '<a href="'+text+'" class="link"'+l_targ+'>'+selected_range+'</a>');
    }

    prompt_window_clean();
}

function prompt_cancel() {

/*      - I dont know why the below is here,
        but I disabled it cause it broke link close function (this function) by enabling sortables...

$( "#s101_app_col1, #s101_app_col2, #s101_app_col3, #s101_app_col4, #s101_app_col5, #s101_app_col6" ).sortable({
			connectWith: ".connectedSortable",
			cursor: "move",
			update: function() { s101_app_save_order(); }
		}).disableSelection();

		$( "#s101_side_bar_default, #s101_side_bar_alt, #s101_side_bar_alt2, #s101_side_bar_blog, #s101_side_bar_news_no_press, #s101_side_bar_news, #s101_side_bar_press, #s101_side_bar_side_images, #s101_side_bar_text_image, #s101_side_bar_text, #s101_side_bar_thankyou, #s101_side_bar_video" ).sortable({
			cursor: "move",
			update: function() { s101_app_save_order(); }
		}).disableSelection();

		$( "#s101_##PAGE##_col1" ).sortable({
			cursor: "move",
			update: function() { s101_app_save_order_div('s101_##PAGE##_col1'); }
		}).disableSelection();

		$( "#s101_##PAGE##_col2" ).sortable({
			cursor: "move",
			update: function() { s101_app_save_order_div('s101_##PAGE##_col2'); }
		}).disableSelection();

		$( "#s101_##PAGE##_col3" ).sortable({
			cursor: "move",
			update: function() { s101_app_save_order_div('s101_##PAGE##_col3'); }
		}).disableSelection();
*/

    document.getElementById('text_area_editor').focus();
    restore_selection(selected_range);
    prompt_window_clean();
}


function switch_links(obj_id, on_off) {

    if (document.getElementById && document.getElementsByTagName)
    {
        obj = document.getElementById(obj_id);
        var anchors = obj.getElementsByTagName('a');

        for (var i=0, end=anchors.length; i<end; i++)
        {
            if (on_off == 'off')
            {
                //anchors[i].href='javascript:void(0);';
                anchors[i].onclick=function(){return false;};
            }
        }
    }
}
