// JavaScript Document

//Drag & Drop  functionality :
//Author @ Balasubramanian





	
		

	//Layer Functions

	var ie4="";
	var ns4="";
	var ns6="";
	
	ns4 = (document.layers)? true:false
	ie4 = (document.all)? true:false
	ns6 = ((document.getElementById)&&(!ie4))?true:false

	
	function MM_setTextOfLayer(objName,x,newText) { //v3.0
	loading=true;
	  if ((obj=MM_findObj(objName))!=null) with (obj)
		if (ns4) {
		document.write(unescape("font face='Verdana', size='-2'>"+newText+"</font>"));
		document.close();
		}
		else {
			innerHTML = unescape(newText);
		}
	}

	function MM_findObj(n, d) { //v4.0
	  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	  for(i=0;!x&&d.layers&&id.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	  if(!x && document.getElementById) x=document.getElementById(n); return x;
	}

	function isDefined(obj){
		return (typeof(obj) != "undefined")
	}


    function cancelEvent() {
            window.event.returnValue = false;
			return false;
        }
function onSelect(e){
	//status= "cancelEvent"
	cancelEvent()
}

var ctrlDwn = false
var isselStart = false

var dodrag = false;
function activate(){
	dodrag = !dodrag;
	//alert(dodrag)
}
<!--

// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false



// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)
if (!IE) document.captureEvents(Event.MOUSEUP)
if (!IE) document.captureEvents(Event.MOUSEDOWN)


// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;
document.onmouseup = onMouseUp;
document.onmousedown = onMouseDown;
document.onkeydown = onKeyDown
document.onkeyup = onKeyUp
//document.onselectstart = onSelect
//document.onselect = onSelect



// Temporary variables to hold mouse x-y pos.s
var tempX = 0
var tempY = 0

// Main function to retrieve mouse x-y pos.s


function getMouseXY(e) {
	  if(document.getElementById("dragLayer") == null || typeof(document.getElementById("dragLayer")) == "undefined") return false;
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  
  if(dodrag){
  	obj = document.getElementById("dragLayer");
	
	b1 =  document.getElementById("btn1"); 
	
	if(typeof(obj) != "undefined"){
		//window.status = tempX + "px , " + tempY + "px";
			imght  = 130;
			imgwdth  = 160;
			//addToList(id)
			
			obj.style.left = (tempX -( 1 + imght)) + "px"
			obj.style.top = (tempY -( 1 + imgwdth)) + "px"
	}
	if(typeof(b1) != "undefined"){
		//b1.value = b1.id + " | " + b1.style.left		
		//targ.style.backgroundColor=targ.style.backgroundColor != "#cccccc"?"#cccccc":"#ffffff"
	}
	
  }
  
  return true
  
  
}


function onMouseUp(e){
	hideLayer()
	
	return true
} 


function hideLayer(){
	
  if(document.getElementById("dragLayer") == null || typeof(document.getElementById("dragLayer")) == "undefined") return false;
	if(dodrag && !ctrlDwn){
	 dodrag = false;
	 isselStart = false
	 resetList()
	}
	obj = document.getElementById("dragLayer");
	//obj.style.left = (tempX + 1) + "px"
	//obj.style.top = (tempY + 1) + "px"
	if(typeof(obj) != "undefined")
		obj.style.visibility="hidden";


}

function onMouseDown(e){
  if(document.getElementById("dragLayer") == null || typeof(document.getElementById("dragLayer")) == "undefined") return false;
	
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
			
			obj = document.getElementById("dragLayer");
			imght  = 130;
			imgwdth  = 160;
			//addToList(id)
			
			if(typeof(obj) != "undefined" && obj != null){
				obj.style.left = (tempX -( 1 + imght)) + "px"
				obj.style.top = (tempY -( 1 + imgwdth)) + "px"
			}
	//obj.style.visibility="visible";
	 //b1 =  document.getElementById("src"); 
	// b1.style.visibility="visible";
	//dodrag = true;
	return true
}

function onKeyUp(e){
	ctrlDwn = false
}

function onKeyDown(e){
	var keyeascii 
	if(ie4){
		keyeascii = event.keyCode
	}
	else
		keyeascii = e.which;

	if(keyeascii == 17) ctrlDwn = true
}


var lastsec = 0;
var totsecsspent = 0;
function doTime(){
	dispobj = document.getElementById("disp");
	var tm = new Date();
	var sec = tm.getSeconds();
	totsecsspent = lastsec != sec?totsecsspent+1:totsecsspent;
	lastsec =sec;
	time = (Math.floor(totsecsspent / 60))  + ":" + (totsecsspent % 60) 	
	dispobj.value = time 
	setTimeout("doTime()",300)
}

function setVal(patchimgpath,imgclrname,boolForceAdd){
	  if(document.getElementById("dragLayer") == null || typeof(document.getElementById("dragLayer")) == "undefined") return false;
	//
	//status =  boolForceAdd + " - " +  ctrlDwn  + " " + id 
	if(!boolForceAdd && ctrlDwn ) return;
	else if (ctrlDwn)
		isselStart = boolForceAdd
	//status = isselStart
	if(isselStart){
	 	//b1 = document.getElementById("src"); 
		//if(isDefined(b1)) {
			//b1.value="ID: "+id;
			obj = document.getElementById("dragLayer");
			
			imght  = 130;
			imgwdth  = 160;
			//addToList(id)
			
			obj.style.left = (tempX -( 1 + imght)) + "px"
			obj.style.top = (tempY -( 1 + imgwdth)) + "px"
			obj.style.visibility="visible";
			MM_setTextOfLayer('dragLayer','',getIDTable(patchimgpath,imgclrname));
			dodrag = true;
		//}
		
	}
}

function getIDTable(patchimgpath,imgclrname){		
			strTableData = "<table style='border-collapse:collapse' bgcolor='#ffffff' class='overall' cellpadding=2 cellspacing=0 border=1 bordercolor=black>"			
			strTableData += "<tr><td ><img  id='xLayerPic' src='" + patchimgpath + "'></td></tr>";
			if(imgclrname != "")
				strTableData += "<tr><td ><b class=blk9pt>" + imgclrname + "<b></td></tr>";			
			strTableData += "</table>"
			return strTableData
}
function resetList(){
			obj = document.getElementById("dragLayer");
			obj.style.left = (tempX + 1) + "px"
			obj.style.top = (tempY + 1) + "px"
			obj.style.visibility="visible";
			MM_setTextOfLayer('dragLayer','',"");
}
function addToList(id){
	
	listfrmObj = document.forms["frmIDList"]["idlist"]	
	var strlist = "";
	if(isDefined(listfrmObj)){
		strlist = listfrmObj.value
		strlist = doCharReplace(strlist," ","")
		if(strlist != ""){
			var listarr = strlist.split(",")
			if(hasID(listarr,id) == -1){//not in list
				addToArray(listarr,id);
			}
			else ;
				//listarr = removefromArray(listarr,id)
				
			strlist = listarr.toString()
		}
		else{
			strlist = id + ""
		}
	}

	strlist = doCharReplace(strlist,"\"","")
	strlist = doCharReplace(strlist,"[","")
	strlist = doCharReplace(strlist,"]","")
	strlist = doCharReplace(strlist," ","")

	listfrmObj.value = strlist
	//status = listfrmObj.value
	
}

function doCharReplace(target,srchchar,replacechar){
	var targLen = target.length
	var srcLen = srchchar.length
	var newStr = ""

	if(target != ""){
		for(var ctr=0;ctr<targLen;ctr++){
			var currChar = target.charAt(ctr)
			if(currChar != srchchar)
				newStr += currChar
			else
				newStr += replacechar
		}		
	}
	return newStr
}
function hasID(arrayobj,id){
	var arrlen = arrayobj.length
	//alert(arrlen + " " + arrayobj)
	if(arrlen > 0){
		for(var ctr = 0;ctr < arrlen;ctr++){
			var currval  = arrayobj[ctr];
			if(parseInt(currval) == id){
				return currval 
			}
		}		
	}
	return -1
}

function addToArray(arrayobj,id){
	var arrlen = arrayobj.length
	//alert(arrlen + " add")
	if(arrlen > 0)
		arrayobj[arrlen] = id
	else
		arrayobj[0] = id	
}
function removefromArray(arrayobj,id){
	var arrlen = arrayobj.length
	//alert(arrlen + " add")
	var newArr
	if(arrlen > 0){		
		var currlist = ""
		for(var ctr = 0;ctr < arrlen;ctr++){
			var currval  = arrayobj[ctr];			
			if(parseInt(currval) != id){
				if(currlist != ""){
					currlist += "," + currval
				}
				else
					currlist = currval
			}
		}
		newArr = currlist.split(",")
	}
	return newArr
}

function selStart(){
	isselStart = !isselStart
}



function setCategoryIDs(catID,strList,formname){
	if(strList != "" && !isNaN(catID) && catID >= 0){
			document.forms[formname]["act"].value="setcat";
			document.forms[formname]["selids"].value = strList
			document.forms[formname]["catid"].value = catID
			//alert(targObj.form.action)
			document.forms[formname].submit()
	}
}




/***********************************************
* Disable select-text script- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for full source code
* Modified here to exclude form tags properly, cross browser by jscheuer1
***********************************************/

//form tags to omit:
var omitformtags=["input", "textarea", "select"]

function disableselect(e){
for (i = 0; i < omitformtags.length; i++)
if (omitformtags[i]==(e.target.tagName.toLowerCase()))
return;
return false
}

function reEnable(){
return true
}

function noSelect(){
if (typeof document.onselectstart!="undefined"){
document.onselectstart=new Function ("return false")
if (document.getElementsByTagName){
tags=document.getElementsByTagName('*')
for (j = 0; j < tags.length; j++){
for (i = 0; i < omitformtags.length; i++)
if (tags[j].tagName.toLowerCase()==omitformtags[i]){
tags[j].onselectstart=function(){
document.onselectstart=new Function ('return true')
}
		if (tags[j].onmouseup!==null){
		var mUp=tags[j].onmouseup.toString()
		mUp='document.onselectstart=new Function (\'return false\');\n'+mUp.substr(mUp.indexOf('{')+2,mUp.lastIndexOf('}')-mUp.indexOf('{')-3);
		tags[j].onmouseup=new Function(mUp);
		}
		else{
				tags[j].onmouseup=function(){
				document.onselectstart=new Function ('return false')
				}
		}
}
}
}
}
else{
document.onmousedown=disableselect
document.onmouseup=onMouseUp
}
}

window.onload=noSelect;
