/**
 * App
 * @author	 		mel
 * Date created: 	25-04-2006 21:00 
 * Date revised: 	27-09-2006 13:58
*/

var App = {
	
	/**
	 * 
	*/
	Page: {
		
		createAccessiblePopupLinks:function (){
			var a = App.getElementsByClassName(document,"popup");
			var dims = {
			    popup:{w:710,h:560},
			    readmore:{w:300,h:300},
			    def:{w:100,h:100},
			    conditions:{w:800,h:800}
			};
			var currentDims;
			for(var i=0; i<a.length; i++){
				var o=a[i];
				var sHref = o.getAttribute("href");
				o.setAttribute("savedHrefAtt",sHref); // save the href attribute so we can use it in the window.open()
				o.onclick = function (){
					if(sHref != "#" && sHref != ""){
						if(!win){
						    if(App.classContains(o,"popup")){
						        currentDims = "popup";
						    } else if(App.classContains(o,"readmore")){
						        currentDims = "readmore";
						    } else if(App.classContains(o,"conditions")){
						        currentDims = "conditions";
						    } else {
						        currentDims = "def";
						    }
							var win = window.open(this.getAttribute("savedHrefAtt"),"Region H","width="+dims[currentDims].w+",height="+dims[currentDims].h);
						} else {
							win.focus();
						}
						return false; 
					}
				};
			}
		}, // @App.Page.createAccessiblePopupLinks
		
		Stylesheet:{
			initialize:function (){
				//this.buttons();
				//this.disable(document.getElementById("ctl00_ssFontsSmall"));
				if(App.Page.Cookie.read("style") == "largetext"){
					this.disable(document.getElementById("ctl00_ssFontsSmall"));
				}		
			},
			buttons:function (){
				if(document.getElementById("menu-tools")) try { App.getElementsByClassName(document.getElementById("menu-tools"),"link-text-small")[0].onclick = function (){ return App.Page.Stylesheet.changeTo("small"); } } catch(e){ App.Page.Logger.add("stylesheet buttons error"); }
				if(document.getElementById("menu-tools")) try { App.getElementsByClassName(document.getElementById("menu-tools"),"link-text-large")[0].onclick = function (){ return App.Page.Stylesheet.changeTo("large"); } } catch(e){ App.Page.Logger.add("stylesheet buttons error"); }
			},
			changeTo:function(sSize){
				var sHref = "css/fontsSmall.css";
				var o = document.getElementById("ctl00_ssFontsSmall"); // <link id="ss-fonts-large" href="css/fontsLarge.css"...
				if(sSize == "large"){
					if(o){ App.Page.Stylesheet.disable(o); }
					App.Page.Cookie.create("style","largetext",365);
				} else if(sSize == "small"){
					if(o){ App.Page.Stylesheet.enable(o); }
					App.Page.Cookie.create("style","smalltext",365);
				}
				return false; 
			},
			disable:function (o){
				o.disabled = true;
			},
			enable:function (o){
				o.disabled = false;
			}
		}, // @App.Page.Stylesheet
		
		Cookie:{
			create:function(name,value,days){
				if(days){
					var date = new Date();
					date.setTime(date.getTime()+(days*24*60*60*1000));
					var expires = "; expires="+date.toGMTString();
				} else {
					expires = "";
				}
				document.cookie = name+"="+value+expires+"; path=/";
			},
			read:function(name){
				var nameEQ = name + "=";
				var ca = document.cookie.split(';');
				for(var i=0; i<ca.length; i++){
					var c = ca[i];
					while (c.charAt(0)==' ') c = c.substring(1,c.length);
					if(c.indexOf(nameEQ)==0) return c.substring(nameEQ.length,c.length);
				}
				return null;
			}
		}, // @App.Page.Cookie
		
		Print:{
			active:false,
			initialize:function (){
				if(document.getElementById("menu-tools")){
					var oThis = this;
					//alert(":::"+document.getElementById("menu-tools").id)
					var btn = App.getElementsByClassName(document.getElementById("menu-tools"),"link-print");
					if(btn[0]){
						btn.onclick = function (){ 
							oThis.enablePrintPreview();
							oThis.active = true;
							return false;
						}
					}

					if(oThis.oPrintPreview()){
						oThis.oPrintPreview().disabled = true;
					}
					// set the possibility to cancel the printpreview by pressing <ESC>
					document.onkeypress = function(e){
						var code;
						if (!e) var e = window.event;
						if(e.keyCode){
							code = e.keyCode;
						} else if(e.which){
							code = e.which;
						}
						if(code == 27 && oThis.active){
							oThis.disablePrintPreview();
						}
					};
				}
			},
			oPrintPreview:function (){ 
				return document.getElementById("ss-print-preview"); 
			},
			enablePrintPreview:function (){
				App.Page.Print.oPrintPreview().disabled = false;
				document.getElementById("cancel-print-preview").onclick = this.disablePrintPreview;
			},
			disablePrintPreview:function (){
				App.Page.Print.oPrintPreview().disabled = true;
				App.Page.Print.active = false;
				return false;
			}
		}, // @App.Page.Print
	
		start:function (){

			App.Page.Print.initialize();
			App.Page.Stylesheet.initialize();
			//App.Page.createAccessiblePopupLinks();
			

		} // @App.Page.start
				
	} // @App.Page
} // @App

