var b = true;
var activeID = null;
var lastLetterId=""

function sendLetterToIFrame(url,no,letterId)
{ 

    resetLettersClass();
    var divObj=document.getElementById('myDiv');
    if(no<8)
    {
        divObj.className='lobby_program_list_div_right';
    }
    else if(no>14)
    {
        divObj.className='lobby_program_list_div_left';
    }
    else
    {
        divObj.className='lobby_program_list_div';
    }
    divObj.style.display = 'block';
    
    /*
    
    
//    if(no<8)
//    {
//        //divObj.className='lobby_program_list_div_right';
//       left=Math.abs(event.clientX - 600+20);
//       window.status = event.clientX;
//    }
//    else if(no>14)
//    {
//        //divObj.className='lobby_program_list_div_left';
//        left = event.clientX-20;
//        window.status = left;
//    }
//    else
//    {
//        divObj.className='lobby_program_list_div';
        left = event.clientX-300;
        right=event.clientX+300;
        if(left<120)
        {
            left=120;
        }
        else if(right>1020)
            left=420;
        window.status = left;
//    }
    
    //var x           = event.clientX;
    //var divWidth    = 600;
    //var left = x-20;
    
    //if(x > divWidth)
    //{
    //    left = Math.abs(event.clientX - 600);
    //    alert(x);
    //}
    
    //window.status = left;
    
    

    divObj.style.left = left;
    divObj.style.display = 'block';
    
    */
    
    document.getElementById('iframe_ABC').src = url;
    
    lastLetterId=letterId;
    
    hideShowIframes(true, 'iframe_ABC');
}
   
function changeLettersClass(letterId)
{
    var letterObj=document.getElementById(letterId);
    if(letterId != lastLetterId)
    {
        if(letterObj)
        {
            letterObj.className='shidurim';
        }
    }
}

function resetLettersClass()
{
    if(lastLetterId !="")
    {
        var lastLetterObj=document.getElementById(lastLetterId);
        if(lastLetterObj)
            lastLetterObj.className='shidurim';
    }
}
    
function GoToHomePage(HomePageUrl)
{
    window.top.hidePopWin(false);
    window.top.parent.location.href = HomePageUrl;
}
        
function HideMe(id)
{
    document.getElementById(id).style.display = 'none'; 
}

function ShowDiv(n)
{
    //status = event.srcElement.id + ' , z-index = ' + event.srcElement.style.zIndex;
    if(b)
    {
        activeID = 'pop_0' + n;
        
        document.getElementById('pop_0' + n).style.display = 'block'; 
        document.getElementById('lightBox').style.display = 'block';
        
        b = false;
    }
}

function HideDiv(n)
{ 
    b = true;
    document.getElementById('pop_0' + n).style.display = 'none'; 
    document.getElementById('lightBox').style.display = 'none'; 
}
function fade(el, way){
    /*Modern Browser Fader by John Davenport Scheuer
      This comment must remain for Legal Use */
    clearTimeout(el.timer);
    if(way=='in'){
        document.getElementById('lightBox').style.display = 'block';
        el.style.display = 'block';
    }
    else{
        document.getElementById('lightBox').style.display = 'none'; 
        el.style.display = 'none';
        //return;
    }
    var targ_op=way=='in'&&el.filters&&el.filters[0]? 100 : way=='in'? 1 : 0;
    var waym=way=='in'? 1 : -1;
    var optype=el.filters&&el.filters[0]&&typeof el.filters[0].opacity=='number'? el.filters[0] : el.style;
    var opinc=el.filters&&el.filters[0]? 20 : .2;
    if(/number|string/.test(typeof optype.opacity))
    {
        optype.opacity=optype.opacity*1 + opinc*waym;
    }
    else
    {
        return;
    }
    if(optype.opacity!=targ_op)
    {
        el.timer=setTimeout(function(){fade(el, way)}, 30);
    }
    else if(way!='in')
    {
       // el.style.display = 'none';
    }
}
/*
function ShowDiv(n)
{
    document.getElementById('pop_0' + n).style.display = 'block'; 
    document.getElementById('lightBox').style.display = 'block';
}

function HideDiv(n)
{
    document.getElementById('pop_0' + n).style.display = 'none'; 
    document.getElementById('lightBox').style.display = 'none'; 
}
*/

//////////////////////
function ShowHideField(f, add_subject)
{
    for (var i = 0; i < document.getElementById(f).length; i ++) 
    {
        if (document.getElementById(f).options[i].selected == true) 
        {
            if (document.getElementById(f).options[i].value == "")
            {
                document.getElementById(add_subject).style.display = '';
            }
            else
            {
                document.getElementById(add_subject).style.display = 'none';
            }
        }
    }
}

function HideField(add_subject)
{
    if(document.getElementById(add_subject) != null)
    {
        document.getElementById(add_subject).style.display = 'none';
    }
}

//////////////////////
function backToTop()
{
    window.scrollTo(0,0);     
}

function trim(str)
{
	try {
		return str.replace(/^\s+|\s+$/g,'');
	}
	catch (e) {
		return str;
	}
}
//////////////////////
function isnull(arg)
{
	arg = arg+'';
	return (arg == '' || arg == 'null' || arg == 'undefined');
}
//////////////////////
function nvl()
{
	for (var i=0; i<arguments.length; i++) {
		if (!isnull(arguments[i])) return arguments[i];
	}
	return null;
}	

//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function getHostAddress()
{
	var	urlPrefix		= getUrlPrefix();
	lastSlashPos		= urlPrefix.lastIndexOf('/');
	hostAddress			= urlPrefix.substring(0,lastSlashPos);
	
	return hostAddress;
}

function sendToAFriend(url,nPopupWinWidth, nPopupWinHeight, bPopupWinScrollbars, bPopupWinToolbar)
{
    var hostAddress = getHostAddress();
    var currLocation	=	window.location.href;
    var redirectUrl	=	url + "?linkURL=" + currLocation;
	window.open(redirectUrl, 'sendToFriend','width=' + nPopupWinWidth + ',height=' + nPopupWinHeight + ',scrollbars=' + bPopupWinScrollbars + ',toolbar=' + bPopupWinToolbar);
}

function getUrlPrefix()
{
	// cut all the url file & query suffix
	var	urlPath			= location.href.substring(0,location.href.indexOf('.aspx'));
	var lastSlashPos	= urlPath.lastIndexOf('/');
	var urlPrefix		= urlPath.substring(0,lastSlashPos);	
	
	return urlPrefix;
}
function ChangeSearchTabsclass(currentSearchType,mouseOverTab,obj)
{
    if(currentSearchType!=mouseOverTab)
    {
        obj.className='';
    }

}
var searchError=0;
var isAdvancedSearchOpen=0;
function searchExecute(textId, searchType)
{
    var searchTextObj = document.getElementById(textId);
	var text = searchTextObj.value;
	if(CheckIllegalCharacters(text) == false)
	{
	    alert(illegalTextError);
	    searchError=1;
	    return;
	}
	url = searchResultsUrl + "?searchText="+escape(text);
	
	if(searchType!=null && searchType=='EPG')
	    url+="&SearchType=EPG";

	if(isAdvancedSearchOpen==1)
	{
	    try
	    {
            url += "&AdvancedSearchOpen=1";
            var genreObj=document.getElementById(EpgSEClientId+"_ddlGenre");
            var genre,genreLbl;
            if(genreObj)
            {
                genre=genreObj.value;
                genreLbl=genreObj.options[genreObj.selectedIndex].text;
            }
            var year=document.getElementById(EpgSEClientId+"_txtYear").value;
            var countryObj=document.getElementById(EpgSEClientId+"_ddlCountries");
            var country,countryLbl
            if(countryObj)
            {
                country=countryObj.value;
                countryLbl=countryObj.options[countryObj.selectedIndex].text;
            }
            var dateFrom=document.getElementById(EpgSEClientId+"_txtDateFrom").value;
            var dateTo=document.getElementById(EpgSEClientId+"_txtDateTo").value;
            
            
            if(genre!=null && genre!='')
            {
                url+="&Genre="+genre;
                url+="&GenreLbl="+genreLbl;
            }
            if(year!=null && year!='')
                url+="&Year="+year;
            if(country!=null && country!='')
            {
               url+="&Country="+country;
               url+="&CountryLbl="+countryLbl;
            }
            if(dateFrom!=null && dateFrom!='')
                url+="&DateFrom="+dateFrom;    
            if(dateTo!=null && dateTo!='')
                url+="&DateTo="+dateTo;    
	    }
	    catch(e){alert(e.description)}
	}
	window.location.href	= url;
	
		
	//return true;
}


function changeChannelsClass(channel,divObj)
{
    var obj=document.getElementById(hidRequestedChannelId);
    if(obj && obj.value != channel)
    {
        divObj.className='luach_channels';
    }
}

function changeChannelsClass(channel,divObj)
{
    var obj=document.getElementById(hidRequestedChannelId);
    if(obj && obj.value != channel)
    {
        divObj.className='luach_channels';
    }
}
function changeDaysClass(day,divObj)
{
    var obj=document.getElementById(hidCurrentWDId);
    if(obj && obj.value != day)
    {
        divObj.className='tabs';
    }
}

function searchExecuteFromWord(text, url)
{
	url = url + "?searchText="+escape(text);
	window.location.href	= url;
		
	return true;
}

function CheckIllegalCharacters(sText)  // by string input.
{
    var ValidChars = "#$%^*/<>;[]{}|";
    
    var IsValid = true;
    var Char;
    var i;
    for (i = 0; i < sText.length && IsValid == true; i++) 
      { 
         Char = sText.charAt(i); 
         if (ValidChars.indexOf(Char) != -1) 
           {
              return false;
           }
       }
    return IsValid;
}
function clearSearchError(objId)
{
    var obj=document.getElementById(objId);
    if(obj)
        obj.innerHTML='';
//    if(searchError==1)
//    {
//        obj.value='';
//        searchError=0;
//    }
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
document.onkeypress	    = document_onEnterPress;
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function document_onEnterPress(e) 
{
	try
	{
	//debugger
	    var code        = (window.event) ? event.keyCode    : e.keyCode;
        var input       = (window.event) ? event.srcElement : e.target;
		if(input && code==13)
		{
            switch(input.id)
            {
               case 'Master_ucHeader_ucSearchBar_searchText': 
               case 'Master_ContentPlaceHolder1_ABC_Tabs1_searchProg': 
					searchExecute(input.id);
					return false; 
                    break; 
				case 'Master_ContentPlaceHolder1_txtEPGSearch':
				case 'Master_ContentPlaceHolder1_ucEpgSearch_txtSearch':
					searchExecute(input.id,'EPG');
                    return false; 
                    break; 
               case 'Master_ContentPlaceHolder1_txtSearch':
               case 'Master_ContentPlaceHolder1_ucGeneralSearchInner_txtSearch':
               {
                var obj=document.getElementById(hidSearchTypeId);
                if(obj && obj.value=='EPG')
                {
                    searchExecute(input.id,'EPG');
                    return false; 
                    break; 
                }
                else
                {
                searchExecute(input.id);
                    return false; 
                    break; 
                }
               }
               case 'Master_ContentPlaceHolder1_ucHomePageUc_Mailing_txtEmail':
               {
                   var obj=document.getElementById('Master_ContentPlaceHolder1_ucHomePageUc_Mailing_btnSendEmail');
                   if(obj)
                   {
                    obj.click();
                   }
                   break; 
               }     
               default:
                    //return false;
                    break; 
            }    
		}
    }
    catch(e){}
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function updateTachiVideoCounter(contentId,clipId)
{

    var imgVideoCounter=document.getElementById(imgVideoCounterId);
    if(imgVideoCounter)
    {
        var imgSrc=imgVideoCounterSrc+"?Type=1&ContentId="+contentId.toString();
        if(clipId!=null && clipId>0)
            imgSrc += "&clip="+clipId.toString();
        imgVideoCounter.src=imgSrc;
        
    }
        
}
function showTachiVideo(fileName)
{

    var iframeObj=document.getElementById(iframeId);
    if(iframeObj)
    {
        iframeObj.src=fileName;
        //iframeObj.style.display='';
    }
}
function showTachiContentDetails(clipName,clipAbstract,programName,chapterName,clipLength)
{
    try
    {
    document.getElementById(clipNameId).innerHTML=clipName;
    document.getElementById(clipAbstractId).innerHTML=clipAbstract;
    document.getElementById(programNameId).innerHTML=programName;
    document.getElementById(chapterNameId).innerHTML=chapterName;
    document.getElementById(clipLengthId).innerHTML=clipLength;
    }
    catch(e){};
    
}
function ShowChapterDetails(clipNameId,clipName,clipTimeId,clipTime,clipAbstractId,clipAbstract,iframeVideoId,iframeVideoSrc)
{
    var clipNameObj=document.getElementById(clipNameId);
    clipNameObj.innerHTML=clipName;
    var clipTimeObj=document.getElementById(clipTimeId);
    clipTimeObj.innerHTML=clipTime;
    var clipAbstractObj=document.getElementById(clipAbstractId);
    clipAbstractObj.innerHTML=clipAbstract;
    var iframeVideoObj=document.getElementById(iframeVideoId);
    iframeVideoObj.setAttribute("src",iframeVideoSrc);
    
}

function updateClipCounter(imgId,imgSrc,ContentId,clipId)
{
    var imgObj=document.getElementById(imgId);
    imgSrc+="?Type=1&ContentId="+ContentId+"&clip="+clipId;
    imgObj.src=imgSrc;
}



function ChangeChapterClass(objId)
{
    var obj=document.getElementById(objId);
    obj.className='selected';
    if(currentSelectedChapterId != '')
    {
        var prevObj=document.getElementById(currentSelectedChapterId);
        if(prevObj)
            prevObj.className='';
    }
    currentSelectedChapterId=objId;
}

function changeChapterItemClass(objId)
{
//alert(objId);
//alert(currentSelectedChapterId);
    if(objId!=currentSelectedChapterId)
    {
        var obj=document.getElementById(objId);
        obj.className='';
    }
}



/***********************************************************/
/* Accessability */
//Specify affected tags. Add or remove from list:

var tags = new Array( 'a', 'div','td','tr','p','th','span','li');

//Specify spectrum of different font sizes:
var sizes = new Array('11px','13px','14px','16px','18px');
var startSize = 1;

function resizeFont(target, incLevel)
{
    if (!document.getElementById) return
	var doc = document,cEl = null, currSize = startSize,i,j,cTags;
	
	currSize += incLevel;
	if ( currSize < 0 ) currSize = 0;
	if ( currSize > 4 ) currSize = 4;
	startSize = currSize;
	
	if ( !( cEl = doc.getElementById( target ) ) ) cEl = doc.getElementsByTagName( target )[ 0 ];

    //cEl.style.fontSize = sizes[ currSize ];

	for ( i = 0 ; i < tags.length ; i++ ) {
		cTags = cEl.getElementsByTagName( tags[ i ] );
		for ( j = 0 ; j < cTags.length ; j++ )
		{
		    cTags[ j ].style.fontSize = sizes[ currSize ];
		    cTags[ j ].style.height = "auto";
		    cTags[ j ].style.lineHeight = "normal";
		}
	}
}

var currDiffFont = 0;
function regularFont()
{
    if(currDiffFont == 0) return;
    resizeFont('body', -2)
    currDiffFont = 0;
    
    document.getElementById("ancRegularFont").className="regular active";
    document.getElementById("ancLargeFont").className="big";
}
function largeFont()
{
    if(currDiffFont == 2) return;
    resizeFont('body', 2);
    currDiffFont = 2;
    
    document.getElementById("ancRegularFont").className="regular";
    document.getElementById("ancLargeFont").className="big active";
}
function openAdvancedSearch(spanId,ancId)
{
    document.getElementById(spanId).style.display='';
    document.getElementById(ancId).style.display='none';
    isAdvancedSearchOpen=1;
}

function ToogleIconLink(obj,iconId,iconOff,iconOn,on)
{

    if(iconId != ""){
        var trg = document.getElementById(iconId);
        if(trg)
        {
            if(on) trg.src = iconOn;
            else  trg.src = iconOff;
            
            if(on) obj.className = "cat_on";
            else obj.className = "cat_off";
        }
    }

}






function openGame(u,w,h)
{
    ShowOverlayDiv(w,h)
    
    
    $(".kids_popup_print").hide()
    $(".kids_popup_full_screen").show()
    $(".kids_popup_cont").css("width",(w+30)+"px")
    $(".kids_popup_cont").css("height",(h+60+30)+"px")
    
    $(".kids_popup_cont").css("top","50%");
    $(".kids_popup_cont").css("left","50%");
    $(".kids_popup_cont").css("z-index","99");

		
	if(h > 700){
	    $(".kids_popup_cont").css("position","absolute");
        //$(".kids_popup_cont").css("top","20px");
	}
	else{	
	    $(".kids_popup_cont").css("position","fixed");
        $(".kids_popup_cont").css("marginTop","-" + $(".kids_popup_cont").height() / 2 + "px");
	}
	$(".kids_popup_cont").css("marginLeft","-" + $(".kids_popup_cont").width() / 2 + "px");
	
	if (isIE6())
	{
		$(".kids_popup_cont").css("position","absolute");
		if(h > 700)
		{
		    $(".kids_popup_cont").css("top","20px");
		}
		else
		{
		    $(".kids_popup_cont").css("top",(document.documentElement.scrollTop + ($(".kids_popup_cont").height()/2)) + ((window.screen.availHeight-$(".kids_popup_cont").height())/4) + "px");
		}
		$(".kids_popup_cont").css("left","50%");

	}
    
    $(".kids_popup_content").css("width",w+"px")
    $(".kids_popup_content").css("height",h+"px")
    $(".kids_popup_content").html("<iframe class='iframe_game' src='"+u+"' frameborder='0' scrolling='no' style='width:"+w+"px;height:"+h+"px;'></iframe>")
    $(".kids_popup_cont").show()
}
function openPaintingImage(u,w,h)
{
    ShowOverlayDiv(w,h)
    
    $(".kids_popup_print").show()
    $(".kids_popup_full_screen").hide()
    
    $(".kids_popup_cont").css("width",(w+30)+"px")
    $(".kids_popup_cont").css("height",(h+60+30)+"px")
    
    $(".kids_popup_cont").css("position","fixed");
    $(".kids_popup_cont").css("top","50%");
    $(".kids_popup_cont").css("left","50%");
    $(".kids_popup_cont").css("z-index","99");

    if(h > 700){
	    //$(".kids_popup_cont").css("position","absolute");
        //$(".kids_popup_cont").css("top","20px");
        $(".kids_popup_cont").css("position","fixed");
        $(".kids_popup_cont").css("marginTop","-" + ($(".kids_popup_cont").height() / 2 - 88) + "px");
	}
	else{	
	    $(".kids_popup_cont").css("position","fixed");
         $(".kids_popup_cont").css("marginTop","-" + ($(".kids_popup_cont").height() / 2 - 38) + "px");
	}
	
	$(".kids_popup_cont").css("marginLeft","-" + $(".kids_popup_cont").width() / 2 + "px");
	
	
	if (isIE6())
	{
		$(".kids_popup_cont").css("position","absolute");
		if(h > 700)
		{
		    $(".kids_popup_cont").css("top","20px");
		}
		else
		{
		    $(".kids_popup_cont").css("top",(document.documentElement.scrollTop + ($(".kids_popup_cont").height()/2)) + ((window.screen.availHeight-$(".kids_popup_cont").height())/4) + "px");
		}
		$(".kids_popup_cont").css("left","50%");

	}
    
    $(".kids_popup_content").css("width",w+"px")
    $(".kids_popup_content").css("height",h+"px")
    $(".kids_popup_content").html("<img class='kids_image_for_print' src='"+u+"' alt=''/>")
    
    $(".kids_popup_cont").show()
}
function closeKidsPopup()
{
    CloseOverlayDiv();
    $(".kids_popup_cont").hide()
    $(".kids_popup_content").html("");
}
function printKidsPopup()
{
    (window.open($(".kids_image_for_print").attr("src"),"pWin")).print()
}
function fullScreenKidsPopup()
{
    window.open($(".iframe_game").attr("src"),"fullWin")//,"fullscreen=yes"
    closeKidsPopup();
}
function isIE6()
{
	return window.navigator.appVersion.toUpperCase().indexOf("MSIE 6") > 0;
}

function ShowOverlayDiv(w,h)
{
    //if(w>910) return;
    
    if (isIE6())
	{
		var divBodyOverLay = document.getElementById("divBodyOverLay");
		$("#divBodyOverLay").css("position","absolute");
		$("#divBodyOverLay").css("width","100%");
		$("#divBodyOverLay").css("height",document.body.offsetHeight);
		$("#divBodyOverLay").css("top","0");
		$("#divBodyOverLay").css("left","0");
	}
	
	if(h > 800){
	    $("#divBodyOverLay").css("height",(h+200) + "px");
	}
	
	$("#divBodyOverLay").show()
}
function CloseOverlayDiv()
{
	$("#divBodyOverLay").hide()
}

function CheckIfIDisValid(source, arg)
{
//debugger
		var id=arg.Value;
		var isLegal=true;
		var digit;
		var bikoret;
		var mul=2;
		var sum=0;
		if(id=='')
			isLegal=false;
		for(var i=id.length;i<=9;i++)
		{
		    id="0"+id;
		}	
		bikoret=parseInt(id.substring(id.length-1,id.length));
		if (bikoret<0 || bikoret>9)
			isLegal=false;
		for(var i=id.length-2;i>=0;i--)
		{
			digit=parseInt(id.substring(i,i+1));
			if (digit<0 || digit>9)
				isLegal=false;
			digit*=mul;
			if (digit>9)
				digit-=9;
			sum+=digit;
			mul=3-mul;
		}
		if (isLegal==true)
		{
			if((sum+bikoret) %10==0)
				isLegal=true;
			else
				isLegal=false;
		}		
		if (isLegal==true)
			arg.IsValid=true;
		else
			arg.IsValid=false;	
      }

function CheckConfirm(source,arg)
{
    var chk=document.getElementById(chkConfirmId);
    if(chk && chk.checked==true)
    {
        arg.IsValid=true;
    }
    else
    {
        arg.IsValid=false;
    }
}
//////////////////////////////

