﻿
onerror=handleErr
var method;

function handleErr(msg,url,l)
{
    txt="Line Number="+ l  + "$#$#Errormessage=" + msg + " $#Method Name=" + method +"$#$# URL:" + url;
    ClickHandler.LogError(txt);
    return true
}


function LogOut()
{
    method = "LogOut";
    ClickHandler.LogOut()
}


function displayMyData()
  {
     //parent.frames["Left"].hightLightNode("1");
     var CurrentId=parent.frames["description"].TemplateId; 
     var res="";
     var inheritDate="false";
     var currentSelectedContainerId=parent.frames["description"].selectedContainerId;
     if(currentSelectedContainerId==null || currentSelectedContainerId=="undefined")
          return;
     var mySplitResult = currentSelectedContainerId.split("pnlDescription");
     currentSelectedContainerId=mySplitResult[1];
     res=ClickHandler.getMySingleInheritInfo(CurrentId,currentSelectedContainerId);
     
     if(res.value!="")    
     {
       if(parent.frames["Left"] != null)
        myDescriptionList=parent.frames["Left"].document.getElementById("selDescription");
       var mySplitResult = res.value.split(":");
       var result=ClickHandler.getDescriptionWithOrder(mySplitResult[0]);
       inheritDate=mySplitResult[3];
      var myDataTable=result.value;
      myDescriptionTable=myDataTable;
    var myObj=parent.frames["Left"].document.getElementById("dvOption");
    if(myObj!=null && myDescriptionList!=null)
    {
       myObj.style.display="block";
      if(parent.frames["Left"].document.getElementById("selDescription")!=null)
      {
          if(typeof(myDataTable)=="object") 
        { 
      //Clear the dropDownlist
          removeAllOptions(myDescriptionList);
                
        // Add ""choose style.. "" option
       optn=document.createElement("OPTION");
       optn.value="0";
       optn.text="Select Description";
       // optn.selected = "selected";
       myDescriptionList.options.add(optn); 
        
        //Populate it..
          for(var i=0; i< myDataTable.Rows.length; i++)
          {
                optn=document.createElement("OPTION");
                optn.value=myDataTable.Rows[i].DescOrder;
                optn.text=myDataTable.Rows[i].BriefDescription;
                if(optn.value==mySplitResult[1])
                optn.selected = "selected";
                myDescriptionList.options.add(optn);            
          } 
           if(parent.frames["Left"].document.getElementById("chkInherit")!=null)
              parent.frames["Left"].document.getElementById("chkInherit").checked=true;   
              if(inheritDate=="True")
              {
               if(parent.frames["Left"].document.getElementById("chkDate")!=null)
                parent.frames["Left"].document.getElementById("chkDate").checked=true;  
              
              }  
              else if(parent.frames["Left"].document.getElementById("chkDate")!=null)
                parent.frames["Left"].document.getElementById("chkDate").checked=false;  
                
    }
                
      }
    }
        
     }
     else if(parent.frames["Left"]!=null)
     {
      if(parent.frames["description"].selectedContainerId.title==null || parent.frames["description"].selectedContainerId.title=="")
      {
         var myObj=parent.frames["Left"].document.getElementById("dvOption");
         if(myObj!=null)
          myObj.style.display="none";
          }
          
     }
   
     
  } 
function ClearText(Identity)
{
    
    method = "ClearText";
      var curRefer =  parent.frames["Left"].location.href;
     if(curRefer!=null && curRefer.indexOf("LeftInherit.aspx")!=-1)
      { 
         displayMyData();
        }
    selectedContainerId=Identity;
    var obj =null;
    if(parent.frames["description"].document !=null)
        obj=parent.frames["description"].document.getElementById(Identity);
    if(obj != null)
    {
        var val=obj.innerHTML;
        if(val.indexOf("Lorem ipsum dolor sit amet") != -1)
            obj.innerHTML="";
        ReflectDescriptionStyle();
    }
}

function setChanged(event)
{
    method = "setChanged";
    ClickHandler.SetChanged();
}



/*------------------------------------ */
/* methods for Permission checking -- by sudeep */
/*------------------------------------ */

function checkPermission(permName, showErrorMessage) {
    if (typeof showErrorMessage == "undefined") {
        showErrorMessage = true;
    }
    var result = CMSPermissions.CheckUserPermission(permName);    
    if (result.value == false) {
        parent.frames["description"].hideLoading();
        
        if (showErrorMessage)
            alert('Sorry, you don\'t have permission to use this feature.');
    }
        
    return result.value;   
   
   
}

function ClearText(Identity)
{
    method = "ClearText";
    var tempid = parent.frames["description"].TemplateId;
    var curRefer =  parent.frames["Left"].location.href;
    var myCount=ClickHandler.chkDescriptionInherit(tempid,Identity);
    selectedContainerId=Identity;
    if(myCount.value !="0")    
    {
        parent.document.getElementById("main").cols="*,254";
        if(curRefer!=null && curRefer.indexOf("LeftInherit.aspx")!=-1)
        { 
         displayMyData();
        }
        else
        {
            
            
            var res = ClickHandler.getIsIndex(tempid);
            if(res.value)
                parent.frames["Left"].location.href="Private/LeftInherit.aspx";
            else
                parent.frames["Left"].location.href="../Private/LeftInherit.aspx";
        }
   }
    
    
    var obj =null;
    if(parent.frames["description"].document !=null)
        obj=parent.frames["description"].document.getElementById(Identity);
    if(obj != null)
    {
        var val=obj.innerHTML;
        if(val.indexOf("Lorem ipsum dolor sit amet") != -1)
            obj.innerHTML="";
        ReflectDescriptionStyle();
    }
}


function PasteHandler(event,obj) {
    method='PasteHandler';
	// skip if browser is not IE.
	if (!document.all) return;

	// skip when the element is not in editable mode
	// implies user is not in admin mode.
	// for non-IE we should use event.target object rather than srcElement
	if (!window.event.srcElement.contentEditable) return;

	// skip when it isnt Ctrl+V
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	var controlKey = (event.altKey ? 1 : 0) + (event.ctrlKey ? 2 : 0) + (event.shiftKey ? 4 : 0);
	if (!(controlKey == 2 && keyCode == 86)) return;

//	// create a textarea for temporary copy of data
//	var txtPasteData = document.getElementById('txtPasteData');
//	if (!txtPasteData) {
//		// note: insertAdjacentHTML is IE specific function
//		document.body.insertAdjacentHTML('beforeEnd', '<textarea id=\'txtPasteData\' style=\'display:none;\'></textarea>');
//		var txtPasteData = document.getElementById('txtPasteData');
//		}
//	if (!txtPasteData) return;
//
//	// copy plain text to the clipboard, removing the old one
//	// note: clipboard handling is IE specific
//	txtPasteData.innerHTML = window.clipboardData.getData('Text');
//	window.clipboardData.setData('Text', txtPasteData.innerHTML);
    
    // skip when the element is not in editable mode
	// implies user is not in admin mode.
	// for non-IE we should use event.target object rather than srcElement
	if (!window.event.srcElement.contentEditable) return;
	// skip when it isnt Ctrl+V
	// copy plain text to the clipboard, removing the old one
	// note: clipboard handling is IE specific
	var str = window.clipboardData.getData('text');

	document.execCommand('Paste',false,str);

	//document.getElementById(obj).setAttribute('contenteditable', 'false');
	document.getElementById(obj).contentEditable = false;
	setTimeout("settingContentEditable('obj')",2);
	window.clipboardData.setData('Text',str);
	setTimeout('setParagraph();',5);
	return false;
}

function setParagraph()
{
    var strs = document.getElementById(selectedContainerId);
    strs.innerHTML = strs.innerHTML.replace(/<br>/gi,'</p><p>');
    
}
function SetSelectedContainerId(obj)
{
  
  selectedContainerId = obj;
 
 
}

function settingContentEditable(obj)
{
    document.getElementById(selectedContainerId).contentEditable = true;
}
