function openWindow(address,args)
{
	randValue = Math.floor(Math.random() * 1000);
	if (args == null) {
		args = "toolbar=no,menubar=no,scrollbars=auto,resizable=yes,left=150,top=150,width=300,height=200,location=no,status=no";
	}
	
	newWindow = window.open(address, 'newWindow' + randValue, args);
}

//BBBOnline Script
function Rcertify() 
{
popupWin = window.open('http://www.bbbonline.org/cks.asp?id=10304071010531135', 'Participant','location=yes,scrollbars=yes,width=700,height=500'); 
window.name = 'opener';
} 

function clearDefault(myfield,mydefault) {
	if (myfield.value == mydefault) {
		myfield.value = '';
	}
}
function resetDefault(myfield,mydefault) {
	if (myfield.value == '') {
		myfield.value = mydefault;
	}
}

// v_GET_init
// Source: http://www.criticalsecurity.net/index.php?s=6d37542df31a7f25bbd076cae0c97a39&showtopic=13847&st=0&p=80784&#entry80784
//
// Documentation:
// Returns an object containing url variables according to the diagram below. If no querystring exists false is returned.
// 
// Class diagram of the returned object if a querystring exists:
//  __________________________
// |          v_GET           |
// |__________________________|
// |   list_name[] : string   |
// |   list_value[] : string  |
// |   raw : string           |
// |__________________________|
// 
// list_name contains an array of the variable names, in the order they appear in the querystring. 
// list_value contains a corresponding array of the values, also in the order they appear in the querystring. 
// raw is a variable containing the entire querystring as-is, I can't see much use for it but it's included anyway. 
// Lastly probably the most used feature but one I don't know how to document in a class diagram. 
// Lets say the querystring is ?a=1&b=2&c=3. Then using v_GET.a will give 1, v_GET.b will equal 2 etc.
//
// Example:
// v_GET = v_GET_init()
// if (v_GET != false)
// {
//     alert(v_GET.list_name[0])
// }

function v_GET_init1()
{
    v_GET = new Object()
    v_GET.list_name = new Array()
    v_GET.list_value = new Array()
    if (location.href.indexOf('?') == -1)
    {
        return false
    }
    
    v_GET.raw = location.href.substring(location.href.indexOf('?')+1,location.href.length)
    getted_var = v_GET.raw.split("&")
    for (i=0; i<getted_var.length; i++)
    {
        getted_var_name = getted_var[i].substring(0,getted_var[i].search('='))
        getted_var_value = getted_var[i].substring(getted_var[i].search('=')+1,getted_var[i].length)
        v_GET.list_name.push(getted_var_name)
        v_GET.list_value.push(getted_var_value)
        eval("v_GET."+getted_var_name+" = "+getted_var_value)
    }
    return v_GET
}






/*
Script Name: Javascript Cookie Script
Author: Public Domain, with some modifications
Script Source URI: http://techpatterns.com/downloads/javascript_cookies.php
Version 1.0.0
Last Update: 30 May 2004

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
*/

// this function gets the cookie, if it exists
function Get_Cookie( 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 ) );
}

/*
only the first 2 parameters are required, the cookie name, the cookie
value. Cookie time is in milliseconds, so the below expires will make the 
number you pass in the Set_Cookie function call the number of days the cookie
lasts, if you want it to be hours or minutes, just get rid of 24 and 60.

Generally you don't need to worry about domain, path or secure for most applications
so unless you need that, leave those parameters blank in the function call.
*/
function Set_Cookie( name, value, expires, path, domain, secure ) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	// if the expires variable is set, make the correct expires time, the
	// current script below will set it for x number of days, to make it
	// for hours, delete * 24, for minutes, delete * 60 * 24
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	//alert( 'today ' + today.toGMTString() );// this is for testing purpose only
	var expires_date = new Date( today.getTime() + (expires) );
	//alert('expires ' + expires_date.toGMTString());// this is for testing purposes only

	document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + //expires.toGMTString()
		( ( path ) ? ";path=" + path : "" ) + 
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}

// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
	if ( Get_Cookie( name ) ) document.cookie = name + "=" +
			( ( path ) ? ";path=" + path : "") +
			( ( domain ) ? ";domain=" + domain : "" ) +
			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}


function trim(s) {
	while (s.substring(0,1) == ' ') {
	s = s.substring(1,s.length);
	}
	while (s.substring(s.length-1,s.length) == ' ') {
	s = s.substring(0,s.length-1);
	}
	return s;
}

function isNumeric(sText) 
{
	var ValidChars = "0123456789."; //Take the "." out if number is an int
	var Char;
	for (i = 0; i < sText.length; i++) 
	{
	Char = sText.charAt(i);
	if (ValidChars.indexOf(Char) == -1) 
	isNumber = false;
	else
	isNumber = true;
	}
	return isNumber;
}



// findPosition();
//
// Find the position of an element on a page.  Pass an element to the function and an array with the X,Y coordinates will be returned.
// Example:
//		var myPos = findPosition(document.getElementById(popContainer))
//		var myPosX = myPos[0];
//		var myPosY = myPos[1];

function findPosition( oElement ) {
  if( typeof( oElement.offsetParent ) != 'undefined' ) {
    for( var posX = 0, posY = 0; oElement; oElement = oElement.offsetParent ) {
      posX += oElement.offsetLeft;
      posY += oElement.offsetTop;
    }
    return [ posX, posY ];
  } else {
    return [ oElement.x, oElement.y ];
  }
}




// THE FOLLOWING 3 METHODS FADE OUT OR FADE IN A DIV OR OTHER HTML ELEMENT.
// EXAMPLE USAGE:
//	<a href="javascript:fade('me',30);">fade</a>  (speed is in milliseconds. lower numbers cause a faster effect.)
//	<a href="javascript:appear('me',30);">show</a>  (speed is in milliseconds. lower numbers cause a faster effect.)
//	<div id="me">Eric Benson</div>


function setOpacity(domId, val) {
	obj = document.getElementById(domId);
	obj.style.MozOpacity = val;
	obj.style.opacity = val/10;
	obj.style.filter = 'alpha(opacity=' + val*10 + ')';
}

function fade(domId,speed){
	obj = document.getElementById(domId); //Get the Element

	if(obj.style.display == "none") return false; //Return false if the element is already hidden

	var alpha = 10; //Set the initial value of alpha to 10 (Opaque)
	
	function f(){ //Internal function

		alpha--; //Decrement the alpha value
		setOpacity(domId, alpha); //Set the opacity of our element to the specified alpha

		if(alpha > -1){ //If alpha is still bigger than -1 then..
			setTimeout(f, speed); //..then call the function again after specified milliseconds
		}
		else{ //otherwise..
			//obj.style.display = 'none'; //..otherwise now that we cant see the element anyways, hide it
			obj.style.visibility = 'hidden'; //..otherwise now that we cant see the element anyways, hide it
		}
	}
	setTimeout(f, speed); //This is where we call the f() function for the first time
}

function appear(domId,speed){
	obj = document.getElementById(domId); //Get the element

	//if(obj.style.display != "none") return false; //Return if it is already being displayed
	if(obj.style.visibility != "hidden") return false; //Return if it is already being displayed

	//obj.style.display = ''; //Un-hide the object before its animation
	obj.style.visibility = 'visible'; //Un-hide the object before its animation
	var alpha = 0; //Set the initial value of alpha to 0 (invisible)

	function a(){ //Internal function
		alpha++; //Increment alpha

		setOpacity(domId, alpha); //Set the opacity of our element to the specified alpha
		if(alpha < 11)setTimeout(a, speed);

		/*Till alpha is 10, keep calling the
		a() function after specified milliseconds */
	}
	setTimeout(a, speed); //This is where we call the a() function for the first time
}

// END OF FADE FUNCTIONS




function left(str, n){
	if (n <= 0)
		return "";
	else if (n > String(str).length)
		return str;
	else
		return String(str).substring(0,n);
}
function right(str, n){
	if (n <= 0)
	   return "";
	else if (n > String(str).length)
	   return str;
	else {
	   var iLen = String(str).length;
	   return String(str).substring(iLen, iLen - n);
	}
}


function addOnLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

