function logininfo(){
    var ctrl = document.getElementById("logininfo-id");
	if (!ctrl){
		return;
	}
	var username = getUserName();
	if (username){
		if (logedUser){
			ctrl.innerHTML=logedUser(username);
		}
	} else {
		if (anonymousUser){
			ctrl.innerHTML=anonymousUser();
		}
	}
}

function getUserName(){
	var action = new Cookie();
	var userName = action.getCookie("loginusername");
	if (userName && userName.length > 0){
		return userName;
	} else {
		return null;
	}
}



function login(userName){
	var action = new Cookie();
	action.setCookie("loginusername", userName);
}


function logout(){
	var action = new Cookie();
	action.setCookie("loginusername", "");
}
// retur
// -1 - http://, 0 - current, 1-https
function getUrl(path, mod){
  var loc = window.location.href;
  var ind=loc.indexOf("/", "http://".length + 1);
  if (ind<0)
	return loc + "/" + path;
  loc=loc.substring(0,ind) + "/" + path;
  if (mod == 0) { 
	return loc;
  } else 	if (mod == -1){
	return replace(loc,"https://", "http://");
  } else if (mod == 1){
	return replace(loc,"http://", "https://");
  } 
}


function replace(str, c, target)
{
	var res="";
	var from = 0;
	var i = str.indexOf(c);
	while(i >=0)
	{
		res+=str.substring(from,i);
		res+=target;
		from = i+c.length;
		i = str.indexOf(c,from);
	}
	res+=str.substring(from);
	return res;
}

