﻿var ns4 = (document.layers)? true:false;// Navigateur Netscape 4.X
var ie4 = (document.all)? true:false;// Navigateur IE 4 uniquement
var dom = (document.getElementById)? true:false;// Navigateur qui supporte DHTML officiel(DOM)
var ns6= document.getElementById&&!document.all;
var firefox = (navigator.userAgent.indexOf("Firefox")!=-1)?true:false;
var fenMouseX = 0, fenMouseY = 0;
var docMouseX = 0, docMouseY = 0;


// Gerer le focus des boites de recherche avance et expres.
// BT #2524
function toggleSearchBoxFocus(toggle)
{
    var searchBoxesIDs = new Array ("ucAdvanced_txbKeyWords", "ucSpecialized_txbKeyWords");
		
	for (var i in searchBoxesIDs)
	{
	    if (document.getElementById(searchBoxesIDs[i]))
	    {
	        if (toggle)
	            document.getElementById(searchBoxesIDs[i]).focus();
	        else
	            document.getElementById(searchBoxesIDs[i]).blur();
	    }
	}
};

function afficheCalque(calque) 
{ 
	if (dom) 
	{
	    document.getElementById(calque).style.display = 'inline';
	    document.getElementById(calque).style.zIndex = 200;
	}
	else if (ns4) 
	{ 
		layerRef="document.layers"; 
		styleRef=""; 
		eval(layerRef + '["' + calque +'"]' + styleRef + '.display = "inline"'); 
	} 
	else if (ie4) 
	{ 
		layerRef="document.all"; 
		styleRef=".style"; 
		eval(layerRef + '["' + calque +'"]' + styleRef + '.display = "inline"'); 
	}

	// Fix IE6 overlapping form elements
	if (document.all)
	{
		// Split the string into part [0] and part [1]
		temp=navigator.appVersion.split('MSIE');
		// Parse the string for the "6" in 6.0
		ieVer=parseInt(temp[1]);
		// Is it greater than 6?
		var isIE6=(ieVer == 6)?1:0;		
		if ( isIE6 && document.getElementById('ucAdvanced_ddlCriteriaKey1') != null)
		{
			document.getElementById('ucAdvanced_ddlCriteriaKey1').style.display = "none";
			document.getElementById('ucAdvanced_ddlCriteriaKey2').style.display = "none";
			document.getElementById('ucAdvanced_ddlCriteriaKey3').style.display = "none";	
			document.getElementById('ucAdvanced_ddlDateRanges').style.display = "none";	
		}
		if ( isIE6 && document.getElementById('ucSpecialized_txbStartDay') != null)
		{
			document.getElementById('ucSpecialized_txbStartDay').style.display = "none";	
			document.getElementById('ucSpecialized_ddlStartMonth').style.display = "none";	
			document.getElementById('ucSpecialized_ddlStartYear').style.display = "none";	
			
			document.getElementById('ucSpecialized_txbEndDay').style.display = "none";	
			document.getElementById('ucSpecialized_ddlEndMonth').style.display = "none";	
			document.getElementById('ucSpecialized_ddlEndYear').style.display = "none";							
		}
    }
	
//	if (dom)
//	    toggleSearchBoxFocus(false);	
}  

function cacheCalque(calque) 
{ 
	if (dom) 
	{ 
		document.getElementById(calque).style.display='none';
	}
	else if (ns4) 
	{ 
		layerRef="document.layers"; 
		styleRef=""; 
		eval(layerRef + '["' + calque +'"]' + styleRef + '.display = "none"'); 
	} 
	else if (ie4) 
	{ 
		layerRef="document.all"; 
		styleRef=".style"; 
		eval(layerRef + '["' + calque +'"]' + styleRef + '.display = "none"'); 
	} 
		
	// Fix IE6 overlapping form elements
	if (document.all)
	{
		// Split the string into part [0] and part [1]
		temp=navigator.appVersion.split('MSIE');
		// Parse the string for the "6" in 6.0
		ieVer=parseInt(temp[1]);
		// Is it greater than 6?
		var isIE6=(ieVer == 6)?1:0;		
		if ( isIE6 && document.getElementById('ucAdvanced_ddlCriteriaKey1') != null)
		{
			document.getElementById('ucAdvanced_ddlCriteriaKey1').style.display = "inline";
			document.getElementById('ucAdvanced_ddlCriteriaKey2').style.display = "inline";
			document.getElementById('ucAdvanced_ddlCriteriaKey3').style.display = "inline";				
			document.getElementById('ucAdvanced_ddlDateRanges').style.display = "inline";				
		}
		if ( isIE6 && document.getElementById('ucSpecialized_txbStartDay') != null)
		{
			document.getElementById('ucSpecialized_txbStartDay').style.display = "inline";	
			document.getElementById('ucSpecialized_ddlStartMonth').style.display = "inline";	
			document.getElementById('ucSpecialized_ddlStartYear').style.display = "inline";	

			document.getElementById('ucSpecialized_txbEndDay').style.display = "inline";	
			document.getElementById('ucSpecialized_ddlEndMonth').style.display = "inline";	
			document.getElementById('ucSpecialized_ddlEndYear').style.display = "inline";	
		}
    }
	
//	if (dom)
//	    toggleSearchBoxFocus(true);	
}


//-------------------------------------------------------------------------
// Ouverture d'une nouvelle page Window qui sera centré selon la résolution
//-------------------------------------------------------------------------
function MM_openBrWindow(theURL,winName,iWidth,iHeight,features)
{
	var iPosWidth = Math.round((screen.width-iWidth)/2);
	var iPosHeight = Math.round((screen.height-iHeight)/2);

	window.open(theURL,winName,features+",width="+iWidth+",height="+iHeight+",screenX="+iPosWidth+",screenY="+iPosHeight+",left="+iPosWidth+",top="+iPosHeight);
}


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_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];}
}

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 decodeURI(str)
{
    return str.replace(/\&lt\;/g, '<').replace(/\&gt\;/g, '>').replace(/\&quot\;/g, '"').replace(/\&amp\;/g, "&");
}

function FullScreen(text, stylesheetLink)
{
	Msg = null;
	var iWidth = 550
	var iHeight=425;
	var iPosWidth = Math.round((screen.width-iWidth)/2);
	var iPosHeight = Math.round((screen.height-iHeight)/2);
	Msg = window.open("about:blank", "_blank","width=550,height=425,menubar=no,resizable=yes,scrollbars=yes,status=no,titlebar=no,toolbar=no,top=" + iPosHeight +",left=" + iPosWidth);
	Msg.document.writeln("<html><HEAD><title>" + document.location.hostname +"</title>");
	Msg.document.writeln("<link href=\"" + stylesheetLink +"\" rel=\"stylesheet\" type=\"text/css\"><style>body{overflow:auto;font-family:Verdana,Arial,Helvetica,sans-serif;background-color:#FFFFFF;margin: 3px 0px 0px 0px;}</style>");
	Msg.document.writeln("<script>function Stubs(Text){var target = window.open('search/stubs.aspx?Text=' + escape(Text),'Stubs','top=50,left=35,width=525,height=470,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes');target.focus();}</script></HEAD>");	
	Msg.document.writeln("<body>");
	Msg.document.writeln("<center>" +text +"</center>");
	Msg.document.writeln("</body></html>");
	Msg.document.close();
	Msg.focus();
}

function Check(prefixNameField, Count)
{		
	for (i = 0; i < Count; i++) 
	{
		var id = prefixNameField +'_' +i
		var obj = document.getElementById(id) ;			
		
		if(obj)
			obj.checked = true;	
	}
}

function UnCheck(prefixNameField, Count)
{		
	for (i = 0; i < Count; i++) 
	{
		var id = prefixNameField +'_' +i
		var obj = document.getElementById(id) ;			
		
		if(obj)
			obj.checked = false;	
	}
}

function OnKeyPressEnterSubmit(Id, evenement)
{
	var touche = window.event ? evenement.keyCode : evenement.which;
	//Le Id doit être celui d'un boutton pour exécuter son événement "click"
	var obj = document.getElementById(Id) ;	
	
	if (touche == 13)
	{		
		if(obj)
			obj.click();		
		return false;
	}
	else
		return true;	
}

String.prototype.format = function()
{
    var str = this;

    for(var i=0;i<arguments.length;i++)
    {
        var re = new RegExp('\\{' + (i) + '\\}','gm');
        str = str.replace(re, arguments[i]);
    }
    return str;
}

function getSelectedRadioValue (radioButton)
{  
	var returnValue = "";        
	if (radioButton.length == 1)
		returnValue = radioButton.value;	 
	else 
	{   	      
		for (i = 0;i < radioButton.length; i++)
		{                			
			if (radioButton[i].checked == true) 
				returnValue = radioButton[i].value;
		}        
	}        
	return returnValue;    
}

function getMousePositionXY(evt)
{	
	fenMouseX = evt.clientX ;
	docMouseX = fenMouseX + document.body.scrollLeft;

	fenMouseY = evt.clientY;
	docMouseY = fenMouseY + document.body.scrollTop;
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.name != 'aspnetForm' ? obj.offsetLeft : 0;
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.name != 'aspnetForm' ? obj.offsetTop : 0;
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function isEmpty(value) { return "undefined" === typeof value || undefined === value || null === value || "" === value; };

function SaveContent(ctrlID, url) {
    if (isEmpty(ctrlID)) ctrlID = 'btnSave';
    if (isEmpty(url)) url = location.href;

    url = url.replace(/DocActionType=2/i, "DocActionType=3");

    var frmSave = document.getElementById("frmSave");

    if (null != frmSave) {
        frmSave.target = "_self";
        frmSave.method = "post";
        frmSave.action = url;
        frmSave.submit();
    }
};

function OpenNGOnline(url, errMess) {
    if (url) {
        winNG = window.open(url, '_blank');
        if (winNG) winNG.focus();
    }
    else if (errMess) {
        alert(errMess);
    }
};