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

function initLoginBox() {
	var login_username = $('login_username');
	if( login_username ) {
		login_username.addEvent('focus', function(ev){
			if( 'username' == login_username.value ) {
				login_username.value = '';
			}
		});
	}
}

function initSubCategoryToolTips() {

    new Tips($$('span.help a'));
    
}

if( window.onDomReady ) {
    window.onDomReady(initLoginBox);
	window.onDomReady(initSubCategoryToolTips); 
}







// setNewWindow v1.5
function setNewWindow() {
	// make sure the browser has what we need
	if (!document.getElementsByTagName) return false;
	// get the elements
	var links = document.getElementsByTagName("a");
	// make sure there are any
	if (links.length < 1) return false;
	for (a=0; a < links.length; a++) {
		var link = links[a];
		if ((link.getAttribute("href")) && (link.getAttribute("rel") == "external")) {
			if (link.getAttribute("title")) {
				var currentTitle = link.getAttribute("title");
				newTitle = currentTitle + " (opens in new window)";
				link.setAttribute("title", newTitle);
			}
			link.onclick = function() {
				var location = this.getAttribute("href");
				window.open(location, "newWindow");				
				return false;
			}
		}
	}
}
if (window.addEvent) {
    window.addEvent('domready', setNewWindow);
}

function initSignupStateOtherLogic() {
	
	/*
	var IE4 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 4.")!=-1)) ? true : false;
	var IE5 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 5.")!=-1)) ? true : false;
	var IE6 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 6.")!=-1)) ? true : false;
	
	if (IE4 || IE5 || IE6) {
		return;
	}
	*/
	
	//var state_other_div = $('state_other_div');
	var state_div = $('state_div');
	var country_div = $('country_div');
	
	if( state_div && country_div ) {
		
		var countries = country_div.getElement('select');
		countries.addEvent('change', function(ev){

			var states = state_div.getElement('select');
			//var state_other_div = $('state_other_div');

			if( countries.value != 'US' ) {
				states.value = 'OT';
				//state_other_div.setStyle('display', '');
				//state_div.setStyle('display', 'none');
			} else {
				states.value = 'NY';
				//state_other_div.setStyle('display', 'none');
				//state_div.setStyle('display', '');
			}

		});
		
	} else {
		return;
	}
	
	/*
	var countries = country_div.getElement('select');
	if( countries.value != 'US' ) {
		state_other_div.setStyle('display', '');
		state_div.setStyle('display', 'none');
	} else {
		state_other_div.setStyle('display', 'none');
		state_div.setStyle('display', '');
	}
	*/
		
}
if (window.addEvent) {
    window.addEvent('domready', initSignupStateOtherLogic);
}