﻿// JScript File
    var _activeHyper
	var m_intIndex = 1;
	var dir=1;
	var imgNo=1;
    var slideShowSpeed = 3000
    var crossFadeDuration = 3
    var Pic = new Array(); 
    var advertMother =  new Array(); 
	var advertNext =  new Array(); 
    var advertCurrent =  new Array(); 
    var advertMax =  new Array(); 
    var advertCount=-1;
    var advertMax=-1;
    var lastPopup='';       
    var lastAdvertMother;   
    var lastFUCtrl=0;
    var lastFCTimeOut = 0;
    var lastTree='';
    var isCombos=new Array();
    var isComboCount = 0;
    var mouseX = 0;
    var mouseY = 0;
    var maxZindex = 25;
    var lastDivName,lastTxtName,lastObjTomove=0,layId=0,lastObjTomoveIsImage=false;
    var fileMode ='editor';
    var rolTxtNo = 1;
    var editorPass = false;
    var posMode='move';
    var editPosX, editPosY
    
    function InsertImageInEditor(img, edt)
    {
        var result = window.showModalDialog('ftb.imagegallery.aspx?rif=~/' + img + '/&cif=~/'+ img +'/&ftb=' + edt);
    }
    
     function ISComboOnShowDropDown(controlId, left, top, width, height) 
     {
        var cboCombo = ISGetObject(controlId);
        cboCombo.DoResize();
        return true;
    }
    
    function addCombo(comboName)
    {
        isCombos[isComboCount] = comboName;
        isComboCount++;
    }
    
    function fixCombos(controlId, left, top, width, height)
    {
    
//        for(var i=0;i<isComboCount;i++)
//        {
//            var cboCombo = ISGetObject(isCombos[i]);
//            cboCombo.DoResize();
//          
//        }
    }
    
    function InitISCombo(controlId, left, top, width, height)
    {
        var cboCombo = ISGetObject(controlId);
        cboCombo.DoResize();
        return true;
    }
    
    function chkfix(chkName)
    {
        var hchk = document.getElementById(chkName);
        if(hchk.value=='1')
            hchk.value='0';
        else
            hchk.value='1';
    
    }
    
   
    
   function FUPopup(FUCtrl,positionCtrl,title,global)
   { 

      if($('#'+FUCtrl))
       {
            
             var pos;
                 if($('#'+FUCtrl).css('display')=='none')
                   {
                       pos = $('#'+ positionCtrl ).offset();  
                       pos.left-=$('.rootDiv').position().left;
                       pos.top+=20;
                      $('#'+FUCtrl).dialog({width:500,title: title,position:pos, close: function(event, ui) { closeFUPopup(); } }); 
                      if(global==undefined || global==false)
                        $('#' + FUCtrl).parent().appendTo($('.rootDiv'));
                      else
                        $('#' + FUCtrl).parent().appendTo($('.mainForm'));
         
                }
                else
                {
                  pos = $('#'+ positionCtrl ).offset();  
                  pos.top+=20;
                  $('#'+FUCtrl).dialog('open');
                  $('#'+FUCtrl).dialog('option','position',pos);
                }
              // $('#'+FUCtrl).dialog('position',pos);
        }
       return false;
   }
    
    	
	function AddHeight(divName)
	{
	    var div = document.getElementById(divName);
	    var hgt = div.offsetHeight;
	    div.style.height=hgt+20;
	}
	
	function GetZIndex()
	{
	    maxZindex++;
	    return maxZindex;
	}
	
	function tree(divName,parentName)
	{
	    if(lastTree!='')
	        if(document.getElementById(lastTree))
	            document.getElementById(lastTree).style.display = 'none';
	    
	  if(document.getElementById(parentName))
	    {
	        if(document.getElementById(divName).style.display == '')
	        {
	            document.getElementById(divName).style.display = 'none';
	        }
	        else
	        {
	            var parentObj = document.getElementById(parentName);
	            var x = findPosX(parentObj);
	            var y = findPosY(parentObj);
	            document.getElementById(divName).style.position = 'absolute';
	            document.getElementById(divName).style.left =  x - 50;
                document.getElementById(divName).style.top  =  y +25;
	            document.getElementById(divName).style.display = '';
	            document.getElementById(divName).style.zIndex = GetZIndex();
	            lastTree = divName;
	        }
	     }   
	    return false;
	}
	
	function FUClose()
	{
	    if(document.getElementById(lastFUCtrl))
	        document.getElementById(lastFUCtrl).style.display = 'none';
	}
	
 function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }

	
	function show_popup1()
	{
	    show_popup(intIndex);
	}
	
	
	
	function show_popup2(intIndex)
	{
	    show_popup(intIndex,false);
	}
	
	function ShowSelPanel(pnlName)
	{
	    var pnl = document.getElementById(pnlName);
	    if(pnl.style.display=='')
	        pnl.style.display='none';
	    else
	        pnl.style.display='';
        
        pnl.style.zIndex = GetZIndex();	        
	    
	    return false;
	}
	
	function show_popup(intIndex,blnDontBrowse, intDirId)
	{
				var objWin, intHgt, intWidth, intLeft, intDiff, intTop, strScroll, strFile
												
				m_intIndex = intIndex;
				
				strScroll = 'no'
				
				dir = intDirId;
					
					            	
	            if(blnDontBrowse)	
	            {
                    intHgt = 200
                    intTop = (window.screen.availHeight/2) - (intHgt/2)
                    intWidth = (window.screen.availWidth/2) 
                    intLeft = intWidth - (intWidth/2)

	                strFile = "upload.aspx?index=" + intIndex + "&dir=" + dir;
	            }
	            else
	            {
	                intHgt = 670
				    intTop = ((window.screen.availHeight/2) - (intHgt/2)) - 40;
				    intWidth = (window.screen.availWidth/2) + 20
				    intLeft = intWidth - (intWidth-50)
    	
				    strFile = "FileBrowse.aspx?index=" + intIndex + "&dir=" + dir;
				}
				
				strSettings = "top=" + intTop + " left=" + intLeft + " width=" + intWidth + " height=" + intHgt + " resizable=yes scrollbars=" + strScroll + " menubar=no titlebar=no toolbar=no location=no "
				
				objWin = window.open(strFile,"frmLookupWindow", strSettings)
	}
	
	function showNextImage(aname)
	{
	    imgNo++;
	    if(imgNo>14)
	        imgNo = 1;
	    
	    var obj = document.getElementById(aname);
	    if(obj)
	    {
           obj.style.filter="blendTrans(duration=2)";
           obj.style.filter="blendTrans(duration=crossFadeDuration)";
           obj.filters.blendTrans.Apply();      
           obj.src = 'rotate/img' + imgNo + '.jpg';
           obj.filters.blendTrans.Play()

	       var f = "showNextImage('" + aname +"');";
	       window.setTimeout(f,4000);
	       
	       var preLoad= new Image(100,25); 
	       var nextImg = imgNo + 1;
	       if(nextImg>43)
	            nextImg = 1;
	            	       
           preLoad.src='rotate/img' + nextImg + '.jpg'; 

	    }
	 	    
	}
	

function refreshAdvert(advertCtrlBtnName)
{
    setTimeout("document.getElementById('" + advertCtrlBtnName + "').click();refreshAdvert('" +  advertCtrlBtnName +"');",20000);
} 


	function uploadFile(hyperLink)
	{
				var objWin, intHgt, intWidth, intLeft, intDiff, intTop, strScroll, strFile
				var	captionFld,guidFld,intDirId						
				
				_activeHyper = document.getElementById(hyperLink);
			
			//.getAttribute
				
				captionFld = _activeHyper.getAttribute('captionFld');
				guidFld = _activeHyper.getAttribute('guidFld');
				intDirId = _activeHyper.getAttribute('folder');
				var iWidth = _activeHyper.getAttribute('iWidth');
				var iHeight = _activeHyper.getAttribute('iHeight');

				strScroll = 'no'
				
				dir = intDirId;
	    	
                intHgt = 200
                intTop = (window.screen.availHeight/2) - (intHgt/2)
                intWidth = (window.screen.availWidth/2) 
                intLeft = intWidth - (intWidth/2)

                strFile = "upload.aspx?index=777&c="+captionFld + "&g=" + guidFld+ "&dir=" + dir + "&i=" + hyperLink + "&w=" + iWidth + "&h=" + iHeight;
                //strFile = "upload.aspx?i=" + hyperLink;
			
				strSettings = "top=" + intTop + " left=" + intLeft + " width=" + intWidth + " height=" + intHgt + " resizable=yes scrollbars=" + strScroll + " menubar=no titlebar=no toolbar=no location=no "
				
				objWin = window.open(strFile,"frmLookupWindow", strSettings)
	}
	
	function regAdvert(column, mother,nextImage, maxImageCount)
	{
	    advertMax++;
	    advertMother[advertMax] = mother;
	    advertNext[advertMax] = nextImage;
	    advertCurrent[advertMax] = 0;
	    advertMax[advertMax] = maxImageCount;
	    
	    if(lastAdvertMother!=mother)
	        window.setTimeout("nextAdvert('" + mother + "'," + advertMax + ")",3000);   
	    
	    lastAdvertMother==mother;
	}
			
	function nextAdvert(motherCtrl, index)
	{
	    advertCurrent[index]+=1;
	    
	    if(advertCurrent[index]>-1)
	    {
	        if(advertCurrent[index]>advertMax[index])
	            advertCurrent[index] = 0;
	        
	        var adCount = 0;
	        var adFound = false;
	        for(i=0;i<=advertMax;i++)
	        {
	            if(advertMother[i]==motherCtrl)
	            {
	                adCount++;
	                if(adCount >= advertCurrent[index])
	                {
	                    adFound=true;
	                    showAdvert(motherCtrl,advertNext[i] );
	                    break;
	                }
	            }
	            
	        }
	        if(!adFound)
	            advertCurrent[index] = -1;
	    }
	    
	    window.setTimeout("nextAdvert('" + motherCtrl + "'," + index + ")",3000);   
	}
	
	function showAdvert(mother, next)
	{
	    motherObj = document.getElementById(mother)
	    nextObj = document.getElementById(next);
	    if(motherObj.urlCtrl)
	    {
	        var urlCtrl = document.getElementById(motherObj.urlCtrl);
	        urlCtrl.value =  nextObj.title;
	    }
	    
	    if(motherObj!=null)
	    {
	        motherObj.src = nextObj.src;
	        motherObj.title =  nextObj.title;
	        
	    }
	    //alert(nextObj.src)
	}
	
	
	
	function moveOverPopup()
	{
	    if(lastPopup!=0)
	        clearTimeout(lastPopupHandle);
	        
	    lastPopupHandle = window.setTimeout('closeLastPopup();',5000);
	}
	
	function closeLastPopup()
	{
	    if(lastPopup!='')
	    {
	        $('#' + lastPopup).removeClass('browsePopupShow').addClass('browsePopupHide');
	    }
	
	}
	
	function placeImage(caption, guid)
	{
	    
	   var guidFld = document.getElementById(_activeHyper.getAttribute('guidFld'));
	   var captionFld =  document.getElementById(_activeHyper.getAttribute('captionFld'));
	   var lnkCtrl;
	   if(_activeHyper.lnkCtrl!='')
	        lnkCtrl =  document.getElementById(_activeHyper.getAttribute('lnkCtrl'));
	   var activeImage = _activeHyper.getAttribute('imgCtrl');

	   var folder = _activeHyper.getAttribute('folderPath');
	  
	   captionFld.value = caption;
	      	  
	   guidFld.value = guid;
	   var imgCtrl = document.getElementById(activeImage);
	   var path = folder +'/' + guidFld.value;
	   //alert(path)
	  
	   if(_activeHyper.getAttribute('lnkCtrl')!='')
	   {
	        if(_activeHyper!=null && _activeHyper.getAttribute('lnkCtrl')!=null)
	            _activeHyper.getAttribute('lnkCtrl').onClick = "openDoc('" + path + "');return false;";
	   }
	   else
	   {
	        imgCtrl.src = path;
	   }
	   
	}
	
	function openDoc(doc)
	{
	    window.open(doc);
	}
	
		
	function lite2(obj) 
	{
        if(document.all&&!window.opera) 
        {
            obj.filters.blendTrans.apply(); 
            obj.filters.blendTrans.play(); 
        }
    } 

	function flashClickUpdate()
	{
    	objects = document.getElementsByTagName("object");
        for (var i = 0; i < objects.length; i++)
        {
            objects[i].outerHTML = objects[i].outerHTML;
        }
	}
	
	function MiniMenu(lastScreen, tableName)
	{
	    var lastMiniTable = document.getElementById(lastScreen).value;
	    if(lastMiniTable!='')
	        document.getElementById(lastMiniTable).style.display = 'none';
	        
	    document.getElementById(tableName).style.display = '';    
	    document.getElementById(lastScreen).value = tableName ;
	    
	    return(false);
	    
	}
	
	function confirm_delete()
    {
      if (confirm("Are you sure you want to delete the record?")==true)
        return true;
      else
        return false;
    }


	
	//window.setTimeout("flashClickUpdate();",10);
	
	var onceOpen = 0;
    
    function openDocOnce(url)
    {
        if(onceOpen==0)
        {
            onceOpen=1;
            window.open(url);
        }
    }
    
    function position(elmIdOrClass,x,y)
    {
        var pos = $('#TopLeft').position();
        pos.top += y;
        pos.left+= x;
        $(elmIdOrClass).css({'position':'absolute','top':pos.top + 'px','left':pos.left + 'px'});
        
    }
    
    function positionAndDisplay(elmIdOrClass,x,y)
    {
        var pos = $('#TopLeft').position();
        pos.top += y;
        pos.left+= x;
        $(elmIdOrClass).css({'position':'absolute','top':pos.top + 'px','left':pos.left + 'px','display':'block'});
        
    }
    
    function AnimateMenuOnHover()
    {
                  $('#jmenuBar a').hover(function()
                   {  
                    //my:'left top',at:'left top'
                        var pos = $(this).position();
                        var pwidth =$(this).width()+30;// + $(this).css('paddingLeft');
                        var pheight =$(this).height();
                       $('#marker').css({display:'inline',position:'absolute'});
                       // $('#marker').addClass('onTop');
                       $('#marker').stop(true,true).animate({top:pos.top,left:pos.left-10,opacity:1,width:pwidth,height:pheight},800,function(){
                        // $(this).effect('shake',80);
                       });
                        //$(this).corner('cc:#009 8px').animate({top:'-=10',fontSize:'18pt',backgroundColor:'black',color:'white',width:'300'},1000);
                       //$(this).flip({direction:'lr',onEnd:function(){
            //            $(this).revertFlip().animate({top:+8},500);
                     //}});            
                     
                   }
                   ,function()
                   {         
                    
                      $('#marker').animate({left:0,width:1000,top:-100,opacity:0,height:300},300,function(){
                       
                            
                            $('#marker').css({display:'none',position:'absolute'});
                            $('#jmenuBar a').css({display:'inline'});
                       });
                       
                             
                   
                   });
                 
    }
     
    function updateMove(ui,divToMove, btnUpdate,txtCtrlName)
    {
       
       $('#' + btnUpdate).parent().appendTo($("form:first"));
      // $('#' + txtCtrlName).val(ui.absolutePosition.top + ', ' + ui.absolutePosition.left);
       $('#' + btnUpdate).click();
    }
 
      $(window).ready(function() 
      {  
     
           //  $('.dgridrow').css({'color':'red'});
      
            $('.dgridrow').hover(function()
            {
                $(this).css({'background-color':'#F5F5F5'});
            }
            ,
                function()
                {
                    $(this).css({'background-color':'white'});
                }
                
            );
            
             
            
            $('.rootDiv').mousemove( function(e) {
               mouseX = e.pageX; 
               mouseY = e.pageY;
             });
             // positionAndDisplay('#headphone',828,18);
            //  position('.navButtons',10,95);
              
             
            $('.jtab').tabs();
            $('#marker').css({opacity:'0'});
            //jQuery.easing.def = 'easeOutBounce';//'<%=Animation %>';

            AnimatePage();
             $(function() {
                var zindex = GetZIndex();
	            $(".jtab").tabs().addClass('ui-tabs-vertical ui-helper-clearfix');
	            $(".jtab>div>ul>li").removeClass('ui-corner-top').addClass('ui-corner-left');
	                                $('.jtab>div:first').css({position:'relative',top:'0px',left:'0px','zIndex':zindex});
            });

            runEffect();
            AutoRoll();
            RMenu();
            

      });
      
    
      
      
    function DragNow(ctrl)
    {
        var zindex = GetZIndex();
        ctrl.css({'z-Index':zindex}).draggable();
    }
        
    //run the currently selected effect
    function runEffect(){

        $(".Drag").mousedown(function (){DragNow($(this));});
        
	    //get effect type from 
	    var selectedEffect = 'bounce';
	    //var selectedEffect = 'clip';
    	
	    //most effect types need no options passed by default
	    var options = {};
	    //check if it's scale, transfer, or size - they need options explicitly set
	    //if(selectedEffect == 'scale'){ options = {percent: 0}; }
    //	else if(selectedEffect == 'transfer'){ options = { to: "#button", className: 'ui-effects-transfer' }; }
	    //else if(selectedEffect == 'size'){ options = { to: {width: 200,height: 60} }; }
    	
	    //run the effect
	    $(".BoxBounce").effect(selectedEffect,options,500,function(){
    	$(".BoxBounce").draggable().resizable();

	    });
    	
    };
		
	function moveScroll(scroll, slider, delta)
	{ 
	    elmScroll = '#' + scroll ;
	    elmSlide = '#' + slider ;
	    var maxScroll = $(elmScroll).attr('scrollHeight') - $(elmScroll).height();
	    var scrollTopVal = $(elmScroll).attr('scrollTop');
	    var pos = scrollTopVal;
	    
	    if(delta > 0)
	      pos-=100;
	    else
	      pos+=100;
	      
	      if(pos>maxScroll)
	        pos = maxScroll;
	    
	    var percent =100 - parseInt(((pos/maxScroll) * 100));
	   
        $(elmSlide).slider({ value: percent });
        $(elmScroll).attr('scrollTop', pos);
	}
	
	function myScrollBar(paraId, scroll, slider, height)
	{
	  var  elmScroll = '#' + scroll ;
	  var  elmSlide = '#' + slider ;
	  var elmPara =  '#' + paraId;
	  

	    
	    $(elmScroll).bind('mousewheel', function(event, delta){ moveScroll(scroll,slider,delta); return false; });
	    $(elmScroll).css('height', height + 'px');
	    $(elmSlide).css('height', height-20 + 'px');
	    $(elmSlide).slider({animate: true, change: 
	        function(e, ui)
	        {
	             //handleSliderChange
	             var maxScroll = $(elmScroll).attr('scrollHeight') - $(elmScroll).height();
	             $(elmScroll).animate({scrollTop: ((100-ui.value) * (maxScroll / 100)) }, 1000);
	        }
	    
	    , slide: 
	        function(e, ui)
	        {
	            //handleSliderSlide
	            var maxScroll = $(elmScroll).attr('scrollHeight') -  $(elmScroll).height();
	            $(elmScroll).attr({scrollTop: ((100-ui.value) * (maxScroll / 100)) });
	        }
	    , orientation:'vertical', value:100 });
	    
	}
	
	
	
    function mPosLeft(mTextCtrl,pos)
    { 
        $('#' + mTextCtrl).css({display:'inline',position:'relative'});
        $('#' + mTextCtrl).animate({'position':'relative','left': pos + 'px'},300)
       
    }
 
    function mPosTop(mTextCtrl,pos)
    {
   
        $('#' + mTextCtrl).css({display:'inline',position:'relative'});
        $('#' + mTextCtrl).animate({'position':'relative','top': pos + 'px'},300)
    }
 


    function MU(scroll,slider)
    {

        var val = GetSliderVal(slider)
        val = val + 30;
        MoveSlider(slider,val);  
        MoveCanvas(scroll,val);
        return false;
    }

    function MD(scroll,slider)
    {

        var val = GetSliderVal(slider)
        val = val - 30;
        MoveSlider(slider,val);  
        MoveCanvas(scroll,val);
        return false;
    }

    function GetSliderVal(slider)
    {
        var  elmSlide = '#' + slider ;
        return $(elmSlide).slider( "option", "value" );
    }

    function MoveSlider(slider, val)
    {
        var  elmSlide = '#' + slider ;
        if(val>100)
            val=100;
        if(val<0)
            val=0;
            
        $( elmSlide).slider({ value: val });
    }

    function MoveCanvas(scroll, val)
    {
       var  elmScroll = '#' + scroll ;
       var maxScroll = $(elmScroll).attr('scrollHeight') - $(elmScroll).height();
         	      
       if(val>100)
            val=100;
       if(val<0)
            val=0;
	    $(elmScroll).animate({scrollTop: ((100-val) * (maxScroll / 100)) }, 1000);

    }
    
    function ShowEditMnu(mnuName)
    {
        $('#' + mnuName).css({'display':'block'});
        
        return false;
    }

    function RegPara(div, editButtons, txtInfo, usexy)
    {   
        var origInfo='';
        $('#'+div).hover(
            function()
            {
                var zindex = GetZIndex();
                var newTop = $('#'+div).position().top + 'px';
                var newLeft = ($('#'+div).position().left + 90) + 'px';
                origInfo = $('#' + txtInfo).val();
                var info = origInfo + ' Coord:' +newTop + ' ' + newLeft;
                $('#' + txtInfo).val(info);
                $('#' + txtInfo).css({'display':'inline'});
                $('#' + txtInfo).click(function()
                {
                    $('#' + txtInfo).css({'display':'none'})
                });
            //    $('#' + editButtons).css({'display':'block','Z-Index':zindex,'left':'0px','top':'-8px'});
                $('#'+div).css({'opacity':'1','border-style':'solid','border-width':'1px'});
            }
            ,
            function()
            {
                $('#' + txtInfo).val(origInfo);
                $('#' + editButtons).css({'display':'none'});
                $('#'+div).css({'opacity':'0.4','border-style':'none','border-width':'0px'});
            }
        );
    }

    function movePara(divToMove, moveIcon, txtCtrlName,btnUpdate,usexy )
    {        
            var offset=0;   
            if(usexy=='False')
            {
                 offset=-10;
                 
                $('#'+divToMove).draggable({ handle: '#'+moveIcon, drag: function(event, ui)
                 {     
                    var newTop = mouseY + offset;
                    var newLeft = mouseX - ($('.rootDiv').position().left + 70);
                    $('#'+txtCtrlName).val( newTop + ', ' +  newLeft );
                 }, stop:function(event, ui){updateMove(ui,divToMove,btnUpdate,txtCtrlName);} });
             }
             else
             {
                 offset=-9;
                 
                $('#'+divToMove).draggable({ handle: '#'+moveIcon, drag: function(event, ui)
                 {     
                    var newTop = mouseY + offset;
                    var newLeft = mouseX - ($('.rootDiv').position().left + 87);
                    $('#'+txtCtrlName).val( newTop + ', ' +  newLeft );
                 }, stop:function(event, ui){updateMove(ui,divToMove,btnUpdate,txtCtrlName);} });
             }
    }
    
    
    function AutoRoll()
    {
        //This does rollovers for class AutoRoll using on and off attributes
        $('.AutoRoll').hover(
        function()
        {
            var img =  $(this).attr('on')
            $(this).attr('src', img )
        }
        ,
        function()
        {
            var img =  $(this).attr('off')
            $(this).attr('src', img )
        }
        
        );
    
    }

// *********** Editor ******************************

    function DeleteEd(divName,txtName)
    {
        StoreEditorName(divName,txtName);
        $('#'+txtName).val('');
        UpdateDivEditor();
        return false;
    }
    
    function UpdateDivEditor()
    {
        $('#'+lastDivName).html($('#'+lastTxtName).val());
    }
    
    function UpdateTextEditor()
    {
        $('#' + lastTxtName).val($('#' + lastDivName).html());
        Filter();
    }
    
    function Filter()
    {
        var html = $('#' + lastTxtName).val();
        html = html.replace("border-top-width: 1px;","");
        html = html.replace("border-right-width: 1px;","");
        html = html.replace("border-bottom-width: 1px;" ,"");
        html = html.replace("border-left-width: 1px;",""); 
        html = html.replace("border-top-style: none;",""); 
        html = html.replace("border-right-style: none;",""); 
        html = html.replace("border-bottom-style: none;",""); 
        html = html.replace("border-left-style: none;","");
        html = html.replace("cursor: pointer;","");
                            
        $('#' + lastTxtName).val(html);
    }
    
      function SelPageEd(page, nw)
    {
        if(fileMode=='roll')
        {
            $('#txtR3').val(page);
        }
        else
        {
                if(nw)
                    htmlEd("link","a",lastDivName,lastTxtName," target='_blank'  href='"+ page + "'","click here");  
                else
                    htmlEd("link","a",lastDivName,lastTxtName,"  href='"+ page + "'","click here");  
        }
    }
    
    
    function MakeRollover()
    {
        var img1 = 'CustomImages/'+ $('#txtR1').val();
        var img2 = 'CustomImages/'+  $('#txtR2').val();
        var page =  $('#txtR3').val();
        var blank = '';
        var onoff = " on='"+ img2 +"' off='"+ img1 +"' class='AutoRoll'  src='"+ img1 + "' class='PosIt' ";
        var nw = $('#chkR4').attr('checked');
        var absolute = $('#chkR5').attr('checked');
        
        if(nw)
          blank = " target='_blank' "
         
            if(page=='')        
            {
                htmlEd("img","img",lastDivName,lastTxtName,onoff,"");
            }
            else
            {
                htmlEd("linkimg","a",lastDivName,lastTxtName," class='PosIt' href='" + page + "' " + blank, "<img " + onoff + " border='0' />");
            }
                
         if(absolute )
         {
            SetupMovableObjects();
         }
            
        return false;
    }
    function HideRollOverPop()
    {
        $('#roll').css({'display':'none'});
        return false;
    }
    function SelFileEd(file)
    {
        if(fileMode =='roll')
        {
            if(rolTxtNo==1)
            {
                $('#txtR1').val(file);
                $('#r1').attr('src', 'customimages/' + file);
            }
            else
            {
                $('#txtR2').val(file);
                $('#r2').attr('src', 'customimages/' + file);
            }
        }
        else
        {
            htmlEd("img","img",lastDivName,lastTxtName,"  class='PosIt' src='customimages/"+ file + "'",""); 
            SetupMovableObjects();
        }
        return false;
    }

    
    function htmlEd(cmd,value,divName,txtName, attrib, content)
    {
        
         editorPass = false;
         StoreEditorName(divName,txtName);
        switch(cmd)
        {   
            case 'link': 
            case 'enter':
            case 'div':
            case 'fcolor':
            case 'para':
            case 'bis':
                editorPass = SurroundWith(value, attrib, content);        
            break;
            case 'linkimg':
            case 'img':
                 SurroundWith(value, attrib, content,true);        
                 editorPass = true;
            case 'upd':
                editorPass = true;
            break;
        }
        
        if(editorPass)
        {
          $('#txtContentUndo').val($('#'+txtName).val());
          $('#'+txtName).val($('#'+divName).html());
        }
        else
        {
            if(cmd=='key')
            {
                $('#txtContentUndo').val($('#'+txtName).val());
                $('#'+txtName).val($('#'+divName).html());
            }
            else
            {
                alert('Please select some text first')
            }
        }
        
        if(cmd=='key') 
            return true;
        else
            return false;
    }
   
    function handleEnterEdDown(event)
    {
         var keyCode = event.which;
         if (keyCode == undefined) 
         {
                keyCode = event.keyCode;
         }
         if (keyCode != undefined) 
         {
            if (keyCode==13 && event.shiftKey == false)
            {
                if (!window.ActiveXObject) 
                {
                    window.event.cancelBubble = true;
                    return false;
                }
            }
         }   
         
         return true;
    }
    
  

    
    function handleEnterEdUp(event,divName,txtName)
    {
         var keyCode = event.which;
         if (keyCode == undefined) 
         {
                keyCode = event.keyCode;
         }
         if (keyCode != undefined) 
         {
            if (keyCode==13 && event.shiftKey == false)
            {
                if (!window.ActiveXObject) 
                {
                    var last='';
                    if(document.getElementById('eol')!=null)
                    { 
                        $('#eol').remove();
                    }
                    var node = SetSelectedText("<br/><br id='eol' />");
                    CaretSetToEnd('eol');
                    return false;
                }
            }
         }   
         
         return htmlEd('key','',divName,txtName);
     
    }
    
    function SetEDFocus(divName)
    {
        var editableDiv = $('#' + divName)[0];
        editableDiv.focus();
    }
    
    
    function ReplaceEnterWithBR(divName)
    {
       var addedBr = false;
       var range;
        
       if (typeof window.getSelection != "undefined") {
            //range.collapse(false);
           
            sel = window.getSelection();
            if (sel.getRangeAt && sel.rangeCount) {
                range = sel.getRangeAt(0);
                range.deleteContents();
                br = document.createElement("br");
                range.insertNode(br);
                 range.setStartAfter(br);
                range.setEndAfter(br);
                sel.removeAllRanges();
                sel.setRange(range);
                if (sel.getSelection().focusNode == br.previousSibling){
                        var nbsp = document.createTextNode('\u00a0');
                        var p = br.parentNode;
                        var ns = br.nextSibling;
                        (ns) ? p.insertBefore(nbsp, ns) : p.appendChild(nbsp);
                        sel.selectNode(nbsp);
                        sel.collapse(1);
                      
                }
                addedBr = true;
            }
        } else if (typeof document.selection != "undefined") {
            sel = document.selection;
            if (sel.createRange) {
                range = sel.createRange();
                range.pasteHTML("<br/>");
                range.select();
                addedBr = true;
            }
        }
        return addedBr;
    }
    
  
    
    
    function CaretSetToEnd(divName)
    {
        var editableDiv = $('#' + divName)[0];
        editableDiv.focus();
        CaretSetToEndBase(editableDiv);
    }
    
    function CaretSetToEndBase(el) 
    {
         var sel, range;
         if (window.getSelection && document.createRange) 
         {
             range = document.createRange();
             range.selectNodeContents(el);
             range.collapse(false);
             sel = window.getSelection(); 
             sel.removeAllRanges();
             sel.addRange(range);
         } 
         else if (document.body.createTextRange) 
         {
             range = document.body.createTextRange();
             range.moveToElementText(el);
             range.collapse(false);
             range.select();
         }
    }
    
    function GetRangeObject(selectionObject) 
    {
	    if (selectionObject.getRangeAt)
		    return selectionObject.getRangeAt(0);
	    else { // Safari!
		    var range = document.createRange();
		    range.setStart(selectionObject.anchorNode,selectionObject.anchorOffset);
		    range.setEnd(selectionObject.focusNode,selectionObject.focusOffset);
		    return range;
	    }
    }
    
    function InitialiseMoveSizePanel()
    {
        var top,left,width,hgt;
        var pos = $('#' + lastDivName).position();
        var scrollTopVal = $('#' + lastDivName).attr('scrollTop');
        var scrollLeftVal = $('#' + lastDivName).attr('scroll');
        if(scrollTopVal==undefined)
            scrollTopVal=0;
        if(scrollLeftVal==undefined)
            scrollLeftVal=0;
        
        top = pos.top + scrollTopVal ; 
        left = pos.left + scrollLeftVal;
        width = $('#' + lastDivName).width();
        hgt = $('#' + lastDivName).height();
        $('#PosGrid').css({'top':top,'left':left,'width':width,'height':hgt,'display':'none'});
        
        
    }
    
    function SetupMovableObjects()
    {
        var pass = false;
        RMenu();
        $('.PosIt').css({'position':'absolute'});
        $('.PosIt').css({'cursor':'pointer'});


        $('.PosIt').hover(
            function()
            {
                $(this).css({'border-style':'solid','border-width':'1px'});
            },
            function()
            {
                $(this).css({'border-style':'none'});
            }
        );

        return pass;
    }
    
    
    function updateMoveEd(ui)
    {
       htmlEd('upd','',lastDivName,lastTxtName);
    }
    
    function StoreEditorName(divName,txtName)
    {
        lastDivName = divName;
        lastTxtName = txtName;
    }
   
   
    function RGBColorEd(divName,txtName)
    {
        var rgb = prompt('Type a RGB Colour, eg. 50,50,50','0,0,0');
        htmlEd('fcolor','span',divName,txtName,'style="color:rgb(' + rgb +');"');
        return false;
    }
    
    function colorEd(cboCombo, divName,txtName)
    {
        var color = GetComboVal(cboCombo);
        htmlEd('fcolor','span',divName,txtName,'style="color:' + color +'"');
         return false;
    }
    
     function RGBColorBEd(divName,txtName)
    {
        var rgb = prompt('Type a RGB Colour, eg. 50,50,50','0,0,0');
        htmlEd('fcolor','span',divName,txtName,'style="background-color:rgb(' + rgb +');"');
        return false;
    }
    
    function colorBEd(cboCombo, divName,txtName)
    {
        var color = GetComboVal(cboCombo);
        htmlEd('fcolor','span',divName,txtName,'style="background-color:' + color +'"');
         return false;
    }
    
     function paraChange(cboCombo, divName,txtName)
    {
        var para = GetComboVal(cboCombo);
        if(para=='DateTime')
            htmlEd("para","div", divName,txtName," class='datetime  ' ");
        else
            htmlEd('para',para, divName,txtName);
            
         return false;
    }
    
    function GetComboVal(cboCombo)
    { 
        var dropdown = document.getElementById(cboCombo);
        var index = dropdown.selectedIndex;
        var ddVal = dropdown.options[index].value;
        
        return ddVal;
    }
    
    
    function UndoHtmlEd(divName,txtName)
    {
        $('#'+txtName).val($('#txtContentUndo').val());
        $('#'+divName).html($('#txtContentUndo').val());
        return false;
    }
    function ToggleHTML(divName,txtName)
    {
        StoreEditorName(divName,txtName);
        if($('#' + divName).css('display') == 'none')
        {
            $('#'+ divName).html($('#' + txtName).val());
            $('#' + divName).css({'display':'block','width':'100%','height':'100%'})
            $('#' + txtName).css({'display':'none'})
            SetupMovableObjects();
        }
        else
        {
            $('#' + txtName).val($('#' + divName).html());
            $('#' + divName).css({'display':'none'})
            $('#' + txtName).css({'display':'block','width':'100%','height':'100%'})
            UpdateTextEditor();
         
        }
        
        return false;
    }
    
    function IsTextSelected(text)
    {
        var pass = false;
        if(text)
        {
            if(text!='|empty|')
            {
               if(text!='')
                {
                    pass = true;
                }
            }
         }
        if(pass==false)         
            alert('Please select some text first');
         
         return pass;
    }
    
    function InsertDiv(divName,txtName)
    {
        StoreEditorName(divName,txtName);
        var obj = GetSelectedText();        
        if(IsTextSelected(obj))
        {      
            var text = obj.toString();
            SetSelectedText('&nbsp;');       
            UpdateTextEditor();      
            var html = $('#' + lastTxtName).val();                  
            html += "<div class='PosIt' style='position:absolute;display:block;width:100px;height:100px;top:10px;left:100px;' >" + text + "</div>";
            $('#' + lastTxtName).val(html);
            UpdateDivEditor();
            SetupMovableObjects();
        }
    
         return false;
    }
    
   
    
    function SurroundWith(value,attrib,content, noSelectionNeeded)
    {
        var pass = false;
        var text = GetSelectedText() ;

        if(text)
        {
            if(text!='|empty|' || noSelectionNeeded)
            {
               if(text!='' || noSelectionNeeded)
                {
                    pass=true;
                 
                    if(attrib==undefined)
                    {
                        
                        if(content==undefined)
                            SetSelectedText("<" + value + ">" + text + "</"+ value + ">");
                        else
                            SetSelectedText("<" + value + ">"+ content + text  + "</"+ value + ">");
                    }
                    else
                    {
                
                        if(content==undefined)
                            SetSelectedText("<" + value + " " + attrib + ">" + text + "</"+ value + ">");
                        else
                            SetSelectedText("<" + value + " " + attrib + ">"+ content + text + "</"+ value + ">");
                        
                    }
                  
                }
            }
        }
        return pass;
    
    }
        
    function SetSelectedText(html) 
    {
      html = html.toString();
      var sel, range, node;
        if (window.getSelection) {
            sel = window.getSelection();
            if (sel.getRangeAt && sel.rangeCount) {
                range = window.getSelection().getRangeAt(0);
                range.extractContents();
                node = range.createContextualFragment(html);
                range.insertNode(node);
                return node;
                
            }
        } else if (document.selection && document.selection.createRange) {
            range = document.selection.createRange();
            range.pasteHTML(html);
        }
        
        return range;                
    }
   
    function GetSelectedText()
    {
        var txt = '|empty|';
        var start = 0;
        var tst;
          
        if (window.ActiveXObject) 
        {
            if(document.selection)
                txt = document.selection.createRange().text;
        }
        else
        {
            tst = window.getSelection();
            if(tst)
                txt = tst;
            //start= txt.anchorOffset;
            
        }

        return txt;
    }
    
   
    function closeFUPopup()
    {
        
    }
   
   function dragMe(isImage)
   {
     
        InitialiseMoveSizePanel();
        var top, left;
        var pos = lastObjTomove.position();
        var width = lastObjTomove.width();
        var hgt = lastObjTomove.height();
        var image='';
        var block='';
        $('#blockMove').css({'display':'none'});  
        $('#blockResize').css({'display':'none'});  
      
        if(posMode=='delete')   
        {
            lastObjTomove.attr('class','deleteme');
            lastObjTomove.parent().empty('.deleteme');
            lastObjTomove=null;
            posMode='move';
            UpdateTextEditor();
            $('#PosGrid').css({'display':'none'}); 
            return false;
        }

         block = '#block'

        $('#posEdit').empty();
        $('#posEdit').append("<img id='block'  src='images/bg_dg.jpg' style='position:absolute;display:none;'>");
       $('#block').dblclick(
               function(){
                ClosePosGrid();
               });
        //.removeAttr("height").css({ width: "", height: "" });
        
        if(isImage)
        {
            image =  lastObjTomove.attr('src');
            $(block).attr('src',image);
     
        }
        else
        {
            $(block).attr('src','images/bg_dg.jpg');
        }

        $('#PosGrid').css({'display':'block'});  
        $(block).css({'position':'absolute','display':'block','top':pos.top,'left':pos.left,'width':width,'height':hgt}) 

        if(posMode=='move')        
        {
                $(block).css({'cursor':'move'});
                $(block).draggable({  stop:function(event, ui)
                {
                   var pos2 = $(block).position();
                   lastObjTomove.css({'top':pos2.top,'left':pos2.left});
                   UpdateTextEditor();
                   $(block).removeAttr("style");
                    $('#PosGrid').css({'display':'none'}); 
                }
             });
        }
        else
        {     
             $(block).resizable({ handles: "all", ghost: false, autoHide: true,  stop:function(event, ui)
             {
                $(block).css({'cursor':'auto'});
                var width2 = $(block).css('width');
                var hgt2 = $(block).css('height');
                lastObjTomove.css({'width':width2,'height':hgt2});
                UpdateTextEditor();
                $(block).removeAttr("style");
                $('#PosGrid').css({'display':'none'}); 
             
             } });;
        }
             
            $(block).hover(
                function()
                {
                    $(this).css({'border-style':'solid','border-width':'1px'});
                },
                function()
                {
                    $(this).css({'border-style':'none'});
                }
            );
    }
    
   
    
    function ClosePosGrid()
    {
        $('#PosGrid').css({'display':'none'}); 
        return false;
    }
    
    function ParaReturnText()
    {
       var txt = $('#editPara').val();
       //txt = return2br(txt);
        //txt = txt.replace(/n/g,"");
       txt = txt.replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1<br>$2')
       SetSelectedText('<p>' + txt + '</p>&nbsp;');
       UpdateTextEditor();
       return false;
    }
    
    function return2br(dataStr) {
       // return dataStr.replace(/[\r\n]/g, "<br />");
        return dataStr.replace("\r", "<br />");
    }
    
    function PosGridMode(mode,el)
    {   
            posMode=mode;
             lastObjTomove=null;
            lastObjTomove = $(el);
           
            if(lastObjTomove.attr('src')==undefined) 
                lastObjTomoveIsImage=false;
            else
                lastObjTomoveIsImage = true;
            
            dragMe(lastObjTomoveIsImage);
            
          return false;
    }
    function format() {
        var event = document.forms[0].elements[0].value;
        event = event.replace(/\n/g, '&lt\;br \\&gt\;');
        var day = 1;
        document.getElementById("input").innerHTML="entry[" + day + "]=\"" + event + "\";";
    } 

function RMenu()
    {
       $(".PosIt").contextMenu({
					menu: 'myMenu'
				},
					function(action, el, pos) {
					PosGridMode(action, el);

				});


    }  