/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

function setOpAndSubmit(op,frmObj)
{
    frmObj.op.value = op;
    frmObj.submit();
}

function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}

/*
* oltre al classico trim sostituisce anche gli spazi interni
* ripetuti con un unico spazio
*/
function extendedTrim(str)
{
   var tmp = str.replace(/\s+/g," ");
   return trim(tmp);
}

/*
 * cssjs
 * written by Christian Heilmann (http://icant.co.uk)
 * eases the dynamic application of CSS classes via DOM
 * parameters: action a, object o and class names c1 and c2 (c2 optional)
 * actions: swap exchanges c1 and c2 in object o
 *			add adds class c1 to object o
 *			remove removes class c1 from object o
 *			check tests if class c1 is applied to object o
 * example:	cssjs('swap',document.getElementById('foo'),'bar','baz');
 */

function cssjs(a,o,c1,c2)
{
	switch (a){
		case 'swap':
			o.className=!cssjs('check',o,c1)?o.className.replace(c2,c1):o.className.replace(c1,c2);
		break;
		case 'add':
			if(!cssjs('check',o,c1)){o.className+=o.className?' '+c1:c1;}
		break;
		case 'remove':
			var rep=o.className.match(' '+c1)?' '+c1:c1;
			o.className=o.className.replace(rep,'');
		break;
		case 'check':
			return new RegExp('\\b'+c1+'\\b').test(o.className)
		break;
	}
}


function checkNatural(value)
{
    var re = /^([123456789]\d*)|(0)$/;
    return checkRegExp(value,re);
}

function checkCap(value)
{
    var re = /^\d{5,5}$/;
    return checkRegExp(value,re);
}

function checkRegExp(value,regexp)
{
    var str = value.toString( );
    if (!str.match(regexp))
    {
        return false;
    }
    return true;
}

function checkIfEnterIsTyped(e)
{ //e is event object passed from function invocation

    var characterCode; //literal character code will be stored in this variable

    if(e && e.which)
    { //if which property of event object is supported (NN4)
        e = e;
        characterCode = e.which; //character code is contained in NN4's which property
    }
    else
    {
        e = event;
        characterCode = e.keyCode; //character code is contained in IE's keyCode property
    }

    if(characterCode == 13)
    { //if generated character code is equal to ascii 13 (if enter key)
        return true;
    }
    else
    {
        return false;
    }
}