// JavaScript Document
/*
	Created By  : Jansan John
	E-Mail      : jans4u@gmail.com
	Description : General Javascript Functions
*/
//--------------------------------------------------------------------------------------------------//

function keyDownHappen(e) {
	if(!e) var e = window.event;
	e.stopPropogation=true;
	return false;
}
//--------------------------------------------------------------------------------------------------//
/*
Return the id of the attribute.
*/
function $(id){return document.getElementById(id);}
//--------------------------------------------------------------------------------------------------//
/*
Return the array elements corressponding to the name of the attribute.
*/
function $N(name){return document.getElementsByName(name);}
//--------------------------------------------------------------------------------------------------//
function $NV(name)
{
	var elementsArray = document.getElementsByName(name);
	var elementsArraySize = elementsArray.length;
	var elementValues = new Array();
	
	for(var i=0; i<elementsArraySize; i++)
	{
		elementValues[i] = elementsArray[i].value;
		//elementValues.push(elementsArray[i].value);
	}
	return elementValues;
}
//--------------------------------------------------------------------------------------------------//
/*
Return the value of the attribute.
*/
function $V(id){return document.getElementById(id).value;}
//--------------------------------------------------------------------------------------------------//
// system error hiding
//window.onerror = SymError;
function SymError()
{
  return true;
}

//--------------------------------------------------------------------------------------------------//
/*
check the string is an integer or not.
*/
function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {  
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

//--------------------------------------------------------------------------------------------------//
/*
strip the chars in the 'bag' from the passing string
*/
function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {  
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

//--------------------------------------------------------------------------------------------------//
/*
strip the chars not in the 'bag' from the passing string
*/
function stripCharsNotInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {  
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) > 0) returnString += c;
    }
    return returnString;
}

//--------------------------------------------------------------------------------------------------//
function filterChars(id,allowedCharsBag)
{
    var str = document.getElementById(id).value;
	alert(str);
    document.getElementById(id).value = stripCharsNotInBag(str,allowedCharsBag);
}

//--------------------------------------------------------------------------------------------------//
// concate the passing argumens
// USAGE : myConcat(',','1','2','3','4')
function myConcat(separator) {
  var result = "";
  // iterate through non-separator arguments
  for (var i = 1; i < arguments.length; i++) {
    result += arguments[i] + separator;
  }
  return result;
}





