/** Namespace - PCC JavaScript */
if (typeof PCCJS == "undefined") PCCJS = {};

/** @constructor */
PCCJS.javautility = function() 
{
	this.init();
}

PCCJS.javautility.prototype.init = function() 
{
}

/*  GetDate() and GetTime() prototypes:

    Formats date/time specified in 'd'

	Parameters
	    format  Optional. For dates: 0 mm/dd/yyyy (USA)
	                                 1 dd/mm/yyyy (FRANCE)
	                                 2 yyy-mm-dd (ISO)
                          For times: 0 12:00:00pm
                                     1 23:00:00 (24-hour)
                                     2 (same)
	    d       Optional. Date object. Client computer's date used if unspecified.
*/
PCCJS.javautility.prototype.GetDate = function(format, d) 
{
    var CT_DATE_USA = '0', CT_DATE_EUR = '1', CT_DATE_ISO = '2' ;
	switch((null == format) ? CT_DATE_USA : String(format)) 
	{
	case CT_DATE_ISO: // yyy-mm-dd ISO
        idx = new Array(0,1,2) ;
        delim = "-" ;
        break ;
	case CT_DATE_EUR:  // dd/mm/yyyy FRANCE
        idx = new Array(2,1,0) ;
	    delim = "/" ;
        break ;
	default: // CT_DATE_USA mm/dd/yyyy USA
        idx = new Array(1,2,0) ;
	    delim = "/" ;
	}
    if(null == d) 
    {
	    d = new Date();
    }
    var res = new Array(String(d.getFullYear()), String(d.getMonth()+1), String(d.getDate())) ;
    if(res[1].length < 2) 
    {
        res[1] = '0' + res[1] ;
    }
    if(res[2].length < 2) 
    {
        res[2] = '0' + res[2] ;
    }
    res = new Array(res[idx[0]], res[idx[1]], res[idx[2]]) ;
	return res.join(delim) ;
}

PCCJS.javautility.prototype.GetTime = function(format, d) 
{
    if(null == d) 
    {
	    d = new Date();
    }
    var res = new Array(String(d.getHours()), String(d.getMinutes()), String(d.getSeconds())) ;
    for(i=0; i < 3; i++) 
    {
        if(res[i].length < 2) 
        {
            res[i] = '0' + res[i] ;
        }
    }
	switch((null == format) ? '0' : String(format)) 
	{
	case '1': // 24-hour
	case '2':  
        m = '' ;
        break ;
    default:  // a/p meridian
        // 00 01 02 03 04 05 06 07 08 09 10 11 | 12 13 14 15 16 17 18 19 20 21 22 23
        // 12 01 02 03 04 05 06 07 08 09 10 11 | 12 01 02 03 04 05 06 07 08 09 10 11
        if(res[0] < 12) 
        {
            m = 'am' ;
            if(res[0] < 1) 
            {
                res[0] = 12 ;
            }
        } 
        else 
        {
            m = 'pm' ;
            if(res[0] > 12) 
            {
                res[0] -= 12 ;
            }
        }
	}
    return res.join(':') + m ;
}

PCCJS.javautility.prototype.ParseDate = function(value) 
{
    value = String(value) ;
    matches = value.split(/[ \/\-]/g);
    if(matches.length < 3) 
    {
        return null ;
    }
    for(i = 0; i < 3; i++) 
    {
        num = parseInt(matches[i], 10) ;
        if(isNaN(num) || num < 1 || num > 2099) 
        {
            return null ;
        }
        matches[i] = num ;
    }
    if(matches[0] > 31) 
    {
        order = [0,1,2] ;
    }
    else if(matches[0] > 12) 
    {
        order = [2,1,0] ;
    }
    else 
    {
        order = [2,0,1] ;
    }
    if(matches[order[1]] > 12 || matches[order[2]] > 31) 
    {
        return null ;
    }
    if(matches[order[0]] < 100) 
    {
        matches[order[0]] += ((matches[order[0]] < 50) ? 2000 : 1900) ;
    }
    return new Date(matches[order[0]], matches[order[1]]-1, matches[order[2]]) ;
}

PCCJS.javautility.prototype.PopupWindow = function(url, sizeX, sizeY) 
{
    if(null == url) 
    {
        return ;
    }
    var attr = new Array(), i = 0 ;
    if(null != sizeX && sizeX > 99) 
    {
        value = screen.width ;
        if(value < 640) 
        {
            value = 640;
        }
        if(sizeX > value) 
        {
            sizeX = value ;
        }
        value = (value - sizeX)/2;
        attr[i++] = 'width=' + sizeX + ',screenX=' + value + ',left=' + value ;
    }
    if(null != sizeY && sizeY > 99) 
    {
        value = screen.height ;
        if(value < 480) 
        {
            value = 480;
        }
        if(sizeY > value) 
        {
            sizeY = value ;
        }
        value = (value - sizeY)/2;
        attr[i++] = 'height=' + sizeY + ',screenY=' + value + ',top=' + value ;
    }
    window.open(url, '', attr.join(",")) ;
}

PCCJS.javautility.prototype.nothing = function() 
{
    return false ;
}

PCCJS.javautility.prototype.output_hlink = function(text, dclass) 
{
	if(document) 
	{
        var s = new String(), i = 0, v = new Array(
        '<a ' + (dclass ? 'class="' + dclass + '" ' : ''),
        'hr', 'ef="', 'ma', 'il', 'to:', 'pcc', '%', 'pcc', 'glo', 'z', 'al', '!', 'org',
        '?subject=Information Request">');
	    for(i = 0; i < v.length; i++) 
	    {
	        s += ('%' == v[i]) ? '&#64;' : ('!' == v[i]) ? '&#46;' : ('z' == v[i]) ? '&#98;' : v[i] ;
	    }
	    s = s.replace(/org/g, 'c' + 'o' + 'm') ;
	    s += text ;
	    s += '</' ;
	    s += 'a>\n' ;
	    document.write(s) ;
	}
}

PCCJS.javautility.prototype.element_onclick = function(id, mode, value) 
{
	if(null != id) 
	{
		if(null == id[0]) 
		{
			id = Array(id) ;
		}
		for(i = 0; i < id.length; i++) 
		{
			if(null != (elm = document.getElementById(id[i]))) 
			{
				switch(mode) 
				{
				case 1:
					if(! i) 
					{
						newelm = document.createElement("input");
						newelm.setAttribute("type", "hidden");
						newelm.setAttribute("name", elm.name + "_001");
						newelm.setAttribute("value", "1");
						elm.form.appendChild(newelm);
					}
					elm.disabled = value ? false : true ;
					break ;
				}
			}
		}
	}
	return true ;
}