﻿// ===========================================
//
// Fonctions communes
//
// ===========================================

var strToolNameVersion = '';

function atx_OutOfFrame() {
	if (top.location != location) {
		top.location.href = document.location.href;
	}

	try {
	    document.body.oncontextmenu = function() { return false; }
	}
	catch (e) {
	}

	var btnDelete          = document.getElementById('btnDelete');

	try {
	    if (btnDelete != null) {
	        btnDelete.atx_previousOnclick = btnDelete.id;
	        btnDelete.onclick = atx_AlertDelete;
	    }
	}
	catch (e) {}

	var btnDelete          = document.getElementById('btnXMLDelete');

	try {
	    if (btnDelete != null) {
	        btnDelete.atx_previousOnclick = btnDelete.id;
	        btnDelete.onclick = atx_AlertDelete;
	    }
	}
	catch (e) {}

	var btnDelete          = document.getElementById('btnMP3Remove');

	try {
	    if (btnDelete != null) {
	        btnDelete.atx_previousOnclick = btnDelete.id;
	        btnDelete.onclick = atx_AlertDelete;
	    }
	}
	catch (e) {}

	var objContent          = document.getElementById('content');
	var objContentLeft      = document.getElementById('content_left');
	var objContentCenter    = document.getElementById('content_center');
	var objContentRight     = document.getElementById('content_right');
	var objMasterCell       = document.getElementById('master_cell');

	try {

		if (objContent != null) {
		    var intMinHeight = 420;
    		if (objContent != null) intMinHeight = Math.max(intMinHeight, objContent.offsetHeight);
    		if (objContentLeft != null) intMinHeight = Math.max(intMinHeight, objContentLeft.offsetHeight);
    		if (objContentCenter != null) intMinHeight = Math.max(intMinHeight, objContentCenter.offsetHeight);
    		if (objContentRight != null) intMinHeight = Math.max(intMinHeight, objContentRight.offsetHeight);
    		if (objMasterCell != null) intMinHeight = Math.max(intMinHeight, objMasterCell.offsetHeight);
    		var strSize = intMinHeight.toString() + 'px';
		    objContent.style.height = strSize;
    		if (objContentLeft != null) objContentLeft.style.height = strSize;
    		if (objContentCenter != null) objContentCenter.style.height = strSize;
    		if (objContentRight != null) objContentRight.style.height = strSize;
    		if (objMasterCell != null) objMasterCell.style.height = strSize;
		}
	}
	catch (e) {}

	try {
	    var objButton = document.getElementsByTagName('img');
	    if (objButton.length == 1) {
	    }
	    else {
	        for (var i = 0; i < objButton.length; i++) {
	            if (objButton[i].src.indexOf('buttons/btn_') >= 0) {
	                objButton[i].onmouseover = atx_OnButton;
	                objButton[i].onmouseout = atx_OffButton;
	            }
	        }
	    }
	}
	catch (e) {}

	try {
	    var objButton = document.getElementsByTagName('input');
	    if (objButton.length == 1) {
	    }
	    else {
	        for (var i = 0; i < objButton.length; i++) {
	            if (objButton[i].src) {
	                if (objButton[i].src.indexOf('buttons/btn_') >= 0) {
	                    objButton[i].onmouseover = atx_OnButton;
	                    objButton[i].onmouseout = atx_OffButton;
	                }
	            }
	        }
	    }
	}
	catch (e) {}
}

function atx_OnButton() {
    try {
        var objButton = window.event.srcElement;
        objButton.src = objButton.src.replace('_off.', '_on.');
    }
    catch (e) {}
}

function atx_OffButton() {
    try {
        var objButton = window.event.srcElement;
        objButton.src = objButton.src.replace('_on.', '_off.');
    }
    catch (e) {}
}

function atx_LinkOver(strStatusText) {
	window.status = strStatusText;
	return (navigator.appName != 'Opera');
}

function atx_LinkOut(strStatusText) {
	window.status = strStatusText;
}

function atx_GetParent(objAtx) {
	if (objAtx.parentElement != null) return objAtx.parentElement;
	else if (objAtx.parentNode != null) return objAtx.parentNode;
	else return null;
}

function atx_LinkToFavorite(strURL, strTitle) {
// <script type="text/javascript">atx_LinkToFavorite('http://www.cinetiks.com/', 'Cinetiks -:- Cinematic Music');</script>

    if( window.sidebar && window.sidebar.addPanel ) {
        //Gecko (Netscape 6 etc.) - add to Sidebar
        document.write('<span class="noprint">::&nbsp;&nbsp;<a href="' + strURL + '" rel="sidebar" title="' + strTitle + '">add to favorites</a>&nbsp;&nbsp;</span>\n');
    } else if( window.external && ( navigator.platform == 'Win32' ||
          ( window.ScriptEngine && ScriptEngine().indexOf('InScript') + 1 ) ) ) {
        //IE Win32 or iCab - checking for AddFavorite produces errors in
        //IE for no good reason, so use a platform and browser detect.
        //adds the current page page as a favourite; if this is unwanted,
        //simply write the desired page in here instead of 'location.href'
        document.write('<span class="noprint">::&nbsp;&nbsp;<a href="javascript:void(window.external.AddFavorite(\'' + strURL + '\', \'' + strTitle + '\'));" title="Bookmark this webpage">add to favorites</a>&nbsp;&nbsp;</span>');
    } else if( window.opera && window.print ) {
        //Opera 6+ - add as sidebar panel to Hotlist
        document.write('<span class="noprint">::&nbsp;&nbsp;<a href="' + strURL + '" title="' + strTitle + '" rel="sidebar">add to favorites</a>&nbsp;&nbsp;</span>');
    }
    return false;
}

// ===========================================
//
// Protection du bouton Supprimer
//
// ===========================================

function atx_AlertDelete() {

	if (confirm(strToolNameVersion
	+ '\n\nVous avez demandé la suppression de l\'information sélectionnée.\nCette opération ne peut pas être annulée.\n\n'
	+ 'Vous pouvez choisir de :\n\n'
	+ ' - Cliquer sur ANNULER pour revenir dans l\'outil sans supprimer l\'information.\n'
	+ ' - Cliquer sur OK pour confirmer la suppression de l\'information.') == true) {
		__doPostBack(window.event.srcElement.atx_previousOnclick,'');
	}
}

// =================================================
//
// Fonction NoSpamHyperlink
// (issue du domaine public)
//
// =================================================

function atx_LinkToMe(link,seed){var ky=
"yJzdeB4CcDnmEFbZtvuHlI1hA8SiLo9MwfN3O6Y5QaRqKTjUpxVk2WgXrP7Gs0";
if(document.all){link=document.all[link];}else{link=document.getElementById(link);}
var storeText=link.innerHTML;var baseNum=parseInt(seed);var atSym=link.href.indexOf("@");
if(atSym==-1)atSym=0;var dotidx=link.href.indexOf(".",atSym);if
(dotidx==-1)dotidx=link.href.length;var scramble=link.href.substring(7,
dotidx);var unscramble="";var su=true;for(i=0;i<scramble.length;i++)
{var ch=scramble.substring(i,i+1);var idx=ky.indexOf(ch);if(idx<0)
{unscramble=unscramble+ch;continue;}idx-=(su?-baseNum:baseNum);
baseNum-=(su?-i:i);while(idx<0)idx+=ky.length;idx%=ky.length;
unscramble=unscramble+ky.substring(idx,idx+1);su=!su;}var emAdd=
unscramble+link.href.substring(dotidx,link.href.length+1);link.href=
"mailto:"+emAdd;var findEm=storeText.indexOf(scramble);while(findEm>
-1){storeText=storeText.substring(0,findEm)+emAdd+
storeText.substring(findEm+emAdd.length,storeText.length);findEm=
storeText.indexOf(scramble);}link.innerHTML=storeText;}


// =================================================
//
// Fonctions COOKIES
// (issues du domaine public)
//
// =================================================

function getCookieVal (offset) {

  var endstr = document.cookie.indexOf (';', offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {

  var argv = GetCookie.arguments;
  var argc = GetCookie.arguments.length;
  var defaultvalue = (argc > 1) ? argv[1] : null;
  var arg = name + '=';
  var alen = arg.length;
  var cookievalue;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg){
      cookievalue = getCookieVal(j);
      if(cookievalue == 'null') return defaultvalue;
      return getCookieVal (j);
    }
    i = document.cookie.indexOf(' ', i) + 1;
    if (i == 0) break; 
  }
  return defaultvalue;
}

function SetCookie (name, value) {

  var argv = SetCookie.arguments;
  var argc = SetCookie.arguments.length;
  var expires = (argc > 2) ? argv[2] : null;
  var path = (argc > 3) ? argv[3] : null;
  var domain = (argc > 4) ? argv[4] : null;
  var secure = (argc > 5) ? argv[5] : false;

  document.cookie = name + '=' + escape (value) +
    ((expires == null) ? '' : ('; expires=' + expires.toGMTString())) +
    ((path == null) ? '' : ('; path=' + path)) +
    ((domain == null) ? '' : ('; domain=' + domain)) +
    ((secure) ? '; secure' : '');
}
/* ================================================= */

function atx_ObjectListProperties(objObject) {
//
// Liste les propriétés d'un objet
// De manière à ne pas occuper trop de place, les valeurs
// trop longues sont tronquées (64 caractères), les fonctions
// ne sont pas listées (<blacklisted>) car consultables en
// mode EDIT...
//
	var strList = 'Properties of object ' + objObject.toString() + '\n\n';
	var i = 0;
	for (prop in objObject) {
		try {
			if (objObject[prop] != null) {
				if ((typeof(objObject[prop]) == 'string') && (objObject[prop].length > 0)) {
					strList = strList + prop + '\t\t (' + typeof(objObject[prop]) + ')\t = '
					strList = strList + objObject[prop].substr(0,64) + '\n';
				}
				else if (typeof(objObject[prop]) == 'function') {
					strList = strList + prop + '\t\t (' + typeof(objObject[prop]) + ')\t = '
					strList = strList + '<blacklisted> \n';
				}
				else if ('<'+objObject[prop]+'>' != '<>') {
					strList = strList + prop + '\t\t (' + typeof(objObject[prop]) + ')\t = '
					strList = strList + objObject[prop] + '\n';
				}
				i += 1;
				if (i == 50) {
					alert(strToolNameVersion + '\n\n'
					+ strList);
					strList = '';
					i = 0;
				}
			}
		}
		catch (e) {
			strList = strList + prop + '\t\t\t  !!! ' + e.message + '\n';
			i += 1;
			if (i == 50) {
				alert(strToolNameVersion + '\n\n'
				+ strList);
				strList = '';
				i = 0;
			}
		}
	}
	alert(strToolNameVersion + '\n\n'
		+ strList);
	return true;
}

// ===========================================
//
// Egalisation de la hauteur des colonnes
//
// ===========================================

function atx_colH() {

	var i;
	var oh;
	var hh;

	var h=0;
	var dA=document.atx_eqc;
	var an=document.atx_eqa;
	
	if (dA && dA.length){

		for ( i = 0; i < dA.length; i++) {
			dA[i].style.height = 'auto';
		}
		
		for ( i = 0; i < dA.length; i++) {
			oh = dA[i].offsetHeight;
			h = (oh > h) ? oh : h;
		}
		
		for ( i = 0; i < dA.length; i++) {
			if (an) {
				dA[i].style.height = h + 'px';
			}
			else {
				atx_eqA(dA[i].id, dA[i].offsetHeight, h);
			}
		}
		
		if (an) {
			for ( i = 0; i < dA.length; i++) {
				hh = dA[i].offsetHeight;
				if (hh > h) {
					dA[i].style.height = (h - (hh - h)) + 'px';
				}
			}
		}
		else {
			document.atx_eqa = 1;
		}

		document.atx_eqth = document.body.offsetHeight;
		document.atx_eqtw = document.body.offsetWidth;
	}
}

function atx_eqT() {

	if (document.atx_eqth != document.body.offsetHeight || document.atx_eqtw != document.body.offsetWidth) {
		atx_colH();
	}
}

function atx_equalCols() {

	if (document.getElementById) {
		document.atx_eqc = new Array;
		if (arguments.length == 0) {
			var i = 0
			while (0 == 0) {
				if (document.getElementById('c' + (i + 1).toString()) == null) break;
				document.atx_eqc[i] = document.getElementById('c' + (i + 1).toString());
				i++;
			}
		}
		else {
			for (i = 0; i < arguments.length; i++) {
				document.atx_eqc[i] = document.getElementById(arguments[i]);
			}
		}
		setInterval("atx_eqT()", 10);
	}
}

function atx_equalColsFast() {

	if (document.getElementById) {
		document.atx_eqc = new Array;
		for (i = 0; i < arguments.length; i++) {
			document.atx_eqc[i] = document.getElementById(arguments[i]);
		}
	}
}

function atx_eqA(el, h, ht) {

	var sp = 10;
	var inc = 10;
	var nh = h;
	var g = document.getElementById(el);
	var oh = g.offsetHeight;
	var ch=parseInt(g.style.height);
	
	ch = (ch) ? ch : h;
	
	var ad = oh-ch;
	var adT = ht-ad;

	nh += inc;
	nh = (nh > adT) ? adT : nh;
	
	g.style.height = nh+'px';
	oh = g.offsetHeight;
	
	if (oh > ht) {
		nh = (ht - (oh - ht));
		g.style.height = nh + 'px';
	}

	if (nh < adT) {
		setTimeout("atx_eqA('" + el + "'," + nh + "," + ht + ")", sp);
	}
}
