var Popup = {
  open: function(options)
  {
    this.options = {
      url: '#',
      width: 350,
      height: 350,
      name:"_blank",
      location:"no",
      menubar:"no",
      toolbar:"no",
      status:"no",
      scrollbars:"no",
      resizable:"yes",
      left:"",
      top:"",
      normal:false,
      centre: false
    }
    
    Object.extend(this.options, options || {});

    if (this.options.normal){
        this.options.menubar = "yes";
        this.options.status = "yes";
        this.options.toolbar = "yes";
        this.options.location = "yes";
    }

    this.options.width = this.options.width < screen.availWidth?this.options.width:screen.availWidth;
    this.options.height=this.options.height < screen.availHeight?this.options.height:screen.availHeight;

    if (this.options.centre) {
        this.options.top = (screen.availHeight - this.options.height) / 2;
        this.options.left = (screen.availWidth - this.options.width) / 2;
    }

    var openoptions = 'width='+this.options.width+',height='+this.options.height+',location='+this.options.location+',menubar='+this.options.menubar+',toolbar='+this.options.toolbar+',scrollbars='+this.options.scrollbars+',resizable='+this.options.resizable+',status='+this.options.status
    if (this.options.top!="")openoptions+=",top="+this.options.top;
    if (this.options.left!="")openoptions+=",left="+this.options.left;
    win = window.open(this.options.url, this.options.name,openoptions );
    return win;
  }
}



function submitChange(element) {
    element.value = '<< Go >>';
	element.disabled;
	return true;
}

    document.observe("dom:loaded", function() {
        $$('img.kudosh').each(function (element) {
           
            content = element.readAttribute('alt');

            content = content.replace(/;/g, "<br/>");

            new Tip(element, content,{hook: {target: 'topRight', tip: 'bottomLeft'}});

            });

        $$('img.ucg').each(function (element) {
           
            content = element.readAttribute('alt');

            content = content.replace(/;/g, "<br/>");

            new Tip(element, content,{hook: {target: 'topRight', tip: 'bottomLeft'}});

            });

        $$('a.reqlogp').each(function (element) {
           
            content = element.readAttribute('title');

            content = content.replace(/;/g, "<br/>");

            new Tip(element, content,{hook: {target: 'topRight', tip: 'bottomLeft'}});

            });

        if ($('country_site')) {
            $('country_site').observe("change", function(element) {

                $('countryself').submit();
            });
        }


        $$('input.flags').each(function (element) {

            element.setAttribute('name', 'setcountry_ie');

            element.observe("click", function(e) {
                if (element.hasClassName('setcountry')) {
                    
                    var i = new Element('input', {'type':'hidden', 'name':'setcountry', 'id':"hsc", 'value': element.getValue()});

                    Element.insert(element, {'after': i});

                } else {
                    var i = new Element('input', {'type':'hidden', 'name':'filter', 'id':"hsc", 'value': element.getValue()});

                    Element.insert(element, {'after': i});

                }
//                $('hsc').setAttribute('value', element.getValue());
                
            });

            element.observe("mouseover", function(e) {
    
                img = element.getAttribute('src');

                if (img && img.indexOf("unselected") != -1) {
                    img = img.replace(/unselected/,"selected");
                    element.setAttribute('src', img);
                    element.addClassName('over');
                } else if (img == null)  {
                    if (!element.hasClassName('selected')) {
                        element.addClassName('selected');
                        element.addClassName('over');
                    }
                }
            });

            element.observe("mouseout", function(e) {
   
                img = element.getAttribute('src');
                
                if (img != null && img.indexOf("_selected") != -1 && element.hasClassName('over')) {
                    img = img.replace(/_selected/,"_unselected");

                    element.setAttribute('src', img);
                    element.removeClassName('over');
                } else if (img == null)  {
                    if (element.hasClassName('selected') && element.hasClassName('over')) {
                        element.removeClassName('selected');
                        element.removeClassName('over');
                    }

                }
            });


        });

    });

    document.observe("dom:loaded", function() {

        $$('a.popup').each(function (element) {
           
            element.observe('click', function(event) {

            href = element.readAttribute('href');
           
            var win = Popup.open({url: '/_popup' + href,'centre':true, 'width':'700','height': '450', 'scrollbars' : 'yes'}); 

            if (window.focus) { win.focus(); };

            Event.stop(event);

            return false;

            });


        });
    });
	
	document.observe("dom:loaded", function() {

        $$('a.popup_business').each(function (element) {
           
            element.observe('click', function(event) {

            href = element.readAttribute('href');
           
            var win = Popup.open({url: '/_popup' + href,'centre':true, 'width':'1100','height': '750', 'scrollbars' : 'yes'}); 

            if (window.focus) { win.focus(); };

            Event.stop(event);

            return false;

            });


        });
    });
 
 
     document.observe("dom:loaded", function() {

        $$('a.popup_mini').each(function (element) {
           
            element.observe('click', function(event) {

            href = element.readAttribute('href');
           
            var win = Popup.open({url: '/_popup' + href,'centre':true, 'width':'333','height': '450', 'scrollbars' : 'yes'}); 

            if (window.focus) { win.focus(); };

            Event.stop(event);

            return false;

            });


        });
    });

function charcount(id, maxlimit, errordiv, message) {
    if (!$(errordiv)) {

        if (errordiv) {
            $(id).insert({after: '<div id="' + errordiv + '" class="smallerror" style="display:none"></div>'});

        } else {

            if (!$('error' + id)) {
                $(id).insert({after: '<div id="error'+id+'" class="smallerror" style="display:none"></div>'});
            }

            errordiv = 'error' + id;
        }
    }
   
    if (!message) {

        message = "(Maximum " + maxlimit + " characters allows)";
    }

    if($F(id).length >= maxlimit) {
        $(errordiv).update(message).show();
        
        $(id).value = $F(id).substring(0,maxlimit - 1);
    } else {
        $(errordiv).update("").hide();
    }
}

function makecharcount(id,maxlimit, errordiv, message) {

    if ($(id)) {

        Event.observe($(id), 'change', function() {charcount(id,maxlimit,errordiv,message);}, false);    
        Event.observe($(id), 'keyup', function() {charcount(id,maxlimit,errordiv,message);}, false);    
        Event.observe($(id), 'keydown', function() {charcount(id,maxlimit,errordiv,message);}, false);    

        charcount(id,maxlimit,errordiv,message)
    }

}

