﻿/// <reference path="/_layouts/jQuery/jquery-1.4.1.min.js" />
var isIE6 = window.navigator.appVersion.indexOf('MSIE 6.0') > 0;
var toscan;

function $Get( objId ) { return document.getElementById( prefix + objId ) }
function $Set( objId, value ) { if($Get( objId )) $Get( objId ).value = value }
function Trim( STRING )
{
    STRING = LTrim( STRING );
    return RTrim( STRING );
}

function RTrim( STRING )
{
    while( STRING.charAt( ( STRING.length -1 ) ) == " " )
    {
        STRING = STRING.substring( 0, STRING.length - 1 );
    }
    return STRING;
}

function LTrim( STRING )
{
    while( STRING.charAt == " " )
    {
        STRING = STRING.replace( STRING.charAt, "" );
    }
    return STRING;
}

function TextCounter( e, maxlimit, txtRemainsLength, vText ) 
{
    var txtRemain = $Get( txtRemainsLength );
    var txt = $Get(vText);

    if (txt.value.length > maxlimit) {
        txt.value = txt.value.substring(0, maxlimit);
        txtRemain.value = maxlimit - txt.value.length;
    }
    else
        txtRemain.value = maxlimit - txt.value.length;
    var keycode = (document.all) ? e.keyCode : e.which;
    //if (keycode == 13 && !document.all) {
    //    txt.value = txt.value + '\n';
    //    return false;
    //}
    return true;
}

function ShowIden(e)
{
	if ( e.shiftKey && e.ctrlKey && (e.keyCode == 90 || e.keyCode == 122) ) 
		document.getElementById('Iden').style.display = 'block';
}

function QA_ShowHide(obj)
{
//	alert(obj.className);
//	alert(obj.parentNode.className);
//	alert(obj.parentNode.childNodes[1].className);
//	for (var i = 0; i < obj.parentNode.childNodes.length; i++)
//		alert(obj.parentNode.childNodes[i].className);
    if (obj.parentNode.childNodes[ document.all ? 1 : 3 ].style.display == 'block')
    {
    	obj.parentNode.style.backgroundColor = 'transparent';
        obj.className = 'QaIconPlus';
        obj.parentNode.childNodes[ document.all ? 1 : 3 ].style.display = 'none';
    }
    else
    {
    	obj.parentNode.style.backgroundColor = '#F1FAFF';
        obj.className = 'QaIconMinus';
        obj.parentNode.childNodes[ document.all ? 1 : 3 ].style.display = 'block';
    }
}
/**** Search Engine ************/
function MyGoSearch() 
{
	//debugger;
	var base = window.location.href.substring(0, window.location.href.indexOf("/"))	
	window.location.href = base + "/Pages/searchresult.aspx?k=" 
		+ document.getElementById('txtGoSearch').value.replace('הקלד טקסט לחיפוש','');  
}

function getParameter( name )
{ 
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]" + name + "=([^&#]*)"; 
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href ); 
	return ( results == null ) ? "" : results[ 1 ];
}

function setScope(scopeName)
{
	tmp = window.location.href;
	if ( ! tmp.match( "s=" ) )
	{
		if ( tmp.indexOf( "?" ) < 0 )
			window.location = tmp + "?s=" + scopeName;
		else
			window.location = tmp + "&s=" + scopeName;
	}
	else
	{
	    str = getParameter('s');
	    if( str != scopeName )
	    {
			tmp = tmp.substring( 0, (tmp.indexOf( '&s=' ) > 0) ? tmp.indexOf( '&s=' ) : tmp.indexOf( '?s=' ) );
			if ( tmp.indexOf( "?" ) < 0 )
				window.location = tmp + "?s=" + scopeName;
			else
				window.location = tmp + "&s=" + scopeName;
		}
	}
}
/*****************************/

// Used For TlvListGridField, developed for Mashov Component, used for display mode.
function SetTable( objId )
{
	var obj = document.getElementById(objId);
	if (obj == null || obj.innerHTML == '')
		return;
	var sValues = obj.innerHTML.split('^');
	if (sValues.length <= 1)
		return;
	var outputStr = "<table border='0' class='TlvGridDisplay_Table' cellspacing='0' cellpadding='2'>";
	var i = 0;
	for ( ; i < sValues.length; i++) 
		outputStr = outputStr + "<tr><td  class='TlvGridDisplay_IdCell' ><span>" + (i + 1) + "</span></td><td class='TlvGridDisplay_ValueCell' ><span>" + sValues[i] + "</span></td></tr>";
	outputStr = outputStr + "</table>";
	obj .innerHTML = outputStr;
}
/***** Run of F template Pages And Hide empty blocks by given tag and classes collection "|classA|classB|classC|" ***************/
function HideEmptyElementsByClassName( sTagName, sClassesNames )
{
	var divWorkArea = document.getElementById('ta-rightDiv');
	if ( ! divWorkArea )
		return;
    var elem = divWorkArea.getElementsByTagName( sTagName );
    if ( elem && elem.length > 0 )
    {
	    for( i = 0; i < elem.length; i++ )
	    {
	        if ( sClassesNames.indexOf( '|' + elem[ i ].className + '|' ) < 0 || elem[ i ].style.display == 'none' )
			    continue;
			if ( DoesMyElementEmpty( elem[ i ] ) )
			{
				var HideMyParent = false;			    
				elem[ i ].style.display = 'none';
			    // Check if to hide My Parent 
				if ( elem[ i ].parentNode.id.indexOf('Paragraph') >= 0 )
				{
					HideMyParent = true;
					var s = 0;
					for( s = 0; s < elem[ i ].parentNode.childNodes.length; s++ )
					{
						// FireFox childNodes is all depth of tree, and we want to check the first level only.
						if ( elem[ i ].parentNode.childNodes[ s ].nodeName == '#text' && navigator.appName.indexOf('Netscape') >= 0 )
						{
							if ( ! DoesMyElementEmpty(elem[ i ].parentNode.childNodes[ s ]) )
							{
								 HideMyParent = false;
								 break;
							}							
							else
								continue;	
						}
							
						if ( elem[ i ].parentNode.childNodes[ s ].style.display != 'none' )
						{
							 HideMyParent = false;
							 break;
						}							
					}
				}
				if ( HideMyParent == true && elem[ i ].parentNode.id != 'ta-rightDiv' )
					elem[ i ].parentNode.style.display = 'none';
			}
	    }
    }
}
function DoesMyElementEmpty( obj ) 
{
	if ( obj.innerHTML )
	{
		if ( obj.innerHTML.indexOf('img') >= 0 || obj.innerHTML.indexOf('IMG') >= 0 )
			return false;
		else
			return ( Trim( obj.innerHTML.replace(/<(.|\n)+?>/g,'').replace(/<\/[a-zA-Z]*>/g,'').replace( /[&nbsp;]/g, '' ).replace(/\r/g, "").replace(/\n/g, "").replace(/\t/g, "") ) == '' )
	}
	else if ( obj.nodeValue )
	{
		if ( obj.nodeValue.indexOf('img') >= 0 || obj.nodeValue.indexOf('IMG') >= 0 )
			return false;
		else
			return ( Trim( obj.nodeValue.replace(/<(.|\n)+?>/g,'').replace(/<\/[a-zA-Z]*>/g,'').replace( /[&nbsp;]/g, '' ).replace(/\r/g, "").replace(/\n/g, "").replace(/\t/g, "") ) == '' )
	}
	else
		return true;
}

function getFileExtension(filename) 
{ 
  var ext = /^.+\.([^.]+)$/.exec(filename); 
  return ext == null ? "" : ext[1]; 
} 

//function CloseModalImagePreview(obj)
//{
//    if ( document.getElementById('TlvImgPreviewIframe') )
//        document.getElementById('TlvImgPreviewIframe').style.display = 'none';
//    document.getElementById('shimImagePreview').style.display = 'none';
//    obj.style.visibility = 'hidden'; 
//    obj.style.display = 'none';
//}
//function ModalImagePreview(obj)
//{
//    if ( ! document.getElementById('TlvImgPreviewIframe') )
//    {	
//        if( isIE6 )
//        {
//            var iframe = document.createElement('iframe'); 
//            iframe.setAttribute("id", "TlvImgPreviewIframe"); 
//            iframe.setAttribute("src", "javascript:false"); 
//            iframe.style.position = 'absolute';   
//            iframe.style.top = '0px';   
//            iframe.style.left = '0px';   
//            iframe.style.zIndex = 99; 
//            iframe.style.width = '100%';
//            iframe.style.height = document.body.clientHeight + 'px';
//            document.body.appendChild(iframe);
//        }
//    }
//    else
//    	document.getElementById('TlvImgPreviewIframe').style.display = 'block';
//    	
//    if ( ! document.getElementById( 'shimImagePreview' ) )
//    {
//        var shimDiv = document.createElement( 'div' );
//        shimDiv.id = 'shimImagePreview';   
//        shimDiv.style.position = 'absolute';   
//        shimDiv.style.top = '0px';   
//        shimDiv.style.left = '0px';   
//        shimDiv.style.width = "100%";   
//        shimDiv.style.height = document.body.clientHeight + 'px';
//        shimDiv.style.backgroundColor = '#000000';  
//        shimDiv.style.zIndex = 10000; 
//        shimDiv.style.opacity = '0.75'; 
//        shimDiv.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=75)'; 
//        document.body.appendChild(shimDiv); 
//    }
//    else
//        document.getElementById('shimImagePreview').style.display = 'block';
//}
function ShowMyPreview( imgUrl )
{
	
	if ( imgUrl == '' )
		return;
	
	tb_show("", imgUrl);
	return;
	
   //var div = document.getElementById('TlvImgPreviewDiv');
//    if (!div)
//    {
//        alert('חסרה מכולה שתאפשר הצגה מוגדלת');
//        return;
//    }

//    ModalImagePreview(div);
//    if ( div.childNodes[0].removeAttribute )
//        div.childNodes[0].removeAttribute('style');
//    else
//    	div.childNodes[0].removeProperty('style');
//    div.childNodes[0].src = imgUrl;
//    div.style.display = 'block';
//    if ( isIE6 )
//    	div.style.position = 'absolute';
//    if (div.childNodes[0].width > 700)
//        div.childNodes[0].style.width = ( window.screen.width * 2 / 3 ) + 'px';
//    if (div.childNodes[0].height > 500)
//        div.childNodes[0].style.height = ( window.screen.height * 2 / 3 ) + 'px';
//    div.style.visibility = 'visible';
//    div.style.top = ( ( window.screen.height - div.childNodes[0].height ) / 4 ) + ( isIE6 ? document.documentElement.scrollTop : 0 ) + 'px';
//    div.style.left = ( ( window.screen.width - div.childNodes[0].width ) / 2 ) + 'px';
//    return false;
}

function ScanPageImages()
{
	if (window.top.location.href.indexOf('abcd') > 0 )
	{	debugger; }
	var imgExt = 'jpg,png,bmp';
    for (i = 0; i < document.images.length; i++) {
        var img = document.images[i];
        if ( ( img.parentNode.tagName == 'A' || img.parentNode.tagName == 'a' ) 
        	  && img.onclick == null
        	  && imgExt.indexOf( getFileExtension( img.src ).toLowerCase() ) >= 0
        	  && imgExt.indexOf( getFileExtension( img.parentNode.href ).toLowerCase() ) >= 0
        	  && ( ! img.getAttribute('setForPreview') ) )
        {
        	// preloading
	        img1 = new Image();
    		img1.src = img.parentNode.href;
    		//---------------------
            img.parentNode.setAttribute('setForPreview','1');
            img.parentNode.onclick = new Function('return ShowMyPreview("' + img.parentNode.href + '");');
            img.parentNode.style.cursor = (document.all) ? 'hand' : 'pointer';
            if ( img.parentNode.removeAttribute )
            	img.parentNode.removeAttribute('href');
            else
            	img.parentNode.removeProperty('href');
        }
        else if ( img.parentNode.className == 'TaPicGalleryItem' )
        {
	        var img1 = new Image();
	        var str = img.parentNode.childNodes[1].getAttribute('onclick').toString();
	        str = str.substring(str.indexOf('\'') + 1, str.lastIndexOf('\''));
    		img1.src = str;
        }
        else
            img.setAttribute('setForPreview','0');
    }
}

function SetAncorsTarget()
{
    var ancs = document.getElementsByTagName( 'a' );
    for ( i = 0; i < ancs.length; i++ ) {
        var a = ancs[ i ];
        if ( ! a.getAttribute( 'target' ) ) {
            var url = a.getAttribute( 'href' );
            if ( url )
            {
            	if ( url.indexOf('http://') >= 0 && url.indexOf( window.top.location.host ) < 0 && url.indexOf( 'javascript:' ) < 0 )
            	    a.setAttribute( 'target', '_blank' );
        		var str = url.substring( ( ( url.length - 4 ) > 0 ) ? url.length - 4 : 0 );
        		if ( str.toLowerCase() == '.pdf')
        			a.setAttribute( 'target', '_blank' );
            }
        }
    }
}

function DoesMyElementContainsTextualTags( obj ) 
{
	if ( window.location.href.indexOf('123456') > 0 )
		debugger;
	if ( obj && obj.has('li').length > 0 || obj.has('span').length > 0 || obj.has('a').length > 0 || obj.has('p').length > 0 || obj.has('div').length > 0 )
			return true;
	return false;
}

//function resizeText( obj, multiplier, verifyNoChilds )
//{
//	if ( verifyNoChilds && Trim( $(obj).html().replace(/<(.|\n)+?>/g,'').replace(/<\/[a-zA-Z]*>/g,'').replace( /[&nbsp;]/g, '' ).replace(/\r/g, '').replace(/\n/g, '').replace(/\t/g, '') ) == '' )
//		return;
//	if ( verifyNoChilds && DoesMyElementContainsTextualTags( obj ) )
//		return;
//    var fontSize = $(obj).css( "font-size" ).replace( 'px', '' ).replace( 'pt', '' ).replace( 'em', '' );
//    var fontUnit = $(obj).css( "font-size" ).replace( fontSize, '' );
//    if ( fontSize.length == 0 )
//    	return;
//    var val = ( parseInt( fontSize.replace( 'px', '' ) ) + multiplier );
//    //$(obj).attr('style', '"font-size: ' + parseFloat( fontSize ) + multiplier + fontUnit + ' !important"');
//	$(obj).css( "font-size", parseFloat( fontSize ) + multiplier + fontUnit );
//}


function resizeText(element, isIncrease)
{
//debugger;

	if(element.children().length > 0)
		return;
	//set how much to increase
	var delta = 1;
	if(isIncrease == false)
		delta = delta * -1;
		
	if(element[0].nodeName == "FONT")
		{
			var fontElSize = $(element).attr("size");
			if(isNaN(fontElSize) || fontElSize == ""){
				return;
			}
			element.attr("size", parseInt(fontElSize) + delta);		
			return;
		}
		var fSize=element.css("font-size");
		if(fSize == undefined || fSize == "")
			return;
			
		element.css("font-size", "");
		fSize = fSize.replace( 'px', '' ).replace( 'pt', '' ).replace( 'em', '' );
		
		fSize = parseInt(fSize) + delta;	
		var cssOldText = element.css('cssText');
		element.css('cssText', cssOldText  + ';font-size:' + fSize.toString() + 'px !important'); 

}

function masterIncreaseFont()
{

	var currFontSizeObj = $('#FontIncDec');
	
	if(currFontSizeObj.val() == "")
		currFontSizeObj.val() = 0;
			
	
	
	if(	parseInt(currFontSizeObj.val()) > 1)
		return;
		
		//debugger;
	$("div.ms-main").find("*").each(function(){resizeText($(this), true);});
	
	currFontSizeObj.val(parseInt(currFontSizeObj.val()) + 1);
}

function masterDecreaseFont()
{
	var currFontSizeObj = $('#FontIncDec');
	
	if(currFontSizeObj.val() == "")
		currFontSizeObj.val() = 0;
			
	
	
	if(	parseInt(currFontSizeObj.val()) < -1)
		return;
		
		//debugger;
	$("div.ms-main").find("*").each(function(){resizeText($(this), false);});
	
	currFontSizeObj.val(parseInt(currFontSizeObj.val()) - 1);

}


//function TaAccessibility() {

//    // Increase Font Size 
//    $(".FontInc").click(function() {
//        //debugger;
//        var currFontSizeObj = $('#FontIncDec');

//        if (currFontSizeObj.val() == "")
//            currFontSizeObj.val() = 0;

//        var currFontSize = parseInt($('#FontIncDec').val());


//        $("*").each(function() {
//            var fSize = $(this).css("font-size").replace('px', '').replace('pt', '').replace('em', '');
//            if (fSize == "")
//                return;
//            fSize = parseInt(fSize) + 1;
//            var cssOldText = $(this).css('cssText');
//            $(this).css('cssText', cssOldText + ';font-size:' + fSize.toString() + 'px !important');
//        });
//        currFontSizeObj.val(currFontSizeObj.val() + 1);
//        return false;
//    });
//    // Decrease Font Size 
//    $(".FontDec").click(function() {
//        if (parseInt($('#FontIncDec').val()) > -1) {
//            $('#FontIncDec').val(parseInt($('#FontIncDec').val()) - 1);
//            $('span').each(function() { resizeText($(this), -1, true); });
//            $('a').each(function() { resizeText($(this), -1, true); });
//            $('li').each(function() { resizeText($(this), -1, true); });
//            $('p').each(function() { resizeText($(this), -1, true); });
//            $('.ArtPicHorizental84pxBrief').each(function() { resizeText($(this), -1, true); });
//            $('.ArtPicHorizental84pxTitle').each(function() { resizeText($(this), -1, true); });
//            $('div[id*=_RichHtmlField]').each(function() { resizeText($(this), -1, false); });
//            $('.ArtBody').each(function() { resizeText($(this), -1, false); });
//            $('.QaAnswer').each(function() { resizeText($(this), -1, false); });
//            $('.QaTitle').each(function() { resizeText($(this), -1, false); });
//            $('.ta-ParagraphTitle').each(function() { resizeText($(this), -1, false); });
//            $('.TaFileTitle').each(function() { resizeText($(this), -1, false); });
//            $('.TaVideoItemsFixedTitle').each(function() { resizeText($(this), -1, false); });
//            $('.TaVideoArtBrief').each(function() { resizeText($(this), -1, false); });
//            $('.ArtPicTitle').each(function() { resizeText($(this), -1, false); });
//            $('.WideWPTitleBar').each(function() { resizeText($(this), -1, false); });
//            $('.ms-vh').each(function() { resizeText($(this), -1, false); });
//            $('.ms-vb').each(function() { resizeText($(this), -1, false); });
//            $('div.ParagraphsBodyDiv').each(function() { resizeText($(this), -1, false); });
//            $('.ms-WPBody').each(function() { resizeText($(this), -1, false); });
//            $('div.DynarchCalendar').each(function() { resizeText($(this), 1, false); });


//        }
//        return false;
//    });
//}
function QaExpandAll( firstQaRowId )
{
    var container = document.getElementById(firstQaRowId).parentNode;
    for( i = 0; i < container.childNodes.length; i++ )
    {
        QaItem = container.childNodes[ i ];
        if ( QaItem.className != 'QaItem')
            continue;
        var Ques = QaItem.childNodes[ 0 ].childNodes[ 0 ].childNodes[ 0 ].childNodes[ 0 ];
        var Ans = QaItem.childNodes[ 0 ].childNodes[ 0 ].childNodes[ 0 ].childNodes[ 1 ];
        Ans.style.display = isIE ? 'block' : 'table-row';
        Ques.childNodes[ 0 ].className = 'QaIconMinus';
        Ques.childNodes[ 1 ].style.fontWeight = 'bold';
        QaItem.className = 'QaItemSel';
    }
    return false;
}
function QaCollapseAll( firstQaRowId )
{
    var container = document.getElementById(firstQaRowId).parentNode;
    for (i = 0; i < container.childNodes.length; i++)
    {
        QaItem = container.childNodes[ i ];
        if ( QaItem.className != 'QaItemSel')
            continue;
        var Ques = QaItem.childNodes[ 0 ].childNodes[ 0 ].childNodes[ 0 ].childNodes[ 0 ];
        var Ans = QaItem.childNodes[ 0 ].childNodes[ 0 ].childNodes[ 0 ].childNodes[ 1 ];
        Ans.style.display = 'none';
        Ques.childNodes[ 0 ].className = 'QaIconPlus';
        Ques.childNodes[ 1 ].style.fontWeight = 'normal';
        QaItem.className = 'QaItem';
    }
    return false;
}
function QaSetMe(me,QaRowId)
{
    var item = document.getElementById(QaRowId);
    if (me.parentNode.childNodes[1].style.display == 'none')
        QaCollapseAll(item.parentNode.childNodes[0].id);
    me.parentNode.childNodes[1].style.display = (me.parentNode.childNodes[1].style.display == 'none') ? (isIE ? 'block' : 'table-row') : 'none';
    me.childNodes[0].className = (me.parentNode.childNodes[1].style.display == 'none') ? 'QaIconPlus' : 'QaIconMinus';
    me.childNodes[1].style.fontWeight = (me.parentNode.childNodes[1].style.display == 'none') ? 'normal' : 'bold';
    item.className = (item.className == 'QaItem') ? 'QaItemSel' : 'QaItem';
    return false;
}

function HideTDToolTip()
{
$("td").attr("title","");
}
