// JavaScript Document
function action(form,actionlink){
	form.action=actionlink;
	if(form.onsubmit)form.onsubmit();
	form.submit();
}
function ajax_call(url,params,is_asynchronous){
	
	var evt={};
	var init={};
	init.parameters=params;
	if(is_asynchronous==undefined) is_asynchronous=true;
	init.asynchronous=is_asynchronous;
	
	init.onSuccess=function(t,r){if(evt.onReturn)evt.onReturn(r)};
	
	new Ajax.Request(url,init);
	return evt;
}

function form_action(form,actionlink){
	form.action=actionlink;
	if(form.onsubmit) {
		if(form.onsubmit()==false)return;
	}
	form.submit();
}

function ajax_action(form,url){
	var evt={};
	if(url) form.action = url;
	form.request({onSuccess:function(t,result){if(evt.onReturn) evt.onReturn(result)}});
	return evt;
}
function swapAllCheckbox(obj,form,inputname){
	form.getInputs("checkbox",inputname).each(function(ele){ele.checked=obj.checked;});
}
function openwin(url,p){
	var features=$H({
		directories:"no",
		toolbar:"no",
		menubar:"no",
		location:"no",
		resizable:"no",
		scrollbars:"no",
		status:"no"
	});
	
	var cfeatures={
		width:p.width,
		height:p.height,
		left:(screen.width-p.width)/2,
		top:(screen.height-p.height)/2
	};
	
	features.merge(cfeatures);
	
	delete p.width;
	delete p.height;
	features.merge(p);

	
	return open(url,"",features.invoke('join','=').join(','));
}

var Cookie = {
  set: function(name, value, daysToExpire) {
    var expire = '';
    if (daysToExpire != undefined) {
      var d = new Date();
      d.setTime(d.getTime() + (86400000 * parseFloat(daysToExpire)));
      expire = '; expires=' + d.toGMTString();
    }
    return (document.cookie = escape(name) + '=' + escape(value || '') + expire);
  },
  get: function(name) {
    var cookie = document.cookie.match(new RegExp('(^|;)\\s*' + escape(name) + '=([^;\\s]*)'));
    return (cookie ? unescape(cookie[2]) : null);
  },
  erase: function(name) {
    var cookie = Cookie.get(name) || true;
    Cookie.set(name, '', -1);
    return cookie;
  },
  accept: function() {
    if (typeof navigator.cookieEnabled=='boolean') {
      return navigator.cookieEnabled;
    }
    Cookie.set('_test', '1');
    return (Cookie.erase('_test') == '1');
  }
}


String.prototype.qupdate=function(params){
	path = this.replace(/(\?.*)?$/,'');
	uparams = Object.extend(this.toQueryParams(),params);
	return path+"?"+$H(uparams).toQueryString();
}

Object.extend(Number.prototype, {
	format:function(f){
		if(f==undefined) f=2;
		var r=[];
		i=0;
		n=String(this.toFixed(f)).split('.');
		n[0].toArray().reverse().each(
			function(c){
				if(((i++)%3)==0){
					r.push(",");
					r.push(c);	
				}else{
					r.push(c);	
				}
				
			}
		);
		
		if(n.length==1){
			return Number(r.reverse().join('').sub(/,$/,''))	
		}else{
			return r.reverse().join('').sub(/,$/,'')+'.'+n[1]
		}
	}
});

Object.extend(String.prototype, {
	isEmail:function(){
		s = this.strip();
		return 	/\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/.test(s);
	}
});


function updateQuery(url,q){
	var qp = url.toQueryParams();
	if(qp){
		p = $H(qp).merge(q);
	}
	return (url.sub(/\?.*/,'')+'?'+p.toQueryString ());
	
}

Object.Event.extend(document);
document._intervalID=setInterval(function(){
	if(document.body){
		this.notify("ready");
		clearInterval(this._intervalID);
	}
}.bind(document),1);


var ua = navigator.userAgent.toLowerCase();

isStrict = document.compatMode == "CSS1Compat",
isOpera = ua.indexOf("opera") > -1,
isSafari = (/webkit|khtml/).test(ua),
isIE = !isOpera && ua.indexOf("msie") > -1,
isIE7 = !isOpera && ua.indexOf("msie 7") > -1,
isGecko = !isSafari && ua.indexOf("gecko") > -1,
isBorderBox = isIE && !isStrict,
isWindows = (ua.indexOf("windows") != -1 || ua.indexOf("win32") != -1),
isMac = (ua.indexOf("macintosh") != -1 || ua.indexOf("mac os x") != -1),
isLinux = (ua.indexOf("linux") != -1),
isSecure = window.location.href.toLowerCase().indexOf("https") === 0;






