/******************************************************************************************************

	HOVER BUTTON
	-------------------------------------------------------------------------------------------
	searches for images with the class="hover_button" and adds event listeners to toggle over 
	and down states. 
	
	The images need be named yourImageName_off.gif, yourImageName_hover.gif, yourImageName_down.gif
	the file extension doesn't matter, just the _off. _hover. & _down.
	
	DEPENDECIES
	- mootools 1.2

******************************************************************************************************/

var hoverButton = new Class({
	initialize: function(options){
		this.options = options; //save our options.
		
		// set the properties for the object
		this.buttonElement = this.options.buttonElement;
		this.offState = this.buttonElement.src;
		this.hoverState = this.offState.replace('_off.', '_hover.');
		
		this.preloadImage([this.hoverState]);		
	},
	setState : function(newState) {
		this.buttonElement.src = newState;	
	},
	preloadImage : function(arrImagePaths) {
		var parentObject = this;
		var img = new Asset.images(arrImagePaths, { onComplete: function(){parentObject.addListeners()} });	
	},
	addListeners : function() {
		this.buttonElement.addEvent('mouseover', this.setState.pass(this.hoverState, this));
		this.buttonElement.addEvent('mouseleave', this.setState.pass(this.offState, this));
	}
});

var hoverButtonHandler = {
	arrHoverButtons : [],
	arrHoverInputs : [],
	
	init : function() {
		var arrButtons = $$('img.hover_button');
		var arrInputs = $$('input.hover_button');
	
		for (i=0; i<arrButtons.length; i++) {		
			hoverButtonHandler.arrHoverButtons[i] = new hoverButton({buttonElement: arrButtons[i]});		
		}	
		
		for (i=0; i<arrInputs.length; i++) {		
			hoverButtonHandler.arrHoverInputs[i] = new hoverButton({buttonElement: arrInputs[i]});		
		}
	}
}

window.addEvent('domready', hoverButtonHandler.init);



/******************************************************************************************************

	MAIN DROP DOWN NAV
	
*******************************************************************************************************/
var mainDropNav = {	
	init : function() {		
		$('primary_nav_home_drop_link').addEvent('click', mainDropNav.openNav);
			
		$('primary_nav_home_drop').addEvent('mouseover', mainDropNav.openNav);		
		$('primary_nav_home_drop').addEvent('mouseout', mainDropNav.closeNav);
	},
	openNav : function() {
		$('primary_nav_home_drop').addClass('open');

	},
	closeNav : function() {
		$('primary_nav_home_drop').removeClass('open');
	}
}



/******************************************************************************************************

	UTILITY NAV DROP DOWNS
	
*******************************************************************************************************/
var utilityDropNav = {	
	init : function() {
		var arrNavs = $('master_container').getElements('.drop_nav');
		
		arrNavs.addEvent('mouseover', utilityDropNav.openNav);
		arrNavs.addEvent('mouseout', utilityDropNav.closeNav);
	},
	openNav : function() {
		this.addClass('open');
	},
	closeNav : function() {
		this.removeClass('open');
	}
}

window.addEvent('domready', utilityDropNav.init);





/******************************************************************************************************

	ACCOUNT LOGIN PANEL 
	
*******************************************************************************************************/
var accountLoginPanel = {
	show : function(xPos, yPos) {
		var loginPanel = $('account_login_panel');
		loginPanel.setStyles({
			top: yPos,
			left: xPos,
			display: 'block'
		});
	},
	closePanel : function() {
		var loginPanel = $('account_login_panel');
		
		loginPanel.setStyle('display','none');
	},
	hideLoginInfo : function() {
		document.getElementById('userid').disabled=true;
		document.getElementById('userpass').disabled=true;
		document.getElementById('rememberme').disabled=true;	
		document.getElementById('useridLabel').style.color = "#a1b2c5";
		document.getElementById('userid').style.backgroundColor = "#a1b2c5";
		document.getElementById('userpass').style.backgroundColor = "#a1b2c5";
		document.getElementById('passLabel').style.color = "#a1b2c5";
		document.getElementById('rememberme').style.backgroundColor = "#a1b2c5";
		document.getElementById('rememberLabel').style.color = "#a1b2c5";			
	},
	showLoginInfo : function() {
		document.getElementById('userid').disabled=false;
		document.getElementById('userpass').disabled=false;
		document.getElementById('rememberme').disabled=false;
		document.getElementById('useridLabel').style.color = "#ffffff";
		document.getElementById('passLabel').style.color = "#ffffff";
		document.getElementById('userid').style.backgroundColor = "#ffffff";
		document.getElementById('userpass').style.backgroundColor = "#ffffff";
		document.getElementById('rememberme').style.backgroundColor = "#ffffff";
		document.getElementById('rememberLabel').style.color = "#ffffff";					
	}
}





/******************************************************************************************************

	POP LAYER 
	- used for the account settings pop-up
	
*******************************************************************************************************/
var popLayer = {
	
	popLayerFade : null,
	popLayerContent : null,
	shim : null,
	center: false,
	shimYOffset: 0,
	shimXOffset: 0,
	
	show : function(popLayerContent) {		
		var popLayerFade = $(popLayer.popLayerFade);
		var popLayerContent = $(popLayer.popLayerContent);
		var shim = $(popLayer.shim);
		
		var windowScrollSize = window.getScrollSize();
		var windowSize = window.getSize();
		
		popLayerContent.setStyles({
			display: 'block',
			visibility: 'hidden'
		});
		
		var popLayerContentSize = popLayerContent.getSize();
		
		popLayerFade.setStyles({
			opacity: 0.6,
			height: $('iefix').getScrollSize().y,
			display: 'block'
		});	
		
		var popContentXPos = (windowSize.x / 2) - (popLayerContentSize.x / 2);
		var popContentYPos = (windowSize.y / 2) - (popLayerContentSize.y / 2);
		
		popLayerContent.setStyles({
			top: popContentYPos,
			left: popContentXPos,
			visibility: 'visible',
			position: 'fixed',
			float: 'left'
		});
		
		shim.setStyles({
			top:  popContentYPos  + (popLayer.shimYOffset), 
			left: popContentXPos + (popLayer.shimXOffset),
			height: popLayerContentSize.y - (popLayer.shimYOffset * 2),
			display: 'block',
			position: 'fixed',
			float: 'left'
		});		
	},
	
	hide : function() {
		var popLayerFade = $(popLayer.popLayerFade);
		var popLayerContent = $(popLayer.popLayerContent);
		var shim = $(popLayer.shim);
		
		popLayerFade.setStyle('display','none');
		popLayerContent.setStyle('display', 'none');
		shim.setStyle('display', 'none');
	}
}




/******************************************************************************************************

	HOVER ROWS
	
	var yourTableReference = new HoverRows('tableID');
	
	- adds hover class to table rows on mouseover
	
*******************************************************************************************************/
var HoverRows = new Class({
    initialize: function(tableID){
		this.tableID = tableID;
		this.arrRows = $(this.tableID).getElements('tr');
		this.arrRows.addEvent('mouseover', this.toggleRow);
		this.arrRows.addEvent('mouseout', this.toggleRow);
	},
	toggleRow: function() {
		var row = this;
		
		if (row.hasClass('hover')) {
			row.removeClass('hover');	
		}
		else {
			row.addClass('hover');	
		}
	}
})


/******************************************************************************************************

	ALL PAIRS DROP DOWN
	
*******************************************************************************************************/
var allPairsDropDown = {	
	init : function() {		
		$('all_pairs_drop_down_link').addEvent('click', allPairsDropDown.openNav);
							

		$('all_pairs_drop_down').addEvent('mouseenter', allPairsDropDown.openNav);		
		$('all_pairs_drop_down').addEvent('mouseleave', allPairsDropDown.closeNav);
		
	},
	openNav : function() {
		$('all_pairs_drop_down').addClass('open');

	},
	closeNav : function() {
		$('all_pairs_drop_down').removeClass('open');
	}
}

/*******************************************

added december 03

*******************************************/

function clearText(theText) 
{
    if (theText.value == theText.defaultValue)
 	{
    theText.value = ""
    }
}


		function displayPhoneNumber() {
			var countrySelect = $('country');
			var newNumber = countrySelect.options[countrySelect.selectedIndex].value;
			$('phone_number_display').set('html', newNumber);
		}


								function sms_providers(proText,example_id){
								
									if (proText == 'att'){
										document.getElementById(example_id).innerHTML = '1234567890@txt.att.net';
									}							
									else  if (proText == 'metropcs'){
										document.getElementById(example_id).innerHTML = '1234567890@mymetropcs.com';
									}
									else  if (proText == 'nextel'){
										document.getElementById(example_id).innerHTML = '1234567890@mymetropcs.com';
									}
									else  if (proText == 'sprint'){
										document.getElementById(example_id).innerHTML = '1234567890@messaging.sprintpcs.com';
									}				
									else if (proText == 'tmobile'){
										document.getElementById(example_id).innerHTML = '1234567890@tmomail.net';
									}			
									else if (proText == 'verizon'){
										document.getElementById(example_id).innerHTML = '1234567890@vtext.com';
									}					
									else if (proText == 'virgin'){
										document.getElementById(example_id).innerHTML = '1234567890@vmobl.com';
									}	
									
									else if (proText == 'selected'){
										document.getElementById(example_id).innerHTML = 'Select a Provider';
									}																																				
								}


 
 
