String.prototype.trim = function() {
	return this.replace( /^\s+|\s+$/, "" );
};
var EMA=(typeof(EMA)=="undefined")?{Globals:{}}:EMA;
EMA.Globals.Cookies={
	domain:'proximus.be',
	path:'/',
	validity:28,
	secure:false,
	set:function(c){
		/// mga#emakina.com 20071008 writes a value /cookie
		//c.name;c.value;c.validity;c.path;c.domain;c.secure
		var WR='';
		WR+=c.name+"="+c.value;
		WR+=";expires="	+((!c.validity)?new Date(new Date().getTime()+(EMA.Globals.Cookies.validity*1000*60*60*24)).toGMTString():c.validity.toGMTString());
		WR+=";path="	+((!c.path)?EMA.Globals.Cookies.path:c.path);
		WR+=";domain="	+((!c.domain)?EMA.Globals.Cookies.domain:c.domain);
		WR+=(!c.secure)?"":";secure=true";
		document.cookie=WR;
	},
	get:function(name){
		// mga#emakina.com 20040622 retrieves a value from a cookie var 
		var c=document.cookie;
		if (c.indexOf(name)>=0){
			for (var i=0;i<c.split(';').length;i++){
				var cs=c.split(';')[i];
				if (cs.indexOf('=')>0){
					if (cs.split('=')[0].trim()==name){
						return cs.split('=')[1].trim();
					}
				}
			}
		}else{
			return null;
		}
	},
	del:function(){
		// mga#emakina.com 20040622 deletes cookies [all if no param || the ones specified in param]
		var a=EMA.Globals.Cookies.del.arguments;
		var e=new Date(new Date().getTime()-1*1000*60*60*24);
		var c=document.cookie;
		for (var i=0;i<c.split(';').length;i++){
			var cs=c.split(';')[i];
			if (cs.indexOf('=')>0){
				if (a.length>0){
					//cookie name specified, deletes specific cookie
					for (var n=0;n<a.length;n++){
						if (a[n]==cs.split('=')[0].trim()){
							var WR='';
							WR+=cs.split('=')[0].trim()+"=";
							WR+=";expires="+e;
							WR+=";domain="+EMA.Globals.Cookies.domain;
							WR+=";path="+EMA.Globals.Cookies.path;
							document.cookie=WR;
						}
					}
				} else {
					//no cookie name specified, delete all
					var WR='';
					WR+=cs.split('=')[0].trim()+"=";
					WR+=";expires="+e;
					document.cookie=WR;
				}
			}
		}
	}
};
EMA.Globals.addEvent=function (obj, evType, fn){
	//unobstrusive event handler
	if (obj.addEventListener){ 
		obj.addEventListener(evType, fn, false); 
		return true; 
	} else if (obj.attachEvent){ 
		var r = obj.attachEvent("on"+evType, fn); 
		return r; 
	} else { 
		return false; 
	} 
}
EMA.Redirects={
	Splash:{
		action:function(){
			var l=EMA.Globals.Cookies.get("PAW_BROWSE_LANGUAGE");
			if (l){
				//for splash pages redirect to homepage of the current segment according to the lang
				document.location.href='http://'+EMA.Globals.segment+'.proximus.be/'+l+'/index.html';
				return true;
			} else {
				return false;
			}
		},
		store:function(l){
			//sets the language cookie
			EMA.Globals.Cookies.set({name:"PAW_BROWSE_LANGUAGE",value:l});
			return true;
		}
	},
	SHP:{
		store:function(l){
			//sets the language cookie
			EMA.Globals.Cookies.set({name:"PAW_BROWSE_LANGUAGE",value:EMA.Globals.lang});
			//we don't store company segment
			if (EMA.Globals.segment!="company"){
				EMA.Globals.Cookies.set({name:"PAW_BROWSE_SEGMENT",value:EMA.Globals.segment});
			}
			return true;
		}
	}
}
