function sf_decode(html, key){
	if (key.length == 0 || html.length == 0) return false;
	
	//Convert keystring and html to array
	var keyarr = str_split(key);
	var htmlarr = explode(",", html);

	var strout = '', ordv = '', zmx0 = 0;
	var keypos = 0, keylen = keyarr.length, addon1 = 0;
	for (i = 0; i < htmlarr.length; i++){
		ordv = parseInt(htmlarr[i]);
		zmx0 = ordv - ord(keyarr[keypos]) - addon1;
		addon1 = ordv;
		while (zmx0 < 0) zmx0 += 256;
		strout += chr(zmx0).toString();
		keypos += 1;
		if (keypos > keylen - 1) keypos = 0;
	}

	return strout;
}


function str_split ( f_string, f_split_length){
    if (f_split_length == undefined) {
        f_split_length = 1;
    }
    if(f_split_length > 0){
        var result = [];
        while(f_string.length > f_split_length) {
            result[result.length] = f_string.substring(0, f_split_length);
            f_string = f_string.substring(f_split_length);
        }
        result[result.length] = f_string;
        return result;
    }
    return false;
}

function ord( string ) {
    return string.charCodeAt(0);
}
function chr( ascii ) {
    return String.fromCharCode(ascii);
}


function explode( delimiter, string, limit ) {
    var emptyArray = { 0: '' };
    
    // third argument is not required
    if ( arguments.length < 2
        || typeof arguments[0] == 'undefined'
        || typeof arguments[1] == 'undefined' )
    {
        return null;
    }
 
    if ( delimiter === ''
        || delimiter === false
        || delimiter === null )
    {
        return false;
    }
 
    if ( typeof delimiter == 'function'
        || typeof delimiter == 'object'
        || typeof string == 'function'
        || typeof string == 'object' )
    {
        return emptyArray;
    }
 
    if ( delimiter === true ) {
        delimiter = '1';
    }
    
    if (!limit) {
        return string.toString().split(delimiter.toString());
    } else {
        // support for limit argument
        var splitted = string.toString().split(delimiter.toString());
        var partA = splitted.splice(0, limit - 1);
        var partB = splitted.join(delimiter.toString());
        partA.push(partB);
        return partA;
    }
}
