var destData = {

    "blr" : [
        {"cardType": "noCard", "url": "/blue-ridge-attractions-and-tours/_d_Blr-p1.html?pass=Blr_Prod_Go"},
        {"cardType": "go", "url": "/blue-ridge-attractions-and-tours/_d_Blr-p1.html?pass=Blr_Prod_Go"}
    ],

    "bos" : [
        {"cardType": "noCard","url": "/boston-attractions-and-tours/_d_Bos-p1.html"},
        {"cardType": "go", "url": "/boston-attractions-and-tours/_d_Bos-p1.html?pass=Bos_Prod_Go"},
        {"cardType": "cust", "url": "/boston-attractions-and-tours/_ptd_Bos-p1.html"}
    ],

    "chi": [
        {"cardType": "noCard", "url": "/chicago-attractions-and-tours/_d_Chi-p1.html"},
        {"cardType": "go", "url": "/chicago-attractions-and-tours/_d_Chi-p1.html?pass=Chi_Prod_Go"},
        {"cardType": "cust", "url": "/chicago-attractions-and-tours/_ptd_Chi-p1.html"}
    ],

    "las":[
        {"cardType": "noCard", "url": "/las-vegas-attractions-and-tours/_d_Las-p1.html?pass=Las_Prod_Exp"},
        {"cardType": "exp", "url": "/las-vegas-attractions-and-tours/_d_Las-p1.html?pass=Las_Prod_Exp"}
    ],

    "lax": [
        {"cardType": "noCard", "url": "/los-angeles-attractions-and-tours/_d_Lax-p1.html"},
        {"cardType": "go", "url": "/los-angeles-attractions-and-tours/_d_Lax-p1.html?pass=Lax_Prod_Go"},
        {"cardType": "cust", "url": "/los-angeles-attractions-and-tours/_ptd_Lax-p1.html"}
    ],

    "mia":[
        {"cardType": "noCard", "url": "/miami-attractions-and-tours/_d_Mia-p1.html?pass=Mia_Prod_Go"},
        {"cardType": "go", "url": "/miami-attractions-and-tours/_d_Mia-p1.html?pass=Mia_Prod_Go"}
    ],

    "nyc": [
        {"cardType": "noCard", "url": "/new-york-attractions-and-tours/_d_Nyc-p1.html"},
        {"cardType": "exp", "url": "/new-york-attractions-and-tours/_d_Nyc-p1.html?pass=Nyc_Prod_Exp"},
        {"cardType": "cust", "url": "/new-york-attractions-and-tours/_ptd_Nyc-p1.html?pass=Nyc_Prod_Exp"}
    ],

    "hio": [
        {"cardType": "noCard", "url": "/oahu-attractions-and-tours/_d_Hio-p1.html"},
        {"cardType": "go", "url": "/oahu-attractions-and-tours/_d_Hio-p1.html?pass=Hio_Prod_Go"},
        {"cardType": "cust", "url": "/oahu-attractions-and-tours/_ptd_Hio-p1.html"}
    ],

    "orl": [
        {"cardType": "noCard", "url": "/orlando-attractions-and-tours/_d_Orl-p1.html"},
        {"cardType": "go", "url": "/orlando-attractions-and-tours/_d_Orl-p1.html?pass=Orl_Prod_Go"},
        {"cardType": "cust", "url": "/orlando-attractions-and-tours/_ptd_Orl-p1.html"}
    ],

    "sdo": [
        {"cardType": "noCard", "url": "/san-diego-attractions-and-tours/_d_Sdo-p1.html"},
        {"cardType": "go", "url": "/san-diego-attractions-and-tours/_d_Sdo-p1.html?pass=Sdo_Prod_Go"},
        {"cardType": "cust", "url": "/san-diego-attractions-and-tours/_ptd_Sdo-p1.html"}
    ],

    "sfo": [
	    {"cardType": "noCard", "url": "/san-francisco-attractions-and-tours/_d_Sfo-p1.html"},
        {"cardType": "go", "url": "/san-francisco-attractions-and-tours/_d_Sfo-p1.html?pass=Sfo_Prod_Go"},
        {"cardType": "cust", "url": "/san-francisco-attractions-and-tours/_ptd_Sfo-p1.html"}
    ],

    "sea": [
        {"cardType": "noCard", "url": "/seattle-attractions-and-tours/_d_Sea-p1.html"},
        {"cardType": "go", "url": "/seattle-attractions-and-tours/_d_Sea-p1.html?pass=Sea_Prod_Go"},
        {"cardType": "cust", "url": "/seattle-attractions-and-tours/_ptd_Sea-p1.html"}
    ]
};

$(document).ready(function(){
	
	go = $("#goOption").detach();
	exp = $("#expOption").detach();
	cust = $("#custOption").detach();
	defOpt = $("#defOption").detach();

    $("#dest").change(function(){
        displayCardTypes();
    });
    $("#goButton").click(function(){
        var destination = $("#dest").val();
        var type = $("#cardOption").val();
        var link = "";
        if(typeof(type) != "undefined"){
            link = getLink(destination, type);
        }

        if(link != ""){
            document.location = encodeURI(link);
        }
    });

    if($("#dest").val() != ""){
        displayCardTypes();
    }
});

function displayCardTypes(){
    var dest = $("#dest").val();

    $("#cardOption").html(defOpt)
     
    var data = destData[dest];
    if(data != undefined) {
	    for(i = 0; i < data.length; i++){
	        var card = data[i];
	        var type = card["cardType"];
	        if(type=="go" && go!=undefined) {
	        	go.appendTo($("#cardOption"));
	        }
	        if(type=="cust" && cust!=undefined) {
	        	cust.appendTo($("#cardOption"));
	        }
	        if(type=="exp" && exp!=undefined) {
	        	exp.appendTo($("#cardOption"));
	        }
	    }
    }
    else {
    	$("#cardOption").html(defOpt)
    }

    $("input[name='cardType']:checked").attr("checked", "");
}

function getLink(dest, cardType){
    var link = "";

    var data = destData[dest];
    for(var i = 0; i < data.length; i++){
        var card = data[i];
        var type = card["cardType"];
        if(type == cardType){
            link = card["url"]
        }
    }

    return link;
}
