function addEvent(obj, evType, fn) {
	if (obj.addEventListener) {
		obj.addEventListener(evType, fn, true);
		return true;
	} else if (obj.attachEvent) {
		var r = obj.attachEvent("on"+evType, fn); 
		return r;
	} else {
		return false;
	}
}

function playSoundlogo() {
  if(document.getElementById("soundlogo")){
   document.getElementById("soundlogo").innerHTML="<embed src='/mp3/soundlogo.mp3' hidden=true autostart=true loop=false>";
  }
}	
function playSoundBtn(surl) {
  if(document.getElementById("soundbtn")){
   document.getElementById("soundbtn").innerHTML="<embed src='/mp3/"+surl+"' hidden=true autostart=true loop=false>";
  }
}



function validateNewsletter(thisObj){
  if(!validEmail(thisObj.email.value)){
  	alert('You have to type a valid email address');
  	thisObj.email.focus();
  	return false;
  }
  return true;
}


function validateRegistration(thisObj){
  if(thisObj.name.value==''){
  	alert('You have to type your name');
  	thisObj.name.focus();
  	return false;
  }
  if(thisObj.company.value==''){
  	alert('You have to type a company');
  	thisObj.company.focus();
  	return false;
  }
  if(thisObj.postalcode.value==''){
  	alert('You have to type your postal code');
  	thisObj.postalcode.focus();
  	return false;
  }
  if(thisObj.city.value==''){
  	alert('You have to type your city');
  	thisObj.city.focus();
  	return false;
  }
  if(thisObj.country.value==''){
  	alert('You have to type your country');
  	thisObj.country.focus();
  	return false;
  }
  if(!validEmail(thisObj.email.value)){
  	alert('You have to type a valid email address');
  	thisObj.email.focus();
  	return false;
  }
  return true;
}

function validateCallforpapers(thisObj){
  if(thisObj.name.value==''){
  	alert('You have to type your name');
  	thisObj.name.focus();
  	return false;
  }
  if(!validEmail(thisObj.email.value)){
  	alert('You have to type a valid email address');
  	thisObj.email.focus();
  	return false;
  }
  if(thisObj.mobile.value==''){
  	alert('You have to type your mobile phone');
  	thisObj.mobile.focus();
  	return false;
  }
	//var btn = valButton(thisObj.s1);
  //if (btn == null){
  //	 alert('You have to select type');
	//	 return false;
	//}
  if(thisObj.title.value==''){
  	alert('You have to type a title');
  	thisObj.title.focus();
  	return false;
  }
  if(thisObj.abstract.value==''){
  	alert('You have to submit your abscrat');
  	thisObj.abstract.focus();
  	return false;
  }
	
  return true;
}

function valButton(btn) {
    var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) {
        if (btn[i].checked) {cnt = i; i = -1;}
    }
    if (cnt > -1) return btn[cnt].value;
    else return null;
}


function validEmail(str) {
		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1){
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false;
		 }
 		 return true					
	}




var tld_ = new Array()
tld_[0] = "com";
tld_[1] = "org";
tld_[2] = "net";
tld_[3] = "se";
tld_[4] = "info";
tld_[10] = "co.uk";
tld_[11] = "org.uk";
tld_[12] = "gov.uk";
tld_[13] = "ac.uk";
var topDom_ = 13;
var m_ = "mailto:";
var a_ = "@";
var d_ = ".";

function mail(name, dom, tl, params)
{
	var s = e(name,dom,tl);
	document.write('<a href="'+m_+s+params+'">'+s+'</a>');
}
function mail2(name, dom, tl, params, display)
{
	document.write('<a href="'+m_+e(name,dom,tl)+params+'">'+display+'</a>');
}
function e(name, dom, tl)
{
	var s = name+a_;
	if (tl!=-2)
	{
		s+= dom;
		if (tl>=0)
			s+= d_+tld_[tl];
	}
	else
		s+= swapper(dom);
	return s;
}
function swapper(d)
{
	var s = "";
	for (var i=0; i<d.length; i+=2)
		if (i+1==d.length)
			s+= d.charAt(i)
		else
			s+= d.charAt(i+1)+d.charAt(i);
	return s.replace(/\?/g,'.');
}
