var quiz_question_block_find_product_image_used=false;

function check_penis_quiz_questions_filled(array_max_id) //uses global "penis_quiz" array
{
	for(var i=0;i<array_max_id;i++)
	{
		if(penis_quiz[i]==null) return false;
	}
	
	return true;
}

function get_penis_quiz_questions_last_displayed_id(quiz_id_string,quiz_from,quiz_to)
{
	for(var i=quiz_from;i<=quiz_to;i++)
	{
		if(document.getElementById(quiz_id_string+'_'+i).style.display=='none')	return i-1;
	}
	
	return quiz_to;
}

function display_penis_quiz_buttons(quiz_id_string,quiz_from,quiz_to)
{
	last_id=get_penis_quiz_questions_last_displayed_id(quiz_id_string,quiz_from,quiz_to);
	if(last_id==quiz_to)
	{
		if(document.getElementById('quiz_question_block_next_image').style.opacity==1)
				document.getElementById('quiz_question_block_next_image').style.opacity=0.4;
		if(document.getElementById('quiz_question_block_find_product_image').style.opacity!=1)
		{
			if(quiz_question_block_find_product_image_used==false && check_penis_quiz_questions_filled(parseInt(quiz_to)))
			{
				quiz_question_block_find_product_image_used=true;
				document.getElementById('quiz_question_block_find_product_image').style.opacity=1;
			}
		}
	}	
}


function display_penis_quiz_questions(quiz_id_string,quiz_from,quiz_to)
{
	for(var i=quiz_from;i<=quiz_to;i++)
	{
		if(document.getElementById(quiz_id_string+'_'+i).style.display=='none')
			document.getElementById(quiz_id_string+'_'+i).style.display='block';
	}	
}

function display_penis_quiz_buttons_next(quiz_id_string,quiz_from,quiz_to)
{
	var temp_i=parseInt(get_penis_quiz_questions_last_displayed_id(quiz_id_string,quiz_from,quiz_to));
	if(temp_i==quiz_to)
	{
		display_penis_quiz_buttons(quiz_id_string,quiz_to,quiz_to);
	}
	else
	{
		display_penis_quiz_questions(quiz_id_string,temp_i+1,temp_i+1);
	}
}

function get_penis_quiz_enlargement_method_message(id)
{
	switch(id)
	{
		case 10:
			return '<h5 class="penis_quiz">Penis quiz result: '+'<a href="http://www.Penis-Enlargement-Natural.com/Penis-Pills">Penis Pills</a></h5>';
			break
		case 11:
			return '<h5 class="penis_quiz">Penis quiz result: '+'<a href="http://www.Penis-Enlargement-Natural.com/Penis-Patches">Penis Patches</a></h5>';
			break;
		case 12:
			return '<h5 class="penis_quiz">Penis quiz result: '+'<a href="http://www.Penis-Enlargement-Natural.com/Penis-Exercises">Penis Exercises</a></h5>';
			break;
		case 13:
			return '<h5 class="penis_quiz">Penis quiz result: '+'<a href="http://www.Penis-Enlargement-Natural.com/Penis-Extenders">Penis Extenders</a></h5>';
			break;
		case -1:
			return '&ldquo;Natural Enlargement Solutions might not be the appropriate solution for you now. Consult our sections and then try once again to see which natural enlargement solutions fits your requirements best.&rdquo;';
			break;
		default:
			return '';
			break;
	}
}

function penis_quiz_enlargement_method_show_category_products(category_number)
{
	document.getElementById('penis_quiz_enlargement_method_message_id').innerHTML=get_penis_quiz_enlargement_method_message(category_number);
	
	/* ajax - load relevant category products */
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
		xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
				document.getElementById('penis_quiz_enlargement_method_category_products').innerHTML=xmlhttp.responseText;
			}
		}
	xmlhttp.open('GET','/ajax/penis_quiz_products.php'+'?category_number='+category_number,true);
	xmlhttp.send();
	/* /ajax - load relevant category products */
}

function get_penis_quiz_enlargement_method(penis_quiz,display_products)
{
    if(penis_quiz==null) return -1;
    
    var suffix='';
    suffix+='?penis_quiz0=';
    if(penis_quiz[0]==false) suffix+='0';
    else suffix+='1';
    suffix+='&penis_quiz1=';
    if(penis_quiz[1]==false) suffix+='0';
    else suffix+='1';
    suffix+='&penis_quiz2=';
    if(penis_quiz[2]==false) suffix+='0';
    else suffix+='1';
    suffix+='&penis_quiz3=';
    if(penis_quiz[3]==false) suffix+='0';
    else suffix+='1';
    suffix+='&penis_quiz4=';
    if(penis_quiz[4]==false) suffix+='0';
    else suffix+='1';
    
    /* ajax - get penis enlargement method */
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			var category_number=parseInt(xmlhttp.responseText);
			
			if(display_products)
			{
				penis_quiz_enlargement_method_show_category_products(category_number);				
			}
			return category_number;
			
		}
	}

    xmlhttp.open('GET','/ajax/penis_quiz_result.php'+suffix,true);
    xmlhttp.send();
    /* /ajax - get penis enlargement method */

    return -1;
}

function penis_quiz_enlargement_method_find_product(quiz_to)
{
	if(document.getElementById('quiz_question_block_find_product_image').style.opacity!=1) return false;
	if(check_penis_quiz_questions_filled(parseInt(quiz_to)))
		document.getElementById('quiz_question_block_find_product_image').style.opacity=0.4;
	get_penis_quiz_enlargement_method(penis_quiz,true);
}
