/**
 * @author ctyler
 */

 
function selectDevice(){
	var deviceID = $F('device');
	
	new Ajax.Updater('brand', '/support/register/offsite_ajax.php?id='+deviceID+'&action=selectDevice', {
		method: 'get'
	});
}
 
function selectBrand(){
	var deviceID = $F('device');
	var brandID = $F('brand');
	
	new Ajax.Updater('model', '/support/register/offsite_ajax.php?device='+deviceID+'&make='+brandID+'&action=selectBrand', {
		method: 'get'
	});
}

function selectModel(){
	var modelSKU = $F('model');
	
	new Ajax.Request('/support/register/offsite_ajax.php?sku='+modelSKU+'&action=selectModel', {
	  method: 'get',
	  onSuccess: function(transport) {
	  	var response = transport.responseText;
	    $('modelText').setAttribute('value', response);
	  }
	});
}

function doValidateCode(){
	var code = $F('code');
	
	$('loading').style.display = '';	
	$('failed').style.display = 'none';
	
	new Ajax.Request('/support/register/offsite_ajax.php?code='+code+'&action=doValidateCode', {
	  method: 'get',
	  onSuccess: function(transport) {
	  	var response = transport.responseText;
		if(response == "pass"){
			$('old_form').style.display = '';
			$('failed').style.display = 'none';
			$('success').style.display = '';
		}else{
			$('old_form').style.display = 'none';
			$('failed').style.display = '';
			$('success').style.display = 'none';
		}		
		$('loading').style.display = 'none';
	  }
	});
}

function chooseForm(id){
	var layer = document.getElementById(id);
	
	if(id == 'new_form'){
		var other_layer = document.getElementById('old_form');
		other_layer.style.display = "none";
	}else{
		var other_layer = document.getElementById('new_form');
		other_layer.style.display = "none";
	}
	layer.style.display = "";
	
}
