(function($) {

$.randomKey = function(oOptions)
{
	// init key var
    var sKey = '';
    
    // set key length to 15, if no key length given
    var iKeyLength = ((typeof oOptions.keyLength == 'undefined' 
        || isNaN(parseInt(oOptions.keyLength)) )? 15 : oOptions.keyLength); 

    // init empty options object, if no object given
    oOptions = ((typeof oOptions == 'object')? oOptions: {});
    // set "special chars" to false if not set
    var bSpecialChars = ((typeof oOptions.specialChars == 'undefined')? false : oOptions.specialChars);
    // set "lower and uppercase" to false it not set
    var bLowerUpper  = ((typeof oOptions.lowerUpper == 'undefined')? false : oOptions.lowerUpper); 
   
    // iterate
    for(var i=0;i<iKeyLength;i++)
    {
    	// if random = 1
        if(Math.floor(Math.random()*2))
        {
        	// add random number from 0 to 9
            sKey += Math.floor(Math.random()*10)+'';
        }
        else
        {
        	// add random char by provided params
            (bSpecialChars && Math.floor(Math.random()*2))? 
        		sKey += String.fromCharCode(Math.floor(Math.random()*15) + 33) : 
        			((bLowerUpper && Math.floor(Math.random()*2))? sKey += 
        				String.fromCharCode(Math.floor(Math.random()*26) + 97).toUpperCase() : 
        				sKey += String.fromCharCode(Math.floor(Math.random()*26) + 97));
        }
    }
    // return the random key
    return sKey;
}

})(jQuery);

