﻿// JScript File
function trim(str)
{
return str.replace(/^\s+/, '');

}
function ChangeBackground(oSpan, isOver){
    if(isOver == 'true')
    {
     oSpan.src =  oSpan.src.replace('normal','over');
     }
     else
     {
        oSpan.src =  oSpan.src.replace('over','normal');
     }
}
    
 function CloseMore(CloseMoreID, OpenLink){ 
 
    var oCloseMore = document.getElementById(CloseMoreID);
    var oOpenMore = document.getElementById(OpenLink);
    oOpenMore.style.display = 'block';
    oCloseMore.style.display = 'none';
    
 }
 
 function openMore(oOpenLink, CloseMoreID){
    var oCloseMore = document.getElementById(CloseMoreID);
    var oOpenLink = document.getElementById(oOpenLink); 
    oOpenLink.style.display = 'none';
    oCloseMore.style.display = 'block';
} 

function openDiv(divID, oLINK, sCloseBox, sOpenBox){
    
    var oDIV = document.getElementById(divID);
    
    if (oDIV.style.display == 'block'){
        oDIV.style.display = 'none';
        oLINK.innerHTML = sOpenBox;
        return;
    }    
    
    
    var coord = findElementCoords(oLINK);
    oLINK.innerHTML = sCloseBox;
    
     
    oDIV.style.left = (coord[0] - 80)+"px";;
    oDIV.style.top = coord[1]+oLINK.offsetHeight+"px";;
    oDIV.style.display = 'block';
}

//multipleContent
function ReplaceContent(DivClicked,itemPostingGuid,ShowIDInFullItem,IsRightItemsVideoAutoPlay, count, PageName)
{   
    var frame = document.getElementsByTagName('iframe');
    document.title = 'TASE TLVInsider-' + PageName;
    if(frame[0])
    {
        frame[0].src = "";
    }
    document.getElementById('MultiplePageName').style.display = 'block';
    document.getElementById('breadCrumbImage').style.display = 'block';
    document.getElementById('MultiplePageName').innerHTML = PageName;
    var divLoading = document.getElementById(dynamicContent);
  
    for (var i = 0; i < count; i++){
        try{
            document.getElementById('RightNavDivID'+i).style.backgroundColor = '#e6e6e6';
            document.getElementById('RightNavDivID'+i+'Arrow').style.display = 'none';
            document.getElementById('RightNavDivID'+i+'Title').style.color = 'black';
        }
        catch(ex){}
    }
    var oDivClicked = document.getElementById(DivClicked);
    oDivClicked.style.backgroundColor = 'white';
    document.getElementById(DivClicked+'Arrow').style.display = 'block';
    document.getElementById(DivClicked+'Title').style.color = '#004b85';
     PrintGUID = itemPostingGuid;
   AJAX.asyncWithCallback( '/TlvInsider/Services/GetMultiContentItemByGuid.ashx', 'Guid='+itemPostingGuid+'&showId='+ShowIDInFullItem+'&vAuto='+IsRightItemsVideoAutoPlay,'HandleReplaceContent', true, false, divLoading)
}

function HandleReplaceContent(htmlString)
{
   
    document.getElementById(dynamicContent).innerHTML = htmlString;
}
function showMoreId(showHide)
{
    if(showHide == 'true')
    {
        document.getElementById('moreId').style.display = '';
        document.getElementById('CloseMore').style.display = '';
    }
    else
    {
      document.getElementById('moreId').style.display = 'none';
      document.getElementById('CloseMore').style.display = 'none';
    }
}


function highlightIssueMore(rowID)
{



    openPreviousDiv(document.getElementById('PrevIssuesBtn'));
    if(rowID.id)
    {
        //document.getElementById(rowID.id).style.backgroundColor="#FFFFFF";
        document.getElementById(rowID.id).className = "IssueSelectedMore";
        currentCityIndex = rowID.id;
    }
    else
    {
       
        //document.getElementById(rowID).style.backgroundColor="#FFFFFF";
        if( document.getElementById(rowID) != null)
        {
            document.getElementById(rowID).className = "IssueSelectedMore";
            currentCityIndex = rowID;
         }
    }
}


function highlightIssue(rowID)
{
  

    openPreviousDiv(document.getElementById('PrevIssuesBtn'));
    if(rowID.id)
    {
        //document.getElementById(rowID.id).style.backgroundColor="#FFFFFF";
        document.getElementById(rowID.id).className = "IssueSelected";
        currentCityIndex = rowID.id;
    }
    else
    {
       
        //document.getElementById(rowID).style.backgroundColor="#FFFFFF";
        if( document.getElementById(rowID) != null)
        {
            document.getElementById(rowID).className = "IssueSelected";
            currentCityIndex = rowID;
         }
    }
}

function lowlightIssueMore(rowID)
{

    if(rowID.id)
    {
        //document.getElementById(rowID.id).style.backgroundColor="rgb(219 , 238 , 255)";
        document.getElementById(rowID.id).className = "IssueNormalMore";
        currentCityIndex = rowID.id;
    }
    else
    {
               if( document.getElementById(rowID) != null)
               {
        //document.getElementById(rowID).style.backgroundColor="rgb(219 , 238 , 255)";
                document.getElementById(rowID).className = "IssueNormalMore";
                currentCityIndex = rowID;
        }
        
    }
}


function lowlightIssue(rowID)
{

    if(rowID.id)
    {
        //document.getElementById(rowID.id).style.backgroundColor="rgb(219 , 238 , 255)";
        document.getElementById(rowID.id).className = "IssueNormal";
        currentCityIndex = rowID.id;
    }
    else
    {
               if( document.getElementById(rowID) != null)
               {
        //document.getElementById(rowID).style.backgroundColor="rgb(219 , 238 , 255)";
                document.getElementById(rowID).className = "IssueNormal";
                currentCityIndex = rowID;
        }
        
    }
}

function IssueSelected(Urlvalue)
{
       
    
  
   
    window.location.href = Urlvalue;
}

function hideCitiesDiv()
{

    var IssuesElem = document.getElementById(prevId);
    IssuesElem.style.display = "none";
   
    currentCityIndex = null;
}

function findElementCoords(obj) 
{

	var curleft = curtop = 0;
	if (obj.offsetParent) 
	{
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		while (obj = obj.offsetParent)            
		{
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
	}
	
	return [curleft,curtop];
}

function openPreviousDiv(objSpan)
{

//    if(document.getElementById(prevId).style.display != 'none')
//    {
//        document.getElementById(prevId).style.display = 'none';
//        return;
//    }
   
   var inputCoords = findElementCoords(objSpan);
  
      document.getElementById(prevId).style.display = "block";
   
     document.getElementById(prevId).style.left  = inputCoords[0]+"px";
     document.getElementById(prevId).style.top  = inputCoords[1]+objSpan.offsetHeight+"px";
     document.getElementById(prevId).style.width = objSpan.offsetWidth - 5  ;
     isOpened = true;
     event.cancelBubble = true;
}


function closeDiv(){
//alert(event.srcElement.tagName);
   if (isOpened){
        if (event.srcElement.tagName.toUpperCase() == 'DIV'){
            document.getElementById(prevId).style.display = 'none';
            isOpened = false;
        }    
            
    }
}

function keyboardFunc(e,id)
{
         
         
    var keynum;
    var keychar;
    var numcheck;
    if(window.event) // IE
      {
        keynum = e.keyCode;
      }
    else if(e.which) // Netscape/Firefox/Opera
      {
        keynum = e.which;
      }
    switch(keynum)
    {
    //enter
        case 13:
               
            if(currentCityIndex)
            {
                var elem = document.getElementById(currentCityIndex);
                
                //citySelected(elem.innerHTML,id,elem.title);
                citySelected(elem.innerHTML,id,elem.getAttribute("cityCode"));
            }
        break;
        //key up
        case 38:
            
            if(currentCityIndex)
            {
                var num = new Number(currentCityIndex.slice(3));
                
                if( num > 1 )
                {
                    lowlightIssue(currentCityIndex);
                    highlightIssue("li_" + (--num));
                }
            }
            
        break;
        //key down
        case 40:
            
            if(currentCityIndex)
            {
                var num = new Number(currentCityIndex.slice(3));
                var citiesElem = document.getElementById("Cities");
                if( num < citiesElem.childNodes.length )
                {
                    lowlightIssue(currentCityIndex);
                    highlightIssue("li_" + (++num));
                }
            }
            else
            {
                highlightIssue("li_1");
            }
           
        break;
        default:
        break;
    }
    
}
function IsParamValid(text,maxLen)
{

    var strErr ='';
   var blackList = '#*#>#<#|#alter#delete#drop#exec#truncate#select#insert#update#script#xp_#--##sp_#';
    //alert(text);
    var arrayBlackList = blackList.split('#');
    if(text.length > maxLen)
    {
        strErr = 'Search text is too long';
    }
    
   if(trim(text).length < 1 || text == '')
   {
    strErr = 'Search value not entered'
   }
  
   for(var i = 0 ; i < arrayBlackList.length ; i++)
   {
        var item = arrayBlackList[i].toLowerCase();
        if(item  != '' && item.length > 0 &&  text.toLowerCase().indexOf(item) > -1)
        {
               oSearchTxt.style.color = "white";
               oSearchTxt.value = "no results and neve will be";
        }
   }
   
    if(strErr != '')
    {
       alert(strErr);
       return false;
    }
    
    return true;
}

	function PrintPage(){
	   try{
	       var sName = document.getElementById(NameTxt);
	       var sEmailTxt = document.getElementById(EmailTxt);
	       var sPositionTxt = document.getElementById(PositionTxt);
	       var sOrganizationTxt = document.getElementById(OrganizationTxt);

	       var sCountryTxt = document.getElementById(CountryTxt);
	       var sAddressTxt = document.getElementById(AddressTxt);
	       var sPhoneTxt = document.getElementById(PhoneTxt);
	       var sCommentTxt = document.getElementById(CommentTxt);
           var win = window.open(window.location.href + '?isPrint=true&Nametxt=' + sName.value + '&EmailTxt=' + sEmailTxt.value + '&PositionTxt=' + sPositionTxt.value + '&OrganizationTxt=' + sOrganizationTxt.value + '&CountryTxt=' + sCountryTxt.value + '&AddressTxt=' + sAddressTxt.value + '&PhoneTxt=' + sPhoneTxt.value + '&CommentTxt=' + sCommentTxt.value, "printWindow", 'status=no,scrollbars=yes, menubar=no, location=no ', '');
       }
       catch(e){
            try{
                var sName = document.getElementById(NameTxt);
	            var sEmailTxt = document.getElementById(EmailTxt);
                var win = window.open(window.location.href + '?isPrint=true&Nametxt=' + sName.value + '&EmailTxt=' + sEmailTxt.value , "printWindow", 'status=no,scrollbars=yes, menubar=no, location=no ', '');
            }
            catch(ex){
                var win = window.open(window.location.href + '?isPrint=true&PrintGUID=' + PrintGUID, "printWindow", 'width=850px, scrollbars=1, height=800px', '');
            }
       }
    }