﻿
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

function addResizeEvent(func) {
  var oldonresize = window.onresize;
  if (typeof window.onresize != 'function') {
    window.onresize = func;
  } else {
    window.onresize = function() {
      if (oldonresize) {
        oldonresize();
      }
      func();
    }
  }
}

function add_print_link( id ){
  if( !document.getElementById ||
      !document.getElementById( id ) ) return;
  // add extra functions to page tools list
  var print_page = document.getElementById( id );
  // create print link
  var print_function = document.createElement('p');
  print_function.className = 'print-link';
  print_function.onclick = function(){ print_preview(); return false; };
  print_function.appendChild( document.createTextNode( 'Print the Page' ) );
}

function print_preview() {
	collapseNavCells()	
	setActiveStyleSheet('Print Preview');
	noPrint();
}

function print_button() {
	  //print_preview()
	  window.print();
	  //normalView();
}
function cancel_print_preview() {
      expandNavCells();   	
	menuDisplay(0,1) ;
	menuDisplay(getMenuByName("Side Menu"),1) ;
   	drawMenus();

	// Switch back stylesheet
	setActiveStyleSheet('Default');
	
	normalView();	
   	// draw necessary for non-event inititated showfloaties
}

function setActiveStyleSheet(title) {
   var i, a, main;
   for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
     if(a.getAttribute("rel").indexOf("style") != -1
        && a.getAttribute("title")) {
       a.disabled = true;
       if(a.getAttribute("title") == title) a.disabled = false;
     }
   }
   redrawAll();
}

function redrawAll() {
	var preview
	preview = isPreview();
   //alert(sheets);
   if (preview == true) { 
   	hideFloaties() ;
   } else {
   	showFloaties() ;
   }
   sizeMain;   

}
function isPreview() {
   var i, a, main, preview, sheets;
   preview = false;
   for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
     if(a.getAttribute("rel").indexOf("style") != -1) {       
	       if((a.getAttribute("title") == "Print Preview") && (a.disabled == false)) {preview = true };
	       if((a.getAttribute("title") == "Blank") && (a.disabled == false)) {preview = true };

	       //sheets = sheets + " ===  media is " + a.getAttribute("media") + ", title is " + a.getAttribute("title") + ", disabled is " + a.disabled + ", preview is now " + preview;
     }
   }
	return preview; 	   
} 

function sizeMain() {
	var preview = isPreview, showpx = 988, widepx = 630, highpix = 460; 
	var maintable = document.getElementById("maintable");
	var menus = document.getElementById("maintable");
	if (parseInt(navigator.appVersion)>3) {
		 if (navigator.appName=="Netscape") {
			  widepx = window.innerWidth;
			  highpix = window.innerHeight;
		 }
		 
		 if (navigator.appName.indexOf("Microsoft")!=-1) {
			  widepx = document.body.offsetWidth;
			  highpix = document.body.offsetHeight;
		 }
	}

	if(preview == false) { showpx = 1128 };

	if (widepx >= 1100) {
		maintable.width = showpx;
	}
	if (widepx < 1100) {
		maintable.width = "94%";
	}
	maintable.position = "absolute";
	maintable.left = "2";
	maintable.top = "2";
	maintable.zIndex="999999";
}

function hideFloaties() {
	menuDisplay(0,0) ;
	menuDisplay(getMenuByName("Side Menu"),0) ;
}

function showFloaties() {
	menuDisplay(0,1) ;
	menuDisplay(getMenuByName("Side Menu"),1) ;
}

function collapseNavCells() {
   var i, a, main, bg, contents, sheets, bannerhide, bannermsg ;
   //first do banners (the cells)
   for(i=0; (a = document.getElementsByTagName("td")[i]); i++) {
	     if(a.getAttribute("bgcolor")) {
	     		bg = a.getAttribute("bgcolor").toUpperCase();
	     		contents = a.innerHTML.toUpperCase();
	     		bannerhide = "<div id='bannerheader' class='screenshow'>" + a.innerHTML + "</div>";
	     		bannermsg = "Our Easy-to-Read Print Guide about"; 
	     		if (IsRO == 1) {
	     			bannermsg = "Ghid uşor de citit în versiunea printabilă despre";
	     		}
	     		if ((bg != "#FFFFFF") && (1 > 0)) {
	     			 if(bg == "#004DD6") {
			       	a.innerHTML = bannerhide + "<table class='printshow' id='printmessage' style='height:28px;float:left;'><tr><td><h3 align='right' style='color: #0033CC;'> " + bannermsg + " " + document.title + "</h3></td></tr></table>" ;
			       }
			       if ((bg == "#E3F7FF") && ((contents.indexOf("ROMANA.JPG") > 4) || (contents.indexOf("ENGLISH.JPG") > 4))) {
			       	a.innerHTML = bannerhide + "<h6 class='printshow' align='right' style='float: right;'>(c) 2009 Rest Romania SRL</h6>" ;
			       }
			       a.className = "row4";
			       var whitewash = "#EEFFFA#004DD6#E3F7FF#E2F7FF";
			       if(whitewash.indexOf(bg) >-1) {
					a.style.backgroundColor = "#FFFFFF";		       	
			       }
		       }
	     }
   }
   //secondly do tables
   for(i=0; (a = document.getElementsByTagName("table")[i]); i++) {
   		var bgcolor = a.getAttribute("bgcolor");
	     if(bgcolor) {
	     		bg = bgcolor.toUpperCase();
	     		contents = a.innerHTML;
	     		if ((bg != "#FFFFFF") && (1 > 0)) {
	     			if(a.innerHTML.indexOf('bannerheader') == 0) {
		     			 bannerhide = "<div id='bannerheader' class='screenshow'>" + a.innerHTML + "</div>";
				}	
	     			 if(bg == "#004DD6") {
			       	a.innerHTML = bannerhide + "<table class='printshow' id='printmessage' style='height:28px;float:left;'><tr><td><h3 align='right' style='color: #0033CC;'> Our Easy-to-Read Print Guide to " + document.title + "</h3></td></tr></table>" ;
			       }
			       if ((bg == "#E3F7FF") && ((contents.indexOf("ROMANA.JPG") > 4) || (contents.indexOf("ENGLISH.JPG") > 4))) {
			       	a.innerHTML = bannerhide + "<h6 class='printshow' align='right' style='float: right;'>(c) 2009 Rest Romania SRL</h6>" ;
			       }
	     			 //a.className = "row4";
	     			 var whitewash = "#EEFFFA#004DD6#E3F7FF#E2F7FF";
			       if(whitewash.indexOf(bg) >-1) {
					a.style.backgroundColor = "#FFFFFF";		       	
			       }
		       }
	     }
   }
   //alert(sheets);
   //if (preview == true) { hideFloaties() };   
}

function expandNavCells() {
   var i, a, main, bg, id, contents, sheets;
   //preview = false;
   for(i=0; (a = document.getElementsByTagName("td")[i]); i++) {
	     if(a.getAttribute("bgcolor")) {       
	     		bg = a.getAttribute("bgcolor").toUpperCase();
			//alert(a.className + ', ' + a.style.backgroundColor + ', ' +bg);		       	
	     		if ((bg != "#FFFFFF") && (1 > 0)) {
	     			a.className = "";
				a.style.backgroundColor = bg;		       	
		       }
	     }
   }
  var maintable = document.getElementById('maintable') ;
  
   for(i=0; (a = document.getElementsByTagName("div")[i]); i++) {
	     if(a.getAttribute("id")) {       
	     		id = a.getAttribute("id");
			//alert(a.className + ', ' + a.style.backgroundColor + ', ' +bg);		       	
	     		if ((id == "bannerheader") && (1 > 0)) {
	     			var bannerwidth =  (maintable.width - 200);
				a.width = bannerwidth;
				a.style.width = bannerwidth;				
		       }
	     }
   }

} 

function noPrint() {
// removes the content for unregistered users
  isPreview();
  var stop_print = document.getElementById('maincontent');
  stop_print.id = 'printcontent';
  stop_print = document.getElementById('printheader');
  stop_print.id = 'noheader';
  //alert('Printing is disabled');
}


function normalView() {
// removes the content for unregistered users
  isPreview();
  var normal_view = document.getElementById('printcontent');
  normal_view.id = 'maincontent';
  normal_view = document.getElementById('noheader');
  normal_view.id = 'printheader';
}




