jQuery.tii={
	  /**
		 * RUP: Replace URL Parameter.
		 * Changes the url paramters that are passed
		 * with json object It keeps the other parameters if they are not set in
		 * the json string Then it redirects the page with GotoURL function
		 *
		 * If the bReturn is set as true, then the function will return the
		 * modified URL hash and will not redirect the page.
		 *
		 * @param {Object}
		 *            json
		 * @param {boolean}
		 *            bReturn optional
		 */
	RUP : function(json, bReturn, h){
	  	/* json : [{p:'param1',v:'value1'},{p:'param2',v:'value2'}] */
	  	if (h==undefined || h=='') {
	  		h=window.location.href;
	  	}
		
	  	if (json.p!==undefined)
	  	{
	  		url=jQuery.tii.SUP(json.p, json.v, h);
	  	}
	  	else
	  	{
	  		for(var i=0; i<json.length; i++)
	  		{
	  			v=json[i].v+'';
	  			p=json[i].p;
	  			//h=jQuery.tii.SUP(p, escape(v.replace('&','&amp;')), h);
	  			h=jQuery.tii.SUP(p, escape(v), h);
	  		}
	  	}
	  	if(bReturn!==undefined && bReturn) return h;
	  	else return jQuery.tii.GotoURL(h);
	},
	  /**
		 * SUP: Set URL Parameter.
		 * Sets the url parameter If there is a set
		 * variable found then updates it otherwise, append the href with name
		 * and value
		 *
		 * @return (string) href
		 */
	  SUP:
	  function(name,value,h){
	  	if (typeof h === 'undefined') h=window.location.href;

	  	var hash='';
	  	if (h.indexOf('#')){tmp=h.split('#');hash=tmp[1];h=tmp[0];}
	    var oldvalue=jQuery.tii.GUP(name);
	    if (oldvalue==null){
	      if (h.indexOf('?')<0)h+='?';
	      h+='&'+name+'='+value;
	    }else{
	      h=h.replace(name+'='+oldvalue,name+'='+value);
	    }
	    return h;
	  },

	  /**
	   * Get URL Parameter
	   * Returns the requested url parameter.
	   * @return (string)
	   */
	  GUP:
	  function(name){
	  	var h=window.location.href;var hash='';
	  	if (h.indexOf('#')){tmp=h.split('#');hash=tmp[1];h=tmp[0];}
	    var name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	    var regexS = "[\\?&]"+name+"=([^&#]*)";
	    var regex = new RegExp( regexS );
	    var results = regex.exec( h );
	    if( results == null )
	      return null;
	    else
	      return results[1];
	  },

	  /**
	   * Redirects the page to the requested URL.
	   */
	  GotoURL:
	  function(url,new_window,params){
	  	if (new_window==undefined) new_window=false;

	  	if (!new_window){
	  		//window.location.href=url;
			setTimeout(function(){
				window.location = url;
			}, 0);
			//window.location.href=url;
			//alert(location.href);
			return true;
	  	}else{
	    	var w=window.open(url,'popup',params);
	    	w.focus();
	  	}
	  },

  /**
   * @param {integer} pnum Page Number
   * @param {integer} tnum Total Page Number
   */
  ChangePagination:
  function(pnum,tnum){
      var current='';
    if ($('#pnum').get(0)){
      current=$('#pnum').val();
    }else{
      current=jQuery.tii.GUP('pnum');
    }
    if(current=='')current=1;
    switch(pnum){
      case 'prev':
        pnum=parseInt(current)-1;
        if (pnum<1) return;
        break;
      case 'next':
        pnum=parseInt(current)+1;
        if (tnum!==undefined && tnum<pnum) return;
        break;
    }
    window.location=jQuery.tii.SUP('pnum',pnum);
  },

    ToggleCheckBox:
    function(obj, el, val, reset_check_group){
        var css_1={'background-color':'#efefef','color':'#369','border':'1px solid #369'};
        var css_2={'background-color':'none','color':'#000','border':'none'};
        if ($(obj).is(':checked')) {
            $(obj).parent().css(css_1);
            var gr=$(obj).attr('check-group');
            if(gr!==undefined){
                $(obj).closest('tr').find('[check-group='+gr+']').not($(obj)).each(function(){
                    $(this).attr('checked',false).parent().css(css_2);
                });
            }
        }else{
            $(obj).parent().css(css_2);
        }

        if (el!==undefined && val!==undefined){
            if (reset_check_group){
                $(obj).closest('tr').find('[check-group='+$(obj).attr('check-group')+']').each(function(){
                    $(this).closest('td').find('input[type=hidden]').val('0');
                });
            }
            $(el).val(val);
        }
    },
	RawUrlEncode: 
	function(str) {
	    // URL-encodes string  
	    // 
	    // version: 911.718
	    // discuss at: http://phpjs.org/functions/rawurlencode
	    // +   original by: Brett Zamir (http://brett-zamir.me)
	    // +      input by: travc
	    // +      input by: Brett Zamir (http://brett-zamir.me)
	    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	    // +      input by: Michael Grier
	    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
	    // +      input by: Ratheous
	    // +      reimplemented by: Brett Zamir (http://brett-zamir.me)
	    // +   bugfixed by: Joris
	    // +      reimplemented by: Brett Zamir (http://brett-zamir.me)
	    // %          note 1: This reflects PHP 5.3/6.0+ behavior
	    // %        note 2: Please be aware that this function expects to encode into UTF-8 encoded strings, as found on
	    // %        note 2: pages served as UTF-8
	    // *     example 1: rawurlencode('Kevin van Zonneveld!');
	    // *     returns 1: 'Kevin%20van%20Zonneveld%21'
	    // *     example 2: rawurlencode('http://kevin.vanzonneveld.net/');
	    // *     returns 2: 'http%3A%2F%2Fkevin.vanzonneveld.net%2F'
	    // *     example 3: rawurlencode('http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a');
	    // *     returns 3: 'http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a'
	    str = (str+'').toString();
	 
	    // Tilde should be allowed unescaped in future versions of PHP (as reflected below), but if you want to reflect current
	    // PHP behavior, you would need to add ".replace(/~/g, '%7E');" to the following.
	    return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').
	                                                                    replace(/\)/g, '%29').replace(/\*/g, '%2A');
	}	
};

$(function(){
        $('.confirm').each(function(){
            var _s=$(this).attr('onclick');
            $(this).attr('onclick','').bind('click',function(){
                if ( ! confirm('The action you are going to take requires confirmation. Are you sure you want to continue?'))
                    return false;
                $(this).unbind('click').bind('click',_s).click();
            });
        });
		
        $('td','.drow').hover(function(){$(this).parent().addClass('drow_over');},function(){$(this).parent().removeClass('drow_over');});

        $('span.yesno').each(function(){$(this).replaceWith($(this).html()==1 ? '<span style="color: #fff; background-color: #3c3; border: 1px solid #3c3; padding: 2px; font-size: 8px">Yes</span>' : '<span style="color: #fff; background-color: #C33; border: 1px solid #c33; padding: 2px; font-size: 8px">NO</span>');});

});


