// Custom JavaScript Functionality for SellYourCell.com
// -----------------------------------------------------
// Created by .Com Marketing
// Last Revision: 2007-05-04


// functionality for resetting the quantity of the phones
// being added back to 1 when it's triggered
function updateQty() {
	var selectBox = document.getElementById('PhoneQuantity')
	selectBox.value = '1'
}

// functionality for 'activating' the second step box
function activateTwo() {
	var stepTwoBox = document.getElementById('two')
	stepTwoBox.removeClassName('inactive')
}

// functionality for 'activating' the third step box
function activateThree() {
	var stepThreeBox = document.getElementById('three')
	stepThreeBox.removeClassName('inactive')
}


function deactivateLink(linkId) {
	var link = document.getElementById(linkId)
	link.setAttribute('onclick','return false;')
}

function activateLink(linkId) {
	var link = document.getElementById(linkId)
	link.setAttribute('onclick','return true;')
}

Event.observe(window, 'load', function() {
	Event.observe('PhoneManuSelect', 'change', function(event) {
		new Ajax.Updater('two','/dev/home/stepTwo', {
			asynchronous:true, 
			evalScripts:true, 
			parameters:Form.serialize('stepOneForm'), 
			requestHeaders:['X-Update', 'two']
		}) 
	}, false);
	Event.observe('search-input', 'focus', function(event) {
		var input_alt = $("search-input").readAttribute("alt");
		var input_value = $("search-input").readAttribute("value");
		if(input_alt == input_value) {
			$("search-input").writeAttribute("value", "");
			$("search-input").addClassName("writing");
		}
	}, false);
	Event.observe('search-input', 'blur', function(event) {
		var input_alt = $("search-input").readAttribute("alt");
		var input_value = $("search-input").readAttribute("value");
		if(input_value == '') {
			$("search-input").writeAttribute("value", input_alt);
			$("search-input").removeClassName("writing");
		}
	}, false);
	
	new Ajax.Autocompleter("search-input", "autocomplete-results", "ajax/search.php", {
		paramName: "value", 
		minChars: 2,
		afterUpdateElement : addPhone
	});
	Event.observe('questionsAboutYourPhone', 'click', function(event) {
		if($("questionsAboutPhoneCallout").getStyle('display') == 'block')
		$("questionsAboutPhoneCallout").setStyle({display : 'none'});
		else
		$("questionsAboutPhoneCallout").setStyle({display : 'block'});
	}, false);
});

function addPhone(text, li) {
	$("id_landing").writeAttribute("value", li.id);
	$("search-input").clear();
	new Ajax.Updater('three','home/stepThree', {
		asynchronous:true, 
		evalScripts:true, 
		parameters:Form.serialize('autoid'), 
		requestHeaders:['X-Update', 'three']
	});
}
