/*
		iAmMap object holds the key/value pairs iAm/an Array object holds the list of IWantTo entries.
		Any number of iWanto entries can be added to the object 
*/

var iAmMap =  { 
	
// US Citizen holds an array[list] of I Want To entries.
		
"USCitizen" 	: 	[{ "iWantTo" : "Bring my brother/sister to live in the U.S.", 		
                     	   "url"     : "/greencard/Green-Card-for-Your-Brother-Sister.jsp?r=wheretostart" },  
			
			 { "iWantTo" : "Bring my fiance to the U.S.", 		
                     	   "url"     : "/visas/family/Fiancee-Visa-K1-Visa.jsp?r=wheretostart" },

			 { "iWantTo" : "Bring my son or daughter who is married to live in the U.S.", 		
                     	   "url"     : "/greencard/Green-Card-for-Your-Child.jsp?r=wheretostart" },

			 { "iWantTo" : "Bring my son or daughter who is unmarried and over 21 to live in the U.S", 		
                     	   "url"     : "/greencard/Green-Card-for-Your-Child.jsp?r=wheretostart" },

			 { "iWantTo" : "Bring my spouse (husband or wife), child (unmarried under 21) or parent(s) to live in the U.S.", 		
                     	   "url"     : "/visas/family/K3-Visa-and-V-Visa.jsp?r=wheretostart" },

			 { "iWantTo" : "Get a copy of my naturalization certificate/certificate of citizenship", 		
                     	   "url"     : "/passport/How-to-get-a-US-Passport.jsp?r=wheretostart" },

			 { "iWantTo" : "Get a passport", 		
                     	   "url"     : "/passport/How-to-get-a-US-Passport.jsp?r=wheretostart" },

			 { "iWantTo" : "Get information about requirements for traveling abroad", 		
                     	   "url"     : "/passport/How-to-get-a-US-Passport.jsp?r=wheretostart" },

			 { "iWantTo" : "Help my adopted child become a Permanent Resident", 		
                     	   "url"     : "/greencard/Green-Card-Through-Family-Member.jsp?r=wheretostart" },

			 { "iWantTo" : "Help my child become a U.S. citizen or get proof of U.S. citizenship", 		
                     	   "url"     : "/us-citizenship/Certificate-of-Citizenship-Form-N-600.jsp?r=wheretostart" },

			 { "iWantTo" : "Help my spouse/child get a K-3/K-4 visa to enter the U.S.", 		
                     	   "url"     : "/visas/family/K3-Visa-and-V-Visa.jsp?r=wheretostart" },

			 { "iWantTo" : "Replace a lost, stolen or destroyed naturalization certificate/certificate of citizenship", 		
                     	   "url"     : "/us-citizenship/Naturalization-Certificate-Citizenship-Form-N-565.jsp?r=wheretostart" }],
 	
"Fiance_k1"	:	[{ "iWantTo" : "Adjust my status to become a permanent resident (green card holder)",  
                           "url"     : "/visas/family/Fiancee-Visa-K1-Visa.jsp?r=wheretostart" }],

"PermanentResident_GreencardHolder"  : 

			[{ "iWantTo" : "Become a U.S. Citizen",  
                           "url"     : "/us-citizenship/U-S-Citizenship-application-Form-N-400.jsp?r=wheretostart" },

			 { "iWantTo" : "Bring my son or daughter who is unmarried and over 21 to live in the U.S.",  
                           "url"     : "/greencard/Green-Card-for-Your-Child.jsp?r=wheretostart" },

			 { "iWantTo" : "Bring my spouse (husband or wife) and/or child (unmarried, under 21) to live in the U.S.",  
                           "url"     : "/greencard/Green-Card-Through-Family-Member.jsp?r=wheretostart" },

			 { "iWantTo" : "Correct an error on my permanent resident card (green card)",  
                           "url"     : "/greencard/renewal-green-card-Form-I-90-replace.jsp?r=wheretostart" },

			 { "iWantTo" : "Get a re-entry permit",  
                           "url"     : "/uscis-forms/Form-I-131-Application-Travel-Document.jsp?r=wheretostart" },

			 { "iWantTo" : "Know my rights and responsibilities",  
                           "url"     : "/uscis-forms/Form-I-131-Application-Travel-Document.jsp?r=wheretostart" },

			 { "iWantTo" : "Renew my Permanent Resident Card (green card)",  
                           "url"     : "/greencard/renewal-green-card-Form-I-90-replace.jsp?r=wheretostart" },

			 { "iWantTo" : "Replace my lost/damaged permanent resident card (green card)",  
                           "url"     : "/greencard/renewal-green-card-Form-I-90-replace.jsp?r=wheretostart" }],  

"ConditionalResident" : [{ "iWantTo" : "Correct an error on my permanent resident card (green card)",  
                           "url"     : "/greencard/renewal-green-card-Form-I-90-replace.jsp?r=wheretostart" },

			 { "iWantTo" : "Remove my conditions",  
                           "url"     : "/greencard/Form-I-751-Remove-Conditions-Residence-Greencard.jsp?r=wheretostart" },

			 { "iWantTo" : "Replace my lost/damaged permanent resident card (green card)",  
                           "url"     : "/greencard/renewal-green-card-Form-I-90-replace.jsp?r=wheretostart" }],

"CitizenOfaForeignCountry": [{ "iWantTo" : "Find out about becoming a permanent resident (green card holder) through a family member",  
                               "url"     : "/greencard/Green-Card-Through-Family-Member.jsp?r=wheretostart" },
                              
			{ "iWantTo" : "Find out how to come to the U.S. as a temporary worker",  
                          "url"     : "/visas/work/How-to-get-a-H1B-Visa.jsp?r=wheretostart" },

			{ "iWantTo" : "Find out how to get a student visa",  
                          "url"     : "/visas/student/Student-Tourist-Visas-dvd.jsp?r=wheretostart" },

			{ "iWantTo" : "Find out how to get a tourist/business visa",  
                          "url"     : "/visas/visitor/Get-a-US-Tourist-Business-Visa-Visitors-Visa-B1-B2-Visa.jsp?r=wheretostart" },  

			{ "iWantTo" : "Participate in the diversity lottery",  
                          "url"     : "/greencard/Green-Card-Lottery.jsp?r=wheretostart" }],
  
"Refugee"    	   :   	[{ "iWantTo" : "Get a refugee travel document",  
                           "url"     : "/uscis-forms/Form-I-131-Application-Travel-Document.jsp?r=wheretostart" },

			 { "iWantTo" : "Know if I am authorized to work in the US",  
                           "url"     : "/greencard/Form-I-765-application-for-employment-authorization.jsp?r=wheretostart" }],

"Asylee"    	  :    [{ "iWantTo" : "Get a refugee travel document",  
                          "url"     : "/uscis-forms/Form-I-131-Application-Travel-Document.jsp?r=wheretostart" },
                                    
		        { "iWantTo" : "Know if I am authorized to work in the US",  
                          "url"     : "/greencard/Form-I-765-application-for-employment-authorization.jsp?r=wheretostart" }],
                 				      

"Visitor_Nonimmigrant": [{ "iWantTo" : "Extend my nonimmigrant stay in the U.S.",  
                           "url"     : "/visas/visitor/Form-I539-Change-or-Extend-your-B1-B2-Nonimmigrant-Status.jsp?r=wheretostart" },

			{ "iWantTo" : "Participate in the diversity lottery",  
                          "url"     : "/greencard/Green-Card-Lottery.jsp?r=wheretostart" }],

                                
"Employee"    	     : [{ "iWantTo" : "Know what document serves as proof of employment authorization",  
                          "url"     : "/greencard/Form-I-765-application-for-employment-authorization.jsp?r=wheretostart" }],
                                    
"PersonWithTemporaryProtectedStatus_US" : 

			[{ "iWantTo" : "Apply for employment authorization",  
                           "url"     : "/greencard/Form-I-765-application-for-employment-authorization.jsp?r=wheretostart" }],
                                   
"US_CitizenActiveDutyMilitaryMember_MilitaryFamilyMember" : 

		       [{ "iWantTo" : "Bring my brother/sister to live in the U.S.",  
                          "url"     : "/greencard/Green-Card-for-Your-Brother-Sister.jsp?r=wheretostart" },
                                    
			{ "iWantTo" : "Bring my child son or daughter to live in the U.S.",  
                          "url"     : "/greencard/Green-Card-for-Your-Child.jsp?r=wheretostart" },

			{ "iWantTo" : "Bring my fiance to the U.S.",  
                          "url"     : "/visas/family/Fiancee-Visa-K1-Visa.jsp?r=wheretostart" },

			{ "iWantTo" : "Bring my parent(s) to live in the US",  
                          "url"     : "/greencard/Green-Card-for-Your-Parent.jsp?r=wheretostart" },

			{ "iWantTo" : "Bring my spouse (husband or wife) to live in the U.S.",  
                          "url"     : "/greencard/Green-Card-for-Your-Spouse.jsp?r=wheretostart" },

			{ "iWantTo" : "Find out about posthumous naturalization",  
                          "url"     : "/us-citizenship/U-S-Citizenship-application-Form-N-400.jsp?r=wheretostart" },

			{ "iWantTo" : "Get a passport",  
                          "url"     : "/passport/How-to-get-a-US-Passport.jsp?r=wheretostart" },

			{ "iWantTo" : "Get proof of my U.S. Citizenship",  
                          "url"     : "/us-citizenship/Certificate-of-Citizenship-Form-N-600.jsp?r=wheretostart" },

			{ "iWantTo" : "Help my adopted child become a U.S. Citizen",  
                          "url"     : "/greencard/Green-Card-for-Your-Child.jsp?r=wheretostart" },

			{ "iWantTo" : "Replace a lost, stolen or destroyed naturalization certificate/certificate of citizenship",  
                          "url"     : "/us-citizenship/Naturalization-Certificate-Citizenship-Form-N-565.jsp?r=wheretostart" }],

"ForeignNationalActiveDutyMilitaryMember" :
		
		       [{ "iWantTo" : "Find out about posthumous naturalization",  
                          "url"     : "/us-citizenship/U-S-Citizenship-application-Form-N-400.jsp?r=wheretostart" },
                                    
			{ "iWantTo" : "Find out about wartime naturalization",  
                          "url"     : "/us-citizenship/U-S-Citizenship-application-Form-N-400.jsp?r=wheretostart" }],
			
"ForeignNationalMilitaryFamilyMember" :

			[{ "iWantTo" : "Find out about becoming a permanent resident (green card holder) through a family member",  
                           "url"     : "/greencard/Green-Card-Through-Family-Member.jsp?r=wheretostart" }],

"ActiveDutyMilitary_FamilyMemberWithPermanentResidentCard" : 

			[{ "iWantTo" : "Become a U.S. Citizen",  
                           "url"     : "/us-citizenship/U-S-Citizenship-application-Form-N-400.jsp?r=wheretostart" },
		
			{ "iWantTo" : "Bring my child son or daughter to live in the U.S.",  
                          "url"     : "/greencard/Green-Card-Through-Family-Member.jsp?r=wheretostart" },
			{ "iWantTo" : "Bring my spouse (husband or wife) to live in the U.S.",  
                          "url"     : "/greencard/Green-Card-for-Your-Spouse.jsp?r=wheretostart" },

			{ "iWantTo" : "Correct an error on my permanent resident card (green card)",  
                          "url"     : "/greencard/renewal-green-card-Form-I-90-replace.jsp?r=wheretostart" },
			
			{ "iWantTo" : "Find out about posthumous naturalization",  
                          "url"     : "/us-citizenship/U-S-Citizenship-application-Form-N-400.jsp?r=wheretostart" },

			{ "iWantTo" : "Renew my permanent resident card (green card)",  
                          "url"     : "/greencard/renewal-green-card-Form-I-90-replace.jsp?r=wheretostart" },

			{ "iWantTo" : "Replace my lost/damaged permanent resident card (green card)",  
                          "url"     : "/greencard/renewal-green-card-Form-I-90-replace.jsp?r=wheretostart" }],
						                           				     
"ConditionalResidentActiveDutyMilitaryMember": 

			[{ "iWantTo" : "Correct an error on my permanent resident card (green card)",  
                          "url"     : "/greencard/renewal-green-card-Form-I-90-replace.jsp?r=wheretostart" },

			{ "iWantTo" : "Remove my conditions",
			  "url"	    : "/greencard/Form-I-751-Remove-Conditions-Residence-Greencard.jsp?r=wheretostart" },

			{ "iWantTo" : "Replace my lost/damaged permanent resident card (green card)",
			  "url"	    : "/greencard/renewal-green-card-Form-I-90-replace.jsp?r=wheretostart" }]
}

var iWanToSize = 0;	// used for refreshing the iWantTo list
var noSelected = 0;	// for providing default select box functionality
var defaultText = "Select One";		// default select box text
var defaultFrmAction = "none";		// initial form action value before selecting iWantTo

// Shows the iAm List
function showIAmList(){	
	noSelected = noSelected + 1;
	if(document.getElementById('iWantToList') != null || document.getElementById('iWantToList') != undefined){
		if(document.getElementById('iWantToList').style.display == "block"){
			hideTheBlock(document.getElementById('iWantToList'));
		}
	}
	if(noSelected == 1){
		showTheBlock(document.getElementById('iAmList'));
		hideTheBlock(document.getElementById('iWantToBlk'));
		document.getElementById('iAm').style.borderBottom = "solid #fff 2px";
		document.getElementById('iAmList').style.marginTop = '-3px'

	}else{
		showTheBlock(document.getElementById('iWantToBlk'));
		hideTheBlock(document.getElementById('iAmList'));
		noSelected = 0;
	}
}

//gets iWantTo list according to user selection
function getIWantToList(SEL_iAmObj){
	var SELECTED_iAmObj = document.getElementById(SEL_iAmObj);
	noSelected = 0;
	refreshIWanToList();
	refreshErrorMsg();
	var iAmObj = document.getElementById('iAm');
	var iAm = SELECTED_iAmObj.innerHTML;	
	iAm = wrapText(iAm);
	iAmObj.innerHTML = iAm;
	iAm_Current = iAm;
	for(var i = 0; i < iAmMap[SELECTED_iAmObj.id].length; i++){
		var nextIwantTo = iAmMap[SELECTED_iAmObj.id][i].iWantTo;
		var nextURL = iAmMap[SELECTED_iAmObj.id][i].url;
		appendIWantToValues(nextIwantTo, nextURL, "list"+i);
		iWanToSize++;
	}	
	hideTheBlock(document.getElementById('iAmList'));
	showTheBlock(document.getElementById('iWantToBlk'));
}

// appends all the iWantTo values to the Select Box
function appendIWantToValues(iWantTo, url, uniqListId){
		
	var iWantToULObj = document.getElementById('selected-menu');
	// if List contains more than five elements apply scroll
	if(parseInt(uniqListId.substring(4,5)) >=5)
	{
		iWantToULObj.setAttribute("class","second-menu-scroll") || iWantToULObj.setAttribute("className","second-menu-scroll");
	}
	// append div Tag
	var dynaDIV = document.createElement("div");
	dynaDIV.id = uniqListId;
	dynaDIV.setAttribute("class","second-menu-list") || dynaDIV.setAttribute("className","second-menu-list");
	dynaDIV.onmouseover = function(){dynaDIV.style.background="#EBEBEB";}
	dynaDIV.onmouseout = function(){dynaDIV.style.background="";}
	iWantToULObj.appendChild(dynaDIV);
   	// append UL Tag
   	var dynaUL = document.createElement("ul");
	dynaDIV.appendChild(dynaUL);
    	// append LI Tag
    	var dynaLI = document.createElement("li");   	 
    	dynaUL.appendChild(dynaLI); 
	// append A Tag
	var hrefObj = document.createElement("a");
	hrefObj.href = "javascript:getIWantToURL('"+iWantTo+"','"+url+"')";
	hrefObj.innerHTML = iWantTo;
 	dynaLI.appendChild(hrefObj);
}

// refreshes previously displayed iWantTo List
function refreshIWanToList(){
	var iWantToListObj = document.getElementById('selected-menu');
	if(iWanToSize > 0){
		for(var i = 0; i < iWanToSize; i++){
			var childTag = document.getElementById('list'+i);
			iWantToListObj.removeChild(childTag);
		}
	}
	iWantToListObj.setAttribute("class","") || iWantToListObj.setAttribute("className","");
	iWanToSize = 0;
	defaultFrmAction = "none";
	document.getElementById('iWantTo').innerHTML = defaultText;
}

// displays the iWantTo List
function showIWantToList(){	
	noSelected = noSelected + 1;
	if(noSelected == 1){
		showTheBlock(document.getElementById('iWantToList'));
		document.getElementById('iWantTo').style.borderBottom = "solid #fff 2px";
		document.getElementById('iWantToList').style.marginTop = '-3px';		
	}else{
		hideTheBlock(document.getElementById('iWantToList'));
		noSelected = 0;
	}
}

//sets the URL for selected iWantTo and sets the selected text into iWantTo
function getIWantToURL(SELECTED_iWantTo, selUrl){
	noSelected = 0;
	var iWantToObj = document.getElementById('iWantTo');
	iWantToObj.innerHTML = wrapText(SELECTED_iWantTo);
	iWantTo_Current = SELECTED_iWantTo;
	hideTheBlock(document.getElementById('iWantToList'));
	defaultFrmAction = selUrl;
	
}

// If select One is selected form action is cleared
function selOne(){
	document.getElementById('iWantTo').innerHTML = defaultText;
	hideTheBlock(document.getElementById('iWantToList'));
	defaultFrmAction = "none";
	noSelected = 0;
}

// Redirects page to the corresponding URL
function goToPage(){

	refreshErrorMsg();
	// creates form element with the selected URL as action
	if(defaultFrmAction != "none")
	{		
		var where_To_Div = document.getElementById('where-to-start');
		var where_To_form = document.createElement("form");
		where_To_form.id = "where_To_form";
		where_To_form.action = defaultFrmAction;
		where_To_form.method = "post";
		where_To_Div.appendChild(where_To_form);
		where_To_form.submit();
	}else{	
		// Error Message block if select box is not selected	
		var Where_To_Begin_Txt = document.getElementById('Where_To_Begin_Txt');
		var dynaP = document.createElement("p");
		dynaP.id = "ErrorMsg";
		dynaP.setAttribute("class","page-errors") || dynaP.setAttribute("className","page-errors");
		dynaP.innerHTML = "Please select your option to proceed";
    		Where_To_Begin_Txt.appendChild(dynaP);
	}
}

// refreshes the error message and form element
function refreshErrorMsg(){
	if(document.getElementById('ErrorMsg') != null || document.getElementById('ErrorMsg') != undefined){
		var Where_To_Begin_Txt = document.getElementById('Where_To_Begin_Txt');
		Where_To_Begin_Txt.removeChild(document.getElementById('ErrorMsg'));
	}
	if(document.getElementById('where_To_form') != null || document.getElementById('where_To_form') != undefined){
		var where_To_Div = document.getElementById('where-to-start');
		where_To_Div.removeChild(document.getElementById('where_To_form'));
	}
}
// common functionalities

function wrapText(text){
	// Wrap the selected text if the size exceeds the option box
	if(text.length > 25){
		text = text.substring(0,23)+"..";
	}
	return text;
}

function showTheBlock(htmlObj){
	htmlObj.style.display = 'block';
}

function hideTheBlock(htmlObj){
	htmlObj.style.display = 'none';
}

// Event Driven functionalities
// closing dropdown by click out of it
// Register event 'click' and associated call back.

  
function respondToClick(event) { 
  var a = Event.element(event);
  if(a != '' || a != null || a != undefined){
	if(a.id != ''){
		if(a.id == 'iAmBlock' || a.id == 'iAmList' || a.id == 'iAm' || a.id == 'iWantToBlk' || a.id == 'iWantTo' || a.id == 'iWantToList'){
			return false;
		}
	}
  }
	noSelected = 0;
	hideTheBlock(document.getElementById('iAmList'));
	hideTheBlock(document.getElementById('iWantToList'));
	showTheBlock(document.getElementById('iWantToBlk'));
}

Event.observe(document, 'click', respondToClick);







