function formInputClear(forma,formel,tekst){
	if(document.getElementById(forma).elements[formel].value==tekst){
		document.getElementById(forma).elements[formel].value="";
	}
}
function formInputFill(forma,formel,tekst){
	if(document.getElementById(forma).elements[formel].value==""){
		document.getElementById(forma).elements[formel].value=tekst;
	}
}

function get_element_by_id(id) {
    if(document.getElementById) {
        var element = document.getElementById(id);
    } else if(document.all) {
        var element = document.all[id]; 
    } else if(document.layers) {
        var element = document.layers[id];
    }
    return element;
}

function getDocumentWidth() {
	var width = 0;
	if(typeof(window.innerWidth) == 'number') {
		// not ie
		width = window.innerWidth;
	} else if(document.documentElement && document.documentElement.clientWidth) {
		// ie sucks
		width = document.documentElement.clientWidth;
	} else {
		// again ie sucks
		width = document.body.clientWidth;
	}
	return width;
}

function getDocumentHeight() {
	var height = 0;
	if(typeof(window.innerHeight) == 'number') {
		// not ie
		height = window.innerHeight;
	} else if(document.documentElement && document.documentElement.clientHeight) {
		// ie sucks
		height = document.documentElement.clientHeight;
	} else {
		// again ie sucks
		height = document.body.clientHeight;
	}
	return height;
}

function getBodyHeight() {
	var height = 0;
	if(typeof(window.innerHeight) == 'number') {
		height = window.innerHeight + window.scrollMaxY;
	} else {
		height = get_element_height(document.body);
	}
	return height;
}

function getVerticalScrollPosition() {
	var scroll = 0;
	
	if(document.documentElement.scrollTop) {
		scroll = document.documentElement.scrollTop;
	}
	if(!scroll && window.pageYOffset) {
		scroll = window.pageYOffset;
	}
	if(!scroll && document.body.scrollTop) {
		scroll = document.body.scrollTop;
	}
	return scroll;
}

function get_element_width(obj) {
    if (typeof obj.clip !== "undefined") {
        return obj.clip.width;
    } else {
        if (obj.style.pixelWidth) {
            return obj.style.pixelWidth;
        } else {
            return obj.offsetWidth;
        }
    }
}

function get_element_height(obj) {
    if (typeof obj.clip !== "undefined") {
        return obj.clip.height;
    } else {
        if (obj.style.pixelHeight) {
            return obj.style.pixelHeight;
        } else {
            return obj.offsetHeight;
        }
    }
}


/*  background size script */
/*
var bvel;
function b_loadBack(){
	bvel = getBackSize();
	document.getElementById("bdy").className="b"+bvel;
}
window.onload = function() {
	b_loadBack();
}
window.onresize = function(){
	if(getBackSize()>bvel){
		b_loadBack();
	}
}
function velicinaProzora() {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
  	ret = new Array();
  	ret[0] = myWidth;
  	ret[1] = myHeight;
  	return ret;
}
function getBackSize(){
	vel = velicinaProzora();
	if(vel[0]<=800 && vel[1]<=600){
		v = 1;
	}else if(vel[0]<=1024 && vel[1]<=768){
		v = 2;
	}else if(vel[0]<=1280 && vel[1]<=1024){
		v = 3;
	}else if(vel[0]<=1600 && vel[1]<=1200){
		v = 4;
	}else {
		v = 5;
	}

	return v;
}
*/

function create_child(child_params, child_options) {
	var child_str = '';
	child_str+= '<' + child_params['type'] + ' ';
	for(i in child_options) {
		child_str+= i + '="' + child_options[i] + '" ';
	}
	if(child_params['close_basic']) {
		child_str+= '/'
	}
	child_str+= '>';
	if(child_params['close_object']) {
		child_str+= '</' + child_params['type'] + '>'
	}
	var new_child = false;
	try {
		new_child = document.createElement(child_str);
	} catch(e) {
		new_child = document.createElement(child_params['type']);
		for(i in child_options) {
			new_child.setAttribute(i, child_options[i]);
		}
	}
	return new_child;
}

function show_image_fullscreen(src_image) {
	var body_container_obj = document.body;
	var img_obj = new Image();
	
	var image_container_obj = create_child(
		{'type' : 'div', 'close_basic' : true, 'close_object' : false},
		{'id' : 'fullImageContainer', 'style' : 'height:' + getBodyHeight() + 'px;'}
	);
	var image_container_frame_obj = create_child(
		{'type' : 'iframe', 'close_basic' : true, 'close_object' : false},
		{'src': '/p/dummy_popup.html', 'scrolling' : 'no', 'border' : 'no', 'frameborder' : 'no', 'style' : 'height:' + getBodyHeight() + 'px;'}
	);
	
	body_container_obj.appendChild(image_container_obj);
	image_container_obj.appendChild(image_container_frame_obj);
	
	img_obj.onload = display_image_fullscreen;
	img_obj.src = src_image;
}

function display_image_fullscreen() {
	var body_container_obj = document.body;
	var container_width = this.width + 10;
	var container_height = this.height + 30;
	var container_left = (getDocumentWidth() - container_width) / 2;
	var container_top = getVerticalScrollPosition() + (getDocumentHeight() - container_height) / 2;
	
	var image_content_obj = create_child(
		{'type' : 'div', 'close_basic' : true, 'close_object' : false},
		{'id' : 'fullImageContent', 'style' : 'width:' + container_width + 'px;left:' + container_left + 'px;height:' + container_height + 'px;top:' + container_top + 'px;'}
	);
	
	image_content_obj.innerHTML = '<div id="fullImageCloseLinkContainer"><a href="javascript:hide_image_fullscreen();">zapri</a></div>';
	image_content_obj.innerHTML+= '<a href="javascript:hide_image_fullscreen();"><img src="' + this.src + '" alt="" /></a>';
	body_container_obj.appendChild(image_content_obj);
}

function hide_image_fullscreen() {
	var body_container_obj = document.body;
	var image_container_obj = get_element_by_id('fullImageContainer');
	var image_content_obj = get_element_by_id('fullImageContent');
	body_container_obj.removeChild(image_content_obj);
	body_container_obj.removeChild(image_container_obj);
}
