window.onload = function(){
    var nationalitySelect = document.getElementById("nationalitySelect");
    var nationalitySelect2 = document.getElementById("nationalitySelect2");
    nationalitySelect.onchange = nationalitySelect2.onchange = nationalityChange;
    showRussianRequirements(nationalitySelect.options[nationalitySelect.selectedIndex].text);
    var nationalitySelect3 = document.getElementById("nationalitySelect3");
    nationalitySelect3.onchange = check_requirements;
    
    document.getElementById("questionP").style.display = "none";
    document.getElementById("answerNo").onclick = hideSameDay;
    document.getElementById("answerYes").onclick = showSameDay;
    
    document.getElementById("addInfo").style.display = "none";
    
    document.getElementById("PurposeOfVisitInfo").onclick = openPurposeOfVisitInfo;
}
var noSameday = "Australia,Italy,Netherlands,United States,Turkmenistan,France";
var noSamedayText = "Do you have UK Leave To Remain or a UK residence permit valid for more than 90 days?"
var noVisa = "Algeria,Angola,Afghanistan,Bangladesh,Vietnam,Georgia,Iraq,Iran,China,North Korea,Nepal,Nigeria,Pakistan,Rwanda,Syria,Somali,Chad,Sri Lanka,Ethiopia";
var noVisaText = "Do you have Long Term UK Leave To Remain or a UK residence permit?";
var visaFree = "Venezuela,Argentina,Cuba,Azerbaijan,Armenia,Belarus,Kazakhstan,Kirghizia,Cuba,Moldova,Tajikistan,Thailand,Uzbekistan,Ukraine,Israel,Kyrgyzstan,Macedonia,Bosnia and Herzegovina,Montenegro"; 

function getNewProcessingDate(country)
{
    var priceTable = document.getElementById("priceTable");
    var questionP = document.getElementById("questionP");
    var question = document.getElementById("question");
    document.getElementById("addInfo").style.display = "none";
    questionP.style.display = "none";
    document.getElementById("answerYes").checked=true;
    var texts = "";
    
    var changeproc = priceTable.getElementsByTagName("TBODY")[0].firstChild;
    if (changeproc.nextSibling.nodeType==3) 
        changeproc = changeproc.nextSibling.nextSibling; 
    else 
        changeproc = changeproc.nextSibling;
    if (changeproc.lastChild.nodeType==3) 
        changeproc = changeproc.lastChild.previousSibling; 
    else changeproc = changeproc.lastChild;
    changeproc.innerHTML = "6 to 8 days";
    
    if(in_array(country,visaFree.split(",")))
    {
        window.countryCode = 2;
        hideSameDay();
        document.getElementById("addInfo").style.display = "block";        
        if (country=="Thailand")
            {                          
             texts="Citizens of " + country + " do not require a visa for Russian Federation up to 30 days; however, it is necessary to present the original visa support documents  (tourist voucher/confirmation) to the immigration authorities at passport control on arrival.";
            }
        else if(country=="Israel")
            {
             texts="Israeli nationals do not require a tourist visa to visit the Russian Federation for up to 30 days; however, it is necessary to present the visa support documents (tourist voucher/confirmation) to the immigration authorities at passport control on arrival (and other visits of up to 90 days require the original invitation).";
            }        
        else if(country=="Macedonia")
            {
             texts="Citizens of Macedonia do not require a tourist visa to visit the Russian Federation for up to 30 days; however, it is necessary to present the visa support documents (tourist voucher/confirmation) to the immigration authorities at passport control on arrival.";
            }                    
        else if(country=="Bosnia and Herzegovina")
            {
             texts="Citizens of Bosnia and Herzegovina do not require a tourist visa to visit the Russian Federation for up to 30 days; however, it is necessary to present the visa support documents (tourist voucher/confirmation) to the immigration authorities at passport control on arrival.";
            }                    
        else if(country=="Montenegro")
            {
             texts="Citizens of Montenegro do not require a visa to visit the Russian Federation for up to 30 days.";
            }                    
        else if(country=="Argentina")
            {
             texts="Citizens of Argentina can stay in the Russian Federation without a visa for up to 90 days in any 180-day period (unless it is for commercial or work-related activities).";
            }                                
        else if(country=="Venezuela")
            {
             texts="Citizens of Venezuela do not require a visa to visit the Russian Federation for up to 90 days.";
            }                                            
        else 
        {
            texts = "Citizens of " + country + " do not require a visa for travel to the Russian Federation.";
        }
        document.getElementById("addInfo").innerHTML = texts;
        alert(texts);
        return false;
    }

   if (in_array(country,noSameday.split(",")))
   {
        questionP.style.display = "";
        question.innerHTML = noSamedayText;
        window.countryCode = 1;
        return false;
    }
    if (in_array(country,noVisa.split(",")))
    {
        questionP.style.display = "";
        question.innerHTML = noVisaText;
        window.countryCode = 2;
        return false;
    } 
    if ((country=="Turkey")||(country=="India")) 
    {
        window.countryCode = 3; 
        hideStandardService(); 
        return false;
    }
}

function hideSameDay()
{
    var nationalitySelect = document.getElementById("nationalitySelect");
    var citizenship = nationalitySelect.options[nationalitySelect.selectedIndex].text;
    var priceTable = document.getElementById("priceTable");
    var allLinks = priceTable.getElementsByTagName("a");
    var procTime= "6 to 8 days";
    switch(citizenship)
    {
        case "Australia": procTime = "10 to 14 days"; break;    
        case "Italy": procTime = "10 days"; break;    
        case "Netherlands": procTime = "10 to 14 days"; break;    
        case "United States": procTime = "10 to 14 days"; break;    
        //case "Canada": procTime = "15 days"; break;
        case "Turkmenistan": procTime = "10 to 14 days"; break;
        case "France": procTime = "10 to 14 days"; break;    
    }
    
    var changeproc = priceTable.getElementsByTagName("TBODY")[0].firstChild;
    if (changeproc.nextSibling.nodeType==3) 
        changeproc = changeproc.nextSibling.nextSibling; 
    else 
        changeproc = changeproc.nextSibling;
    if (changeproc.lastChild.nodeType==3) 
        changeproc = changeproc.lastChild.previousSibling; 
    else changeproc = changeproc.lastChild;
    changeproc.innerHTML = procTime;
 
    for(var i=0;i<allLinks.length;i++){
        if(allLinks[i].parentNode.nodeName !="TH") {
            service = allLinks[i].href.split("service=")[1].substring(3,5);
            allLinks[i].href += "&sameday=false";
            if(window.countryCode==1){
                if(service!="ST"){
                    allLinks[i].innerHTML = "not available"
                    allLinks[i].onclick = function(){alert("Sorry, this service is not available.");return false;}
                    allLinks[i].className = "notAvailable";
                }
            }    
            else {
                allLinks[i].innerHTML = "not available"
                allLinks[i].onclick = function(){alert("Sorry, this service is not available.");return false;}
                allLinks[i].className = "notAvailable";
            }
        }
    }
}

function hideStandardService(){
    var nationalitySelect = document.getElementById("nationalitySelect");
    var citizenship = nationalitySelect.options[nationalitySelect.selectedIndex].text;
    var priceTable = document.getElementById("priceTable");
    var allLinks = priceTable.getElementsByTagName("a");
    //var procTime= "2 days";
    
    //var changeproc = priceTable.getElementsByTagName("TBODY")[0].firstChild;
    //if(changeproc.nextSibling.nodeType==3) changeproc = changeproc.nextSibling.nextSibling; else changeproc = changeproc.nextSibling;
    //if(changeproc.lastChild.nodeType==3) changeproc = changeproc.lastChild.previousSibling; else changeproc = changeproc.lastChild;
   // changeproc.innerHTML = procTime;
 
 //http://192.168.26.59/Apply/tourist_apply2.asp?service=SE-ST&citizenship=Australia&sameday=false
    for(var i=0;i<allLinks.length;i++){
        if(allLinks[i].parentNode.nodeName !="TH") {
            service = allLinks[i].href.split("service=")[1].substring(3,5);
            allLinks[i].href += "&sameday=false";
            if(window.countryCode==3){
                if(service!="SA"){
                    allLinks[i].innerHTML = "not available"
                    allLinks[i].onclick = function(){alert("Sorry, this service is not available.");return false;}
                    allLinks[i].className = "notAvailable";
                }
            }    
           // else {
            //    allLinks[i].innerHTML = "not available"
            //    allLinks[i].onclick = function(){alert("Sorry, this service is not available.");return false;}
            //    allLinks[i].className = "notAvailable";
            //}
        }
    }
}

function showSameDay(){
    var priceTable = document.getElementById("priceTable");
    var changeproc = priceTable.getElementsByTagName("TBODY")[0].firstChild;
    if(changeproc.nextSibling.nodeType==3) changeproc = changeproc.nextSibling.nextSibling; else changeproc = changeproc.nextSibling;
    if(changeproc.lastChild.nodeType==3) changeproc = changeproc.lastChild.previousSibling; else changeproc = changeproc.lastChild;
    changeproc.innerHTML = "6 to 8 days";
    fillPriceTable();
}

var nationalityChange = function(){
    if(this.id=="nationalitySelect") document.getElementById("nationalitySelect2").selectedIndex = this.selectedIndex;
        else document.getElementById("nationalitySelect").selectedIndex = this.selectedIndex;
    var nationalitySelect = document.getElementById("nationalitySelect");
    var clickToApplyLink = document.getElementById("clickToApplyLink");
    var citizenship = nationalitySelect.options[nationalitySelect.selectedIndex].text;
    var priceTable = document.getElementById("priceTable");
    var allLinks = priceTable.getElementsByTagName("a");
    var entry = "", service="";
    var totalPrice = 0;
    
    var questionP = document.getElementById("questionP");
    var question = document.getElementById("question");
    document.getElementById("addInfo").style.display = "none";
    questionP.style.display = "none";document.getElementById("answerYes").checked=true;
    
    fillPriceTable();
    
    getNewProcessingDate(citizenship);
    
    showRussianRequirements(citizenship);
}

var fillPriceTable = function(){
    var nationalitySelect = document.getElementById("nationalitySelect");
    var clickToApplyLink = document.getElementById("clickToApplyLink");
    var citizenship = nationalitySelect.options[nationalitySelect.selectedIndex].text;
    var priceTable = document.getElementById("priceTable");
    var allLinks = priceTable.getElementsByTagName("a");
    var entry = "", service="";
    var totalPrice = 0;

    for(var i=0;i<allLinks.length;i++){
        allLinks[i].href = allLinks[i].href.split("&citizenship")[0] + "&citizenship="+citizenship;
        clickToApplyLink.href = clickToApplyLink.href.split("&citizenship")[0] + "&citizenship="+citizenship;
        if(allLinks[i].parentNode.nodeName !="TH") {
            allLinks[i].href.replace("&sameday=false","");
            entry = "Russian " + allLinks[i].href.split("service=")[1].substring(0,2).replace("SE","TS").replace("DE","TD");
            service = allLinks[i].href.split("service=")[1].substring(3,5).replace("ST",'Standard').replace("BR",'Bronze').replace("SA","Same") + " service";
            totalPrice = new allPrices(entry,service,"Include Visa Support Documents","No registration service needed","I will collect from your office",citizenship,"Moscow",false,"TSBR-29808-2FA42F7-SM","Tourist");
            allLinks[i].innerHTML = "&pound;" + totalPrice.fullPrice.toFixed(2);
            allLinks[i].className = "";
            allLinks[i].onclick = function(){}
        }
    }
}

function check_requirements() {
    var lst = document.getElementById("nationalitySelect3");
    var addr = (/.*realrussia.*/.test(document.location)) ? "https://www.realrussia.co.uk/" : "http://192.168.26.59/";
    document.location.href = addr + "visa/visa_requirements.asp?citizenship=" + lst.options[lst.selectedIndex].text;
  }

function showRussianRequirements(country){
    var countryLabel = "<h5>Documents required for passport holders of "+country+":</h5>";
    var nationalityRequirementsDiv = document.getElementById("nationalityRequirements");
    var forWhat = "notemail";
    var visatype = "";
    var sdm = "";
    var age = 0;
    var purpose = "";
    var request = getRequest();
    var url  = "/inc/showRequirements.asp" + "?country="+country + "&forWhat="+forWhat + "&visatype="+visatype + "&sdm="+sdm + "&age="+age + "&purpose="+purpose;
    request.open("GET", url, true);
    request.onreadystatechange = function(){ 
        if (request.readyState == 4) {
            if(request.status==200){
                nationalityRequirementsDiv.innerHTML = countryLabel + request.responseText;
            }
        };
    }
    request.send("0");
}

