var XMLHTTP_PROGIDS = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0']

var HttpRequest   = {};
var requestStatus = "";

HttpRequest.getXmlhttpObject = function() {
    var http = null;
    var last_e = null;
    try{ http = new XMLHttpRequest(); }catch(e){}
    if(!http){
      for(var i=0; i<3; ++i){
        var progid = XMLHTTP_PROGIDS[i];
	try{
	  http = new ActiveXObject(progid);
	}catch(e){
	  last_e = e;
	}
        if(http){
	  XMLHTTP_PROGIDS = [progid];  // so faster next time
	  break;
	}
      }
    }
    if(!http){
        if(typeof(console) == 'object')
 	console.debug("XMLHTTP not available", last_e);
    }
    return http;
}

HttpRequest.getText = function(uri, async_cb, fail_ok){
	var http = this.getXmlhttpObject();
	if(async_cb){
		http.onreadystatechange = function(){
			if(4==http.readyState){
				if((!http["status"])||((200 <= http.status)&&(300 > http.status))){
					async_cb(http.responseText);
				}
			}
		}
	}
	http.open('GET', uri, async_cb ? true : false);
	try{
		http.send(null);
		if(async_cb){
			return null;
		}
		if((http["status"])&&((200 > http.status)||(300 <= http.status))){
			throw Error("Unable to load "+uri+" status:"+ http.status);
		}
	}catch(e){
		if((fail_ok)&&(!async_cb)){
			return null;
		}else{
			throw e;
		}
	}
	return http.responseText;
}

//setInterval(function() { HttpRequest.getText('/ajax.php?Action=UpdateActivity'); }, 30000);


function switchFriends(Action) {
	var Action = Action;
	if(Action == null) { Action = '1'; }

        MyCookie.Write('SwithMyFriend', Action, 365);
        document.getElementById('MyFriendsBlock').innerHTML = HttpRequest.getText('/ajax.friends.php' + '?Action=' + Action);
        var friendTitle = document.getElementById('MyFriendsTitle');

        if(MyCookie.Read('SwithMyFriend') == '1') {
          document.SwithMyFriendForm.SwithMyFriend[0].checked = true;
          friendTitle.innerHTML = 'Moji přátelé online';
        }

        else if(MyCookie.Read('SwithMyFriend') == '2') {
          document.SwithMyFriendForm.SwithMyFriend[1].checked = true;
          friendTitle.innerHTML = 'Moji přátelé offline';
        }

        else if(MyCookie.Read('SwithMyFriend') == '3') {
          document.SwithMyFriendForm.SwithMyFriend[2].checked = true;
          friendTitle.innerHTML = 'Moji přátelé na chatu';
        }

        else if(MyCookie.Read('SwithMyFriend') == '4') {
          document.SwithMyFriendForm.SwithMyFriend[3].checked = true;
          friendTitle.innerHTML = 'Moji přátelé';
        }

        else {
          document.SwithMyFriendForm.SwithMyFriend[0].checked = true;
          friendTitle.innerHTML = 'Moji přátelé';
        }
}


function switchBGMenu(a, idStyle) {

  if(idStyle == '') {
    idStyle = '1';
  }

  for(i=1; i <= 7; i++) {

     if(a == i) {
         document.getElementById('bg_topmenu_left_'+i).style.backgroundImage='url(/_face/img/'+idStyle+'/bg_topmenu_left_extra.png)';
         document.getElementById('bg_topmenu_inside_'+i).style.backgroundImage='url(/_face/img/'+idStyle+'/bg_topmenu_inside_extra.png)';
         document.getElementById('bg_topmenu_right_'+i).style.backgroundImage='url(/_face/img/'+idStyle+'/bg_topmenu_right_extra.png)';
     } else {
         document.getElementById('bg_topmenu_left_'+i).style.backgroundImage='url(/_face/img/'+idStyle+'/bg_topmenu_left.png)';
         document.getElementById('bg_topmenu_inside_'+i).style.backgroundImage='url(/_face/img/'+idStyle+'/bg_topmenu_inside.png)';
         document.getElementById('bg_topmenu_right_'+i).style.backgroundImage='url(/_face/img/'+idStyle+'/bg_topmenu_right.png)';
     }

  }

}



function switchMenu(Action, SubMenu) {
	var Action = Action;
	if(Action == null) { Action = '1'; }

	//alert(SubMenu);


        MyCookie.Write('switchMenu', Action, 365);
        document.getElementById('menuBlock').innerHTML = HttpRequest.getText('/ajax.menu.php' + '?Action=' + Action + "&SubMenu=" + SubMenu);


        /*
        if(Action == '1') {
         document.getElementById('bg_topmenu_left_2').style.backgroundImage='url(/_face/img/bg_topmenu_left_extra.png)';
         document.getElementById('bg_topmenu_inside_2').style.backgroundImage='url(/_face/img/bg_topmenu_inside_extra.png)';
         document.getElementById('bg_topmenu_right_2').style.backgroundImage='url(/_face/img/bg_topmenu_right_extra.png)';
        }

        if(Action == '2') {
         document.getElementById('bg_topmenu_left_3').style.backgroundImage='url(/_face/img/bg_topmenu_left_extra.png)';
         document.getElementById('bg_topmenu_inside_3').style.backgroundImage='url(/_face/img/bg_topmenu_inside_extra.png)';
         document.getElementById('bg_topmenu_right_3').style.backgroundImage='url(/_face/img/bg_topmenu_right_extra.png)';
        }
        */

}

function switchBGSubmenu(a, c, idStyle) {
  var color;

  if(idStyle == '1') {
    color = '#E03265';
  } else if(idStyle == '2') {
    color = '#5C7CC7';
  }

  for(i=1; i <= c; i++) {
     if(a == i) {
         document.getElementById('bg_submenu_'+i).style.backgroundColor=color;
         document.getElementById('cmenu_item_'+i).style.color='#000000';
     } else {
//         document.getElementById('bg_submenu_'+i).style.backgroundImage='url(/_face/img/bg_menu.png)';
     }

  }
}
