
/*
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);

	}
}


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")
}

function openDialog(thePage,idWin,popW,popH)
{
	w = screen.availWidth;
	h = screen.availHeight;
	var leftPos = (w-popW)/2,  topPos = (h-popH)/2;
	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)
{

	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));
}

function isEmail(s) {
  var msg="";
  mail = "^\\w+((-\\w+)|(\\.\\w+))*\\@[A-Za-z0-9]+((\\.|-)[A-Za-z0-9]+)*\\.[A-Za-z0-9]+$";
  var reMail = new RegExp(mail);
  if (!reMail.test(s))
		msg = "     - You need to enter a valid email address.\n";
  return(msg);	
}

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 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;
}