// JavaScript Document
function GetURL(icUrl){
	if(icUrl != "#")window.location.href = icUrl;
	else alert("pas d'url");
}

function ResizeContent(){
	var headerHeight = (document.getElementById("divHeader"))?(document.getElementById("divHeader").offsetHeight):(0);
	var centreHeight = document.getElementById("divCentre").offsetHeight;
	var footerHeight = document.getElementById("divFooter").offsetHeight;
	//-------------------------------------------------------------------------
	var browserOffset = 0;
	var avaibleHeight = 0;
	if (self.innerHeight) // all except Explorer
	{
		avaibleHeight = self.innerHeight;
		browserOffset = 0;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
	{
		avaibleHeight = document.documentElement.clientHeight;
		browserOffset = 0;
	}
	else if (document.body) // other Explorers
	{
		avaibleHeight = document.body.offsetHeight;
		browserOffset = 0;
	}
	//alert(avaibleHeight);
	//-------------------------------------------------------------------------
	var diffHeight = Number(avaibleHeight-headerHeight-footerHeight-browserOffset);
	if(centreHeight < diffHeight){
	    document.getElementById("divCentre").style.height = diffHeight + "px";
	    if(document.getElementById("tableContent"))document.getElementById("tableContent").style.height = diffHeight + "px";
	}
	if(document.getElementById("divGallery")){
        document.getElementById("divGallery").style.height = (diffHeight) + "px";
    }
	//-------------------------------------------------------------------------
	    
    if(document.getElementById("IFramePage")){
        document.getElementById("IFramePage").height = diffHeight-30;
    }
	
	document.getElementById("divAll").style.display = "";
}

function PrintOpenerContent(){
    document.getElementById("divContentToPrint").innerHTML = window.opener.document.getElementById("divContentScroll").innerHTML;
    window.print();
    window.close();
}

myWindow = null;
function Popup(icURL, icWIdth, icHeight, ilResisable, icWindowName){
	myWindow = window.open (icURL, icWindowName, "status=0,toolbar=0,menubar=0,location=0,resizable="+ ilResisable +",scrollbars=1,fullscreen=0,directories=0,top=20,left=" + ((screen.availWidth - icWIdth) / 2) + ",height=" + icHeight + ",width=" + icWIdth);
}


var Navmenu;
function DoLayout(){
  Navmenu = document.getElementById("Navmenu");
  if(timer == null)InitIFrameProcess("https://thybris.com/LogStatus.asp?domain="+document.domain);
  //ResizeContent();
}

//window.onresize=ResizeContent;
//window.onchange=ResizeContent;

var timerInterv;
function Interval(nLapsTime){
    //alert(nLapsTime);
    timerInterv = setTimeout("GetHome()", nLapsTime);
}

function GetHome(){
    window.location = "/default.aspx";
    clearTimeout(timerInterv);
}

function GetFlashMovie(swfFile, width, height, divToWrite, bgcolor){
    if(document.getElementById(divToWrite)){
        var swfObjId = swfFile.substring(0,swfFile.indexOf(".swf"));
        var so = new SWFObject("/Ext/Layouts/Common.Layout10/Thybris/images/" + swfFile, swfObjId, width, height, "9.0.0", bgcolor, true);
        so.addParam("quality", "high");
        so.addParam("menu", "false");
        so.addParam("allowScriptAccess", "sameDomain");
        so.addParam("salign ", "T");
        so.useExpressInstall('/Styles/expressinstall.swf');
        so.write(divToWrite);
    }    
}

function GetMoviePlayer(file, width, height, divToWrite, idVideo){
    if(document.getElementById(divToWrite)){
        //var swfObjId = swfFile.substring(0,file.indexOf(".swf"));
        var mpObj = "<OBJECT ID='MediaPlayer1' classid='CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95' codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715' WIDTH='" +width+ "' HEIGHT='" +height+ "' standby='Loading Microsoft® Windows Media Player components...' type='application/x-oleobject'> <PARAM NAME='FileName' VALUE='" +file+ "'> <PARAM NAME='AnimationatStart' VALUE='false'> <PARAM NAME='TransparentatStart' VALUE='true'> <PARAM NAME='AutoStart' VALUE='true'> <PARAM NAME='ShowControls' VALUE='true'> <EMBED name='MediaPlayer1' type='application/x-mplayer2' pluginspage='http://www.microsoft.com/Windows/MediaPlayer/' SRC='" +file+ "' WIDTH='" +width+ "' HEIGHT='" +height+ "' AutoStart='true'></EMBED></OBJECT>";
        document.getElementById(divToWrite).innerHTML = mpObj;
    }
}
//------------------ IFRAME PROCESS -----------------
var nbInterval = 0;
var timer = null;
function InitIFrameProcess(strLocation){
    if(document.getElementById("ifrmProcess")){
        document.getElementById("ifrmProcess").src = strLocation;
        timer = setInterval("GetIframeProcessResult()", 100);
        nbInterval = 0; 
    }
}

function GetIframeProcessResult(){
    nbInterval++;
    try {
        var loginString = document.getElementById("ifrmProcess").contentWindow.location.href;
        if(loginString.indexOf("#") != -1){
            loginString = loginString.substring(loginString.indexOf("#")+1);
            if(loginString.length > 1 && document.getElementById("ifrmRightBanner").contentWindow.document.getElementById("divLoginForm")){
                document.getElementById("ifrmRightBanner").contentWindow.document.getElementById("divLoginForm").innerHTML = "<div style='height:150px;'>Bienvenue, <b style='text-transform:uppercase;'>" + unescape(loginString) + "</b><br/><IMG hspace=0 src='/Ext/Layouts/Common.Layout10/Thybris/images/separateur2.gif' align='middle' vspace='1' border='0' /><br /><a href='https://thybris.com/' class='highlight' target='_parent'>Acc&eacute;der &agrave; ma messagerie</a></div>";
                clearInterval(timer);
            }
        }
    }
    catch(e){
        
    }

}

//-----------------------------------
// Copyright © Thybris 2001-2003
//-----------------------------------


function openPopup(pageURL, winName, width, height, left, top, menu, scroll, tool, status, location, resizable) {
  var properties;
  properties  = 'width=' + width + ',height=' + height;
  properties += ',left=' + left + ',top=' + top + ',screenX=' + left + ',screenY=' + top + ',directories=0,hotkeys=1';
  properties += ',menubar=' + menu + ',scrollbars=' + scroll + ',toolbar=' + tool + ',status=' + status;
  properties += ',location=' + location + ',resizable=' + resizable;
  return window.open(pageURL, winName, properties);
}
function openWindow(url, winName, width, height, x, y, scroll, resizable) {
  /**
  * Détection du browser
  **/
  var _navType;
  if (navigator.appName.indexOf('Netscape') != -1) _navType = "ns";
  else if (navigator.appName == "Microsoft Internet Explorer") _navType = "ie";
  var _v   = parseInt(navigator.appVersion);
  var _ns  = (_navType == "ns" && _v >= 4);
  var _ie  = (_navType == "ie" && _v >= 4);
  var _dom = (document.createElement && document.appendChild && document.getElementsByTagName ? true : false);
  var xOffset = 0, yOffset = 0;
  if (_ie) {
    var site = eval("top" + topframe);
    if (site) {
      xOffset = site.screenLeft + x;
      yOffset = site.screenTop  + y;
    }
    else {
      xOffset = top.screenLeft + x;
      yOffset = top.screenTop  + y;
    }
  }
  else if (_ns) {
    var site = eval(topframe == "" ? "top" : "top.frames" + topframe);
    if(site) {
      xOffset = (site.outerWidth  - site.innerWidth);
      yOffset = (site.outerHeight - site.innerHeight) - 10;
    }
  }
  if (height <= 0) height = screen.height - yOffset - 55;
  /**
  * Ouverture de la fenêtre PopUp
  **/
  if (xOffset || yOffset) {
    var w = window.open(url, winName,
                        'width=' + width + ',height=' + height +
                        ',left=' + xOffset + ',top=' + yOffset +
                        ',screenX=' + xOffset + ',screenY=' + yOffset +
                        ',scrollbars=' + scroll + ',resizable=' + resizable);
  }
  else {
    var w = window.open(url, winName,
                        'width=' + width + ',height=' + height +
                        ',scrollbars=' + scroll + ',resizable=' + resizable);
  }
  w.focus();
  return w;
}
//
function popupSize(pageURL, winName, width, height) {
//return openPopup (pageURL, winName, width, height, 100, 100, 0, 0, 0, 0, 0, 1);
  return openWindow(pageURL, winName, width, height,  45,  45, 0, 1);
}
//
var notewin = null;
function closenote() {
  if (notewin && !notewin.closed) notewin.close();
}
function openote(url) {
  closenote();
//notewin = openPopup (url, '', 600, 400, 100, 100, 0, 1, 0, 0, 0, 1);
  notewin = openWindow(url, '', 600, 400, 15, 15, 1, 1);
}
//
function getQueryData(query, name) {
  var start = query.indexOf(name + '=');
  var len = start + name.length + 1;
  if ((!start) && (name != query.substring(0, name.length)))
    return null;
  if (start == -1)
    return null;
  var end = query.indexOf('&', len);
  if (end == -1) end = query.length;
  return query.substring(len, end);
}
//
function getUrlData(url, name) {
  return getQueryData(url.search, name);
}
//
function getFormData(forms, name) {
  return eval(forms + '.' + name + '.value');
}
function setFormData(forms, name, value) {
  eval(forms + '.' + name).value = value;
}
//
function getCookie(name) {
  var start = document.cookie.indexOf(name + '=');
  var len = start + name.length + 1;
  if ((!start) && (name != document.cookie.substring(0, name.length)))
    return null;
  if (start == -1)
    return null;
  var end = document.cookie.indexOf(';', len);
  if (end == -1) end = document.cookie.length;
  return unescape(document.cookie.substring(len, end));
}
function setCookie(name, value, expires, path, domain, secure) {
  document.cookie = 
    name + '=' + escape(value) +
    ( (expires) ? ';expires=' + expires.toGMTString() : '') +
    ( (path) ? ';path=' + path : '') + 
    ( (domain) ? ';domain=' + domain : '') +
    ( (secure) ? ';secure' : '');
}
function deleteCookie(name, path, domain) {
  if (getCookie(name))
    document.cookie =
      name + '=' +
      ( (path) ? ';path=' + path : '') +
      ( (domain) ? ';domain=' + domain : '') +
      ';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}
//-------------------------------------------------
//       THYBRIS ADMIN 
//-------------------------------------------------

function IsValidAddress(sEmailAddress)
{
	//LAG 2001
	// la string sCheckOk est composée des caractère ASCII de 33 à 127 moins les caractères "(),:;<>[\]
	var sCheckOk= "!#$%&'*+-./0123456789=?@ABCDEFGHIJKLMNOPQRSTUVWXYZ^_`abcdefghijklmnopqrstuvwxyz{|}~ "
	var iArobaseCount = 0;
	if (sEmailAddress=="") return false;
	if (sEmailAddress.length < 5) return false;
	if (sEmailAddress.indexOf("@") == -1) return false; 
		
	for (var i=0;i < sEmailAddress.length; i++)
	{
		ch = sEmailAddress.charAt(i)
		if (sCheckOk.indexOf(ch)==-1)
		{
			return false
		}
		if (ch=="@")
		{
			iArobaseCount++
		}	
	}
	if(iArobaseCount>1)
	{
		return false
	}
	
	return true
}


function fValidateData()
{  

	if(!IsValidAddress(frm.txtUserLogin.value))
	{
	  alert("Vous devez saisir votre adresse Email.");
	  frm.txtUserLogin.focus()
	  return false;
	}      
	 
	if(frm.txtUserPassword.value=="")
	{
	  alert("Vous devez saisir votre mot de passe.");
	  frm.txtUserPassword.focus()
	  return false;
	}
	
	return true
			
}

function PasswordRequestLink_Click()
  {	
		var bContinue=true
		
		if(document.getElementById("txtUserLogin").value!="")
		{
			if(!IsValidAddress(document.getElementById("txtUserLogin").value))
      {        
        alert("Vous devez saisir votre adresse Email.");
        document.getElementById("txtUserLogin").focus();
        bContinue = false;
      }
		}
		
		if (bContinue)
		{		
			var myDate = new Date();
			parent.location.href = "https://thybris.com/Forms/Authenticate/PasswordRequest.asp?UserLogin=" + document.getElementById("txtUserLogin").value + "&NoCach=" + myDate.getDate();		
		}
  }
