﻿
var userAgent = navigator.userAgent.toLowerCase();
var is_opera = userAgent.indexOf('opera') != -1 && opera.version();
var is_moz = (navigator.product == 'Gecko') && userAgent.substr(userAgent.indexOf('firefox') + 8, 3);
var is_ie = (userAgent.indexOf('msie') != -1 && !is_opera) && userAgent.substr(userAgent.indexOf('msie') + 5, 3);
function thumbImg(obj) {
    setImgSize(obj,615,1000);
}
function setImgSize(img,maxWidth,maxHeight)
{
	//var img = document.images[imgID];
	if(maxWidth < 1)
	{
	    if(img.height > maxHeight)
	    {
	        img.height = maxHeight;
	    }
	    return true;
	}
	if(maxHeight < 1)
	{
	    if(img.width > maxWidth)
	    {
	        img.width = maxWidth;
	    }
	    return true;
	}
	if(img.height > maxHeight || img.width > maxWidth)
	{
	    if((img.height / maxHeight) > (img.width / maxWidth))
	    {
	        img.height = maxHeight;
	    }
	    else
	    {
	        img.width = maxWidth;
	    }
	    return true;
	}
}

function CPos(x, y){
     this.x = x;
     this.y = y;
}

function GetObjPos(ATarget){
     var target = ATarget;
     var pos = new CPos(target.offsetLeft, target.offsetTop);    
     var target = target.offsetParent;
     while (target){
         pos.x += target.offsetLeft;
         pos.y += target.offsetTop;
         target = target.offsetParent;
     }
    
     return pos;
}


document.onkeyup = function(event)
{
    var e = event||window.event; 
    var ele = e.srcElement||e.target;
	if(typeof(ele.value)!="undefined")
	{
		if(ele.value.indexOf(',')!=-1)
			ele.value = ele.value.replace(/\,/g,'，');
		if(ele.value.indexOf('\"')!=-1)
			ele.value = ele.value.replace(/\"/g,"'");
	}
}

/****************************FF中的outerHTML***********************************/
if (window.HTMLElement) {
  HTMLElement.prototype.__defineSetter__("outerHTML",function(sHTML) {
        var r=this.ownerDocument.createRange();
        r.setStartBefore(this);
        var df=r.createContextualFragment(sHTML);
        this.parentNode.replaceChild(df,this);
        return sHTML;
    });

    HTMLElement.prototype.__defineGetter__("outerHTML",function() {
     var attr;
        var attrs=this.attributes;
        var str="<"+this.tagName.toLowerCase();
        for (var i=0;i<attrs.length;i++) {
            attr=attrs[i];
            if(attr.specified)
                str+=" "+attr.name+'="'+attr.value+'"';
        }
        if(!this.canHaveChildren)
            return str+">";
        return str+">"+this.innerHTML+"</"+this.tagName.toLowerCase()+">";
        });

   HTMLElement.prototype.__defineGetter__("canHaveChildren",function() {
     switch(this.tagName.toLowerCase()) {
         case "area":
         case "base":
         case "basefont":
         case "col":
         case "frame":
         case "hr":
         case "img":
         case "br":
         case "input":
         case "isindex":
         case "link":
         case "meta":
         case "param":
         return false;
     }
     return true;
   });
}


String.prototype.Trim = function()
{
	return this.replace( /(^[ \t\n\r]*)|([ \t\n\r]*$)/g, '' ) ;
}

String.prototype.LTrim = function()
{
	return this.replace( /^[ \t\n\r]*/g, '' ) ;
}

String.prototype.RTrim = function()
{
	return this.replace( /[ \t\n\r]*$/g, '' ) ;
}

String.prototype.lenByte = function(){return this.replace(/[^\x00-\xff]/g,"**").length;}
