function colorItById(tableid){
	var table = document.getElementById(tableid);
	var RashodiCol = -1;
	if(table){
		if (table.rows && table.rows.length > 0) {
			for(i=0;i<table.rows.length;i++){
				
				var Row = table.rows[i];
				for(j=0;j<Row.cells.length;j++){
			
					if(Row.cells[j].innerHTML=="Rashodi") RashodiCol = j;
					if(j!=RashodiCol){
						Row.cells[j].innerHTML = formatNumber(Row.cells[j].innerHTML, "red");
					}
					else{
						Row.cells[j].innerHTML = formatNumber(Row.cells[j].innerHTML, "green");
					}
				}
			}
	    }
	}
}


function colorIt(tableid){
	var tbl = document.getElementsByTagName(tableid);
	var RashodiCol = -1;
	if(tbl){
		for(x=0;x<tbl.length;x++){
			var table = tbl[x];
			if (table.rows && table.rows.length > 0) {
				for(i=0;i<table.rows.length;i++){
					
					var Row = table.rows[i];
					for(j=0;j<Row.cells.length;j++){
						if(Row.cells[j].innerHTML=="Rashodi") RashodiCol = j;
						if(j!=RashodiCol){
							Row.cells[j].innerHTML = formatNumber(Row.cells[j].innerHTML, "red");
						}
						else{
							Row.cells[j].innerHTML = formatNumber(Row.cells[j].innerHTML, "green");
						}
					}
				}
		    }
		}
	}
}

function formatNumber(num, boja){
	if(boja=="") boja="red";
	tmp = num.replace(/\./g,"");
	tmp = tmp.replace(",",".");
	tmp = tmp.replace(" ","");
	
	if(tmp.indexOf("STRONG")!=-1 || tmp.indexOf("strong")!=-1){
		tmp = tmp.replace(/<strong>/i,"");
		tmp = tmp.replace(/<\/strong>/i,"");
		if (tmp<0){
			num = "<font color='" + boja +"'><strong>" + num.replace(" ","") + "</strong></font>";
		}	
	}
	else{
		if (tmp<0){
		num = "<font color='" + boja + "'>" + num.replace(" ","") + "</font>";
		}	
	}
	return num
}

function validate_form() {
  validity = true; // assume valid
  if (!check_empty(document.form.NAME.value))
  	{ validity = false; alert('Ime nije upisano!'); }
  if (!check_email(document.form.EMAIL.value))
  	{ validity = false; alert('Email adresa je kriva!'); }
  if (!check_empty(document.form.COMPANY.value))
  	{ validity = false; alert('Tvrtku niste upisali!'); }
  if (!check_empty(document.form.ADDRESS_LINE1.value))
  	{ validity = false; alert('Adresa je prazna!'); }
  if (!check_empty(document.form.CITY.value))
  	{ validity = false; alert('Grad nije unesen!'); }
  if (!check_empty(document.form.ZIP_CODE.value))
  	{ validity = false; alert('Upisati P. broj!'); }

  return validity;
}

function validate_upitnik() {
  validity = true; // assume valid
  if (!check_empty(document.upitnik.KLIJENT.value))
  	{ validity = false; alert('Niste se potpisali!'); }

  return validity;
}

function check_empty(text) {
  return (text.length > 0); // returns false if empty
}

function check_email(address) {
  if ((address == "")
    || (address.indexOf ('@') == -1)
    || (address.indexOf ('.') == -1))
      return false;
  return true;
}
function popAnaliza(file_name, aType){
	window.open("http://www.credos.hr/csv2html.aspx?file=analize/" + file_name + "&type=" + aType, "", "height=600,width=800,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes")
}
function pop3Kvartal(file_name, aType){
	window.open("http://www.credos.hr/csv2html_3kvartal.aspx?file=3kvartal/" + file_name + "&type=" + aType, "", "height=600,width=800,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes")
}
function popNovost(popupURL) {
var option = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=780,height=545";
var win3 = window.open(popupURL, "title", option);
}
function popKombinacija(popupURL) {
var option = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=900,height=600";
var win3 = window.open(popupURL, "title", option);
}

function changeContent(){
	switch (document.getElementById("tick").value){
		case "VSE" :
				//document.getElementById("VSElayer").style.visibility = "visible";
				document.getElementById("ZSElayer").style.visibility = "hidden";
			break;
		case "ZSE" :
				//document.getElementById("VSElayer").style.visibility = "hidden";
				document.getElementById("ZSElayer").style.visibility = "visible";
			break;
	}
}
