// $Id: default.js,v 1.5 2005/04/15 21:52:53 thughes Exp $

/*********************
*                    *
*      objectId()    *
*                    *
*********************/
function objectId(id){
	var objectId = "";
	objectId = document.getElementById(id);
	return objectId;
}

/*********************
*                    *
*   image_rotator    *
*                    *
*********************/

var backgroundSrcs = new Array(
	"/images/pic_frame/pic_frame_00.jpg",
	"/images/pic_frame/pic_frame_01.jpg",
	"/images/pic_frame/pic_frame_02.jpg",
	"/images/pic_frame/pic_frame_03.jpg",
	"/images/pic_frame/pic_frame_04.jpg",
	"/images/pic_frame/pic_frame_05.jpg",
	"/images/pic_frame/pic_frame_06.jpg",
	"/images/pic_frame/pic_frame_07.jpg",
	"/images/pic_frame/pic_frame_08.jpg",
	"/images/pic_frame/pic_frame_09.jpg",
	"/images/pic_frame/pic_frame_10.jpg",
	"/images/pic_frame/pic_frame_11.jpg",
	"/images/pic_frame/pic_frame_12.jpg",
	"/images/pic_frame/pic_frame_13.jpg",
	"/images/pic_frame/pic_frame_14.jpg",
	"/images/pic_frame/pic_frame_15.jpg",
	"/images/pic_frame/pic_frame_16.jpg"
);


function pickimage(){
	var bgimage = backgroundSrcs[(Math.round(Math.random()*(backgroundSrcs.length-1)))];

	if (document.getElementById('pic_frame')){
		document.getElementById('pic_frame').attributes['src'].nodeValue = bgimage;
	}
}

/*********************
*                    *
*  preloadimages()   *
*                    *
*********************/
var load_images=new Array()

function preloadimages(){
	for (i=0;i<preloadimages.arguments.length;i++){
		load_images[i]=new Image()
		load_images[i].src=preloadimages.arguments[i]
	}
}

//preloadimages("block.gif","block_on.gif");


/*********************
*                    *
*      rollover()    *
*                    *
*********************/
function rollover(obj,imgString) {
	// get the image object we're referring to
	// var thisimg = document.getElementById(imgID);
	// and add "_on" to its src
	thisimg.src = thisimg.src.replace(/(\.[a-z0-9]+)$/i,'_on$1');
	obj.src = imgString;
}

function rollout(obj,imgString) {
	// get the image object we're referring to
	// var thisimg = document.getElementById(imgID);
	// and remove "_on" from its src

	thisimg.src = thisimg.src.replace(/_on(\.[a-z0-9]+)$/i,'$1');
	obj.src = imgString;
	
}

function rowOff(obj){
	if (obj.className == "hover") 
		obj.className = "";
}

function rowOver(obj){

	if (obj.className != "selected")
		obj.className = "hover";
}


//sample - <img src="block.gif" id="roll" onmouseover="rollover('roll')" onmouseout="rollout('roll')" />


/***************************
*                          *
*    enable_div_blocks()   *
*                          *
****************************/
var	element_enabled = true;

function enable_div_blocks() {
	var	page_element = new Array(2);
		page_element[0] = "mbrl_sandbox_question";
		page_element[1] = "mbrl_sandbox_definition";
	
	var check_length = page_element.length - 1;

	for (i = 0; i < page_element.length; i++) {
		element = document.getElementById(page_element[i]);
	   	if (element_enabled) {
			element.className = page_element[i] + "_on";
			if (i == check_length) {
				element_enabled = false;
			}
		} else {
			element.className = page_element[i];
			if (i == check_length) {
				element_enabled = true;
			}
		}
	}
}


/*********************
*                    *
*   open_window()    *
*                    *
*********************/
function open_window(sURL,xwidth,yheight) {
	window.name = "main";
	var newwindow = null;
	var s_width = screen.availWidth;
	var s_height = screen.availHeight;
	var p_width = xwidth;
	var c_height = yheight;
	var x_position = ((s_width - p_width - 10) * .5);
	var y_position = ((s_height - c_height - 30) * .5);

	newwindow=window.open(sURL,'childwin','scrollbars=1,toolbar=0,directories=0,menubar=0,resizable=1,status=0,width=' + xwidth + ',height=' + yheight + ',left='+ x_position + ',top='+ y_position);
	//newwindow.resizeTo(p_width,c_height);
	//newwindow.moveTo(x_position,y_position);
	newwindow.focus();
}

function open_win(sURL) {
	window.name = "main";
	var newwindow = null;
	var sPercent = 80;
	var s_width = screen.availWidth;
	var s_height = screen.availHeight;
	var p_width = (s_width * (sPercent / 100));
	var c_height = (s_height * (sPercent / 100));
	var x_position = ((s_width - p_width - 10) * .5);
	var y_position = ((s_height - c_height - 30) * .5);

	newwindow=window.open(sURL,'childwin','scrollbars=1,toolbar=0,directories=0,menubar=0,resizable=1,status=0,width=' + p_width + ',height=' + c_height + ',left='+ x_position + ',top='+ y_position);
	//newwindow.resizeTo(p_width,c_height);
	//newwindow.moveTo(x_position,y_position);
	newwindow.focus();
}

function open_full_window(sURL) {
	window.name = "main";
	var newwindow = null;
	var s_width = screen.availWidth;
	var s_height = screen.availHeight;
	
	newwindow=window.open(sURL,'childwin','scrollbars=1,location=0,toolbar=0,directories=0,menubar=0,resizable=0,status=0,width='+ s_width +',height='+ s_height +',left=0,top=0');
	newwindow.resizeTo(s_width,s_height);
	newwindow.moveTo(0,0);
	newwindow.focus();
}

/*********************
*                    *
*    quick_menu()    *
*                    *
*********************/
function quick_menu(x) {
	var menu_selection = "";
	menu_selection = select_choice(x);
	if (menu_selection != "") {
		document.location.href = menu_selection;
	}
}

/**********************
*                     *
*   select_choice()   *
*                     *
**********************/
function select_choice(objectName) {
	var selection = "";
	menuIndex = objectName.selectedIndex;
	selection = objectName.options[menuIndex].value;
	return selection;
}

/*********************
*                    *
*   radio_choice()   *
*                    *
*********************/
function radio_choice(objectName) {
	var radio = "";
	for (var i=0; i < objectName.length; i++){
		if (objectName[i].checked){
			radio = objectName[i].value;
		}
	} 
	return radio;
}

/*********************
*                    *
*     set_focus()    *
*                    *
*********************/
function set_focus(objectName) {
	obx = objectId(objectName);
	obx.focus();
}

/*********************
*                    *
*      num_char()    *
*                    *
*********************/
function num_char(evt) {
	if (evt) {
        if (evt.charCode) {
			charCode = evt.charCode;
		} else if(evt.keyCode) {
			charCode = evt.keyCode;
		} else {
			charCode = "";
		}
		if ((charCode > 47 && charCode < 58 ) || (charCode == 8 || charCode == 9)) {
			return true;
		} else {
			return false;
		}
	}
}

/*********************
*                    *
*    alpha_char()    *
*                    *
*********************/
function alpha_char(evt) {
	if (evt) {
        if (evt.charCode) {
			charCode = evt.charCode;
		} else if(evt.keyCode) {
			charCode = evt.keyCode;
		} else {
			charCode = "";
		}
		if ((charCode > 64 && charCode < 91 ) || (charCode > 96 && charCode < 123 ) || (charCode == 8 || charCode == 9 || charCode == 32)) {
			return true;
		} else {
			return false;
		}
	}
}

/*********************
*                    *
*  num_char_plus()   *
*                    *
*********************/
function num_char_plus(evt) {
	if (evt) {
        if (evt.charCode) {
			charCode = evt.charCode;
		} else if(evt.keyCode) {
			charCode = evt.keyCode;
		} else {
			charCode = "";
		}
		if ((charCode > 47 && charCode < 58 ) || (charCode == 8 || charCode == 9 || charCode == 32 || charCode == 40 || charCode == 41 || charCode == 44 || charCode == 45 || charCode == 46 || charCode == 47 )) {
			return true;
		} else {
			return false;
		}
	}
}

/*********************
*                    *
*  alpha_char_plus() *
*                    *
*********************/
function alpha_char_plus(evt) {
	if (evt) {
        if (evt.charCode) {
			charCode = evt.charCode;
		} else if(evt.keyCode) {
			charCode = evt.keyCode;
		} else {
			charCode = "";
		}
		if ((charCode > 64 && charCode < 91 ) || (charCode > 96 && charCode < 123 ) || (charCode == 8 || charCode == 9 || charCode == 32 || charCode == 40 || charCode == 41 || charCode == 44 || charCode == 45 || charCode == 46 || charCode == 47 )) {
			return true;
		} else {
			return false;
		}
	}
}

/*********************
*                    *
*    date_format()   *
*                    *
*********************/
function date_format(string,objectName,evt) {
	var x = 0;
	if (evt) {
        if (evt.charCode) {
			charCode = evt.charCode;
		} else if(evt.keyCode) {
			charCode = evt.keyCode;
		} else {
			charCode = "";
		}
		if (charCode == 8 || charCode == 9) {
			x = 1;
		} else {
			x = 0;
		}
		if (x == 0){
			if (string.length == 2 || string.length == 5) {
				objectName.value = objectName.value + "/";
			} 
		}
	}
}

/*********************
*                    *
*   phone_format()   *
*                    *
*********************/
function phone_format(string,objectName,evt) {
	var x = 0;
	if (evt) {
        if (evt.charCode) {
			charCode = evt.charCode;
		} else if(evt.keyCode) {
			charCode = evt.keyCode;
		} else {
			charCode = "";
		}
		if (charCode == 8 || charCode == 9) {
			x = 1;
		} else {
			x = 0;
		}
		if (x == 0) {
			if (string.length == 1) {
				objectName.value = "(" + objectName.value;
			} else if (string.length == 4) {
				objectName.value = objectName.value + ")";
			} else if (string.length == 8) {
				objectName.value = objectName.value + "-";
			}
		}
	}
}

/*********************
*                    *
*    check_date()    *
*                    *
*********************/
function check_date(string) {
	var error = 0;
	a = string.value;
	if (a.length != 10) { 
		error=1;
	}
	b = a.substring(0, 2)// month
	c = a.substring(2, 3)// '/'
	d = a.substring(3, 5)// day
	e = a.substring(5, 6)// '/'
	f = a.substring(6, 10)// year
	if (b < 1 || b > 12) { 
		error = 1; 
	}
	if (d < 1 || d > 31) {
		error = 1;
	}
	if (f < 1900 ) {
		error = 1;
	}
	if (b == 4 || b == 6 || b == 9 || b == 11) {
		if (d == 31) {
			error = 1;
		}
	}
	if (b == 2){
		var g = parseInt(f/4);
		if (isNaN(g)) {
			error = 1;
		}
		if (d > 29) {
			error = 1;
		}
		if (d == 29 && ((f/4)!=parseInt(f/4))) {
			error = 1;
		}
	}
	if (error == 1) {
		alert(string.value + " is not a valid date. Please format date as xx/xx/xxxx.");
		string.value = "";
	}
}

/*********************
*                    *
*   check_email()   *
*                    *
*********************/
function check_email(string) {
	var regexp_0 = eval(/(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/);
	var regexp_1 = eval(/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/);
	
	/*
	/(^[a-z]([a-z_\.]*)@([a-z_\.]*)([.][a-z]{3})$)|(^[a-z]([a-z_\.]*)@([a-z_\.]*)(\.[a-z]{3})(\.[a-z]{2})*$)/i
	/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi
	/(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/
	/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/
	*/
	
	var email = string.value.match(regexp_0);
		email = string.value.match(regexp_1);
	
	if (email) {
	   //alert("This is a valid email address.");
	} else {
	   alert("Please enter a valid email address. Please format email as xxx@xxx.com.");
	   string.value = "";
   }
}

/***********************
*                      *
*   virtual keyboard   *
*                      *
***********************/

var shift_state = false;


function setSource(obj){
	document.getElementById('originating_source').value = document.getElementById(obj).id;
}	

function setShift(){
	if (shift_state) {
	  	document.getElementById('shift_button').value = "false";
		shift_state = false;
	} else {
		document.getElementById('shift_button').value = "true";
		shift_state = true;
	}
}	


function setCapsLock(){
	var number_buttons = document.getElementById('property').getElementsByTagName('input');
	for (i = 0; i < number_buttons.length; i++){
		var string = number_buttons[i].attributes['value'].nodeValue;
		var regexp_0 = eval(/^[a-z]{1}$/);	
		var regtest_0 = string.match(regexp_0);
		var regexp_1 = eval(/^[A-Z]{1}$/);	
		var regtest_1 = string.match(regexp_1);
		if (regtest_0){
			number_buttons[i].attributes['value'].nodeValue = string.toUpperCase();
		} else if (regtest_1) {
			number_buttons[i].attributes['value'].nodeValue = string.toLowerCase();
		}
	}
}

function setBackspace(){
	var focus_source = document.getElementById('originating_source').value;
	if (focus_source != ""){
		var text_area = document.getElementById(focus_source).value;
		if (text_area != ""){
			text_area = text_area.substring(0,(text_area.length - 1));
			document.getElementById(focus_source).value = text_area;
		} 
	}
}

function setSpace(){
	var focus_source = document.getElementById('originating_source').value;
	if (focus_source != ""){
		var text_area = document.getElementById(focus_source).value;
		if (text_area != ""){
			text_area = text_area + " ";
			document.getElementById(focus_source).value = text_area;
		} 
	}
}

function setKeyStroke(obj){
	var focus_source = document.getElementById('originating_source').value;
	if (focus_source != ""){
		var text_area = document.getElementById(focus_source).value;
		if (shift_state) {
			obj = obj.toUpperCase();
		}
		text_area = text_area + obj;
		document.getElementById(focus_source).value = text_area;
		shift_state = false; 
	}
}

/*********************
*                    *
*  check_then Submit *
*                    *
*********************/


function checkfirst() {
	if(document.check.disclaimer.checked)
	{
	document.check.submit.disabled=false;
	}
	else
	{
	document.check.submit.disabled=true;
	}
}

/*************************
*                        *
*  video speed selector  *
*                        *
*************************/


function radio_input(url)
{
// Re-direct the browser to the url value
window.location.href = url 
}

/*************************
*                        *
*  popup for Help text   *
*                        *
*************************/

function open_win_help(sURL,xwidth,yheight) {
	window.name = "main";
	var newwindow = null;
	var s_width = screen.availWidth;
	var s_height = screen.availHeight;
	var p_width = xwidth;
	var c_height = yheight;
	var x_position = ((s_width - p_width - 10) * .5);
	var y_position = ((s_height - c_height - 30) * .5);

	newwindow=window.open(sURL,'childwin','scrollbars=0,toolbar=0,directories=0,menubar=0,resizable=0,status=0,width=' + xwidth + ',height=' + yheight + ',left='+ x_position + ',top='+ y_position);
	newwindow.resizeTo(p_width,c_height);
	newwindow.moveTo(x_position,y_position);
}

