


var modalRoundRadius = 16;
var orangeSeparator = orangeColor = colorOrange = "#EAC785";

function randomizeArray( arr ) {


	for( var t=0; t<arr.length; t++ ) {
	
		var i1 = Math.floor( Math.random() * arr.length );
		var i2 = Math.floor( Math.random() * arr.length );
		
		var subst = arr[i2];
		arr[i2] = arr[i1];
		arr[i1]=subst;
	
	}


	return arr;

};

function getAllElementsStartingWith( withStr ) {


	var ret = new Array;
	
	for( var k in document.all ) {
		
		var v = document.all;
		
		if ( startsWith( v.id, withStr ) )
			ret.push( v.id );
	
	}
	
	return ret;

};




// get random key
function getRandomArrayKey( arr ) {

	if ( count( arr ) == 0 ) 
		return;

	var keys = new Array;
	for( var k in arr )
		keys.push( k );

	return keys[ Math.floor( Math.random() * keys.length ) ];

};

	

function isset( variable ) {
    try {


    	return !( typeof( variable ) == 'undefined' ) ;


    	return true;
    } catch ( e ) {
    	log( "ISSET error: " + e )
        return false;
    }
};


function HXML()
{

	var req = null;




	if(window.XMLHttpRequest)
	{
		try
		{
			req = new XMLHttpRequest();

		}
		catch(e)
		{
			req = false;
		}

		// branch for IE/Windows ActiveX version
	}
	else if(window.ActiveXObject)
	{
		try
		{
			req = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				req = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e)
			{
				req = false;
			}
		}
	}

	return req;
};

/** find in array */
function arrayIndexOf( arr, value ) {
	return indexOf( arr, value );
}
function indexOf( arr, value ) {

	for( var k in arr ) {
		if ( arr[k] == value )
			return k;
	}

	return -1;

};

function decodePressedButton( e ) {

	var keynum;
	var keychar;
	var numcheck;

	if(window.event) // IE
		keynum = e.keyCode;
	else if(e.which)  // Netscape/Firefox/Opera
		keynum = e.which;

	return keynum;
};

function urldecode(str){
	str=replaceAll( str, "+", " " );
	return unescape(str);
};

function urlencode(str){
	str=escape(str);
	str=replaceAll( str, "+", "%2B" );
	return str;
};
	


function POST_AND_EXECUTE( url, params, executeCode ) {

	try {

		var req = HXML();
		req.open('POST', url, true);
		req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				var ret =  req.responseText;
				eval( executeCode );
			}
		}
		req.send( params );

	} catch ( e ) {
		var ret =  null;
		eval( executeCode );
	}
};

function GET_AND_EXECUTE( url, executeCode ) {

	try {

		var req = HXML();
		req.open('GET', url, true);
		req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				var ret =  req.responseText;
				eval( executeCode );
			}
		}
		req.send( );

	} catch ( e ) {
		var ret =  null;
		eval( executeCode );
	}
};

function ID ( elementID ) {
    return document.getElementById( elementID );
};



function setCookie(name,value,days) {
     return createCookie( name, value, days );
};


function writeCookie(name,value,days) {

	if ( !days )
		days = 365;

     return createCookie( name, value, days );
};

function createCookie(name,value,days)
{


	if ( !days )
		days = 365;

	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else
		var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
};

function getCookie(name) {
	return readCookie( name );
}


function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ')
			c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0)
			return c.substring(nameEQ.length,c.length);
	}
	return null;
};

function eraseCookie(name){
	createCookie(name,"",-1);
};

function deleteCookie(name){
	createCookie(name,"",-1);
};


/** Returns new visibility state (true|false) */
function TOGGLE ( id, focusID ) {

    var oldState = ID( id ).style.display;

    ID( id ).style.display = ( oldState == "none" ? "" : "none" );

    // getting focus
    if ( focusID && oldState == "none" ) {
        FOCUS( focusID );
    }

    return oldState == "none";
};


function startsWith ( str, strWith ) {

    if ( !str ) return !strWith;
	
	str = "" + str;

    if ( str.length < strWith.length ) return false;

    if ( str.substring ( 0, strWith.length ) == strWith )
        return true;

    return false;

};


function endsWith ( str, strWith ) {

    if ( !str || !strWith || str.length < strWith.length ) return false;

    if ( str.substring ( str.length - strWith.length ) == strWith )
        return true;

    return false;

};

function trim(TRIM_VALUE)
{

	if ( TRIM_VALUE == null )
		return null;

	if(TRIM_VALUE.length < 1)
	{
		return"";
	}

	TRIM_VALUE = RTrim(TRIM_VALUE);
	TRIM_VALUE = LTrim(TRIM_VALUE);

	if(TRIM_VALUE=="")
	{
		return "";
	}
	else
	{
		return TRIM_VALUE;
	}
}; //End Function

function RTrim(VALUE)
{
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";

	if(v_length < 0)
	{
		return"";
	}

	var iTemp = v_length -1;

	while(iTemp > -1)
	{
		if(VALUE.charAt(iTemp) == " " ||
		        VALUE.charAt(iTemp) == "\n" ||
		        VALUE.charAt(iTemp) == "\t" ||
		        VALUE.charAt(iTemp) == "\b" ||
		        VALUE.charAt(iTemp) == "\r"
		  )
		{}
		else
		{
			strTemp = VALUE.substring(0,iTemp +1);
			break;
		}

		iTemp = iTemp-1;

	} //End While

	return strTemp;

}; //End Function

function LTrim(VALUE)
{
	var w_space = String.fromCharCode(32);

	if(v_length < 1)
	{
		return"";
	}

	var v_length = VALUE.length;
	var strTemp = "";

	var iTemp = 0;

	while(iTemp < v_length)
	{
		if(VALUE.charAt(iTemp) == " " ||
		        VALUE.charAt(iTemp) == "\n" ||
		        VALUE.charAt(iTemp) == "\t" ||
		        VALUE.charAt(iTemp) == "\b" ||
		        VALUE.charAt(iTemp) == "\r"
		  )
		{}
		else
		{
			strTemp = VALUE.substring(iTemp,v_length);
			break;
		}

		iTemp = iTemp + 1;
	} //End While

	return strTemp;
}; //End Function



function firstElement( arr ) {
	return arr[ getElementK( arr, 0 ) ];
}

function getElementK( ar, num ) {
	var ret = null;
	for ( var k4 in ar ) {
		ret = k4;
		if ( num==0 )
			break;
		num--;
	}
	return ret;
};

/** counts array, whether numeric or k/v */
function count ( ar ) {

	if ( !ar )
		return 0;

    var cnt = 0;
    for ( var k in ar )
        cnt++;
    return cnt;
};


function getLastKey( arr ) {
	
	
	var k = null;
	for( k in arr );
	
	return k;
	
}

function getPeriod( sec ) {

	if ( sec < 60 ) return "<1 min";
	if ( sec < 60 * 60 ) return Math.floor(sec/(60))+" min";
	
	if ( sec < 60 * 60 * 24 ) {

		var hrs = Math.floor(sec/(60*60));

		if ( hrs >= 4 )
			return hrs+"h";
		else
			return hrs + "h:" + (Math.floor(sec/60) - (hrs*60)) + "m";
	}
	
	
	if ( sec < 86400 * 60 ) return Math.floor( sec/(60*60*24) )+" days";

	if ( sec < 86400 * 2 * 365 ) return Math.floor(sec/(60*60*24*30)) + " months";

	return (Math.floor(sec/(86400 * 365)) + " years"  );

	/*
	
	if ( $sec < 86400 * 60 ) return (int)($sec/(60*60*24))." days";
	if ( $sec < 86400 * 2 * 365 ) return (int)($sec/(60*60*24*30))." months";
	return (int)($sec/(60*60*24))." ".((int)($sec/(86400 * 365)) + "years"  );
	
	return Math.floor( sec/(60*60*24) )+" days";
*/
};




/** print properties */
function PROPERTIES( obj ) {

    var s = "";
    s += typeof ( obj )+"\n====================\n";

    s += _PROPERTIES ( obj, 0 );

    alert ( s );

};
function _PROPERTIES( obj, level ) {

    if ( obj == null ) return alert ( "null" );

    var s = "";

    if ( obj instanceof Array ) {

 	    for ( var propname in obj ) {

		    s += _PROPERTIES ( obj[propname] );
	        s += "-----------------------\n";
	    }



    } else {

	    for ( var propname in obj )   {


	        var propvalue = obj[propname];

            if ( propvalue instanceof Object ) {



                s += fillstr( "    ", level ) +  propname + " => { \n";
                s += _PROPERTIES ( propvalue, level + 1 );
                s += fillstr( "    ", level ) +"}\n";



            } else {
		        s += fillstr( "    ", level ) + propname + " => " + propvalue + "\n";
		    }

	    }
	}


	return s;

};


function fillstr ( c, num ) {

    var s = "";
    for ( var t=0; t<num;  t++ )
        s += c;
    return s;

};



function replaceAll( str, what, intoWhat, caseInsensitive ) {

	if ( !str )
		return str;

	var str2 = caseInsensitive ? str.toLowerCase() : str;
	var what2 = caseInsensitive ? what.toLowerCase() : what;

    if ( str2.indexOf(what2) == -1 ) return str;

    if ( str2 == what2 ) return intoWhat;

    var ret = "";
    for( var i = 0; i < str2.length; i++ ) {

    	// search
    	if ( i <= str2.length - what2.length &&
    	     str2.substr( i, what2.length ) == what2 ) {

    		ret = ret.concat( intoWhat );
    		i += what2.length-1;
    		continue;

    	// normal
    	} else {
    		ret = ret.concat( str.charAt(i) )
    	}

    }


    return ret;
};



function log( str ) {

	if ( typeof( console ) != "undefined" )
		console.log( str );
};







/**
  WARNING: This method is not tested
example: "test.a.b.c" will generate `test` object and return it */
function createMultiDepthObject( kWithDots, baseObject ) {


	var kname = kWithDots.split(".");

	var knameTmp = "";

	for ( var k8 in kname ) {

		knameTmp += kname[ k8 ];

		eval( "if ( !isset( baseObject."+knameTmp+" ) ) baseObject."+knameTmp+" = new Object();" );


//		knameTmp += ".";

	}

//	knameTmp = knameTmp.substring( 0, knameTmp.length - 1 );
//	eval( "o."+knameTmp+" = faa;" );


	return o;

};





/** Validate email */
function isEmail(str) {

	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if (str.indexOf(at)==-1){
	   return false;
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false;
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    return false;
	}

	 if (str.indexOf(at,(lat+1))!=-1){
	    return false;
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    return false;
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	    return false;
	 }

	 if (str.indexOf(" ")!=-1){
	    return false;
	 }

		 return true	;

};


/** do rectangles intersect */
function isIntersection( x1, y1, w1, h1,
                         x2, y2, w2, h2 ) {


    var xx1 = x1 + w1;
    var yy1 = y1 + h1;
    var xx2 = x2 + w2;
    var yy2 = y2 + h2;







    // is first over second

    if ( x1 <= x2 && y1 <= y2 && xx1 >= xx2 && yy1 >= yy2 )
    	return true;
    if ( x2 <= x1 && y2 <= y1 && xx2 >= xx1 && yy2 >= yy1 )
    	return true;

    	// they intersect
	 return ! ( x2 >= xx1
	        || xx2 <= x1
	        || y2  >= yy1
	        || yy2 <= y1
	        );


};



/** returns object from line like a=4\tc=6 */
function _getObjectFromHmmLine( str ) {
	// generate new object from e content
	var faa = new Object();

	var e = trim(str).split("\t");

	for ( var k2 in e ) {
		var e2 = trim( e[k2] );
		var param = trim ( urldecode( unescape( e2.substring( 0, e2.indexOf("=" ) ) ) ) );
		var value = trim ( urldecode( unescape( e2.substring( e2.indexOf("=" )+1 ) ) ) );
		faa[ replaceAll( param, ".", "-" ) ] = value;
	}

	return faa;

};






/** set info */
function setINFO( item, value )  {
	
	hitServer( "setINFO", "item="+urlencode( item )+"&value="+urlencode( value ) );
	
};


// AB ----------------------------------
// actionValues = "k1=v1,k2=v2...";
var abBuffer = new Array();
var abBufferLastTimeSent = new Date().getTime();
function addAB( actionName, actionValues ) {


	log( "(AB) "+actionName+": " +actionValues );

	abBuffer.push( actionName + "," + Math.floor( new Date().getTime() / 1000 ) +  ":" + actionValues );
	
	// too much in buffer, send
	if (  new Date().getTime() - abBufferLastTimeSent > 90*1000 ) 
		hitServer( "PING", "", "" );
		
};
function getABBufferAsParam() {

	var ret = abBuffer.join( ";" );

	abBuffer.length = 0;
	abBufferLastTimeSent = new Date().getTime();
	
	//log( "AB Requested" );
	
	return ret;
};
// -------------------------------------

function getMousePosition(e) {
	return getCursorPosition(e);
}

function getCursorPos(e) {
	return getCursorPosition(e);
}
function getCursorPosition(e) {

	try {
		e = e || window.event;
	    var cursor = {x:0, y:0};
	    if (e.pageX || e.pageY) {
	        cursor.x = e.pageX;
	        cursor.y = e.pageY;
	    }
	    else {
	        var de = document.documentElement;
	        var b = document.body;
	        cursor.x = e.clientX +
	            (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
	        cursor.y = e.clientY +
	            (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
	    }
	    return cursor;
	} catch ( exx ) {
		return {x:0,y:0};
	}
};

function getPagePosition() {
//	return { x:document.documentElement.scrollLeft, y:document.documentElement.scrollTop };

	return { x:document.body.scrollLeft, y:document.body.scrollTop };

};

function getWindowClientDimensions() {

	return { width:  document.body.clientWidth,
	         height: document.body.clientHeight };

};




/** center html on the screen */
function centerElement( id ) {

	CENTER( id );

/*
	var cli   = getWindowClientDimensions();

	var pagePos = getPagePosition();

	var e = ID( id );


	e.style.left = cli.width / 2  - e.clientWidth  / 2 + pagePos.x;
	e.style.top  = cli.height / 2 - e.clientHeight / 2 + pagePos.y;
*/
};



function CENTER( id ) {
	
	
	var e = ID( id );
	var cli   = getWindowClientDimensions();
	
	var pagePos = getPagePosition();
	
	//log( "CENTER: " + e.style.position );

	e.style.display = "";

	
 	if ( e.style.position == "absolute" ) {
		e.style.left = Math.floor( cli.width / 2 ) - Number( e.offsetWidth ) / 2;
		e.style.top  = Math.floor( cli.height / 4 ) + pagePos.y;
	} else {
		e.style.left = Math.floor( cli.width / 2 )  - Number( e.offsetWidth )  / 2;
		e.style.top  = Math.floor( cli.height / 4 );
	}
	
	
	
	
	
}



function isArray( v ) {
	return v.constructor == Array;
}

function isString( v ) {
	return v.constructor == String;
}



function turnIntoArray( any ) {
	
	if ( !any )
		return [];
	
	var ret = new Array;
	

	
	
	if ( typeof( any ) == "string" ) {
		ret = (""+any).split(",");
	} else {
		for( var k in any ) {
			ret.push( any[k] );
		}
	}
	
	
	return ret;
	
}


function getElementAbsPosition(obj) {
	return findElementAbsolutePosition(obj);
};

function findElementAbsolutePosition(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return { x:curleft, y:curtop };
};





/** create K for name, subitable for using as ID or as object property */

function getKeyFromText( s ) {

	var ret = "";
	for( var t=0; t<s.length; t++ ) {
		var c = s.charAt(t);

		if ( c >= 'A' && c <= 'z' )
			ret += c;
	}

	return ret;

};


/*
 * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
 * Digest Algorithm, as defined in RFC 1321.
 * Version 2.1 Copyright (C) Paul Johnston 1999 - 2002.
 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
 * Distributed under the BSD License
 * See http://pajhome.org.uk/crypt/md5 for more info.
 */

/*
 * Configurable variables. You may need to tweak these to be compatible with
 * the server-side, but the defaults work in most cases.
 */
var hexcase = 0;  /* hex output format. 0 - lowercase; 1 - uppercase        */
var b64pad  = ""; /* base-64 pad character. "=" for strict RFC compliance   */
var chrsz   = 8;  /* bits per input character. 8 - ASCII; 16 - Unicode      */

/*
 * These are the functions you'll usually want to call
 * They take string arguments and return either hex or base-64 encoded strings
 */
function md5(s) { return hex_md5(s); };
function hex_md5(s){ return binl2hex(core_md5(str2binl(s), s.length * chrsz));};
function b64_md5(s){ return binl2b64(core_md5(str2binl(s), s.length * chrsz));};
function str_md5(s){ return binl2str(core_md5(str2binl(s), s.length * chrsz));};
function hex_hmac_md5(key, data) { return binl2hex(core_hmac_md5(key, data)); };
function b64_hmac_md5(key, data) { return binl2b64(core_hmac_md5(key, data)); };
function str_hmac_md5(key, data) { return binl2str(core_hmac_md5(key, data)); };

/*
 * Perform a simple self-test to see if the VM is working
 */
function md5_vm_test()
{
  return hex_md5("abc") == "900150983cd24fb0d6963f7d28e17f72";
};

/*
 * Calculate the MD5 of an array of little-endian words, and a bit length
 */
function core_md5(x, len)
{
  /* append padding */
  x[len >> 5] |= 0x80 << ((len) % 32);
  x[(((len + 64) >>> 9) << 4) + 14] = len;

  var a =  1732584193;
  var b = -271733879;
  var c = -1732584194;
  var d =  271733878;

  for(var i = 0; i < x.length; i += 16)
  {
    var olda = a;
    var oldb = b;
    var oldc = c;
    var oldd = d;

    a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);
    d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);
    c = md5_ff(c, d, a, b, x[i+ 2], 17,  606105819);
    b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);
    a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);
    d = md5_ff(d, a, b, c, x[i+ 5], 12,  1200080426);
    c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341);
    b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983);
    a = md5_ff(a, b, c, d, x[i+ 8], 7 ,  1770035416);
    d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417);
    c = md5_ff(c, d, a, b, x[i+10], 17, -42063);
    b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);
    a = md5_ff(a, b, c, d, x[i+12], 7 ,  1804603682);
    d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);
    c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);
    b = md5_ff(b, c, d, a, x[i+15], 22,  1236535329);

    a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);
    d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
    c = md5_gg(c, d, a, b, x[i+11], 14,  643717713);
    b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);
    a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);
    d = md5_gg(d, a, b, c, x[i+10], 9 ,  38016083);
    c = md5_gg(c, d, a, b, x[i+15], 14, -660478335);
    b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848);
    a = md5_gg(a, b, c, d, x[i+ 9], 5 ,  568446438);
    d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690);
    c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961);
    b = md5_gg(b, c, d, a, x[i+ 8], 20,  1163531501);
    a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);
    d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);
    c = md5_gg(c, d, a, b, x[i+ 7], 14,  1735328473);
    b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);

    a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);
    d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);
    c = md5_hh(c, d, a, b, x[i+11], 16,  1839030562);
    b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);
    a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
    d = md5_hh(d, a, b, c, x[i+ 4], 11,  1272893353);
    c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632);
    b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640);
    a = md5_hh(a, b, c, d, x[i+13], 4 ,  681279174);
    d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222);
    c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979);
    b = md5_hh(b, c, d, a, x[i+ 6], 23,  76029189);
    a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);
    d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);
    c = md5_hh(c, d, a, b, x[i+15], 16,  530742520);
    b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);

    a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);
    d = md5_ii(d, a, b, c, x[i+ 7], 10,  1126891415);
    c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);
    b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);
    a = md5_ii(a, b, c, d, x[i+12], 6 ,  1700485571);
    d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606);
    c = md5_ii(c, d, a, b, x[i+10], 15, -1051523);
    b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799);
    a = md5_ii(a, b, c, d, x[i+ 8], 6 ,  1873313359);
    d = md5_ii(d, a, b, c, x[i+15], 10, -30611744);
    c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380);
    b = md5_ii(b, c, d, a, x[i+13], 21,  1309151649);
    a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);
    d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);
    c = md5_ii(c, d, a, b, x[i+ 2], 15,  718787259);
    b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);

    a = safe_add(a, olda);
    b = safe_add(b, oldb);
    c = safe_add(c, oldc);
    d = safe_add(d, oldd);
  }
  return Array(a, b, c, d);

};

/*
 * These functions implement the four basic operations the algorithm uses.
 */
function md5_cmn(q, a, b, x, s, t)
{
  return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b);
};
function md5_ff(a, b, c, d, x, s, t)
{
  return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
};
function md5_gg(a, b, c, d, x, s, t)
{
  return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
};
function md5_hh(a, b, c, d, x, s, t)
{
  return md5_cmn(b ^ c ^ d, a, b, x, s, t);
};
function md5_ii(a, b, c, d, x, s, t)
{
  return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
};

/*
 * Calculate the HMAC-MD5, of a key and some data
 */
function core_hmac_md5(key, data)
{
  var bkey = str2binl(key);
  if(bkey.length > 16) bkey = core_md5(bkey, key.length * chrsz);

  var ipad = Array(16), opad = Array(16);
  for(var i = 0; i < 16; i++)
  {
    ipad[i] = bkey[i] ^ 0x36363636;
    opad[i] = bkey[i] ^ 0x5C5C5C5C;
  }

  var hash = core_md5(ipad.concat(str2binl(data)), 512 + data.length * chrsz);
  return core_md5(opad.concat(hash), 512 + 128);
};

/*
 * Add integers, wrapping at 2^32. This uses 16-bit operations internally
 * to work around bugs in some JS interpreters.
 */
function safe_add(x, y)
{
  var lsw = (x & 0xFFFF) + (y & 0xFFFF);
  var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
  return (msw << 16) | (lsw & 0xFFFF);
};

/*
 * Bitwise rotate a 32-bit number to the left.
 */
function bit_rol(num, cnt)
{
  return (num << cnt) | (num >>> (32 - cnt));
};

/*
 * Convert a string to an array of little-endian words
 * If chrsz is ASCII, characters >255 have their hi-byte silently ignored.
 */
function str2binl(str)
{
  var bin = Array();
  var mask = (1 << chrsz) - 1;
  for(var i = 0; i < str.length * chrsz; i += chrsz)
    bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (i%32);
  return bin;
};

/*
 * Convert an array of little-endian words to a string
 */
function binl2str(bin)
{
  var str = "";
  var mask = (1 << chrsz) - 1;
  for(var i = 0; i < bin.length * 32; i += chrsz)
    str += String.fromCharCode((bin[i>>5] >>> (i % 32)) & mask);
  return str;
};

/*
 * Convert an array of little-endian words to a hex string.
 */
function binl2hex(binarray)
{
  var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
  var str = "";
  for(var i = 0; i < binarray.length * 4; i++)
  {
    str += hex_tab.charAt((binarray[i>>2] >> ((i%4)*8+4)) & 0xF) +
           hex_tab.charAt((binarray[i>>2] >> ((i%4)*8  )) & 0xF);
  }
  return str;
};

/*
 * Convert an array of little-endian words to a base-64 string
 */
function binl2b64(binarray)
{
  var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  var str = "";
  for(var i = 0; i < binarray.length * 4; i += 3)
  {
    var triplet = (((binarray[i   >> 2] >> 8 * ( i   %4)) & 0xFF) << 16)
                | (((binarray[i+1 >> 2] >> 8 * ((i+1)%4)) & 0xFF) << 8 )
                |  ((binarray[i+2 >> 2] >> 8 * ((i+2)%4)) & 0xFF);
    for(var j = 0; j < 4; j++)
    {
      if(i * 8 + j * 6 > binarray.length * 32) str += b64pad;
      else str += tab.charAt((triplet >> 6*(3-j)) & 0x3F);
    }
  }
  return str;
};




function getRandomKey( arr ) {

	var i = Math.floor( Math.random() * count(arr) );
	for( var k in arr ) {
		if ( (i--) <= 0 )
			return k;
	}

	return null;
};



	
/** show modal */
function HIDE_MODAL( ) {
	ID( "modalDIV" ).style.display = "none";
};

var __currentModalName = null;
var __currentModalWidth = null;
var __currentModalHeight = null;
function centerModal() {

	var windowRect = getWindowClientDimensions();
	
	var pagePos = getPagePosition();
	
	
	var rwidth = 0;
	var rheight = 0;
	
	if ( __currentModalWidth < 0 )
		rwidth = Math.floor( windowRect.width * (Math.abs(__currentModalWidth)/100) );
	else
		rwidth = __currentModalWidth;
		
	if ( __currentModalHeight < 0 )
		rheight  = Math.floor( windowRect.height * (Math.abs(__currentModalHeight)/100) );
	else 
		rheight = __currentModalHeight;
		
	ID( "modalDIV" ).style.width   = "" + rwidth  + "px";
	
	if ( rheight > 0 )
		ID( "modalDIV" ).style.height  = "" + rheight + "px";

	 
//	alert( "" + rheight + "px" );
		
	// center
	ID( "modalDIV" ).style.left = "" + (windowRect.width  / 2 - rwidth / 2) + "px";


	ID( "modalDIV" ).style.top  = "" + (Number( pagePos.y ) + 80) + "px";

	/*
	if( __currentModalHeight == 0 ) 
		ID( "modalDIV" ).style.top  = "40px";
	else
		ID( "modalDIV" ).style.top  = "" + (windowRect.height / 2 - rheight / 2) + "px";
		*/
		

	// inner pane, for content
	ID( "modalDIV_content" ).style.width   = "" + ( rwidth  - modalRoundRadius * 2 )  + "px";
	
	if ( __currentModalHeight != 0 )
		ID( "modalDIV_content" ).style.height  = "" + ( rheight - modalRoundRadius - 32 ) + "px";
	
};

function SHOW_MODAL( name, width, height, s, noscroll, noClose ) {


	// this is important for auto-position modules
	__currentModalName   = name;
	__currentModalWidth  = width;
	__currentModalHeight = height;



	ID( "modalDIV_content" ).innerHTML = s;
	ID( "modalDIV_title" ).innerHTML = name;
	
	if ( noscroll ) {
		ID( "modalDIV_content" ).style.overflowY = "hidden";
	} else {
		ID( "modalDIV_content" ).style.overflowY = "scroll";
	}
	
	if ( noClose ) 
		ID( "modalControlCloseButton" ).style.display = "none";
	else
		ID( "modalControlCloseButton" ).style.display = "";
	
	// initial position
	centerModal();
	window.scrollTo(0,0);
	
	
	
	
	ID( "modalDIV" ).style.display = "";

};


function throbberON() { 
	return;
	if ( ID( "throbberHeader" ) )
		ID( "throbberHeader" ).style.display=""; 
};
function throbberOFF() { 
	if ( ID( "throbberHeader" ) )
		ID( "throbberHeader" ).style.display="none"; 
};



/** get timestamp sec */
function getTimestampSec() {
    return Math.floor(new Date().getTime() / 1000);
}
function time() {
    return getTimestampSec();
}


function getYear() {
	return Math.floor(time()/(86400*365.25) ) + 1970;
};



function getAgeFromFBBirthday( bb ) {

	if ( !bb ) 
		return 0;

	var bb = trim( replaceAll( bb, ",", " " ) ).split(" ");
	
	
	if ( !bb ) 
		return 0;
		
		
	for ( var k in bb ) {
		var v = Number( bb[k] );
		if ( v > 1900 && v < 2050 ) {
			return (getYear() - v);
		}
	}

	return 0;
	
};






/**
*
* Base64 encode / decode
* http://www.webtoolkit.info/
*
**/

var Base64 = {

    // private property
    _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

    // public method for encoding
    encode : function (input) {
        var output = "";
        var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
        var i = 0;

        input = Base64._utf8_encode(input);

        while (i < input.length) {

            chr1 = input.charCodeAt(i++);
            chr2 = input.charCodeAt(i++);
            chr3 = input.charCodeAt(i++);

            enc1 = chr1 >> 2;
            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
            enc4 = chr3 & 63;

            if (isNaN(chr2)) {
                enc3 = enc4 = 64;
            } else if (isNaN(chr3)) {
                enc4 = 64;
            }

            output = output +
            this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
            this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);

        }

        return output;
    },

    // public method for decoding
    decode : function (input) {
        var output = "";
        var chr1, chr2, chr3;
        var enc1, enc2, enc3, enc4;
        var i = 0;

        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

        while (i < input.length) {

            enc1 = this._keyStr.indexOf(input.charAt(i++));
            enc2 = this._keyStr.indexOf(input.charAt(i++));
            enc3 = this._keyStr.indexOf(input.charAt(i++));
            enc4 = this._keyStr.indexOf(input.charAt(i++));

            chr1 = (enc1 << 2) | (enc2 >> 4);
            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
            chr3 = ((enc3 & 3) << 6) | enc4;

            output = output + String.fromCharCode(chr1);

            if (enc3 != 64) {
                output = output + String.fromCharCode(chr2);
            }
            if (enc4 != 64) {
                output = output + String.fromCharCode(chr3);
            }

        }

        output = Base64._utf8_decode(output);

        return output;

    },

    // private method for UTF-8 encoding
    _utf8_encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // private method for UTF-8 decoding
    _utf8_decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

};



function getGloGloNumber( num ) {

	var s = "";
	
	
	num = 0+parseInt( num );
	
	if ( num <= 5 ) {
		switch( num ) {
			case 1: s = "1st"; break;
			case 2: s = "2nd"; break;
			case 3: s = "3rd"; break;
			case 4: s = "4th"; break;
			case 5: s = "5th"; break;
		}
	} else {
		if ( num != "11" && endsWith( ""+num, "1" ) ) {
			s = num + "st";
		} else if ( num != "12" && endsWith( ""+num, "2" ) ) {
			s = num + "nd";
		} else if ( num != "13" && endsWith( ""+num, "3" ) ) {
			s = num + "rd";
		} else {
			s = num + "th";
		}
	}

//	alert( num + "=" + s );

	
	return s;
};

function ROUND_CORNERS_OPEN( cc, rr, styleOnOuter ) {

	var s = "";

	if ( startsWith( cc, "#" ) )
		cc = cc.substring(1);
	
	s += "<div style=\"background-color:#"+cc+"; padding:0px; "+styleOnOuter+"\">";
	s += "<div style=\"height:100%; padding: 0px;  background: url( http://p57.mepopular.com/fb/graphics.php?action=round&c="+cc+"&bc=ffffff&w="+rr+"&h="+rr+"&a=br ) no-repeat bottom right;	\" >";
	s += "<div style=\"height:100%; padding: 0px;  background: url( http://p57.mepopular.com/fb/graphics.php?action=round&c="+cc+"&bc=ffffff&w="+rr+"&h="+rr+"&a=tr ) no-repeat top    right;\" >";
	s += "<div style=\"height:100%; padding: 0px;  background: url( http://p57.mepopular.com/fb/graphics.php?action=round&c="+cc+"&bc=ffffff&w="+rr+"&h="+rr+"&a=tl ) no-repeat top    left;\" >";
	s += "<div style=\"height:100%; padding: "+rr+"px;  background: url( http://p57.mepopular.com/fb/graphics.php?action=round&c="+cc+"&bc=ffffff&w="+rr+"&h="+rr+"&a=bl ) no-repeat bottom left;	\" >";

	return s;

};


function ROUND_CORNERS_CLOSE( ) {

	return  "</div></div></div></div></div>";

};







function var_dump( v ) {
	var s = "";
	for( var k in v ) {
		s += k + " => " + v[k]+ "\n";
	}
	alert(s);
}





function var_export( v ) {
	var s = "";
	for( var k in v ) {
		s += k + " => " + v[k]+ "\n";
	}
	return s;
}






function getHash32(str)	{

	var h = 0;
	for(var n = 0; n < str.length; n++ )	{
		h = ((((h & 0x7ffffff) << 5) - h + str.charCodeAt( n ) ));
		h = parse_unsigned_int(h);
	}

	return h;
	
}


function parse_unsigned_int( str ) {
    var x = 0+str;
    if (x > 2147483647)
        x -= 4294967296;
    if (x < -2147483648)
        x += 4294967296;
    return x;
}

    
function km2mi( km ) {
	return  km * 0.621371192;
}
function mi2km( mi ) {
	return  mi / 0.621371192;
}


	

	
	
	
	

function lastElement( arr ) {

	var v = null;
	for( var k in arr ) 
		v = arr[k];
	
	return v;
	
}	

function lastElementK( arr ) {

	var v = null;
	for( var k in arr ) 
		v = k;
	
	return v;
	
}	








function SCROLL_TO( id ){

	var theElement = ID( id );
	
	if ( !theElement )
		return;

	var selectedPosX = 0;
	var selectedPosY = 0;

	while(theElement != null){
		selectedPosX += theElement.offsetLeft;
		selectedPosY += theElement.offsetTop;
		theElement = theElement.offsetParent;
	}

	window.scrollTo(selectedPosX,selectedPosY);

}


function SCROLL_TO_BOTTOM( id ) {
	var objDiv = ID(id);
	objDiv.scrollTop = objDiv.scrollHeight;
}


function getFunctionName( argumentsCalleeToString ) {
	
    argumentsCalleeToString = argumentsCalleeToString.substr('function '.length);        // trim off "function "

    argumentsCalleeToString = argumentsCalleeToString.substr(0, argumentsCalleeToString.indexOf('('));
	
	return argumentsCalleeToString;
	
}


function implode( sep, arr ) {
	
	var ret = new Array;
	
	for( var k in arr ) {
		ret.push( arr[k] );
	}
	
	return ret.join( sep );
	
}








function getTimestampFromCalendarControl( wts ) {

	// 1 based
	var __gtfcc_months = [ '', 'January','February','March','April','May','June','July','August','September','October','November','December'];


	if ( !wts ) {
		wts = 0;
	}

	log( "getTimestampFromCalendarControl: " + wts );

	try {
		wts = wts.split("-");

		if ( startsWith( wts[1], "0" ) )
			wts[1] = wts[1].substring(1);
		if ( startsWith( wts[0], "0" ) )
			wts[0] = wts[0].substring(1);

		wts = __gtfcc_months[ Number( wts[0] ) ] + " " + Number( wts[1] )  + ", " + Number( wts[2] ) + " 00:00:00";

		log( wts );

		// alert( wts );

		wts = Math.floor( new Date ( wts ).getTime() / 1000 );

	} catch ( e ) {
		wts = 0;
	}


	return wts;
	
}






function highlightSearched( str, kwd ) {
	return replaceAll( str, kwd, "<span style=\"background-color:#ffffa0;\" >"+kwd+"</span>" );
}






/**
*
*  Javascript crc32
*  http://www.webtoolkit.info/
*
**/
 
function crc32 (str) {
 
	function Utf8Encode(string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	};
 
	str = Utf8Encode(str);
 
	var table = "00000000 77073096 EE0E612C 990951BA 076DC419 706AF48F E963A535 9E6495A3 0EDB8832 79DCB8A4 E0D5E91E 97D2D988 09B64C2B 7EB17CBD E7B82D07 90BF1D91 1DB71064 6AB020F2 F3B97148 84BE41DE 1ADAD47D 6DDDE4EB F4D4B551 83D385C7 136C9856 646BA8C0 FD62F97A 8A65C9EC 14015C4F 63066CD9 FA0F3D63 8D080DF5 3B6E20C8 4C69105E D56041E4 A2677172 3C03E4D1 4B04D447 D20D85FD A50AB56B 35B5A8FA 42B2986C DBBBC9D6 ACBCF940 32D86CE3 45DF5C75 DCD60DCF ABD13D59 26D930AC 51DE003A C8D75180 BFD06116 21B4F4B5 56B3C423 CFBA9599 B8BDA50F 2802B89E 5F058808 C60CD9B2 B10BE924 2F6F7C87 58684C11 C1611DAB B6662D3D 76DC4190 01DB7106 98D220BC EFD5102A 71B18589 06B6B51F 9FBFE4A5 E8B8D433 7807C9A2 0F00F934 9609A88E E10E9818 7F6A0DBB 086D3D2D 91646C97 E6635C01 6B6B51F4 1C6C6162 856530D8 F262004E 6C0695ED 1B01A57B 8208F4C1 F50FC457 65B0D9C6 12B7E950 8BBEB8EA FCB9887C 62DD1DDF 15DA2D49 8CD37CF3 FBD44C65 4DB26158 3AB551CE A3BC0074 D4BB30E2 4ADFA541 3DD895D7 A4D1C46D D3D6F4FB 4369E96A 346ED9FC AD678846 DA60B8D0 44042D73 33031DE5 AA0A4C5F DD0D7CC9 5005713C 270241AA BE0B1010 C90C2086 5768B525 206F85B3 B966D409 CE61E49F 5EDEF90E 29D9C998 B0D09822 C7D7A8B4 59B33D17 2EB40D81 B7BD5C3B C0BA6CAD EDB88320 9ABFB3B6 03B6E20C 74B1D29A EAD54739 9DD277AF 04DB2615 73DC1683 E3630B12 94643B84 0D6D6A3E 7A6A5AA8 E40ECF0B 9309FF9D 0A00AE27 7D079EB1 F00F9344 8708A3D2 1E01F268 6906C2FE F762575D 806567CB 196C3671 6E6B06E7 FED41B76 89D32BE0 10DA7A5A 67DD4ACC F9B9DF6F 8EBEEFF9 17B7BE43 60B08ED5 D6D6A3E8 A1D1937E 38D8C2C4 4FDFF252 D1BB67F1 A6BC5767 3FB506DD 48B2364B D80D2BDA AF0A1B4C 36034AF6 41047A60 DF60EFC3 A867DF55 316E8EEF 4669BE79 CB61B38C BC66831A 256FD2A0 5268E236 CC0C7795 BB0B4703 220216B9 5505262F C5BA3BBE B2BD0B28 2BB45A92 5CB36A04 C2D7FFA7 B5D0CF31 2CD99E8B 5BDEAE1D 9B64C2B0 EC63F226 756AA39C 026D930A 9C0906A9 EB0E363F 72076785 05005713 95BF4A82 E2B87A14 7BB12BAE 0CB61B38 92D28E9B E5D5BE0D 7CDCEFB7 0BDBDF21 86D3D2D4 F1D4E242 68DDB3F8 1FDA836E 81BE16CD F6B9265B 6FB077E1 18B74777 88085AE6 FF0F6A70 66063BCA 11010B5C 8F659EFF F862AE69 616BFFD3 166CCF45 A00AE278 D70DD2EE 4E048354 3903B3C2 A7672661 D06016F7 4969474D 3E6E77DB AED16A4A D9D65ADC 40DF0B66 37D83BF0 A9BCAE53 DEBB9EC5 47B2CF7F 30B5FFE9 BDBDF21C CABAC28A 53B39330 24B4A3A6 BAD03605 CDD70693 54DE5729 23D967BF B3667A2E C4614AB8 5D681B02 2A6F2B94 B40BBE37 C30C8EA1 5A05DF1B 2D02EF8D";
 
	if (typeof(crc) == "undefined") { crc = 0; }
	var x = 0;
	var y = 0;
 
	crc = crc ^ (-1);
	for( var i = 0, iTop = str.length; i < iTop; i++ ) {
		y = ( crc ^ str.charCodeAt( i ) ) & 0xFF;
		x = "0x" + table.substr( y * 9, 8 );
		crc = ( crc >>> 8 ) ^ x;
	}
 
	return crc ^ (-1);
 
};











function isDigit(num) {
	if (num.length>1){return false;}
	var string="1234567890";
	if (string.indexOf(num)!=-1){return true;}
	return false;
}


String.prototype.ucFirst = function () {

   return this.substr(0,1).toUpperCase() + this.substr(1,this.length);

};






function createDiv( id, parentIDOrNullForBody )
{
	var divTag = document.createElement("div");
	divTag.id = id;
	
	var parent = document.body;
	
	if ( parentIDOrNullForBody )
		parent = ID( parentIDOrNullForBody );
	
	if ( parent )
		parent.appendChild(divTag);


	return divTag;
}

















/*
 * Date Format 1.2.3
 * (c) 2007-2009 Steven Levithan <stevenlevithan.com>
 * MIT license
 *
 * Includes enhancements by Scott Trenda <scott.trenda.net>
 * and Kris Kowal <cixar.com/~kris.kowal/>
 *
 * Accepts a date, a mask, or a date and a mask.
 * Returns a formatted version of the given date.
 * The date defaults to the current date/time.
 * The mask defaults to dateFormat.masks.default.
 */

var dateFormat = function () {
	var	token = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZ]|"[^"]*"|'[^']*'/g,
		timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,
		timezoneClip = /[^-+\dA-Z]/g,
		pad = function (val, len) {
			val = String(val);
			len = len || 2;
			while (val.length < len) val = "0" + val;
			return val;
		};

	// Regexes and supporting functions are cached through closure
	return function (date, mask, utc) {
		var dF = dateFormat;

		// You can't provide utc if you skip other args (use the "UTC:" mask prefix)
		if (arguments.length == 1 && Object.prototype.toString.call(date) == "[object String]" && !/\d/.test(date)) {
			mask = date;
			date = undefined;
		}

		// Passing date through Date applies Date.parse, if necessary
		date = date ? new Date(date) : new Date;
		if (isNaN(date)) throw SyntaxError("invalid date");

		mask = String(dF.masks[mask] || mask || dF.masks["default"]);

		// Allow setting the utc argument via the mask
		if (mask.slice(0, 4) == "UTC:") {
			mask = mask.slice(4);
			utc = true;
		}

		var	_ = utc ? "getUTC" : "get",
			d = date[_ + "Date"](),
			D = date[_ + "Day"](),
			m = date[_ + "Month"](),
			y = date[_ + "FullYear"](),
			H = date[_ + "Hours"](),
			M = date[_ + "Minutes"](),
			s = date[_ + "Seconds"](),
			L = date[_ + "Milliseconds"](),
			o = utc ? 0 : date.getTimezoneOffset(),
			flags = {
				d:    d,
				dd:   pad(d),
				ddd:  dF.i18n.dayNames[D],
				dddd: dF.i18n.dayNames[D + 7],
				m:    m + 1,
				mm:   pad(m + 1),
				mmm:  dF.i18n.monthNames[m],
				mmmm: dF.i18n.monthNames[m + 12],
				yy:   String(y).slice(2),
				yyyy: y,
				h:    H % 12 || 12,
				hh:   pad(H % 12 || 12),
				H:    H,
				HH:   pad(H),
				M:    M,
				MM:   pad(M),
				s:    s,
				ss:   pad(s),
				l:    pad(L, 3),
				L:    pad(L > 99 ? Math.round(L / 10) : L),
				t:    H < 12 ? "a"  : "p",
				tt:   H < 12 ? "am" : "pm",
				T:    H < 12 ? "A"  : "P",
				TT:   H < 12 ? "AM" : "PM",
				Z:    utc ? "UTC" : (String(date).match(timezone) || [""]).pop().replace(timezoneClip, ""),
				o:    (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4),
				S:    ["th", "st", "nd", "rd"][d % 10 > 3 ? 0 : (d % 100 - d % 10 != 10) * d % 10]
			};

		return mask.replace(token, function ($0) {
			return $0 in flags ? flags[$0] : $0.slice(1, $0.length - 1);
		});
	};
}();

// Some common format strings
dateFormat.masks = {
	"default":      "ddd mmm dd yyyy HH:MM:ss",
	shortDate:      "m/d/yy",
	mediumDate:     "mmm d, yyyy",
	longDate:       "mmmm d, yyyy",
	fullDate:       "dddd, mmmm d, yyyy",
	shortTime:      "h:MM TT",
	mediumTime:     "h:MM:ss TT",
	longTime:       "h:MM:ss TT Z",
	isoDate:        "yyyy-mm-dd",
	isoTime:        "HH:MM:ss",
	isoDateTime:    "yyyy-mm-dd'T'HH:MM:ss",
	isoUtcDateTime: "UTC:yyyy-mm-dd'T'HH:MM:ss'Z'"
};

// Internationalization strings
dateFormat.i18n = {
	dayNames: [
		"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
		"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
	],
	monthNames: [
		"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
		"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
	]
};

// For convenience...
Date.prototype.format = function (mask, utc) {
	return dateFormat(this, mask, utc);
};






//Check if two arrays' contents are the same
//returns true if they are, otherwise false
function compareArray(a,b)
{
  //Check if the arrays are undefined/null
  if(!a || !b)
    return false;

  //first compare their lengths
  if(a.length == b.length)
  {
    //go thru all the vars
    for( var i in a )
    {
      //if the var is an array, we need to make a recursive check
      //otherwise we'll just compare the values
      if(typeof a[i] == 'object') {
        if(!compareArray(a[i],b[i]))
          return false;
      }
      else if(a[i] != b[i])
        return false;
    }
    return true;
  }
  else return false;
}


function disableForm( formElement ) {
	__enableDisableFormElements( formElement, false );
}

function enableForm( formElement ) {
	__enableDisableFormElements( formElement, true );
}


function __enableDisableFormElements( xForm, xHow ) {
	
	
  objElems = xForm.elements;
  for(i=0;i<objElems.length;i++){
    objElems[i].disabled = xHow;
  }
	
}








// baseURL, overURL  can be file paths on local machine
function combineImages( baseURL, overURL, nocache ) {
	
	return "http://p57.mepopular.com/fb/combineImage.php?baseURL="+urlencode( baseURL )+"&overURL="+urlencode( overURL )+"&nocache="+(nocache?"1":"0" );
	
}



//modified version of http://www.webmasterworld.com/forum91/4686.htm
//myField accepts an object reference, myValue accepts the text string to add
function insertAtCursor( elementID, myValue ) {
	
	var myField = ID( elementID );
	
    //IE support
    if (document.selection) {

		try{ 
			
			myField.focus();

	        //in effect we are creating a text range with zero
	        //length at the cursor location and replacing it
	        //with myValue
	        sel = document.selection.createRange();
	        sel.text = myValue;

			
			 } catch ( e ) {}


    //Mozilla/Firefox/Netscape 7+ support
    } else if (myField.selectionStart || myField.selectionStart == '0') {

		try{ 
			
			myField.focus(); 

	        //Here we get the start and end points of the
	        //selection. Then we create substrings up to the
	        //start of the selection and from the end point
	        //of the selection to the end of the field value.
	        //Then we concatenate the first substring, myValue,
	        //and the second substring to get the new value.
	        var startPos = myField.selectionStart;
	        var endPos = myField.selectionEnd;
	        myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length);
	        myField.setSelectionRange(endPos+myValue.length, endPos+myValue.length);

			
		} catch ( e ) {}
    } else {
        myField.value += myValue;
    }
}


function is_function( fname ) {
	
	return(typeof fname == 'function');
	
} 




function niceString( str, maxChars ) {

	str = replaceAll( str, "\n", " " );
	str = replaceAll( str, "\r", "" );

	if ( str.length > maxChars )
		str = str.substring( 0, maxChars-3 ) + "...";


	return str;
	

}













var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();









function isVisible( id ) {
	
	if ( !ID( id ) )
		return false;
		
	return !!ID( id ).offsetWidth;
		
	return ( ID( id ).style.visibility != "hidden" );
	
}





function endsWith( str, what ) {
	
	
	if ( !str || !what )
		return false;
	
	if ( what.length > str.length )
		return false;
		
	if ( typeof( str ) != "string"  )
		return false;
		
	return ( str.substring( str.length - what.length ) == what ) ;
		
	
}


function startsWith( str, what ) {
	
	
	if ( !str || !what )
		return false;
	
	if ( what.length > str.length )
		return false;
		
	if ( typeof( str ) != "string"  )
		return false;
		
		
	return ( str.substring( 0, what.length ) == what ) ;
		
	
}


function FOCUS( id, ms ) {

	setTimeout( "_focusComponent( \""+id+"\" )", ms ? ms : 250 );

}
function _focusComponent( id ) {
	if( ID( id ) && isVisible(id) )
		try { ID( id ).focus(); } catch(e) {};
}










