var IE = document.all?true:false

function adjustIFrameSize(id, top_main_frame) {
		if (top_main_frame){
			var myIframe = top.document.getElementById(id);
		}else {
			var myIframe = document.getElementById(id);
		}
    if (myIframe) {
        if (myIframe.contentDocument && myIframe.contentDocument.body.offsetHeight) {
            // W3C DOM (and Mozilla) syntax
            myIframe.height = myIframe.contentDocument.body.offsetHeight;
        } else if (myIframe.Document && myIframe.Document.body.scrollHeight) {
            // IE DOM syntax
            myIframe.height = myIframe.Document.body.scrollHeight;
        }
    }
}

function adjustIFrameSizeAdd(id, top_main_frame) {
		if (top_main_frame){
			var myIframe = top.document.getElementById(id);
		}else {
			var myIframe = document.getElementById(id);
		}
    if (myIframe) {
        if (myIframe.contentDocument && myIframe.contentDocument.body.offsetHeight) {
            // W3C DOM (and Mozilla) syntax
            myIframe.height = myIframe.contentDocument.body.offsetHeight + 200;
        } else if (myIframe.Document && myIframe.Document.body.scrollHeight) {
            // IE DOM syntax
            myIframe.height = myIframe.Document.body.scrollHeight + 200;
        }
    }
}

function reload_banners() {
	window.banners.location.reload();
}

function open_edit(uri, w, h){
	var win= window.open(uri, '', 'width='+w+', height='+h);
}

function centerScreenWindow(){
	if (IE){
		diffl= document.body.clientWidth;
		difft= document.body.clientHeight;
	}else {
		diffl= document.body.clientWidth;
		difft= window.innerHeight;
	}
	var winl = (screen.width - diffl) / 2;
	var wint = (screen.height - difft) / 2;
	window.moveTo(winl, wint);
}

function change_bgcolor(elem_id, hover_bgcolor){
	row_elem= document.getElementById(elem_id);
	orig_color= row_elem.style.backgroundColor;
	
	row_elem.style.backgroundColor= hover_bgcolor;
	
	row_elem.onmouseout= do_orig;
}
function do_orig(){
	this.style.backgroundColor= orig_color;
}

function toggle_el_disp(elem_id){
	a= document.getElementById(elem_id);
	if (a.style.display==''){
		a.style.display= 'none';
	}else {
		a.style.display= '';
	}
}

function fsubmit(form_name){
	a= document.forms[form_name];
	if (a.onsubmit()){
		a.submit();
	}
}

function freset(form_name){
	document.forms[form_name].reset();
}

function oglas_delete(form_name){
	document.forms[form_name].action.value= "delete";
	fsubmit(form_name);
}

function check_numeric(input_field){
	input_field.value= input_field.value.match(/\d*/);
}

function check_decimal(input_field){
	input_field.value= input_field.value.match(/\d*\.?\d*/);
}

function load_news(url_main){
	window.nep_main.location.href= url_main;
}

function toggle_checked(elem_id){
	a= document.getElementById(elem_id);
	if (a){
		if (a.checked){
			a.checked= false;
		}else{
			a.checked= true;
		}
	}
}

function toggle_checked_all(form_element_name, action){
	a= document.advanced_search_form;
	for (ii=0; ii<a.elements.length;ii++){
		if (a.elements[ii].name == form_element_name){
			if (action==1){
				to_do= true;
			}else if (action==0){
				to_do= false;
			}
			a.elements[ii].checked = to_do;
		}
	}
}

function winpop(address, w, h, params){
	params= 'left=50, top=50, width='+w+', height='+h+params;
	var win= window.open(address, '', params);
}

function print_window(el2hide){
	if (el2hide!=''){
		a= document.getElementById(el2hide);
		a.style.display= 'none';
		window.focus();
		window.print();
		a.style.display= '';
	}
}

// za plus/minus input fields
function toggle_field(field_name, action){
	displayed= 0;
	if (a= document.getElementsByName(field_name)){
		// koliko je prikazanih
		for (ii=0; ii<a.length; ii++){
			if (a.item(ii).style.display==''){
				displayed++;
			}						
		}

		// pokazi polje
		if (action=='+' && displayed<a.length){
			a.item(displayed).style.display= '';
		}

		// skrij polje
		if (action=='-' && (displayed-1)>0){
			a.item(displayed-1).style.display= 'none';

			// zbrisem vrednost input fielda
			field_number= displayed-1;
			field= field_name+field_number.toString();
			document.getElementById(field).value= 'asdasadsds';
		}
	}
}

function toggle_view (elem_id){
	a= document.getElementById(elem_id);
	if (a){
		if (a.style.display=='none'){
			a.style.display= '';
		}else{
			a.style.display= 'none';
		}
	}	
}
