﻿String.prototype.Trim=function(){return this.replace(/(^\s*)|(\s*$)/g, "");}
String.prototype.LTrim=function(){return this.replace(/(^\s*)/g,"");}
String.prototype.RTrim=function(){return this.replace(/(\s*$)/g,"");}
Function.prototype.bind=function(object){
	var _method=this;
	return function(){
		_method.apply(object,arguments);
	}
}
Function.prototype.bindAsEventListener=function(object){
	var _method=this;
	return function(event){
		_method.call(object,event || window.event);
	}
}
function $(o){return document.getElementById(o);}
function _(tagName){return document.getElementsByTagName(tagName);}
//type:msie||firefox
function Browser(type){return (0<=window.navigate.userAgent.toLowerCase().indexOf(type));}
function getEvent(evt){return (evt=evt?evt:window.event);}
function setSelected(slt,value){
	for(var i=0;i<slt.options.length;i++){
		if(slt.options[i].value==value)slt.options[i].selected=true;
		else slt.options[i].selected=false;
	}
}
function AddDate(oldDate,date){return (oldDate.getTime()+date*24*60*60*1000);}
function DateSpan(date1,date2){return ((date1.getTime()-date2.getTime())/(24*60*60*1000));}
function ImageWH(image,width,height){if(image.offsetWidth>width){var ht=image.offsetHeight*width/image.offsetWidth;if(ht>height)ht=height;image.style.height=ht+'px';image.sytle.width=width+'px';}}
//var style={color:#ff0000,backgroundColor:#ffffff,borderWidth:2px}
function Style(object,style){
	for(var p in style){
		object.style[p]=style[p];
	}
}
function createFunction(obj,strFunc){
	var args=[];
	if(!obj)obj=window;
	for(var i=2;i<arguments.length;i++)args.push(arguments[i]);
	return function(){
		obj[strFunc].apply(obj,args);
	}
}
function Delegate(fn,params,obj){   
    return function(){   
        fn.apply(obj||window,params);   
    }   
}
function SetStyle(o,css){o.className=css;}
function SetImgSrc(o,src){o.src=ApplicationUri+src;}

function Ajax(url){
	var m_xmlReq=null;
	var m_OnSucceed=function(param,result){};
	var m_Param=null;
	if(window.ActiveXObject){
	    try{
	        m_xmlReq = new ActiveXObject('Msxml2.XMLHTTP'); 
	    }catch(e){
	        try{
	            m_xmlReq = new ActiveXObject('Microsoft.XMLHTTP');
	        }catch(e){}
	    }
	}
	else if(window.XMLHttpRequest){
	    m_xmlReq = new XMLHttpRequest();
	}
	
	this.OnSucceed=function(succeed,param){
		m_OnSucceed=succeed;
		m_Param=param;
	}
	
	this.Post=function(d){
	    if(!m_xmlReq)  return;
	    m_xmlReq.open('POST',url,true);
	    m_xmlReq.onreadystatechange = function(){
	        if(m_xmlReq.readyState==4 && m_xmlReq.status==200){
		        eval(m_OnSucceed+'("'+m_Param+'","'+m_xmlReq.responseText+'")');    
		    }
	    };
	    m_xmlReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset=utf-8');
	    m_xmlReq.send(d);
	}
}
function HideMenu(o){
	var subMenu=o.getElementsByTagName('ul')[0];
	subMenu.style.display='none';
}
function ShowMenu(o){
	var subMenu=o.getElementsByTagName('ul')[0];
	subMenu.style.display='block';
}
var ApplicationUri='/';
