﻿var reg;
var boxColorInvalid;
var boxColorValid;

boxColorInvalid = "#FF0000";
boxColorValid = "#FFFFFF";


function showHideLoader() {
    if($('pop_overlay').style.display == 'none')
        $('pop_overlay').style.display = 'block';
    else
        $('pop_overlay').style.display = 'none';
}

function showHideInfo() {
    if($('info_overlay').style.display == 'none')
        $('info_overlay').style.display = 'block';
    else
        $('info_overlay').style.display = 'none';
        $('infoDiv').innerHTML = '';
}


// prikaz i sakrivanje lijevog panela
function showHideLeftPanel(obj, img) {
    // nije do kraja implemetirano
    //showHideLeftMenu();
    
    if(obj.style.display == "block" || obj.style.display == "") {
        obj.style.display = "none";
        img.src = "images/resultset_next.png";
        $("main").style.marginLeft = "10px";
    }
    else {
        obj.style.display = "block";
        img.src = "images/resultset_previous.png";
        $("main").style.marginLeft = "230px";
    }
}






function showHideHelp(obj, img) {
    if(obj.style.display == "block" || obj.style.display == "") {
        obj.style.display = "none";
    }
    else {
        obj.style.display = "block";
    }
}

function showHideLeftMenu() {
	///
}

function GetMedicalInfo(g) {
    new Ajax.Request('AjaxScripts.ashx', {
        method:'get',
        parameters: {tip: 'med_info', guid: g},
        onSuccess: function(transport){
            ShowResult(transport);
        },
        onFailure: function(){ 
            alert('Pogreška kod dohvata podataka ...') 
        }
    });  
} 


    

Ajax.Responders.register( {
    onCreate: function() {     
        //alert('a request has been initialized!');   
        showHideLoader()
    },   
    onComplete: function() {     
        //alert('a request completed');   
        showHideLoader()
    } 
});
        
function ShowResult(context) {
    showHideInfo()
    $("infoDiv").innerHTML = context.responseText
}

function isDate(cId) {
	// od 1950 do 2099 - ... ([2][0]\d{2}|[1][5-9]\d{2}) ...
	reg = /^(([1-9]|[0-2]\d|[3][0-1])\.([1-9]|[0]\d|[1][0-2])\.([2][0]\d{2}|[1][5-9]\d{2}))$|^(([1-9]|[0-2]\d|[3][0-1])\.([1-9]|[0]\d|[1][0-2])\.([2][0]\d{2}|[1][5-9]\d{2})\s([1-9]|[0-1]\d|[2][0-3])\:[0-5]\d)$/;
	return check(cId, "Format datuma nije ispravan!\n Upišite ga u formatu dd.MM.yyyy!");
}

function isInt(cId) {
	reg = /^[-]*\d+$/;
	return check(cId, "Ovo polje prihvaća samo cijele brojeve!");
}

function isDecimal(cId) {
	//reg = /^([-]*\d+|(\d*\,{1}\d{1,2}){1})$/;
	reg = /^(-?[0-9]{0,5}|-?[0-9]{0,5}\,[0-9]{1,3})?$/;
	return check(cId, "Ovo polje prihvaća samo cijele i decimalne brojeve!");
}										

function check(cId, msg) {
	if(cId.value == "")
		return true;
		
	if(cId.value.match(new RegExp(reg)) == null) {
		cId.value = "";
		cId.style.backgroundColor = boxColorInvalid;
		alert(msg);
		return false;
	}
	else {
		cId.style.backgroundColor = boxColorValid;
		return true;
	}
}

function initFormElements() {
	var obj;					
	for(var i = 0; i < document.getElementsByTagName("input").length; i++) {
		obj = document.getElementsByTagName("input")[i];
		
		
		if(obj.className == "dat") {
			initCalDate(obj,obj);
			obj.onchange += function(){ isDate(this); };
		}
		else if(obj.className == "datT") {
			initCalTime(obj,obj);
			obj.onchange = function(){ isDate(this); };
		}
		else if(obj.className == "num") {
			obj.onchange = function(){ isInt(this); };
		}
		else if(obj.className == "dec") {
			obj.onchange = function(){ isDecimal(this); };
		}
	}
}

var oOpenWindow; 
function OpenBrWindow(theURL,winName,features, myWidth, myHeight, isCenter) { //v3.0
if(window.screen)if(isCenter)if(isCenter=="true"){
	var myLeft = (screen.width-myWidth)/2;
	var myTop = (screen.height-myHeight)/2;
	features+=(features!='')?',':'';
	features+=',left='+myLeft+',top='+myTop;
}
oOpenWindow=  window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
	
oOpenWindow.focus();
}

function getCheckedRadioValue(name) {
      var radioButtons = document.getElementsByName(name);
      for (var x = 0; x < radioButtons.length; x ++) {
        if (radioButtons[x].checked) {
          return radioButtons[x].value;
        }
      }
    }
      // creates a function to set the css class name of input controls when they

 // receive or lose focus.

 setAspnetTextFocus = function() {

    // CSS class name to use when no focus is on the input control

    var classBlur = 'input_text';

  // CSS class name to use when the input control has focus

    var classFocus = 'input_text_focus';

    // get all of the input tags on the page

    var inputElements = document.getElementsByTagName('input');

     

    for (var i = 0; i < inputElements.length; i++) {

         // add the onfocus event and set it to add the on focused CSS class

        inputElements[i].onfocus = function() {

            if (this.className == 'input_text') {
               this.className += ' ' + classFocus;

             }

         }

        // add the onblur event and set it to remove the on focused CSS class when it loses focus

        inputElements[i].onblur = function() {

          this.className = this.className.replace(new RegExp(' ' + classFocus + '\\b'), '');

      }

   }

 }

 // attach this event on load of the page

 if (window.attachEvent) window.attachEvent('onload', setAspnetTextFocus);


function navigacija(theURL,p1,p2) {
window.location =theURL;


}