﻿//Trim()
String.prototype.trim = function() {
	return (this.replace(/^\s+|\s+$/g,""));
}
//Ltrim()
String.prototype.ltrim = function() {
	return (this.replace(/^\s*/,""));
}
//Rtrim()
String.prototype.rtrim = function() {
	return (this.replace(/\s*$/,""));
}
String.prototype.toUTF8 = function(){
	return this.replace(/[^\u0000-\u00FF]/g,function($0){return escape($0).replace(/(%u)(\w{4})/gi,"&#x$2;")});
}
String.prototype.toGB2312 =function(){
	return unescape(this.replace(/&#x/g,'%u').replace(/;/g,''));
}
function $(id){return document.getElementById(id);}
function readCookie(name)
{
  var cookieValue = "";
  var search = name + "=";
  if(document.cookie.length > 0)
  { 
    offset = document.cookie.indexOf(search);
    if (offset != -1)
    { 
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = decodeURI(document.cookie.substring(offset, end))
    }
  }
  return cookieValue;
}
function ImageResize(img){
    if(img.src != ""){
	    var i=new Image();
	    i.src=img.src;
	    if(i.width>img.width){
		    i.height= i.height * (img.width/i.width)
		    i.width=img.width;
	    }
	    if(i.height>img.height){
		    i.width=i.width*(img.height/i.height);
		    i.height=img.height;
	    }
	    if(i.height>0 && i.width>0 ){
	        img.height=i.height;
	        img.width=i.width;
	    }
	}
}