//***************************
// Static Function findPosX *
//***************************
function findPosX(obj)
{	
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
		
	}
	else if (obj.x)
	{
		curleft += obj.x;
	}
	
	return parseInt(curleft);
}

//***************************
// Static Function findPosY *
//***************************
function findPosY(obj)
{	
	var curtop = 0;
	if (obj.offsetParent)
	{	
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
		
	}
	else if (obj.y)
	{
		curtop += obj.y;
	}
	
	return parseInt(curtop);
}

//********************************
// Static Function create loader *
//********************************
function createLoader(obj, loading_image)
{
	// get ids
	var body_node	= document.getElementsByTagName('body').item(0);
						
	// create filter div
	var filter_div	= document.createElement('div');
	filter_div.setAttribute('id', 'loading_filter');
	
	// create loading div
	var loading_div	= document.createElement('div');
	loading_div.setAttribute('id', 'loading_icon');
	
	// get position of trigger obj
	var pos_y = findPosY(obj);
	
	// set position of loading div
	loading_div.style.top	= pos_y + 20 + 'px';
	
	// create loading image
	var loading_img	= document.createElement('img');
	loading_img.setAttribute('src', loading_image);
	
	// append image to loading div
	loading_div.appendChild(loading_img);
	
	// append filter div and loading div to body
	body_node.appendChild(filter_div);
	body_node.appendChild(loading_div);
}

//********************************
// Static Function remove loader *
//********************************
function removeLoader()
{
	// get the loading nodes
	var loading_filter	= document.getElementById('loading_filter');
	var loading_icon	= document.getElementById('loading_icon');
	
	// remove the loading nodes
	loading_filter.parentNode.removeChild(loading_filter);
	loading_icon.parentNode.removeChild(loading_icon);
}

//*****************************
// Static function detect key *
//*****************************
function detectKey(e)
{	
	var code;

	if (!e) var e = window.event;

	if (e.keyCode)
	{
		code = e.keyCode;
	}
	else if (e.which)
	{
		code = e.which;
	}
	
	return code;
}

//***********************************
// Static Function blank validation *
//***********************************
function isBlank(val)
{
	if (val==null)
	{
		return true;
	}
	
	for (var i=0;i<val.length;i++)
	{
		if ((val.charAt(i) != ' ') && (val.charAt(i) != "\t") && (val.charAt(i) != "\n") && (val.charAt(i) != "\r"))
		{
			return false;
		}
	}
	
	return true;
}

//*************************************
// Static Function integer validation *
//*************************************
function isInteger(val)
{
	if (isBlank(val))
	{
		return false;
	}
	
	for (var i=0;i<val.length;i++)
	{
		if (!isDigit(val.charAt(i)))
		{
			return false;
		}
	}
	
	return true;
}

//***********************************
// Static Function digit validation *
//***********************************
function isDigit(num)
{
	if(num.length>1)
	{
		return false;
	}
	
	var string="1234567890";
	
	if(string.indexOf(num)!=-1)
	{
		return true;
	}
	
	return false;
}