/************************************************************* * demographics.js * * Sets up the demographics form and performs the necessary * checks before the subject is allowed to move on. * * Last Modified : July 25, 2013 by Jonathan Taratuta-Titus * * * Author: Yuechen Zhao, Jun Sup Lee, Norman Zhu, * adapted from a version created by Nancy Chen * * © Copyright 2014 LabintheWild * For questions about this file and permission to use * the code, contact us at info@labinthewild.org *************************************************************/ var countries = { ' ': ' ', 'Afghanistan': 'Afghanistan', 'Aland Islands': 'Aland Islands', 'Albania': 'Albania', 'Algeria': 'Algeria', 'American Samoa': 'American Samoa', 'Andorra': 'Andorra', 'Angola': 'Angola', 'Anguilla': 'Anguilla', 'Antarctica': 'Antarctica', 'Antigua And Barbuda': 'Antigua And Barbuda', 'Argentina': 'Argentina', 'Armenia': 'Armenia', 'Aruba': 'Aruba', 'Australia': 'Australia', 'Austria': 'Austria', 'Azerbaijan': 'Azerbaijan', 'Bahamas': 'Bahamas', 'Bahrain': 'Bahrain', 'Bangladesh': 'Bangladesh', 'Barbados': 'Barbados', 'Belarus': 'Belarus', 'Belgium': 'Belgium', 'Belize': 'Belize', 'Benin': 'Benin', 'Bermuda': 'Bermuda', 'Bhutan': 'Bhutan', 'Bolivia': 'Bolivia', 'Bosnia And Herzegovina': 'Bosnia And Herzegovina', 'Botswana': 'Botswana', 'Bouvet Island': 'Bouvet Island', 'Brazil': 'Brazil', 'British Indian Ocean Territory': 'British Indian Ocean Territory', 'Brunei Darussalam': 'Brunei Darussalam', 'Bulgaria': 'Bulgaria', 'Burkina Faso': 'Burkina Faso', 'Burundi': 'Burundi', 'Cambodia': 'Cambodia', 'Cameroon': 'Cameroon', 'Canada': 'Canada', 'Cape Verde': 'Cape Verde', 'Cayman Islands': 'Cayman Islands', 'Central African Republic': 'Central African Republic', 'Chad': 'Chad', 'Chile': 'Chile', 'China': 'China', 'Christmas Island': 'Christmas Island', 'Cocos (Keeling) Islands': 'Cocos (Keeling) Islands', 'Colombia': 'Colombia', 'Comoros': 'Comoros', 'Congo': 'Congo', 'The Democratic Republic Of The Congo': 'The Democratic Republic Of The Congo', 'Cook Islands': 'Cook Islands', 'Costa Rica': 'Costa Rica', 'Cote Divoire': 'Cote Divoire', 'Croatia': 'Croatia', 'Cuba': 'Cuba', 'Cyprus': 'Cyprus', 'Czech Republic': 'Czech Republic', 'Denmark': 'Denmark', 'Djibouti': 'Djibouti', 'Dominica': 'Dominica', 'Dominican Republic': 'Dominican Republic', 'Ecuador': 'Ecuador', 'Egypt': 'Egypt', 'El Salvador': 'El Salvador', 'Equatorial Guinea': 'Equatorial Guinea', 'Eritrea': 'Eritrea', 'Estonia': 'Estonia', 'Ethiopia': 'Ethiopia', 'Falkland Islands (Malvinas)': 'Falkland Islands (Malvinas)', 'Faroe Islands': 'Faroe Islands', 'Fiji': 'Fiji', 'Finland': 'Finland', 'France': 'France', 'French Guiana': 'French Guiana', 'French Polynesia': 'French Polynesia', 'French Southern Territories': 'French Southern Territories', 'Gabon': 'Gabon', 'Gambia': 'Gambia', 'Georgia': 'Georgia', 'Germany': 'Germany', 'Ghana': 'Ghana', 'Gibraltar': 'Gibraltar', 'Greece': 'Greece', 'Greenland': 'Greenland', 'Grenada': 'Grenada', 'Guadeloupe': 'Guadeloupe', 'Guam': 'Guam', 'Guatemala': 'Guatemala', 'Guernsey': 'Guernsey', 'Guinea': 'Guinea', 'Guinea-bissau': 'Guinea-bissau', 'Guyana': 'Guyana', 'Haiti': 'Haiti', 'Heard Island And Mcdonald Islands': 'Heard Island And Mcdonald Islands', 'Holy See (Vatican City State)': 'Holy See (Vatican City State)', 'Honduras': 'Honduras', 'Hong Kong': 'Hong Kong', 'Hungary': 'Hungary', 'Iceland': 'Iceland', 'India': 'India', 'Indonesia': 'Indonesia', 'Iran': 'Iran', 'Iraq': 'Iraq', 'Ireland': 'Ireland', 'Isle Of Man': 'Isle Of Man', 'Israel': 'Israel', 'Italy': 'Italy', 'Jamaica': 'Jamaica', 'Japan': 'Japan', 'Jersey': 'Jersey', 'Jordan': 'Jordan', 'Kazakhstan': 'Kazakhstan', 'Kenya': 'Kenya', 'Kiribati': 'Kiribati', 'Democratic Peoples Republic of Korea': 'Democratic Peoples Republic of Korea', 'Republic of Korea': 'Republic of Korea', 'Kuwait': 'Kuwait', 'Kyrgyzstan': 'Kyrgyzstan', 'Lao Peoples Democratic Republic': 'Lao Peoples Democratic Republic', 'Latvia': 'Latvia', 'Lebanon': 'Lebanon', 'Lesotho': 'Lesotho', 'Liberia': 'Liberia', 'Libyan Arab Jamahiriya': 'Libyan Arab Jamahiriya', 'Liechtenstein': 'Liechtenstein', 'Lithuania': 'Lithuania', 'Luxembourg': 'Luxembourg', 'Macao': 'Macao', 'Macedonia': 'Macedonia', 'Madagascar': 'Madagascar', 'Malawi': 'Malawi', 'Malaysia': 'Malaysia', 'Maldives': 'Maldives', 'Mali': 'Mali', 'Malta': 'Malta', 'Marshall Islands': 'Marshall Islands', 'Martinique': 'Martinique', 'Mauritania': 'Mauritania', 'Mauritius': 'Mauritius', 'Mayotte': 'Mayotte', 'Mexico': 'Mexico', 'Micronesia': 'Micronesia', 'Republic of Moldova': 'Republic of Moldova', 'Monaco': 'Monaco', 'Mongolia': 'Mongolia', 'Montenegro': 'Montenegro', 'Montserrat': 'Montserrat', 'Morocco': 'Morocco', 'Mozambique': 'Mozambique', 'Myanmar': 'Myanmar', 'Namibia': 'Namibia', 'Nauru': 'Nauru', 'Nepal': 'Nepal', 'Netherlands': 'Netherlands', 'New Caledonia': 'New Caledonia', 'New Zealand': 'New Zealand', 'Nicaragua': 'Nicaragua', 'Niger': 'Niger', 'Nigeria': 'Nigeria', 'Niue': 'Niue', 'Norfolk Island': 'Norfolk Island', 'Northern Mariana Islands': 'Northern Mariana Islands', 'Norway': 'Norway', 'Oman': 'Oman', 'Pakistan': 'Pakistan', 'Palau': 'Palau', 'Palestinian Territory': 'Palestinian Territory', 'Panama': 'Panama', 'Papua New Guinea': 'Papua New Guinea', 'Paraguay': 'Paraguay', 'Peru': 'Peru', 'Philippines': 'Philippines', 'Pitcairn': 'Pitcairn', 'Poland': 'Poland', 'Portugal': 'Portugal', 'Puerto Rico': 'Puerto Rico', 'Qatar': 'Qatar', 'Reunion': 'Reunion', 'Romania': 'Romania', 'Russian Federation': 'Russian Federation', 'Rwanda': 'Rwanda', 'Saint Helena': 'Saint Helena', 'Saint Kitts And Nevis': 'Saint Kitts And Nevis', 'Saint Lucia': 'Saint Lucia', 'Saint Pierre And Miquelon': 'Saint Pierre And Miquelon', 'Saint Vincent And The Grenadines': 'Saint Vincent And The Grenadines', 'Samoa': 'Samoa', 'San Marino': 'San Marino', 'Sao Tome And Principe': 'Sao Tome And Principe', 'Saudi Arabia': 'Saudi Arabia', 'Senegal': 'Senegal', 'Serbia': 'Serbia', 'Seychelles': 'Seychelles', 'Sierra Leone': 'Sierra Leone', 'Singapore': 'Singapore', 'Slovakia': 'Slovakia', 'Slovenia': 'Slovenia', 'Solomon Islands': 'Solomon Islands', 'Somalia': 'Somalia', 'South Africa': 'South Africa', 'South Georgia And The South Sandwich Islands': 'South Georgia And The South Sandwich Islands', 'Spain': 'Spain', 'Sri Lanka': 'Sri Lanka', 'Sudan': 'Sudan', 'Suriname': 'Suriname', 'Svalbard And Jan Mayen': 'Svalbard And Jan Mayen', 'Swaziland': 'Swaziland', 'Sweden': 'Sweden', 'Switzerland': 'Switzerland', 'Syrian Arab Republic': 'Syrian Arab Republic', 'Taiwan': 'Taiwan', 'Tajikistan': 'Tajikistan', 'Tanzania': 'Tanzania', 'Thailand': 'Thailand', 'Timor-leste': 'Timor-leste', 'Togo': 'Togo', 'Tokelau': 'Tokelau', 'Tonga': 'Tonga', 'Trinidad And Tobago': 'Trinidad And Tobago', 'Tunisia': 'Tunisia', 'Turkey': 'Turkey', 'Turkmenistan': 'Turkmenistan', 'Turks And Caicos Islands': 'Turks And Caicos Islands', 'Tuvalu': 'Tuvalu', 'Uganda': 'Uganda', 'Ukraine': 'Ukraine', 'United Arab Emirates': 'United Arab Emirates', 'United Kingdom': 'United Kingdom', 'United States': 'United States', 'United States Minor Outlying Islands': 'United States Minor Outlying Islands', 'Uruguay': 'Uruguay', 'Uzbekistan': 'Uzbekistan', 'Vanuatu': 'Vanuatu', 'Venezuela': 'Venezuela', 'Viet Nam': 'Viet Nam', 'British Virgin Islands': 'British Virgin Islands', 'U.S. Virgin Islands': 'U.S. Virgin Islands', 'Wallis And Futuna': 'Wallis And Futuna', 'Western Sahara': 'Western Sahara', 'Yemen': 'Yemen', 'Zambia': 'Zambia', 'Zimbabwe': 'Zimbabwe'}; // to input data from cookies function inputFromCookie() { // setting the value from cookies as default var defLength = def.length; for(var i = 0; i < defLength; i++) { var temp = readCookie(def[i]); // console.log("cookie value = " + temp); if (temp!= null && temp!= " " && temp!= "") { // console.log("entered condition to call select element function"); selectElement(def[i], temp); } } } // to pre-select the elements in the form function selectElement(elementName, valueToSelect) { // console.log("element name = " + elementName); var element = document.getElementsByName(elementName); if(element[0].name == "retake" || element[0].name == "gender" || element[0].name == "multinational" || element[0].name == "normalvision") element[0][parseInt(valueToSelect) + 1].selected = true; else if(element[0].name == "age") { element[0][parseInt(valueToSelect) - 5].selected = true; } else if(element[0].name == "country0" || element[0].name == "country1" || element[0].name == "country" || element[0].name == "home" || element[0].name == "current" || element[0].name == "father" || element[0].name == "mother") element[0][findIndex(countries_en, valueToSelect)].selected = true; else if(element[0].name == "education") element[0][findIndex(education_en, valueToSelect)].selected = true; else if(element[0].name == "lang0" || element[0].name == "lang1") element[0][findIndex(languages_en, valueToSelect)].selected = true; /* The language menu doesn't work for cookies because of translation and key-value issues as mentioned in research notes */ else if(element[0].name == "fluency1") element[0][findIndex(fluency, valueToSelect)].selected = true; else if(element[0].name == "years0" || element[0].name == "years1" || element[0].name == "years" || element[0].name == "homeyears" || element[0].name == "currentyears") { if (parseFloat(valueToSelect) == 0.5) element[0][1].selected = true; else element[0][parseInt(valueToSelect) + 1].selected = true; } else {} } // find index of country in associative array, can change function parameters to take in any array if needed function findIndex(data, content) { var index = 0; for(var key in data) { if(data[key] == content) return index; index++; } } // function to create a cookie function createCookie(name,value,days) { if (days) { var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); var expires = "; expires="+date.toGMTString(); } else var expires = ""; document.cookie = "LITW" + name+"="+value+expires+"; path=/"; } // function to read a cookie function readCookie(name) { var nameEQ = "LITW" + 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; } // function to erase a cookie function eraseCookie(name) { createCookie("LITW" + name,"",-1); } var countries_en = { ' ': ' ', 'Afghanistan': 'Afghanistan', 'Aland Islands': 'Aland Islands', 'Albania': 'Albania', 'Algeria': 'Algeria', 'American Samoa': 'American Samoa', 'Andorra': 'Andorra', 'Angola': 'Angola', 'Anguilla': 'Anguilla', 'Antarctica': 'Antarctica', 'Antigua And Barbuda': 'Antigua And Barbuda', 'Argentina': 'Argentina', 'Armenia': 'Armenia', 'Aruba': 'Aruba', 'Australia': 'Australia', 'Austria': 'Austria', 'Azerbaijan': 'Azerbaijan', 'Bahamas': 'Bahamas', 'Bahrain': 'Bahrain', 'Bangladesh': 'Bangladesh', 'Barbados': 'Barbados', 'Belarus': 'Belarus', 'Belgium': 'Belgium', 'Belize': 'Belize', 'Benin': 'Benin', 'Bermuda': 'Bermuda', 'Bhutan': 'Bhutan', 'Bolivia': 'Bolivia', 'Bosnia And Herzegovina': 'Bosnia And Herzegovina', 'Botswana': 'Botswana', 'Bouvet Island': 'Bouvet Island', 'Brazil': 'Brazil', 'British Indian Ocean Territory': 'British Indian Ocean Territory', 'Brunei Darussalam': 'Brunei Darussalam', 'Bulgaria': 'Bulgaria', 'Burkina Faso': 'Burkina Faso', 'Burundi': 'Burundi', 'Cambodia': 'Cambodia', 'Cameroon': 'Cameroon', 'Canada': 'Canada', 'Cape Verde': 'Cape Verde', 'Cayman Islands': 'Cayman Islands', 'Central African Republic': 'Central African Republic', 'Chad': 'Chad', 'Chile': 'Chile', 'China': 'China', 'Christmas Island': 'Christmas Island', 'Cocos (Keeling) Islands': 'Cocos (Keeling) Islands', 'Colombia': 'Colombia', 'Comoros': 'Comoros', 'Congo': 'Congo', 'The Democratic Republic Of The Congo': 'The Democratic Republic Of The Congo', 'Cook Islands': 'Cook Islands', 'Costa Rica': 'Costa Rica', 'Cote Divoire': 'Cote Divoire', 'Croatia': 'Croatia', 'Cuba': 'Cuba', 'Cyprus': 'Cyprus', 'Czech Republic': 'Czech Republic', 'Denmark': 'Denmark', 'Djibouti': 'Djibouti', 'Dominica': 'Dominica', 'Dominican Republic': 'Dominican Republic', 'Ecuador': 'Ecuador', 'Egypt': 'Egypt', 'El Salvador': 'El Salvador', 'Equatorial Guinea': 'Equatorial Guinea', 'Eritrea': 'Eritrea', 'Estonia': 'Estonia', 'Ethiopia': 'Ethiopia', 'Falkland Islands (Malvinas)': 'Falkland Islands (Malvinas)', 'Faroe Islands': 'Faroe Islands', 'Fiji': 'Fiji', 'Finland': 'Finland', 'France': 'France', 'French Guiana': 'French Guiana', 'French Polynesia': 'French Polynesia', 'French Southern Territories': 'French Southern Territories', 'Gabon': 'Gabon', 'Gambia': 'Gambia', 'Georgia': 'Georgia', 'Germany': 'Germany', 'Ghana': 'Ghana', 'Gibraltar': 'Gibraltar', 'Greece': 'Greece', 'Greenland': 'Greenland', 'Grenada': 'Grenada', 'Guadeloupe': 'Guadeloupe', 'Guam': 'Guam', 'Guatemala': 'Guatemala', 'Guernsey': 'Guernsey', 'Guinea': 'Guinea', 'Guinea-bissau': 'Guinea-bissau', 'Guyana': 'Guyana', 'Haiti': 'Haiti', 'Heard Island And Mcdonald Islands': 'Heard Island And Mcdonald Islands', 'Holy See (Vatican City State)': 'Holy See (Vatican City State)', 'Honduras': 'Honduras', 'Hong Kong': 'Hong Kong', 'Hungary': 'Hungary', 'Iceland': 'Iceland', 'India': 'India', 'Indonesia': 'Indonesia', 'Iran': 'Iran', 'Iraq': 'Iraq', 'Ireland': 'Ireland', 'Isle Of Man': 'Isle Of Man', 'Israel': 'Israel', 'Italy': 'Italy', 'Jamaica': 'Jamaica', 'Japan': 'Japan', 'Jersey': 'Jersey', 'Jordan': 'Jordan', 'Kazakhstan': 'Kazakhstan', 'Kenya': 'Kenya', 'Kiribati': 'Kiribati', 'Democratic Peoples Republic of Korea': 'Democratic Peoples Republic of Korea', 'Republic of Korea': 'Republic of Korea', 'Kuwait': 'Kuwait', 'Kyrgyzstan': 'Kyrgyzstan', 'Lao Peoples Democratic Republic': 'Lao Peoples Democratic Republic', 'Latvia': 'Latvia', 'Lebanon': 'Lebanon', 'Lesotho': 'Lesotho', 'Liberia': 'Liberia', 'Libyan Arab Jamahiriya': 'Libyan Arab Jamahiriya', 'Liechtenstein': 'Liechtenstein', 'Lithuania': 'Lithuania', 'Luxembourg': 'Luxembourg', 'Macao': 'Macao', 'Macedonia': 'Macedonia', 'Madagascar': 'Madagascar', 'Malawi': 'Malawi', 'Malaysia': 'Malaysia', 'Maldives': 'Maldives', 'Mali': 'Mali', 'Malta': 'Malta', 'Marshall Islands': 'Marshall Islands', 'Martinique': 'Martinique', 'Mauritania': 'Mauritania', 'Mauritius': 'Mauritius', 'Mayotte': 'Mayotte', 'Mexico': 'Mexico', 'Micronesia': 'Micronesia', 'Republic of Moldova': 'Republic of Moldova', 'Monaco': 'Monaco', 'Mongolia': 'Mongolia', 'Montenegro': 'Montenegro', 'Montserrat': 'Montserrat', 'Morocco': 'Morocco', 'Mozambique': 'Mozambique', 'Myanmar': 'Myanmar', 'Namibia': 'Namibia', 'Nauru': 'Nauru', 'Nepal': 'Nepal', 'Netherlands': 'Netherlands', 'Netherlands Antilles': 'Netherlands Antilles', 'New Caledonia': 'New Caledonia', 'New Zealand': 'New Zealand', 'Nicaragua': 'Nicaragua', 'Niger': 'Niger', 'Nigeria': 'Nigeria', 'Niue': 'Niue', 'Norfolk Island': 'Norfolk Island', 'Northern Mariana Islands': 'Northern Mariana Islands', 'Norway': 'Norway', 'Oman': 'Oman', 'Pakistan': 'Pakistan', 'Palau': 'Palau', 'Palestinian Territory': 'Palestinian Territory', 'Panama': 'Panama', 'Papua New Guinea': 'Papua New Guinea', 'Paraguay': 'Paraguay', 'Peru': 'Peru', 'Philippines': 'Philippines', 'Pitcairn': 'Pitcairn', 'Poland': 'Poland', 'Portugal': 'Portugal', 'Puerto Rico': 'Puerto Rico', 'Qatar': 'Qatar', 'Reunion': 'Reunion', 'Romania': 'Romania', 'Russian Federation': 'Russian Federation', 'Rwanda': 'Rwanda', 'Saint Helena': 'Saint Helena', 'Saint Kitts And Nevis': 'Saint Kitts And Nevis', 'Saint Lucia': 'Saint Lucia', 'Saint Pierre And Miquelon': 'Saint Pierre And Miquelon', 'Saint Vincent And The Grenadines': 'Saint Vincent And The Grenadines', 'Samoa': 'Samoa', 'San Marino': 'San Marino', 'Sao Tome And Principe': 'Sao Tome And Principe', 'Saudi Arabia': 'Saudi Arabia', 'Senegal': 'Senegal', 'Serbia': 'Serbia', 'Seychelles': 'Seychelles', 'Sierra Leone': 'Sierra Leone', 'Singapore': 'Singapore', 'Slovakia': 'Slovakia', 'Slovenia': 'Slovenia', 'Solomon Islands': 'Solomon Islands', 'Somalia': 'Somalia', 'South Africa': 'South Africa', 'South Georgia And The South Sandwich Islands': 'South Georgia And The South Sandwich Islands', 'Spain': 'Spain', 'Sri Lanka': 'Sri Lanka', 'Sudan': 'Sudan', 'Suriname': 'Suriname', 'Svalbard And Jan Mayen': 'Svalbard And Jan Mayen', 'Swaziland': 'Swaziland', 'Sweden': 'Sweden', 'Switzerland': 'Switzerland', 'Syrian Arab Republic': 'Syrian Arab Republic', 'Taiwan': 'Taiwan', 'Tajikistan': 'Tajikistan', 'Tanzania': 'Tanzania', 'Thailand': 'Thailand', 'Timor-leste': 'Timor-leste', 'Togo': 'Togo', 'Tokelau': 'Tokelau', 'Tonga': 'Tonga', 'Trinidad And Tobago': 'Trinidad And Tobago', 'Tunisia': 'Tunisia', 'Turkey': 'Turkey', 'Turkmenistan': 'Turkmenistan', 'Turks And Caicos Islands': 'Turks And Caicos Islands', 'Tuvalu': 'Tuvalu', 'Uganda': 'Uganda', 'Ukraine': 'Ukraine', 'United Arab Emirates': 'United Arab Emirates', 'United Kingdom': 'United Kingdom', 'United States': 'United States', 'United States Minor Outlying Islands': 'United States Minor Outlying Islands', 'Uruguay': 'Uruguay', 'Uzbekistan': 'Uzbekistan', 'Vanuatu': 'Vanuatu', 'Venezuela': 'Venezuela', 'Viet Nam': 'Viet Nam', 'British Virgin Islands': 'British Virgin Islands', 'U.S. Virgin Islands': 'U.S. Virgin Islands', 'Wallis And Futuna': 'Wallis And Futuna', 'Western Sahara': 'Western Sahara', 'Yemen': 'Yemen', 'Zambia': 'Zambia', 'Zimbabwe': 'Zimbabwe' }; var languages_en = { ' ' : ' ', 'Persian': 'Persian', 'Indonesian': 'Indonesian', 'Catalan': 'Catalan', 'Czech': 'Czech', 'Danish': 'Danish', 'German': 'German', 'English': 'English', 'Spanish': 'Spanish', 'French': 'French', 'Croatian': 'Croatian', 'Italian': 'Italian', 'Lithuanian': 'Lithuanian', 'Hungarian': 'Hungarian', 'Dutch': 'Dutch', 'Norwegian': 'Norwegian', 'Polish': 'Polish', 'Portuguese': 'Portuguese', 'Romanian': 'Romaniam', 'Slovak': 'Slovak', 'Slovenian': 'Slovenian', 'Finnish': 'Finnish', 'Swedish': 'Swedish', 'Vietnamese': 'Vietnamese', 'Turkish': 'Turkish', 'Greek': 'Greek', 'Bulgarian': 'Bulgarian', 'Russian': 'Russian', 'Serbian': 'Serbian', 'Ukrainian': 'Ukranian', 'Hebrew': 'Hebrew', 'Arabic': 'Arabic', 'Standard Hindi': 'Standard Hindi', 'Thai': 'Thai', 'Korean': 'Korean', 'Chinese': 'Chinese', 'Japanese': 'Japanese', 'Other': 'Other'}; var havent_en = { ' ' : ' ', 'have not' : 'have not', 'have' : 'have'}; var urban_en = { ' ' : ' ', 'urban' : 'urban', 'suburban' : 'suburban', 'rural' : 'rural'}; var profession_en = { ' ' : ' ', 'Administrative' : 'Administrative', 'Medical' : 'Medical', 'Artist/Creative/Performer' : 'Artist/Creative/Performer', 'Sales/Marketing' : 'Sales/Marketing', 'Executive Management' : 'Executive Management', 'Education' : 'Education', 'Banking/Financial' : 'Banking/Financial', 'Computers/Technology' : 'Computers/Technology', 'Travel/Hospitality' : 'Travel/Hospitality', 'Legal' : 'Legal', 'Self-Employed' : 'Self-Employed', 'Architect' : 'Architect', 'Craftsman/Construction' : 'Craftsman/Construction', 'Engineer' : 'Engineer', 'Professional Trade' : 'Professional Trade', 'Homemaker' : 'Homemaker', 'Food Services' : 'Food Services', 'Military/Government/Politics' : 'Military/Government/Politics', 'Real Estate' : 'Real Estate', 'Research' : 'Research', 'Retail' : 'Retail', 'Retired' : 'Retired', 'Student' : 'Student', 'Unemployed' : 'Unemployed', 'Other' : 'Other'}; var fluency_en = { ' ' : ' ', 'fluently' : 'fluently', 'very well' : 'very well', 'well' : 'well', 'at beginner\'s level' : 'at beginner\'s level'}; var education_en = { ' ' : ' ', 'pre-high school' : 'pre-high school', 'high school' : 'high school', 'college' : 'college', 'graduate school' : 'graduate school', 'professional school' : 'professional school', 'PhD' : 'PhD', 'postdoctoral' : 'postdoctoral'}; var gender_en = { ' ' : ' ', 'male' : 'male', 'female' : 'female', 'N/A' : 'N/A' }; /* dictionary and arrays so that additional fields for countries lived in * can be added and cleared with the same code */ var multikey = {'country':0,'lang':1,'years':0,'fluency':1}; var multi1 = ['country', 'lang']; var multi2 = ['years', 'fluency']; // options and counters var def = ["retake","gender","age","handedness","multinational","country0","years0","lang0",/*"urban","web_usage","profession",*/"father","mother","education","normalvision"]; var noyes = { ' ':' ', 'No' : 'No', 'Yes' : 'Yes' }; var numctries = 0; //http://en.wikipedia.org/wiki/Global_Internet_usage#Languages_used_on_the_Internet var languages = { ' ' : ' ', 'Persian': ' فارسی', 'Indonesian': 'Bahasa Indonesia', 'Catalan': 'Català', 'Czech': 'Čeština', 'Danish': 'Dansk', 'German': 'Deutsch', 'English': 'English', 'Spanish': 'Español', 'French': 'Français', 'Croatian': 'Hrvatski', 'Italian': 'Italiano', 'Lithuanian': 'Lietuvių', 'Hungarian': 'Magyar', 'Dutch': 'Nederlands', 'Norwegian': 'Norsk', 'Polish': 'Polski', 'Portuguese': 'Português', 'Romanian': 'Română', 'Slovak': 'Slovenčina', 'Slovenian': 'Slovenščina', 'Finnish': 'Suomi', 'Swedish': 'Svensk', 'Vietnamese': 'Tiếng Việt', 'Turkish': 'Türkçe', 'Greek': 'Ελληνικά', 'Bulgarian': 'български език', 'Russian': 'Русский', 'Serbian': 'Српски', 'Ukrainian': 'Українська', 'Hebrew': 'עברית', 'Arabic': 'اللغة العربية', 'Standard Hindi': 'हिन्दी', 'Thai': 'ภาษาไทย', 'Korean': '한국어', 'Chinese': '中文', 'Japanese': '日本語', 'Other': 'Other'}; var numlangs = 0; var havent = {' ':' ','have not' : 'have not', 'have' : 'have'};var years = [' ',0.5]; var web_usage = [' ',"< 1",1,2,3,4,5,6,7,8,9,"10+"]; var urban = {' ':' ','urban' : 'urban','suburban' : 'suburban','rural' : 'rural'}; var handedness = { ' ' : ' ','right' : 'right hand', 'left' : 'left hand', 'both' : 'both hands'}; var age = [' ']; var profession = {' ' : ' ','Administrative' : 'Administrative', 'Architect' : 'Architect', 'Artist/Creative/Performer' : 'Artist/Creative/Performer', 'Banking/Financial' : 'Banking/Financial', 'Computers/Technology' : 'Computers/Technology', 'Craftsman/Construction' : 'Craftsman/Construction', 'Education' : 'Education', 'Engineer' : 'Engineer', 'Executive Management' : 'Executive Management', 'Food Services' : 'Food Services', 'Homemaker' : 'Homemaker', 'Legal' : 'Legal', 'Medical' : 'Medical', 'Military/Government/Politics' : 'Military/Government/Politics', 'Professional Trade' : 'Professional Trade', 'Real Estate' : 'Real Estate', 'Research' : 'Research', 'Retail' : 'Retail', 'Retired' : 'Retired', 'Sales/Marketing' : 'Sales/Marketing', 'Self-Employed' : 'Self-Employed', 'Student' : 'Student', 'Travel/Hospitality' : 'Travel/Hospitality', 'Unemployed' : 'Unemployed', 'Other' : 'Other'}; var fluency = { ' ' : ' ','fluently' : 'fluently', 'very well' : 'very well', 'well' : 'well', 'at beginner\'s level' : 'at beginner\'s level'}; var education = {' ' : ' ','pre-high school' : 'pre-high school','high school' : 'high school','college' : 'college','graduate school' : 'graduate school','professional school' : 'professional school','PhD' : 'PhD','postdoctoral' : 'postdoctoral'}; var gender = {' ' : ' ', 'male' : 'male', 'female' : 'female', 'N/A' : 'N/A'}; for(var i = 6;i<100;i++){ age.push(i); } for(var i=1; i<100; i++){ years.push(i); } /* the questions in order * Each question dictionary contains first part of sentence (header), end of sentence (footer) * and options in dropdown box (options) */ var questions = new Array(); questions['retake'] = {'q':'Have you taken this test before?','options':noyes, 'translated' : true}; questions['gender'] = {'q':'What is your gender?'}; questions['gender']['options'] = gender; questions['gender']['translated'] = true; // ************************************************************************ questions['age'] = {'q':'How old are you?','options':age, 'translated' : false}; // ************************************************************************ questions['handedness'] = {'q':'Which hand do you use to write?', 'translated' : true}; questions['handedness']['options'] = handedness; // ************************************************************************ questions['education'] = {'q':'What is the highest level of education you have received or are pursuing?', 'translated' : true}; questions['education']['options'] = education; // ************************************************************************ questions['multinational'] = {'q':'Have you lived in more than one country?','options':noyes, "translated" : true}; questions['home'] = {'q':'Which was the first country where you lived?','options':countries, 'translated' : true}; questions['homeyears'] = {'q':'How many years did you live there?','options':years, 'translated' : false}; questions['country1'] = {'q':'' + 'Please add countries in order from the country you were born in to the most recent.' + '

' + 'First Country','options':countries, 'translated' : true}; questions['years1'] = {'q':' ' + 'Year(s):','options':years, 'translated' : false}; questions['country'] = {'q':'Next country:','options':countries, 'translated' : true}; questions['years'] = {'q':' ' + 'Year(s):','options':years, 'translated' : false}; questions['current'] = {'q':'Current country:','options':countries, 'translated' : true}; questions['currentyears'] = {'q':' ' + 'Current Years:','options':years, 'translated' : false}; // ************************************************************************ // questions['urban']= {'q':'Currently, I live in a mostly', 'options':urban, 'translated' : true}; // ************************************************************************ questions['lang0'] = {'q':'What is your native language?','options':languages, 'translated' : true}; questions['lang'] = {'q':'Language:','options':languages, 'translated' : true}; questions['fluency'] = {'q':' ' + 'Fluency:', 'translated' : true}; questions['fluency']['options'] = fluency; questions['father'] = {'q':'What is your father\'s nationality?','options':countries, 'translated' : true}; questions['mother'] = {'q':'What is your mother\'s nationality?','options':countries, 'translated' : true}; // ************************************************************************ // questions['web_usage']= {'q':'On a normal day, I am on the Internet for approximately this many hours:','options':web_usage, 'translated' : true}; // ************************************************************************ // questions['profession']= {'q':'My profession is','options':profession, 'translated' : true}; // ************************************************************************ questions['normalvision'] = {'q':'Do you have normal or corrected-to-normal vision (including normal color vision)?','options':noyes, 'translated' : true}; function whyDemo() { alert('We need this information for data analysis. Please note that none of the answers are personally identifiable. Lab in the Wild takes your privacy very seriously. You may email us at info@labinthewild.org for more information.'); } /* called in studyinfo(), display of demographics form */ function demographics() { // begin form var html = "

" + 'Please tell us a little bit about yourself.' + "" + 'Why?' + "

" + '

These questions are optional, but if you could answer at least the first four, that would really help us.

'; // fill in all the questions for (title in questions) { // do not include question in "have" case of living in multiple countries or for additional language fields multinational = title == "country1" || title == "years1" || title == "country" || title == "years" || title == "current" || title == "currentyears"; multilingual = title == "lang" || title == "fluency"; if (!multinational && !multilingual) { /* add a div tag surrounding history of countries lived in */ if (title == "home") { html += "
"; } // add full question html += dropdown(title); // place "Add Languages" button if (title == 'lang0') { html += " " + '[Add Another Language]' + ""; } // do not put a new line if question has multiple parts // var multiquestion = title == 'home'|| title=="gender"; /* if (!multiquestion) { */ html += "

"; //} // add a div tag surrounding languages if (title == "lang0") { html += "
"; // add div tag for each additional language for (var i = 1; i < 7; i++) { html += ""; } html += "" html += "
"; html += "
"; } /* close div tag */ if (title == "homeyears") { html += "
" } } } // end form html += "
"; html += "
" + 'I am on a personal computer.' + "" + 'Why?' + "
"; setHTML("demographics", html); document.getElementById('whyCookie').onclick = function() {alert('If you are on a personal computer, we will store your demographics information on your local machine. This will allow you to skip the demographics form on any other Lab in the Wild tests that you might take. If you\'d prefer not to have a saved copy, simply leave the box unchecked.')}; document.getElementById('addlang').onclick = addlang; inputFromCookie(); } // add question and dropdown boxes for additional languages function addlang() { if (numlangs == 0) { numlangs++; var html = dropdown('lang', numlangs)+dropdown('fluency', numlangs); setHTML('delete_lang', '[Delete]' + "

"); setHTML('lang'+numlangs, html); } else if (numlangs < 6) { numlangs++; var html = "

"+dropdown('lang', numlangs)+dropdown('fluency', numlangs); setHTML('lang'+numlangs, html); } else { setHTML('lang7',""); setHTML('addlang',""); } } function rmvlang() { setHTML('lang'+numlangs,""); setHTML('lang7',""); setHTML('addlang',"" + '[Add Another Language]' + ""); numlangs--; if (numlangs==0){ setHTML('delete_lang',""); } } // add question and dropdown boxes for additional countries function addctry() { if (numctries == 1) { // BUG FIXED on 7/29/13 by WSX (dropdown('country') -> dropdown('country', numctries)) numctries++; var html = dropdown('country',numctries)+dropdown('years',numctries); setHTML('delete_ctry', '[Delete]' + "

"); setHTML('country'+numctries, html); } else if (numctries < 5) { numctries++; var html = "

"+dropdown('country',numctries)+dropdown('years',numctries); setHTML('country'+numctries, html); } else { setHTML('country6',""); setHTML('addctry',""); } } function rmvctry(){ setHTML('country'+numctries,""); setHTML('addctry',"" + '[Add Another Country]' + ""); numctries--; if (numctries==1){ setHTML('delete_ctry',""); } } // switch from one country lived in to multiple countries lived in function history(input) { var html; // "yes" case if (input == 1) { numctries = 1; // "grew up in" html = dropdown('country1')+dropdown('years1'); html += " " + '[Add Another Country]' + "

"; // add div fields for each additonal country for (var i = 1; i <= 6; i++) { html += ""; } html += "" html += dropdown('current')+dropdown('currentyears')+"

"; } // "no" case else if (input == 0) { numctries = 0; html = dropdown('home')+ "

" + dropdown('homeyears')+"

"; } setHTML('history',html); if (input == 1) { document.getElementById('addctry').onclick = addctry; } } // set second field to blank if first field is blank function blank(number, type) { index = document.demo[multi1[type]+number].options.selectedIndex; selected = document.demo[multi1[type]+number].options[index].value; if (selected == 0) { document.demo[multi2[type]+number].options.selectedIndex = 0; } } // clear both fields of question if "clear" button pressed function clrentries(number, type) { document.demo[multi1[type]+number].options.selectedIndex = 0; document.demo[multi2[type]+number].options.selectedIndex = 0; } // fill in field if (num) { html += select(title, num); } else { html += select(title); } // "; } /* function option(str) { value = str; // switch names to values for certain cases switch(str) { case 'have not': case 'male': //case ' ': value = 0; break; case 'have': case 'female': case 'at beginner\'s level': value = 1; break; case 'N/A': case 'well': value = 2; break; case 'very well': value = 3; break; case 'fluently': value = 4; break; } return ""; } */ function submit() { var response = document.demo.elements; var data = {}; // var def = ["retake","gender","age","multinational","country0","years0","lang0",/*"urban","web_usage","profession",*/"father","mother","education","normalvision"]; var def = ["retake"]; // wsx 7/22/13 - auto put in retake, otherwise, submit // kzg: undid that; we do not want to flag retake unless we have evidence that it's true; // taking out the validation loop because we do not use it for anything //for (var i = 0; i < def.length; i++) { // if (document.demo[def[i]].options.selectedIndex == 0) { //alert("Please fill in blank fields before continuing"); //$("#demo").find("[name='retake']").val(1); // } //} $$$("ajax_working").style.display = 'block'; $$$("ajax_working").style.top = '-85px'; $$$("demographics").style.opacity = '0.3'; $$$("next_button").style.opacity = '0.3'; disableKeyboard(); var data = {}; for (var i = 0; i < response.length; i++) { // creates a key-value pair to record in the data array data[response[i].name] = response[i].value; // creates a cookie with the same pair for future use if($("#cookies").is(":checked")) { createCookie(response[i].name, response[i].value, 1); } } data.numlangs = numlangs; data.numctries = numctries; var ua = new UAParser(); data.ua = { browser : ua.getBrowser().name + " " + ua.getBrowser().version, major : ua.getBrowser().major, os : ua.getOS().name + " " + ua.getOS().version, device : ua.getDevice().type + " " + ua.getDevice().vendor, }; console.log(data); data.locale = litw_locale; $.ajax({ type: 'POST', url: 'includes/demographics.php', data: data }).done(function(r) { // outputs a whitespace because of UTF-8 encoding for demographics.php r = $.trim(r); if ((typeof r) == "string" && r.slice(0,6) == "Failed") { showFailPage(); } else { try { console.log(" id "+r.substring(r.length-5,r.length)); //Yan change this echo value, it was Number(r) before which isn't working globals.participant_id = r.substring(r.length-5,r.length); console.log(globals) setTimeout(init, 1000); } catch (e) { console.log(e); showFailPage(); } } }); }