
var Globals = {};

var Utils = {};
Utils.getDefaultProfileImage = function(min_size, gender){
	var extention = 60; 
	if(min_size > 60){
		extention = 180;
		if(min_size > 180){
			extention = 520;
			if(min_size > 520){
				extention = 868;
			}
		}
	}
	switch(gender*1){
		case 1: 	return "/img/man_"+extention+".jpg";
		case 2: 	return "/img/woman_"+extention+".jpg";
		default : 	return "/img/mannOgDame_"+extention+".jpg";
	}
}

Utils.progress_bar = null;
Utils.displayProgress = function(){
	if(!Utils.progress_bar){
		Utils.progress_bar 	= document.createElement("div");
		Utils.progress_bar.id = "progress_bar";
		Utils.progress_bar.innerHTML = 
					"<div class='container'>"+
						"<div class='container_trans transparent'></div>" +
						"<div class='container_content'></div>"+
					"</div>";
		document.body.appendChild(Utils.progress_bar);
	}
	Utils.progress_bar.style.display = "block";	
}
Utils.hideProgress = function(){
	if(!Utils.progress_bar) return;
	Utils.progress_bar.style.display = "none";
}

Utils.getPos = function(e_){
	if(!e_ || !e_.parentNode)
		return {x: 0, y: 0};
	var pleft = 0;
	var ptop  = 0;

	while (e_.offsetParent){
		pleft += e_.offsetLeft;
		ptop  += e_.offsetTop;
		e_     = e_.offsetParent;
	}

	pleft += e_.offsetLeft;
	ptop  += e_.offsetTop;

	return {x:pleft, y:ptop};
}	

Utils.ge = function(id){
	return document.getElementById(id);
}
Utils.applyDefault = function(input, text, type_){
	input.style.color = "#555";
	input.value = text;
	input.onfocus = function(){
		if(input.value == text){		
			input.value = "";
			input.style.color = "#000";
		}
		input.type = type_;
	}
	input.onblur = function(){
		if(input.value == ""){
			input.value = text;
			input.style.color = "#555";
			input.type = "text";
		}
	
	}
}

Utils.applyEnter = function(input, func_){
	input.onkeyup = function(e){			
		e = e || window.event				
		var keynum = e.keyCode || e.which;				
		if(keynum == 13){
			func_();
		}		
	}
}

Utils.onfocus = function(input, func_){
	input.onfocus = func_(); 
}

Utils.displayError = function(err_text){	
	var err_field = Utils.ge("err_field");
	Utils.displayMessage("Error", err_text);
	Utils.hideProgress();
}

Utils.displayMessage = function(header, message){
	var dialog_bg 			= Utils.ge("modal_background");
	dialog_bg.style.display = "block";
	var dialog 				= Utils.ge("modal_message");
	dialog.style.display 	= "block";
	dialog.style.zIndex		= "2";
	dialog.firstChild.childNodes[0].innerHTML = header;
	dialog.firstChild.childNodes[1].innerHTML = message;
	
	var hide = function(){
		dialog_bg.style.display = "none";
		dialog.style.display 	= "none";		
	}
	
	dialog.firstChild.childNodes[2].firstChild.onclick = hide;
	dialog_bg.onclick = hide;
}

Utils.ls = function(module, label_){
	if(localised_strings[label_])
		return localised_strings[label_];
	return "cb_frontpage_js::"+label_;
	
}
Utils.mousePos = function(ev){
	if(ev.pageX || ev.pageY){
		return {x:ev.pageX, y:ev.pageY};
	}
	var scrollTop = window.pageYOffset || document.documentElement.scrollTop || 0; 
	var scrollLeft = window.pageXOffset || document.documentElement.scrollLeft || 0;				
	return {				
		x:ev.clientX + scrollLeft, 
		y:ev.clientY + scrollTop
	};			
}

Utils.getDateTimeAsString = function(d){
	if (d != null) {
		var day = d.getDate();
		var month = d.getMonth() + 1;
		var year = d.getFullYear();		
		var hours = d.getHours();
		var minutes = d.getMinutes();	
		var seconds = d.getSeconds();
		if (day < 10)
			day = "0" + day;			
		if (month < 10)
			month = "0" + month;
		if (hours < 10)
		 	hours = "0" + hours;
		if (minutes < 10)
		 	minutes = "0" + minutes;	 		
		 if(seconds < 10)
		 	seconds = "0"+seconds;		   
		return year + "-" + month + "-" + day + " " + hours + ":" + minutes+":"+seconds; 			
	}
	return "";
}
Utils.getWindowSize = function(){	
	if( typeof( window.innerWidth ) == 'number' ) {//Non-IE    
	    Globals.win_width = window.innerWidth;
	    Globals.win_height = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {//IE 6+ in 'standards compliant mode'    
	    Globals.win_width = document.documentElement.clientWidth;
	    Globals.win_height = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {//IE 4 compatible	    
	    Globals.win_width = document.body.clientWidth;
	    Globals.win_height = document.body.clientHeight;
	}	
}
