/* variables: */
var Opoint_base_url        = '';
var Opoint_curr_tab        = 'orig';
var Opoint_num_matches     = 0;
var Opoint_show_matches    = 0;
var Opoint_show_pdf        = 0;
var Opoint_show_PDF_border = 0;
var Opoint_show_PDF_overlay = 0;
var Opoint_show_PDF_zoom   = 0;
var Opoint_show_glued_PDF  = 0;
var Opoint_curr_match      = -1;
var Opoint_last_match      = null;
var Opoint_start_content   = null;
var Opoint_end_content     = null;
var Opoint_start_content_y = 0;
var Opoint_end_content_y   = 0;
var Opoint_start_lim       = 0.04;
var Opoint_end_lim         = 0.25;
var Opoint_src_url_mode    = "none";
var Opoint_num_comments    = 0;
var Opoint_comments_mode   = 'none';
var Opoint_found_part      = 0;
var Opoint_tab_change_cnt  = 0;
var Opoint_cache_avail     = 0;

/* variables controlling the scrolling behavior: */
var Opoint_use_scroll      = false;
var Opoint_scroll_tid      = null
var Opoint_scroll_frame    = null;
var Opoint_scroll_start    = 0;
var Opoint_scroll_end      = 0;
var Opoint_scroll_height   = 0;
var Opoint_scroll_speed    = 20;
var Opoint_scroll_step     = 25;
var Opoint_scroll_dir      = 1;



/* go to the top of the article: */
function Opoint_goto_top()
{
  Opoint_set_border(Opoint_last_match,'0px','','');
  Opoint_last_match = null;
  Opoint_curr_match = -1;
  document.getElementById('button_remove').src = 'img/button_remove_disabled.gif';
  if (Opoint_num_matches>0)
    document.getElementById('button_add').src  = 'img/button_add.gif';
  Opoint_init_scroller(Opoint_start_content_y-30,0);
}


/* go to the bottom of the article: */
function Opoint_goto_bottom()
{
  Opoint_set_border(Opoint_last_match,'0px','','');
  Opoint_last_match = null;
  Opoint_curr_match = Opoint_num_matches;
  document.getElementById('button_add').src  = 'img/button_add_disabled.gif';
  if (Opoint_num_matches>0)
    document.getElementById('button_remove').src = 'img/button_remove.gif';
  Opoint_init_scroller(Opoint_end_content_y+80,0);
}


/* go to the next match: */
function Opoint_goto_match(val)
{
  var frame = parent.frames['Opoint_mainpage'];
  if (frame) {
    if ((val<0 && (Opoint_curr_match>=0 || Opoint_curr_match==-1)) ||
	(val>0 && Opoint_curr_match < Opoint_num_matches)) {
      Opoint_curr_match+=val;

      if (Opoint_curr_match==-1 || Opoint_curr_match == Opoint_num_matches) {
	Opoint_set_border(Opoint_last_match,'0px','','');
	Opoint_last_match = null;
	if (Opoint_curr_match==-1) {
	  Opoint_goto_top();
	} else { //Opoint_curr_match == Opoint_num_matches
	  Opoint_goto_bottom();
	}

      } else if (Opoint_curr_match==-2) {
	Opoint_curr_match=-1;
      } else {
	if (Opoint_curr_match==0)
	  document.getElementById('button_remove').src = 'img/button_remove.gif';
	else if (Opoint_curr_match==Opoint_num_matches-1)
	  document.getElementById('button_add').src  = 'img/button_add.gif';

	var elem = frame.document.getElementById('Opoint_mark' + Opoint_curr_match);
	if (typeof elem != 'undefined' && elem) {
	  var y = Opoint_ypos(elem);
	  var height = (typeof frame.innerHeight != 'undefined') ? frame.innerHeight : frame.document.body.offsetHeight;
	  var top_lim = frame.document.body.scrollTop +          height*(val>0 ? Opoint_start_lim : Opoint_end_lim);
	  var end_lim = frame.document.body.scrollTop + height - height*(val>0 ? Opoint_end_lim : Opoint_start_lim);

	  if (y < top_lim || y > end_lim) {
	    Opoint_scroll_frame  = frame;
	    //orig: Opoint_init_scroller(y-height*Opoint_start_lim*2,0);
	    //also OK: Opoint_init_scroller(y - (height*(val>0 ? Opoint_start_lim : Opoint_end_lim)*2),0);
	    if (val>0)
	      Opoint_init_scroller(y - (height*Opoint_start_lim*2),0);
	    else
	      Opoint_init_scroller(y - (height - (height*Opoint_end_lim)),0);
	  }
	  Opoint_set_border(Opoint_last_match,'0px','','');
	  Opoint_set_border(elem,'2px','solid','red');
	  Opoint_last_match = elem;
	}
      }
    }
  }
}


function Opoint_jump_match(frame,anchor)
{
  if (frame) {
    var pos = -1;
    var href = frame.document.location.href;

    if ((typeof anchor == 'undefined')) {
      if ((pos = href.indexOf('#')) >= 0)
	frame.document.location.href = href.substring(0,pos);
    }

    else {
      if ((pos = href.indexOf('#')) >= 0)
	frame.document.location.href = href.substring(0,pos) + '#Opoint_mark' + anchor;
      else
	frame.document.location.href = href + '#Opoint_mark' + anchor;
    }
  }
}


function Opoint_set_border(obj,w,s,c)
{
  if (obj) {
    obj.style.borderWidth = w;
    obj.style.borderStyle = s;
    obj.style.borderColor = c;
    if (!Opoint_show_matches) {
      if (w!='0px' && w!='') {
	obj.style.paddingLeft = '2px;';
	if (obj.className.indexOf('both')>0)
	  obj.style.paddingRight = '2px;';
      } else {
	obj.style.paddingLeft = '';
	obj.style.paddingRight = '';
      }
    }
  }
}


function Opoint_toggle_matches(use_current)
{
  if (typeof use_current=='undefined') use_current = false;
  if ((!use_current && Opoint_show_matches) ||
      (use_current && !Opoint_show_matches)) {
    Opoint_show_matches = 0;
    document.getElementById('check_btn').src  = 'img/unchecked.gif';
  } else {
    Opoint_show_matches = 1;
    document.getElementById('check_btn').src  = 'img/checked.gif';
  }

  var frame = parent.frames['Opoint_mainpage'];
  if (frame) {
    if (Opoint_show_pdf) {
      Opoint_open_tab('pdf');
    } else {
      var pos = -1;
      for (var i=0; i < Opoint_num_matches; i++) {
	var elem = frame.document.getElementById('Opoint_mark'+i);
	if (elem) {
	  if (!Opoint_show_matches)
	    elem.className = 'old_' + elem.className;
	  else if (elem.className.indexOf('old_') == 0)
	    elem.className = elem.className.substring(4);
	}
      }
    }
  }
}

function Opoint_toggle_PDF_border(use_current,reload)
{
  if (!document.getElementById('check_PDF_border_btn')) return;
  if (typeof use_current=='undefined') use_current = false;
  if (typeof reload=='undefined') reload = true;
  if ((!use_current && Opoint_show_PDF_border) ||
      (use_current && !Opoint_show_PDF_border)) {
    Opoint_show_PDF_border = 0;
    document.getElementById('check_PDF_border_btn').src  = 'img/unchecked.gif';
  } else {
    Opoint_show_PDF_border = 1;
    document.getElementById('check_PDF_border_btn').src  = 'img/checked.gif';
  }

  if (reload)
    Opoint_open_tab('pdf');
}
function Opoint_toggle_PDF_overlay(use_current,reload)
{
  if (!document.getElementById('check_PDF_overlay_btn')) return;
  if (typeof use_current=='undefined') use_current = false;
  if (typeof reload=='undefined') reload = true;
  if ((!use_current && Opoint_show_PDF_overlay) ||
      (use_current && !Opoint_show_PDF_overlay)) {
    Opoint_show_PDF_overlay = 0;
    document.getElementById('check_PDF_overlay_btn').src  = 'img/unchecked.gif';
  } else {
    Opoint_show_PDF_overlay = 1;
    document.getElementById('check_PDF_overlay_btn').src  = 'img/checked.gif';
  }

  if (reload)
    Opoint_open_tab('pdf');
}
function Opoint_toggle_PDF_zoom(use_current,reload)
{
  if (!document.getElementById('check_PDF_zoom_btn')) return;
  if (typeof use_current=='undefined') use_current = false;
  if (typeof reload=='undefined') reload = true;
  if ((!use_current && Opoint_show_PDF_zoom) ||
      (use_current && !Opoint_show_PDF_zoom)) {
    Opoint_show_PDF_zoom = 0;
    document.getElementById('check_PDF_zoom_btn').src  = 'img/unchecked.gif';
  } else {
    Opoint_show_PDF_zoom = 1;
    document.getElementById('check_PDF_zoom_btn').src  = 'img/checked.gif';
  }

  if (reload)
    Opoint_open_tab('pdf');
}

function Opoint_toggle_glue_PDF(dir,reload)
{
  if (!document.getElementById('check_PDF_glue_btn')) return;
  if (typeof reload=='undefined') reload = true;
  if (Opoint_show_glued_PDF == dir) {
    Opoint_show_glued_PDF = 0;
    document.getElementById('check_PDF_glue_btn').src  = 'img/unchecked.gif';
    document.getElementById('check_PDF_glue_btn').title  = gettext('GLUE_PDF_NEXT');//FIX

    //change their icons back to the original version...
    //document.getElementById('check_btn')
    //document.getElementById('check_PDF_border_btn')
    //document.getElementById('check_PDF_overlay_btn')
    //document.getElementById('check_PDF_zoom_btn')

  } else {
    Opoint_show_glued_PDF = dir;
    document.getElementById('check_PDF_glue_btn').src  = 'img/checked.gif';
    document.getElementById('check_PDF_glue_btn').title  = gettext('SPLIT_PDF');

    //change their icons to a disabled version... (and keep previous state, at least for matches-img)
    //document.getElementById('check_btn')
    //document.getElementById('check_PDF_border_btn')
    //document.getElementById('check_PDF_overlay_btn')
    //document.getElementById('check_PDF_zoom_btn')
  }

  if (reload)
    Opoint_open_tab('pdf');
}


function Opoint_reset_matches()
{
  Opoint_curr_match = -1;
  Opoint_last_match = null;
  document.getElementById('button_remove').src = 'img/button_remove_disabled.gif';
  if (Opoint_num_matches)
    document.getElementById('button_add').src  = 'img/button_add.gif';
  else
    document.getElementById('button_add').src  = 'img/button_add_disabled.gif';
}


function Opoint_toggle_tabs(pressed_id,other_ids)
{
  var m1 = document.getElementById(pressed_id+'_center');
  var s1 = document.getElementById(pressed_id+'_start');
  var e1 = document.getElementById(pressed_id+'_end');

  if (m1 && typeof m1 != 'undefined' && m1.className=="inactive_center") {
    m1.className = "active_center";
    s1.className = "active_start";
    e1.className = "active_end";

    for (var i=0; i<other_ids.length; i++) {
      var tmp = document.getElementById(other_ids[i]+'_center');
      if (tmp && typeof tmp != 'undefined') {
	tmp.className = "inactive_center";
	document.getElementById(other_ids[i]+'_start').className = "inactive_start";
	document.getElementById(other_ids[i]+'_end').className = "inactive_end";
      }
    }
    Opoint_reset_matches();
    Opoint_curr_tab = pressed_id;
    //Opoint_open_tab(pressed_id);
  }
  Opoint_open_tab(pressed_id);
  Opoint_tab_change_cnt++;
}


function Opoint_open_tab(id)
{
  var frame = parent.frames['Opoint_mainpage'];
  if (frame) {
    var params = '?url=' + Opoint_src_url + (typeof Opoint_encoding != 'undefined' ? '&OpointEncoding='+Opoint_encoding : '') + '&OpointShowMatches='+Opoint_show_matches + '&OpointPDFBorder='+Opoint_show_PDF_border + '&OpointPDFOverlay='+Opoint_show_PDF_overlay + '&OpointPDFZoom='+Opoint_show_PDF_zoom + '&OpointPDFglue='+Opoint_show_glued_PDF + '&OpointData=' + OpointData;
    //var params = '?url=' + Opoint_src_url + '&OpointData=' + OpointData;

    if (id=='cache') {
      Opoint_open_tab_url('index_ocl.php' + params);
    } else if (id=='comment') {
      frame.location.href = 'index_comments.php' + params;
    } else if (id=='pdf') {
      Opoint_open_tab_url('index_pdf.php' + params);
    } else {
      Opoint_open_tab_url('index_sft.php' + params);
    }
  }
}

function Opoint_open_tab_url(url)
{
  var frame = parent.frames['Opoint_mainpage'];
  if (frame) {
    if (Opoint_translate && Opoint_lang) {
      frame.location.href = Opoint_translateUrl(url);
    } else {
      frame.location.href = Opoint_base_url + url;
    }
  }
}


function Opoint_translateUrl(url) {
  if(url == "" || url == "http://") return url;
  url = escape(Opoint_utf8_encode(Opoint_base + url));

  var trans_url = url;
  if (Opoint_lang && Opoint_translate) {


    /* try google */
    var google_langs = new Array('ar','bg','zh-CN','zh-TW','hr','cs','da','nl','en','fi','fr','de','el','hi','it','ja','ko','no','pl','pt','ro','ru','es','sv');
    var valid = 0;
    for (var i=0; i<google_langs.length; i++)
      if (google_langs[i] == Opoint_lang || google_langs[i] == Opoint_translate) {
	valid++;
      }

    /* use google */
    if (valid == 2) {
      trans_url = 'http://translate.google.com/translate?hl=en&ie=UTF8&sl='+Opoint_translate+'&tl='+Opoint_lang+'&u='+url;

    } else {

      /* try systran */
      var lang_pair = Opoint_translate+'_'+Opoint_lang;
      var systran_langs = new Array("en_fr","fr_en","en_es","es_en","en_it","it_en","en_pt","pt_en","en_de","de_en","en_nl","nl_en","en_sv","sv_en","en_ru","ru_en","pl_en","en_ar","ar_en","en_zh","zh_en","en_ja","ja_en","en_ko","ko_en","fr_es","es_fr","fr_it","it_fr","fr_pt","pt_fr","fr_de","de_fr","fr_nl","nl_fr");
      var valid_lp = false;
      for (var i=0; i<systran_langs.length; i++)
	if (systran_langs[i] == lang_pair) {
	  valid_lp = true;
	  break;
	}
      
      /* use systran */
      if (valid_lp) {
	trans_url = "http://svsurl.systransoft.com/?trans=1" +
	  "&gui=sbox/normal/systran/systranEN" +
	  "&lp=" + lang_pair +
	  "&loc_lang=en" +
	  "&path=systran/systranEN" +
	  "&frame=1" +
	  "&url=" + url;
      }
      
      /* try transexp */
      else {
	var lang_map = {'en': 'eng', // English
			'bg': 'bul', // Bulgarian (CP 1251)
			'hr': 'cro', // Croatian (CP 1250)
			'cs': 'che', // Czech (CP 1250)
			'da': 'dan', // Danish
			'nl': 'dut', // Dutch
			'es': 'spa', // Spanish
			'fi': 'fin', // Finnish
			'fr': 'fre', // French
			'de': 'ger', // German
			'gr': 'grk', // Greek
			'hu': 'hun', // Hungarian (CP 1250)
			'is': 'ice', // Icelandic
			'it': 'ita', // Italian
			'no': 'nor', // Norwegian
			'pl': 'pol', // Polish (ISO 8859-2)
			'pt': 'poe', // Portuguese
			'ro': 'rom', // Romanian (CP 1250)
			'ru': 'rus', // Russian (CP 1251)
			'sr': 'sel', // Serbian (CP 1250)
			'sl': 'slo', // Slovenian (CP 1250)
			'sv': 'swe', // Swedish
			'cy': 'wel', // Welsh
			'tr': 'tur' // Turkish (CP 1254)
	};

	/* use transexp */
	if (lang_map[Opoint_lang] && lang_map[Opoint_translate]) {
	  trans_url = 'http://www1.tranexp.com:2000/Translate/index.shtml?from='+lang_map[Opoint_translate]+'&to='+lang_map[Opoint_lang]+'&type=url&url='+url;
	}
      }

    }
  }

  return trans_url;
}


function Opoint_print()
{
  if (Opoint_show_pdf) {
    Opoint_show_matches = false;
    Opoint_show_PDF_border = false;
    Opoint_show_PDF_overlay = false;
    Opoint_toggle_PDF_border(true,false);
    Opoint_toggle_PDF_overlay(true,false);
    Opoint_toggle_matches(true);
  } else {
    var frame = parent.frames['Opoint_mainpage'];
    if (frame) {
      frame.focus();
      frame.print();
    }
  }
}


function Opoint_set_loaded()
{
  var frame = parent.frames['Opoint_mainpage'];
  if (frame) {
    top.document.title = frame.document.title;
    Opoint_num_matches = (typeof frame.Opoint_num_matches == 'undefined' ? 1 : parseInt(frame.Opoint_num_matches));
    Opoint_found_part = (typeof frame.Opoint_found_part == 'undefined' ? 100 : parseInt(frame.Opoint_found_part));

    Opoint_toggle_matches(true);
    Opoint_toggle_PDF_border(true,false);
    Opoint_toggle_PDF_overlay(true,false);
    Opoint_toggle_PDF_zoom(true,false);
    Opoint_toggle_glue_PDF(Opoint_show_glued_PDF,false);
    Opoint_toggle_comments();

    if (Opoint_num_matches && document.getElementById('button_add'))
      document.getElementById('button_add').src  = 'img/button_add.gif';
    Opoint_start_content = frame.document.getElementById('Opoint_start_content');
    Opoint_end_content = frame.document.getElementById('Opoint_end_content');
    Opoint_start_content_y = Opoint_ypos(Opoint_start_content);
    Opoint_end_content_y   = Opoint_ypos(Opoint_end_content)+80;
    Opoint_scroll_frame  = frame;
    //frame.focus();

    Opoint_init_scroller(Opoint_start_content_y-30,1250);

    if (Opoint_found_part<25 && Opoint_tab_change_cnt==1 && Opoint_cache_avail)
      Opoint_toggle_tabs('cache',['orig']);
  }
}




var cnt = 0;
function Opoint_init_scroller(end,timeout)
{
  if (Opoint_scroll_frame) {
    Opoint_scroll_start  = Opoint_scroll_frame.document.body.scrollTop;
    Opoint_scroll_end    = end;
    Opoint_scroll_height = (typeof Opoint_scroll_frame.innerHeight != 'undefined') ? Opoint_scroll_frame.innerHeight : Opoint_scroll_frame.document.body.offsetHeight;
    Opoint_scroll_step   = 25;
    Opoint_scroll_dir    = Opoint_scroll_start<end ? 1 : -1;
    cnt=0;

    if (Opoint_scroll_dir==-1 && Opoint_scroll_end < Opoint_start_content_y - 30) {
      Opoint_scroll_end = Opoint_start_content_y - 30;
    }
    if (Opoint_scroll_dir==1 && Opoint_end_content_y < Opoint_scroll_end + Opoint_scroll_height - Opoint_scroll_height*Opoint_start_lim) {
      Opoint_scroll_end = Opoint_end_content_y - Opoint_scroll_height + Opoint_scroll_height*Opoint_start_lim;
    }
    if (Opoint_end_content_y > Opoint_scroll_height) {
      if (Opoint_use_scroll)
	setTimeout("Opoint_scroll();",timeout);
      else
	setTimeout("Opoint_scroll_frame.scrollBy(0,"+(Opoint_scroll_end - Opoint_scroll_start)+");",timeout);
    }
  }
}


function Opoint_scroll()
{
  if (cnt<200) {
    if (Opoint_scroll_frame.document.body.scrollTop*Opoint_scroll_dir >= Opoint_scroll_end*Opoint_scroll_dir) {
      if (Opoint_scroll_tid)
	clearTimeout(Opoint_scroll_tid);
      Opoint_scroll_tid = null;
    } else {
      //if (cnt%10==0)
      //alert('step='+Opoint_scroll_step+' pst='+((Opoint_scroll_frame.document.body.scrollTop-Opoint_scroll_start) + ' / ' + (Opoint_scroll_end - Opoint_scroll_start) + ' = ' + ((Opoint_scroll_frame.document.body.scrollTop-Opoint_scroll_start) / (Opoint_scroll_end - Opoint_scroll_start) / 1)) + ' res=' + (Opoint_scroll_step*((Opoint_scroll_frame.document.body.scrollTop-Opoint_scroll_start) / (Opoint_scroll_end - Opoint_scroll_start) / 1)));

      //Opoint_scroll_step -= Opoint_scroll_step*((Opoint_scroll_frame.document.body.scrollTop-Opoint_scroll_start) / (Opoint_scroll_end - Opoint_scroll_start) / 1);
      //Opoint_scroll_step += Opoint_scroll_step*((Opoint_scroll_start-Opoint_scroll_frame.document.body.scrollTop) / (Opoint_scroll_end - Opoint_scroll_start));
      Opoint_scroll_step = 3+(Opoint_scroll_end - Opoint_scroll_frame.document.body.scrollTop)/(1000/Opoint_scroll_speed);
      //if (cnt%10==0) alert(Opoint_scroll_step);

      //if (Opoint_scroll_step < 2) Opoint_scroll_step = 2;

      Opoint_scroll_frame.scrollBy(0,Opoint_scroll_step*Opoint_scroll_dir);
      Opoint_scroll_tid = setTimeout("Opoint_scroll()",Opoint_scroll_speed);
    }
  }
  cnt++;
}



var Opoint_scroll_targets = new Array();
function Opoint_jump(frame,id)
{
  if (frame) {
    var height = (typeof frame.innerHeight != 'undefined') ? frame.innerHeight : frame.document.body.offsetHeight;
    var y_min  = frame.document.body.scrollTop;

    if (Opoint_scroll_targets.length==0) {
      for (var i=0; i < Opoint_num_matches; i++) {
	var elem = frame.document.getElementById('Opoint_mark'+i);
	if (elem) {
	  Opoint_scroll_targets[i] = Opoint_ypos(elem);
	}
      }
    }

    if (id==-1)
      frame.scrollTo(0,0);
    else
      frame.scrollTo(0,Opoint_scroll_targets[id]-100);

  }
}

function Opoint_ypos(element)
{
  var yPos = 0;
  if (element) {
    yPos = eval(element).offsetTop;
    tempEl = eval(element).offsetParent;
    while (tempEl!=null) {
      yPos += tempEl.offsetTop;
      tempEl = tempEl.offsetParent;
    }
  }
  return yPos;
}


function Opoint_height(element)
{
  while (element) {
    if (element.offsetHeight)
      return element.offsetHeight;
    element = element.parentNode;
  }
  return 0;
}


function Opoint_toggle_origurl()
{
  var txt = '';
  var line_height = 18;
  var orig_height = 44;
  var new_height = orig_height;

  if (Opoint_src_url_mode == 'none') {
    Opoint_src_url_mode = (document.all) ? 'block' : 'table-row'; //IE bug
    new_height += line_height;
    txt = gettext('HIDE_ORIG_URL');
  } else {
    Opoint_src_url_mode = 'none';
    txt = gettext('SHOW_ORIG_URL');
  }

  parent.document.body.setAttribute('rows',new_height+',*');
  document.getElementById('url_row').style.display = Opoint_src_url_mode;
  document.getElementById('orig_url').title = txt;
}

function Opoint_toggle_comments()
{
  var line_height = 18;
  var orig_height = 44;
  var new_height = orig_height;

  if (Opoint_comments_mode == 'none') {
    Opoint_comments_mode = (document.all) ? 'block' : 'table-row'; //IE bug
    new_height += line_height * Opoint_num_comments;
  } else {
    Opoint_comments_mode = 'none';
  }

  parent.document.body.setAttribute('rows',new_height+',*');
  var tags = document.getElementsByTagName('tr');
  for (var i = 0; i < tags.length; i++) {
    if (tags[i].getAttribute('name') == 'comment_row') {
      tags[i].style.display = Opoint_comments_mode;
    }
  }
}


function Opoint_send_mail(id_site,id_article,lang)
{
  //if (parent.window.opener && !parent.window.opener.closed
  //    && typeof parent.window.opener.RL_sendMail != 'undefined') {
  //  //alert('Bruk Opoint Monitor for å sende mailen');
  //  parent.window.opener.RL_sendMail(id_site,id_article);
  //  //alert(parent.window.opener.top);
  //  //if (parent.window.opener.top)
  //  //parent.window.opener.top.focus();
  //  //else
  //  parent.window.opener.focus();
  //} else {
    window.open('tips.php?id_site='+id_site+'&id_article='+id_article+'&lang='+lang,'redir_mail','width=700,height=300,resizable=1,scrollbars=auto,menubar=0');
  //}
}


function Opoint_validate_form()
{
  if (document.tips.send_to.value == '' ||
      document.tips.send_to.value.match(/^\s*$/) ||
      !Opoint_valid_email(document.tips.send_to.value)) {
    alert(gettext('FLEASE_PROVIDE_A_VALID_EMAIL_ADDRESS'));
    document.tips.send_to.focus();
    return false;
  } else if (document.tips.from.value == '' ||
	     document.tips.from.value.match(/^\s*$/) ||
	     !Opoint_valid_email(document.tips.from.value)) {
    alert(gettext('FLEASE_PROVIDE_A_VALID_EMAIL_ADDRESS'));
    document.tips.from.focus();
    return false;
  }
  return true;
}


function Opoint_valid_email(emails)
{
  //var pattern = /^[a-z0-9]([a-z0-9]¦([\w\-]+[a-z0-9]))*(\.([a-z0-9]¦[a-z0-9][\w\-]+[a-z0-9]))*@[a-z0-9][\w\-]*[a-z0-9]\.([a-z0-9][\w\-]*[a-z0-9]\.)*[a-z]{2,6}$/i;
  var pattern = /^[a-z0-9_.-]*[a-z0-9]+@[a-z0-9_.-]*[a-z0-9]+\.([a-z]{2,4}|[a-z]{6})$/i;
  var arr = emails.replace(/\s+/,'').split(/[,;]/);
  for (var i=0; i<arr.length; i++) {
    if (arr[i].match(pattern)==null)
      return false;
  }
  return true;
}


function Opoint_set_url()
{
  if (parent.window.opener && !parent.window.opener.closed) {
    document.tips.url.value = parent.window.opener.parent.location.href;
  } else {
    alert(gettext('ERROR_OCCURED'));
  }
}


function Opoint_utf8_encode(str)
{
  str = str.replace(/\r\n/g,"\n");
  var str_enc = '';

  for (var n = 0; n < str.length; n++) {

    var c = str.charCodeAt(n);

    if (c < 128) {
      str_enc += String.fromCharCode(c);
    }
    else if((c > 127) && (c < 2048)) {
      str_enc += String.fromCharCode((c >> 6) | 192);
      str_enc += String.fromCharCode((c & 63) | 128);
    }
    else {
      str_enc += String.fromCharCode((c >> 12) | 224);
      str_enc += String.fromCharCode(((c >> 6) & 63) | 128);
      str_enc += String.fromCharCode((c & 63) | 128);
    }

  }

  return str_enc;
}

