emailNotValid = "Email is not valid. Please correct it." ;

function valid(form) {
	var email = form.fromemail;  
	if(-1 == email.value.indexOf("@") || -1 == email.value.indexOf(".") ) { 
		   email.focus(); 
		   alert(emailNotValid); 
		   return false; 
   }
   else   return true;
}

d = document; w = window;

function getParOf(form) {
	var qs = ''
	if (typeof encodeURIComponent != "function")
		encodeURIComponent = encodeURIComponentNew
	for (e=0;e<form.elements.length;e++) {
		if (form.elements[e].name!='') {
			qs+=(qs=='')?'?':'&'
			qs+=form.elements[e].name+'='+encodeURIComponent(form.elements[e].value)
		}
	}
	return qs
}

function load(file) {
	if( d.layers && s.layers['datadiv'].load ) 
		d.layers['datadiv'].load(file,0);
	else if( w.frames && w.frames.length ) 
		w.frames['dataframe'].window.location.replace(file);
}

function writeContent(answer,container){
	d.getElementById(container).innerHTML = answer.innerHTML ;
}

function sendmail(ta){
	if (valid(ta)){
		load('mail.php'+getParOf(ta));
	}
	return false;
}

// following code for older browsers only
function utf8(wide){
  var c, s;
  var enc = "";
  var i = 0;
  while(i<wide.length) {
    c= wide.charCodeAt(i++);
    // handle UTF-16 surrogates
    if (c>=0xDC00 && c<0xE000) continue;
    if (c>=0xD800 && c<0xDC00) {
      if (i>=wide.length) continue;
      s= wide.charCodeAt(i++);
      if (s<0xDC00 || c>=0xDE00) continue;
      c= ((c-0xD800)<<10)+(s-0xDC00)+0x10000;
    }
    // output value
    if (c<0x80) enc += String.fromCharCode(c);
    else if (c<0x800) enc += String.fromCharCode(0xC0+(c>>6),0x80+(c&0x3F));
    else if (c<0x10000) enc += String.fromCharCode(0xE0+(c>>12),0x80+(c>>6&0x3F),0x80+(c&0x3F));
    else enc += String.fromCharCode(0xF0+(c>>18),0x80+(c>>12&0x3F),0x80+(c>>6&0x3F),0x80+(c&0x3F));
  }
  return enc;
}

var hexchars = "0123456789ABCDEF";

function toHex(n) {
  return hexchars.charAt(n>>4)+hexchars.charAt(n & 0xF);
}

var okURIchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-";

function encodeURIComponentNew(s) {
  var s = utf8(s);
  var c;
  var enc = "";
  for (var i= 0; i<s.length; i++) {
    if (okURIchars.indexOf(s.charAt(i))==-1)
      enc += "%"+toHex(s.charCodeAt(i));
    else
      enc += s.charAt(i);
  }
  return enc;
}
