
/*
	StoryToolbar v1.0
	
	Written by Design Technologist
		- Seth Van Booven [svanbooven@sacbee.com]
	
	Copyright © The Sacramento Bee
	Created by the New Media Department
	Created: June 01, 2001 (sv)  /  Last update: 03/11/02 (sv)
	
	Concepts and ideas originated from the UI SHARP SHOOTER
		- John Weir [info@smokinggun.com]
		  	and his brilliant www.iht.com
	
	PC-Tested for 
		- Internet Explorer 4.0, 5.0, 5.5, 6.01b
		- Netscape 6.01
	MAC-Tested for 
		- Internet Explorer 5.0, 5.1b
	
	****************************************************
		IF YOU DON'T KNOW WHAT YOU ARE DOING
		THEN YOU DON'T BELONG HERE.
		.........................CLOSE IMMEDIATELY!
	****************************************************
------------------------------------------------------------*/

var stLoad     = 0;    // used to init the Story Toolbar - in combination with scripts.js
var stRepOpen  = 0;
var fSize      = 1;	   // init sans-serif
var fontSize   = 13;
var fontFamily = 'verdana,geneva,arial,helvetica,sans-serif';

var stY        = 15;
var stX        = -50;  // init Story Toolbar X position (offstage)

var yElm       = document.getElementById('stY');
var ieX = ie;

if (yElm)
{
	var lyrRef = yElm;
	while (lyrRef.offsetParent != null) 
	{
		stY += lyrRef.offsetTop;
		lyrRef = lyrRef.offsetParent;
	}
	stY += lyrRef.offsetTop;
}
else stY = 325;

if (agt.indexOf('mac') != -1) stY += 15;
if (ie4 || ns6) stY += 5;

var screenWidth = ((ieX || ie4) && document.body) ? document.body.clientWidth : self.innerWidth;

stX = (screenWidth / 2) - 384;
if (ns6) stX -= 7;

if ((ieX || ns6) && document.getElementById('st')) document.getElementById('st').style.top  = stY;
if ((ieX || ns6) && document.getElementById('st')) document.getElementById('st').style.left = stX;

if ((ie4) && document.all('st')) document.all('st').style.pixelTop  = stY;
if ((ie4) && document.all('st')) document.all('st').style.pixelLeft = stX;

function rePos()
{
	screenWidth = (ieX || ie4) ? document.body.clientWidth : self.innerWidth;
	
	stX = (screenWidth / 2) - 384;
	if (ns6) stX -= 7;
	
	var extreme, overflow, temp;
	extreme = stX - 3;
	
	if (screenWidth < 768) 
	{
		temp = extreme;
		temp -= stX;
		stX = temp;
	}
	
	if (ieX || ns6) document.getElementById('st').style.left = stX;
	if (ie4) document.all('st').style.pixelLeft = stX;
};

onresize = function() { rePos(); };

function stDisplay(id)
{
	repObj = (ieX || ns6) ? document.getElementById('stRRFrame') : document.all('stRRFrame');
	if (repObj) 
	{
		repObj.style.display = 'none';
		actDyn = true;
	}
	
	togObj = (ieX || ns6) ? document.getElementById(id) : document.all(id);
	if (togObj)
	{
		if (togObj.style.display == 'block') togObj.style.display = 'none';
		else togObj.style.display = 'block';
	}
};

function stRRToggle(id)
{
	togObj = (ieX || ns6) ? document.getElementById('stInfo') : document.all('stInfo');
	if (togObj) togObj.style.display = 'none';
	
	repObj = (ieX || ns6) ? document.getElementById(id) : document.all(id);
	if (repObj)
	{
		if (repObj.style.display == 'block') 
		{
			stRepOpen = 1;
			repObj.style.display = 'none';
			actDyn = true;
		}
		else 
		{
			if (skin) fizz(); // the fizz() function is located in toolTips.js
			var tmpURL = '/dwb_content_search/v-reporter/index.html?target=' + stRRURL + '&search_fields=8&collection=Current';
			actDyn = false;
			repObj.style.display = 'block';
			if (stRepOpen == 0)
			{
				if (ieX || ns6) document.getElementById('stReporter').src = tmpURL;
				if (ie4) window.top.stReporter.location.href = tmpURL;
			}
		}
	}
};

function stSetObj()
{
	stObj = (document.getElementById) ? document.getElementById('middle-column-static') : document.all('middle-column-static');
};
	
function stTTog()
{
	stSetObj();
	if (fontFamily == 'verdana,geneva,arial,helvetica,sans-serif')
	{
		fontFamily = 'georgia,times,times new roman,serif';
		if (fSize == 1)	// checks for sans-serif then adjusts
		{
			fontSize += 3;	// +3px for the serif font
			stObj.style.fontSize = fontSize + 'px';
			fSize = 0;
		}
	}
	else
	{
		fontFamily = 'verdana,geneva,arial,helvetica,sans-serif';
		if (fSize == 0)	// checks for serif then adjusts
		{
			fontSize -= 3;	// -3px for the serif font
			stObj.style.fontSize = fontSize + 'px';
			fSize = 1;
		}
	}
	stObj.style.fontFamily = fontFamily;
	stSavePrefs();
};

function stTBgr()
{
	fontSize += 1;
	if (fSize == 1)
	{
		if (fontSize > 16) fontSize = 16;
	}
	else 
	{
		if (fontSize > 19) fontSize = 19;	// +3px for the serif font
	}
	stSetObj();
	stObj.style.fontSize = fontSize + 'px';
	stObj.style.lineHeight = (fontSize * 1.2) + 'px';
	stSavePrefs();
};
	
function stTSmr()
{
	fontSize -= 1;
	if (fSize == 1)
	{
		if (fontSize < 9) fontSize = 9;
	}
	else 
	{
		if (fontSize < 12) fontSize = 12;	// +3px for the serif font
	}
	stSetObj();
	stObj.style.fontSize = fontSize + 'px';
	stObj.style.lineHeight = (fontSize * 1.2) + 'px';
	stSavePrefs();
};

function stSavePrefs()
{
	tCookie = 'stPrefs=';
	tCookie = tCookie + '^fSize=' + fSize + '^fontSize=' + fontSize + '^fontFamily=' + fontFamily;
	var expire = new Date ();
   	expire.setTime (expire.getTime() + (6 * 24 * 3600000));	// expires 6 days from users clock
   	expire = expire.toGMTString();
	fCookie = tCookie + '; path=/; expires=' + expire; 
  	document.cookie = fCookie;
};

function stLoadPrefs()
{
	stPrefString = null;
	tArray = document.cookie.split(';');
	for (tA = 0; tA < tArray.length; tA++)
	{
		if (tArray[tA].indexOf('stPrefs=') > -1)
		{
			tPos = tArray[tA].indexOf('=') + 2;
			stPrefString = tArray[tA].substring(tPos, tArray[tA].length);
		}
	}
	if (stPrefString != null)
	{
		tArray = stPrefString.split('^');
		for (tA = 0; tA < tArray.length; tA++)
		{
			if (tArray[tA].indexOf('fSize') > -1)
			{
				tFSize = tArray[tA].split('=');
				fSize  = parseInt(tFSize[1]);
			}
			if (tArray[tA].indexOf('fontSize') > -1)
			{
				tFontSize = tArray[tA].split('=');
				fontSize  = parseInt(tFontSize[1]);
			}
			if (tArray[tA].indexOf('fontFamily') > -1)
			{
				tFontFamily = tArray[tA].split('=');
				fontFamily  = (tFontFamily[1]);
			}
		}
	}
};

function stSetElm()
{
	stSetObj();
	stObj.style.fontSize = fontSize + 'px';
	stObj.style.fontFamily = fontFamily;
	stSavePrefs();
};

function stInit()	// loaded in a global onload function in script.js
{
	stLoadPrefs();
	stSetElm();
};



addEvent = function(o, e, f){
    var a, r = o[r = "_" + (e = "on" + e)] = o[r] || (o[e] ? [o[e]] : []);
    r[r.length] = f, o[e] = function(e){
        try{
            (e = e || event).preventDefault || (e.preventDefault = function(){e.returnValue = false;});
            e.stopPropagation || (e.stopPropagation = function(){e.cancelBubble = true;});
            e.target || (e.target = e.srcElement || null);
            e.key = (e.which + 1 || e.keyCode + 1) - 1 || 0;
        }catch(f){}
        for(f in r)
            a = r[f], a.call ? a.call(o, e) : (o._ = a, o._(e), o._ = null);
        e = null;
    }
};

removeEvent = function(o, e, f){
    for(var i in e = o["_on" + e])
        if(e[i] == f)
            return delete e[i];
    return false;
};

var arrVatStructure = Array();
arrVatStructure.push(new cAssocElm('', ''));
arrVatStructure.push(new cAssocElm('AT', '\U99999999'));
arrVatStructure.push(new cAssocElm('BE', '0999999999')); //999999999
arrVatStructure.push(new cAssocElm('CY', '99999999C'));
arrVatStructure.push(new cAssocElm('CZ', '9999999999'));
arrVatStructure.push(new cAssocElm('DE', '999999999'));
arrVatStructure.push(new cAssocElm('DK', '99 99 99 99'));
arrVatStructure.push(new cAssocElm('EE', '999999999'));
arrVatStructure.push(new cAssocElm('EL', '999999999'));
arrVatStructure.push(new cAssocElm('ES', 'A9999999A'));
arrVatStructure.push(new cAssocElm('FI', '99999999'));
arrVatStructure.push(new cAssocElm('FR', 'AA 999999999'));
arrVatStructure.push(new cAssocElm('GB', '*'));
arrVatStructure.push(new cAssocElm('HU', '99999999'));
arrVatStructure.push(new cAssocElm('IE', '9*99999C'));
arrVatStructure.push(new cAssocElm('IT', '99999999999'));
arrVatStructure.push(new cAssocElm('LT', '999999999999'));
arrVatStructure.push(new cAssocElm('LU', '99999999'));
arrVatStructure.push(new cAssocElm('LV', '99999999999'));
arrVatStructure.push(new cAssocElm('MT', '99999999'));
arrVatStructure.push(new cAssocElm('NL', '999999999B99'));
arrVatStructure.push(new cAssocElm('PL', '9999999999'));
arrVatStructure.push(new cAssocElm('PT', '999999999'));
arrVatStructure.push(new cAssocElm('SE', '999999999999'));
arrVatStructure.push(new cAssocElm('SI', '99999999'));
arrVatStructure.push(new cAssocElm('SK', '9999999999'));

MaskInput = function( f, m, change){ //v1.0
	for( var i in ( !/^(.)\^(.*)$/.test( m ) && f.setAttribute( 'maxlength', m.length ), { keypress: 0, keyup: 1 } ) )
		removeEvent(f, i, function( e ){});
        addEvent( f, i, function( e ){
        	if (e.altKey) return false;
    		if (e.ctrlKey) return false;
            var patterns = { "1": /[A-Z]/i, "2": /[0-9]/, "4": /[?-?]/i, "8": /./ }, rules = { "a": 3, "A": 7, "9": 2, "C":5, "c": 1, "*": 8 };
            function validChar( c, rule ){
                var r = rules[rule] || 0;
                
                for( var i = 1; i <= r; i<<=1 )
                    if( r & i && patterns[i].test( c ) )
                        break;
                return i <= r || c == rule;
            }
            
            var k, mC, r, c = String.fromCharCode( k = e.key ), l = f.value.length;
            ( !k || k == 8 ? 1 : ( r = /^(.)\^(.*)$/.exec( m ) ) && ( r[0] = r[2].indexOf( c ) + 1 ) + 1 ? r[1] == "O" ? r[0] : r[1] == "E" ? !r[0] : validChar( c, r[1] ) || r[0] : ( l = ( f.value += m.substr( l, ( r = /[A|9|C|\*]/i.exec( m.substr( l ) ) ) ? r.index : l ) ).length ) < m.length && validChar( c, m.charAt( l ) ) ) || e.preventDefault();
         } );
};

function cAssocSearch(arr, key){
	for (i=0; i<arr.length && arr[i].key != key; i++);
	return (i>=arr.length ? 0 : (arr[i].key == key ? i : 0));
}