var hairBG = new Image();
hairBG.src = '/en_ca/registration/images/registration_hair_BG.gif';
var eyeBG = new Image();
eyeBG.src = '/en_ca/registration/images/registration_eye_BG.gif';

var warmMatch = new Image();
warmMatch.src = 'images/registration_warmMatch.jpg'
var warmMatch_on = new Image();
warmMatch_on.src = 'images/registration_warmMatch_on.jpg'

var coolMatch = new Image();
coolMatch.src = 'images/registration_coolMatch.jpg'
var coolMatch_on = new Image();
coolMatch_on.src = 'images/registration_coolMatch_on.jpg'

var skinShade = new Array('Very Light1','Very Light2','Very Light3','Very Light4','Light1','Light2','Light3','Light4','Medium1','Medium2','Medium3','Medium4','Deep1','Deep2','Deep3','Deep4');
	
function clearAll(formSection) {
	targetContainer = $(formSection+'Container');
	for(i=0;i<targetContainer.getElementsByTagName('div').length;i++) {
		if (targetContainer.getElementsByTagName('div')[i].className==formSection+'Option') {
			targetContainer.getElementsByTagName('div')[i].style.backgroundImage='';
		}		
	}	
}

function menuSelector(el, value) {
	el.style.backgroundRepeat = 'no-repeat';
	switch(el.className) {
		case 'hairOption':
			clearAll('hair');
			el.style.backgroundImage = 'url('+hairBG.src+')'
			$('regHairColor').value = value;
		break;
		case 'eyeOption':
			clearAll('eye');
			el.style.backgroundImage = 'url('+eyeBG.src+')'
			$('regEyeColor').value = value;
		break;
		default:
			return;
		break;	
	}
}

function colorMatch(el) {
	switch(el.id) {
		case 'coolMatch':
			$('regColorMatch').value='cool';
			$('warmMatch').src = warmMatch.src;
			el.src = coolMatch_on.src;
		break;
		case 'warmMatch':
			$('regColorMatch').value='warm';
			$('coolMatch').src = coolMatch.src;
			el.src = warmMatch_on.src;
		break;
		default:
			return;
		break;
	}
}

function getSkinShade(v) {
	$('regSkinShade').value=skinShade[v];
}

function setSkinShade() {
	if ($F('regSkinShade').length>0) {
		return skinShade.indexOf($F('regSkinShade'))
	} else {
		return skinShade.length/2;
	}
	
}
function formPhone(){
	$('mobilOptinPhone').value = $F('phone1') + '-' + $F('phone2') + '-' + $F('phone3');
	if (trimAll($F('phone1')).length==0 && trimAll($F('phone2')).length==0 && trimAll($F('phone3')).length==0) {$('mobilOptinPhone').value=''}
}

function formBday() {
	$F('bdaymonth').length==1 ? bdayMonth = '0'+$F('bdaymonth') : bdayMonth = $F('bdaymonth') 
	$F('bdayday').length==1 ? bdayDay = '0'+$F('bdayday') : bdayDay = $F('bdayday')
	$('ageMin_13_err').value = bdayMonth+'/'+bdayDay+'/'+$F('bdayyear')
	if (trimAll($F('bdaymonth')).length==0 && trimAll($F('bdayday')).length==0 && trimAll($F('bdayyear')).length==0) {$('ageMin_13_err').value=''}
}

function toggleMobileAlert(el) {
	if (el.checked) {
		$('mobilOptinPhone').value='xxx-xxx-xxxx'
		$('phone1').value='';
		$('phone2').value='';
		$('phone3').value='';
		$('cgAlertContainer').style.display='block';
	} else {
		$('mobilOptinPhone_err').innerHTML = '';
		$('mobilOptinPhone').value='';
		$('cgAlertContainer').style.display='none';
	}
}

function registerPageInit() {
	
	//formPhone();
	//formBday();

	//Initialize Hair Color
	try {
		hairDiv = $F('regHairColor');
		$(hairDiv).style.backgroundRepeat = 'no-repeat'
		$(hairDiv).style.backgroundImage = 'url('+hairBG.src+')';
	} catch(exception) {}		
	//Initialize Eye Color
	try {
		eyeDiv = $F('regEyeColor');
		$(eyeDiv).style.backgroundRepeat = 'no-repeat'
		$(eyeDiv).style.backgroundImage = 'url('+eyeBG.src+')';
	} catch(exception) {}
	//Initialize Skin Tone -- Alreadyinitialized in /registration/index.php
		//regSlider.options.sliderValue = setSkinShade();
		
	//toggleMobileAlert($('toggleMobileBox'))
	//if (!$('toggleMobileBox').checked) $('mobilOptinPhone').value='';
	//Initialize Color Match
	try {
		switch($F('regColorMatch')) {
			case 'cool':
				$('coolMatch').src = coolMatch_on.src
			break;
			case 'warm':
				$('warmMatch').src = warmMatch_on.src
			break;
			default:
				return;
			break;
		}
	} catch(exception) {}	

}

window.onload = registerPageInit;
