﻿/// <reference path="jquery-1.2.3-intellisense.js" />

$(function(){
    $('.delete').click(function(){
        $(this).css('color','red');
        var b = confirm('确定要删除吗？');
         $(this).css('color','');
         return b;
    });
})


if( !wuchang )
{
    var wuchang = new Object();
}    
(function($)
{
    $.HTMLEncode = function( text )
    {
        if ( !text )
            return '' ;

        text = text.replace( /&/g, '&amp;' ) ;
        text = text.replace( /</g, '&lt;' ) ;
        text = text.replace( />/g, '&gt;' ) ;

        return text ;
    }

    $.HTMLDecode = function( text )
    {
        if ( !text )
            return '' ;

        text = text.replace( /&gt;/g, '>' ) ;
        text = text.replace( /&lt;/g, '<' ) ;
        text = text.replace( /&amp;/g, '&' ) ;

        return text ;
    }

    $.setTimeout = function( func, milliseconds, thisObject, paramsArray, timerWindow )
    {
        return ( timerWindow || window ).setTimeout(
            function()
            {
	            if ( paramsArray )
		            func.apply( thisObject, [].concat( paramsArray ) ) ;
	            else
		            func.apply( thisObject ) ;
            },
            milliseconds ) ;
    }

    $.setInterval = function( func, milliseconds, thisObject, paramsArray, timerWindow )
    {
        return ( timerWindow || window ).setInterval(
            function()
            {
	            func.apply( thisObject, paramsArray || [] ) ;
            },
            milliseconds ) ;
    }

    $.cloneObject = function( src )
    {
        if( typeof(src)!="object" || src==null)return src; 

        var obj;
        try
        {
            obj = new  src.constructor();
        }catch(e)
        {
            obj = new Object();
        }   
        for ( var key in src )
        {
            if(  src[key] ==null )
            {
                obj[key]= null;
            }else
            {
                var cst= src[key].constructor; 
                if (cst==Boolean || cst==String || cst==Number || cst==Date  )
                {
                     //obj[key] =  new cst( src[key].valueOf())
                     obj[key]=  src[key];
                }else if( cst== Array )
                {
                    obj[key] = new Array();
                    for( var i in src[key])
                    {
                        obj[key][i] = $.cloneObject( src[key][i] );
                    }
                }else if( cst==Object)
                {
                    obj[key] = $.cloneObject( src[key] )
                }else if(typeof(src[key]) =='object')
                {
                    obj[key]= $.cloneObject( src[key] )
                }else
                {
                    alert( [
                        '此属性不支持 clone :',key.toString(),
                        'cst:', cst,
                        'typeof',typeof src[key],
                        'typeof==function',(typeof src[key]) === 'function'
                    ].join('') )
                }
            }

        }
        
        return obj;
    }
    
    function Arguments(args) {
        //convert arguments object to array
        this.value = [].slice.call(args);
    }
/*
  @desc  inject the function
  @param aOrgFunc     the original function to be injected.
  @param aBeforeExec  this is called before the execution of the aOrgFunc.
                      you must return the arguments(new Arguments(arguments)) if you wanna modify the arguments value of the aOrgFunc.
                      it will stop the execution of the aOrgFunc if you return a value not an Arguments object nor a undefined value 
  @param aAtferExec   this is called after the execution of the aOrgFunc.
                      you must add a result argument at the last argument of the aAtferExec function if you wanna get the result value of the aOrgFunc.
                      you must add a isDenied argument following the result argument if you wanna know whether the aOrgFunc is executed.
                      you must return the result if you wanna modify the result value of the aOrgFunc .

  @Usage  Obj.prototype.Method = Inject(Obj.prototype.Method, aFunctionBeforeExec[, aFunctionAtferExec]);
  @version 1.1
  @author  Aimingoo&Riceball
  @history
    V1.0 -- fiest released.
    V1.1 -- 
      Supports to denie the aOrgFunc execution in aBeforeExec.
      Supports around in the aAtferExec, the aAtferExec be always executed even though denie the aOrgFunc execution in aBeforeExec.
        + isDenied argument to the aAtferExec function. notice the aAtferExec whether the aOrgFunc is executed

  eg:
  var doTest = function (a) {return a};
  function beforeTest(a) { alert('before exec: a='+a); a += 3; return new Arguments(arguments);};
  function afterTest(a, result, isDenied) { alert('after exec: a='+a+'; result='+result+';isDenied='+isDenied); return result+5;};
  
  doTest = Inject(doTest, beforeTest, afterTest);
  
  alert (doTest(2));
  the result should be 10.

*/
    $.inject=function( aOrgFunc, aBeforeExec, aAtferExec ) 
    {
        return function() 
        {
            var Result, isDenied=false, args=[].slice.call(arguments);
            if (typeof(aBeforeExec) == 'function') 
            {
                Result = aBeforeExec.apply(this, args);
                if (Result instanceof Arguments) //(Result.constructor === Arguments)
                    args = Result.value;
                else if (isDenied = Result !== undefined)
                    args.push(Result)
            }

            !isDenied && args.push(aOrgFunc.apply(this, args)); //if (!isDenied) args.push(aOrgFunc.apply(this, args));

            if (typeof(aAtferExec) == 'function')
                Result = aAtferExec.apply(this, args.concat(isDenied));
            else 
                Result = undefined;

            return (Result !== undefined ? Result : args.pop());
        }
    }
    
    $.getElementsByClassName=function(className,ele)
    {
        if( !ele )
            ele = document
        if(document.all)
        {
            var children = ele.all;
        }else
        {
            var children = ele.getElementsByTagName('*');
        }
        
        var elements = new Array();
        for (var i = children.length-1; i>=0; i--) 
        {
            var child = children[i];
            var classNames = child.className.split(' ');
            for (var j = 0; j < classNames.length; j++) 
            {
                if (classNames[j] == className) 
                {
                    elements.push( child ); 
                    break;
                }
            }
        }
        return elements;
    }
    
    //format("yyyy-MM-dd hh:mm:ss")); 

    $.dateTimeFormat = function(date, format )
    {
        var o = { 
            "M+" : date.getMonth()+1, //month 
            "d+" : date.getDate(), //day 
            "h+" : date.getHours(), //hour 
            "m+" : date.getMinutes(), //minute 
            "s+" : date.getSeconds(), //second 
            "q+" : Math.floor((date.getMonth()+3)/3), //quarter 
            "S" : date.getMilliseconds() //millisecond 
        } 
        if(/(y+)/.test(format)) 
            format=format.replace(RegExp.$1,(date.getFullYear()+"").substr(4 - RegExp.$1.length) ); 
        for(var k in o)
            if(new RegExp("("+ k +")").test(format)) 
                format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length)); 
        return format; 
    }

 })(wuchang);       


(function ($) {
    var m = {
            '\b': '\\b',
            '\t': '\\t',
            '\n': '\\n',
            '\f': '\\f',
            '\r': '\\r',
            '"' : '\\"',
            '\\': '\\\\'
        },
        s = {
            'array': function (x) {
                var a = ['['], b, f, i, l = x.length, v;
                for (i = 0; i < l; i += 1) {
                    v = x[i];
                    f = s[typeof v];
                    if (f) {
                        v = f(v);
                        if (typeof v == 'string') {
                            if (b) {
                                a[a.length] = ',';
                            }
                            a[a.length] = v;
                            b = true;
                        }
                    }
                }
                a[a.length] = ']';
                return a.join('');
            },
            'boolean': function (x) {
                return s.string(x);
            },
            'null': function (x) {
                return '"null"';
            },
            'number': function (x) {
                return isFinite(x) ? s.string(x) : '"null"';
            },
            'object': function (x) {
                if (x) {
                    switch( x.constructor)
                    {
                        case String:
                        case Date:
                        case Number:
                        case Boolean:
                            return s.string(x);
                        case Array:
                            return s.array(x);
                    }
                    var a = ['{'], b, f, i, v;
                    for (i in x) {
                        v = x[i];
                        f = s[typeof v];
                        if (f) {
                            v = f(v);
                            if (typeof v == 'string') {
                                if (b) {
                                    a[a.length] = ',';
                                }
                                a.push(s.string(i), ':', v);
                                b = true;
                            }
                        }else
                        {   
                            //var msg =i + ':' + v+ typeof v;
                            //alert(msg);
                        }
                    }
                    a[a.length] = '}';
                    return a.join('');
                }
                return 'null';
            },
            'string': function (x) {
                if (/["\\\x00-\x1f]/.test(x)) {
                    x = x.replace(/([\x00-\x1f\\"])/g, function(a, b) {
                        var c = m[b];
                        if (c) {
                            return c;
                        }
                        c = b.charCodeAt();
                        return '\\u00' +
                            Math.floor(c / 16).toString(16) +
                            (c % 16).toString(16);
                    });
                }
                return '"' + x + '"';
            }
        };

	$.toJSON = function(v) {
		var f = isNaN(v) ? s[typeof v] : s['number'];
		if (f) return f(v);
	};
	
	$.parseJSON = function(v, safe) {
		if (safe === undefined) safe = $.parseJSON.safe;
		if (safe && !/^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/.test(v))
			return undefined;
		return eval('('+v+')');
	};
	
	$.parseJSON.safe = false;

})(wuchang);




