function initializePage(page, value1, value2, value3) {
	switch(page) {
		case 'http://' + document.domain + '/integrated/tell_a_friend/popup_tell_a_friend.php':
				f2_InitMoreTBTAs('tafFriendEmail', 'cloneOption', 'friend_email[0]');
				break;
		case 'http://' + document.domain + '/create_survey.php':
			if (value1 == 1) {
				changeCPMode(1);
			} else if (value1 == 2 && value3 != 'novice') {
				f2_InitMoreTBTAs('cloneOptions', 'cloneOption', 'option[' + value2 + ']');
				changeCPQuestionMode(1);
				changeCPOptionFormat(1, 1);
			}
			
			toggleVisibility('footerNotice', 0);
			break;
		case 'http://' + document.domain + '/create_instance.php':
			changeCIShowInput(1);
			toggleVisibility('footerNotice', 0);
			break;
		default:
			toggleVisibility('footerNotice', 0);
			break;
	}
}

function deinitializePage(page, flag) {
	switch(page) {
		default:
			break;
	}
}

var form_controller = new Array();
function doSubmit(elm){
	if (form_controller[elm.name] == undefined) {
		form_controller[elm.name] = 1;
		return true;
	} else return false;
}

function copySelected(theField) {
	if (theField) {
		var tempval=eval("document."+theField);
		tempval.focus();
		tempval.select();
	}	
	var selectedText = document.selection;
	
	if (document.all) {
		if (selectedText.type == 'Text') {
			var selText = selectedText.createRange();
			selText.execCommand("Copy");
			alert('Press ctrl-V to paste the copied text');
		} else {
			alert('You must first highlight text before it can be copied');
		}
	} else {
		if (theField) {
			alert('Press ctrl-C to copy the selected text and ctrl-V to paste it');
		} else {
			alert('Highlight the text and hit ctrl-C to copy it and ctrl-V to paste it');
		}
	}
}

function setFocus(TargetFormName) {
  var target = 0;
  if (TargetFormName) {
    for (i=0; i<document.forms.length; i++) {
      if (document.forms[i].name == TargetFormName) {
        target = i;
        break;
      }
    }
  }
  
  var TargetForm = document.forms[target];
    
  for (i=0; i<TargetForm.length; i++) {
    if (TargetForm.elements[i].type != 'image' && TargetForm.elements[i].type != 'hidden' && TargetForm.elements[i].type != 'reset' && TargetForm.elements[i].type != 'submit' && TargetForm.elements[i].type != 'undefined') {
      TargetForm.elements[i].focus();
		
      if (TargetForm.elements[i].type == 'text' || TargetForm.elements[i].type == 'password') {
        TargetForm.elements[i].select();
      }

      break;
    }
  }
}

function bookmark(site_url, site_title) {
	if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
		window.external.AddFavorite(site_url , site_title);
	} else if (navigator.appName == "Netscape") {
		alert("Don't forget to bookmark us!  (Press CTRL + D)");
	} else {
		alert("Please bookmark us using your browser interface");
	}
}

function make_start_page(elem, url) {
	if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
		elem.setHomePage(url)
	} else {
		alert("Please make this your start page using your browser interface");
	}
}

function toggleVisibility(szDivID, iState, keep_width, flag) { // 2, auto, 1 visible, 0 hidden
	var obj = '';
	if (document.layers) obj = document.layers[szDivID];
	else if (document.getElementById && document.getElementById(szDivID)) obj = document.getElementById(szDivID).style;
	else if (document.all && document.all[szDivID] && document.all[szDivID].style) obj = document.all[szDivID].style;

	if (obj) {
		if (keep_width) {
			if (iState == 2) obj.visibility = document.layers ? (obj.visibility == 'hide' ? 'show' : 'hide') : (obj.visibility == 'hidden' ? 'visible' : 'hidden');
			else obj.visibility = document.layers ? (iState ? 'show' : 'hide') : (iState ? 'visible' : 'hidden');
			if (flag != 1 && (obj.visibility == 'show' || obj.visibility == 'visible')) toggleVisibility(szDivID, 1, 0, 1);
		} else {
			if (iState == 2) obj.display = obj.display == 'none' ? '' : 'none';
			else obj.display = (iState ? '' : 'none');
			if (flag != 1 && obj.display == '') toggleVisibility(szDivID, 1, 1, 1);
		}
	}
}

function redirect_to(url) {
	window.location = url;
}

function openWindow(site_url, window_name, window_params) {
	window.open(site_url, window_name, window_params);
	return false;
}

var active_menu_id = menu_timeout = headerLinkFlag = null;
function headerLink(menu_id, mode, default_menu_id) {
	if (mode == 0) { /* initialize */
		eval("document.getElementById('headerMenu_" + menu_id  + "').style.display='block'");
		active_menu_id = menu_id;
	}
	else if (mode == 1) { /* mouseover */
		if (menu_id != active_menu_id && active_menu_id != null) {
			eval("document.getElementById('headerMenu_" + active_menu_id  + "').style.display='none'");
			if (active_menu_id > 0) {
				eval("document.getElementById('headerLink_" + active_menu_id  + "').style.borderBottom='1px solid black'");
				eval("document.getElementById('headerLink_" + active_menu_id  + "').style.backgroundColor='#9cf'");
			}
			window.clearTimeout(menu_timeout);
			active_menu_id = menuTimeout = null;
		}
		if (menu_id == active_menu_id) {
			menu_timeout = window.setTimeout('headerLink(' + menu_id + ', 2, ' + default_menu_id + ')', (headerLinkFlag == 1 ? 4500 : 2000));
			headerLinkFlag = 1;
		}
		
		eval("document.getElementById('headerMenuGuide').style.display='block'");
		eval("document.getElementById('headerMenu').style.display='block'");
		eval("document.getElementById('headerMenu_" + menu_id  + "').style.display='block'");
		if (menu_id > 0) {
			eval("document.getElementById('headerLink_" + menu_id  + "').style.borderBottom='1px solid #FFEB8F'");
			eval("document.getElementById('headerLink_" + menu_id  + "').style.backgroundColor='#FFEB8F'");
		}
		active_menu_id = menu_id;
	} else if (mode == 2) { /* timeout executes */
		eval("document.getElementById('headerMenu_" + active_menu_id  + "').style.display='none'");
		if (active_menu_id > 0) {
			eval("document.getElementById('headerLink_" + active_menu_id  + "').style.borderBottom='1px solid black'");
			eval("document.getElementById('headerLink_" + active_menu_id  + "').style.backgroundColor='#9cf'");
		}
		eval("document.getElementById('headerMenu_" + default_menu_id  + "').style.display='block'");
		active_menu_id = default_menu_id;
	}
}

function startclock() {
		var thetime=new Date();
		
		var nhours=thetime.getUTCHours();
		var nmins=thetime.getUTCMinutes();
		var nsecn=thetime.getUTCSeconds();
		var nday=thetime.getUTCDay();
		var AorP=" ";
		
		if (nhours>=12) AorP="PM";
		else AorP="AM";
		if (nhours>=13) nhours-=12;
		if (nhours==0) nhours=12;
		if (nsecn<10)nsecn="0"+nsecn;
		if (nmins<10) nmins="0"+nmins;
		if (nhours<10) nhours="0"+nhours;
		if (nday==0) nday="Sun";
		if (nday==1) nday="Mon";
		if (nday==2) nday="Tues";
		if (nday==3) nday="Wed";
		if (nday==4) nday="Thur";
		if (nday==5) nday="Fri";
		if (nday==6) nday="Sat";

		document.clockform.clockspot.value=nday + " " + nhours+":"+nmins+":"+nsecn+" "+AorP;
		
		setTimeout('startclock()',1000);
		
}

var acMode = 'authors';
function acController(theField) {
		autocompleteOn(theField, acMode, true, 10);
}

function set_acMode(theField) {
	var flag = false;
	if (theField.value != acMode) {
		autocomplete.clearList(); autocomplete.hideList();
		flag = true;
	}
	if (theField.value == 'authors') acMode = theField.value;
	else acMode = 'null';
	
	autocomplete.plugin = acMode;
	if (autocomplete.input) { autocomplete.autoComplete(); autocomplete.input.focus();}
}