//====================================================================================================
//	File Name		:	index.js
//----------------------------------------------------------------------------------------------------
//	Purpose			:	Input validation and action handling
//	Author			:	Dinesh Sailor
//	Creation Date	:	11-June-2004
//	Copyright		:	Copyrights © 2004 Dot Infosys
//	Email			:	dinesh@dotinfosys.com
//	History			:
//						Date						Author						Remark
//						11-June-2004				Dinesh Sailor				Initial Release
//
//====================================================================================================

function rotate_image()
{
	if (do_rotate) 
	{ 
		curr_image++;
		if (curr_image == image_cache.length) 
		{ 
			curr_image = 0;
		}
		document.homepage_img.src = image_cache[curr_image].src;
	} 
	else 
	{ 
		window.setTimeout('rotate_image();', 2000);
	}
}

function Start()
{
	if(document.all)
	{
		ieslider1.style.top = sheight;
		iemarquee(ieslider1);
	}
	else if(document.layers)
	{
		document.ns4slider.document.ns4slider1.top = sheight;
		document.ns4slider.document.ns4slider1.visibility = 'show';
		ns4marquee(document.ns4slider.document.ns4slider1);
	}
	else if(document.getElementById && !document.all)
	{
		document.getElementById('ns6slider1').style.top = sheight;
		ns6marquee(document.getElementById('ns6slider1'));
	}
}

function iemarquee(whichdiv)
{
	iediv = eval(whichdiv);
	
	if (iediv.style.pixelTop > 0 && iediv.style.pixelTop <= sspeed)
	{
		iediv.style.pixelTop = 0;
	}
	if (iediv.style.pixelTop >= (sheight * -3))
	{
		iediv.style.pixelTop -= sspeed;
		setTimeout("iemarquee(iediv)",100);
	}
	else
	{
		iediv.style.pixelTop = sheight;
		iediv.innerHTML = arrProperty[i];
		setTimeout("iemarquee(iediv)",100);

		if (i == arrProperty.length-1)
			i=0;
		else
			i++;
	}
}

function ns4marquee(whichlayer)
{
	ns4layer = eval(whichlayer);
	if (ns4layer.top > 0 && ns4layer.top <= sspeed)
	{
		ns4layer.top = 0;
		setTimeout("ns4marquee(ns4layer)",100);
	}
	if (ns4layer.top>=sheight*-1)
	{
		ns4layer.top -= sspeed;
		setTimeout("ns4marquee(ns4layer)",100);
	}
	else
	{
		ns4layer.top = sheight;
		ns4layer.document.write(arrProperty[i]);
		ns4layer.document.close();
		
		if (i==arrProperty.length-1)
			i=0;
		else
			i++;
	}
}

function ns6marquee(whichdiv)
{
	ns6div = eval(whichdiv);
	
	if (parseInt(ns6div.style.top) > 0 && parseInt(ns6div.style.top) <= sspeed)
	{
		ns6div.style.top = 0;
		setTimeout("ns6marquee(ns6div)",100);
	}
	
	if (parseInt(ns6div.style.top) >= sheight * -1)
	{
		ns6div.style.top = parseInt(ns6div.style.top) - sspeed;
		setTimeout("ns6marquee(ns6div)",100);
	}
	else
	{
		ns6div.style.top = sheight;
		ns6div.innerHTML = arrProperty[i];
		if (i == arrProperty.length-1)
			i=0;
		else
			i++;
	}
}

//====================================================================================================
// block for tool tips starts here
//====================================================================================================
var ie = document.all ? 1 : 0;
var ns = document.layers ? 1 : 0;

if(ns){doc = "document."; sty = "";}
if(ie){doc = "document.all."; sty = ".style";}

var initialize = 0;
var Ex, Ey, topColor, subColor, ContentInfo;

if(ie)
{
	Ex = "event.x";
	Ey = "event.y";
	
	topColor = "#808080";
	subColor = "#C0C0C0";
}

if(ns)
{
	Ex = "e.pageX";
	Ey = "e.pageY";
	window.captureEvents(Event.MOUSEMOVE);
	window.onmousemove=overhere;
	topColor = "#808080";
	subColor = "#C0C0C0";
}

function MoveToolTip(layerName, FromLeft, FromTop, e)
{
	menuobj=ie? document.all.ToolTip : ns? document.getElementById("ToolTip") :  ""

	menuobj.contentwidth=(ie||ns)? menuobj.offsetWidth : menuobj.document.width
	menuobj.contentheight=(ie||ns)? menuobj.offsetHeight : menuobj.document.height
	eventX=ie? event.clientX : ns? e.clientX : e.x
	eventY=ie? event.clientY : ns? e.clientY : e.y
	
	//Find out how close the mouse is to the corner of the window
	var rightedge=ie? document.body.clientWidth-eventX : window.innerWidth-eventX
	var bottomedge=ie? document.body.clientHeight-eventY : window.innerHeight-eventY

	//if the horizontal distance isn't enough to accomodate the width of the context menu
	if (rightedge<menuobj.contentwidth)
	//move the horizontal position of the menu to the left by it's width
		left1=ie? document.body.scrollLeft+eventX-menuobj.contentwidth : ns? window.pageXOffset+eventX-menuobj.contentwidth : eventX-menuobj.contentwidth
	else
	//position the horizontal position of the menu where the mouse was clicked
		left1=ie? document.body.scrollLeft+eventX : ns? window.pageXOffset+eventX : eventX
	
	//same concept with the vertical position
	if (bottomedge<menuobj.contentheight)
		top1=ie? document.body.scrollTop+eventY-menuobj.contentheight : ns? window.pageYOffset+eventY-menuobj.contentheight : eventY-menuobj.contentheight
	else
		top1=ie? document.body.scrollTop+event.clientY : ns? window.pageYOffset+eventY : eventY

	if(ie)
	{
		eval(doc + layerName + sty + ".top = "  + top1);
	}
	if(ns){eval(doc + layerName + sty + ".top = "  +  eval(FromTop));}
	eval(doc + layerName + sty + ".left = " + left1);
/*	if(ie)
	{
		eval(doc + layerName + sty + ".top = "  + (eval(FromTop) + document.body.scrollTop));
	}
	if(ns){eval(doc + layerName + sty + ".top = "  +  eval(FromTop));}
	eval(doc + layerName + sty + ".left = " + (eval(FromLeft) + 15));*/
}

function ReplaceContent(layerName)
{   
	if(ie)
	{
		document.all[layerName].innerHTML = new String(ContentInfo);
	}
	if(ns)
	{
		with(document.layers[layerName].document) 
		{ 
		   open(); 
		   write(ContentInfo); 
		   close(); 
		}
	}
}

function Activate()
{
	initialize=1;
}
function deActivate(){initialize=0;}

function overhere(e)
{
	if(initialize==1)
	{
//		MoveToolTip("ToolTip", "event.x", "event.y", "e");
		MoveToolTip("ToolTip", Ex, Ey, "e");
		eval(doc + "ToolTip" + sty + ".visibility = 'visible'");
	}
	else
	{
		MoveToolTip("ToolTip", 0, 0, "e");
		eval(doc + "ToolTip" + sty + ".visibility = 'hidden'");
	}
}

function EnterContent(layerName, TTitle, TContent)
{  
	ContentInfo = '<table border="0" width="150" cellspacing="0" cellpadding="0">'+
	'<tr><td width="100%" bgcolor="#000000">'+
	
	'<table border="0" width="100%" cellspacing="1" cellpadding="0">'+
	'<tr><td width="100%" bgcolor="#FFFFFF">'+
	
	'<table border="0" width="90%" cellpadding="0" cellspacing="1" align="center">'+
	
	'<tr><td width="100%"'+
	
	' class="boldText">'+TContent+'</font>'+
	
	'</td></tr>'+
	'</table>'+
	
	'</td></tr>'+
	'</table>'+
	
	'</td></tr>'+
	'</table>';
	
	ReplaceContent(layerName);
}
//====================================================================================================
// block for tool tips end here
//====================================================================================================

//====================================================================================================
//	Function Name	:	Next_Click()
//	Purpose			:	This function will set the Link Id and action and then submit the form.
//	Parameters		:	LinkId  - Link Id whose detail will to be delete
//	Return			:	none
//	Author			:	Jinasa Naik
//	Creation Date	:	22-Aug-2003
//----------------------------------------------------------------------------------------------------
function Next_Click()
{
	with(document.frmCalender)
	{
		Action.value = "Next";
		submit();
	}
}

//====================================================================================================
//	Function Name	:	Prev_Click()
//	Purpose			:	This function will set the Link Id and action and then submit the form.
//	Parameters		:	LinkId  - Link Id whose detail will to be delete
//	Return			:	none
//	Author			:	Jinasa Naik
//	Creation Date	:	22-Aug-2003
//----------------------------------------------------------------------------------------------------
function Prev_Click()
{
	with(document.frmCalender)
	{
		Action.value = "Previous";
		submit();
	}
}

//====================================================================================================
//	Function Name	:	Show_Click()
//	Purpose			:	This function will set the Link Id and action and then submit the form.
//	Parameters		:	LinkId  - Link Id whose detail will to be shown
//	Return			:	none
//	Author			:	Jignasa Naik
//	Creation Date	:	22-Aug-2003
//----------------------------------------------------------------------------------------------------
function ShowEvent_Click(Month,Year,CountyId)
{
	with(document.frmCalender)
	{
		prevmonth.value = Month;
		prevyear.value  = Year;
		county_id.value = CountyId;
		Action.value = "Show";
		submit();
	}
}

function ShowSchedule_Click(Month,Year,Day,CountyId,LevelId,Gender)
{
	with(document.frmCalender)
	{

		action = "schedule.php?&current_date="+Year+"-"+Month+"-"+Day;
		prevmonth.value = Month;
		prevyear.value  = Year;
		prevday.value  = Day;
		county_id.value = CountyId;
		level_id.value  = LevelId;
		gender.value  = Gender;
		Action.value = "View All";
		submit();
	}
}

function redirectPage()
{
	document.frmIndex.submit();
}

function Poll_Vote_Click()
{
	with(document.frmPoll)
	{
		Action.value = "A_VOTE";
		submit();
	}
}
function showWindow(url,discount)
{
window.open('url');
window.open('discount');
}