$(document).ready(function(){
	conciergerie.init();
	
	if ($('a.fcContact').length > 0)
	{
		$('a.fcContact').fancybox({
			'transitionIn'			:	'elastic',
			'transitionOut'			:	'elastic',
			'speedIn'				:	600, 
			'speedOut'				:	200,
			'height'				:	650,
			'width'					:	700,
			'type'					:	'iframe',
			'titlePosition'			:	'inside',
			'hideOnOverlayClick'	:	false,
			'centerOnScroll'		:	true
		});
	}
	
	if ($('a.fcCandType').length > 0)
	{
		$('a.fcCandType').fancybox({
			'transitionIn'			:	'elastic',
			'transitionOut'			:	'elastic',
			'speedIn'				:	600, 
			'speedOut'				:	200,
			'height'				:	650,
			'width'					:	700,
			'type'					:	'iframe',
			'titlePosition'			:	'inside',
			'hideOnOverlayClick'	:	false,
			'centerOnScroll'		:	true
		});
	}
	
	if ($('a.fcFiche, a.fcCandidat, a.fcEnseigne').length > 0)
	{
		$('a.fcFiche, a.fcCandidat, a.fcEnseigne').fancybox({
			'transitionIn'			:	'elastic',
			'transitionOut'			:	'elastic',
			'speedIn'				:	600, 
			'speedOut'				:	200,
			'height'				:	600,
			'width'					:	700,
			'type'					:	'iframe',
			'titlePosition'			:	'inside',
			'hideOnOverlayClick'	:	false,
			'centerOnScroll'		:	true
		});
	}
	
	if ($('a.fcDev').length > 0)
	{
		$('a.fcDev').fancybox({
			'transitionIn'			:	'elastic',
			'transitionOut'			:	'elastic',
			'speedIn'				:	600, 
			'speedOut'				:	200,
			'height'				:	400,
			'width'					:	700,
			'type'					:	'iframe',
			'titlePosition'			:	'inside',
			'hideOnOverlayClick'	:	false,
			'centerOnScroll'		:	true
		});
	}
	
	if ($('a.fcMail').length > 0)
	{
		$('a.fcMail').fancybox({
			'transitionIn'			:	'elastic',
			'transitionOut'			:	'elastic',
			'speedIn'				:	600, 
			'speedOut'				:	200,
			'height'				:	150,
			'width'					:	700,
			'type'					:	'iframe',
			'titlePosition'			:	'inside',
			'hideOnOverlayClick'	:	false,
			'centerOnScroll'		:	true
		});
	}
	
	if ($('a.fcLogin').length > 0)
	{
		$('a.fcLogin').fancybox({
			'transitionIn'			:	'elastic',
			'transitionOut'			:	'elastic',
			'speedIn'				:	600, 
			'speedOut'				:	200,
			'height'				:	160,
			'width'					:	700,
			'type'					:	'iframe',
			'titlePosition'			:	'inside',
			'hideOnOverlayClick'	:	false,
			'centerOnScroll'		:	true
		});
	}
	
	if ($('a.fcMsg').length > 0)
	{
		$('a.fcMsg').fancybox({
			'transitionIn'			:	'elastic',
			'transitionOut'			:	'elastic',
			'speedIn'				:	600, 
			'speedOut'				:	200,
			'height'				:	500,
			'width'					:	700,
			'type'					:	'iframe',
			'titlePosition'			:	'inside',
			'hideOnOverlayClick'	:	false,
			'centerOnScroll'		:	true
		});
		
		$('a.fcMsgSup').fancybox({
			'transitionIn'			:	'elastic',
			'transitionOut'			:	'elastic',
			'speedIn'				:	600, 
			'speedOut'				:	200,
			'height'				:	150,
			'width'					:	700,
			'type'					:	'iframe',
			'titlePosition'			:	'inside',
			'hideOnOverlayClick'	:	false,
			'centerOnScroll'		:	true
		});
		
	}

});



function initExtranet()
{
	//en cas de multi ancres / retour à une seule ancre (multi navigateurs / pour validation des formulaires multibox)
	if(window.top.location.hash	!=	'')
	{
		tmpTab						=	window.top.location.hash.split('#');
		if(tmpTab.length > 2)
			window.top.location			=	'http://'+window.top.location.host+window.top.location.pathname+'#'+tmpTab[1];
	}
	
	//execution d'un Init Spécifique -> passé par le biais d'un Hidden
	if(document.getElementById('jsLaunch') && document.getElementById('jsLaunch').value != "")
		eval(document.getElementById('jsLaunch').value+'()');
		
	//Menu gauche, Roll Over
	/*if(document.getElementById('menuExtranet'))
	{
		a =	document.getElementById('menuExtranet').getElementsByTagName('a'); 
		if (a.length > 0) 
		{
			for (i = 0; i < a.length; i++)
			{
				a[i].onmouseover = function(){
					if(this.id == '')
					{
						reg 	= /.+\/(.+)\.php/;
						res		=	reg.exec(this.href);
						this.style.backgroundImage = 'url(../images/menu-'+res[1]+'.gif)';
					}
				}
				a[i].onmouseout = function(){
					if(this.id == '')
					{
						reg 	= /.+\/(.+)\.php/;
						res		=	reg.exec(this.href);
						this.style.backgroundImage = 'url(../images/menu-'+res[1]+'-nb.gif)';
					}
				}
			}
		}
	}*/
	
	
}


//Mon Compte
function initMessagerie()
{
	TR = document.getElementById('tblMessagerie').getElementsByTagName('tr');
	if (TR.length > 0) 
	{
		for(i= 0 ; i < TR.length ; i++)
		{
			if(TR[i].id.indexOf('ln') != -1)
			{
				TR[i].onmouseover = function(){
					TD  = document.getElementById(this.id).getElementsByTagName('td');
					if (TD.length > 0) 
						for(j= 0 ; j < TD.length ; j++)
							TD[j].style.backgroundColor = '#F2F2F2';
					
				}
				TR[i].onmouseout = function(){
					TD  = document.getElementById(this.id).getElementsByTagName('td');
					if (TD.length > 0) 
						for(j= 0 ; j < TD.length ; j++)
							TD[j].style.backgroundColor = '#FFF';
				}
			}
		}
	}
}


// JavaScript Document
function	checkLogin(obj)
{
	if (obj.login.value != "" && obj.pass.value != "")
		return true;
	return false;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}


function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

var httpReponse = '';

function	ajax(nameScript,data,nameFunction)
{
	var xhr_object	= null;
	
	if(window.XMLHttpRequest)		// Firefox 
		xhr_object = new XMLHttpRequest();
	else if(window.ActiveXObject) 	// Internet Explorer 
	      xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	if (xhr_object != null)
	{
		xhr_object.open("POST", nameScript, true);
		if (nameFunction && nameFunction != '' && nameFunction != undefined)
		{
			//alert(nameFunction);
			xhr_object.onreadystatechange = function()
			{ 
				if(xhr_object.readyState == 4)
				{
					httpReponse = xhr_object.responseText;
					eval(nameFunction + '();')
				}
			}
		}
		xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xhr_object.send(data);
	}
	else
		nameFunction('noAjax');
}

function show(val,id)
{
	if(document.getElementById(id))
		obj = document.getElementById(id).innerHTML = unescape(val);
}


function	updatePage()
{
	document.getElementById('candiType').innerHTML = httpReponse;
}

function	updateDataCandidatType()
{
	ajax('aj_getTableCandidatType.php', '', 'updatePage');
}

var conciergerie = {
	
	_base16: "0A12B34C56D78E9F",
	_baseClassName:"observatoire",

	encode: function (str)
	{
		var retour = "";
		
		for(var i = 0; i < str.length; i++)
		{
			var cc = str.charCodeAt(i);
			var ch = cc >> 4;
			var cl = cc - (ch * 16);

			retour += this._base16[ch] + this._base16[cl];
		}
		return _baseClassName + retour;
	},

	decode: function (str)
	{
		var retour = "";
		
		for(var i = 0; i < str.length; i += 2)
		{
			var ch = this._base16.indexOf(str.charAt(i));
			var cl = this._base16.indexOf(str.charAt(i + 1));
			retour += String.fromCharCode((ch * 16) + cl);
		}
		return retour;
	},
	
	init: function ()
	{
		var tagsA = document.getElementsByTagName("span");
		var regHttpMatch	= /^https?:\/\/.+$/;
		var regGoToSite		= /^.+go_site_enseigne.php.+$/;
		
		for(var i = 0; i < tagsA.length; i++)
		{
			if (tagsA[i].className.substring(0, this._baseClassName.length) == this._baseClassName)
			{
				var url		= this.decode(tagsA[i].className.substring(this._baseClassName.length));
				var nlink	= document.createElement("a");
				nlink.href	= url;

				if (tagsA[i].getAttribute('classLnk'))
					nlink.className = tagsA[i].getAttribute('classLnk');
					
				if (tagsA[i].getAttribute('classId'))
					nlink.setAttribute('id', tagsA[i].getAttribute('classId'));
					
				if (tagsA[i].getAttribute('title'))
					nlink.setAttribute('title', tagsA[i].getAttribute('title'));
					
				if (tagsA[i].getAttribute('gotoEns'))
				{
					refIdenseigne = tagsA[i].getAttribute('gotoEns');
					nlink.setAttribute('onclick', 'return gstAddVisSite(' + refIdenseigne + ');');
				}
					
				if (url.match(regHttpMatch) || url.match(regGoToSite))
					nlink.setAttribute('target','_blank');
					
				var nbl		= tagsA[i].childNodes.length;
				
				for(var j = 0; j < nbl; j++)
				{
					nlink.appendChild(tagsA[i].childNodes[0]);
				}
				tagsA[i].appendChild(nlink);
				
				
			}
		}
	}	
}



