var reEmail = /^.+\@.+\..+$/
var isOpera = (navigator.userAgent.indexOf("Opera")  > -1);
var isNS4 = (document.layers);
var isNS6 = (!document.all && document.getElementById);
var isMacIE = ( (navigator.userAgent.indexOf("MSIE")  > -1) && (navigator.userAgent.indexOf("Mac")  > -1) );
var isMacIE4 = ( (navigator.userAgent.indexOf("IE 4")  > -1) && (navigator.userAgent.indexOf("Mac")  > -1) );

function openPopup(URL, name, width, height ) {
   var oWindow = window.open(URL, name, "resizable=1, scrollbars=1, toolbar=0, location=0, directories=0, status=0, menubar=0, copyhistory=0, width=" + width + ", height=" + height );  
   if (window.focus) { oWindow.focus(); }
}

function isEmpty(s) {   
   return ((s == null) || (s.length == 0));
}

function isEmail (email) {
   if (!isEmpty(email)) {
      return reEmail.test(email);
   } else {
      return false;
   }
}

function addBookmark(bookmarkurl, bookmarktitle) {
	if (document.all && !isOpera) {
		window.external.AddFavorite(bookmarkurl, bookmarktitle);
	} else if (isNS4 || isNS6) {
		alert("To add this page to your bookmarks, press Ctrl + D");
	} else if (isOpera) {
		alert("To add this page to your bookmarks, press Ctrl + T");
	}
	return;
}

function checkForm(txtJSValidation, field) {
	var errMsg = "";
	if (!isEmail(field.value)) {
		errMsg = errMsg + "- e-mail (myemail@email.org)\n\n";
	}
	if (errMsg != "") {
		alert(txtJSValidation + " :\n\n" + errMsg);
	} else {
		document.subscribeForm.submit();
	}
}

function initSearchForm(currentURL) {
	if (currentURL.indexOf('trial-watch') != -1) {
		document.searchform.searchType.selectedIndex = 1;
	}
}

function searchForm(currentURL, languageID) {
	if (document.searchform.searchType.selectedIndex == 0) {
		document.searchform.action = currentURL;
	} else {
		if (languageID == "3") {
			document.searchform.action= '/de/trial-watch/suchen.html';
		} else if(languageID == "0") {
			document.searchform.action = '/fr/trial-watch/recherche.html';
		} else {
			document.searchform.action = '/en/trial-watch/search.html';
		}
	}
	document.searchform.submit();
}