var save_r_select = '';


function getRegion(type)
{  
     var html;      
          $.ajax
             ({     
                  type: "POST",
                  url: "/ajax/search_region.php",
                  dataType: "json",
                  data: "type=" + type,
                  success: function(x)
                      {                                                        
                       
                   
                      document.getElementById('regionslist').innerHTML = x.html;
                                                                 
                        
                       }      
                });         

   // document.getElementById('s-reg').disabled = true;      
   // if (save_r_select == '') save_r_select = document.getElementById('s-reg').innerHTML;
   // var data = 'type=' + type;
   // makeR('/ajax/search_region.php', 's-reg', data);
   // alert(data);
}

function islaResponse(req, obj) {
    if (req.readyState == 4) {
        if ((req.status == 200) || (req.status == 0) || (req.status == 413)) {
            if (document.getElementById(obj) != null){
           
                var regions = eval(' ( ' + req.responseText + ' ) ');
                var r_select = document.getElementById(obj);

                r_select.innerHTML = save_r_select;

                for (var region in regions){
                    var r_option = document.createElement("option");
                    r_option.setAttribute("value", region);
                    var r_text = document.createTextNode(regions[region]);
                    r_option.appendChild(r_text);
                    r_select.appendChild(r_option);

                    r_select.disabled = false;
                }


            }
        } else {
            return false;
        }
    }
}

function makeR(url, obj, data) {
   var req = false;
   if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        if (req.overrideMimeType) {
            req.overrideMimeType('text/xml');
        }
    } else if (window.ActiveXObject) { // IE
        try {
            req = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                req = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }

    if (!req) {
        return false;
    }

    req.onreadystatechange = function() {islaResponse(req, obj);};
    req.open('POST', url, true);
    if (data){
        req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    }
    if (!data) var data = '';
    req.send(data);
    return true;
}

function Search()
{
    var opt_id = document.getElementById('s-typ').value;      
    document.getElementById('search-form').action = document.getElementById('link_'+opt_id).href;
    document.getElementById('search-form').submit();        
    
}


function imagePopup(url) {
    

    newWin=window.open('','popupwin','height=640,width=640,resizable=1');
    newWin.document.write('<html>\n');
    newWin.document.write('<head>\n');
    newWin.document.write('<title>'+url+'</title>');
    newWin.document.write('</head>\n');
    newWin.document.write('<body style="background-color:white; margin:0px; padding:0px;">\n');
    newWin.document.write('<table border=0 style="height:100%; width:100%; text-align:center;"><tr><td align="center" valign="middle">\n');
    newWin.document.write('<img src="" id="image_preview" border="0"/>');
    newWin.document.write('<script language="JavaScript" type="text/javascript">');
    newWin.document.write('document.getElementById("image_preview").src = "'+url+'";');
    newWin.document.write('if (navigator.appName != "Microsoft Internet Explorer") window.resizeTo(document.getElementById("image_preview").width+40, document.getElementById("image_preview").height+80);');
    newWin.document.write('</script>');
    newWin.document.write('</td>\n</tr>\n</table>\n</body>\n');
    newWin.document.write('</html>');
    newWin.document.close()
    newWin.focus();
}

var scrolltotop={
    setting: {startline:600, scrollto: 0, scrollduration:1000, fadeduration:[500, 100]}, 
    controlHTML: '<img src="/images/up_arrow.jpg" alt="Scroll up">', 
    controlattrs: {offsetx:5, offsety:5}, 
    anchorkeyword: '#top', 

    state: {isvisible:false, shouldvisible:false},

    scrollup:function(){
        if (!this.cssfixedsupport) //if control is positioned using JavaScript
            this.$control.css({opacity:0}) //hide control immediately after clicking it
        var dest=isNaN(this.setting.scrollto)? this.setting.scrollto : parseInt(this.setting.scrollto)
        if (typeof dest=="string" && jQuery('#'+dest).length==1) //check element set by string exists
            dest=jQuery('#'+dest).offset().top
        else
            dest=0
        this.$body.animate({scrollTop: dest}, this.setting.scrollduration);
    },

    keepfixed:function(){
        var $window=jQuery(window)
        var controlx=$window.scrollLeft() + $window.width() - this.$control.width() - this.controlattrs.offsetx
        var controly=$window.scrollTop() + $window.height() - this.$control.height() - this.controlattrs.offsety
        this.$control.css({left:controlx+'px', top:controly+'px'})
    },

    togglecontrol:function(){
        var scrolltop=jQuery(window).scrollTop()
        if (!this.cssfixedsupport)
            this.keepfixed()
        this.state.shouldvisible=(scrolltop>=this.setting.startline)? true : false
        if (this.state.shouldvisible && !this.state.isvisible){
            this.$control.stop().animate({opacity:1}, this.setting.fadeduration[0])
            this.state.isvisible=true
        }
        else if (this.state.shouldvisible==false && this.state.isvisible){
            this.$control.stop().animate({opacity:0}, this.setting.fadeduration[1])
            this.state.isvisible=false
        }
    },
    
    init:function(){
        jQuery(document).ready(function($){
            var mainobj=scrolltotop
            var iebrws=document.all
            mainobj.cssfixedsupport=!iebrws || iebrws && document.compatMode=="CSS1Compat" && window.XMLHttpRequest //not IE or IE7+ browsers in standards mode
            mainobj.$body=(window.opera)? (document.compatMode=="CSS1Compat"? $('html') : $('body')) : $('html,body')
            mainobj.$control=$('<div id="topcontrol">'+mainobj.controlHTML+'</div>')
                .css({position:mainobj.cssfixedsupport? 'fixed' : 'absolute', bottom:mainobj.controlattrs.offsety, right:mainobj.controlattrs.offsetx, opacity:0, cursor:'pointer'})
                .attr({title:'Scroll Back to Top'})
                .click(function(){mainobj.scrollup(); return false})
                .appendTo('body')
            if (document.all && !window.XMLHttpRequest && mainobj.$control.text()!='') //loose check for IE6 and below, plus whether control contains any text
                mainobj.$control.css({width:mainobj.$control.width()}) //IE6- seems to require an explicit width on a DIV containing text
            mainobj.togglecontrol()
            $('a[href="' + mainobj.anchorkeyword +'"]').click(function(){
                mainobj.scrollup()
                return false
            })
            $(window).bind('scroll resize', function(e){
                mainobj.togglecontrol()
            })
        })
    }
}

scrolltotop.init()


