
//*****************************************************
//*************  DW USUAL FONCTIONS   *****************
//*****************************************************
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);


//*****************************************************
//*************  ROLL OVER NAV   **********************
//*****************************************************
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_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_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];}
}

//*****************************************************
//*************  AFFICHER/MASQUER CALQUES  ************
//*****************************************************
function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

//*****************************************************
//*************  POP UP   **********************
//*****************************************************
function openwin(cible) {
  window.open(cible,'popup','resizable=no,scrollbars=yes,width=740,height=550,left=100')
//, 'width=740,height=510,location=no,status=no,toolbar=no,scrollbars=yes'
}

//*****************************************************
//**********  ENREGISTRER SOUS HTML ou EXCEL **********
//*****************************************************
function openSaveWindow(action, calculator) {
  var content = document.getElementById('content').innerHTML;
  content = content.replace(/#666666/g, '#AAAAAA');
  var selectId = (calculator == 'passthru' ? 'description' : 'productCode');
  content = replaceHtmlControlByValue(content, selectId, 'select');
  content = replaceHtmlControlByValue(content, 'dailyServings', 'input');
  content = replaceHtmlControlByValue(content, 'daysMenuedPerMonth', 'input');
  
  if (action == 'html') 
  {
    var myWindow = window.open('about:blank', 'saveWindow', 'resizable=no,scrollbars=yes,width=500,height=500,left=40,top=40');
    myWindow.document.writeln('<html><head><title>McCain 4 Schools: Save calculation</title></head>');
    myWindow.document.writeln('<body>');
    myWindow.document.writeln(content);
    myWindow.document.writeln('</body></html>');
    myWindow.document.close();
    myWindow.document.execCommand('SaveAs', true, 'http://www.mccain4schools.com/pages/calculation.html');
    myWindow.close();
  } 
  else if (action == 'excel') {    
  	document.excelForm.buffer.value = content;
    document.excelForm.submit();
  }
}

function replaceHtmlControlByValue(inputText, controlId, controlType) {
	var htmlControl = document.getElementById(controlId);
    var searchText = htmlControl.outerHTML;
    var replaceText;
    if (controlType == 'select')
      replaceText = htmlControl.options[htmlControl.selectedIndex].text;
    else
      replaceText = htmlControl.value;
      
    return inputText.replace(searchText, replaceText);
}


function changeProduct() {
	var list = document.getElementById('description');
	//var myOption = list.options[list.selectedIndex];
	var productCodeTD = document.getElementById('productCode');
	//var legendDiv1 = document.getElementById('legend1');
	//var legendDiv2 = document.getElementById('legend2');
	
	//productCodeTD.innerText = myOption.value;
	
	//if (myOption.snack == "yes") {
	//	legendDiv1.innerText = ""
	//	legendDiv2.innerText = "Lbs of Cheese"
	//}
	//else {
	//	legendDiv1.innerText = "Pounds of Commodity A232 Diversion Needed For:"
	//	legendDiv2.innerText = "Lbs of Raw A232"
	//}
}



function changeProduct_usage() {
	var list = document.getElementById('description');
	var myOption = list.options[list.selectedIndex];
	var productCodeTD = document.getElementById('productCode');

	
	productCodeTD.innerText = myOption.value;
	
	
}

//*****************************************************
//**********       TOGGLE TABS               **********
//*****************************************************

function toggleOn(menuName) {
var el = document.getElementById(menuName);
el.style.display = 'block';
}

function toggleOff(menuName) {
var el = document.getElementById(menuName);
el.style.display = 'none';
}

//This function handles changing the highlighted tab on  the Product_details page
//@param lnkobj as object- the tab object just clicked
//@param tabToToggle as String- the tab to either turn on or off
function chgcolor(lnkobj, tabToToggle){
		
		var tab = document.getElementById(tabToToggle)	//this object is the tab we are to turn on or off		
		var str = tab.className;
		
		str = str.substring(str.length, str.length - 6); 
		//if the toggle tab is already active and is not the tabclicked, turn it off.
		if((str == 'Active') && !(lnkobj.id == tabToToggle))
		{
			str = tab.className;
			tab.className = str.substring(str.length - 6, 0);
		}	
		//if the toggle tab is already active and is the clicked tab , leave it on...
		else if((str == 'Active') && (lnkobj.id == tabToToggle))
		{
			str = tab.className;
			str = str.substring(str.length - 6, 0);
			tab.className = str + 'Active';	
		}
		//if the toggle tab is not active and is the clicked tab , turn it on...
		else if(!(str == 'Active') && (lnkobj.id == tabToToggle))
		{
			str = tab.className;
			tab.className = str + 'Active';	
		}
		//if the toggle tab is not active and is not the clicked tab then do nothing...	
		
}



//*****************************************************
//**********       PRINT ZONE                **********
//*****************************************************

function imprime_zone(titre, obj) 

{
// Define the impression area
var zi = document.getElementById(obj).innerHTML;
zi = zi.replace(/none/, "block")
zi = zi.replace("id=print","id='print' style='display:none;'")

var Headers = '<!DOCTYPE HTML PUBLIC ><HTML><HEAD><link rel="stylesheet" type="text/css" href="../styles/print.css" /></HEAD><BODY onload="window.print();window.close()">';
var Footers = "</body></html>";

// Open a new Window
var f = window.open("", "ZoneImpr", "height=500, width=600,toolbar=0, menubar=0, scrollbars=1, resizable=1,status=0, location=0, left=10, top=10");

// Define page style
f.document.body.style.color = '#000000';
f.document.body.style.backgroundColor = '#FFFFFF';
f.document.body.style.padding = "10px";
f.document.body.style.fontFamily = "Arial, Helvetica, sans-serif";
f.document.body.style.fontSize = "11px";
f.document.body.style.lineHeight = "11pt";
f.document.body.style.verticalAlign = "top";


// Add datas
f.document.write ("" + Headers + zi +Footers);
f.document.close();
return;

}