﻿function CheckControlValidated(controlToClickClientID, controlEvent)
{
	var key = 0;
	var returnValue;
	
	if (window.event) 
	{ 
		key = event.keyCode;
	} 
	else if (controlEvent)
	{ 
		key = controlEvent.which;
	}
	
	if (key == 13) 
	{
		document.getElementById(controlToClickClientID).click();
		returnValue = false;
	} 
	else 
	{
		returnValue = true;
	}
	
	if (window.event) 
	{ 
		event.returnValue = returnValue;
	}
		
	return returnValue;	
}
		
function breakIFrames()
{
	if (top.frames.length != 0) 
		top.location = self.document.location;
}

function reloadIFrame(frameName)
{
	top.frames[frameName].location = top.frames[frameName].location;
}

function changeIFrame(frameName, frameUrl)
{
	top.frames[frameName].location = frameUrl;
}

function PrintArticleContents(p_divContents1, p_divContents2, p_title)
{ 
    var v_contents = new String();
    v_contents = v_contents.concat('<html xmlns="http://www.w3.org/1999/xhtml" >');
    v_contents = v_contents.concat('<head><title> VISIOPLAINE - ');
    v_contents = v_contents.concat(p_title);
    v_contents = v_contents.concat('</title><link rel="stylesheet" href="/includes/style.css">');
    v_contents = v_contents.concat('<script language="javascript" type="text/javascript" src="/includes/script.js"></script></head>');
    v_contents = v_contents.concat('<body>');
    v_contents = v_contents.concat('<a href="javascript:window.print();"><img src="/images/picto_imprimer.gif" border="0"></a>&nbsp;&nbsp;&nbsp;Imprimer cette page<br>');
    v_contents = v_contents.concat(p_divContents1);
    v_contents = v_contents.concat(p_divContents2);
    v_contents = v_contents.concat('</body></html>');
    
    //ouvre la fenêtre en pop-up
    var v_printWindow = window.open('','printwin','width=800,height=600,scrollbars=yes');
    
    //peuple la fenêtre avec les contenus de l'impression
    v_printWindow.document.write(v_contents);
    v_printWindow.document.close();
    
    //met la fenêtre en premier plan
    v_printWindow.focus();
}

function PrintMarge(p_divContents1, style)
{ 
    var v_contents = new String();
    v_contents = v_contents.concat('<html xmlns="http://www.w3.org/1999/xhtml" >');
    
    if (style == 'EMC2')
        v_contents = v_contents.concat('<head><title></title><link rel="stylesheet" href="/includes/emc2.css"></head>');
    else if (style == 'AGRI3D')
        v_contents = v_contents.concat('<head><title></title><link rel="stylesheet" href="/includes/agri3D.css"></head>');
    else
        v_contents = v_contents.concat('<head><title></title><link rel="stylesheet" href="/includes/style.css"></head>');
    
    v_contents = v_contents.concat('<body>');
    v_contents = v_contents.concat('<a href="javascript:window.print();"><img src="/images/picto_imprimer.gif" border="0"></a>&nbsp;&nbsp;&nbsp;Imprimer cette page<br /><br />');
    v_contents = v_contents.concat(p_divContents1);
    v_contents = v_contents.concat('</body></html>');
    
    //ouvre la fenêtre en pop-up
    var v_printWindow = window.open('','printwin','width=750,height=600,scrollbars=yes');
    
    //peuple la fenêtre avec les contenus de l'impression
    v_printWindow.document.write(v_contents);
    v_printWindow.document.close();
    
    //met la fenêtre en premier plan
    v_printWindow.focus();
}

function owPAC()
{
  //Alert temporaire 
  //alert('Service disponible en Avril');
    //return;

	// Ouvre la fenêtre en pop-up
	var openWindow = window.open('/workspace/reports/owPAC.aspx?WorkspaceDate=' + document.getElementById('ctl00_SubMenuServiceUserControl__lblWorkspaceDate').innerText,'PAC','width=400,height=250,scrollbars=yes');

	// Met la fenêtre en premier plan
	openWindow.focus();	
}

function owHelp()
{
	// Ouvre la fenêtre en pop-up
	var openWindow = window.open('/help/default.aspx?PopUp=true', 'HELP','width=800,height=650,scrollbars=yes');

	// Met la fenêtre en premier plan
	openWindow.focus();	
}


function owZoom(productPath)
{
	// Ouvre la fenêtre en pop-up
	var url = '/catalogs/owzoom.aspx?ProductPath=' + productPath;
	var openWindow = window.open(url, 'ZOOM','width=400,height=500,scrollbars=yes');

	// Met la fenêtre en premier plan
	openWindow.focus();	
}

function owPPF()
{
 // Ouvre la fenêtre en pop-up
 var openWindow = window.open('/workspace/reports/owPPF.aspx?WorkspaceDate=' + document.getElementById('ctl00_SubMenuServiceUserControl__lblWorkspaceDate').innerText,'PPF','width=400,height=250,scrollbars=yes');

 // Met la fenêtre en premier plan
 openWindow.focus(); 
}

function SetFocus(ctrlid)
{
    //Place le focus sur le controle dont l'id est passé en paramètre
    document.getElementById(ctrlid).focus();
}

// On remplace le point par la virgule à la saisie.
function ReplacePointByComas(e)
{
  var key = window.event ? e.keyCode : e.which;
	var keychar = String.fromCharCode(key);

  if (keychar == '.')
  {
    e.keyCode = 44;
    e.which = 44;
  }
  return keychar;

}

function RedirectTopPage(redirectUrl) 
{
    top.location = redirectUrl; 
}