//よく使うもの
Ext.BLANK_IMAGE_URL = './ext-2.2/resources/images/default/s.gif';
Ext.Ajax.url = './php/action.php';


String.prototype.getExtent = function(ruler) {
  f = Ext.get(ruler).dom;
  while (c = f.lastChild) f.removeChild(c);
  var text = f.appendChild(document.createTextNode(this));
  var width = f.offsetWidth;
  f.removeChild(text);
  return width;
}

String.prototype.tententen = function(maxWidth, ruler) {
  if (this.length == 0) return '';
  if (this.getExtent(ruler) <= maxWidth) return this;
  for (var i=this.length-1; i>=1; --i) {
    var s = this.slice(0, i) + '...';
    if (s.getExtent(ruler) <= maxWidth) return s;
  }
  return '';
}

setParam = function(action, p1, p2, n1, n2){
	var param = new Object();

	if(action !== ''){param.action = action;}
	if(p1 !== ''){param.panel = p1;}
	if(p2 !== ''){param.panel2 = p2;}
	if(n1 !== ''){param.node = n1;}
	if(n2 !== ''){param.node2 = n2;}

	var fix = Ext.get('fix').getValue();
	var flt = Ext.get('flt').getValue();

	param.user = Ext.get('uid').getValue();
	param.pass = MD5_hexhash(flt + MD5_hexhash(fix));

	return param;
}


setHidden = function(res, hidden){

	res = res.responseText;
	res = Ext.decode(res)[0];

	if(res.flt){hidden.flt.setValue(res.flt);}
	if(res.fix){hidden.fix.setValue(res.fix);}
	if(res.uid){hidden.uid.setValue(res.uid);}

}

setCookie = function(){

	expire = ';expires=' + (new Date( new Date().getTime() + (1000 * 60 * 60 * 24 * 14)));

	var fix = Ext.get('fix').getValue();
	var flt = Ext.get('flt').getValue();

	var user = Ext.get('uid').getValue();
	var pass = MD5_hexhash(flt + MD5_hexhash(flt + fix));

	document.cookie = 'user=' + user + expire;
	document.cookie = 'pass=' + pass + expire;

}

successAjax = function(res, hidden){
	setHidden(res, hidden);
	setCookie();
}

setPanelIds = function(cel){
	//cel:CompositeELment
	var a=new Array();
	a[0]='';
	for(i = 1; i <= cel.getCount(); i++ ){
		a[i]=cel.item(i-1).id;
	}
	return a;
}

checkRes = function(res){

	if(res.responseText.search("error:1") > -1){
		location.href = document.URL;
	}
	return true;
}

between = function(a,b,c){
	if( (a<b && b<c) || (c<b && b<a) ){return true;}
	return false;
}

getColor = function(color){
	switch(color){
		case 1:
			return 'gray';
		break;
		case 2:
			return 'green';
		break;
		case 3:
			return 'orange';
		break;
		case 4:
			return 'purple';
		break;
		case 5:
			return 'red';
		break;

		default:
			return 'blue';
		break;
	}
}

getEmptyInfo = function(){
	emptyInfo = {
	title: ''
	, subtitle: ''
	, url: ''
	, color: '0'
	, comment: ''
	};
	return emptyInfo;
}

logout = function(){
	document.cookie = 'user=;expires=' + (new Date( new Date().getTime() - 1000));
	document.cookie = 'pass=;expires=' + (new Date( new Date().getTime() - 1000));
	document.cookie = 'al=;expires=' + (new Date( new Date().getTime() - 1000));
	location.href = document.URL;
}




getAllProperty = function(obj){
	var myChar = '';
	for (var property in obj){
		myChar += property + "=" + obj[property] + '\n';
	}
	return myChar;
}

