function getAjax()

{

	try

	{

		//Firefox, Opera 8.0+, Safari

		ajax=new XMLHttpRequest();

	}

	catch (e)

	{

		try

		{

			//IE 5.5+

			ajax=new ActiveXObject("Microsoft.XMLHTTP");

		}

		catch (e)

		{

			try

			{

				//IE 6.0+

				ajax=new ActiveXObject("Msxml2.XMLHTTP");

			}

			catch (e)

			{

				ajax=null;

			}

		}

	}

	return ajax;

}

function ltrim(str)

{

	while(str.charAt(0)==" ")

	{

		str=str.replace(" ","");

	}

	return str;

}

function rtrim(str)

{

	last=str.length-1;

	while(str.charAt(last)==" ")

	{

		str=str.substring(0,last);

		last--;

	}

	return str;

}

function trim(str)

{

	return ltrim(rtrim(str));

}

function fillok(str)

{

	if(trim(str).length>0)

		return true;

	else

		return false;

}

function emailok(str)

{

	emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i;

	if(emailfilter.test(str)==true)

		return true;

	else

		return false;

}

function show(id)

{

	document.getElementById(id).style.display="";

}

function hide(id)

{

	document.getElementById(id).style.display="none";

}

function visible(id)

{

	document.getElementById(id).style.visibility="visible";

}

function invisible(id)

{

	document.getElementById(id).style.visibility="hidden";

}

function is_displayed(id)

{

	if(document.getElementById(id).style.display=="none")

		return false;

	else

		return true;

}

function is_visible(id)

{

	if(document.getElementById(id).style.visibility=="hidden")

		return false;

	else

		return true;

}

function toggle_display(id)

{

	if(is_displayed(id))

		hide(id);

	else

		show(id);

}

function toggle_visibility(id)

{

	if(is_visible(id))

		invisible(id);

	else

		visible(id);

}

function set_value(id,val)

{

	document.getElementById(id).value=val;	

}

function get_value(id)

{

	return document.getElementById(id).value;	

}

function set_inner(id,val)

{

	document.getElementById(id).innerHTML=val;	

}

function get_inner(id)

{

	return document.getElementById(id).innerHTML;	

}

function set_class(id,class_name)

{

	document.getElementById(id).className=class_name;

}

function add_class(id,class_name)

{

	document.getElementById(id).className+=" "+class_name;

}

function remove_class(id,class_name)

{

	document.getElementById(id).className=document.getElementById(id).className.replace(new RegExp(" "+class_name+"\\b"),"");

}

function limit_text(id,limit) // this function should be called on onKeyUp() and onBlur() events

{

	if(get_value(id).length>limit)

		set_value(id,get_value(id).substring(0,limit));

}

function text_count(id,max_length,show_id) // this function should be called on onKeyUp() and onBlur() events

{

	if(get_value(id).length<=max_length)

		set_inner(show_id,max_length-get_value(id).length);

	else

		set_inner(show_id,"<font color='#ff0000'>"+(max_length-get_value(id).length)+"</font>");

}

function remove_breaks(str)

{

	return str.replace(new RegExp("\\n","g")," ");	

}

function remove_tabs(str)

{

	return str.replace(new RegExp("\\t","g")," ");	

}

function strip_tags(str, allowed_tags) {

    var key = '', allowed = false;

    var matches = [];

    var allowed_array = [];

    var allowed_tag = '';

    var i = 0;

    var k = '';

    var html = '';



    var replacer = function(search, replace, str) {

        return str.split(search).join(replace);

    };



    // Build allowes tags associative array

    if (allowed_tags) {

        allowed_array = allowed_tags.match(/([a-zA-Z]+)/gi);

    }

	

    str += '';



    // Match tags

    matches = str.match(/(<\/?[^>]+>)/gi);



    // Go through all HTML tags

    for (key in matches) {

        if (isNaN(key)) {

            // IE7 Hack

            continue;

        }



        // Save HTML tag

        html = matches[key].toString();



        // Is tag not in allowed list? Remove from str!

        allowed = false;



        // Go through all allowed tags

        for (k in allowed_array) {

            // Init

            allowed_tag = allowed_array[k];

            i = -1;



            if (i != 0) { i = html.toLowerCase().indexOf('<'+allowed_tag+'>');}

            if (i != 0) { i = html.toLowerCase().indexOf('<'+allowed_tag+' ');}

            if (i != 0) { i = html.toLowerCase().indexOf('</'+allowed_tag)   ;}



            // Determine

            if (i == 0) {

                allowed = true;

                break;

            }

        }



        if (!allowed) {

            str = replacer(html, "", str); // Custom replace. No regexing

        }

    }



    return str;

}

function urlencode( str ) {

    var histogram = {}, tmp_arr = [];

    var ret = str.toString();

    

    var replacer = function(search, replace, str) {

        var tmp_arr = [];

        tmp_arr = str.split(search);

        return tmp_arr.join(replace);

    };

    

    // The histogram is identical to the one in urldecode.

    histogram["'"]   = '%27';

    histogram['(']   = '%28';

    histogram[')']   = '%29';

    histogram['*']   = '%2A';

    histogram['~']   = '%7E';

    histogram['!']   = '%21';

    histogram['%20'] = '+';

    

    // Begin with encodeURIComponent, which most resembles PHP's encoding functions

    ret = encodeURIComponent(ret);

    

    for (search in histogram) {

        replace = histogram[search];

        ret = replacer(search, replace, ret) // Custom replace. No regexing

    }

    

    // Uppercase for full PHP compatibility

    return ret.replace(/(\%([a-z0-9]{2}))/g, function(full, m1, m2) {

        return "%"+m2.toUpperCase();

    });

    

    return ret;

}

function urldecode( str ) {

    var histogram = {};

    var ret = str.toString();

    

    var replacer = function(search, replace, str) {

        var tmp_arr = [];

        tmp_arr = str.split(search);

        return tmp_arr.join(replace);

    };

    

    // The histogram is identical to the one in urlencode.

    histogram["'"]   = '%27';

    histogram['(']   = '%28';

    histogram[')']   = '%29';

    histogram['*']   = '%2A';

    histogram['~']   = '%7E';

    histogram['!']   = '%21';

    histogram['%20'] = '+';



    for (replace in histogram) {

        search = histogram[replace]; // Switch order when decoding

        ret = replacer(search, replace, ret) // Custom replace. No regexing   

    }

    

    // End with decodeURIComponent, which most resembles PHP's encoding functions

    ret = decodeURIComponent(ret);



    return ret;

}

function cursor_to_end(id)

{

	document.getElementById(id).focus();

	set_value(id,get_value(id));

}

function show_grey_box(title,url,width,height)
{
	window.top.GB_showCenter(title,url,height,width);
}