function confirmLink(theLink, msg)
{
    var is_confirmed=confirm(msg);
    if(is_confirmed) {
        theLink.href += '&is_js_confirmed=1';
    }

    return is_confirmed;
}

function conf(link,msg){
  if(confirm(msg))
    {
	location.href=link;
	}
  }

function current_rating(id, rating) {
  post_id = id;
  post_rating = rating;
  var images_path='skins/default_skin/ita/images';
  for(i = 1; i <= rating; i++)
    {
    document.images['rating_' + post_id + '_' + i].src = images_path + '/rating_over.gif';
    }
  }

function ratings_off(rating_score, insert_half) {
  var ratings_max=5;
  var images_path='skins/default_skin/ita/images';
  for(i = 1; i <= ratings_max; i++)
    {
    if(i <= rating_score)
      {
      document.images['rating_' + post_id + '_' + i].src =  images_path + '/rating_on.gif';
      }
      else if(i == insert_half)
      {
      document.images['rating_' + post_id + '_' + i].src =  images_path + '/rating_half.gif';
      }
      else
      {
      document.images['rating_' + post_id + '_' + i].src =  images_path + '/rating_off.gif';
      }
    }
  }

function toggleLayer(whichLayer) {
  if (document.getElementById)
    {
    // this is the way the standards work
    var style2 = document.getElementById(whichLayer).style;
    style2.display = style2.display? "":"block";
    }
    else if (document.all)
    {
    // this is the way old msie versions work
    var style2 = document.all[whichLayer].style;
    style2.display = style2.display? "":"block";
    }
    else if (document.layers)
    {
    // this is the way nn4 works
    var style2 = document.layers[whichLayer].style;
    style2.display = style2.display? "":"block";
    }
  }

	var done = new Array();

	function clearField(fieldname) {
		setStatus(fieldname, 'clear');
		if (fieldname == "name") {
		var button = document.getElementById('checkname');
		button.value = "Check Availability";
		button.disabled = '';
		button.style.display = '';
		}
	}

	function checkField(name) {
		if (name == "newuser[username]")
			{
			var input = document.getElementById("newuser[username]");
			if (input.value != null && input.value.length > 5 && input.value.match(/^([a-zA-Z0-9_])+$/))
				setStatus(name, 'good');
			else if (input.value.length < 1)
				clearField(name);
			else setStatus(name, 'bad');
			}
		else if (name == "newuser[mail]")
			{
			var input = document.getElementById("newuser[mail]");
			if (input.value != null && input.value.length > 4 && input.value.match(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/))
				setStatus(name, 'good');
			else if (input.value.length <= 4)
				clearField(name);
			else setStatus(name, 'bad');
			}
		else if (name == "newuser[mail2]")
			{
			var input = document.getElementById("newuser[mail2]");
			var first = document.getElementById("newuser[mail]");
			if (first.value == input.value && input.value != null && input.value.length > 4 && input.value.match(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/))
				setStatus(name, 'good');
			else if (input.value.length <= 4)
				clearField(name);
			else setStatus(name, 'bad');
			}
		else if (name == "newuser[password]")
			{
			var input = document.getElementById("newuser[password]");
			if (input.value != null && input.value.length > 5 && input.value.match(/^\w*$/))
				setStatus(name, 'good');
			else if (input.value.length < 1)
				clearField(name);
			else setStatus(name, 'bad');
			}
		else if (name == "newuser[password2]")
			{
			var input = document.getElementById("newuser[password2]");
			var first = document.getElementById("newuser[password]");
			if (first.value == input.value && input.value != null && input.value.length > 5 && input.value.match(/^\w*$/))
				setStatus(name, 'good');
			else if (input.value.length < 1)
				clearField(name);
			else setStatus(name, 'bad');
			}
		//if (input.value != null && input.value.length > 4 && input.value.match(/@(.+)\./))

	}

	function setStatus(inputid, status) {
		var RootPath="skins/Standard/ita";
		var indicator = document.getElementById(inputid+'_status');
		if (indicator) {
			if (status == "good") {
				indicator.style.backgroundImage = "url('" + RootPath  + "/images/correct.gif')";
				done[inputid] = true;
				}
		else if (status == "bad") {
		   indicator.style.backgroundImage = "url('" + RootPath  + "/images/incorrect.gif')";
		   done[inputid] = false;
		   }
		else {
		   indicator.style.backgroundImage = 'none';
		   }
		}
	}



	// create the prototype on the String object

	String.prototype.trim = function() {

	 // skip leading and trailing whitespace
	 // and return everything in between
	  var x=this;
	  x=x.replace(/^\s*(.*)/, "$1");
	  x=x.replace(/(.*?)\s*$/, "$1");
	  return x;
	}
