function ajaxCall(plugin, controller, method, action, call_arguments)
{
	return _ajx_callAdvFunction(plugin, controller, method, action, call_arguments );
}

function toggleCheckboxes(form_name, form_toggle_name, checkbox_filter_name)
{
	toggle_item_status = document[form_name][form_toggle_name].checked;
	filter_size  = checkbox_filter_name.length;
	for (var i=0; i < document[form_name].length; i++)
	{
		fldObj = document[form_name].elements[i];
		if (fldObj.type != 'checkbox')
		{
			continue;
		}
		item_name = fldObj.name.substr(0,filter_size);
		if (item_name == form_toggle_name)
		{
			fldObj.checked = document[form_name][form_toggle_name].checked;
		}
	}
}

var div_visible= true;

function _(id)
{
    return document.getElementById(id);
} 

function toggle_div( div_id )
{
    div_obj = _( div_id );

    if( div_visible )
    {
       div_obj.style.display = 'none'; 
       div_visible = false;
    } 
    else
    {
       div_obj.style.display=''; 
       div_visible = true;
    } 
} 

function addSmile(smile_id, smile_alias)
{
	var tmp = document.getElementById(smile_id);
	tmp.value += " " + smile_alias + " ";
    tmp.focus();
}

function showMessage()
{
	document.getElementById('screen').style.height = getDocumentHeight();
	document.getElementById('screen').style.display="";
	document.getElementById('message').style.top="200";
	document.getElementById('message').style.left="500";
	
	document.getElementById('message').style.display="";
	Drag.init(document.getElementById('message'));
	
	document.getElementById('message_close').focus();
}

function restore()
{
	_ajx_callFunction('xajax','RunXajax','ajx_dropMessage','');
	document.getElementById('message').style.display='none';
	document.getElementById('screen').style.display='none';
}


function highlight_div(checkbox_node)
{
    label_node = checkbox_node.parentNode;
    if (checkbox_node.checked)
    {
	    label_node.style.backgroundColor='#0a246a';
	    label_node.style.color='#fff';
    }
    else
    {
        label_node.style.backgroundColor='#fff';
        label_node.style.color='#000';
    }
}

function getDocumentHeight()
{
	if( document.height )
	{
		return document.height;
	}
	else if( document.body.clientHeight )
	{
		return document.body.clientHeight;
	}
	return 0;
};


// Expand UL menu tree - Fix for IE
sfHover = function(id) {
	var sfEls = document.getElementById(id).getElementsByTagName('LI');
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=' sfhover';
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"),'');
		}
	}
}




/**
 * This array is used to remember mark status of rows in browse mode
 */
var marked_row = new Array;

function markRowsInit() {
	
    // for every table row ...
    var rows = document.getElementsByTagName('tr');
    for ( var i = 0; i < rows.length; i++ ) {
        // ... with the class 'odd' or 'even' ...
        if ( 'tr_body_1' != rows[i].className.substr(0,9) && 'tr_body_2' != rows[i].className.substr(0,9) ) {
            continue;
        }
        
        // ... add event listeners ...
        // ... to highlight the row on mouseover ...
        if ( navigator.appName == 'Microsoft Internet Explorer' ) {
            // but only for IE, other browsers are handled by :hover in css
            
            rows[i].onmouseover = function() {
                this.className += ' hover';
            }
            rows[i].onmouseout = function() {
                this.className = this.className.replace( ' hover', '' );
            }
        }
        // Do not set click events if not wanted
        if (rows[i].className.search(/noclick/) != -1) {
            continue;
        }
        
        // onload mark checked rows
        checkbox = rows[i].getElementsByTagName( 'input' )[0];
        if ( checkbox && checkbox.type == 'checkbox' ) {
        	if(checkbox.checked) {
        		rows[i].className += ' marked';
        		unique_id=checkbox.name + checkbox.value;
        		marked_row[unique_id] = true;
        	}
        }
        else if ( rows[i].id.length > 0 ) {
             unique_id = rows[i].id;
        }
        else {
             rows[i].id = 'id_'+i;
             unique_id = rows[i].id;
        }
        
        // ... and to mark the row on click ...
        rows[i].onmousedown = function() {
            var unique_id;
            var checkbox;

            checkbox = this.getElementsByTagName( 'input' )[0];
            if ( checkbox && checkbox.type == 'checkbox' ) {
                unique_id = checkbox.name + checkbox.value;
            } else if ( this.id.length > 0 ) {
                unique_id = this.id;
            } else {
            	return;
            }

            if ( typeof(marked_row[unique_id]) == 'undefined' || !marked_row[unique_id] ) {
                marked_row[unique_id] = true;
            } else {
                marked_row[unique_id] = false;
            }

            if ( marked_row[unique_id] ) {
                this.className += ' marked';
            } else {
                this.className = this.className.replace(' marked', '');
            }

            if ( checkbox && checkbox.disabled == false ) {
                checkbox.checked = marked_row[unique_id];
            }
        }
        

        // ... and disable label ...
        var labeltag = rows[i].getElementsByTagName('label')[0];
        if ( labeltag ) {
            labeltag.onclick = function() {
                return false;
            }
        }
        // .. and checkbox clicks
        var checkbox = rows[i].getElementsByTagName('input')[0];
        if ( checkbox ) {
            checkbox.onclick = function() {
                // opera does not recognize return false;
                this.checked = ! this.checked;
            }
        }
    }
}
window.onload=markRowsInit;


function markAllRows( container_class_name ) {
	
	var tables = document.getElementsByTagName('table');
    var rows;
    var unique_id;
    var checkbox;
    var i;
    
    for (i = 0; i < tables.length; i++ ){
    	
    	if(tables[i].className==container_class_name) rows = tables[i].getElementsByTagName('tr');
    }

    for (i = 0; i < rows.length; i++) {

        checkbox = rows[i].getElementsByTagName( 'input' )[0];

        if ( checkbox && checkbox.type == 'checkbox' ) {
            unique_id = checkbox.name + checkbox.value;
            if ( checkbox.disabled == false ) {
                checkbox.checked = true;
                if ( typeof(marked_row[unique_id]) == 'undefined' || !marked_row[unique_id] ) {
                    rows[i].className += ' marked';
                    marked_row[unique_id] = true;
                }
            }
        }
    }

    return true;
}


function unMarkAllRows( container_class_name ) {
    
	var tables = document.getElementsByTagName('table');
    var rows;
    var unique_id;
    var checkbox;
    var i;
    
    for (i = 0; i < tables.length; i++ ){
    	
    	if(tables[i].className==container_class_name) rows = tables[i].getElementsByTagName('tr');
    }

    for (i = 0; i < rows.length; i++ ) {

        checkbox = rows[i].getElementsByTagName( 'input' )[0];

        if ( checkbox && checkbox.type == 'checkbox' ) {
            unique_id = checkbox.name + checkbox.value;
            checkbox.checked = false;
            rows[i].className = rows[i].className.replace(' marked', '');
            marked_row[unique_id] = false;
        }
    }

    return true;
}

function checkAllRows( container_class_name ){
	
	var tables = document.getElementsByTagName('table');
    var rows;
    var unique_id;
    var checkbox;
    var i;
    
    for (i = 0; i < tables.length; i++ ){
    	
    	if(tables[i].className==container_class_name) rows = tables[i].getElementsByTagName('tr');
    }
    
    for (i = 0; i < rows.length; i++ ) {

        checkbox = rows[i].getElementsByTagName( 'input' )[0];

        if ( checkbox && checkbox.type == 'checkbox' && !checkbox.checked) {
        	
        	return markAllRows( container_class_name );
        }
    }
    
    return unMarkAllRows( container_class_name );
}

var tnyTextareasArr = new Array;
function setTextareaToTinyMCE(sEditorID) {
	var oEditor = document.getElementById(sEditorID);
	if(oEditor && (tnyTextareasArr[sEditorID]=='undefined' || !tnyTextareasArr[sEditorID])) {
		tinyMCE.execCommand('mceAddControl', true, sEditorID);
		tnyTextareasArr[sEditorID] = true;
	}
	return;
}
function unsetTextareaToTinyMCE(sEditorID) {
	var oEditor = document.getElementById(sEditorID);
	if(oEditor && tnyTextareasArr[sEditorID]!='undefined' && tnyTextareasArr[sEditorID]) {
		tinyMCE.execCommand('mceRemoveControl', true, sEditorID);
		tnyTextareasArr[sEditorID] = false;
	}
	return;
}

function displayMapPopup(tpg_id, point)
{
    if(  tpg_id <= 0 )
    {
        alert('Please select template page');
        return;
    }
    var template_viewer = '/en/template_viewer/'+tpg_id;

    if( point.length > 0 )
    {
        template_viewer = template_viewer+'/'+point+'/';
    }
    //alert(template_viewer);
    window.open(template_viewer,'','status=yes,scrollbars=yes,resizable=yes,width=800,height=600');
}


