﻿var selectedBox="";
var selectedPannelItem="";
var objTimeout=0;
var t8;
var endHeight=70;
var moving ;
var objItem;
var objItemNew;


// ICQ API
var IcqAPI = {
	// enumerators
	// ===========
	
	// user list types. used in GetUsersList()
	UserListTypes: {UnknownUsers: -1, InvisibleUsers: 0, VisibleUsers: 1, IgnoreUsers: 2, AllUsers: 3, UsersNotYetInList: 4, ExternalUsers: 5, FutureUsers: 6, SpamUsers: 7}
	
	// user list sort types. used in GetUsersList(). several sort types can be combined with several filter types
	,UsersListSortTypes: {XtrazSupport: 0x00000001, AwayStatus: 0x00000002, OnlineStatus: 0x00000004, DisplayName: 0x00000008, SMSAvailable: 0x00000010}
	
	// user list filter types. used in GetUsersList(). several sort types can be combined with several filter types
	,UsersListFilterTypes: {
		All: 0
		,OnlineOnly: 0x00010000			// Include Online status only
		,XtrazSupportOnly: 0x00020000	// Include Xtraz support available only
		,NotAvailable: 0x00040000		// Include Not Available status only
		,NotSMSAvailable: 0x00080000	// Include SMS not available only
		,NotICQUsers: 0x00100000		// Include non-ICQ users
		}
	
	// user status. matches the value of the MISBUserInfo object's Status property. GetUsersList() returns a list MISBUserInfo objects.
	,UserStatus: {Connecting: -1, Available: 0, Away: 1, DoNotDisturb: 2, Out: 4, Busy: 16, Chat: 32 /* free for chat */, Invisible: 256, WebAware: 65536 /* User status is shown in searches */}
}


//******************
/* Client-side access to querystring name=value pairs
	Version 1.3
	28 May 2008
	
	License (Simplified BSD):
	http://adamv.com/dev/javascript/qslicense.txt
*/
function Querystring(qs) { // optionally pass a querystring to parse
	this.params = {};
	
	if (qs == null) qs = location.search.substring(1, location.search.length);
	if (qs.length == 0) return;

// Turn <plus> back to <space>
// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	qs = qs.replace(/\+/g, ' ');
	var args = qs.split('&'); // parse out name/value pairs separated via &
	
// split out each name=value pair
	for (var i = 0; i < args.length; i++) {
		var pair = args[i].split('=');
		var name = decodeURIComponent(pair[0]);
		
		var value = (pair.length==2)
			? decodeURIComponent(pair[1])
			: name;
		
		this.params[name] = value;
	}
}

Querystring.prototype.get = function(key, default_) {
	var value = this.params[key];
	return (value != null) ? value : default_;
}

Querystring.prototype.contains = function(key) {
	var value = this.params[key];
	return (value != null);
}

//******************


// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ left accordion 

//function slidedown(){
//        if(moving)return;
//        if(objItem.style.display != "none")return;
//        objItem.style.display = "block";
//        moving = true;
//        objItem.previousSibling.style.backgroundImage="url('Images/BoxBackgroundTop_1_on.gif')";
//        t8=setInterval('slideDownTick();',5);
//}
//function slideup(){
//        if(moving)return;
//        if(objItem.style.display == "none")return;
//        moving = true;
//        if(objItem.parentNode.parentNode.id!=selectedBox)objItem.previousSibling.style.backgroundImage="url('Images/BoxBackgroundTop_1.gif')";
//        t8=setInterval('slideUpTick();',5);
//}
//function slideUpTick(){
//        if(objItem.style.pixelHeight-10<0){
//            clearInterval(t8);
//            moving=false;
//            objItem.style.display = "none";
//            objItem.style.pixelHeight = 1;
//            objItem=objItemNew;
//            slidedown();
//            return; 
//        }
//        objItem.style.pixelHeight -= 10;
//}
//function slideDownTick(){
//        if(objItem.style.pixelHeight+10>endHeight){
//            clearInterval(t8);
//            moving=false;
//            objItem.style.pixelHeight = endHeight;
//            return;
//        }
//        objItem.style.pixelHeight += 10;
//}
//function toggleSlide(item){
//    if(objItem==item.nextSibling)return;
//    objItemNew=item.nextSibling;
//    if(objItem.parentNode.parentNode.id.indexOf("7")!=-1)document.getElementById('leftfooter').style.display="block";
//    if(objItemNew.parentNode.parentNode.id.indexOf("7")!=-1)document.getElementById('leftfooter').style.display="none";
//    slideup();
//}
function CategoryOver_R(item){
    if(item.parentNode.id!=selectedBox)item.firstChild.style.backgroundImage="url('Images/BoxBackgroundTop_r.gif')";
    var itemsParentDiv =item.childNodes[1].firstChild;
    for(i=0;i<itemsParentDiv.childNodes.length;i++){
        if(itemsParentDiv.childNodes[i].style.display == 'block'){itemsParentDiv.childNodes[i].lastChild.style.visibility='visible';break;}
    }
}
function CategoryOut_R(item){
    if(item.parentNode.id!=selectedBox)item.firstChild.style.backgroundImage="url('Images/BoxBackgroundTop_e.gif')";
    var itemsParentDiv =item.childNodes[1].firstChild;
    for(i=0;i<itemsParentDiv.childNodes.length;i++){
        if(itemsParentDiv.childNodes[i].style.display == 'block'){itemsParentDiv.childNodes[i].lastChild.style.visibility='hidden';break;}
    }
}
function CategoryOver_L(item){
    if(item.parentNode.parentNode.id!=selectedBox && objItem!=item.nextSibling)item.style.backgroundImage="url('Images/BoxBackgroundTop_1_on.gif')";
}
function CategoryOut_L(item){
    if(item.parentNode.parentNode.id!=selectedBox && objItem!=item.nextSibling)item.style.backgroundImage="url('Images/BoxBackgroundTop_1.gif')";
}
function CategoryClicked_R(item){
	//DisplayBanner(item.getAttribute("bannerId"));
    var itemsParentDiv =item.nextSibling.firstChild;
    for(i=0;i<itemsParentDiv.childNodes.length;i++){
        if(itemsParentDiv.childNodes[i].style.display == 'block'){
        itemsParentDiv.childNodes[i].click();
        break;
       }
    }
}
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Pannel Scroller
function scroll_R_To(index){
    if (index>2){PannelFrame.scroll((index-2)*83,0);}
    }
function scroll_L(){
	PannelFrame.scrollBy(-10,0);
	objTimeout=setTimeout("scroll_L()",60);
	}
function scroll_R(){
	PannelFrame.scrollBy(10,0);
	objTimeout=setTimeout("scroll_R()",60);
}
function stopScrolling() {
    clearTimeout(objTimeout);
}
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@   random box change     
var t1,t2,i,j,temp;
//var allBoxesArr =new Array("2","3","4","5","6","7","13","14","15","16","17","18","19","20","21","22","23","24");
var allBoxesArr =new Array("13","14","15","16","17","18","19","20","21","22","23","24");
var myimages = new Array();
function Load(){
//alert("load1")

    for(i=1;i<100;i++){ //  boxes  
    var checkME = document.getElementById('BOX' + i);
        if (checkME){       
        if((document.getElementById('BOX' + i).firstChild.firstChild.firstChild.innerText=="")){document.getElementById('BOX' + i).style.display='none'};
        }
    }
    
    LoadRandom();
    LoadLeftRandom();

    // check to see if correct images are being loaded. check against Barak's preloading javascript
    /*preloading("b_down_left_1_down.jpg","b_down_left_2.jpg","b_down_left_1_over.jpg","b_down_left_2_over.jpg","b_down_right_1.jpg","b_down_right_2_down.jpg","b_down_right_1_over.jpg","b_down_right_2_over.jpg","tooltipBG_Down.gif","tooltipBG_Up.gif","v_b_playlist_left_over.gif","v_b_playlist_right_over.gif","v_b_playlist_left_down.gif","v_b_playlist_right_down.gif","BoxBackgroundTop_1_on.jpg","BoxBackgroundTop_1.jpg","BoxBackgroundTop_e.gif","BoxBackgroundTop_r.gif","reporters_button_e.gif","b_search_down.jpg","hazara_b_down.jpg","reporters_button_r.gif","b_search_over.jpg","hazara_b_over.jpg");*/
    
//alert("load2")
}
function preloadImages(){
	preloading("b_down_left_1_down.jpg","b_down_left_2.jpg","b_down_left_1_over.jpg","b_down_left_2_over.jpg","b_down_right_1.jpg",	"b_down_right_2_down.jpg","b_down_right_1_over.jpg","b_down_right_2_over.jpg","tooltipBG_Down.gif","tooltipBG_Up.gif","v_b_playlist_left_over.gif","v_b_playlist_right_over.gif","v_b_playlist_left_down.gif","v_b_playlist_right_down.gif","BoxBackgroundTop_1_on.jpg","BoxBackgroundTop_1.jpg","BoxBackgroundTop_e.gif","BoxBackgroundTop_r.gif","reporters_button_e.gif","b_search_down.jpg","hazara_b_down.jpg","reporters_button_r.gif","b_search_over.jpg","hazara_b_over.jpg");
}
function preloading(){
    for (var i=0; i<preloading.arguments.length; i++){
        myimages[i] = new Image();
        myimages[i].src = "Images/"+preloading.arguments[i];
    }
}
// ??????????????????????????????
function LoadRandom(){
    clearTimeout(t1);
    clearInterval(t2);  
    for (i=0;i<12;i++){
        j= Math.floor((Math.random()*12));
        temp=allBoxesArr[i];
        allBoxesArr[i]= allBoxesArr[j];
        allBoxesArr[j]=temp;
    }
    t1 = setTimeout("StartRandom()",5000)
}
function StartRandom(){
    i = 0;
    t2 = setInterval("LoopItems()",1000)
}
function LoopItems(){
    var pagerArrowRight;
    // added by Gail on 29/10/2007 to avoid js object error
    try {
        pagerArrowRight = document.getElementById('BOX' + allBoxesArr[i]).firstChild.childNodes[1].childNodes[2].firstChild.lastChild; 
    } catch (exception) {
        return;
    }    
    if (!pagerArrowRight)return;
    Pager_left_or_right(pagerArrowRight,1);
    i++;
    if (i==11){i=0};    // 12 category boxes
}


/// left boxes rotation
var lt1,lt2,li,lj,ltemp;
var lallBoxesArr =new Array("2","3");
function LoadLeftRandom(){
    clearTimeout(lt1);
    clearInterval(lt2);  
    /*for (li=0;li<2;li++){
        lj= Math.floor((Math.random()*2));
        ltemp=lallBoxesArr[li];
        lallBoxesArr[li]= lallBoxesArr[lj];
        lallBoxesArr[lj]=ltemp;
    }*/
    lt1 = setTimeout("StartLeftRandom()",10000)
}
function StartLeftRandom(){
    li = 0;
    lt2 = setInterval("LoopLeftItems()",5000)
}
function LoopLeftItems(){
    var pagerArrowRight;
    // added by Gail on 29/10/2007 to avoid js object error
    try {
        pagerArrowRight = document.getElementById('BOX' + lallBoxesArr[li]).firstChild.childNodes[1].childNodes[2].firstChild.lastChild; 
    } catch (exception) {
        return;
    }    
    if (!pagerArrowRight)return;
    Pager_left_or_right(pagerArrowRight,1);
    li++;
    if (li==2){li=0};    // 2 category boxes
}
///////////////////////

//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@        replace boxes  buttons
function right_Scroller_B_Down(){
    document.getElementById("rightScroller").scrollTop+=10;   
    objTimeout=setTimeout("right_Scroller_B_Down()",60);  
}
function right_Scroller_B_Up(){
    document.getElementById("rightScroller").scrollTop-=10;   
    objTimeout=setTimeout("right_Scroller_B_Up()",60);
}
function left_Scroller_B_Down(){
    document.getElementById("leftScroller").scrollTop+=5;   
    objTimeout=setTimeout("left_Scroller_B_Down()",60);
}
function left_Scroller_B_Up(){
    document.getElementById("leftScroller").scrollTop-=5;   
    objTimeout=setTimeout("left_Scroller_B_Up()",60);
}
function Scroller_B_Change(item,url){
    item.src="Images/"+url;
}
function B_Change(item,url){
    item.src="Images/"+url;
}
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@   reporters
function ReportersOver(){
    if (selectedBox != "BOX1")document.getElementById("BOX1").firstChild.firstChild.style.backgroundImage="url('Images/reporters_title_r.gif')";
}
function ReportersOut(){
    if (selectedBox != "BOX1")document.getElementById("BOX1").firstChild.firstChild.style.backgroundImage="url('Images/reporters_title_e.gif')";
}
function ReportersDown(){
    var reporters = document.getElementById("BOX1").firstChild.childNodes[2].childNodes;
    if(!reporters)return;
    if (reporters.length > 5){
        for(var i=0;i<reporters.length-5;i++){
            if(reporters[i].style.display == "block"){
                reporters[i].style.display ="none";
                reporters[i+5].style.display ="block";
                return;
            }
        }
    }
}
function ReportersUp(){
    var reporters = document.getElementById("BOX1").firstChild.childNodes[2].childNodes
    if(!reporters)return;
    if (reporters.length > 5){
        for(var i=reporters.length-1;i>4;i--){
            if(reporters[i].style.display == "block"){
                reporters[i].style.display ="none";
                reporters[i-5].style.display ="block";
                return;
            }
        }
    }
}
function ReporterItemOut(item){
    item.className = "ReportersItem";
    }
function ReporterItemOver(item)
{item.className = "ReportersItemSelected";}
function ReporterItemClicked(url,ReporterId,Index,desc,item){  
    item.style.display="none";
    item.parentNode.lastChild.style.display="block";
    document.getElementById("PannelFrame").src = "PannelArticles.aspx?ReporterId=" + ReporterId;
    //var boxChilds = item.parentNode.parentNode.parentNode.childNodes;
    if (selectedBox != "BOX1" && selectedBox.indexOf("BOX")== 0){SelectedBoxFocusChanged() } 
    else if (selectedBox == "BOX1" && selectedPannelItem != Index){SelectedPannelFocusChanged();}
    selectedBox = "BOX1";
    document.getElementById("BOX1").firstChild.firstChild.style.backgroundImage="url('Images/reporters_title_r.gif')";
    selectedPannelItem = Index;
    var objTitle=document.getElementById("MovieTitle");
    objTitle.firstChild.style.display="none";
    objTitle.childNodes[1].style.display="block";
    objTitle.childNodes[1].firstChild.innerHTML=desc;
}
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ PAGER
function Pager_left_or_right(arrow,direction){   
   var i;
   var buttons = arrow.parentNode.childNodes;
   if (buttons.length == 0)
    return;
   var maxItems = arrow.parentNode.parentNode.parentNode.parentNode.childNodes[1].firstChild.childNodes.length;
   if (direction == 0){
        if((buttons.length > 1) && (buttons[1].innerText > 1)){
            for(i=1;i<buttons.length-1;i++){
                buttons[i].innerText --;
                if (buttons[i].pressed==1){pagerButtonClicked(buttons[i]);}
            }
        }
    } 
    else{
        //alert(maxItems);
        //var maxItems = arrow.parentNode.parentNode.parentNode.parentNode.childNodes[1].firstChild.childNodes.length;
        if((buttons.length > 2) && (buttons[buttons.length-2].innerText < maxItems)){
            for(i=1;i<buttons.length-1;i++){
                buttons[i].innerText ++;
                if (buttons[i].pressed==1){pagerButtonClicked(buttons[i]);}
            }
        }
        else if((buttons.length > 3) && (buttons[1].pressed==1)){pagerButtonClicked(buttons[2]);}
        else if((buttons.length > 4) && (buttons[2].pressed==1)){pagerButtonClicked(buttons[3]);}
        else if((buttons.length > 3) && (buttons[3].pressed==1)){
            for(i=1;i<buttons.length - 1;i++){
                buttons[i].innerText = i;
            }  
            if(buttons.length > 1)
                pagerButtonClicked(buttons[1]);
        }
    }
    for(i=1;i< buttons.length-1;i++) {
        if (buttons[i].innerText > maxItems) {
            buttons[i].style.visibility = "hidden";
        } else {
            buttons[i].style.visibility = "visible";
        }
    }
    buttons[0].style.visibility = "visible";
    buttons[buttons.length-1].style.visibility = "visible";
    if (buttons.length > 2) {
        if (buttons[1].innerText == "1") {
            buttons[0].style.visibility = "hidden";
        }
        if (buttons[buttons.length-2].innerText >= maxItems) {
            buttons[buttons.length-1].style.visibility = "hidden";
        }
    } else {
        buttons[0].style.visibility = "hidden";
        buttons[buttons.length-1].style.visibility = "hidden";
    }
}
function pagerButtonClicked(objButton){
    var itemsParentDiv = objButton.parentNode.parentNode.parentNode.parentNode.childNodes[1].firstChild;
    if(!itemsParentDiv.childNodes[objButton.innerText - 1])return;
    var i;
    itemsParentDiv.filters[0].enabled = true;
    itemsParentDiv.filters[0].Apply();
    for(i=0;i<itemsParentDiv.childNodes.length;i++){
        if(itemsParentDiv.childNodes[i].style.display == 'block'){itemsParentDiv.childNodes[i].style.display='none';}
    }
    
    if (itemsParentDiv.childNodes[objButton.innerText - 1].style.backgroundImage == "") {
		itemsParentDiv.childNodes[objButton.innerText - 1].style.backgroundImage = "url('" +
			itemsParentDiv.childNodes[objButton.innerText - 1].getAttribute("BgUrl") + "')";
    }
    
    itemsParentDiv.childNodes[objButton.innerText - 1].style.display = 'block';    
    itemsParentDiv.filters[0].Play();
    var buttons = objButton.parentNode.childNodes;
    if(objButton.parentNode.id!="RightPager"){
        for(i=1;i<buttons.length - 1;i++){
            buttons[i].style.backgroundColor="#C9CDD6";
            buttons[i].style.color= "Black";
            buttons[i].pressed=0;
        }
        objButton.style.backgroundColor="#4B70C1";//"FF6600";
        objButton.style.color= "White";
    }
    else{
        for(i=1;i<buttons.length - 1;i++){
            buttons[i].style.backgroundColor="#C9CDD6";
            buttons[i].style.color= "Black";
            buttons[i].pressed=0;
        }
        objButton.style.backgroundColor="#4B70C1";//"FF6600";
        objButton.style.color= "White";
    }    
    objButton.pressed=1;
}
function pagerButtonOver(item){
    item.style.borderColor = "#0453A2";
    }
function pagerButtonOut(item){
    item.style.borderColor = "#7F8699";
    }
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
function ShowLive(item)
{
	//alert("JScript:ShowLive");
	//document.getElementById("CastUpFrame").src = 
	//"http://switch5.castup.net/customers/icqru/v_480x270_live/Design.asp?as=1&clipurl=http%3A//switch3.castup.net/cunet/gm.asp%3Fai%3D509%26ar%3DLivepl01";
	//"http://switch5.castup.net/Customers/ICQRU/v_432x243_clickable/design.asp?as=1&clipurl=http%3A//switch3.castup.net/cunet/gm.asp%3Fai%3D509%26ar%3DLivepl01";
	//"http://switch5.castup.net/Customers/ICQRU/v_432x243_live/Design.asp?clipurl=http%3A//switch3.castup.net/cunet/gm.asp%3Fai%3D509%26ar%3DLivepl01";
    var objTitle=document.getElementById("MovieTitle");
    objTitle.childNodes[1].style.display="none";
    objTitle.firstChild.style.display="block";
    if (item.id == "PannelShowLive"){
        item.style.display="none";
        item.parentNode.firstChild.style.display="block";
        }
    else if(item.id == "MenuShowLive"){
        if(selectedBox != ""){
                if (selectedBox != item.parentNode.parentNode.parentNode.id && selectedBox != "BOX1"){SelectedBoxFocusChanged()}
                else if (selectedBox == "BOX1" ){
                    SelectedPannelFocusChanged();
                    selectedPannelItem = "";
                }
            }
        }
    else{
        var boxType=1;
        var boxId=selectedBox.substr(3);
        if  (boxId > 11){boxType=3;}
        else if (boxId > 8){boxType=2;}
        var boxChilds = item.parentNode.parentNode.parentNode.childNodes[1].childNodes;
        item.parentNode.parentNode.parentNode.firstChild.firstChild.style.backgroundImage="url('Images/BoxBackgroundTop_"+boxType+".gif')";
        boxChilds[1].style.display = "none";
        boxChilds[0].style.display = "block";
        boxChilds[3].style.display = "none";
        boxChilds[2].style.display = "block";
        }      
        selectedBox=""; 
        document.getElementById("CastUpFrame").src = "";   
        frames["PannelFrame"].location.href = "PannelLiveNew.aspx";

}

function ShowLive2(item)
{
	isLive = true;
	HideBuddiesDiv();
	HideOptionsDiv();

	document.getElementById("CastUpFrame").src = 
		"http://switch5.castup.net/Customers/ICQRU/v_432x243_Black_CrossDomain/Design.asp?clipurl=http%3A//switch3.castup.net/cunet/gm.asp%3Fai%3D509%26ar%3DLivepl01"+ "&playertype1=Live" + "&location=" + encodeURIComponent(location.href);
		// "http://switch5.castup.net/Customers/ICQRU/v_432x243_live/Design.asp?clipurl=http%3A//switch3.castup.net/cunet/gm.asp%3Fai%3D509%26ar%3DLivepl01";
		//"http://switch5.castup.net/customers/icqru/v_432x243_live_tictacti/design.asp?ClipURL=http%3A%2F%2Fswitch3%2Ecastup%2Enet%2Fcunet%2Fgm%2Easp%3Fai%3D509%26ar%3DLivePL01%26TTTTagType%3Ddefault&StrechToFit=true&AutoStart=true&VideoWidth=432&VideoHeight=243&TTTTagType=default&TTTpublisherId=3152";  

	var objTitle=document.getElementById("MovieTitle");
	objTitle.childNodes[1].style.display = "none";
	objTitle.firstChild.style.display = "block";
    
    if (item != null)
    {
		switch(item.id)
		{
			case "PannelShowLive":
				item.style.display = "none";
				item.parentNode.firstChild.style.display = "block";
				break;
			
			case "MenuShowLive":
				if (selectedBox != "")
				{
					if (selectedBox != item.parentNode.parentNode.parentNode.id && selectedBox != "BOX1")
						SelectedBoxFocusChanged();

					else if (selectedBox == "BOX1")
					{
						SelectedPannelFocusChanged();
						selectedPannelItem = "";
					}
				}
				break;
		
			case "lnkShowLive":
				break;
		}
    }

	if (selectedBox != "")
	{
		if (item && item.parentNode && item.parentNode.parentNode && item.parentNode.parentNode.parentNode &&
			selectedBox != "BOX1" && selectedBox != item.parentNode.parentNode.parentNode.id)
			SelectedBoxFocusChanged();
		else if (selectedBox == "BOX1")
		{
			SelectedPannelFocusChanged();
			selectedPannelItem = "";
		}
	}
    
//	if (item.id == "PannelShowLive")
//	{
//		item.style.display="none";
//		item.parentNode.firstChild.style.display="block";
//	}
//	else if(item.id == "MenuShowLive")
//	{
//		if(selectedBox != "")
//		{
//			if (selectedBox != item.parentNode.parentNode.parentNode.id && selectedBox != "BOX1")
//			{
//				SelectedBoxFocusChanged()
//			}
//			else if (selectedBox == "BOX1" )
//			{
//				SelectedPannelFocusChanged();
//				selectedPannelItem = "";
//			}
//		}
//	}
//	else
//	{
//		var boxType=1;
//		var boxId=selectedBox.substr(3);
//		if  (boxId > 11){boxType=3;}
//		else if (boxId > 8){boxType=2;}
//		var boxChilds = item.parentNode.parentNode.parentNode.childNodes[1].childNodes;
//		item.parentNode.parentNode.parentNode.firstChild.firstChild.style.backgroundImage="url('Images/BoxBackgroundTop_"+boxType+".gif')";
//		boxChilds[1].style.display = "none";
//		boxChilds[0].style.display = "block";
//		boxChilds[3].style.display = "none";
//		boxChilds[2].style.display = "block";
//	}
    
    selectedBox="";  
    frames["PannelFrame"].location.href = "PannelLiveNew.aspx";
}

function ShowMovie(url,title,bannerId, movieTicTacTiId, catTicTacTiId)
{
	DisplayBanner(bannerId);
	isLive=false;
	HideBuddiesDiv();
	HideOptionsDiv();
	//currentMovieUrlRaw = 'CastUP: ' + url;	//once we showmovie means we are on vod and add 'CastUP: ' to simulate as if we get it from CDplayer event
	currentMovieUrl = url;
		
	document.getElementById("MovieTitle").childNodes[1].lastChild.innerHTML = title;
	//alert("ShowMovie")
	//alert('showmovie url \n' + url + '\n title ' + title);
    if(url.indexOf("http") == 0)
    {
        var popup = window.open(url);
    }
    else
    {
		//var ttype = "default";
		var ttype = "";
	    
		if (movieTicTacTiId)
			ttype = movieTicTacTiId;
		else
			if (catTicTacTiId)
				ttype = catTicTacTiId;
			
		document.getElementById("CastUpFrame").src = 
			"http://switch5.castup.net/Customers/ICQRU/v_432x243_Black_CrossDomain/Design.asp?clipurl=http%3A%2F%2Fswitch3.castup.net%2Fcunet%2Fgm.asp%3Fai%3D509%26ar%3D" + encodeURIComponent(url)  + "&playertype1=VOD" + "&location=" + encodeURIComponent(location.href);
	
		checkIfHaveNext(url);
		
		//"http://switch5.castup.net/Customers/ICQRU/v_432x243_clickable/design.asp?clipurl=http%3A//switch3.castup.net/cunet/gm.asp%3Fai%3D509%26ar%3D" + url + "&ak=null";
		//"http://switch5.castup.net/customers/icqru/v_432x243_clickable_tictacti/design.asp?ClipURL=http%3A//switch3.castup.net/cunet/gm.asp%3Fai%3D509%26ar%3D" + url + "&ak=null";	    
		//"http://switch5.castup.net/customers/icqru/v_432x243_clickable_tictacti/design.asp?ClipURL=http%3A//switch3.castup.net/cunet/gm.asp%3Fai%3D509%26ar%3D" + url + "&ak=null&TTTpublisherId=3152&TTTTagType=" + ttype;
    }
}
function BoxTextOver(item){
    item.lastChild.style.visibility="visible";
}
function BoxTextOut(item){
    item.lastChild.style.visibility="hidden";
}
function BoxItemClicked(url,areanumber,areatype,index,desc,bannerId,item){
	DisplayBanner(bannerId);
    if(selectedBox != ""){
        if (selectedBox != item.parentNode.parentNode.parentNode.parentNode.id && selectedBox != "BOX1"){SelectedBoxFocusChanged()}
        else if (selectedBox == "BOX1" ){
            SelectedPannelFocusChanged();
            selectedPannelItem = "";
            document.getElementById("BOX1").firstChild.firstChild.style.backgroundImage="";
        }
    }
    selectedBox = item.parentNode.parentNode.parentNode.parentNode.id;
    //alert(selectedBox);
    var boxChilds = item.parentNode.parentNode.parentNode.childNodes[1].childNodes;
    item.parentNode.parentNode.parentNode.firstChild.style.backgroundImage="url('Images/BoxBackgroundTop_"+areatype+"_on.gif')";
    boxChilds[0].style.display ="none";
    boxChilds[1].style.display ="block";
    boxChilds[2].style.display="none";
    boxChilds[3].style.display="block";
    var objTitle=document.getElementById("MovieTitle");
    objTitle.firstChild.style.display="none";
    objTitle.childNodes[1].style.display="block";
    objTitle.childNodes[1].firstChild.innerHTML=desc;
    frames["PannelFrame"].location.href = "PannelCategory.aspx?AreaNumber=" + areanumber + "&AreaType=" + areatype + "&Index=" + index;
}
function SelectedBoxFocusChanged()
{
    var boxType=1;
    var boxId=selectedBox.substr(3);
    if  (boxId > 11){boxType=3;}
    else if (boxId > 8){boxType=2;}
    var oldBoxChilds = document.getElementById(selectedBox).firstChild.childNodes[1].childNodes;
    document.getElementById(selectedBox).firstChild.firstChild.style.backgroundImage="url('Images/BoxBackgroundTop_"+boxType+".gif')";
    oldBoxChilds[0].style.display="block";
    oldBoxChilds[1].style.display="none";
    oldBoxChilds[2].style.display="block";
    oldBoxChilds[3].style.display="none";
}
function SelectedPannelFocusChanged(){
    var oldPannelChilds = document.getElementById("BOX1").firstChild.childNodes[2].childNodes[selectedPannelItem].childNodes;
    oldPannelChilds[0].style.display="block";
    oldPannelChilds[1].style.display="none";
}
//@@@@@@@@@@@@@@@@ search
function search(){
    var SearchText = document.getElementById("SearchBar").value;
    DisplayBanner('');
    if((document.getElementById("tab2").className=="Tab") && (frames["PannelFrame"])){
        frames["PannelFrame"].location.href = "PannelSearch.aspx?SearchText="+ SearchText;
    }
    else{
    SearchText = encodeURI(SearchText);
    //var pop=window.open("http://search.icq.com/search/results.php?q="+ SearchText +"&ch_id=icqtv_web","");
     var pop=window.open("http://search.rambler.ru/cgi-bin/icqweb?stat=icqClient&words=" + SearchText, "");
    } 
}
function tabClicked(index){
    if(index==1){
        document.getElementById("tab1").className="Tab";
        document.getElementById("tab2").className="selectedTab";
        }
        else{
        document.getElementById("tab2").className="Tab";
        document.getElementById("tab1").className="selectedTab";
        }

}

function tabSearch() {
				var SearchText = document.getElementById("SearchBar").value;
				if(document.getElementById("tab2").className=="Tab"){
					document.location.href = "Default.aspx" + location.search + "&search=" + encodeURI(SearchText) ;
				}
				else{
					SearchText = encodeURI(SearchText);
					//var pop=window.open("http://search.icq.com/search/results.php?q="+ SearchText +"&ch_id=icqtv_web","");
					var pop=window.open("http://search.rambler.ru/cgi-bin/icqweb?stat=icqClient&words=" + SearchText, "");
				} 
			}

	
var connector;

function checkconn()
{	 //try to create new connector if succeeds returns true else false
	var res = false;//debugger;
	try
	{
		connector = XtrazConnector.getIcqConnector(); //chreation of the connector
		res = true;
	}
	catch(e){}
	return res;
}
function redirect(url)
{//debugger;
	var qs = new Querystring(location.search.replace("?",""));
	var bld = qs.get("bld");
    var dst = qs.get("dst");
    var id = qs.get("id");
    var mode = qs.get("mode");
    
    if (url.indexOf("?") != -1)
     	url += "&bld=" + bld + "&dst=" + dst + "&id=" + id + "&mode=" + mode;
    else
		url += "?bld=" + bld + "&dst=" + dst + "&id=" + id + "&mode=" + mode;
	window.location.replace(url);
}
		
function redirectToUserPreferencesPage()
{//debugger;
	if (!checkconn())
	{
		// no connector - handle error
		return;
	}
	var sk =connector.GetIMOwnerData("SESSION_KEY");
	var sUid = connector.GetIMOwnerData("SCREEN_NAME");
	redirect("UP.aspx?uid=" + sUid + "&sk=" + sk);
}

function goBackToLive()
{
	redirect('default.aspx');
}


function GoBackToLive(item)
{
	HideOptionsDiv();
	ShowLive2(item);
}
function checkIfHaveNext(url)
{
	var lnk = document.getElementById('lnkPlayNext');
	var pannel = frames["PannelFrame"].document.getElementById("TopDiv");
	if (pannel)
	{
	    var c =pannel.childNodes.length;
	    for (var i=0;i<c;i++) {
		    if (pannel.childNodes[i].getAttribute("clipName")== url)
		    {
			    if (!pannel.childNodes[i].nextSibling)
			    {
				    lnk.onclick = function(){return false;}
				    lnk.style.cursor = 'default';
				    break;
			    }
			    else
			    {
				    lnk.style.cursor = 'hand';
				    var nextUrl = pannel.childNodes[i].nextSibling.getAttribute("clipName");
				    var nextItem = pannel.childNodes[i+1];
				    lnk.onclick = function(){ playNext(nextUrl,nextItem); }
				    break;
			    }
		    }
		}
    }
}

function playNext(url,item)
{
	HideOptionsDiv();
	frames["PannelFrame"].window.PannelItemClicked(url,'',item);
}


function ShowOptionsDiv()
{
	document.getElementById("optionsContainer").style.display = 'block';
	//document.getElementById("CastUpFrame").style.display = 'none';
}

function HideOptionsDiv()
{
	document.getElementById("optionsContainer").style.display = 'none';
	//document.getElementById("CastUpFrame").style.display = 'block';
}

function ShowBuddiesDiv()
{
	document.getElementById("buddiesListDiv").style.display = 'block';
}

function HideBuddiesDiv()
{
	document.getElementById("buddiesListDiv").style.display = 'none';
}

function CloseBuddiesDiv()
{
    HideBuddiesDiv();
    ShowOptionsDiv();
}

function ShowSendToFriend()
{
	var bShowOnlineUsersOnly = true; // if set to true only online users are displayed (including away, busy and N/A=out)
	var bShowOnlyAvailStatusImage = true; // if set to true all online users will be displayed with available status icon
	var iGetUsersListFilter = bShowOnlineUsersOnly? IcqAPI.UsersListFilterTypes.OnlineOnly: IcqAPI.UsersListSortTypes.All;
	
	//debugger;
	HideOptionsDiv();
	var connector = XtrazConnector.getIcqConnector();
	var screen_name = connector.GetIMOwnerData('SCREEN_NAME');
	var display_name = connector.GetIMOwnerData('DISPLAY_NAME');

	var buddies = connector.GetUsersList(IcqAPI.UserListTypes.AllUsers, IcqAPI.UsersListSortTypes.DisplayName | iGetUsersListFilter);
	var count = buddies.count;
	var tt_name;
	var uin;
	var innerHtml;
	var firstColumn = '';
	var secondColumn = '';
	var statusImage;
	
	var innerTable = '' +
		'<table class="buddies_inner_table"  border="0" cellspacing="0" cellpadding="0">' +
			'<tr>' +
				'<td style="text-align:right;width:16px;padding-bottom:2px;"><input class="btn" id="{2}" type="checkbox" name="chkBuddies" /></td>' +
				'<td style="width:16px;height:16px;"><img src="Images/send/{0}" border="0" /></td>' +
				'<td style="color:white;font-size:14px;padding-bottom:2px;">&nbsp;{1}</td>' +
			'</tr>' +
		'</table>';
	
    //innerHtml = '<div >';
    innerHtml = '' +
		'<table cellspacing="0" cellpadding="0" border="0" class="buddies_table">';
    
    
    for (var i = 0; i < count; i++)
    {
		 uin = buddies(i).ScreenName;
		 tt_name = buddies(i).DisplayName;
		 bUserIsOnline = bShowOnlineUsersOnly ||
			buddies(i).Status == IcqAPI.UserStatus.Available ||
			buddies(i).Status == IcqAPI.UserStatus.Away ||
			buddies(i).Status == IcqAPI.UserStatus.Busy ||
			buddies(i).Status == IcqAPI.UserStatus.Out;
		 statusImage = GetStatusImg(bShowOnlyAvailStatusImage? IcqAPI.UserStatus.Available: buddies(i).Status);
		 
	     if (i % 2 == 0)
	     {
			innerHtml += '' +
				'<tr>' +
					'<td class="buddies_first_cell">' +
					String.format(innerTable, statusImage, tt_name, uin) +
					'</td>';
	     }
	     else
	     {
			innerHtml += '' +
					'<td class="buddies_second_cell">' +
					String.format(innerTable, statusImage, tt_name, uin) +
					'</td>' +
				'</tr>';
	     }  
    }
	
    innerHtml += '' +
		'</table>';
	
	// innerHtml += '<hr style="height:1px;color:#577D92;width:387px;"/>';
	//  innerHtml += '<input id="btnSendToFriend" type="button" value="Send" onclick="SendToFriend();" />';
	//  innerHtml += '<a href="#" onclick="SelectChkBoxes(true);">בחר הכל</a>';
	//innerHtml += '<a href="#" onclick="SelectChkBoxes(false);">נקה הכל</a>';
	//innerHtml += '</div>';
	document.getElementById("buddies").innerHTML = innerHtml;
	ShowBuddiesDiv();
}

function SelectChkBoxes(Select)
{
	var arrayOfCheckBoxes = document.getElementById("buddies").getElementsByTagName("input");
	for(var i = 0; i < arrayOfCheckBoxes.length; i++)
	{
		if (arrayOfCheckBoxes[i].name == "chkBuddies")
		{
			arrayOfCheckBoxes[i].checked = Select;
		}
	}
	return false;
}
	
function GetStatusImg(userStatus)
{
	//debugger;
	var image;
	switch (userStatus)
	{
		case IcqAPI.UserStatus.Connecting:
			image = 'icq_connecting.gif';
			break;
		case IcqAPI.UserStatus.Available:
			image = 'icq_avail.gif';
			break;
		case IcqAPI.UserStatus.Away:
			image = 'icq_away.gif';
			break;
		case IcqAPI.UserStatus.DoNotDisturb:
			image = 'icq_dnd.gif';
			break;
		case IcqAPI.UserStatus.Out:
			image = 'icq_out.gif';
			break;
		case IcqAPI.UserStatus.Busy:
			image = 'icq_dnd.gif';
			break;
		case IcqAPI.UserStatus.Chat:
			image = 'icq_avail.gif';
			break;
		case IcqAPI.UserStatus.Invisible:
			image = 'icq_avail_inv.gif';
			break;
		default:
			image = 'transparent.png';
	}
	
	return image;	
}

/*
function SendToFriend()
{
	//debugger;
	var arrayOfCheckBoxes = document.getElementById("buddies").getElementsByTagName("input");
	
	var checkedBuddiesCount = GetCheckedBuddiesCount(arrayOfCheckBoxes)
	if (checkedBuddiesCount>3)//if more than 10 buddies to send- open the send_to_friend xtra
	{
	    var initData = buildInitDataQs(arrayOfCheckBoxes);
	    var sn = connector.GetIMOwnerData('SCREEN_NAME');
	    connector.OpenPlugin(sn,'send_to_friend',initData);
	}
	else//less than 10 buddies - send it now
	{
	    for(var i=0;i<arrayOfCheckBoxes.length;i++)//go over the checkbox list
	    {
		    if (arrayOfCheckBoxes[i].name == "chkBuddies")
		    {
			    if (arrayOfCheckBoxes[i].checked)//if checked send the xtra
				    connector.SendXtra(arrayOfCheckBoxes[i].id, "icq_tv", 'mv=' + currentMovieUrl);//currentMovieUrl holds the current played movie
		    }
	    }
	}
	HideBuddiesDiv();
	ShowOptionsDiv();
}

function buildInitDataQs(arrayOfCheckBoxes)
{
	//debugger;
    var initData = "";
    initData += "xtraId=icq_tv";
    initData += "&movie=" + currentMovieUrl;
    initData += "&buddies="
    for(var i=0;i<arrayOfCheckBoxes.length;i++)//go over the checkbox list
	    {
		    if (arrayOfCheckBoxes[i].name == "chkBuddies")
		    {
			    if (arrayOfCheckBoxes[i].checked)//if checked send the xtra
				   initData += arrayOfCheckBoxes[i].id + "|";
		    }
	    }
	    return initData;
}

function GetCheckedBuddiesCount(arrayOfCheckBoxes)
{
    var checkedCount = 0;
    for(var i=0;i<arrayOfCheckBoxes.length;i++)//go over the checkbox list
	{
		if (arrayOfCheckBoxes[i].name == "chkBuddies")
		{
			if (arrayOfCheckBoxes[i].checked)//if checked send the xtra
				checkedCount++;
		}
	}
	return checkedCount;
	
}
*/

function SendToFriend()
{
	var connector = XtrazConnector.getIcqConnector();
	if (!connector)
		return;
	
	// get recipients' ids array
	var aRecipientIds = SendToFriend.GetRecipientsArray();
	// prompt an error message if no user been selected
	if (aRecipientIds.length == 0)
	{
		//var sErrorMsg = connector.GetIMClientData("LANG_ID") == 'he-il'? "לא נבחרו חברים": "You have selected no buddies";
		var sErrorMsg = "Вы не выбрали получателей.";
		connector.ShowPrompt(sErrorMsg);	
		return;
	}
	
	// get send to friend parameters
	var iRecipientsBatchSize = 10;
	var iDelayBetweenBatchesInSeconds = 5;
	var iMaxRecipients = -1; // any value smaller than 1 is considered as un limited
	
	if (document.getElementById("hdn_SendToFriend_RecipientsBatchSize") &&
		document.getElementById("hdn_SendToFriend_DelayBetweenBatchesInSeconds") &&
		document.getElementById("hdn_SendToFriend_MaxRecipients"))
	{
		iRecipientsBatchSize = Number(document.getElementById("hdn_SendToFriend_RecipientsBatchSize").value);
		iDelayBetweenBatchesInSeconds = Number(document.getElementById("hdn_SendToFriend_DelayBetweenBatchesInSeconds").value);
		iMaxRecipients = Number(document.getElementById("hdn_SendToFriend_MaxRecipients").value);
	}
	
	// prompt an error message if user selected more than maximal recipients limit
	if (iMaxRecipients > 0 && aRecipientIds.length > iMaxRecipients)
	{
		//var sErrorMsg = connector.GetIMClientData("LANG_ID") == 'he-il'?
		//	String.format("ניתן לסמן עד {0} חברים.<br>אנא שנה/י את הסימון ונסה/י שנית", iMaxRecipients):
			var sErrorMsg = String.format("Вы можете выбрать не более {0} получателей.<br>Пожалуйста, измените количество получателей и попробуете еще раз.", iMaxRecipients);
		connector.ShowPrompt(sErrorMsg);	
		return;
	}
	//aRecipientIds = [471282228,471282228,471282228,471282228,471282228,471282228,471282228,471282228,471282228,471282228,471282228,471282228,471282228,471282228,471282228,471282228,471282228,471282228,471282228,471282228,471282228,471282228];
	
	// if less than batch size send synchronically
	if (aRecipientIds.length <= iRecipientsBatchSize)
	{
		for (var i = 0; i < aRecipientIds.length; i++)
		{
			SendToFriend.SendMovieMessage(aRecipientIds[i], currentMovieUrl);
		}
	}
	
	// otherwise send a-synchronically via a separate extra window
	else
	{
	    var sInitData = "xtraId=icqtv_russia&movie=" + currentMovieUrl +
			"&buddies=" + aRecipientIds.join() + "&batchsize=" + iRecipientsBatchSize +
			"&delay=" + iDelayBetweenBatchesInSeconds + "&max=" + iMaxRecipients;
	    var sIcqScreenName = connector.GetIMOwnerData('SCREEN_NAME');
	    connector.OpenPlugin(sIcqScreenName, 'send_to_friend_russia', sInitData);
	}
	
	HideBuddiesDiv();
	ShowOptionsDiv();
}

function SendToFriend.SendMovieMessage(i_iRecipientId, i_sMovieName)
{
	// NOTE: connector is a global variable defined in default.aspx
	if (!connector)
		return;
	
	// NOTE: currentMovieUrl is a global variable defined and managed in /scripts/CustUpCD.js
	//	currentMovieUrl holds the current played movie
	connector.SendXtra(i_iRecipientId, "icqtv_russia", "mv=" + i_sMovieName);
}

function SendToFriend.GetRecipientsArray()
{
	//debugger;
	var aCheckBuddies = new Array();
	
	var oBuddiesFormInputCollection = null;
	
	// get buddies checbox collection
	if (document.getElementById("buddies") != null)
		oBuddiesFormInputCollection = document.getElementById("buddies").getElementsByTagName("input");
	if (oBuddiesFormInputCollection == null || oBuddiesFormInputCollection.length == 0)
		return aCheckBuddies;
	
	// iterate through collection and push checked buddies' id
	for (var i = 0; i < oBuddiesFormInputCollection.length; i++)
	{
		if (oBuddiesFormInputCollection[i].name == "chkBuddies" && oBuddiesFormInputCollection[i].checked)
			aCheckBuddies.push(oBuddiesFormInputCollection[i].id);
	}
	
	return aCheckBuddies;
}

String.format = function(text)
{
    //check if there are two arguments in the arguments list
    if (arguments.length <= 1)
    {
        //if there are not 2 or more arguments there’s nothing to replace
        //just return the original text
        return text;
    }
    
    //decrement to move to the second argument in the array
    var tokenCount = arguments.length - 1;
    for (var token = 0; token < tokenCount; token++)
    {
		//iterate through the tokens and replace their placeholders from the original text in order
		text = text.replace(
			new RegExp("\\{" + token + "\\}", "gi"),
			arguments[token + 1]
			);
    }
    
    return text;
};





