// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults


/* Shows and hides the information on the contact form so that when a location is selected in the drop-down,
 * the proper address info is displayed.
 */
function toggleContactSubmit(location){
	var contactLocations = ['GeneralInformation', 'LondonPressOffice', 'NewYorkPressOffice'];
	contactLocations.each(function(location){
		$(location).hide();
	})
	$(location.gsub(" ", "").camelize()).show();
}

/*
 * Generates a random password for a user so they don't need to think of a good one.
 */
function randomPassword(length)
{
  chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
  pass = "";
  for(x=0;x<length;x++)
  {
    i = Math.floor(Math.random() * 62);
    pass += chars.charAt(i);
  }
  return pass;
}

function uppercase(evt){
/* 
A simple capitaliser.
e.g onKeypress="uppercase(event);"
*/

//key = window.event.keyCode;
var key;
if(navigator.appName=='Netscape'){
		key=evt.charCode;
		if ((key > 0x60) && (key < 0x7B)){
		key = key-0x20;
		var newEvent = document.createEvent("KeyEvents")
		newEvent.initKeyEvent("keypress", true, true, document.defaultView,
                          evt.ctrlKey, evt.altKey, evt.shiftKey,
                          evt.metaKey, 0, String.fromCharCode(key).charCodeAt(0))
		evt.preventDefault()
		evt.target.dispatchEvent(newEvent)	
		}
		if((key==0) && (evt.which==13)){
			//Enter key so suppress
			evt.preventDefault();
		}
}else{
	key = window.event.keyCode ? window.event.keyCode : window.event.which ? window.event.which : window.event.charCode;
	if ((key > 0x60) && (key < 0x7B))
		window.event.keyCode = key-0x20;
	}
	if(key==13){
		//Enter key so suppress
		window.event.cancelBubble = true;
		window.event.returnValue = false;
	}
}

function lowercase(evt){
/* 
A simple lowercase function.
e.g onKeypress="lowercase(event);"
*/
var key;

if(navigator.appName=='Netscape'){
		key=evt.charCode;
		if ((key > 0x40) && (key < 0x5B)){
		key = key+0x20;
		var newEvent = document.createEvent("KeyEvents")
		newEvent.initKeyEvent("keypress", true, true, document.defaultView,
                          evt.ctrlKey, evt.altKey, evt.shiftKey,
                          evt.metaKey, 0, String.fromCharCode(key).charCodeAt(0))
		evt.preventDefault()
		evt.target.dispatchEvent(newEvent)	
		}
}else{
	key = window.event.keyCode;
	if ((key > 0x40) && (key < 0x5B))
	window.event.keyCode = key+0x20;
	}
}

function caseL(obj,evt){
/* 
A lazy word capitaliser.
e.g onKeypress="caseL(this,event);"
*/
var iLen;
var key;
iLen=obj.value.length;
if(navigator.appName=='Netscape'){
		key = evt.charCode;
		if((key==0) && (evt.which==13)){
			//Enter key so suppress
			evt.preventDefault();
		}
	}else{
		key = window.event.keyCode;
		if(key==13){
			//Enter key so suppress
			window.event.cancelBubble = true;
			window.event.returnValue = false;
		}	
	}
if ((iLen==0)||(obj.value.charAt(iLen-1)==" ")||(obj.value.charAt(iLen-1)=="-")){
	
	if ((key > 0x60) && (key < 0x7B)){
		if(navigator.appName=='Netscape'){
			key = key-0x20;
			var newEvent = document.createEvent("KeyEvents")
			newEvent.initKeyEvent("keypress", true, true, document.defaultView, evt.ctrlKey, evt.altKey, evt.shiftKey, evt.metaKey, 0, String.fromCharCode(key).charCodeAt(0))
			evt.preventDefault()
			evt.target.dispatchEvent(newEvent)
		}else{
			window.event.keyCode = key-0x20;
		}
	}
}
}

function maxLength(obj,evt, max,countObj){
	var inc = 1;
	if(navigator.appName == 'Netscape'){	
		key = evt.charCode;
		if(key == 0){
			key = evt.which;
		}
	}else{
		key = window.event.keyCode;
	}
	if(obj.value.length >= max && key != Event.KEY_BACKSPACE && key != Event.KEY_TAB){
		obj.value = obj.value.substring(0, max - 1);
		Event.stop(evt);
	}
	if(key == Event.KEY_BACKSPACE){
		inc = -1;
	}
	if(key == 0){
		inc = 0;
	}
	$(countObj).innerHTML = (obj.value.length + inc >= 0) ? obj.value.length + inc : 0; 
}

// Change the exhibitors exhibits on their show page.
function ChangeExhibit(Number){
	$("exhibits").select("div.exhibitor-exhibit-main").each(function(div) {
  		div.hide()
	});
	$("main-image-" + Number).show();
	$("exhibits-list").select("li").each(function(li) {
  		li.removeClassName("selected");
	});
	$("exhibits-" + Number).addClassName("selected");
}

// Show Exhibit More Info
function ShowMoreInfo(Number){
	$("more-info-details-" + Number).show();
	$("more-info-" + Number).hide();
}

// Show Exhibit More Info
function CloseMoreInfo(Number){
	$("more-info-details-" + Number).hide();
	$("more-info-" + Number).show();
}
