/**
 * by Dariusz Pelka
 * js component
 */

function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
 }

function setPosY(obj, Ypos)
{ 
    if (obj.offsetParent) 
    {
        obj.offsetTop = Ypos;
    } 
    else 
    {     
        obj.y = Ypos;
    }
}

function findPosY(obj)
{ 
    var curleft = 0; 
    var curtop = 0; 
    
    if (obj.offsetParent) 
    {  
        while (obj.offsetParent)  
        {   
            curleft += obj.offsetLeft-obj.scrollLeft;   
            curtop += obj.offsetTop-obj.scrollTop;   
            var position='';   
            if (obj.style&&obj.style.position) 
                position=obj.style.position.toLowerCase();   
            if ((position=='absolute')||(position=='relative')) 
                break;   
            while (obj.parentNode!=obj.offsetParent) 
            {    
                obj=obj.parentNode;    
                curleft -= obj.scrollLeft;    
                curtop -= obj.scrollTop;   
            }   
            obj = obj.offsetParent;  
         } 
     } 
     else 
     {     
        if (obj.x)      
            curleft += obj.x;  
        if (obj.y)      
            curtop += obj.y;    
     } 

    return curtop;
 }

function findPosX(obj)
{ 
    var curleft = 0; 
    var curtop = 0; 
    
    if (obj.offsetParent) 
    {  
        while (obj.offsetParent)  
        {   
            curleft += obj.offsetLeft-obj.scrollLeft;   
            curtop += obj.offsetTop-obj.scrollTop;   
            var position='';   
            if (obj.style&&obj.style.position) 
                position=obj.style.position.toLowerCase();   
            if ((position=='absolute')||(position=='relative')) 
                break;   
            while (obj.parentNode!=obj.offsetParent) 
            {    
                obj=obj.parentNode;    
                curleft -= obj.scrollLeft;    
                curtop -= obj.scrollTop;   
            }   
            obj = obj.offsetParent;  
         } 
     } 
     else 
     {     
        if (obj.x)      
            curleft += obj.x;  
        if (obj.y)      
            curtop += obj.y;    
     } 

    return curleft;
 }
 
// comes from prototype.js; this is simply easier on the eyes and fingers
function $(id)
{
    return document.getElementById(id);
}

function getURLParam(strParamName)
{
    var strReturn = "";
    var strHref = window.location.href;  
    if ( strHref.indexOf("?") > -1 )
    {
        var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();	
        var aQueryString = strQueryString.split("&");
        for ( var iParam = 0; iParam < aQueryString.length; iParam++ )
        {
            if (aQueryString[iParam].indexOf("=") > -1 )
            {
                var aParam = aQueryString[iParam].split("=");
                strReturn = aParam[1];				
                break;
            }
        }
    }
    return strReturn;
}

function CheckMaxLength(fieldName, infoDivName, maxNoOfChars, errorDivName)
{
    try
    {
        setTimeout("CheckMaxLength('" + fieldName + "', '" + infoDivName + "', " + maxNoOfChars + " , '" + errorDivName + "' )", 1000);
        var textContent = document.getElementById(fieldName).value;
        document.getElementById(infoDivName).innerHTML = "Remaining characters " + (maxNoOfChars - textContent.length);
        if((maxNoOfChars - textContent.length) < 0) 
        {
            if(document.getElementById(errorDivName).style.display == "none")
                document.getElementById(errorDivName).style.display = "inline"; 
            else
                document.getElementById(errorDivName).style.display = "none"; 
        }
        else 
            document.getElementById(errorDivName).style.display = "none"; 
    }
    catch(e)
    {
        //alert('function CheckMaxLength ' + e);   
    }
}

/**************************************
* Displays if hidden or hides of shown popup
***************************************/
function showHidePopup (windowPupUpDivName)
{
	popupDiv = document.getElementById(windowPupUpDivName);

	if( popupDiv.style.display == 'none')
	{
	    popupDiv.style.display = 'inline';
		popupDiv.style.display.className = 'popup';
	}
	else
	{
	    popupDiv.style.display = 'none';
		popupDiv.style.display.className = 'popup';
	}

}

/**************************************
* Displays a popup
***************************************/
function createPopup (windowPupUpDivName)
{
	popupDiv = document.getElementById(windowPupUpDivName);
    popupDiv.style.display = 'inline';
	popupDiv.style.display.className = 'popup';
}

/************************
* hides popup
*************************/
function hidePopup (windowPupUpDivName)
{
	popupDiv = document.getElementById(windowPupUpDivName);
	popupDiv.style.display = 'none';
}

function addEvent(obj, evType, fn, useCapture)
{
    try
    {
      if (obj.addEventListener)
      {
        obj.addEventListener(evType, fn, useCapture);
        return true;
      } 
      else if (obj.attachEvent)
            {
                var r = obj.attachEvent("on"+evType, fn);
                return r;
            } 
            else 
            {
                alert("Handler could not be attached");
            }
      }
    catch(e)
    {
        alert('Error in addEvent function ' + e.message);
    }
} 

