//This function is used to get the style for the pop-up div
function getStyleObject(objectId) {
	if(document.getElementById && document.getElementById(objectId)) {
		return document.getElementById(objectId).style;
	} else if (document.all && document.all(objectId)) {
		return document.all(objectId).style;
	} else if (document.layers && document.layers[objectId]) {
		return document.layers[objectId];
	} else {
		return false;
	}
}

//This function is used to change visibility of div
function changeObjectVisibility(objectId, newVisibility) {
	var styleObject = getStyleObject(objectId);
	if(styleObject){
		styleObject.visibility = newVisibility;
		if(newVisibility=="hidden")
			styleObject.display="none";
		else
			styleObject.display="";
		
		return true;
	} 
	else {
		return false;
	}
}

//This function is used to move the pop-up div on mouse movement
function moveObject(objectId, newXCoordinate, newYCoordinate,index) {
    changeObjectVisibility(objectId, 'visible');
	var styleObject = getStyleObject(objectId);
	var obj = document.getElementById(objectId);
	var heightPop = obj.clientHeight;
	//newXCoordinate=70;	
	if(newYCoordinate+ heightPop>document.body.scrollHeight-15){
		newYCoordinate=document.body.scrollHeight-heightPop-15;
	}
	if(newYCoordinate < 0){	
		newYCoordinate = 0;
		ChangeText(objectId,index,true,'');
		hideCurrentPopup();
	 }
	if(styleObject) {
		styleObject.left = newXCoordinate+"px";
		styleObject.top = newYCoordinate+"px";
		return true;
	} 
	else {
		return false;
	}
} 
var xOffset = 480;
var yOffset = 250;
var tempX = 480;
var tempY = 250;
var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;

//This function is used to get Mouse X-Y co-ordinates
function getMouseXY(e) {
	if (IE) {
		tempX = event.clientX + document.body.scrollLeft;
		tempY = event.clientY + document.body.scrollTop;
	}
	else {
		tempX = e.pageX;
		tempY = e.pageY;
	}
	if (tempX < 0){tempX = 0;}
	if (tempY < 0){tempY = 0;}
	
	return true;
}

//This function is used to show pop-up div
function showPopup (targetObjectId, eventObj,index,data) {
    
	ChangeText(targetObjectId,index,false,data);
	
	if(eventObj) {
		hideCurrentPopup();
		eventObj.cancelBubble = true;
		var newXCoordinate = (eventObj.x + xOffset + 0);
		var newYCoordinate = ( eventObj.y + yOffset + 0);
		
				
		document.getElementById('nameFieldPopup').style.left = xOffset+"px";
		document.getElementById('nameFieldPopup').style.top = yOffset+"px";
		document.getElementById('nameFieldPopup').style.display = '';
		document.getElementById('nameFieldPopup').style.visibility = 'visible';
		
		xOffset=tempX+"px";
		yOffset=tempY+"px";
		
		moveObject(targetObjectId, tempX, tempY,index);
		if(changeObjectVisibility(targetObjectId, 'visible') ) {
			window.currentlyVisiblePopup = targetObjectId;
			return true;
		} 
		else {
			return false;
		}
	} 
	else {
		return false;
	}
}

//This function is used to hide pop-up div
function hideCurrentPopup() {
	if(window.currentlyVisiblePopup) {
		changeObjectVisibility(window.currentlyVisiblePopup, 'hidden');
		window.currentlyVisiblePopup = false;
		
	}
	window.currentlyVisiblePopup = false;
}

//window.onload = initializeHacks;
document.onclick = hideCurrentPopup;

//This function is used to create window event object according to browser type
function initializeHacks() {
	if ((navigator.appVersion.indexOf('MSIE 5') != -1)&& (navigator.platform.indexOf('Mac') != -1)) 
	{
	}
	createFakeEventObj();
}

//This function is used to create window event object
function createFakeEventObj() {
	if (!window.event) {		
	   window.event = false;
	   window.event=true;
	}
	
}

//This function is used to resize pop-up div
function resizeBlankDiv() {
	getStyleObject('blankDiv').width = document.body.clientWidth - 20;
	getStyleObject('blankDiv').height = document.body.clientHeight - 1;
}
function explorerMacResizeFix () {
}

//This function is used change text after formatting
function ChangeText(target,index, shouldtrim,data){

	
	document.getElementById(target).innerHTML =data;//format(index,shouldtrim);
}



//This function used to show pop-up div on mouse move
function Show(index,data){
    
	showPopup('nameFieldPopup',event,index,data);
	
}

//This function is used to check whether data is to be retrived from internal cache or fresh from site
function divmouseout(e){
	var xx=0;
	var yy=0;
	if(IE) {
		xx=event.clientX;
		yy=event.clientY
	}
	else {
		xx=e.pageX;
		yy=e.pageY;
	}
	hideCurrentPopup();
	if(xx<0 || xx> document.body.scrollWidth || yy<0 || yy> document.body.scrollHeight)
		hideCurrentPopup();
}


