function show(my_img) //only for first page
{
	document.getElementById('left').style.background='url(images/' + my_img + ')';
}

function hide() //only for first page
{
	document.getElementById('left').style.background='url(images/content.jpg)';
}

sfHover = function() {
	var sfEls = document.body.getElementsByTagName("div");
	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"), "");
		}
	}
}
//if (window.attachEvent) window.attachEvent("onload", sfHover);


function addHover(element) {
	element.className+=" hover";
}

function addHoverDelayed(element, time) {
  if(!time) time=2500;
  pausecomp(time);
  element.className+=' hover';
}

function removeHover(element) {
	element.className=element.className.replace(new RegExp("hover\\b"), "");
}

function addClass(element, cl) {
	element.className+= " " + cl;
}
function removeClass(element, cl) {
	element.className=element.className.replace(new RegExp(cl + "\\b"), "");
}
function switchClass(element, cl) {
	if(element.className.indexOf(cl)!=-1) {
		element.className=element.className.replace(new RegExp(cl + "\\b"), "");
	}
	else {
		element.className+= " " + cl;
	}
}
// start new project page - move one li between to uls.
function moveCriteria(criteria_id, source_list_id, target_list_id)
{
	var d = document.getElementById(criteria_id);

	// create the list item in the target list
	var new_li = document.createElement("li");

	new_li.id = criteria_id;

	if(navigator.userAgent.toLowerCase().indexOf("msie") != -1) {
  	new_li.setAttribute("onclick", function() { moveCriteria(this.id, target_list_id, source_list_id);});
	  new_li.setAttribute("onmouseover", function() { this.className = 'li_hover';});
	  new_li.setAttribute("onmouseout", function() { this.className = '';});
	}
	else {
  	new_li.setAttribute("onclick", "moveCriteria(this.id, '" + target_list_id + "', '" + source_list_id + "');");
	  new_li.setAttribute("onmouseover", "this.className = 'li_hover';");
	  new_li.setAttribute("onmouseout", "this.className = '';");
	}
	new_li.innerHTML = d.innerHTML;

	document.getElementById(target_list_id).appendChild(new_li);
	if(target_list_id == 'chosen_criterias') {
		new YAHOO.example.DDList(criteria_id);
	}

	// delete the list item from the source list

	var lis = document.getElementById(source_list_id).getElementsByTagName("li");
	for (i = 0; i < lis.length; i++)
	{
		if (lis[i].id == criteria_id)
		{
			document.getElementById(source_list_id).removeChild(lis[i]);
		}
	}

	// update the criterias box
	document.getElementById("the_criterias").setAttribute("value", "");
	var lis2 = document.getElementById("chosen_criterias").getElementsByTagName("li");
	var the_chosen_criterias = "";
	for (i = 0; i < lis2.length; i++)
	{
		the_chosen_criterias += lis2[i].id + ";"

	}

	document.getElementById("the_criterias").value = the_chosen_criterias;
}

function show_ownCriteria()
{
	document.getElementById('add_criteria').className='add_criteria2';
	//return false;
}
function addCriteria(criteria)
{
	// create the list item in the target list
	var new_li = document.createElement("li");
	new_li.innerHTML = criteria[1];

	new_li.id = "li1_"+criteria[0];
	if(navigator.userAgent.toLowerCase().indexOf("msie") != -1) {
	  new_li.setAttribute("onclick", function() { moveCriteria(this.id, 'suggested_criterias', 'chosen_criterias');});
	  new_li.setAttribute("onmouseover", function() { this.className = 'li_hover';});
	  new_li.setAttribute("onmouseout", function() { this.className = '';});
	}
	else {
  	new_li.setAttribute("onclick", "moveCriteria(this.id, 'suggested_criterias', 'chosen_criterias');");
	  new_li.setAttribute("onmouseover", "this.className = 'li_hover';");
	  new_li.setAttribute("onmouseout", "this.className = '';");
	}
	document.getElementById('suggested_criterias').appendChild(new_li);

}
function addCriteria2(criteria)
{
	var numberOfNodes=0;
	var childNodes = document.getElementById('chosen_criterias').childNodes;
	for( var c = 0; c <childNodes.length; c++ )
	{
		numberOfNodes++;
	}

	numberOfNodes = numberOfNodes +1;
	var _id = "li1_n" + numberOfNodes;

	// create the list item in the target list
	var new_li = document.createElement("li");
	new_li.innerHTML =criteria;
	new_li.id = _id;
	if(navigator.userAgent.toLowerCase().indexOf("msie") != -1) {
	  new_li.setAttribute("onclick", function() { moveCriteria(this.id, 'chosen_criterias', 'suggested_criterias');});
	  new_li.setAttribute("onmouseover", function() { this.className = 'li_hover';});
	  new_li.setAttribute("onmouseout", function() { this.className = '';});
	}
	else {
  	new_li.setAttribute("onclick", "moveCriteria(this.id, 'chosen_criterias', 'suggested_criterias');");
	  new_li.setAttribute("onmouseover", "this.className = 'li_hover';");
	  new_li.setAttribute("onmouseout", "this.className = '';");
	}
	new YAHOO.example.DDList(_id);

	document.getElementById('chosen_criterias').appendChild(new_li);

}
function getCriteria(source_list_id,criteria_field)
{
	var _output;

	_output = '';

	var lis = document.getElementById(source_list_id).getElementsByTagName("li");
	for (i = 0; i < lis.length; i++)
	{
		//$_ = lis[i];
		_output+= lis[i].innerHTML + "\n";
	}
	criteria_field.value = _output;

	return true;
}



function preloader() {

    /* images = new Array();
     //images = ['yes', 'no', 'add_now', 'continue', 'create_account', 'done', 'edit', 'edit_project', 'save_changes', 'start_project', 'upload'];

     for(i=0; i<images.length; i++) {
     	  imageObj1 = new Image();
          imageObj1.src = '/images/' + images[i] + '_off.gif';
          imageObj2 = new Image();
          imageObj2.src = '/images/' + images[i] + '_on.gif';
          imageObj3 = new Image();
          imageObj3.src = '/images/' + images[i] + '_click.gif';
     }*/
}

//window.onload =	preloader;



function section_title_onmouseover(section_name)
{
  try{
	var section_title = document.getElementById(section_name + '_title');
	var section_content = document.getElementById(section_name + '_content');
	if (section_content.style.display=='none')
	{
		section_title.className='section_title_show_content';
	}
	else
	{
		section_title.className='section_title_hide_content';
	}
	} catch (e) {}
}

function section_title_onclick(section_name)
{
  try {
	var section_title = document.getElementById(section_name + '_title');
	var section_content = document.getElementById(section_name + '_content');
	if (section_content.style.display=='none')
	{
		section_content.style.display='block';
		section_title.className='section_title_hide_content';
	}
	else
	{
		section_content.style.display='none';
		section_title.className='section_title_show_content';
	}
  } catch (e) {}
}

function show_popup(text, title) {
  var title = (title == null) ? "" : title;
  
  YAHOO.namespace("panel.container");
  YAHOO.panel.container.panel1 = new YAHOO.widget.Panel("panel1", { close:false, constraintoviewport:true, fixedcenter:true, draggable:true, visible:true, modal:true, underlay:"none" } );
	YAHOO.panel.container.panel1.setBody('<div id="add_friend" style="width:600px;"><h1><span><a onmouseout="YAHOO.panel.container.panel1.configDraggable(\'\', {0: false}, \'\')" onmouseover="YAHOO.panel.container.panel1.configDraggable(\'\', {0: true}, \'\')" onclick="return false;" style="border: 0px none ; margin-right: 5px; cursor: move;" href="#"><img id="panel1_h" width="21" height="21" alt="close" src="/images/drag_icon.png"/></a><a onclick="YAHOO.panel.container.panel1.hide(); return false;" style="border: 0px none ;" href="#"><img width="21" height="21" alt="close" src="/images/close.png"/></a></span>' + title + '</h1><div class="help_box"><p>' + text + '</p></div>');
	YAHOO.panel.container.panel1.render(document.body);
	YAHOO.panel.container.panel1.show;
}

function show_popup_square(text, title) {
  var title = (title == null) ? "" : title;
  
  YAHOO.namespace("panel.container");
  YAHOO.panel.container.panel1 = new YAHOO.widget.Panel("panel1", { close:false, constraintoviewport:true, fixedcenter:true, draggable:true, visible:true, modal:true, underlay:"none" } );
	YAHOO.panel.container.panel1.setBody('<div id="add_friend" style="width:400px;height:210px;"><h1><span><a onclick="YAHOO.panel.container.panel1.hide(); return false;" style="border: 0px none ;" href="#"><img width="21" height="21" alt="close" src="/images/close.png"/></a><a onmouseout="YAHOO.panel.container.panel1.configDraggable(\'\', {0: false}, \'\')" onmouseover="YAHOO.panel.container.panel1.configDraggable(\'\', {0: true}, \'\')" onclick="return false;" style="border: 0px none ; margin-right: 5px; cursor: move;" href="#"><img id="panel1_h" width="21" height="21" alt="close" src="/images/drag_icon.png"/></a></span>' + title + '</h1><div class="help_box"><p>' + text + '</p></div>');
	YAHOO.panel.container.panel1.render(document.body);
	YAHOO.panel.container.panel1.show;
}


function show_popup_square_load(url, title) {
  var title = (title == null) ? "" : title;
  YAHOO.namespace("panel.container");
  YAHOO.panel.container.panel1 = new YAHOO.widget.Panel("panel1", { close:false, constraintoviewport:true, fixedcenter:true, draggable:true, visible:true, modal:true, underlay:"none" } );
	YAHOO.panel.container.panel1.setBody('<div id="add_friend" style="width:500px;height:250px;"><h1><span><a onclick="YAHOO.panel.container.panel1.hide(); return false;" style="border: 0px none ;" href="#"><img width="21" height="21" alt="close" src="/images/close.png"/></a><a onmouseout="YAHOO.panel.container.panel1.configDraggable(\'\', {0: false}, \'\')" onmouseover="YAHOO.panel.container.panel1.configDraggable(\'\', {0: true}, \'\')" onclick="return false;" style="border: 0px none ; margin-right: 5px; cursor: move;" href="#"><img id="panel1_h" width="21" height="21" alt="close" src="/images/drag_icon.png"/></a></span>' + title + '</h1><div class="help_box"><div id="short_login_content"></div></div>');
	YAHOO.panel.container.panel1.render(document.body);
	YAHOO.util.Connect.asyncRequest("GET", url, { success: function (o) { document.getElementById("short_login_content").innerHTML = o.responseText;}}, {evalScripts: true});
	new Ajax.Updater({success: 'short_login_content',failure: 'short_login_content'},url,{asynchronous:true, evalScripts:true, method: "GET"});
	YAHOO.panel.container.panel1.show;
}

function evalScripts(s) {
    var matchAll = new RegExp('(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)', 'img');
    var matchOne = new RegExp('(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)', 'im');
    var scripts = s.match(matchAll);
    for(i = 0; i< scripts.length; i++) {
      eval(scripts[i].match(matchOne)[1]);
    }
}

function switch_show_hide(element){
  if(element.innerHTML.indexOf("hide")!=-1)
    element.innerHTML="show&nbsp;&#x25bc;";
  else 
    element.innerHTML="hide&nbsp;&#x25b2;";
}

function pausecomp(millis)
{
  var date = new Date();
  var curDate = null;
  
  do { curDate = new Date(); }
  while(curDate-date < millis);
}

function str_replace(search, replace, subject) {
    var _is_array = function(mixed_var) {
        return (mixed_var instanceof Array);
    };
    
    var f = search, r = replace, s = subject;
    var ra = _is_array(r), sa = _is_array(s), f = [].concat(f), r = [].concat(r), i = (s = [].concat(s)).length;
 
    while (j = 0, i--) {
        if (s[i]) {
            while (s[i] = s[i].split(f[j]).join(ra ? r[j] || "" : r[0]), ++j in f){};
        }
    };
     
    return sa ? s : s[0];
}

function autoEllipseText(element, text, width, id)
{
   
   //element.innerHTML = text;
   inSpan = document.getElementById(id);
   if(inSpan.offsetWidth > width)
   {
		
      var i = 1;
      inSpan.innerHTML = '';
      
      while(inSpan.offsetWidth <(width) && i <text.length)
      {
         inSpan.innerHTML = text.substr(0,i) + '...';
         i++;
         //alert(inSpan.innerHTML + ' - ' + inSpan.offsetWidth + ' ' + width);   
      }

      returnText = inSpan.innerHTML;
      element.innerHTML=returnText;
	  element.innerHTML=str_replace("_x_",".",element.innerHTML);
	  element.innerHTML=str_replace("_I_",'"',element.innerHTML);
	  element.innerHTML=str_replace("_Q_","'",element.innerHTML);
      //return returnText;
   }else{
     //returnText=text;
   }
     //return text;
}


function detectBrowser()
{
var browser=navigator.appName
var b_version=navigator.appVersion
var version=parseFloat(b_version)
return browser;
}


function getScreenWidth() {
  return screen.width;
}

function getScreenHeight() {
  return screen.height;
}

function openNewWindow(url){
  window.open(url,'mywindow','location=1,directories=1,status=1,toolbar=1,menubar=1,scrollbars=1,copyhistory=1,resizable=1,width='+getScreenWidth()+',height='+getScreenHeight());
}


function openerFullScreen(window){
  alert(window.opener.href);
  window.opener.maximize();
}
