﻿//if (ptjQuery != undefined) {
//    ptjQuery.extend(jQuery.expr[':'], { Contains: "jQuery(a).text().toUpperCase().indexOf(m[3].toUpperCase())>=0" });
//}

jQuery.extend(jQuery.expr[':'], { Contains: "jQuery(a).text().toUpperCase().indexOf(m[3].toUpperCase())>=0" });


String.prototype.format = function() {
    var pattern = /\{\d+\}/g;
    var args = arguments;
    return this.replace(pattern, function(capture) { return args[capture.match(/\d+/)]; });
}

function namespace(ns) {
    var nsParts = ns.split(".");
    var root = window;

    for (var i = 0; i < nsParts.length; i++) {
        if (typeof root[nsParts[i]] == "undefined") {
            root[nsParts[i]] = new Object();
        }
        root = root[nsParts[i]];
    }
}


// Toggles an elements visibility
function toggle(obj) {
	var el = document.getElementById(obj);
	if ( el.style.display != 'none' ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
	}
}

function getCookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ';', len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function setCookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name+'='+escape( value ) +
		( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) + //expires.toGMTString()
		( ( path ) ? ';path=' + path : '' ) +
		( ( domain ) ? ';domain=' + domain : '' ) +
		( ( secure ) ? ';secure' : '' );
}

function deleteCookie( name, path, domain ) {
	if ( getCookie( name ) ) document.cookie = name + '=' +
			( ( path ) ? ';path=' + path : '') +
			( ( domain ) ? ';domain=' + domain : '' ) +
			';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}

function randomPassword(length)
{
  chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
  //chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
  pass = "";
  for(x=0;x<length;x++)
  {
    i = Math.floor(Math.random() * chars.length);
    pass += chars.charAt(i);
  }
  return pass;
}


// Toggles the visibility of an element. Returns true if the element
// is visible after the function call.
function toggleInlineVisibility(el)
{
    var result;

    if (el.style.display == 'none') {
        el.style.display = 'inline';
        result = true;
    } else {
        el.style.display = 'none';
        result = false;
    }
    
    return result;
}

// Toggles the visibility of an element. Returns true if the element
// is visible after the function call.
function toggleElementVisibility(el)
{
    var result;

    if (el.style.display == 'none') {
        showElement(el);
        result = true;
    } else {
        hideElement(el);
        result = false;
    }
    
    return result;
}

// Hides an element
function hideElement(el)
{
    el.style.display = 'none';
}

// Shows an element
function showElement(el)
{
    el.style.display = 'block';
}

