/*
	ISSUES:
	1) for third world countries (thirdVSD) - we've got the following algorythm:
		*) hide express for SE90 and ME
		*) for those standard services that are left
		    for SE90/ME
		        full processing time = consular processing time
		        mouseover "assumes you provide your own VSD"
		    for other services
		        full processing time = full std. processing time (as these nationals will still need VSD)
		        normal mouseover

*/

var tbodys = new Array();

//these global vars are falsy by default - set later in redrawTable based on the current citizenship selection 
var ukVSD = false;
var thirdVSD = false;  
var notallowedVSD = false;  

//global list of tables (except for Transit)
var tables = ["tableTourist","tableBusiness","tableBusinessDE","tableBusinessME"];

//global vars for the services which need to get hidden for certain nationalities groups
//OUTDATED -  SEE THE hideServices function
//var hideServicesNoVSD = ["TS","SE"];
//var hideServicesOwnVSD = ["TS","TD","SE","SE90","DE","ME"];
//var hideServicesOwnVSDRisky = ["SE90","ME"];
//var processingNoVSD = '5 days';
//var processingNeedVSD = '11 days';

var changestyle = function(){ this.className=(this.className=="")?"hovered":""; }

//*******************************************************************************
/**
 *  This function is called when onclick event occurs on the table caption
 *
*/
var showtable = function(){
 
    //take the actual table
    var tbl = this.parentNode;

    //determine the current nationality
    var nationalitySelect = document.getElementById('nationalitySelect');
   
    //get DE and ME business tables
    var tableBusinessDE = document.getElementById('tableBusinessDE'),
		tableBusinessME = document.getElementById('tableBusinessME');
    
    //if there's at least one tbody in the current table, then we need to hide and remove both business tables
    if(tbl.getElementsByTagName("TBODY").length>0){

		//if we're in the business table at the moment, hide DE and ME business tables 
		if(tbl.id=='tableBusiness') tableBusinessDE.style.display = tableBusinessME.style.display = 'none'; 

		//and remove current table from the DOM
        tbl.removeChild(tbodys[tbl.id]);

		//then set bottom border equal to 0 for all the tables
        document.getElementById('tableTourist').style.borderBottom = document.getElementById('tableBusiness').style.borderBottom = 0;
        tableBusinessDE.style.borderBottom = tableBusinessME.style.borderBottom = 0;
    }    

    //otherwise, we need to show both business tables and restore current table
    else {
        if(tbl.id=='tableBusiness'){
           tableBusinessDE.style.display = '';
           tableBusinessME.style.display = '';
        }
        tbl.appendChild(tbodys[tbl.id]);
    }

	//and then we redraw the tables 
    redrawTable();   
    return false;
}



//this method adds required number of calendar days to the date
Date.prototype.addDays = function(total) {
	//create new date object of the same date as current
	var newDate = new Date(this.getTime());

	//just add the days there
	newDate.setDate(this.getDate() + total);

	//copy actualDays and totalDays properties there
	//newDate.actualDays = this.actualDays + total;
	//newDate.totalDays = this.totalDays + total;

	return newDate;
};

//this method adds required number of working days to the date, skipping sat/sun
Date.prototype.addWorkingDays = function(total) {

	//create new date object of the same date
	var copiedDate = new Date(this.getTime());

	//add day by day skipping saturdays and sundays as they don't count towards the processing
	while(total != 0){

		//if it's saturday, add 2 days
		if(copiedDate.getDay() == 6) copiedDate.setDate(copiedDate.getDate() + 2);

		//if it's sunday, add 1 day
		if(copiedDate.getDay() == 0) copiedDate.setDate(copiedDate.getDate() + 1);
		
		//if it's wed, add 1 day
		//if(copiedDate.getDay()==3) copiedDate.setDate(copiedDate.getDate() + 1);

		//decrement number of days
		total -= 1;

		copiedDate.setDate(copiedDate.getDate() + 1);
	}

	if(copiedDate.getDay() == 6) copiedDate.setDate(copiedDate.getDate() + 2);
	if(copiedDate.getDay() == 0) copiedDate.setDate(copiedDate.getDate() + 1);
	//if(copiedDate.getDay() == 3) copiedDate.setDate(copiedDate.getDate() + 1);

	return copiedDate;
  
};

//short method to check if it's wednesday
Date.prototype.isWed = function(){ return 3 == this.getDay(); };


/**
 *  This function is used to determine which processing time is required for current nationality, visa service and visa type
 *
 *	@returns Object {text, actualDays, tableDays}
 *   @actualDays is the amount of days will be taken to process the visa
 *	 @tableDays is what we display in the table (working days, excluding weds, not counting next day service start etc)
 *
*/
var getProcessingTime = function(service,visaType){ 

    //debugger;

    //if country is in notAllowedVSD or in the third world countries lists, they have to provide their own vsds
    var ownvsd = notallowedVSD || (thirdVSD && in_array(visaType, ['SE90', 'ME90', 'ME180', 'ME365']));

    var result_date = new Date();

    var processingDays = 0;

//	debug.add('<b>working on ' +service+ ' service and '+ visaType+'</b><table><tbody>');

//	debug.add('<tr><td>1. original date</td><td>' + result_date);

    //added one working day (skipping sat/sun)
    result_date = result_date.addWorkingDays(1);

//	debug.add('</td></tr><tr><td>2. we start processing on next working day only</td><td>' + result_date);

    //bool var indicating if that's a standard service (used later)
    var isStd = 'st' == service.toLowerCase();  

    //VSD is not needed for TS30, SE30 and Transit visas for noVSDCountries 
    var isShort = ukVSD && in_array(visaType, ['TS30', 'TD60', 'SE30', 'XS']) || (visaType=='XS');

    //if client orders VSD with us
    if(!ownvsd && !isShort) {

       //we can't lodge STANDARD visa to MID on wednesdays 
       if (isStd && result_date.isWed()) result_date = result_date.addDays(1);

//		debug.add('</td></tr><tr><td>3. skipped wed if needed</td><td>' + result_date);

       //wait 4 or 2 days for MID to prepare telex
       result_date = result_date.addWorkingDays(isStd ? 4 : 2); //4 for std and 2 for expr

		processingDays += isStd? 4 : 2; //add processing days

//		debug.add('</td></tr><tr><td>4. waited ' + (isStd?4:2) + ' working days for MID to do telex</td><td>' + result_date);

       //wait for two days for telex to arrive to the consulate 
       result_date = result_date.addWorkingDays(2);

		processingDays += 2;

//		debug.add('</td></tr><tr><td>5. waited for two working days for telex to arrive</td><td>' + result_date);


		//add another day as Sally says we need to lodge next day only
		result_date = result_date.addWorkingDays(1);

//		debug.add('</td></tr><tr><td>6 waited another day before lodging</td><td>' + result_date);


       //we can't lodge to the consulate on Wednesday, so need to wait another day if it's wednesday
       if (result_date.isWed()) result_date = result_date.addDays(1);

//		debug.add('</td></tr><tr><td>7. skipped wed if needed</td><td>' + result_date);

       //then it takes 4 days to process the documents at the consulate
       result_date = result_date.addWorkingDays(4);

		processingDays += 5;

//		debug.add('</td></tr><tr><td>8. waited 4 working days at the cons</td><td>' + result_date);

    }

    //if he's got his own VSD or doesn't need VSD
    else {

       //we can't lodge to the consulate on Wednesdays
       if (result_date.isWed()) result_date = result_date.addDays(1);

//		debug.add('</td></tr><tr><td>3. skipped wed if needed</td><td>' + result_date);

       //then takes 4 days to process the documents at the consulate
       result_date = result_date.addWorkingDays(4);

		processingDays += 4;

//		debug.add('</td></tr><tr><td>4. waited 4 working days at the cons</td><td>' + result_date);

    }


	//skip Wednesday as we can't collect from the consulate on Wednesdays
    if (result_date.isWed()) result_date = result_date.addDays(1);
//	debug.add('</td></tr><tr><td>(collection) skipped wed if needed</td><td>' + result_date);
  


//	debug.add('</td></tr></tbody></table>');

//	debug.show();

//ADD think we'd need Oman to stay on the notAllowed list for ones that aren't SE 30d tourist/business and DE 60d and aren't own VSD
//will that work?
    
    var res = "If ordered today, this visa should be ready on or before <br><strong>" +formatDate(result_date)+ "</strong>";
    if(ownvsd && visaType!="XS")
        res+=".<br><br>The price and processing time assume that you provide your <strong>own</strong> visa support documents.";

    return { text: res
			,actualDays: Math.round(Math.abs(result_date.getTime() - new Date().getTime())/86400000)
			,tableDays: processingDays};

};


//*******************************************************************************
/**
 *  This function recalculates the prices based on the allPrices.js 
 *
*/
var recalcPrice = function(nationality) {

	//NOTE: this functions loops can be optimised (e.g. all links within the tables could be taken to avoid costly getElementsByTagName

    //take all tables and go through them
    var tables = ["tableTransit","tableTourist","tableBusiness","tableBusinessDE","tableBusinessME"];
    for (var i=0, tds, table, td,th, processingTd, service,visaType,link,totalPrice, tmp; (table=document.getElementById(tables[i])); ++i) {

		//get all the tds
        tds = table.getElementsByTagName('td');

		//go through all the td 
        for(var j=0,a, currentLink, procTime; (td=tds[j]); j++){

			//take the first link in TD 
			currentLink = td.getElementsByTagName('a')[0];

			//if parent td has cost in its className, we 
            if((td.className.indexOf('cost')>-1) && currentLink){

   				//take everything after service  (smth. like TS30-ST)
				link = (currentLink.href).split('service=')[1];

   				//split to get visatype and service
   				tmp = link.split('-');
				visaType = tmp[0];
				service = tmp[1].replace('ST','Standard service').replace('EX','Express service');

   				//get price from the allPrices.js
                                if(in_array(nationality,kazakhCountryList.thirdCountries) && (visaType=="ME180" || visaType=="ME365")){
                                    totalPrice = new allPrices('Kazakh '+'ME90',service,'','','',nationality,'','','');
                                }
                                else {

                                    totalPrice = new allPrices('Kazakh '+visaType,service,'','','',nationality,'','','');
                                }

   				//set the price to a value in the link
				currentLink.firstChild.data = '£'+totalPrice.visaCost.toFixed(2);

   				//set highlight function to hide/show link title in a nice toolbox
				currentLink.onmouseover = currentLink.onmouseout = highlight;

				//get the processing time object based on the current service type and visa type
				var procTime = getProcessingTime(service.substring(0,2),visaType);

   				//get a div handler (it's used as a holder for title data - for the highlight function)
				var oldDiv = td.getElementsByTagName('div')[0];

   				//if there's no such div (i.e. recalcPrice is fired for the first time, we create this div)
				if(!oldDiv) oldDiv = td.appendChild(document.createElement('div'));

   				//when the div is fetched or created, we get processing times text and put into this div (so highlight can show it)
   				oldDiv.innerHTML = procTime.text;

   				//and set its className so it's hidden
   				oldDiv.className = 'titleHolderHidden';

				//we need to get the last TD in the row to set its processing time
				//processingTd = td.parentNode.lastChild;
                                //due to gecko adding textNode in the separate DOM element, use next variant
                                if (table.id=='tableBusinessME'){
                                 processingTD = td.parentNode.cells[4];   
                                }
                                else if (table.id=='tableBusinessDE') {
                                 processingTD = td.parentNode.cells[3];
                                }
                                else {
                                 processingTD = td.parentNode.cells[2];
                                }
                                processingTD.innerHTML = procTime.tableDays + ' days';
                                
                                //processingTd.innerHTML = procTime.tableDays + ' days';
                                

            }//endif

			//add nationality to the link href
            if(currentLink) currentLink.href = currentLink.href.split("&citizenship")[0] + "&citizenship="+nationality;

        }//endfor
     }//endfor
};


//*******************************************************************************
/**
 *  This functon is called when user changes nationality in either first dropdown or the second one
 *
*/
var citizenshipChange = function(){

    //get selected nationality
    var nationality = this.options[this.selectedIndex].text;

    //synchronise with the other dropdown
    document.getElementById((this.id=="nationalitySelect")  ? "nationality" : "nationalitySelect").selectedIndex = this.selectedIndex;

    //if this coutnry's nationals don't need a visa, hide all tables and show information about this
    if(in_array(nationality,kazakhCountryList.notNeeded)){
        hideServices();
        //alert("Passport holders of "+nationality+" do not currently require a visa to travel to Kazakhstan."); 
        }
    
    //get all the tables redrawn (because some services may be hidden for certain nationalities
    redrawTable();

    //and populate purpose of visit and visa types selects 
    populateSelects();
    
};


//********************************************************************************
/**
 *   This function has to work according to the following algorythm:
 *   It's called when user either changes his nationality or collapses/expands one of the tables
 *
 * hideServices is called to hide those services that are not available for the selected nationality
 *    if ukVSD
 *        hide express (TS TD SE30)
 *    if notallowedVSD
 *        hide express (TS TD SE30 SE90 DE ME)
 *    if thirdVSD
 *        hide express (SE90 ME)
 *        for standard services that are left
 *           for SE90/ME
 *               full processing time = consular processing time
 *               mouseover "assumes you provide your own VSD"
 *           for other services
 *               full processing time = full std. processing time (as these nationals will still need VSD)
 *               normal mouseover
 *
*/
var hideServices = function(){
  
	//take all the rows in our tables
	var trs = document.getElementById('tableHolderAdd').getElementsByTagName('tr');

	//remove display none for all the trs
	for(var i=0, tr; (tr=trs[i]); ++i) tr.style.display = '';

	//depending on the VSD mode, decide which services to hide
	var whatToHide = "";	
	var hideCols = "DE90ST,DE90EX,CAPTION90";
        var nationality = document.getElementById('nationality');
        nationality = nationality[nationality.selectedIndex].value;        
	if (ukVSD) {
            whatToHide = "TS,TD,SE30";            
        }
	if (notallowedVSD) {
            whatToHide = "TS,TD,SE30,SE90,DE,ME";
        }
	if (thirdVSD) { 
            whatToHide = "SE90,ME";
        }
        if (nationality=="Malaysia") {
            whatToHide = "TS,TD,SE30,SE90,ME";
        }
        if (nationality=="Saudi Arabia") {
            whatToHide = "TS,TD,SE30,DE,SE90,ME";
        }
        if(nationality=='Chile' || nationality=='Colombia' || nationality=='Cuba'||nationality=='Costa Rica'||nationality=='Ecuador'||nationality=='El Salvador'||nationality=='Nicaragua'||nationality=='Panama'||nationality=='Paraguay'||nationality=='Puerto Rico'){
            whatToHide = "TS,TD,SE30,DE,SE90,ME";
        }        
	whatToHide = whatToHide.split(',');

	//explicitly hide those services that we don't need
	if (1 < whatToHide.length) for (var i=0, elem, tmp; (elem = whatToHide[i]); ++i) {
     tmp = document.getElementById(elem);
     if (tmp) tmp.style.display = 'none';
    }
    
    //hide DE90 Std, Exp for thridCountries (risk countries)
    hideCols = hideCols.split(",");
     for (var i=0, tmp, tbody; i<hideCols.length; i++) {
      tmp = document.getElementById(hideCols[i]);
      tbody = tmp.parentNode.parentNode;
      
      if(tmp && thirdVSD){
       tmp.style.display = 'none';
       tbody.rows[1].cells[0].className = 'service';
       tbody.rows[1].cells[1].className='price';
       tbody.rows[1].cells[3].className='time';
//       tmp.parentNode.childNodes[1].width="32%";                
//       tmp.parentNode.parentNode.childNodes[2].childNodes[0].width="32%";
//       tmp.parentNode.parentNode.parentNode.width="100%";
      }
      else {
       tmp.style.display = '';
       tbody.rows[1].cells[0].className = 'serviceSmall';
       tbody.rows[1].cells[1].className='priceSmall';
       tbody.rows[1].cells[3].className='timeSmall';
//       tmp.parentNode.childNodes[1].width="32%";              
//       tmp.parentNode.parentNode.childNodes[2].childNodes[0].width="";
      }
    }
    
    //hide all tables for countries that don't need visa to kazakhstan
    var nationality = document.getElementById('nationalitySelect').options[document.getElementById('nationalitySelect').selectedIndex].text;    
    var isToHide = false;
    var tablesAll = tables;
    var msgVisaNotNeeded = document.getElementById('msgVisaNotNeeded');
    if(!in_array('tableTransit',tablesAll))
    tablesAll[tables.length] = 'tableTransit';
    
    //If visa don't needed by country then hide all tables. Else show tables.
    isToHide = in_array(nationality,kazakhCountryList.notNeeded);
    
    for(var i=0, tmp; i<tablesAll.length; i++) {
            tmp = document.getElementById(tables[i]);
            if(isToHide){
                tmp.style.display = 'none';                
             }
            else {
            if(tmp.id!='tableBusinessDE' && tmp.id!='tableBusinessME')
                tmp.style.display = 'table';                
             }
        }
        
    if(isToHide) {
        if(nationality=="Armenia")
            msgVisaNotNeeded.innerHTML = "Passport holders of "+nationality+" do not currently require a visa to travel to Kazakhstan for trips of up to 90 days."
        else
            msgVisaNotNeeded.innerHTML = "Passport holders of "+nationality+" do not currently require a visa to travel to Kazakhstan."
        msgVisaNotNeeded.style.display = 'block';
    }
    else {
        msgVisaNotNeeded.style.display = 'none';
    }

};


//*******************************************************************************
/**
 *  This function is called by showTable and citizenshipChange 
 *
 *  It sets ukVSD/notallowedVSD/thirdVSD variables according to the current nationality
 *  and then calls recalcPrice and hideServices
 *
*/
var redrawTable = function(){

	//get current nationality
    var nationalitySelect = document.getElementById('nationalitySelect');
    nationalitySelect = nationalitySelect.options[nationalitySelect.selectedIndex].text;

	//set global VSD modes
    ukVSD = in_array(nationalitySelect,kazakhCountryList.noVSDCountries);
    notallowedVSD = in_array(nationalitySelect,kazakhCountryList.notAllowedCountries);
    thirdVSD = in_array(nationalitySelect,kazakhCountryList.thirdCountries);

	//calls RecalcPrice to redo the prices based on the currently selected nationality
    recalcPrice(nationalitySelect);

	//and calls hideServices to hide those services that we don't provide for this nationality
    hideServices();
};


//*******************************************************************************
window.onload = function(){

/*   var debug = document.body.appendChild(document.createElement('div'));
     with(debug.style){
    position= 'fixed';
    left = '0';
    bottom = '0';
    height = '200px';
    width = '800px';
    font='10px Courier';
    background = 'white';
    border ='1px solid #ccc';
    }
    debug.data = '';
    debug.add = function(t){
      this.data += t;
    };
    debug.show = function(){
      this.innerHTML = this.data;
      this.data = '';
      alert('Are you done with checking, so I can proceed to the next service?')
    };
    window.debug = debug;
	
//	window.debug = {add: function(){}, show: function(){}}; //not needed on the production
*/
    //go through all the tables and set time tooltip for all links
    for(var insideLinks = document.getElementById('tableHolderAdd').getElementsByTagName('a'), i=0, l; 
            (l=insideLinks[i]); 
            ++i) l.onmouseover = l.onmouseout = highlight;
    

    //go through transit/tourist/business tables, add hover&onclick for captions and move their tbodies to the global tbodys array
    var tables = ["tableTransit","tableTourist","tableBusiness"]; 
    for (var i=0, l=tables.length, caption, table; i<l; ++i) {
        //get the table
        table = document.getElementById(tables[i]);

        //the caption
        caption = table.getElementsByTagName("caption")[0];

        //table body
        body = table.getElementsByTagName("tbody")[0];

		//make caption change style on hover
        caption.onmouseout = caption.onmouseover = changestyle;  

        //make caption toggle body visibility when clicked
        caption.onclick = showtable;

        //add current tbody into global associative array
        tbodys[table.id] = body;

        //and remove the tbody from the DOM (will be added back in showtable)
        table.removeChild(tbodys[table.id]);

    }


    //just hide tableBusinessDE and tableBusinessME 
    document.getElementById('tableBusinessDE').style.display = 'none';
    document.getElementById('tableBusinessME').style.display = 'none';

    //set onchange handlers for both nationality dropdowns
    var nationalitySelect = document.getElementById('nationalitySelect'),
		nationality = document.getElementById('nationality');
    nationality.onchange = nationalitySelect.onchange = citizenshipChange;

    //when purpose of visit dropdown is changed, selects should be re-populated
    document.getElementById('purpose').onchange = populateSelects;

	//when visatype is changed, requirements have to be reconfirmed
    document.getElementById('visaType').onchange = getRequirements;

    //check if current nationality either requires VSD, or is not allowed or is a third country 
    var currentNationality = nationality.options[nationality.selectedIndex].text
    ukVSD = in_array(currentNationality,kazakhCountryList.noVSDCountries);
    notallowedVSD = in_array(currentNationality,kazakhCountryList.notAllowedCountries);
    thirdVSD = in_array(currentNationality,kazakhCountryList.thirdCountries);
    
    //calls populateSelects procedure which based on the current nationality, visatype and purpose of visit, populates all the selects 
    populateSelects();

    //set links helpers - if we change the markup, we won't need them
    var touristLink = document.getElementById('touristLink'),
		businessLink = document.getElementById('businessLink'),
		transitLink = document.getElementById('transitLink'),
		optionsLink1 = document.getElementById('optionsLink1'),
		optionsLink2 = document.getElementById('optionsLink2'); 
	optionsLink1.onclick = optionsLink2.onclick = touristLink.onclick = businessLink.onclick = transitLink.onclick = focusLink;


};


//*******************************************************************************
/**
 * this function hides leftMenu and rightMenu and shows them after a 100 ms timeou
 *  this is required because our layout is crap and if you follow a link with a hash, top part of the page will disapear in IE
 *
*/
var focusLink = function(elemId){
	var leftMenu = document.getElementById('leftMenu'),
		rightMenu = document.getElementById('rightMenu');
    leftMenu.style.display = rightMenu.style.display='none';
    window.setTimeout(function(){ 
		leftMenu.style.display = rightMenu.style.display = 'block';
	}, 100);
};


//*******************************************************************************
/**
 *  function populates 'purpose of visit' and 'service types' dropdowns based on current nationality and purpose of visit.
 *
*/
var populateSelects = function(){
    var nationality = document.getElementById('nationality'),
		purpose = document.getElementById('purpose'),
		visaType = document.getElementById('visaType');
    
	//preserve current selected value (can't be done by using selectedIndex because options will be recreated
    var oldValue = visaType.options[visaType.selectedIndex].text;

	//clear the dropdown
    visaType.options.length = 0;

	//determine which options should visa type select have based on the current purpose of visit
	switch(purpose.options[purpose.selectedIndex].text) {
		case "Transit":
			visaType.options[visaType.options.length] = new Option('Single Entry valid for 5 days','XS');
			break;

		case "Tourist":
			visaType.options[visaType.options.length] = new Option('Single Entry valid for 30 days','SE30');
			visaType.options[visaType.options.length] = new Option('Double Entry valid for 60 days','DE60');
			break;

		case "Business":
			visaType.options[visaType.options.length] = new Option('Single Entry valid for 30 days','SE30');
			visaType.options[visaType.options.length] = new Option('Single Entry valid for 90 days','SE90');
			visaType.options[visaType.options.length] = new Option('Double Entry valid for 60 days','DE60');
			visaType.options[visaType.options.length] = new Option('Double Entry valid for 90 days','DE90');
			visaType.options[visaType.options.length] = new Option('Multiple Entry valid for 3 months','ME90');
			visaType.options[visaType.options.length] = new Option('Multiple Entry valid for 6 months','ME06');
			visaType.options[visaType.options.length] = new Option('Multiple Entry valid for 12 months','ME12');
			break;

	}

    //set the originally selected value back
    setSelectedByText('visaType', oldValue);
    
    //get the requirements for this nationality, purpose of visit and visa type
    getRequirements();

};


//*******************************************************************************
/**
 *  This function sets requirements div innerHTML depending on the current nationality, visa type and purpose of visit
 *
 *
*/
//procedure sets requirements div.innerhtml to a text of requirement for this nationality, visa type and purpose of visit
var getRequirements = function(){

    //get nationality, purpose of visit, visatype and requirements DOM elements
    var nationality = document.getElementById('nationality'),
		purpose = document.getElementById('purpose'),
		nationalityRequirements = document.getElementById('nationalityRequirements'),
		visaType = document.getElementById('visaType');

    //cache their text
	var purposeText = purpose.options[purpose.selectedIndex].text,
		visaTypeText = visaType.options[visaType.selectedIndex].value,
		nationalityText = nationality.options[nationality.selectedIndex].text;

    var texts = "<h5>Documents required for passport holders of " + nationalityText + ':</h5><ol>';

    //based on the current purpose of visit, add different text for the nationality requirements
	switch (purposeText) {
		case "Transit":
	        texts += "<li>Your original passport (it should have minimum 1 blank visa page and be valid for at least 6 months after the end of the visa)</li>" +
	        	"<li>A single recent colour passport photograph</li>" +
	        	"<li>The signed Consulate application form</li>" +
	        	"<li>Copy of ticket / itinerary</li>" +
	        	"<li>Visa for destination country</li>";
			break;

		case "Tourist":
	        texts += "<li>Your original passport (it should have minimum 1 blank visa page and be valid for at least 6 months after the end of the visa)</li>" +
    	    	"<li>A single recent colour passport photograph</li>"+
        		"<li>The signed Consulate application form</li>";
        	//if((ukVSD)&&(visaTypeText!='DE60' && visaTypeText!='SE30'))
                  //  texts += "<li>Visa support document (unless being provided by Real Russia)</li>";
	        if((!ukVSD)&&(!notallowedVSD)) {
                    texts += "<li>Visa support document (unless being provided by Real Russia)</li>";
                }
                else if(notallowedVSD||thirdVSD) {
                    texts += "<li>Visa support document</li>";
                }                
			texts += "<li>Supporting letter (indicating the purpose of your trip, your contact in Kazakhstan (if applicable), the dates of your planned trip, and places to be visited. If you are driving in (by car / motorbike), please also include your vehicle details, i.e. make/type, registration number, colour</li>";

			break;

		case "Business":
			texts += ((visaTypeText=='ME90')||(visaTypeText=='ME06')||(visaTypeText=='ME12'))
				? "<li>Your original passport (it should have minimum 2 blank visa pages and be valid for at least 6 months after the end of the visa)</li>"
				: "<li>Your original passport (it should have minimum 1 blank visa page and be valid for at least 6 months after the end of the visa)</li>";
	        texts += "<li>A single recent colour passport photograph</li>" +
	        	"<li>The signed Consulate application form</li>";                    
	        if(ukVSD&&(visaTypeText!='SE30' && visaTypeText!='DE60' && visaTypeText!=''))texts += "<li>Visa support document (unless being provided by Real Russia)</li>";
	        if((!ukVSD)&&(!notallowedVSD)) {
                    texts += "<li>Visa support document (unless being provided by Real Russia)</li>";
                }
                else if(notallowedVSD) {
                    texts += "<li>Visa support document</li>";
                }
	        texts += "<li>Supporting letter <a href='/files/blank_company_support_letter_business (Kazakh).doc'>(pro-forma)</a>; if you are driving in (by car / motorbike), please also include your vehicle details, i.e. make/type, registration number, colour</li>";
			break;

	}

    texts += "<li>Payment (if not paying online)</li></ol>";

	//set the resulting data into the box
    nationalityRequirements.innerHTML = texts;

};



//*******************************************************************************
function thisindex(elm) { 
    var nodes = elm.parentNode.childNodes, node; 
    var i = count = 0; 
    while( (node=nodes.item(i++)) && node!=elm ) 
        if( node.nodeType==1 ) count++; 
    return  count; 
}

var highlight = function(ev){
    var td = this.parentNode;
    var tr = this.parentNode.parentNode;
    var trbuf = this.parentNode.parentNode;
    var th1 = tr.getElementsByTagName('th')[0];
    var hoverDiv;    
    var index = thisindex(td);
    var classname = '';
    trbuf = trbuf.previousSibling;
    if(trbuf.nodeType=='3')trbuf = trbuf.previousSibling;
    
    while(trbuf.childNodes[index].nodeName.toLowerCase()!='th'){
        trbuf = trbuf.previousSibling;
        if(trbuf.nodeType=='3')trbuf = trbuf.previousSibling;
    }
    
    var th2 = trbuf.getElementsByTagName('th')[index];
    
        if (/over/.test((ev||window.event).type)) {
            if(td.getElementsByTagName('div')[0]) td.getElementsByTagName('div')[0].className = 'titleHolder';
            if(th2){ th1.className+=" yellowLink2"; th2.className+=" yellowLink2";}
        } else {
            if(td.getElementsByTagName('div')[0]) td.getElementsByTagName('div')[0].className = 'titleHolderHidden';
            if(th2){th1.className = th1.className.replace(" yellowLink2","");th2.className = th2.className.replace(" yellowLink2","");}
        }
};


//*******************************************************************************
/*function calc_date(total) {
  var todays_date = new Date(); //this is TODAY!! 
  while(total != 0){
    //if it's saturday, add 2 days
    if(todays_date.getDay() == 6) todays_date.setDate(todays_date.getDate() + 2);

    //if it's sunday, add 1 day
    if(todays_date.getDay() == 0) todays_date.setDate(todays_date.getDate() + 1);

    //if it's wednesday, add 1 day
    if(todays_date.getDay() == 3) todays_date.setDate(todays_date.getDate() + 1);

    //decrement number of days
    total -= 1;

    todays_date.setDate(todays_date.getDate() + 1);
  }

  if(todays_date.getDay() == 6) todays_date.setDate(todays_date.getDate() + 2);
  if(todays_date.getDay() == 0) todays_date.setDate(todays_date.getDate() + 1);
  if(todays_date.getDay() == 3) todays_date.setDate(todays_date.getDate() + 1);

  return todays_date;
} */
