// JavaScript Document
function showorhide( val ) {
    var obj = document.getElementById( val ) ;
    if ( obj.style.display == "block" ) {
        obj.style.display = "none" ;
    } else {
        obj.style.display = "block" ;
    }    
}

function removeElementById(eleId) {
	eleId = document.getElementById(eleId);
	if (eleId.parentNode && eleId.parentNode.removeChild) {
		eleId.parentNode.removeChild(eleId);
	}
}
function openWindow(theURL, winName, features)
{
	window.open(theURL, winName, features);
}

function showflash(file,width,height) {
    document.write('<object type=\"application/x-shockwave-flash\" data=\"'+file+'\" width=\"'+width+'\" height=\"'+height+'\">');
    document.write('    <param name=\"movie\" value=\"'+file+'\" />');
    document.write('    <param name=\"wmode\" value=\"transparent\" />');
    document.write('</object>');
}

///////////////////////* window over *////////////////////
function getScroll() {
   if (document.body.scrollTop != undefined) {	// IE model
      var ieBox = document.compatMode != "CSS1Compat";
      var cont = ieBox ? document.body : document.documentElement;
      return {x : cont.scrollLeft, y : cont.scrollTop};
   }
   else {
      return {x : window.pageXOffset, y : window.pageYOffset};
   }
}


function showtip(current, whichDiv)
{
		var scrollInfo = getScroll();
		elm = document.getElementById( whichDiv );
		elm.style.visibility = "visible";
		elm.style.top = findPosY(current,20) + "px";
		elm.style.left = findPosX(current,20)  + "px" ;
		window.status = '';
}

function hidetip(whichDiv){
	elm2 = document.getElementById( whichDiv );
    elm2.style.visibility="hidden";
}
function popWin(WindowURL,WindowName,WindowArg) {
    var WindowResults = window.open(WindowURL,WindowName,WindowArg);
}

/**
 * Adjusts the x position of a specified element in relation to 
 * the midpoint of the page and is invoked in the onLoad and onResize 
 * events of the window
 *
 * @param  whichElem  	div id of the element to be adjuusted
 * @param  horizTweak	integer x offset in pixels of the specified div
 * @return	
 */
function resAdj(whichElem,horizTweak,verticalTweak){

   var tabWhichElem = whichElem;
   
   if(whichElem == 'wrn'){
      tabWhichElem = 'bbg';
   }
   
	if(!horizTweak){horizTweak = 0;}
	this.obj1 = document.getElementById(whichElem + 'Brand').style;
	yPosition = findPosY(tabWhichElem + "Tab1");
	xPosition = findPosX(tabWhichElem + "Tab1");
	
	this.obj1.top = yPosition + parseInt(verticalTweak) + 15;
	this.obj1.left = xPosition - parseInt(horizTweak);
	
	this.obj1.display = 'block';
	return this.obj1;
}

/**
 * Returns y position of the top left of the passed object 
 *
 * @param	whichObj	id/name of the element to be referenced
 * @return	integer value of the y position of the top left of the specified element
 */
function findPosY(whichObj){
	obj = eval(whichObj);
	var t = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			t += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		t += obj.y;
	return t ;
}

function findPosY(whichObj,offset){
	obj = eval(whichObj);
	var t = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			t += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		t += obj.y;
	return t + offset ;
}

/**
 * Returns x position of the top left of the passed object 
 *
 * @param	whichObj	id/name of the element to be referenced
 * @return	integer value of the x position of the top left of the specified element
 */
function findPosX(whichObj){
	obj = eval(whichObj);
	var t = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			t += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		t += obj.x;
	return t;
}

function findPosX(whichObj, offset){
	obj = eval(whichObj);
	var t = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			t += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		t += obj.x;
	return t + offset;
}
document.getElementsByClassName = function(cl) {
var retnode = [];
var myclass = new RegExp('\\b'+cl+'\\b');
var elem = this.getElementsByTagName('*');
for (var i = 0; i < elem.length; i++) {
var classes = elem[i].className;
if (myclass.test(classes)) retnode.push(elem[i]);
}
return retnode;
};

function encode64(input) {
	// This code was written by Tyler Akins and has been placed in the
	// public domain.  It would be nice if you left this header intact.
	// Base64 code from Tyler Akins -- http://rumkin.com

   var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   do {
      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 + keyStr.charAt(enc1) + keyStr.charAt(enc2) + 
         keyStr.charAt(enc3) + keyStr.charAt(enc4);
   } while (i < input.length);
   
   return output;
}

function decode64(input) {
	// This code was written by Tyler Akins and has been placed in the
	// public domain.  It would be nice if you left this header intact.
	// Base64 code from Tyler Akins -- http://rumkin.com

   var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
   input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

   do {
      enc1 = keyStr.indexOf(input.charAt(i++));
      enc2 = keyStr.indexOf(input.charAt(i++));
      enc3 = keyStr.indexOf(input.charAt(i++));
      enc4 = 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);
      }
   } while (i < input.length);

   return output;
}

function numeric(field)  {
            var e1 = new RegExp("^[0-9]+$");

//            var e2 = new RegExp("^[0-9]*\\.?[0-9]+$");

            if (!e1.test(field.value) /*&& !e2.test(field.value)*/) 

            {

                        var newnum = new String();

                        var boolean = true;

                        for (var i=0 ; i < field.value.length ; i++) 

                        {

                                    if (field.value.charAt(i).match(new RegExp("[0-9]"))) 

                                    {

                                                newnum = newnum + field.value.charAt(i);

                                    } 

                                 
                        }

            field.value = newnum;

            }

}


