function process_login_form(form,element_account,element_passwd,msg_account,msg_passwd)
{
  if (!form || !form.elements[element_account] || !form.elements[element_passwd])
    return true;

  if (form.elements[element_account].value=='')
  {
    alert(msg_account);
    form.elements[element_account].focus();
    return false;
  }
  if (form.elements[element_passwd].value=='')
  {
    alert(msg_passwd);
    form.elements[element_passwd].focus();
    return false;
  }

  return true;
}

function open_popup(url,popwidth,popheight) {
  var popup;
  popup = window.open(url,'survey',"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,left=0,top=0,width="+popwidth+",height="+popheight);
}

function get_emoticons(id) {
  var imgs = ['smile', 'laughing', 'cool', 'wink', 'kiss', 'frown', 'cry', 'undecided', 'surprised', 'tongueout', 'moneyinmouth', 'yell'];
  var codes = [':-)', ':-))', 'B-)', ';-)', '=*', ':-(', ':-((', ':-/', ':-O', ':-P', '$-)', 'X-(' ];
 
  var out='';
  for (var i=0; i<imgs.length; i++) {    
     out+='<img alt="'+codes[i]+'" src="images/share/emoticons/'+imgs[i]+'.png" class="emoticon" onclick="insert_at_caret($(\''+id+'\'),\' '+codes[i]+' \');return false;" />';
  }
  document.write(out);
}


function insert_at_caret(obj, text) {
	if(document.selection) {
		obj.focus();
		var orig = obj.value.replace(/\r\n/g, "\n");
		var range = document.selection.createRange();

		if(range.parentElement() != obj) {
			return false;
		}

		range.text = text;
			
		var actual = tmp = obj.value.replace(/\r\n/g, "\n");

		for(var diff = 0; diff < orig.length; diff++) {
			if(orig.charAt(diff) != actual.charAt(diff)) break;
		}
		for(var index = 0, start = 0; tmp.match(text) && (tmp = tmp.replace(text, "")) 	&& index <= diff; index = start + text.length) {
			start = actual.indexOf(text, index);
		}
	} else if(obj.selectionStart) {
		var start = obj.selectionStart;
		var end   = obj.selectionEnd;

		obj.value = obj.value.substr(0, start) + text + obj.value.substr(end, obj.value.length);
	}
		
	if(start != null) {
		set_caret_to(obj, start + text.length);
	} else {
		obj.value += text;
	}
}
	
function set_caret_to(obj, pos) {
	if(obj.createTextRange) {
		var range = obj.createTextRange();
		range.move('character', pos);
		range.select();
	} else if(obj.selectionStart) {
		obj.focus();
		obj.setSelectionRange(pos, pos);
	}
}

/** toggle info **/
function toggledisplay (id, indicator,text1, text2){
	if (document.getElementById) {
		var obj = document.getElementById(id);
		var indi = document.getElementById(indicator);
		obj.style.display = (obj.style.display=='block'?'none':'block');
		indi.innerHTML = (obj.style.display=='block'?text2:text1);
	} else if(document.all) { // IE
		id.style.display = (id.style.display=='block'?'none':'block');
		indi.innerHTML = (id.style.display=='block'?text2:text1);
	} else if (document.layers) { // Netscape 4.x
		document.id.style.display = (document.id.style.display=='block'?'none':'block');
		document["indicator"].document.open();
		if (document.id.style.display=='block')
		    document["indicator"].document.write(text2);
		if (document.id.style.display!='block')
		    document["indicator"].document.write(text1);
		document["indicator"].document.close();
	}
}

/** Language selection **/
function check_lang_sel() 
{
  var curselect = $('site_id');
  if (curselect.value != 0) 
  {
    document.langform.submit();
   }
}


/** Language selection **/

var Menu = new Class ({
  options: {
    id	: 'menu'
   },	
   initialize: function(options)
   {
      this.setOptions(options);
      var a = $$('#naviul ul li a.active');

		// Searching the li elements
		$ES('li', this.options.id).each(function(e, i) {
			// Events
			e.addEvents({
				'mouseover': this.show,
				'mouseout': this.hide,
				'click': this.hide
			});

			// Add an id for selector
			e.setAttribute( 'id', this.options.id + '_li_' + i );
		}.bind(this));
    },
    
	// Hide elements
	hide: function()
	{   
		// Select the sub_lists of the element
		var oUl = $E('ul', this.id);
		
		// Hide if exists
		if (oUl != null)
			oUl.setStyle('visibility', 'hidden');

                if (a != null) a.getParent().getParent().setStyle('visibility', 'visible');
	},
	
	// Show elements
	show: function()
	{
                if (a != null) a.getParent().getParent().setStyle('visibility', 'hidden');


		// Select the sub_lists of the element
		var oUl = $E('ul', this.id);
		
		// Show if exists
		if (oUl != null)
		oUl.setStyle('visibility', 'visible');

	}
});

Menu.implement(new Options);

Element.extend({
	addMenu: function() {
		var CMenu = new Menu({
			id: this.id
		});
	}
});

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent(function() {
 var Tips1 = new Tips($$('.Tips1'));
});