
//====================================================================================================
//	File Name		:	functions.js
//----------------------------------------------------------------------------------------------------
//	Purpose			:	Javascript Utility functions
//	Author			:	Nirmal Patel
//	Creation Date	:	05-May-2003
//	Copyright		:	Copyrights  2003 Dot Infosys
//	Email			:	dinesh@dotinfosys.com
//	History			:
//						Date						Author						Remark
//						05-May-2003					Nirmal Patel				Initial Release
//
//====================================================================================================

//====================================================================================================
//	Function Name	:	popupWindowURL
//	Purpose			:	Whenever you wanna open a link into a new window just call this function
//								you need to pass some arguemnts as described below.
//	Parameters		:
//								url  = url to be open in the new window
//								winname = winname is the window name for the reference of that window
//								w is the width
//								h is the height
//								menu is the parameter, if you want menubar to be enabled on the window
//								resize if you wanna resize the window
//								scroll i fyou needed
//	Return			:	true or false
//	Author			:	Nirmal Patel
//	Creation Date	:	05-May-2003
//----------------------------------------------------------------------------------------------------

function popupWindowURL(url, winname,  w, h, menu, resize, scroll) {

    var x = (screen.width-w)/2;
    var y = (screen.height-h)/3;

	if (winname == null) winname = "newWindow";
	if (w == null) w = 800;
	if (h == null) h = 600;
	if (resize == null) resize = 1;

	menutype   = "nomenubar";
	resizetype = "noresizable";
	scrolltype = "noscrollbars";
	if (menu) menutype = "menubar";
	if (resize) resizetype = "resizable";
	if (scroll) scrolltype = "scrollbars";
	//alert(url+","+x+","+winname);
    cwin=window.open(url,winname,"top=" + y + ",left=" + x + ",screenX=" + x + ",screenY=" + y + "," + "status," + menutype + "," + scrolltype + "," + resizetype + ",width=" + w + ",height=" + h);

	if (!cwin.opener) cwin.opener=self;
	cwin.focus();

	return true;
}

function CheckUncheck_Click(fld, status)
{
	if(fld.length)
		for(i=0; i < fld.length; i++)
			fld[i].checked = status;
	else
		fld.checked = status;
}

function UploadImage_Change(obj, imgTag, defaultVal, defaultWidth)
{
	imgTag.width=120;

	if(obj.value == '')
		imgTag.src = defaultVal;
	else
	{
		imgTag.src = obj.value;
		if(defaultWidth != '')
			imgTag.width=defaultWidth;
	}
}

function SetTime()
{
	if(!document.all('timeId'))	return;

	var Hours;
	var Mins;
	var Time;

	Stamp = new Date();

	Hours = Stamp.getHours();
	
	if (Hours >= 12)
		Time = " PM";
	else
		Time = " AM";
	
	if (Hours > 12)
		Hours -= 12;
	
	if (Hours == 0)
		Hours = 12;
	
	Mins = Stamp.getMinutes();

	if (Mins < 10)
		Mins = "0" + Mins;

	Sec = Stamp.getSeconds();
	if (Sec < 10)
		Sec = "0" + Sec;

	document.all('timeId').innerHTML = ("&nbsp;" + Hours + ":" + Mins + ":" + Sec + Time);
}

//setInterval('SetTime()',1000);

function getDate(parmDate)
{
	var m_names = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September","October", "November", "December");

	var curr_date = parmDate.getDate();

	var sup = "";

	if (curr_date == 1 || curr_date == 21 || curr_date ==31)
	{
	   sup = "st";
	}
	else if (curr_date == 2 || curr_date == 22)
	{
	   sup = "nd";
	}
	else if (curr_date == 3 || curr_date == 23)
	{
	   sup = "rd";
	}
	else
	{
	   sup = "th";
	}

	var curr_month 	= parmDate.getMonth();
	var curr_year 	= parmDate.getFullYear();

	return (curr_date + "<SUP>" + sup + "</SUP> " + m_names[curr_month] + " " + curr_year);
}

function change_area(frm,lstarea,locSel,loc_cmb)
{
	try
	{
		cat = lstarea.options[lstarea.selectedIndex].value;
		with(frm)
		{
			for(i=0; i<arrLocation.length; i++)
			{
				if(arrLocation[i][0] == cat)	break;
			}
		
			if(i!=arrLocation.length)
			{
				loc_cmb.disabled=false;
				loc_cmb.length = 1;
				
				for(j=1; j<arrLocation[i].length; j+=3)
				{
					loc_cmb.length++;
					loc_cmb[loc_cmb.length-1].value = arrLocation[i][j];
					loc_cmb[loc_cmb.length-1].text = arrLocation[i][j+1];
					
					if(locSel == arrLocation[i][j])
					{
						loc_cmb[loc_cmb.length-1].selected = true;
					}
				}
			}
			else
			{
				loc_cmb.length = 1;
				loc_cmb.disabled=true;
			}
			
		}
	}
	catch(error)
	{
	}
}

function attachEventListener(target, eventType, functionRef, capture) 
{ 

	if (typeof target.addEventListener != "undefined") 
	{ 
		target.addEventListener(eventType, functionRef, capture); 
	} 
	else if (typeof target.attachEvent != "undefined") 
	{ 
		var functionString = eventType + functionRef; 
		target["e" + functionString] = functionRef; 
		
		target[functionString] = function(event) 
		{ 
			if (typeof event == "undefined") 
			{ 
				event = window.event; 
			} 
			target["e" + functionString](event); 
		}; 
		
		target.attachEvent("on" + eventType, target[functionString]); 
	} 
	else 
	{ 
		eventType = "on" + eventType; 
		
		if (typeof target[eventType] == "function") 
		{ 
			var oldListener = target[eventType]; 
			
			target[eventType] = function() 
			{ 
				oldListener(); 
				
				return functionRef(); 
			} 
		} 
		else 
		{ 
			target[eventType] = functionRef; 
		} 
	} 
} 

function detachEventListener(target, eventType, functionRef, capture) 
{ 
	if (typeof target.removeEventListener != "undefined") 
	{ 
		target.removeEventListener(eventType, functionRef, capture) 
	} 
	else if (typeof target.detachEvent != "undefined") 
	{ 
		var functionString = eventType + functionRef; 
		
		target.detachEvent("on" + eventType, target[functionString]); 
		
		target["e" + functionString] = null; 
		target[functionString] = null; 
	} 
	else 
	{ 
		target["on" + eventType] = null; 
	} 
}

function animate()
{
	return;
	var elem = document.getElementById('progress');

	if(elem != null) {
//		alert('here');
		if (pos==0) len += dir;
		if (len>32 || pos>79) pos += dir;
		if (pos>79) len -= dir;
		if (pos>79 && len==0) pos=0;
		elem.style.left = pos;
		elem.style.width = len;
	}
}

function remove_loading() {
	this.clearInterval(t_id);
	var targelem = document.getElementById('loader_container');
	targelem.style.display='none';
	targelem.style.visibility='hidden';
	var t_id = setInterval(animate,60);
}