﻿//AddComment.js
function ShowJeeranAccountOptions(LoggedIn){
    if (LoggedIn == false)
    {
        document.getElementById('JeeranAccountDiv').style.display='block';
        document.getElementById('OtherOptionsDiv').style.display='none';
    }
    else
    {
        document.getElementById('OtherOptionsDiv').style.display='none';
    }    
}

function ShowOtherOptions(){
    document.getElementById('OtherOptionsDiv').style.display='block';
    if (IsLoggedIn == 'False')
    {
        document.getElementById('JeeranAccountDiv').style.display='none';
    }
}

function ToggleComments(){
    var CommentsDiv=document.getElementById('PostComments');
    var CommentsStateSpan=document.getElementById('StateSpan');
    var CommentsCountDiv=document.getElementById('CommentsCount');
    if(CommentsDiv.style.display=='none')
    {
           CommentsDiv.style.display='block' ;  
           CommentsStateSpan.innerHTML=CommentsStateSpan.innerHTML.replace('+','-');  
           CommentsCountDiv.title="-";
    }
    else
    {
           CommentsDiv.style.display='none' ; 
            CommentsStateSpan.innerHTML= CommentsStateSpan.innerHTML.replace('-','+'); 
            CommentsCountDiv.title="+";
    }
}

/// Add smiley to the textbox - Eyad Salah - Case# 3606 - V[2.s.0] - 8/29/2007
function addSmiley(textField, text){
    var textBox = j$Obj(textField);
    textBox.value += " " + text;
}

//BlogSlider.js
var CurrentBox = 1;
var NextBox = CurrentBox;
var Timmer = 15000;
var Play = true;
var TotalBoxes = 1;

function funcChangeSliderStatus(PlayTitle, PauseTitle)
{
    Play=!Play; 
    if(Play)
     {
        //play
        j$Obj('PlayPauseImage').src = "/im/blogs/NewDesign/Pause.gif";
        j$Obj('PlayPauseImage').title = PauseTitle;
        funcGetNextDiv('Next', TotalBoxes);
     }
    else
     {
        //pause
        j$Obj('PlayPauseImage').src="/im/blogs/NewDesign/Play.gif";
        j$Obj('PlayPauseImage').title = PlayTitle;
     }
}

function funcChangeBox(action, NumberOfBoxes)
{   
    if(NumberOfBoxes>1)
    {        
        if(action=='Next')
        {
            if(CurrentBox==NumberOfBoxes) NextBox = 0;
            NextBox++;
        }
        else if(action=='Previous')
        {                        
            if(CurrentBox==1) NextBox = NumberOfBoxes+1;
            NextBox--;
        }
        //alert(CurrentBox + ' ' + NextBox);   
        
	    j$Obj('BlogSliderDiv' + NextBox).style.zIndex = NumberOfBoxes;
	    opacity('BlogSliderDiv' + NextBox , 0, 100, 1000);
	    j$Obj('BlogSliderDiv' + CurrentBox).style.zIndex = NumberOfBoxes-1;
	    setTimeout("opacity('BlogSliderDiv" + CurrentBox + "', 100, 0, 500)",500);
	    CurrentBox = NextBox ;    
    }
}


function PlayBlogSlider(action, NumberOfBoxes)
{    
    TotalBoxes = NumberOfBoxes;
    setTimeout(function(){funcGetNextDiv(action, NumberOfBoxes)},Timmer);    
}

function funcGetNextDiv(action, NumberOfBoxes)
{    
    if(Play)
    {
        funcChangeBox(action, NumberOfBoxes);
        setTimeout(function(){funcGetNextDiv(action, NumberOfBoxes)},Timmer);        
    }
}

function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

    //Categories.js
    function Categories()
    {
        AllPosts="";
        CategoryPosts="";

        for (var i=0; i < document.forms[0].elements.length; i++) 
        {
            if ((document.forms[0].elements[i].name.indexOf('formAllPosts') > -1)) 
            {
                AllPosts=document.forms[0].elements[i];
               
            }
             if ((document.forms[0].elements[i].name.indexOf('formCategoryPosts') > -1)) 
            {
                CategoryPosts=document.forms[0].elements[i];
               
            }
        }

        AllPosts.ondblclick=AddPost;
        CategoryPosts.ondblclick=RemovePost;
    }
    
    function GetSelectedPosts()
    {
        document.forms[0].formSelectedPosts.value="";
        for(var i=0;i<CategoryPosts.options.length;i++)
        {
            document.forms[0].formSelectedPosts.value += CategoryPosts.options[i].value; 
            if(i != CategoryPosts.options.length-1)
            {
                document.forms[0].formSelectedPosts.value +=",";   
            }
        }
    }
    
   function AddPost()
   {
   var Index=AllPosts.selectedIndex;
  
    for(var i=0;i<AllPosts.length;i++)
    {
        if(AllPosts.options[i].selected)
        {
            var NewElement=document.createElement("option");
            NewElement.text=AllPosts.options[i].text;
            NewElement.value=AllPosts.options[i].value;
           

            try 
            {
            CategoryPosts.add(NewElement, null); // standards compliant; doesn't work in IE
            }
            catch(ex)
            {
              CategoryPosts.add(NewElement, 0); // IE only
            }
          
           
        }
    }
    
    
    while(AllHasSelected())
    {
        for(var i=0;i<AllPosts.length;i++)
        {
            if(AllPosts.options[i].selected)
            {
                AllPosts.remove(i);
               
            }
        }
   
    }

    if(Index<AllPosts.length){
    AllPosts.selectedIndex=Index;
    }
    else{
    AllPosts.selectedIndex=AllPosts.length-1;
    }
   CategoryPosts.selectedIndex=0;
       
       
   }
   
   function AllHasSelected()
   {
     for(var i=0;i<AllPosts.length;i++)
        {
            if(AllPosts.options[i].selected)
            {
                return true;
            }
        }
        
        return false;
   
   }
   
   function CategoryHasSelected()
   {
     for(var i=0;i<CategoryPosts.length;i++)
        {
            if(CategoryPosts.options[i].selected)
            {
                return true;
            }
        }
        
        return false;
   
   }
   
   function RemovePost()
   {
    var Index=CategoryPosts.selectedIndex;
   for(var i=0;i<CategoryPosts.length;i++)
    {
        if(CategoryPosts.options[i].selected)
        {
        var NewElement=document.createElement("option");
        NewElement.text=CategoryPosts.options[i].text;
        NewElement.value=CategoryPosts.options[i].value;
        
        try 
        {
        AllPosts.add(NewElement, null); // standards compliant; doesn't work in IE
        }
        catch(ex)
         {
          AllPosts.add(NewElement, 0); // IE only
         }
        }
    }
        
         while(CategoryHasSelected())
         {
            for(var i=0;i<CategoryPosts.length;i++)
            {
                if(CategoryPosts.options[i].selected)
                {
                   CategoryPosts.remove(i);
                   
                }
            }
   
         }

        AllPosts.selectedIndex=0;
         if(Index<CategoryPosts.length){
        CategoryPosts.selectedIndex=Index;
        }
        else{
        CategoryPosts.selectedIndex=CategoryPosts.length-1;
        }
   
   }
   

//Cloud.js
function trimAll(sString){
    
    while (sString.substring(0,1) == ' '){
        sString = sString.substring(1, sString.length);
    }
    
    while (sString.substring(sString.length-1, sString.length) == ' '){
        sString = sString.substring(0,sString.length-1);
    }
    
    return sString;
}

function Search(SearchField){
    var Tag = trimAll(j$Obj(SearchField).value);
    if(Tag.length >= 2){
        document.location= SearchPage + Tag.replace('/','') + "/?lang=" + lang;
        return true;
    } 
    return false;
}

function StopPostBack(e, textBoxID){
    var key = window.event ? e.keyCode : e.which;
    if(key == 13 && j$Obj(textBoxID).value.length >= 2){
        Search(textBoxID);
    }
    e.returnValue = false; 
    e.cancel = true; 
    e.cancelBubble = true;
    //e.preventDefault();
}

/// Replacement for ajax control extenders - Eyad Salah - Case# 3607 - 9/4/2007
function ShowTagsAutoComplete(textBoxID, prefix, count, e, serviceUrl){
    StopPostBack(e, textBoxID);
    
    var tagsList = j$Obj('tagsList');
    var tagsAutoCompleteRequest = CreateAjaxRequest(serviceUrl +'&prefix=' + prefix + "&count=" + count, "POST", "");
    tagsAutoCompleteRequest.OnLoaded = function(){
        var tags = tagsAutoCompleteRequest.GetText().split(",");
        
        tagsList.style.left = j$Obj(textBoxID).style.left;
        tagsList.style.top = j$Obj(textBoxID).style.top + j$Obj(textBoxID).style.height;
        //tagsList.style.width = j$Obj(textBoxID).style.width;
        
        //Clear the list
        while(tagsList.firstChild){
            tagsList.removeChild(tagsList.firstChild);
        }
        if(tags[0] == "false"){
            showHide(false);
            j$Obj(textBoxID).focus();
            return false;
        }

        //Fill the list with new data
        for(var i=0; i<tags.length - 1; i++){
            var option = document.createElement('option');
            option.appendChild(document.createTextNode(tags[i]));
            option.setAttribute('value', tags[i]);
            tagsList.appendChild(option);
        }
        
        showHide(true);
        return true;
    }   
    tagsAutoCompleteRequest.OnFailure = function(){
        showHide(false);
        j$Obj(textBoxID).focus();
        return false;
    }
}

/// Show or hide auto complete list - Eyad Salah - 10/7/2007
function showHide(autoCompleteHasFocus){
    if(autoCompleteHasFocus){
        j$Obj('tagsList').style.visibility = 'visible';
    }
    else{
        j$Obj('tagsList').style.visibility = 'hidden';
    }
}

/// fill the text field with the selected item from the auto complete list - Eyad Salah - Case# 3653 - 9/6/2007
function selectMe(e, textBoxID){
    // Called to fill
    if(e == null){
        showMe(true, textBoxID);
        var tagsList = j$Obj('tagsList');
        
        //Clear the list
        while(tagsList.firstChild){
            tagsList.removeChild(tagsList.firstChild);
        }
        //And hide it
        showHide(false);
        j$Obj(textBoxID).focus();
    }
    // Called to fill if the "return" key was pressed
    else if((e && e.keyCode == 13) || (e.which && e.which == 13)){
            showMe(true, textBoxID);
    }
}

/// When selecting an item from the auto complete it's shown in the text field - Eyad Salah - Case# 3653 - 9/6/2007
function showMe(close, textBoxID){
    var tagsList = j$Obj('tagsList');
    if(tagsList.firstChild && tagsList.selectedIndex > -1){
        j$Obj(textBoxID).value = tagsList.options[tagsList.selectedIndex].value;   
        if(close){
            showHide(false);
            j$Obj(textBoxID).focus();
        }
    }
}

// Only select the top option
function SelectOptionTop(iPick){
    var tagsList = j$Obj('tagsList');
    var intSpot  = iPick + tagsList.size - 1;
    if(tagsList.options.length>intSpot){
        tagsList.selectedIndex = intSpot;
    }
    tagsList.selectedIndex = iPick;
}

/// When pressing the down arrow key, the dropdown list is automatically activated - Eyad Salah - Case# 3653 - 9/6/2007
function Move2AutoComplete(e){
    try{
        if(e && e.keyCode == 40){
            j$Obj('tagsList').focus();
        }
        else if(e.which && e.which == 40){
            j$Obj('tagsList').focus();
        }
        else if(e && e.keyCode == 13){
            e.returnValue = false; 
            e.cancel = true; 
            e.cancelBubble = true;
            e.preventDefault();
        }
        else if(e.which && e.which == 13){
            e.returnValue = false; 
            e.cancel = true; 
            e.cancelBubble = true;
            e.preventDefault();
        }
    }
    catch(err){}
}

//Common.js
function SwitchStyleClass(Obj, NewClass)
{
    Obj.className = NewClass;
}

//jb.js
var jblog = true;
function EmailPost(PageURL){
var x=screen.availWidth/2-125;
var y=screen.availHeight/2-225;
window.open(PageURL,"","width=300,height=550,location=0,toolbar=0,resizable=1,scrollbars=0,screenX="+x+",left="+x+",screenY="+y+",top="+y);
}
function AddComment(PageURL){
var x=screen.availWidth/2-350;
var y=screen.availHeight/2-250;
window.open(PageURL,"","width=720,height=600,location=0,toolbar=0,resizable=1,scrollbars=1,screenX="+x+",left="+x+",screenY="+y+",top="+y);
}
/* News marquee - NawwarG 18.08.2008 */
 function InitializeMarquee()
  {
  
    var xhr;

  if (window.ActiveXObject) //IE
        xhr = new ActiveXObject("Microsoft.XMLHTTP");
    else if (window.XMLHttpRequest) //other
    {
        xhr = new XMLHttpRequest();
    }
    else
        alert("your browser does not support AJAX");

    
     xhr.open("GET","/news.xml",true);
  
   

      xhr.setRequestHeader("Cache-Control", "no-cache");
      xhr.setRequestHeader("Pragma", "no-cache");

    xhr.onreadystatechange = function() {
        if (xhr.readyState == 4)
        {
            if (xhr.status == 200)
           {
               /*F*/
                if (xhr.responseText != null)
                    processRSS(xhr.responseXML);
               
            }
        }
    }
     xhr.send(null);
 }
 
function processRSS(rssxml)
{
    showRSS(rssxml);
}

function showRSS(rssxml)
{
  
    var itemElements = rssxml.getElementsByTagName("item");


   for (var i=0; i<itemElements.length; i++)
  {
        if (window.ActiveXObject) //IE
        {       
                if (itemElements[i].nodeType == 1)//ignore white spaces
                {
                   var item='<a class="MarqueeText" href="' + itemElements[i].getElementsByTagName("link")[0].firstChild.text  + ' " >';
                   item+=  itemElements[i].getElementsByTagName("title")[0].firstChild.text ;
                   item+='</a> ...      ';
                   var items = document.getElementById("items");
                   items.innerHTML+=item;
                }
        }
        else
        {
             if (itemElements[i].nodeType == 1)//ignore white spaces
             {
                var item='<a class="MarqueeText" href="' +   itemElements[i].getElementsByTagName("link")[0].firstChild.textContent  + ' " >';
               item+= itemElements[i].getElementsByTagName("title")[0].firstChild.textContent ;
               item+='</a> ...      ';
               var items = document.getElementById("items");
               items.innerHTML+=item;
                      
             }
        }

  }

}