// aNobii landing javascript

function stepNav(targetStep)
{
    if(targetStep=='step1')
        {
            document.getElementById('step1').className = 'active';
			document.getElementById('step2').className = '';
			document.getElementById('step3').className = '';
			document.getElementById('step4').className = '';
        }
    if(targetStep=='step2')
        {
            document.getElementById('step1').className = '';
			document.getElementById('step2').className = 'active';
			document.getElementById('step3').className = '';
			document.getElementById('step4').className = '';
        }
    if(targetStep=='step3')
        {
            document.getElementById('step1').className = '';
			document.getElementById('step2').className = '';
			document.getElementById('step3').className = 'active';
			document.getElementById('step4').className = '';
        }
    if(targetStep=='step4')
        {
            document.getElementById('step1').className = '';
			document.getElementById('step2').className = '';
			document.getElementById('step3').className = '';
			document.getElementById('step4').className = 'active';
        }
}

////////////////////////////////////////////////////////////////////////////////
function openwin (url, width, height, scrollbar, resizable) 
// open pop up window
{
	window.open(url, 'newwindow', 'width = '+width+', height = '+height+', resizable = '+resizable+', scrollbars='+scrollbar+', toolbar=no, menubar=no, location=no, status=no');

	return;
} // openwin

////////////////////////////////////////////////////////////////////////////////
function change_id (input_id, value_1, value_2)
// change particular HTML ID
{
	var input = document.getElementById(input_id);
	
	if (!value_2) {
		if (input) {
			input.className = value_1;
		} 
	} else {
		if (input.className == value_1) {
			input.className = value_2;
		} else {
			input.className = value_1;
		}
	}
	
  	return;
} // change_id

////////////////////////////////////////////////////////////////////////////////
function change_html_value (target_id, val)
// change the HTML value
{
	var target = document.getElementById(target_id);
	
	if (target) {
		target.innerHTML = val;
	} 
	
  	return;
} // change_html_value

////////////////////////////////////////////////////////////////////////////////
function trim (s)
// remove leading and trainling withespace from a string 
{
	while (s.substring(0, 1) == ' ') {
    	s = s.substring(1, s.length);
  	}
  	
  	while (s.substring(s.length - 1, s.length) == ' ') {
    	s = s.substring(0, s.length - 1);
  	}
  	
  	return s;
} // trim

////////////////////////////////////////////////////////////////////////////////
function change_value (text_id, val)
// change the text value
{
	var text = document.getElementById(text_id);
	
	if (text) {
		text.value = val;
	} 
	
  	return;
} // change_value

////////////////////////////////////////////////////////////////////////////////
function clear_form_value (box) 
// clear form value (only the default one) when mouse click
{
	if (box.value == box.defaultValue) {
	 	box.value = '';
	}
	
	return;
} // clear_form_value

////////////////////////////////////////////////////////////////////////////////
function select_highlight (target_id, highlight_id, class_name, class_id) 
// give yellow background for selected check box / radio button
{
	var target    = document.getElementById(target_id);
	var highlight = document.getElementById(highlight_id);
	
	if (target.checked == true) {
		highlight.className = class_name;
		
		change_value(class_id, class_name);
	} else {
		highlight.className = '';
		
		change_value(class_id, '');
	}
	
	return;
} // select_highlight

////////////////////////////////////////////////////////////////////////////////
function person_language_check (total_lang, total_prod) 
// disable button if error occur
{
	var sub   = document.getElementById('submit_language');
	var total_check_lang = 0;
	var total_check_prod = 0;
	
	for (var i = 1; i <= total_lang; i++) {
		 var lang = document.getElementById('person_language_'+i);
         
		 if (lang) {
		 	if (lang.checked == true) {
		 	 	total_check_lang++;
		 	}
		 }
	}
	
	for (var j = 1; j <= total_prod + 2; j++) {
		 var prod = document.getElementById('product_type_'+j);
         
		 if (prod) {
		 	if (prod.checked == true) {
		 		 total_check_prod++;
		 	}	
		 }
	}

	if (total_check_lang == 0 || total_check_prod == 0) {
		sub.disabled = true;
	} else {
		sub.disabled = false;
	}
	
	return;
} // person_language_check

////////////////////////////////////////////////////////////////////////////////
function form_input_check_signin (input_id, error_id, error_message) 
// form value check
{
	var error = 0;
	
	var input = document.getElementById(input_id);

	if (input) {
		if (trim(input.value) == '' || input.value == '') {
			error = 1;
	
			change_id(input_id, 'alert');
			change_id(error_id, '');
			change_html_value(error_id, error_message);
		} else {
			change_id(input_id, '');
			change_id(error_id, 'hidden');
			change_html_value(error_id, '');
		}
	}
	
	return error;
} // form_input_check_signin

////////////////////////////////////////////////////////////////////////////////
function form_input_check_signup (input_id, error_id, error_message) 
// form value check
{
	var error = 0;
	
	var input = document.getElementById(input_id);

	if (input) {
		if (trim(input.value) == '' || input.value == '') {
			error = 1;
	
			change_id(input_id, 'alert');
			change_id(error_id, 'alert');
			change_html_value(error_id, error_message);
		} else {
			change_id(input_id, '');
			change_id(error_id, 'hidden');
			change_html_value(error_id, '');
		}
	}
	
	return error;
} // form_input_check_signup

//Preload mouseover image
function preload_image()
{
var image_file = new Array('http://static.anobii.com/anobi/live/image/landing/tab01.jpg',
'http://static.anobii.com/anobi/live/image/landing/tab02_active.jpg',
'http://static.anobii.com/anobi/live/image/landing/tab03_active.jpg',
'http://static.anobii.com/anobi/live/image/landing/tab04_active.jpg',
'http://static.anobii.com/anobi/live/image/landing/btn_signup_over.png',
'http://static.anobii.com/anobi/live/image/landing/btn_taketour_over.png',
'http://static.anobii.com/anobi/live/image/landing/btn_sellbook_over.jpg');

// start preloading
var img = new Array();

for (i = 0; i <= image_file.length; i++) {
img[i] = new Image();
img[i].src = image_file[i];
}

return;
} // preload_image
