// JavaScript Document

var VRWindow ; // needs to be a global variable
var w ; 

function makeBig()
{
  window.moveTo(0,0);
  window.resizeTo(screen.availWidth,screen.availHeight);
}

function openNewWindowX(url) 
{
  //newWindow=window.open(url,'piagetfull', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=900,height=740,left = 400,top = 4000');
  var wid = screen.availWidth;
  var hei = screen.availHeight ;
  if(newWindow == null || newWindow.closed)
{
//  newWindow=window.open(url,'jetflyfull', //'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width='+wid+',height='+hei+',left=0,top=0');
  newWindow=window.open(url,'fullwindow','toolbar=0, scrollbar=1, location=0,statusbar=0,menubar=0,resizable=0,width='+wid+',height='+hei+',left=0,top=0');
  }
  else if(!newWindow.closed)
{
newWindow.focus();
}
  //newWindow.moveTo(0,0);
  //newWindow.resizeTo(screen.availWidth,screen.availHeight);
}

function openVRWindow(url) 
{
  //newWindow=window.open(url,'piagetfull', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=900,height=740,left = 400,top = 4000');
  var hpos = Math.round(screen.availWidth/2)  - 500;
  var vpos = 150;
if(VRWindow == null || VRWindow.closed)
{
 VRWindow=window.open(url,'VR', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=1000,height=465,left='+hpos+',top='+ vpos+'');
}
else if(!VRWindow.closed)
{
VRWindow.focus();
}
}

function getQuery(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  } 
//  alert('Query Variable ' + variable + ' not found');
}

function resize() {
var forcesize = new SWFForceSize(so, 955, 755 );
}

function appelFlash(str,cmd_id) {
document.getElementById("poilane").retourjs(str,cmd_id);	
}


function getFlashMovie(movieName) {
  var isIE = navigator.appName.indexOf("Microsoft") != -1;
  return (isIE) ? window[movieName] : document[movieName];
 }


function updateNewsAll() {
	updateNews("fr");
	updateNews("en");
}


function updateNews(lang) {
var form = document.getElementById("formnews"); 
var tarea = form["titre_" + lang];
var titre = nl2br(tarea.value);
tarea = form["accroche_" + lang];
var accroche = nl2br(tarea.value);
//var flash = document.getElementById("newsflash");
//sonews.call('updateflashnews','test');
//document.getElementById("newsflash").
var flash = getFlashMovie("ardoise_"+lang);
flash.update(titre,accroche);
//updateflashnews('test','test');
}


function openpayment_bk(url,args) {
//alert("testing");
//testing
//url = "pages/pop_paiement.php"; 
//ags= "n=";
var message  = "A popup-blocker was detected!";
message += " Please click the link to try again.";
var wid = 750;
var maxwid  = screen.availWidth;
var le = maxwid/2 - wid/2;
var hei = 650;
var maxhei = screen.availHeight;
if (hei > maxhei ) { hei = maxhei; }
popupProp = "fullscreen=no, toolbar=no, scrollbar=yes, location=yes, width="+ wid + ", height=" + hei  + ", top=50, left=" +  le  + " ";

w = window.open(url +"?" + args, 'payment', popupProp);
if(!w) { // popup was blocked
document.getElementById("poilane").retourjs('popup_blocked',0);
}
else {
w.focus();	
}
}

function openpayment() {
//alert("testing");
//testing
url = "pages/pop_paiement.php"; 
//ags= "n=";
var message  = "A popup-blocker was detected!";
message += " Please click the link to try again.";
var wid = 750;
var maxwid  = screen.availWidth;
var le = maxwid/2 - wid/2;
var hei = 650;
var maxhei = screen.availHeight;
if (hei > maxhei ) { hei = maxhei; }
popupProp = "fullscreen=no, toolbar=no, scrollbar=yes, location=yes, width="+ wid + ", height=" + hei  + ", top=50, left=" +  le  + " ";
w = window.open(url, 'payment', popupProp);
if(!w) { // popup was blocked
document.getElementById("poilane").retourjs('popup_blocked',0);
}
else {
w.focus();	
}
}


function openpop(url,lang) {
//alert("testing");
//testing
//url = "pages/pop_paiement.php"; 
//ags= "n=";
if (lang == "en") {
var message  = "A popup-blocker was detected!";
message += " Please allow popups for poilane.fr.";
}
else {var message  = "Un bloqueur de fenetres a été détecté. Vous devez autoriser Poilane.fr"; }
var wid = 500;
var maxwid  = screen.availWidth;
var le = maxwid/2 - wid/2;
var hei = 550;
var maxhei = screen.availHeight;
if (hei > maxhei ) { hei = maxhei; }
popupProp = "fullscreen=no, toolbar=no, scrollbars=yes, location=yes, width="+ wid + ", height=" + hei  + ", top=50, left=" +  le  + " ";
w = window.open(url, 'breadclub', popupProp);
if(!w) { // popup was blocked
alert(message);
//document.getElementById("poilane").retourjs('popup_blocked',0);
}
else {
w.focus();	
}
}

function openrecette(id, lang) {
//alert("testing");
//testing
url = "../pop_recettes.php";
//ags= "n=";
if (lang == "en") {
var message  = "A popup-blocker was detected!";
message += " Please allow popups for poilane.fr.";
}
else {var message  = "Un bloqueur de fenetres a été détecté. Vous devez autoriser Poilane.fr"; }
var wid = 550;
var maxwid  = screen.availWidth;
var le = maxwid/2 - wid/2;
var hei = 680;
var maxhei = screen.availHeight;
if (hei > maxhei ) { hei = maxhei; }
popupProp = "resizable=yes, toolbar=yes, width="+ wid + ", height=" + hei  + ", top=50, left=" +  le  + " ,scrollbars=yes";
w = window.open(url + "?id=" + id + "&lang=" + lang, 'breadclub', popupProp);
if(!w) { // popup was blocked
alert(message);
//document.getElementById("poilane").retourjs('popup_blocked',0);
}
else {
w.focus();	
}
}


function opensudoku(lang) {
//alert("testing");
//testing
url = "../pop_sudoku.php"; 
//ags= "n=";
if (lang == "en") {
var message  = "A popup-blocker was detected!";
message += " Please allow popups for poilane.fr.";
}
else {var message  = "Un bloqueur de fenetres a été détecté. Vous devez autoriser Poilane.fr"; }
var wid = 650;
var maxwid  = screen.availWidth;
var le = maxwid/2 - wid/2;
var hei = 600;
var maxhei = screen.availHeight;
if (hei > maxhei ) { hei = maxhei; }
popupProp = "fullscreen=no, toolbar=no, scrollbar=true, location=yes, width="+ wid + ", height=" + hei  + ", top=50, left=" +  le  + " ";
w = window.open(url + "?lang=" + lang, 'breadclub', popupProp);
if(!w) { // popup was blocked
alert(message);
//document.getElementById("poilane").retourjs('popup_blocked',0);
}
else {
w.focus();	
}
}

function checkPaymentWindow(order_ID) {
	if(!w) {appelFlash('windowClosed',order_ID);} //fenetre fermée;
}

function nl2br(string)
{
temp = string.replace(/\r/g,'');
return temp.replace(/\n/g,'<br />');
}

function br2nl(string) {
return temp.replace(/<br \/>/g,'\r\n');
}

// conteneur = id du bloc (<div>, <p> ...) contenant les checkbox
// a_faire = '0' pour tout décocher
// a_faire = '1' pour tout cocher
// a_faire = '2' pour inverser la sélection

function GereChkbox(conteneur, a_faire) {

var blnEtat=null;
var i = 0;
var Chckbox = document.getElementById("checkbox_"+ conteneur + "_" +i);
//alert(document.getElementById("checkbox"+conteneur+i));
	while (Chckbox!=null) {
		blnEtat = (a_faire=='0') ? false : (a_faire=='1') ? true : (Chckbox.checked) ? false : true;
		Chckbox.checked=blnEtat;
		i++;
		Chckbox = document.getElementById("checkbox_"+ conteneur + "_" + i);
	}
}

function executeChkbox(conteneur, params) {

var blnEtat=null;
var i = 0;
var list="";
var Chckbox = document.getElementById("checkbox_"+conteneur+"_"+i);
	while (Chckbox!=null) {
		if (Chckbox.checked == true) {
		list += Chckbox.value + "-";
		}
		i++;
		Chckbox = document.getElementById("checkbox_"+conteneur+"_"+i);
	}
	
	window.location.href="admin_commandes.php?" + params + "&ID="+ list;
}