// browser identification
	_agt = navigator.userAgent.toLowerCase();
	_is_ie	   = ((_agt.indexOf("msie") != -1) && (_agt.indexOf("opera") == -1));
	_is_gecko  = (navigator.product == "Gecko");
/*
This function is used only for the surfer part and open a new window with predefined attributes that are set in the contrib. part
*/
function openWindow(thePage,popW,popH,popL,popT,flgTitle,flgTool,flgStatus,flgMenu,flgResize,flgScroll,flgLocation)
{

	if (thePage.length > 0)
	{
		popW.toString().length > 0?param = "width=" + popW + ",":param ="";
		popH.toString().length  > 0?param += "height=" + popH+ ",":param +="";
		popL.toString().length  > 0?param += "left=" + popL+ ",":param +="";
		popT.toString().length  > 0?param += "top=" + popT+ ",":param +="";
		param+="titlebar=" + flgTitle.toString() + ",";
		param+="toolbar=" + flgTool.toString() + ",";
		param+="status=" + flgStatus.toString() + ",";
		param+="menubar=" + flgMenu.toString() + ",";
		param+="resizable=" + flgResize.toString() + ",";
		param+="scrollbars=" + flgScroll.toString() + ",";
		param+="location=" + flgLocation.toString() + ",";
		param=param.substr(0,param.length-1);
		window.open(thePage,'test',param);

	}
}

//obfuscast mailto links in source code until mouseover - link will be <a href=mailto:a@b>c</a>
function obfuscateMail(a,b,c)
{
  document.write("<a href='YouNeedJavascript' onmouseover=\"this.href='mailto:" + a + "@" + b + "'\" onmouseout=\"this.href='YouNeedJavascript'\">" + (c?c:a+'@'+b) + "</a>");
}


function openPopup(thePage,idWin,popW,popH)
{
	w = screen.availWidth;
	h = screen.availHeight;
	var leftPos = (w-popW)/2,  topPos = (h-popH)/2;
	window.open(thePage,idWin,"left=" + leftPos + ",top=" + topPos + ",width="+ popW +",height=" + popH  + ",toolbar=no,status=no,titlebar=no,menubar=no,resizable=yes,scrollbars=yes")
}

function openDialog(thePage,idWin,popW,popH)
{
	w = screen.availWidth;
	h = screen.availHeight;
	var leftPos = (w-popW)/2,  topPos = (h-popH)/2;
	
	if (! window.showModalDialog)
	{
		window.showModalDialog = function(url, vArguments, sFeatures)
		{
			var sf = sFeatures.replace('dialog', '');
			sf = sf.replace('px', '');
			sf = sf.replace('scroll', 'scrollbars').split(';').join(', ');
			sf += ', location=0, menubar=0, toolbar=0, dependent=1';
			var mw = window.open(url, 'Dialog', sf);
			mw.dialogArguments = vArguments;
			this.onfocus = function(){
				alert("Nico");
				if(winDisabled==false)
					this.onfocus=null;
				else 
					this.blur()
			}
			return mw.returnValue;
		}
	}

	return window.showModalDialog (thePage,idWin,"dialogLeft:" + leftPos + "px;dialogTop:" + topPos + "px;dialogWidth:"+ popW +"px;dialogHeight:" + popH  + "px;status:no;scroll:no");	
}

function openACEditor(MenuId,ZoneOrder,ContentID,ZoneId,PubDate)
{
	w = screen.availWidth;
	h = screen.availHeight;
	var leftPos = (w-800)/2,  topPos = (h-400)/2;
	Hwnd_ACeditor = window.open("../../Edition/ACEditorFrameDef.asp?MenuId=" + MenuId + "&ZoneOrder=" + ZoneOrder + "&ContentID=" + ContentID + "&ZoneID=" + ZoneId + "&PubDate=" + PubDate,"Editor","left=" + leftPos + ",top=" + topPos + ",width="+ 800 +",height=" + 400  + ",toolbar=no,status=yes,titlebar=no,menubar=no,resizable=yes")
	Hwnd_ACeditor.focus()
}

function openEditor(MenuId,ZoneOrder,ContentID,ZoneId,PubDate,IsActiveContent,event)
{
	if(IsActiveContent)
	{
		Hwnd_editor = window.open("../../Edition/ACEditorFrameDef.asp?MenuId=" + MenuId + "&ZoneOrder=" + ZoneOrder + "&ContentID=" + ContentID + "&ZoneID=" + ZoneId + "&PubDate=" + PubDate,"Editor","width=800,height=600,left=0,top=0,toolbar=no,status=yes,titlebar=yes,menubar=no,resizable=yes")
	}
	else
	{
		Hwnd_editor = window.open("../../Edition/Editor.asp?MenuId=" + MenuId + "&ZoneOrder=" + ZoneOrder + "&ContentID=" + ContentID + "&ZoneID=" + ZoneId + "&PubDate=" + PubDate,"Editor","width=800,height=600,left=0,top=0,toolbar=no,status=yes,titlebar=yes,menubar=no,resizable=yes")
	}
	Hwnd_editor.focus()
}
function trimString (str) {
  str = this != window? this : str;
  return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

String.prototype.trim = trimString;

function isURL (s) {
    var machine = "[A-Za-z0-9]+((\\.|(\\-)+)[A-Za-z0-9]+)*";
    var reURL = new RegExp("^" + machine + "$");
    return (reURL.test(s));
}

/*http://www.breakingpar.com/bkp/home.nsf/Doc!OpenNavigator&87256B280015193F87256C40004CC8C6*/
function isEmail(s) {
  var msg="";
  var reMail = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[(2([0-4]\d|5[0-5])|1?\d{1,2})(\.(2([0-4]\d|5[0-5])|1?\d{1,2})){3} \])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
  if (!reMail.test(s))
		msg = "     - You need to enter a valid email address.\n";
  return(msg);	
}

//Check for multiple comma or semi-colon separated emails
function isEmails(val)
{ 	      	
  myregexp=/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*([,;]\s*\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*)*/;
  return(val.match(myregexp));
}
  
function isLogin(s){
  var msg = "";
  if (s.length < 3)
    msg += "     - You need to define a login name of at least 3 characters.\n";
  if (s.indexOf(' ')>-1)
    msg += "     - The login must not contain any spaces.\n";
  return(msg);
}

function isPassword(s){
  var msg = "";
  if (s.length < 3)
    msg += "     - You need to define a password of at least 3 characters.\n";
  if (s.indexOf(' ')>-1)
    msg += "     - The password must not contain any spaces.\n";
  return(msg);
}


function IsDigit(e)
{// whole numbers only (8=delete)
 // Use this code like so: onKeyPress="return IsDigit(event);"
  var key = GetKeyCode(e);
  if(((key < 48) || (key > 57)) && (!isControlKey(key))) {return false};
}

function isControlKey(key)
{
  var cursorKeys ="8;9;37;38;39;40;35;36";
	return (cursorKeys.indexOf(key+";") >= 0) 
}

function GetKeyCode(e)
{
  if(!e)e = window.event;
  return(e.which?e.which:e.keyCode);
}

function TextAreaMax(e, maxLen)
{// limit entry in text area
 // Use this code like so: onKeyPress="return TextAreaMax(event,500);"
  if (GetKeyCode(e)==8 || isControlKey(GetKeyCode(e))) return true;  // backspace/cursor allowed!
  if(!e)e = window.event;
  len = e.srcElement?e.srcElement.value.length:e.target.value.length; 
  return (len < maxLen)
}

function IsPosNumber(e)
{// positive decimal numbers (46 = '.')
  var key = GetKeyCode(e);
	if(((key < 48) || (key > 57)) && (key != 46) && (!isControlKey(key))) return false;
}

function IsWholeNumber(e)
{// positive or negative Whole numbers (45= '-')
  var key = GetKeyCode(e);
	if(((key < 48) || (key > 57)) && (key != 45) && (!isControlKey(key))) return false;
}

function IsNumber(e)
{// positive or negative decimal numbers (45='-', 46 = '.')
  var key = GetKeyCode(e);
	if(((key < 48) || (key > 57)) && (key != 45) && (key != 46) && (!isControlKey(key))) return false;
}

function cboSync(cbo,txt)
{
   var len=txt.value.length;
   var tex=txt.value.toUpperCase();

   var i = 0;
   while (i < cbo.options.length && cbo.options[i].text.substring(0,len).toUpperCase() <= tex)
   {
     if (cbo.options[i].text.substring(0,len).toUpperCase() == tex)
     {
       cbo.options[i].selected=true;
       return;
     }
     i++;
   }
   if (i>0) i-=1;
   cbo.options[i].selected=true;
}

// -------------------------------------------------------------------
// autoComplete (text_input, select_input, ["text"|"value"], [true|false])
//   Use this function when you have a SELECT box of values and a text
//   input box with a fill-in value. Often, onChange of the SELECT box
//   will fill in the selected value into the text input (working like
//   a Windows combo box). Using this function, typing into the text
//   box will auto-select the best match in the SELECT box and do
//   auto-complete in supported browsers.
//   Arguments:
//      field = text input field object
//      select = select list object containing valid values
//      property = either "text" or "value". This chooses which of the
//                 SELECT properties gets filled into the text box -
//                 the 'value' or 'text' of the selected option
//      forcematch = true or false. Set to 'true' to not allow any text
//                 in the text box that does not match an option. Only
//                 supported in IE (possible future Netscape).
// -------------------------------------------------------------------

function autoComplete (field, select, property, forcematch) {
	var found = false;
	for (var i = 0; i < select.options.length; i++) {
		tmp = select.options[i][property]
		tmp = tmp.toUpperCase();
	if (tmp.indexOf(field.value.toUpperCase()) == 0) {
		found=true; break;
	}

	}
	if (found) { select.selectedIndex = i; select.onchange() }
	else { select.selectedIndex = -1; }

	if (field.createTextRange) {
		if (forcematch && !found) {
			field.value=field.value.substring(0,field.value.length-1);
			return;
			}
		var cursorKeys ="8;46;37;38;39;40;33;34;35;36;45;";
		if (cursorKeys.indexOf(event.keyCode+";") == -1) {
			var r1 = field.createTextRange();
			var oldValue = r1.text;
			var newValue = found ? select.options[i][property] : oldValue;
			if (newValue != field.value) {
				field.value = newValue;
				var rNew = field.createTextRange();
				rNew.moveStart('character', oldValue.length) ;
				rNew.select();
				}
			}
		}
	}
	
// To limit the text in a textarea
function LimitText(fieldObj,maxChars)
{
  var result = true;
  if (fieldObj.value.length >= maxChars)
  {
    result = false;
    fieldObj.value = fieldObj.value.substring(0, maxChars);
    alert("Your string has been truncated to " + maxChars + " chars");
   }
  
  if (window.event)
    window.event.returnValue = result;
  return result;
}