﻿    function toggleLayer(whichLayer,state) {
        var elem, vis;
        if(document.getElementById) // this is the way the standards work
        elem = document.getElementById(whichLayer);
        else if(document.all) // this is the way old msie versions work
        elem = document.all[whichLayer];
        else if(document.layers) // this is the way nn4 works
        elem = document.layers[whichLayer];
        vis = elem.style;

        // if the style.display value is blank we try to figure it out here
        if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined) {
        //vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
        }

    //vis.display = (vis.display==''||vis.display=='block')?'none':'block';
    vis.display = state;
    }
    
    function toggleCSS(force)
    {
        var whichLayer = 'commentForm1';
        var elem, vis;
        if(document.getElementById) // this is the way the standards work
            elem = document.getElementById(whichLayer);
        else if(document.all) // this is the way old msie versions work
            elem = document.all[whichLayer];
        else if(document.layers) // this is the way nn4 works
            elem = document.layers[whichLayer];

        var x;

        if (force == true)
            x = elem.className;
         else
            x = get_cookie ("searchType");
         
        if (x == 'SearchS') {
            elem.className = 'SearchA'; 
            toggleLayer('commentForm2','block');
            document.cookie = "searchType=SearchS;";
            
            document.getElementById('divSpace').style.height = '78px';
            document.getElementById('divSpace2').style.height = '20px';
            
            document.getElementById('searchLinkS').className = 'tabS2';
            document.getElementById('searchLinkA').className = 'tabA2';
            
            document.getElementById('btnReset').src = '/Images/Site/btnObrisiA.gif';
        }
        else {
            elem.className = 'SearchS'; toggleLayer('commentForm2','none');
            document.cookie = "searchType=SearchA;";
            
            document.getElementById('divSpace').style.height = '10px';
            document.getElementById('divSpace2').style.height = '20px';

            document.getElementById('searchLinkS').className = 'tabS1';
            document.getElementById('searchLinkA').className = 'tabA1';
            
            document.getElementById('btnReset').src = '/Images/Site/btnObrisi.gif';
        }
    }

    function get_cookie ( cookie_name )
    {
   
      var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );

      if ( results )
        return ( unescape ( results[2] ) );
      else
        return null;
    }
    
    
    function querySt(ji) {
        hu = window.location.search;
        
        alert(hu);
        
        gy = hu.split("&");
        for (i=0;i<gy.length;i++) {
            ft = gy[i].split("=");
            if (ft[0] == ji) {
                return ft[1];
            }
        }
    }
 

    function ClearItems(obj) {
        for (i = obj.options.length - 1; i > -1; i--) {
            obj.options[i] = null;
            //obj.remove(0);
        }
    }

    function AddNewItem(obj, text, value) {
        obj.options.add(new Option(text, value));
    }



    function PopulateBusiness(ctrl, text, val) {
        //document.getElementById(ctrl).options.add(new Option(text, 0));
        for (i = 0; i < Business.length; i++) {
            document.getElementById(ctrl).options.add(new Option(Business[i], BusinessId[i]));
        }
        $('#' + ctrl).val(val);
    }

    function PopulateRegion(ctrl, text, val) {
        //document.getElementById(ctrl).options.add(new Option(text, 0));
        for (i = 0; i < Region.length; i++) {
            document.getElementById(ctrl).options.add(new Option(Region[i], RegionId[i]));
        }
        $('#' + ctrl).val(val);
    }

    function PopulateCity(comboMj, comboZup, Place, Val) {

        var Sel = comboZup.options[comboZup.selectedIndex].value;

        ClearItems(comboMj);

        AddNewItem(comboMj, Place, 0);

        for (i = 0; i < BR.length - 1; i++) {
            if (BR[i] == Sel || Sel == 0)
                AddNewItem(comboMj, City[i], PBR[i]);
        }
        $('#' + comboMj.id).val(Val);

    }

    function PopulateAreaCode(ctrl, text, val) {
        //document.getElementById(ctrl).options.add(new Option(text, 0));
        for (i = 0; i < AreaCode.length; i++) {
            document.getElementById(ctrl).options.add(new Option('0' + AreaCode[i], AreaCode[i]));
        }
        $('#' + ctrl).val(val);
    }

    function PopulateValue(ctrl, val) {
        if (val == '')
            document.getElementById(ctrl).value = document.getElementById(ctrl).title;
        else
            document.getElementById(ctrl).value = val;
    }
     