﻿// JScript File

var ob_dnd_tve,ob_dnd_tvr,ob_dnd_tvt=0,ob_dnd_tvq=0,ob_dnd_tvy=false;
var ob_dnd_tvu=null,ob_dnd_tvi=null;
var tree_dd_path="",tree_dd_id="",ob_dnd_tvo=0,ob_dnd_tvp=0,ob_dnd_tva=true;
var ob_dnd_tvs=0,ob_dnd_tvd=0;

function Optionover(txt)
{
    $get("txtdrag").value=txt;
}

function mydragj(id,data)
    {
        $get("txtdisplay").value = data;
        $get("txtdisplayid").value = id;
        ob_attachDragAndDrop(document.getElementById(id));
    }
   
        function check_uncheck(Val)
        {
          var ValChecked = Val.checked;
          var ValId = Val.id;
          var frm = document.forms[0];
          // Loop through all elements
          for (i = 0; i < frm.length; i++)
          {
            // Look for Header Template's Checkbox
            //As we have not other control other than checkbox we just check following statement
            if (this != null)
            {
              if (ValId.indexOf('CheckAll') !=  - 1)
              {
                // Check if main checkbox is checked,
                // then select or deselect repeater checkboxes
                if (ValChecked)
                  frm.elements[i].checked = true;
                else
                  frm.elements[i].checked = false;
              }
              else if (ValId.indexOf('chkBox') !=  - 1)
              {
                // Check if any of the checkboxes are not checked, and then uncheck top select all checkbox
                if (frm.elements[i].checked == false)
                  frm.elements[1].checked = false;
              }
            } // if
          } // for
        } // function
         function confirmMsg(frm)
        {
          // loop through all elements
                return confirm('Are you sure want to delete selected Users? Yes/No')
          }
          
           function AddFunction(){			
		    if(document.form1.txtFunction.value=="")
		    {
			    if(document.form1.cmbFunction.value != "0") 
			    {
			    document.form1.txtFunction.value=document.form1.cmbFunction.value;
			    }
		    }
		    else
		    {
		        if(document.form1.cmbFunction.value != "0") 
		        {
			    document.form1.txtFunction.value=document.form1.txtFunction.value + "," + document.form1.cmbFunction.value;
			    }
		    }
	    }



//dragging code 
function ob_attachDragAndDrop(el)
{
	el.ondragstart = function(){return false;};
	if(document.all)
	{
		el.onmousedown=new Function("ob_dnd_t10(null,this);");
		el.onmouseup=new Function("ob_dnd_t12();");
	}
	else
	{
		el.setAttribute("onmousedown","ob_dnd_t10(event,this);");
		el.setAttribute("onmouseup","ob_dnd_t12();");
	}
}

function ob_dnd_t10(event,el)
{
	// EVENT. Before Drag start.
	ob_dnd_tvy=true;
	ob_dnd_tvi=el;
	myiddragging=true;
	// events for mouse move
	document.onmousemove=function(e){ob_dnd_t11(e);o_A=null;};
	document.onmouseup=function(e){ob_dnd_t13(e, null, null, null);};
	document.onselectstart=function(){return false;};
	document.onmousedown=function(){return false;};
	
	//mytd=document.getElementById("tdactivedata");
	//mytd.onmouseup=new Function("newmemberup();");
}

function ob_dnd_t12()
{
	ob_dnd_tvy=false;
	
	// remove the events
	document.onmousemove=null;
	document.onselectstart=function(){return true;};
	document.onmousedown=function(){return true;};
}
    
function ob_dnd_t11(event)
{
	if(ob_dnd_tva==true)
	{
		if(window.event)
		{
			var event=window.event;
			ob_dnd_tvo=event.x;
			ob_dnd_tvp=event.y;
		}
		else
		{
			ob_dnd_tvo=event.pageX;
			ob_dnd_tvp=event.pageY;
		}
		ob_dnd_tva=false;
		return;
	}
	else
	{
		if(window.event)
		{
			var event=window.event;
			ob_dnd_tvs=event.x;
			ob_dnd_tvd=event.y;
		}
		else
		{
			ob_dnd_tvs=event.pageX;
			ob_dnd_tvd=event.pageY;
		}
	}
	
	if((Math.abs(ob_dnd_tvs-ob_dnd_tvo)>5)||(Math.abs(ob_dnd_tvd-ob_dnd_tvp)>5)){}
	else{return;}
	
	if(ob_dnd_tvy==false) return;
	if(ob_dnd_tvu==null)
	{
		// create the dragable div
		ob_dnd_tvu = document.createElement('div');
		document.body.appendChild(ob_dnd_tvu);
		ob_dnd_tvu.id="ob_dnd_drag";

		// create the note ghost
		var tbl = document.createElement("TABLE");
		tbl.id = ob_dnd_tvi.id;
		var eb = tbl.appendChild(document.createElement("tbody"));
		var etr = eb.appendChild(document.createElement("tr"));
		//var etdIcon = etr.appendChild(document.createElement("td"));
		var etdContent = etr.appendChild(document.createElement("td"));
		//var img = etdIcon.appendChild(document.createElement("img"));
				
		//img.src = "images/indi1.gif";
		
        ob_dnd_tvu.className = "ob_t2";
		//etdIcon.className="ob_t2";
		etdContent.className="ob_t2";
		etdContent.innerHTML=$get("txtdisplay").value;
		etdContent.style.backgroundColor="#C2D0F0";
		etdContent.style.color="#000000";
		etdContent.style.fontWeight="Bold";
		ob_dnd_tvu.appendChild(tbl);

		ob_dnd_tvu.style.width=200;
		ob_dnd_tvu.style.position = "absolute";
		ob_dnd_tvu.style.zIndex="0";
		ob_dnd_tvu.style.filter="Alpha(Opacity='80',FinishOpacity='0',Style='1',StartX='0',StartY='0',FinishX='100',FinishY='100')";		
		
		if(window.event) 
		{
			ob_dnd_tvt=document.body.scrollLeft;
			ob_dnd_tvq=document.body.scrollTop;
		}
		else
		{
			ob_dnd_tve=event.pageX;
			ob_dnd_tvr=event.pageY;
		}
	}

//	// show the ghost div at the mouse coords
	if(window.event)
	{
		var event=window.event;
		ob_dnd_tvu.style.left=event.x+ob_dnd_tvt-15;
		ob_dnd_tvu.style.top=event.y+ob_dnd_tvq-15;
	}
	else
	{
		ob_dnd_tvu.style.left=event.pageX-15;
		ob_dnd_tvu.style.top=event.pageY-15;
	}
		
}

function ob_dnd_t13(event, ob_dnd_tvh, ob_dnd_tvj)
{      
	var e,lensrc,s,s2;ob_dnd_tva=true;

	// if no node as start node
	if(ob_dnd_tvu==null){return;}
	
	// get mouse position
	if (ob_dnd_tvh == null || ob_dnd_tvj == null)
	{
		if(window.event)
		{
			var event=window.event;
			var ob_dnd_tvh=event.x+ob_dnd_tvt;
			var ob_dnd_tvj=event.y+ob_dnd_tvq;
		}
		else
		{
			var ob_dnd_tvh=event.pageX;
			var ob_dnd_tvj=event.pageY;
		}
	}
	
	var ob_dnd_tvf,flagReturn=false;
	ob_dnd_tvu.style.display="none";
	
	//For Active
	mytd=document.getElementById("tdactivedata");
	var top=ob_dnd_t14(mytd);// - objGrid.scrollTop;
	// get left of item
	var left=ob_dnd_t15(mytd);// - objGrid.scrollLeft;
	// if mouse up was inside this item
	if((ob_dnd_tvj >= top && ob_dnd_tvj <= mytd.offsetHeight + top) && (ob_dnd_tvh >= left&&ob_dnd_tvh <= mytd.offsetWidth+left))
	{
	   
        ids=$get("txtdisplayid").value;
        $get("Mydragid").value=ids;
        document.getElementById('LbtnActive').click();
    }
	
	//For Pending
	mytd=document.getElementById("tdpendingdata");
	var top=ob_dnd_t14(mytd);// - objGrid.scrollTop;
	// get left of item
	var left=ob_dnd_t15(mytd);// - objGrid.scrollLeft;
	// if mouse up was inside this item
	if((ob_dnd_tvj >= top && ob_dnd_tvj <= mytd.offsetHeight + top) && (ob_dnd_tvh >= left&&ob_dnd_tvh <= mytd.offsetWidth+left))
	{
	    
        ids=$get("txtdisplayid").value;
        $get("Mydragid").value=ids;
        document.getElementById('LbtnPending').click();
	}
	
	//For Delete
	mytd=document.getElementById("tddeletedata");
	var top=ob_dnd_t14(mytd);// - objGrid.scrollTop;
	// get left of item
	var left=ob_dnd_t15(mytd);// - objGrid.scrollLeft;
	// if mouse up was inside this item
	if((ob_dnd_tvj >= top && ob_dnd_tvj <= mytd.offsetHeight + top) && (ob_dnd_tvh >= left&&ob_dnd_tvh <= mytd.offsetWidth+left))
	{
        ids=$get("txtdisplayid").value;
        $get("Mydragid").value=ids;
        document.getElementById('LbtnDelete').click();
	}
	
	//For Profile
	mytd=document.getElementById("tdprofiledata");
	var top=ob_dnd_t14(mytd);// - objGrid.scrollTop;
	// get left of item
	var left=ob_dnd_t15(mytd);// - objGrid.scrollLeft;
	// if mouse up was inside this item
	if((ob_dnd_tvj >= top && ob_dnd_tvj <= mytd.offsetHeight + top) && (ob_dnd_tvh >= left&&ob_dnd_tvh <= mytd.offsetWidth+left))
	{
        ids=$get("txtdisplayid").value;
        $get("Mydragid").value=ids;
        document.getElementById('LbtnProfile').click();
	}
	//For Cr_Limit
	mytd=document.getElementById("tdhistorydata");
	var top=ob_dnd_t14(mytd);// - objGrid.scrollTop;
	// get left of item
	var left=ob_dnd_t15(mytd);// - objGrid.scrollLeft;
	// if mouse up was inside this item
	if((ob_dnd_tvj >= top && ob_dnd_tvj <= mytd.offsetHeight + top) && (ob_dnd_tvh >= left&&ob_dnd_tvh <= mytd.offsetWidth+left))
	{
        ids=$get("txtdisplayid").value;
        $get("Mydragid").value=ids;
        document.getElementById('LbtnCrLimit').click();
	}
	
	//For Members
	mytd=document.getElementById("tdmembers");
	var top=ob_dnd_t14(mytd);// - objGrid.scrollTop;
	// get left of item
	var left=ob_dnd_t15(mytd);// - objGrid.scrollLeft;
	// if mouse up was inside this item
	if((ob_dnd_tvj >= top && ob_dnd_tvj <= mytd.offsetHeight + top) && (ob_dnd_tvh >= left&&ob_dnd_tvh <= mytd.offsetWidth+left))
	{
        ids=$get("txtdisplayid").value;
        $get("Mydragid").value=ids;
        document.getElementById('LbtnMembers').click();
	}
	
	//For Lead
	mytd=document.getElementById("tdleaddata");
	var top=ob_dnd_t14(mytd);// - objGrid.scrollTop;
	// get left of item
	var left=ob_dnd_t15(mytd);// - objGrid.scrollLeft;
	// if mouse up was inside this item
	if((ob_dnd_tvj >= top && ob_dnd_tvj <= mytd.offsetHeight + top) && (ob_dnd_tvh >= left&&ob_dnd_tvh <= mytd.offsetWidth+left))
	{
        ids=$get("txtdisplayid").value;
        $get("Mydragid").value=ids;
        document.getElementById('LbtnLead').click();
	}
	
	//For Reward Point
	mytd=document.getElementById("tdreward");
	var top=ob_dnd_t14(mytd);// - objGrid.scrollTop;
	// get left of item
	var left=ob_dnd_t15(mytd);// - objGrid.scrollLeft;
	// if mouse up was inside this item
	if((ob_dnd_tvj >= top && ob_dnd_tvj <= mytd.offsetHeight + top) && (ob_dnd_tvh >= left&&ob_dnd_tvh <= mytd.offsetWidth+left))
	{
        ids=$get("txtdisplayid").value;
        $get("Mydragid").value=ids;
        document.getElementById('LbtnRewardPoint').click();
	}
	
	//For History
	mytd=document.getElementById("tdrewardpointdata");
	var top=ob_dnd_t14(mytd);// - objGrid.scrollTop;
	// get left of item
	var left=ob_dnd_t15(mytd);// - objGrid.scrollLeft;
	// if mouse up was inside this item
	if((ob_dnd_tvj >= top && ob_dnd_tvj <= mytd.offsetHeight + top) && (ob_dnd_tvh >= left&&ob_dnd_tvh <= mytd.offsetWidth+left))
	{
        ids=$get("txtdisplayid").value;
        $get("Mydragid").value=ids;
        document.getElementById('LbtnHistory').click();
	}
	// if drop target not null
	if(ob_dnd_tvf!=null)
	{				    
		// remove the mouse events
		document.onmousemove="";
		
		// remove the ghost div
		document.body.removeChild(ob_dnd_tvu);
	}
	else
	{
		// remove the ghost div
		document.body.removeChild(document.getElementById("ob_dnd_drag"));
	}

	ob_dnd_tvu=null;
	ob_dnd_tvy=false;
	myiddragging=false;
	// restore mouse events
	document.onselectstart=function(){return true;};
	document.onmousedown=function(){return true;};
	document.onmouseup=null;
	document.onmousemove = "";		
	// EVENT. After Drag & Drop finished.
	
	
}

// get left position
function ob_dnd_t15(vz){
    var pos=0;
    if(vz.offsetParent){
        while(vz.offsetParent){
            pos+=vz.offsetLeft;vz=vz.offsetParent;
        }
    }else if(vz.x)
        pos+=vz.x;
        return pos;
}

// get top position
function ob_dnd_t14(ue){
    var pos=0;
    if(ue.offsetParent){
        while(ue.offsetParent){
            pos+=ue.offsetTop;
            ue=ue.offsetParent;
        }
    }else if (ue.y)
        pos+=ue.y;
        return pos;
}