// shortcuts
	function elm_id(el){ return document.getElementById(el) }
	function elm_val(el){ return document.getElementById(el).value }
	function elm_style(el){ return document.getElementById(el).style }
	
document.getElementsByClassName = function(cl) {
    var retnode = [];
    var myclass = new RegExp('\\b'+cl+'\\b');
    var elem = this.getElementsByTagName('*');
    for (var i = 0; i < elem.length; i++) {
        var classes = elem[i].className;
        if (myclass.test(classes)) retnode.push(elem[i]);
    }
    return retnode;
};
    
    
function turn_overlay_on(){
	overlay = document.getElementById('overlay').style
	overlay.top = document.body.scrollTop ? document.body.scrollTop + 'px' : window.pageYOffset + 'px'
	overlay.height = window.innerHeight + 'px'
	overlay.width = window.innerWidth + 'px'
	document.body.style.overflow = 'hidden'
	overlay.display = 'block'
}

function turn_overlay_off(){
	overlay = document.getElementById('overlay').style
	document.body.style.overflow = 'visible'
	overlay.display = 'none'
}

function window_width(){
	var myWidth = 0
	if( typeof( window.innerWidth ) == 'number' ) {
		myWidth = window.innerWidth;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	    myWidth = document.documentElement.clientWidth;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		myWidth = document.body.clientWidth;
	}
	return myWidth
}

function window_height(){
	myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		myHeight = document.body.clientHeight;
	}
	return myHeight
}

function close_user_alert(){
    clearInterval(user_alert)
    document.getElementById("user_alert").innerHTML = "&nbsp;"
}

function install_app_to_blog(id, location, query, app_type, app_category, page){
	blog = document.getElementById("blog_to_install_appid_"+id+"_on").value
	document.location.href = "/blogs/install/"+id+"/"+blog+"/"+location+"/"+query+"/0/"+app_category+"/"+page
}

function install_app_to_account(app_id, user_id){
    document.getElementById("install_user_area_msg").innerHTML = "Uninstall this app from my Account"
    document.getElementById("install_user_area_btn").innerHTML = '<input type="button" value="Uninstall App" onclick="uninstall_app_to_account(\''+app_id+'\', \''+user_id+'\')">'
    url = "/application_user_install/"+app_id+"/"+user_id+"/0"
    create_script_tag(url)
}

function uninstall_app_to_account(app_id, user_id){
    if(document.getElementById("install_user_area_msg")) document.getElementById("install_user_area_msg").innerHTML = "Install this app to my Account"
    if(document.getElementById("install_user_area_btn")) document.getElementById("install_user_area_btn").innerHTML = '<input type="button" value="Install App" onclick="install_app_to_account(\''+app_id+'\', \''+user_id+'\')">'
    url = "/application_user_uninstall/"+app_id+"/"+user_id+"/0"
    create_script_tag(url)
}

function create_script_tag(url){
    var head = document.getElementsByTagName('head').item(0)
    var a = document.createElement('script')
        a.setAttribute("src", url)
	    a.setAttribute("type", "text/javascript")
    head.appendChild(a)
}

function itk_user_message(msg){
    m = document.getElementById("user_alert")
    m.innerHTML = '<img id="notice" src="/gfx/exclamation.png"> &nbsp;' + msg
    url = "/clear_js_user_msg"
    create_script_tag(url)
}
