

function validate_email(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		var fail=0
		if (str.indexOf(at)==-1){   fail = 1 }
		else if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){   fail = 1 }
		else if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){   fail = 1 }
		else if (str.indexOf(at,(lat+1))!=-1){   fail = 1 }
		else if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){   fail = 1 }
		else  if (str.indexOf(dot,(lat+2))==-1) {   fail = 1 }
		else  if (str.indexOf(" ")!=-1){   fail = 1 }

		if (fail) {
			alert("Invalid email address: "+ str +". Please try again.")
			return false
		}
 		return true					
	}


// Initialize all textareas.
//insert this code on page for expanding textareas : window.onload = function() { taInit(false); }

// If bCols is false then columns will not be resized.
function taInit(bCols)
{
  var i, ta = document.getElementsByTagName('textarea');
  for (i = 0; i < ta.length; ++i)
  {
    ta[i]._ta_resize_cols_ = bCols;
    ta[i]._ta_default_rows_ = ta[i].rows;
    ta[i]._ta_default_cols_ = ta[i].cols;
    ta[i].onkeyup = taExpand;
    ta[i].onmouseover = taExpand;
    ta[i].onmouseout = taRestore;
    ta[i].onfocus = taOnFocus;
    ta[i].onblur = taOnBlur;
  }
}
function taOnFocus(e)
{
  this._ta_is_focused_ = true;
  this.onmouseover();
}
function taOnBlur()
{
  this._ta_is_focused_ = false;
  this.onmouseout();
}
// Set to default size if not focused.
function taRestore()
{
  if (!this._ta_is_focused_)
  {
    this.rows = this._ta_default_rows_;
    if (this._ta_resize_cols_) this.cols = this._ta_default_cols_;
  }
}
// Resize rows and cols to fit text.
function taExpand()
{
  var a, i, r, c = 0;
  a = this.value.split('\n');
  if (this._ta_resize_cols_)
  {
    for (i = 0; i < a.length; i++) // find max line length
    {
      if (a[i].length > c) c = a[i].length;
    }
    if (c < this._ta_default_cols_) c = this._ta_default_cols_;
    this.cols = c;
    r = a.length;
  }
  else
  {
    for (i = 0; i < a.length; i++)
    {
      if (a[i].length > this.cols) // find number of wrapped lines
      {
        c += Math.floor(a[i].length / this.cols);
      }
    }
    r = c + a.length; // add number of wrapped lines to number of lines
  }  
  if (r < this._ta_default_rows_) r = this._ta_default_rows_;
  this.rows = r;
}




// opens a pop up window showing the file 'path', having 'title' as window title
function popUp(path,title) {
    var popwin;
    if (title!="view") {
        // small window
        leftval=(screen.width)?(screen.width-400)/2:100;
        topval=(screen.height)?(screen.height-500)/2:100;
        popwin=window.open(path, title, "width=400,height=500,top=" + topval + ",left=" + leftval + ",toolbar=0,scrollbars=1,directories=no,location=0,statusbar=0,menubar=0,resizable=0");
    } else {
        // big window
        leftval=(screen.width)?(screen.width-750)/2:100;
        topval=(screen.height)?(screen.height-750)/2:100;
        popwin=window.open(path, title, "width=750,height=750,top=" + topval + ",left=" + leftval + ",toolbar=0,scrollbars=1,directories=no,location=0,statusbar=0,menubar=0,resizable=1");
    }
    popwin.focus();
}



// selects all entries in the selectbox 'select_name' in the form 'form_name'
function setSelect(form_name, select_name) {
    var select_field=document.forms[form_name].elements[select_name];
    for (var i=0; i < select_field.length; i++) select_field.options[i].selected=true;
    return true;
}
// selects all entries in the selectbox 'select_name' in the form 'form_name'
function clearSelect(form_name, select_name) {
    var select_field=document.forms[form_name].elements[select_name];
    for (var i=0; i < select_field.length; i++) select_field.options[i].selected=false;
    return true;
}
