﻿function disableOption(select1, select2)
{
    var selIndex1 = document.getElementById(select1).selectedIndex;
    
    for (var i=0; i<document.getElementById(select1).options.length; i++ )
    {
        //enable all
        document.getElementById(select2).options[i].disabled=false;
    }
    //disable it!
    if (select1 == 'source')
        document.getElementById(select2).options[selIndex1].disabled=true;

    
    // if languages are the same, change one of them!
    if (selIndex1 == document.getElementById(select2).selectedIndex)
    {
        if (selIndex1 == 0)
            document.getElementById(select2).options[selIndex1+1].selected=true
        else
            document.getElementById(select2).options[selIndex1-1].selected=true;
    }
}

function setFormValues()
{
    document.getElementById('questionaire_source').value = document.getElementById('source').options[document.getElementById('source').selectedIndex].value;
    document.getElementById('questionaire_target').value = document.getElementById('target-lang').options[document.getElementById('target-lang').selectedIndex].value;
    document.getElementById('questionaire_phrase').value = document.getElementById('autocomplete').value;
    //alert('gdfg');
    //return false;
}

function showQuestionaire() {
    if (readCookie('info_sent') == 1)
        return true;
    else
    {
		if (navigator.appVersion.indexOf("MSIE")!=-1){
			document.getElementById('source').style.display = 'none';
			document.getElementById('target-lang').style.display = 'none';
			document.getElementById('lang').style.display = 'none';
		}

		
        //document.getElementById('result').style.display = 'block';
        document.getElementById('overlay').style.display = 'block';
        document.getElementById('loader').style.display = 'block';
        new Ajax.Updater('result', '/vocabulary/questionaire', {onComplete:function(){ document.getElementById('result').style.display = 'block';}}, {asynchronous:true});
        return false;
    }
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}