﻿var GlobalFunc = {
  ExtendSession: function(){
    new Ajax.Request('/Ajax/SessionAjax.ashx');
    setTimeout(GlobalFunc.ExtendSession, 600000);
  },
  
  AddOption: function(select, text, value) {
		var option = document.createElement("option");
		option.text = text;
		option.value = value;	
		if (Prototype.Browser.IE) {
			select.add(option);
		}
		else {
			select.add(option, null);
		}
	},
	
	ClearOptions: function(select) {
		for (var i = select.options.length; i >= 0; i--) {
		  select.remove(i);
		}
	},
  
  FormatPrice: function(price, withPoints){
    if(withPoints == true){
      price = price.toFixed(2);
    }
    price += '';
	  x = price.split('.');
	  x1 = x[0];
	  x2 = x.length > 1 ? ',' + x[1] : '';
	  var rgx = /(\d+)(\d{3})/;
	  while (rgx.test(x1)) {
		  x1 = x1.replace(rgx, '$1' + '.' + '$2');
	  }
	  return x1 + x2;
  },
  
  GetUID: function(){
    if(typeof this.id == 'undefined'){
      this.id = 0;
    }
    return new Date().getTime() + this.id++;
  },
  
  IsNull: function(elm){
    return elm == null || typeof elm == 'undefined';
  },
  
  OpenPopup: function(url, name, dim, settings){
    var winSettings = Object.extend({
      scrollbars: 'yes',
      status: 1,
      resizable: 1
    }, settings);
    var pos = {
      left: (screen.width) ? (screen.width - dim.width)/2 : 0,
      top: (screen.height) ? (screen.height - dim.height)/2 : 0
    };
    document.title = url;
	  return window.open(url, name, 'height='+dim.height+',width='+dim.width+',top='+pos.top+',left='+pos.left+',scrollbars='+winSettings.scrollbars+',status=' + winSettings.status + ',resizable=' + winSettings.resizable)
  }
}

var NewsFunc = {
  Subscribe: function(){
    if(!$F('email').empty()){
      location.href='/Mailinglist.aspx?m=sub&email=' + $F('email');
    }
    return false;
  },
  
  Unsubscribe: function(){
    if(!$F('email').empty()){
      location.href='/Mailinglist.aspx?m=unsub&email=' + $F('email');
    }
    return false;
  }
}

var Search = {
  PerformSearch: function(query){
    if(!query.empty()){
      location.href = '/Group.aspx?q=' + escape(query);
    }
  }
}

var cachedList = new Hash();
function $$C(key, clearCache){
  if(clearCache || !cachedList.contains(key)){
    cachedList.set(key, $$(key));
  }
  return cachedList.get(key);
}