function change_locale(locale)
{

    var tmphref=location.href;
    var newlang = locale.slice(0,2)+'.';
    if (newlang=='en.') {
	newlang = '';
    }

    var re_sublangdomain = new RegExp(/\/\/(\w{2})\.(.*?)\/(.*)/);
    var re_toplangdomain = new RegExp(/\/\/(.*?)\/(.*)/);
    var m = re_sublangdomain.exec(tmphref);
    var language = null;
    var topleveldomain = null;
    var url = null;
    if (m != null) {
	language = m[1];
	topleveldomain = m[2];
	url = m[3];
    } else {
	var m = re_toplangdomain.exec(tmphref);
	if (m!=null) {
	    topleveldomain = m[1];
	    url = m[2];
	    language = 'en';
	}
    }
    var newurl = '//'+newlang+topleveldomain+'/'+url;

    var today = new Date();
    var expires = new Date(today.getTime() + 52*7*24*60*60*1000);

    topleveldomain = topleveldomain.split(':')[0]
    document.cookie = "YP_lang=" + escape(locale) +
        "; expires=" + expires.toGMTString() +
    	"; domain=." + topleveldomain+
    	"; path=/;";

    location.href=newurl;

}

function tt_Browser()
{
	var n, nv, n6, w3c;

	n = navigator.userAgent.toLowerCase();
	nv = navigator.appVersion;
	tt_op = (document.defaultView && typeof(eval("w" + "indow" + "." + "o" + "p" + "er" + "a")) != tt_u);
	tt_ie = n.indexOf("msie") != -1 && document.all && !tt_op;
	if(tt_ie)
	{
		var ieOld = (!document.compatMode || document.compatMode == "BackCompat");
		tt_db = !ieOld ? document.documentElement : (document.body || null);
		if(tt_db) {
			tt_ie56 = parseFloat(nv.substring(nv.indexOf("MSIE") + 5)) >= 5.5;
			//		&& typeof document.body.style.maxHeight == tt_u;
                }
	}
	else
	{
		tt_db = document.documentElement || document.body ||
				(document.getElementsByTagName ? document.getElementsByTagName("body")[0]
				: null);
		if(!tt_op)
		{
			n6 = document.defaultView && typeof document.defaultView.getComputedStyle != tt_u;
			w3c = !n6 && document.getElementById;
		}
	}
	tt_body = (document.getElementsByTagName ? document.getElementsByTagName("body")[0]
				: (document.body || null));
	return true;
}


var
tt_db, tt_op, tt_ie, tt_ie56, 	// Browser flags
tt_body, tt_u = "undefined";

tt_Browser();

 function disableSubmitOfForm(){
    try {
        var sb = document.getElementById('submit_button');
        sb.disabled=true;
    } catch(e) {}
   return true;
 }

 /* Returns the class name of the argument or undefined if
   it's not a valid JavaScript object.
*/
function getObjectClass(obj) {
    if (obj && obj.constructor && obj.constructor.toString) {
        var arr = obj.constructor.toString().match(/function\s*(\w+)/);

        if (arr && arr.length == 2) {
            return arr[1];
        }
    }

    return undefined;
}


// dictionary with urls required in js
// keys are url names in django, values - fact urls
// Dictionary should be filled as required in templates the way like:
// Urls['current-translations'] = {% url current-translations %}
Urls = {}

