ERR_MESSAGES[CHK_TEXT]		= "Please fill in the field";
ERR_MESSAGES[CHK_NUM]		= "Please enter a number";
ERR_MESSAGES[CHK_INT]		= "Please enter a round number";
ERR_MESSAGES[CHK_EMAIL]		= "The e-mail address is invalid";
ERR_MESSAGES[CHK_LENGTH]	= ["Please enter at least %1 charater(s)","The text can contain maximum %2 characters","The text can contain %1 - %2 characters"];
ERR_MESSAGES[CHK_INTERVAL]	= ["You should enter %1 or a greater number","The value can not be greater than %2","The value must be a number between %1 and %2"];
ERR_MESSAGES[CHK_NOTSELECT]	= ["Please select a(n) %1","Please select a(n) %2","Please select an item"];
ERR_MESSAGES[CHK_PWDMATCH]	= "The passwords do not match";
ERR_MESSAGES[CHK_FILE]	    = "A file should be specified";
ERR_MESSAGES[CHK_REQUIRED]  = ["Please select a(n) %1","Please select a(n) %2","Please select an item"];
ERR_MESSAGES[CHK_RADIO]     = ["Please select a(n) %1","Please select a(n) %2","Please select an item"];
ERR_MESSAGES[CHK_CHECKED]   = ["Please select a(n) %1","Please select a(n) %2","Please select an item"];

function NI()
{
    alert('Under development!');
}

function goIndex()
{
    window.location = basedir;
}

function writeRBS(url_root,id,type)
{
    document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="280" height="340" id="rsb" align="middle" style="float: left; width: 280px; clear: both; margin-bottom: 20px;" >');
    document.write('<param name="allowScriptAccess" value="sameDomain" />');
    document.write('<param name="movie" value="'+url_root+'rsb.swf#id='+id+'|type='+type+'|cfg=rsb.config.xml" />');
    document.write('<param name="quality" value="high" />');
    document.write('<param name="bgcolor" value="#ffffff" />');
    document.write('<embed src="'+url_root+'rsb.swf#id='+id+'|type='+type+'|cfg=rsb.config.xml" quality="high" bgcolor="#ffffff" width="280" height="340" name="rsb" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
    document.write('</object>');
}

function writeRBSFull(url_root,id,type)
{
    document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="100%" height="100%" id="rsb" align="top" style="width: 100%;height:100%">');
    document.write('<param name="allowScriptAccess" value="sameDomain" />');
    document.write('<param name="movie" value="'+url_root+'rsb.swf#id='+id+'|type='+type+'|cfg=rsb.config.full.xml" />');
    document.write('<param name="quality" value="high" />');
    document.write('<param name="bgcolor" value="#ffffff" />');
    document.write('<param name="scale" value="noscale" />');
    document.write('<param name="salign" value="lt" />');
    document.write('<embed src="'+url_root+'rsb.swf#id='+id+'|type='+type+'|cfg=rsb.config.full.xml" quality="high" scale="noscale" salign="lt" bgcolor="#ffffff" width="100%" height="100%" name="rsb" align="top" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
    document.write('</object>');
}

function writeVideoPlayer(url_video_player,url_video,name_video,stillimgurl, _width, _height)
{
document.write('<object id="video" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" style="width:'+(_width != '' ? _width : 400)+'px; height:'+(_height != '' ? _height : 300)+'px;">');
document.write('<param name="movie" value="'+url_video_player+'#src='+url_video+'&volume=100&autoplay=no&fn='+name_video+'&stillimgurl='+stillimgurl+'">');
document.write('<param name="src" value="'+url_video_player+'#src='+url_video+'&volume=100&autoplay=no&fn='+name_video+'&stillimgurl='+stillimgurl+'">');
document.write('<param name="quality" value="High">');
document.write('<param name="allowScriptAccess" value="sameDomain">');
document.write('<param name="bgcColor" value="FFFFFF">');
document.write('<embed src="'+url_video_player+'#src='+url_video+'&volume=100&autoplay=no&fn='+name_video+'&stillimgurl='+stillimgurl+'" quality="high" bgcolor="#ffffff" name="video" allowscriptaccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" style="width:'+(_width != '' ? _width : 400)+'px; height:'+(_height != '' ? _height : 300)+'px; text-align:middle;">');
document.write('</object>');
}

function setUserPref(key,value,level,redirect)
{
    if( redirect == undefined ) redirect = basedir + 'index.php';
    var axID = "axc_setupref_" + key;
	Ajax.call(axID,"update.php?action=ax:setuserpref",null,Ajax.OP_REDIRECT,{post: {"key":key,"value":value,"level":level,"redirect":redirect} });
}

function editProfilePersonal()
{
	var post = (getEbyID("bkProfilePersonal").getElementsByTagName('form').length) ? {} : {editable:"yes"};
    var axID = "axc_editprfpersonal";
	Ajax.call(axID,basedir + "index.php?page=ax:prfpersonal",null,Ajax.OP_SETHTML,{nodeId:"bkProfilePersonal", post: post },true);

    var form = document.forms['frmSetprofilePersonal'];
    if( form )
    {
	    var ascript = "autocom.php";

	    if( form.organ_name )		new AutoComplete("frmSetprofilePersonal::organ_name",		"signup:organization",	ascript);
	    if( form.organ_website )	new AutoComplete("frmSetprofilePersonal::organ_website",	"signup:website",		ascript);
	    if( form.position )			new AutoComplete("frmSetprofilePersonal::position",			"signup:position",		ascript);

        updateSetProfilePersonalStates();
	}
}

function cancelEditProfilePersonal()
{
    var axID = "axc_editprfpersonal";
	Ajax.call(axID,basedir + "index.php?page=ax:prfpersonal",null,Ajax.OP_SETHTML,{nodeId:"bkProfilePersonal", post: {} },true);
}

function editProfileAbout(link)
{
	var post = (getEbyID("bkProfileAbout").getElementsByTagName('form').length) ? {} : {editable:"yes"};
    var axID = "axc_editprfabout";
	Ajax.call(axID,basedir + "index.php?page=ax:prfabout",null,Ajax.OP_SETHTML,{nodeId:"bkProfileAbout", post: post },true);
}

function cancelEditProfileAbout()
{
    var axID = "axc_editprfabout";
	Ajax.call(axID,basedir + "index.php?page=ax:prfabout",null,Ajax.OP_SETHTML,{nodeId:"bkProfileAbout", post: {} },true);
}

function editProfileAvatar()
{
	var post = (getEbyID("bkProfileAvatar").getElementsByTagName('form').length) ? {} : {editable:"yes"};
    var axID = "axc_editprfavatar";
	Ajax.call(axID,basedir + "index.php?page=ax:prfavatar",null,Ajax.OP_SETHTML,{nodeId:"bkProfileAvatar", post: post },true);
	updateCommAvatarStates();
	avatarSetBgColor(document.forms['frmSetprofileAvatar'].avatar_type.item(0));
}

function cancelEditProfileAvatar()
{
    var axID = "axc_editprfavatar";
	Ajax.call(axID,basedir + "index.php?page=ax:prfavatar",null,Ajax.OP_SETHTML,{nodeId:"bkProfileAvatar", post: {} },true);
}

function editProfileContact()
{
	var post = (getEbyID("bkProfileContact").getElementsByTagName('form').length) ? {} : {editable:"yes"};
    var axID = "axc_editprfcontact";
	Ajax.call(axID,basedir + "index.php?page=ax:prfcontact",null,Ajax.OP_SETHTML,{nodeId:"bkProfileContact", post: post },true);
}

function cancelEditProfileContact()
{
    var axID = "axc_editprfcontact";
	Ajax.call(axID,basedir + "index.php?page=ax:prfcontact",null,Ajax.OP_SETHTML,{nodeId:"bkProfileContact", post: {} },true);
}

function goMakeAPost(section)
{
    if( section == "library" )
        window.location = basedir + "make_a_post?reset=yes";
    else
        window.location = basedir + "make_a_post?reset=yes&section=" + section;
}

function updateSignupStates(formName,wpage)
{
    var form = document.forms[formName];
    switch( wpage )
    {
        case "2"    :   var bkOrganName = getEbyID('bkOrganName');
						var bkOrganWebsite = getEbyID('bkOrganWebsite');
                        showBlock(bkOrganName,getRadioValue(form.organmember) == "yes");
                        showBlock(bkOrganWebsite,getRadioValue(form.organmember) == "yes");
                        enableInput(form.organ_name,getRadioValue(form.organmember) == "yes");
                        enableInput(form.organ_website,getRadioValue(form.organmember) == "yes");
                        break;
    }
}

function updateSetProfilePersonalStates()
{
    var form = document.forms['frmSetprofilePersonal'];
    var rowOrganName = getEbyID('rowOrganName');
	var rowOrganWebsite = getEbyID('rowOrganWebsite');
    showRow(rowOrganName,getRadioValue(form.organmember) == "yes");
    showRow(rowOrganWebsite,getRadioValue(form.organmember) == "yes");
    enableInput(form.organ_name,getRadioValue(form.organmember) == "yes");
    enableInput(form.organ_website,getRadioValue(form.organmember) == "yes");
}

function updateEditUserStates(formName)
{
    var form = document.forms[formName];
    var bkOrganName = getEbyID('bkOrganName');
	var bkOrganWebsite = getEbyID('bkOrganWebsite');
    showBlock(bkOrganName,getRadioValue(form.organmember) == "yes");
    showBlock(bkOrganWebsite,getRadioValue(form.organmember) == "yes");
    enableInput(form.organ_name,getRadioValue(form.organmember) == "yes");
    enableInput(form.organ_website,getRadioValue(form.organmember) == "yes");
}


function makePost()
{
    if( checkMakePost() )
    {
        var form = document.forms['frmMakepost'];
        return true;
    }

    return false;
}

function previewPost()
{
    if( checkMakePost() )
    {
        var form = document.forms['frmMakepost'];
        form.preview.value = 'yes';
        form.submit();
    }
}

function addURLListItem(name)
{
    var sel = getEbyID("ctrlurllist_"+name);
    var title = getEbyID("ctrlurllist_title_"+name);
    var link = getEbyID("ctrlurllist_link_"+name);
    if( ! sel ) { alert('Invalid URL list control!'); return false;};
    if( ! title ) { alert('Invalid title of URL list control!'); return false;};
    if( ! link ) { alert('Invalid link of URL list control!'); return false;};


    if( checkInput(title,CHK_TEXT,"") )
        if( checkInput(link,CHK_TEXT,"") )
        {

            var optTitle = title.value + " (" + link.value + ")";
            var optValue = "<" + link.value + ">" + title.value;
            listAddOption(sel,optValue,optTitle);

            title.value = "";
            link.value = "";
        }
}

function removeURLListItem(name)
{
    var sel = getEbyID("ctrlurllist_"+name);
    if( ! sel ) { alert('Invalid URL list control!'); return false;};

    if( sel.options.length > 0 )
    {
        if( sel.selectedIndex > -1 )
            listDelOption(sel,true);
        else
            alert('Select an option!');
    }
}

function filterBrowseMembers(filter,value)
{
    var form = document.forms['frmFilterMembers'];

    if( filter == "work_profile" )
    {
        var last_wp = form.work_profile.value;
        if( last_wp != "" )
        {
            var nodeLink = getEbyID("linkWorkprofile_" + last_wp);
            if( nodeLink )
                nodeLink.className = nodeLink.className.replace(/\s*selected/,"");
        }

        var nodeLink = getEbyID("linkWorkprofile_" + value);
        if( nodeLink )
            nodeLink.className += " selected";

        form.work_profile.value = value;
    }

    var axID = "axc_browsemembers";
	Ajax.call(axID,basedir + "index.php?page=ax:browsemembers",null,Ajax.OP_SETHTML,{nodeId:"bkUserList", post: {"searchtext":form.searchtext.value,"letter":form.letter.value,"work_profile":form.work_profile.value,"usergroup": (form.usergroup.checked?form.usergroup.value:'')} });
}

function filterBrowseOrganizations(filter,value)
{
    var form = document.forms['frmFilterOrganizations'];

    if( filter == "work_profile" )
    {
        var last_wp = form.work_profile.value;
        if( last_wp != "" )
        {
            var nodeLink = getEbyID("linkWorkprofile_" + last_wp);
            if( nodeLink )
                nodeLink.className = nodeLink.className.replace(/\s*selected/,"");
        }

        var nodeLink = getEbyID("linkWorkprofile_" + value);
        if( nodeLink )
            nodeLink.className += " selected";

        form.work_profile.value = value;
    }

    var axID = "axc_browseorganizations";
	Ajax.call(axID,basedir + "index.php?page=ax:browseorganizations",null,Ajax.OP_SETHTML,{nodeId:"bkUserList", post: {"searchtext":form.searchtext.value,"letter":form.letter.value,"work_profile":form.work_profile.value,"usergroup": (form.usergroup.checked?form.usergroup.value:'')} });
}

var _FILTER_WORDS = {};

function filterWorkspaceSectionList(section,filter,value,noload)
{
    var form = document.forms['frmFilterWSL' + section];

    if( filter == "work_profile" )
    {
        if( value == "" ) value = "all";
        var last_wp = form.work_profile.value;
        if( last_wp != "" )
        {
            var nodeLink = getEbyID("linkWorkprofile_" + last_wp);
            if( nodeLink )
                nodeLink.className = nodeLink.className.replace(/\s*selected/,"");
        }

        var nodeLink = getEbyID("linkWorkprofile_" + value);
        if( nodeLink )
            nodeLink.className += " selected";

        form.work_profile.value = value;

		_FILTER_WORDS[filter] = value;
    }


    if( filter == "section" )
    {
        if( value == "" ) value = "all";
        var last_section = form.section.value;
        if( last_section != "" )
        {
            var nodeLink = getEbyID("linkSection_" + last_section);
            if( nodeLink )
                nodeLink.className = nodeLink.className.replace(/\s*selected/,"");
        }

        var nodeLink = getEbyID("linkSection_" + value);
        if( nodeLink )
            nodeLink.className += " selected";

        form.section.value = value;

		_FILTER_WORDS[filter] = value;
    }

    if( filter == "sltopic" )
    {
        if( value == "" ) value = "all";
        var last_sltopic = form.sltopic.value;
        if( last_sltopic != "" )
        {
            var nodeLink = getEbyID("linkSLTopic_" + last_sltopic);
            if( nodeLink )
                nodeLink.className = nodeLink.className.replace(/\s*selected/,"");
        }

        var nodeLink = getEbyID("linkSLTopic_" + value);
        if( nodeLink )
            nodeLink.className += " selected";

        form.sltopic.value = value;
    }

    if( filter == "yearmonth" )
    {
        if( value == "" ) value = "";
        var last_date = form.yearmonth.value;
        if( last_date != "" )
        {
            var nodeLink = getEbyID("linkDate_" + last_date);
            if( nodeLink )
                nodeLink.className = nodeLink.className.replace(/\s*selected/,"");
        }

        var nodeLink = getEbyID("linkDate_" + value);
        if( nodeLink )
            nodeLink.className += " selected";

        form.yearmonth.value = value;

        if( form.list_month )
            if( listSelectByValue(form.list_month,value) == 0 )
                listSelectByValue(form.list_month,"");
    }

    if( filter == "locationflip" )
    {
        var bkLocationFilter = getEbyID('bkLocationFilter');
        if( bkLocationFilter )
            showBlock(bkLocationFilter, !isVisible(bkLocationFilter));

        noload = true;

        if( !isVisible(bkLocationFilter) )
        {
            if( form.id_country )
                listSelectByValue(form.id_country,"");
            if( form.city )
            {
                listDelOption(form.city,false);
                listAddOption(form.city,"","All cities");
            }
        }
    }

    if( filter == "country" )
    {
        if( value == "" )
        {
            listDelOption(form.city,false);
            listAddOption(form.city,"","All cities");
        }
    }

    if( !noload)
    {
        var axID = "axc_list" + section;
        var post = {};
        if( form.section )
            post.section = form.section.value;
        if( form.sltopic )
            post.sltopic = form.sltopic.value;
        if( form.work_profile )
            post.work_profile = form.work_profile.value;
        if( form.privacy )
            post.privacy = (form.privacy.checked?form.privacy.value:'');
        if( form.yearmonth )
            post.yearmonth = form.yearmonth.value;
        if( form.tag )
            post.tag = form.tag.value;
        if( form.fulltext )
            post.fulltext = form.fulltext.value;
        if( form.organ_name )
            post.organ_name = form.organ_name.value;
        if( form.id_user )
            post.id_user = form.id_user.value;
        if( form.city )
        {
            post.id_country = form.id_country.value;
            post.city = form.city.value;
        }

		Ajax.call(axID,basedir + "index.php?page=ax:list" + section,null,Ajax.OP_SETHTML,{"nodeId":"bkWSL"+section, "post": post});
    }

	if( getEbyID("bkSearchFilters") )
	{
		var res = [];
		for(var i in _FILTER_WORDS)
		{
			switch( _FILTER_WORDS[i] )
			{
				case 'all'				:	if(i == "work_profile")
												res.unshift("All people");
											else
												res.push("All contents");
											break;

				case 'busleader'		: res.unshift('Business leader');break;
				case 'analyst'			: res.unshift('Analyst');break;
				case 'academic'			: res.unshift('Academic');break;
				case 'regulator'		: res.unshift('Regulator');break;
				case 'diguser'			: res.unshift('DE User');break;
				case 'forum'			: res.unshift('DE Community Manager');break;
				case 'discussions'		: res.push('Discussions');break;
				case 'papers'			: res.push('Papers');break;
				//case 'community_news'	: res.push('Community news');break;
				case 'videos'			: res.push('Videos');break;
				case 'events'			: res.push('Events');break;
			}
		}

		var res = res.join(" / ");
		if( res )
			getEbyID("bkSearchFilters").innerHTML = "/ "+res;
		else
			getEbyID("bkSearchFilters").innerHTML = "";
	}
}

function updateMakepostStates()
{
	var sendButtonCaptions = {
		videos : "Post to videos",
		discussions	: "Post to discussions",
		events : "Post to events",
		papers : "Post to papers"
		//community_news : "Post to community news"
	};

    var form = document.forms['frmMakepost'];
    var section = form.section.options[form.section.selectedIndex].value;

    var bkPostOriginalSource = getEbyID('bkPostOriginalSource');
    var bkPostAddress = getEbyID('bkPostAddress');
    var bkPostLocation = getEbyID('bkPostLocation');
    var bkPostFacility = getEbyID('bkPostFacility');
    var bkPostDateTo = getEbyID('bkPostDateTo');
    var bkPostDateRefer = getEbyID('bkPostDateRefer');
    var bkPostMoreInfo = getEbyID('bkPostMoreInfo');
    var bkPostAttachFiles = getEbyID('bkPostAttachFiles');
    var bkPostUploadVideo = getEbyID('bkPostUploadVideo');

    //showBlock(bkPostOriginalSource,(section == "community_news"));
    showBlock(bkPostAddress,(section == "events"));
    showBlock(bkPostLocation,(section == "events"));
    showBlock(bkPostFacility,(section == "events"));
    showBlock(bkPostDateTo,(section == "events"));
    showBlock(bkPostDateRefer,(section == "events"));
    showBlock(bkPostMoreInfo,(section == "events"));
    showBlock(bkPostAttachFiles,(section != "videos"));
    showBlock(bkPostUploadVideo,(section == "videos"));

	if( form.id_post.value > 0 )
        getEbyID('sendPostButton').value = 'Save';
	else
    	if( section && sendButtonCaptions[section] )
    		getEbyID('sendPostButton').value = sendButtonCaptions[section];
    	else
    		getEbyID('sendPostButton').value = 'Post';

    if( section != "videos" )
        resizeIframe('ifUploadAttachment');

    if( section == "videos" )
        resizeIframe('ifUploadVideo');
}

function requireRecentActivity(section,content)
{
    var linkRecentComments = getEbyID('linkRecentComments');
    var linkRecentPosts = getEbyID('linkRecentPosts');

    linkRecentComments.className = linkRecentComments.className.replace("selected","");
    linkRecentPosts.className = linkRecentPosts.className.replace("selected","");

    switch( content )
    {
        case 'comments' :   linkRecentComments.className += "selected";
                            break;
        case 'posts'    :   linkRecentPosts.className += "selected";
                            break;
    }

    var axID = "axc_recentactivity_" + content;
    Ajax.call(axID,basedir + "index.php?page=ax:recentactivity",null,Ajax.OP_SETHTML,{nodeId:"bkRecentActivityContainer", post: {"section":section,"content":content} });
}

function uploadAttachment()
{
    var form = document.forms['frmUploadAttachment'];

	if( form.title.value == form.title.title )
		form.title.value = '';

    if( checkFile(form.file_attch,"") )
        if( checkInput(form.title,CHK_LENGTH,"",3) )
            form.submit();
}

function uploadVideo()
{
    var form = document.forms['frmUploadVideo'];

    if( checkFile(form.file_video,"") )
        form.submit();
}

function deleteAttachment(id_attachment,id_post)
{
    if( confirm('Are you sure ?') )
    {
        window.location = basedir + "update.php?action=common:deleteattch&id_attachment=" + id_attachment + "&id_post=" + id_post;
    }
}

function openMap(addr)
{
    openPopupPage(basedir + "map.php?addr="+addr,"POP_MAP",640,480, "location:no;menubar:no;resizable:no;scrollbars:no;status:yes;titlebar:yes;toolbar:no;center:yes", false);
}

function fillSelect(cmd, id, param)
{
	Ajax.call("FS_"+id,basedir + "index.php?page="+cmd,null,Ajax.OP_SELECT,{nodeId:id, post:{param:param}},true);
}

function goSuggestAFeed()
{
    window.location = basedir + "suggest_a_feed";
}

function addToMySpotlight(category,title,value)
{
    var axID = "Addtomysl_" + category;
    
    if( category == "search" )
        var postfix = '	&nbsp;|&nbsp;<img src="images/icon.rss.feed.gif" alt="" /><a href="rss/search/'+value+'/rss.xml">subscribe to feed</a>';
    else
        var postfix = "";
    Ajax.call(axID,"update.php?action=myspotlight:add",null,Ajax.OP_AUTO,{post: {"category":category,"value":value,"title":title,"postfix":postfix} });
}

function spotlightAdded(postfix)
{
    /*
	getEbyID('makenew').onclick = function(){};
	getEbyID('makenew').style.cursor = "default";
	getEbyID('makenew').style.backgroundImage = "url('images/button.item.added.to.your.spotlight.gif')";
	*/
	
	if( postfix == undefined )
	    postfix = '';
	    
	getEbyID('bkAddToMySpotlight').innerHTML = '<img src="images/icon.spotlight.gif" alt="" style="" />added to my spotlight!' + postfix;
}


function removeFromMySpotlight(id_sltopic)
{
    if( confirm('Are you sure you want to remove this item from the spotlight?') )
    {
        var axID = "axc_removespotlightlist";
        var post = {};
        post.id_sltopic = id_sltopic;

	    Ajax.call(axID,"update.php?action=myspotlight:remove",null,Ajax.OP_SETHTML,{"nodeId":"bkSpotlightTopiclist", "post": post});
    }
}

function doneMySpotlightEditing()
{
    window.location = basedir + "my_spotlight";
}

function postSearch(formName)
{
    var form = document.forms[formName];

    if( form )
        if( checkInput(form.fulltext,CHK_LENGTH,"Please enter at least 3 characters.",3) )
            return true;

    return false;
}

function postPeopleSearch()
{
    var form = document.forms['frmPeopleSearch'];

    if( form )
        if( checkInput(form.searchtext,CHK_LENGTH,"Please enter at least 3 characters.",3) )
            return true;

    return false;
}

function postLiveSearch(frm)
{
	if( frm == "frmFilterWSLlibrary" )
		filterWorkspaceSectionList('library','tag', document.forms[frm]["tag"].value);
	else
		document.forms[frm].submit();
}

function enableSearchSuggestion()
{
    if( document.forms['frmSearch'] )
    {
	    var ascript = "autocom.php";
	    new AutoComplete("frmSearch::fulltext",	"search:suggestion",	ascript, [window, "postLiveSearch", "frmSearch"]);
	}
    if( document.forms['frmNewsearch'] )
    {
	    var ascript = "autocom.php";
	    new AutoComplete("frmNewsearch::fulltext",	"search:suggestion",	ascript, [window, "postLiveSearch", "frmNewsearch"]);
	}
}

function enableLibraryTagSuggestion()
{
    if( document.forms['frmFilterWSLlibrary'] )
    {
	    var ascript = "autocom.php";
	    new AutoComplete("frmFilterWSLlibrary::tag",	"library:tag",	ascript, [window, "postLiveSearch","frmFilterWSLlibrary"]);
	}
}

function setStillVideoImage()
{
    var form = document.forms['frmStillImage'];

    if( form.stillimg )
    {
        if( checkRadio(form.stillimg) )
            return true;

        if( checkFile(form.upload_stillimg) )
            return true;

        alert("Select an image frame for still image or upload a new one!");
    }
    else
        if( checkFile(form.upload_stillimg,"Browse a file for still image!") )
            return true;

    return false;
}

function votePoll()
{
    var form = document.forms['frmPoll'];

    if( checkRadio(form.id_answer,"Select an option!") )
        form.submit();
}

function goSurveyPage(sp)
{
    window.location = basedir + "survey?sp=" + sp;
}

function submitSurvey()
{
    if( surveycheck )
    {
        var form = document.forms['frmSurvey'];
        for(var i=0;i < surveycheck.length;i++)
        {
            if( surveycheck[i].compulsion == "yes" )
                switch( surveycheck[i].type )
                {
                    case 'text' :   var element = form.elements['item'+surveycheck[i].id_surveyitem];
                                    if( !checkInput(element,CHK_TEXT,"Please give an answer to this question: " + surveycheck[i].question) )
                                        return false;
                                    break;
                    case 'radio':   var element = form.elements['item'+surveycheck[i].id_surveyitem];
                                    if( !checkRadio(element,"Please select an answer for this question: " + surveycheck[i].question) )
                                        return false;
                                    break;
                    case 'check':   if( !checkCBList("surveyitem"+surveycheck[i].id_surveyitem+"_",0,surveycheck[i].num_answer-1,1,"Please select at least one answer for this question: " + surveycheck[i].question) )
                                        return false;
                                    break;
                }
        }

        return true;
    }

    return false;
}

function setUserContactPrivacy(key,privacy)
{
    var form = document.forms['frmSetprofileContact'];
    var last_privacy = form.elements[key].value;
    if( last_privacy != "" )
    {
        var nodeLink = getEbyID("linkUCP_" + key + "_" + last_privacy);
        if( nodeLink )
            nodeLink.className = nodeLink.className.replace(/\s*selected/,"");
    }

    var nodeLink = getEbyID("linkUCP_" + key + "_" + privacy);
    if( nodeLink )
        nodeLink.className += " selected";

    form.elements[key].value = privacy;
}

function postPrivMsg()
{
    var form = document.forms['frmPrivMsg'];

    if( checkInput(form.msgbody,CHK_TEXT,"Please fill the message body!") )
        return true;

    return false;
}

function addExternalURL(formName,fnURL,fnTitle,fnContainer,divListName)
{
    var form = document.forms[formName];
    if( form )
    {
        var inURL = form.elements[fnURL];
        var inTitle = form.elements[fnTitle];
        var inContainer = form.elements[fnContainer];
        var divList = getEbyID(divListName);

        if( (inURL) && (inContainer) && (divList) )
        {
            if( checkInput(inURL,CHK_LENGTH,"Please type the URL!",3) )
                if( (!inTitle) || ((inTitle) && (checkInput(inTitle,CHK_LENGTH,"Please type the title!",3))) )
                {
                    if( inContainer.value != "" )
                    {
                        var l = inContainer.value.split("\n");
                        var idx = l.length;
                    }
                    else
                        var idx = 0;
                        
                    var title = (inTitle) ? inTitle.value : '';

                    divList.innerHTML += title + ' (' + inURL.value + ') <a href="javascript:delExternalURL(\''+idx+'\',\''+formName+'\',\''+fnContainer+'\',\''+divListName+'\');">(Delete)</a><br />';
                    if(inContainer.value != "")
                        inContainer.value += "\n";
                    inContainer.value += "<" + inURL.value + ">" + title;
                    inURL.value = "";
                    
                    if( inTitle )
                        inTitle.value = "";
                }
        }
    }
}

function delExternalURL(idx,formName,fnContainer,divListName)
{
    var form = document.forms[formName];
    if( form )
    {
        var inContainer = form.elements[fnContainer];
        var divList = getEbyID(divListName);

        if( (inContainer) && (divList) )
        {
            if( inContainer.value != "" )
            {
                if( confirm('Are you sure ?') )
                {
                    var l = inContainer.value.split("\n");
                    var t = new Array();

                    for(var i=0;i < l.length;i++)
                        if( i != idx )
                            t[t.length] = l[i];

                    divList.innerHTML = "";
                    inContainer.value = "";

                    var idx = 0;
                    for(var i=0;i < t.length;i++)
                    {
                        var val = t[i];
                        var fD = val.indexOf('<');
                        var lD = val.lastIndexOf('>');
                        var url = val.substr(fD+1,lD-fD-1);
                        var title = val.substr(lD+1);

                        if( (url) && (title) )
                        {
                            divList.innerHTML += title + ' (' + url + ') <a href="javascript:delExternalURL(\''+idx+'\',\''+formName+'\',\''+fnContainer+'\',\''+divListName+'\');">(Delete)</a><br />';
                            inContainer.value += "<" + url + ">" + title + "\n";
                            idx++;
                        }
                    }
                }
            }
        }
    }
}

function postSetAvatar()
{
    var form = document.forms['frmSetprofileAvatar'];
    var avatar_type = getRadioValue(form.avatar_type);

    if( avatar_type == "own" )
        return true;

    if( avatar_type == "community" )
        if( checkRadio(form.gender,"Please select your gender!") )
            if( form.commavatar.value == "" )
                alert("Please select an avatar from the list!");
            else
                return true;
        

    return false;
}

function updateCommAvatarStates()
{
    var form = document.forms['frmSetprofileAvatar'];
    var gender = getRadioValue(form.gender);
    
    var axID = "axc_avatarthumbs";
    var post = {"gender":gender,"work_profile":form.work_profile.value};
    Ajax.call(axID,basedir + "index.php?page=ax:avatarthumbs",null,Ajax.OP_SETHTML,{nodeId:"bkAvatarThumbs", post: post},true);    
}

function setCommAvatar(avatar,url_full)
{
    var imgCommAvatar = getEbyID('imgCommAvatar');
    if( imgCommAvatar )
        imgCommAvatar.src = url_full;
        
    var form = document.forms['frmSetprofileAvatar'];
    if( form )
        form.commavatar.value = avatar;
}

/*** ADMIN *******************************************************************************************/

function adminToggleOption(optionName,mustConfirm,param)
{
    var confirmed = (mustConfirm) ? confirm('Are your sure ?') : true;

    if( confirmed )
    {
        var axID = "axc_adminsetopt" + optionName;
        var post = {"optionName":optionName};
        if( typeof(param) == "object" )
            for(key in param)
                post[key] = param[key];

	    Ajax.call(axID,"update.php?action=ax:admintoggleopt",null,Ajax.OP_AUTO,{"post": post},true);
    }
}

function adminSetOption(optionName,bChecked)
{
    var imgNode = getEbyID('imgToggleOption_' + optionName);
    if( imgNode )
    {
		var res = imgNode.src.replace(/unchecked\.gif|checked.gif/,'');
        imgNode.src = res + ((bChecked) ? "checked.gif" : "unchecked.gif");
    }
}


/** Newsletter **/

function nfIndex()
{
    window.location = basedir + 'admin/news_fix';
}

function nfAddNewFeed()
{
    window.location = basedir + 'admin/news_fix?section=addfeed';
}

function nfEditFeed(newsfeed)
{
    if( newsfeed != undefined )
        window.location = basedir + 'admin/news_fix?section=editfeed&newscat=' + newsfeed;
    else
        window.location = basedir + 'admin/news_fix?section=editfeed';
}

function nfEditCat(newscat)
{
    if( newscat != undefined )
        window.location = basedir + 'admin/news_fix?section=editcat&newscat=' + newscat;
    else
        window.location = basedir + 'admin/news_fix?section=editcat';
}

function nfDeleteCat(newscat)
{
    if( confirm('Are you sure ?') )
    {
        var form = document.forms['frmEditNFCat'];
        form.id_newscat.value = newscat;
        form.action.value = "newsfix:delcat";
        form.submit();
    }
}

function nfPreviewFeed(feed)
{
    window.location = basedir + "admin/news_fix?section=preview&feed=" + feed;
}

function nfDeleteFeed(feed)
{
    if( confirm('Are you sure ?') )
    {
        var form = document.forms['frmEditNFeed'];
        form.id_newsfeed.value = feed;
        form.action.value = "newsfix:delfeed";
        form.submit();
    }
}

function nfOrderFeedList(orderway)
{
    var orderdir = 'asc';
    if( feedlist_orderway == orderway )
        orderdir = (feedlist_orderdir == "asc") ? "desc" : "asc";
    window.location = basedir + 'admin/news_fix?section=editfeed&orderway=' + orderway + '&orderdir=' + orderdir;
}

/** Poll **/

function pollIndex()
{
    window.location = basedir + 'admin/poll';
}

function pollAdd()
{
    window.location = basedir + 'admin/poll?section=edit';
}

function pollDelete(id_poll)
{
    if( confirm('Are you sure ?') )
    {
        var form = document.forms['frmEditPoll'];
        form.id_poll.value = id_poll;
        form.action.value = "poll:delpoll";
        form.submit();
    }
}

function pollModify(poll)
{
    window.location = basedir + 'admin/poll?section=edit&poll=' + poll;
}

function pollActivate()
{
    if( confirm('Are you sure ?') )
    {
        var form = document.forms['frmEditPoll'];
        form.submit();
    }
}

function pollClose()
{
    if( confirm('Are you sure ?') )
    {
        var form = document.forms['frmEditPoll'];
        form.action.value = "poll:close";
        form.submit();
    }
}

function previewPoll(poll)
{
    window.location = basedir + "admin/poll?section=preview&poll="+poll;
}

function pollSetAnswer()
{
    var form = document.forms['frmEditPoll'];

//        if( checkInput(form.answer_rank,CHK_TEXT,"") )
  //          if( checkInput(form.answer_rank,CHK_INT,"") )

    if( checkInput(form.answer_title,CHK_TEXT,"") )
            {
                if( form.answeridx.value == "" )
                    Ajax.call("axc_polladdanswer","update.php?action=ax:addpollanswer",null,Ajax.OP_AUTO,{post: {"answer_title":form.answer_title.value} },true);
                else
                    Ajax.call("axc_pollmodanswer","update.php?action=ax:modpollanswer",null,Ajax.OP_AUTO,{post: {"idx":form.answeridx.value,"answer_title":form.answer_title.value} },true);

                form.answer_title.value = "";
                //form.answer_rank.value = "";
                form.answeridx.value = "";

                showBlock(getEbyID('linkPollAddAnswer'),true);
                showBlock(getEbyID('linkPollModAnswer'),false);
                showBlock(getEbyID('linkPollCancelModAnswer'),false);
            }
}

function pollModAnswer(idx,title,rank)
{
    var form = document.forms['frmEditPoll'];
    form.answer_title.value = title;
    //form.answer_rank.value = rank;
    form.answeridx.value = idx;
    showBlock(getEbyID('linkPollAddAnswer'),false);
    showBlock(getEbyID('linkPollModAnswer'),true);
    showBlock(getEbyID('linkPollCancelModAnswer'),true);
}

function pollCancelModAnswer()
{
    var form = document.forms['frmEditPoll'];
    form.answer_title.value = "";
    //form.answer_rank.value = "";
    form.answeridx.value = "";

    showBlock(getEbyID('linkPollAddAnswer'),true);
    showBlock(getEbyID('linkPollModAnswer'),false);
    showBlock(getEbyID('linkPollCancelModAnswer'),false);
}

function pollDelAnswer(idx)
{
    if( confirm('Are you sure ?') )
        Ajax.call("axc_polldelanswer","update.php?action=ax:delpollanswer",null,Ajax.OP_AUTO,{post: {"idx":idx} },true);
}

function pollMoveupAnswer(idx)
{
    Ajax.call("axc_pollmoveupanswer","update.php?action=ax:moveuppollanswer",null,Ajax.OP_AUTO,{post: {"idx":idx} },true);
}

function pollMovedownAnswer(idx)
{
    Ajax.call("axc_pollmovedownanswer","update.php?action=ax:movedownpollanswer",null,Ajax.OP_AUTO,{post: {"idx":idx} },true);
}

function pollPost()
{
    var form = document.forms['frmEditPoll'];

    if( checkInput(form.question,CHK_TEXT,"") )
        if( form.num_answer.value > 0 )
            return true;
        else
            alert('Add at least one answer!');

    return false;
}

function pollListArchive()
{
    window.location = basedir + 'admin/poll?section=listarch';
}


function pollOrderPollList(orderway)
{
    var orderdir = 'asc';
    if( polllist_orderway == orderway )
        orderdir = (polllist_orderdir == "asc") ? "desc" : "asc";
    window.location = basedir + 'admin/poll?section=listarch&orderway=' + orderway + '&orderdir=' + orderdir;
}

/** User **/

function userIndex()
{
    window.location = basedir + 'admin/user';
}

function userAdd()
{
    window.location = basedir + 'admin/user?section=add';
}

function userCancelAdd()
{
    window.location = basedir + 'admin/user?section=canceladd';
}

function userEdit(id_user)
{
    window.location = basedir + 'admin/user?section=edit&user=' + id_user;
}

function userDeleteContent(id_user)
{
    var sel = getEbyID('selUserDeleteContent');
    var content = listGetSelectedValue(sel);

    switch( content )
    {
        case 'user'     :   if( confirm('Are you sure ?') )
                                window.location = basedir + "update.php?action=user:del&id_user=" + id_user;
                            break
        case 'postcomm' :   if( confirm('Are you sure ?') )
                                window.location = basedir + "update.php?action=user:delpostcomm&id_user=" + id_user;
                            break
    }
}

function userBrowseMembers(l)
{
    if( l != undefined )
        window.location = basedir + 'admin/user?section=browsemembers&l=' + l;
    else
        window.location = basedir + 'admin/user?section=browsemembers&reset=yes';
}

function userBrowseOrganizations(l)
{
    if( l != undefined )
        window.location = basedir + 'admin/user?section=browseorganizations&l=' + l;
    else
        window.location = basedir + 'admin/user?section=browseorganizations&reset=yes';
}

function userBrowseAdministrators(l)
{
    if( l != undefined )
        window.location = basedir + 'admin/user?section=browseadmin&l=' + l;
    else
        window.location = basedir + 'admin/user?section=browseadmin&reset=yes';
}

function userBrowseTrustedUsers(l)
{
    if( l != undefined )
        window.location = basedir + 'admin/user?section=browsetrusted&l=' + l;
    else
        window.location = basedir + 'admin/user?section=browsetrusted&reset=yes';
}

function userRecentUsers()
{
    window.location = basedir + 'admin/user?section=recentusers';
}

function userRecentOrganizations()
{
    window.location = basedir + 'admin/user?section=recentorgan';
}

function userOrderRecentOrganization(orderway)
{
    var orderdir = 'asc';
    if( recorganlist_orderway == orderway )
        orderdir = (recorganlist_orderdir == "asc") ? "desc" : "asc";
    window.location = basedir + 'admin/user?section=recentorgan&orderway=' + orderway + '&orderdir=' + orderdir;
}

function userOrderRecentUser(orderway)
{
    var orderdir = 'asc';
    if( recuserlist_orderway == orderway )
        orderdir = (recuserlist_orderdir == "asc") ? "desc" : "asc";
    window.location = basedir + 'admin/user?section=recentusers&orderway=' + orderway + '&orderdir=' + orderdir;
}



/** Tag **/

function tagIndex()
{
    window.location = basedir + "admin/tag";
}

function tagRename(tag)
{
    window.location = basedir + "admin/tag?section=edit&tag=" + tag;
}

function tagDelete(tag)
{
    if( confirm('Are you sure ?') )
        window.location = basedir + "update.php?action=tag:del&tag=" + tag;
}

function tagOrderTagList(orderway)
{
    var orderdir = 'asc';
    if( taglist_orderway == orderway )
        orderdir = (taglist_orderdir == "asc") ? "desc" : "asc";
    window.location = basedir + 'admin/tag?orderway=' + orderway + '&orderdir=' + orderdir;
}

/** Editpage **/

function editpageIndex()
{
    window.location = basedir + "admin/content_pages";
}

function editpageModify(name)
{
    window.location = basedir + "admin/content_pages?section=edit&pn=" + name;
}

function tagOrderTagList(orderway)
{
    var orderdir = 'asc';
    if( taglist_orderway == orderway )
        orderdir = (taglist_orderdir == "asc") ? "desc" : "asc";
    window.location = basedir + 'admin/tag?orderway=' + orderway + '&orderdir=' + orderdir;
}


/** Post **/

function postIndex()
{
    window.location = basedir + 'admin/post?reset=yes';
}

function postOrderPostCommList(orderway)
{
    var orderdir = 'asc';
    if( postcommlist_orderway == orderway )
    {
        orderdir = (postcommlist_orderdir == "asc") ? "desc" : "asc";
    }
    window.location = basedir + 'admin/post?orderway=' + orderway + '&orderdir=' + orderdir;
}

function postRemovePost(post,back)
{
    if( back == undefined ) back = "admin";
    if( confirm('Are you sure ?') )
        window.location = basedir + "update.php?action=workspace:delpost&back="+back+"&id_post=" + post;
}

function postRemoveComment(comment,back)
{
    if( back == undefined ) back = "admin";
    if( confirm('Are you sure ?') )
        window.location = basedir + "update.php?action=workspace:delcomment&back="+back+"&id_comment=" + comment;
}


function postSetInSpotlight(post)
{
    if( confirm('Are you sure ?') )
        window.location = basedir + "update.php?action=workspace:setspotlight&id_post=" + post;
}

function postSetInFocus(post)
{
    if( confirm('Are you sure ?') )
        window.location = basedir + "update.php?action=workspace:setfocus&id_post=" + post;
}

function postSetForumEvent(post)
{
    if( confirm('Are you sure ?') )
        window.location = basedir + "update.php?action=workspace:setforumevent&id_post=" + post;
}


function postUnsetInSpotlight(post)
{
    if( confirm('Are you sure ?') )
        window.location = basedir + "update.php?action=workspace:unsetspotlight&id_post=" + post;
}

function postUnsetInFocus(post)
{
    if( confirm('Are you sure ?') )
        window.location = basedir + "update.php?action=workspace:unsetfocus&id_post=" + post;
}

function postUnsetForumEvent(post)
{
    if( confirm('Are you sure ?') )
        window.location = basedir + "update.php?action=workspace:unsetforumevent&id_post=" + post;
}


function postEdit(post)
{
    window.location = basedir + "make_a_post?reset=yes&post=" + post;
}

function postSetBlacklist()
{
    window.location = basedir + 'admin/post?section=blacklist';
}

/** Survey **/

function surveyIndex()
{
    window.location = basedir + 'admin/survey';
}

function surveyAdd()
{
    window.location = basedir + 'admin/survey?section=edit';
}

function surveyDelete(id_survey)
{
    if( confirm('Are you sure ?') )
    {
        var form = document.forms['frmEditSurvey'];
        form.id_survey.value = id_survey;
        form.action.value = "survey:delsurvey";
        form.submit();
    }
}

function surveyModify(survey)
{
    window.location = basedir + 'admin/survey?section=edit&survey=' + survey;
}

function surveyActivate()
{
    if( confirm('Are you sure ?') )
    {
        var form = document.forms['frmEditSurvey'];
        form.submit();
    }
}

function previewSurvey(survey)
{
    window.location = basedir + "admin/survey?section=preview&survey="+survey;
}

function surveySetItem()
{
    var form = document.forms['frmEditSurvey'];

    if( checkSelect(form.type,"Please select the type of the block!","") )
    {
        var submit = false;
        var type = listGetSelectedValue(form.type);

        switch( type )
        {
            case "static"   :   tinyMCE.triggerSave();
                                submit = true;
                                break;
            case "pagebreak" :  submit = true;
                                break;
            case "radio"    :
            case "check"    :
            case "text"     :   if( checkInput(form.question,CHK_TEXT,"") )
                                    if( checkInput(form.rank,CHK_TEXT,"") )
                                        if( checkInput(form.rank,CHK_INT,"") )
                                            if( checkInput(form.answers,CHK_TEXT,"") )
                                                submit = true;
                                break;
        }

        if( submit )
        {
            if( form.itemidx.value == "" )
                Ajax.call("axc_surveyadditem","update.php?action=ax:addsurveyitem",null,Ajax.OP_AUTO,{post: {"type":form.type.value,"compulsion":((form.compulsion.checked) ? form.compulsion.value : "no"),"rank":form.rank.value,"question":form.question.value,"statictext":form.statictext.value,"answers":form.answers.value} },true);
            else
                Ajax.call("axc_surveymoditem","update.php?action=ax:modsurveyitem",null,Ajax.OP_AUTO,{post: {"idx":form.itemidx.value,"type":form.type.value,"compulsion":((form.compulsion.checked) ? form.compulsion.value : "no"),"rank":form.rank.value,"question":form.question.value,"statictext":form.statictext.value,"answers":form.answers.value} },true);

            form.type.selectedIndex = 0;
            form.compulsion.checked = false;
            form.rank.value = "";
            form.question.value = "";
            form.statictext.value = "";
            form.answers.value = "";
            form.itemidx.value = "";

            showBlock(getEbyID('bkSurveyItemCompRank'),false);
            showBlock(getEbyID('bkSurveyItemStaticText'),false);
            showBlock(getEbyID('bkSurveyItemAnswers'),false);

            showBlock(getEbyID('linkSurveyAddItem'),true);
            showBlock(getEbyID('linkSurveyModItem'),false);
            showBlock(getEbyID('linkSurveyCancelModItem'),false);
        }
    }
}

function surveyModItem(idx,type,compulsion,rank,question)
{
    var form = document.forms['frmEditSurvey'];

    listSelectByValue(form.type,type);
    surveyChangeType();
    form.compulsion.checked = (compulsion == "yes");
    form.rank.value = rank;
    form.question.value = question;
    form.answers.value = getEbyID('surveyitemanswers_'+idx) ? getEbyID('surveyitemanswers_'+idx).value : "";
    form.statictext.value = form.answers.value;
    form.itemidx.value = idx;
    tinyMCE.updateContent("statictext");

    showBlock(getEbyID('linkSurveyAddItem'),false);
    showBlock(getEbyID('linkSurveyModItem'),true);
    showBlock(getEbyID('linkSurveyCancelModItem'),true);
}

function surveyCancelModItem()
{
    var form = document.forms['frmEditSurvey'];
    form.type.selectedIndex = 0;
    form.compulsion.checked = false;
    form.rank.value = "";
    form.question.value = "";
    form.statictext.value = "";
    form.answers.value = "";
    form.itemidx.value = "";
    tinyMCE.updateContent("statictext");

    showBlock(getEbyID('bkSurveyItemCompRank'),false);
    showBlock(getEbyID('bkSurveyItemStaticText'),false);
    showBlock(getEbyID('bkSurveyItemAnswers'),false);

    showBlock(getEbyID('linkSurveyAddItem'),true);
    showBlock(getEbyID('linkSurveyModItem'),false);
    showBlock(getEbyID('linkSurveyCancelModItem'),false);
}

function surveyDelitem(idx)
{
    if( confirm('Are you sure ?') )
        Ajax.call("axc_surveydelitem","update.php?action=ax:delsurveyitem",null,Ajax.OP_AUTO,{post: {"idx":idx} },true);
}

function surveyDelRespond(crc)
{
    if( confirm('Are you sure ?') )
    {
        var form = document.forms['frmDelSurveyRespond'];
        form.crc.value = crc;
        form.submit();
    }
}

function surveyPost()
{
    var form = document.forms['frmEditSurvey'];

    if( checkInput(form.title,CHK_TEXT,"") )
        if( form.num_item.value > 0 )
            return true;
        else
            alert('Add at least one block!');

    return false;
}

function surveyListArchive()
{
    window.location = basedir + 'admin/survey?section=listarch';
}

function surveyPreviewPage(survey,sp)
{
    window.location = basedir + 'admin/survey?section=preview&survey=' + survey + '&sp=' + sp;
}

function surveyOrderSurveyList(orderway)
{
    var orderdir = 'asc';
    if( surveylist_orderway == orderway )
        orderdir = (surveylist_orderdir == "asc") ? "desc" : "asc";
    window.location = basedir + 'admin/survey?section=listarch&orderway=' + orderway + '&orderdir=' + orderdir;
}

function surveyChangeType()
{
    var form = document.forms['frmEditSurvey'];
    var type = listGetSelectedValue(form.type);
    var bkSurveyItemCompRank = getEbyID("bkSurveyItemCompRank");
    var bkSurveyItemStaticText = getEbyID("bkSurveyItemStaticText");
    var bkSurveyItemAnswers = getEbyID("bkSurveyItemAnswers");

    switch( type )
    {
        case "static"   :   showBlock(bkSurveyItemCompRank,false);
                            showBlock(bkSurveyItemAnswers,false);

							form.statictext.value = "";
							tinyMCE.updateContent("statictext");
                            showBlock(bkSurveyItemStaticText,true);

                            break;
        case "pagebreak" :  showBlock(bkSurveyItemCompRank,false);
                            showBlock(bkSurveyItemAnswers,false);
                            showBlock(bkSurveyItemStaticText,false);
                            break;
        case "radio"    :
        case "check"    :   showBlock(bkSurveyItemStaticText,false);
                            if( !isVisible(bkSurveyItemCompRank) )
                            {
                                form.answers.value = "";
                                form.compulsion.checked = false;
                                form.rank.value = "";
                                form.question.value = "";
                            }
                            showBlock(bkSurveyItemCompRank,true);
                            showBlock(bkSurveyItemAnswers,true);
                            break;
        case "text"      :  showBlock(bkSurveyItemCompRank,true);
                            showBlock(bkSurveyItemAnswers,false);
                            showBlock(bkSurveyItemStaticText,false);
                            break;
    }
}

function surveyExportResult()
{
    var form = document.forms['frmEditSurvey'];

    var action = form.action.value;
    var target = form.target.value;

    form.action.value = "survey:export";
    form.target = "ifDump";

    form.submit();

    form.target = target;
    form.action.value = action;
}

function surveyListResult(survey)
{
    window.location = basedir + 'admin/survey?section=listres&survey=' + survey;
}


function openTerms()
{
    openPopupPage(basedir + "terms_of_use?hide_header=yes","POP_TERMS",670,480, "location:no;menubar:no;resizable:no;scrollbars:yes;status:yes;titlebar:yes;toolbar:no;center:yes", false);
}

function setDateFirst(node, pfx)
{
	var target = getEbyID(pfx+"_"+node.id.split("_").pop());

	if( target.value ) return false;

	for(var i=0;i<target.options.length;i++)
		target.options[i].selected = (i == node.selectedIndex);
}

function chginput(oi, type)
{
	var	_new = document.createElement("input");

	_new.type = type;
	_new.value = oi.value;
    _new.name = oi.name;
    _new.id = oi.id;
    _new.className	= oi.className;

	oi.parentNode.replaceChild(_new, oi);
}

function pwdsafeSubmit(n, f)
{
	var o	= null;

	for( i = 1; i <= n; i++  )
	{
		o	= document.getElementById('ff' + i);

		if( o )
		{
			chginput(o, 'text')
		}
	}

	of	= document.getElementById(f);

	if( of )
	{
		of.submit();
	}

	for( i = 1; i <= n; i++  )
	{
		o	= document.getElementById('ff' + i);

		if( o )
		{
			chginput(o, 'password')
		}
	}
}

function avatarSetBgColor(radio_obj)
{
	var where = (radio_obj.value == 'own' && radio_obj.checked ? 'left' : 'right');
	var where2 = (where == 'left' ? 'right' : 'left');
	var obj = null;
	if((obj = document.getElementById('avatar-set-'+where)))
	{
		obj.style.backgroundColor = '#f0f1ec';
	}
	if((obj = document.getElementById('avatar-set-'+where2)))
	{
		obj.style.backgroundColor = '#FFFFFF';
	}
}

function pickDate(formName,inputName)
{
    var url = "calendar.php?formName="+formName+"&inputName="+inputName;

    var form = document.forms[formName];

    if( form )
    {
        var year  = form.elements[inputName + '_year'];
        var month = form.elements[inputName + '_month'];
        var day   = form.elements[inputName + '_day'];

        var data_year = listGetSelectedValue(year);
        if( data_year > 0 ) url += "&y=" + data_year;
        var data_month = listGetSelectedValue(month);
        if( data_month > 0 ) url += "&m=" + data_month;
    }

	openPopupPage(url,"DATEPICKER",182,204,"center:yes");
}

function setPickedDate(formName,inputName,date)
{
    var form = document.forms[formName];
    if( form )
    {
        var year  = form.elements[inputName + '_year'];
        var month = form.elements[inputName + '_month'];
        var day   = form.elements[inputName + '_day'];
    }
    else
        {
            var year  = getEbyID(inputName+'_year');
            var month = getEbyID(inputName+'_month');
            var day   = getEbyID(inputName+'_day');
        }

	if( (year) && (month) && (day) )
	{	
    	var date_year = date.substr(0,4);
    	var date_month = date.substr(5,2);
    	var date_day = date.substr(8,2);
    
        listSelectByValue(year,date_year);
        listSelectByValue(month,date_month);
        listSelectByValue(day,date_day);
    }
}

var _CHECK_ON_MOUSE_OUT = new Array();

var de =
{
	showEventLayer: function(obj, date)
	{
		if( !(layer = document.getElementById('event-layer-'+date)) ) return false;
		document.getElementsByTagName('body').item(0).appendChild(layer);
		
		var bound = getBounds(obj);
		
		layer.style.visibility = 'hidden';
		layer.style.display = 'block';
		layer.style.left = bound._x - (layer.offsetWidth - bound.width) / 2 + 'px';
		layer.style.top = bound._y - (layer.offsetHeight - bound.height) / 2 + 'px';
		
		
		
		layer.style.visibility = 'visible';
		
		layer.myOnMouseOut = function(e)
		{
			this.style.display = 'none';
			this.style.visibility = 'hidden';			
		}
		
		_CHECK_ON_MOUSE_OUT.push({bound:getBounds(layer), obj:layer});
		return true;
	}
}


addEvent(document, 'mousemove', null, function(e)
{
	var evt = e || window.event;
	
	if(_CHECK_ON_MOUSE_OUT.length)
	{
		var point = getMouseCoords(evt);
		for(var k=0 ; k<_CHECK_ON_MOUSE_OUT.length ; k++)
		{
			var curr = _CHECK_ON_MOUSE_OUT[k];
			if(curr && curr.bound && !pointInBox(curr.bound, point))
			{
				if(typeof curr.obj.myOnMouseOut == 'function')
					curr.obj.myOnMouseOut();
				delete _CHECK_ON_MOUSE_OUT[k];
			}
		}
	}
	
});