var code_approved = false;

// Hashtable for One Year Codes
var valid_code1 = new Array();   // ONE YEAR
valid_code1['tatmediat'] = 19.95; // discount
valid_code1['inkandirontee'] = 20.00; // free tee and discount
valid_code1['eb928'] = 19.95; // $10.00 discount
valid_code1['fb0820'] = 19.95; // free tee & $10.00 discount
valid_code1['tftee'] = 29.95; //free tee
valid_code1['tuaca'] = 19.95; // for Don
valid_code1['virtual647'] = 19.95; //$10/off. 
valid_code1['popunder'] = 29.95; //USED for the PopUnder
valid_code1['mad'] = 9.95; // no free tee
valid_code1['gq'] = 9.95; // no free tee
valid_code1['"gq"'] = 9.95; // no free tee
valid_code1['brinkt'] = 29.95; //free tee
valid_code1['bijulestee'] = 29.95; //free tee
valid_code1['fiink'] = 29.95; // free tee
valid_code1['bestdeal'] = 19.95;   // discount & tee
valid_code1['spin'] = 19.95;   // discount & tee
valid_code1['best deal'] = 19.95;   // discount & tee
valid_code1['tommylee'] = 29.95;   // discount & tee
valid_code1['fitee'] = 19.95; // discount,  tee 
valid_code1['agatha'] = 19.95; // discount,  tee 
valid_code1['junker'] = 19.95; // discount, no tee
valid_code1['booth'] = 19.95; // discount, no tee
valid_code1['lucky'] = 19.95; // discount, no tee
valid_code1['newyork'] = 19.95; // discount, no tee
valid_code1['new york'] = 19.95; // discount, no tee
valid_code1['philly'] = 9.95; // discount, no tee
valid_code1['inked'] = 19.95; // discount, no tee 
valid_code1['jrogers'] = 19.95; // discount, no tee 
valid_code1['msdiscount'] = 19.95; // discount, no tee 
valid_code1['indiscount'] = 19.95; // discount, no tee
valid_code1['cldiscount'] = 19.95; // discount, no tee
valid_code1['myspace'] = 19.95; // discount, no tee
valid_code1['inked'] = 19.95; // discount, no tee
valid_code1['twinkie'] = 19.95; // discount, no tee
valid_code1['live free'] = 19.95; // discount, no tee
valid_code1['moment'] = 19.95; // discount, no tee
valid_code1['lindfjeld'] = 19.95; // discount, no tee
valid_code1['jules'] = 19.95; // discount, no tee
valid_code1['kerli'] = 19.95; // discount, no tee
valid_code1['katvond'] = 19.95; // discount, no tee
valid_code1['inkedgirls'] = 19.95; // discount, no tee
valid_code1['becker'] = 19.95; // discount, no tee
valid_code1['lipstick'] = 19.95; // discount, no tee
valid_code1['fitee'] = 19.95; // discount, tee
valid_code1['prisonhearts'] = 19.95; // discount, tee
valid_code1['tattoodreams tee'] = 19.95; // url based disc and tee
valid_code1['THREEISSUESUB'] = 9.95; // Three issue subscription

var valid_code2 = new Array();   // TWO YEARS
valid_code2['tatmediat'] = 39.95; // Discount
valid_code2['tftee'] = 49.95; //free tee
valid_code2['popunder'] = 49.95; //USED for the PopUnder
valid_code2['fb0820'] = 39.95; // free tee & $10.00 discount
valid_code2['eb928'] = 39.95; // discount
valid_code2['bestdeal'] = 39.95; // discount & tee
valid_code2['spin'] = 39.95; // discount & tee
valid_code2['best deal'] = 39.95; // discount & tee
valid_code2['tommylee'] = 49.95; // discount & tee
valid_code2['fitee'] = 39.95; // discount, no tee 
valid_code2['inked'] = 39.95; // discount, no tee
valid_code2['newyork'] = 39.95; // discount, no tee
valid_code2['new york'] = 39.95; // discount, no tee
valid_code2['philly'] = 19.95; // discount, no tee
valid_code2['msdiscount'] = 39.95; // discount, no tee
valid_code2['indiscount'] = 39.95; // discount, no tee
valid_code2['cldiscount'] = 39.95; // discount, no tee
valid_code2['jrogers'] = 39.95; // discount, no tee
valid_code2['myspace'] = 39.95; // discount, no tee
valid_code2['agatha'] = 39.95; // discount, no tee
valid_code2['inked'] = 39.95; // discount, no tee
valid_code2['twinkie'] = 39.95; // discount, no tee
valid_code2['moment'] = 39.95; // discount, no tee
valid_code2['live free'] = 39.95; // discount, no tee
valid_code2['tequila'] = 39.95; // discount, no tee
valid_code2['civet'] = 39.95; // discount, no tee
valid_code2['junker'] = 39.95; // discount, no tee
valid_code2['booth'] = 39.95; // discount, no tee
valid_code2['lucky'] = 39.95; // discount, no tee
valid_code2['lindfjeld'] = 39.95; // discount, no tee
valid_code2['jules'] = 39.95; // discount, no tee
valid_code2['kerli'] = 39.95; // discount, no tee
valid_code2['inkedgirls'] = 39.95; // discount, no tee
valid_code2['katvond'] = 39.95; // discount, no tee
valid_code2['prisonhearts'] = 39.95; // discount, no tee
valid_code2['fitee'] = 39.95; // discount,  tee
valid_code2['tattoodreams tee'] = 39.95; // url based disc and tee

function checkShirtSelected() {
    if (document.getElementById("tshirt_selector").style.display == "block") {
        var myform = document.forms["paypal_form"];
        if (myform.os0.value.toLowerCase() == "none") {
            alert("You have not selected a size for your free t-shirt.  Please ensure that you have selected either small, medium, large or extra-large and then press the 'Subscribe Now' button to process your subscription!");
            return false;
        } else {
            return true;
        }
    } else {
        return true;
    }
}



function insertTshirt() {
    var myform = document.forms["BB_BuyButtonForm"];
    if (myform.item_select.value == 1) {
        myform.item_option_name_1.value = myform.item_option_name_1.value.substring(0,19)+' '+myform.shirt_selection.value;
    } else {
        myform.item_option_name_2.value = myform.item_option_name_2.value.substring(0,19)+' '+myform.shirt_selection.value;
    }
}

function changeSubscriptionDetails() {
    var myform = document.forms["paypal_form"];
    var special_code = '';

    if (location.href == 'http://www.inkedmag.com/subscriptions/tattoo_of_your_dreams/') {
        myform.specialcode.value = 'tattoodreams tee';
    }	

    if (location.href == 'http://www.inkedmag.com/subscriptions/popunder/') {
        myform.specialcode.value = 'popunder';
    }

    if (myform.specialcode.value.toLowerCase() == "mstee" ||
        myform.specialcode.value.toLowerCase() == "inkandirontee" ||
        myform.specialcode.value.toLowerCase() == "popunder" ||
        myform.specialcode.value.toLowerCase() == "eb928" ||
        myform.specialcode.value.toLowerCase() == "fb0820" ||
        myform.specialcode.value.toLowerCase() == "virtual647" ||
        myform.specialcode.value.toLowerCase() == "tuaca" ||
        myform.specialcode.value.toLowerCase() == "tatmediat" ||
        myform.specialcode.value.toLowerCase() == "intee" ||
        myform.specialcode.value.toLowerCase() == "tftee" ||
        myform.specialcode.value.toLowerCase() == "tattee") {
        document.getElementById("specialcoderesults").innerHTML = 'Code Accepted, Discount Applied!<br><span class="smaller">* Discounted price shown at payment verification time.</span>';
        code_approved = true;
        special_code = ' - Special Code: '+document.forms["paypal_form"].specialcode.value.toUpperCase();
        sc_contents = myform.specialcode.value.toLowerCase();
    } else {
        code_approved = false;
        document.getElementById("specialcoderesults").innerHTML = '';

        if (myform.specialcode.value == "NORMALSUBSCRIPTION") {
            document.getElementById("tshirt_selector").style.display = "block";
            document.getElementById("subscription_header_image").src = '/static/images/subscriptions/header-shirt.jpg';
        // Placeholder
        } else if (myform.specialcode.value == "THREEISSUESUB") {
            document.getElementById("subscription_header_image").src = '/static/images/subscriptions/header995.jpg';
            document.getElementById("length_dropdown").style.display = "none";
            document.getElementById("specialcoderesults").innerHTML = '<B>Special Three Issue Offer - $9.95</B>';
            document.getElementById("tshirt_selector").style.display = "inline";
            code_approved = true;
        } else {
            document.getElementById("tshirt_selector").style.display = "inline";
            document.getElementById("subscription_header_image").src = '/static/images/subscriptions/header-shirt.jpg';
        }
    }

    if (myform.subtype.value != 2) {
        if (code_approved) {
            if (myform.delivery.value == 1) {
                if (myform.specialcode.value == "THREEISSUESUB") {
                    myform.item_name.value = "$"+valid_code1[myform.specialcode.value]+" - 3 Issue Discounted InkedMag Subscription within the United States" + special_code;
                    myform.item_amount.value = valid_code1[myform.specialcode.value];
                } else {
                    myform.item_name.value = "$"+valid_code1[myform.specialcode.value]+" - 1 Year Discounted InkedMag Subscription within the United States (10 Issues)" + special_code;
                    myform.item_amount.value = valid_code1[myform.specialcode.value];
                }
            } else if (myform.delivery.value == 2) {
                if (myform.specialcode.value == "THREEISSUESUB") {
                    myform.item_name.value = "$"+(valid_code1[myform.specialcode.value]+10)+" - 3 Issue Discounted InkedMag Subscription to Canada" + special_code;
                    myform.item_amount.value = valid_code1[myform.specialcode.value]+10;
                } else {
                    myform.item_name.value = "$"+(valid_code1[myform.specialcode.value]+10)+" - 1 Year Discounted InkedMag Subscription to Canada (10 Issues)" + special_code;
                    myform.item_amount.value= valid_code1[myform.specialcode.value]+10;
                    document.getElementById("tshirt_selector").style.display = "inline";
                    document.getElementById("subscription_header_image").src = '/static/images/subscriptions/header.gif';
                }
            } else {
                if (myform.specialcode.value == "THREEISSUESUB") {
                    myform.item_name.value = "$"+(valid_code1[myform.specialcode.value]+60)+" - 3 Issue Discounted InkedMag Subscription Outside of North America" + special_code;
                    myform.item_amount.value = valid_code1[myform.specialcode.value]+60;
                } else {
                    myform.item_name.value = "$"+(valid_code1[myform.specialcode.value]+60)+" - 1 Year Discounted InkedMag Subscription Outside of North America (10 Issues)" + special_code;
                    myform.item_amount.value= valid_code1[myform.specialcode.value]+60;
                    document.getElementById("tshirt_selector").style.display = "inline";
                    document.getElementById("subscription_header_image").src = '/static/images/subscriptions/header.gif';
                }
            }
        } else {
            if (myform.delivery.value == 1) {
                myform.item_name.value = "$29.95 - 1 Year InkedMag Subscription within the United States (10 Issues)";
                myform.item_amount.value= "29.95" + special_code;
            } else if (myform.delivery.value == 2) {
                myform.item_name.value = "$39.95 - 1 Year InkedMag Subscription to Canada (10 Issues)";
                myform.item_amount.value= "39.95" + special_code;
                document.getElementById("tshirt_selector").style.display = "inline";
                document.getElementById("subscription_header_image").src = '/static/images/subscriptions/header.gif';
            } else {
                myform.item_name.value = "$89.95 - 1 Year InkedMag Subscription Outside of North America (10 Issues)";
                myform.item_amount.value= "89.95" + special_code;
                document.getElementById("tshirt_selector").style.display = "inline";
                document.getElementById("subscription_header_image").src = '/static/images/subscriptions/header.gif';

            }
        }
    } else {
        if (code_approved) {
            if (myform.delivery.value == 1) {
                myform.item_name.value = "$"+valid_code2[myform.specialcode.value]+" - 2 Year Discounted InkedMag Subscription within the United States (20 Issues)" + special_code;
                myform.item_amount.value= valid_code2[myform.specialcode.value];
            } else if (myform.delivery.value == 2) {
                myform.item_name.value = "$"+(valid_code2[myform.specialcode.value]+10)+" - 2 Year Discounted InkedMag Subscription to Canada (20 Issues)" + special_code;
                myform.item_amount.value= valid_code2[myform.specialcode.value]+10;
                document.getElementById("tshirt_selector").style.display = "inline";
                document.getElementById("subscription_header_image").src = '/static/images/subscriptions/header.gif';
            } else {
                myform.item_name.value = "$"+(valid_code2[myform.specialcode.value]+60)+" - 2 Year Discounted InkedMag Subscription Outside of North America (20 Issues)" + special_code;
                myform.item_amount.value= valid_code2[myform.specialcode.value]+60;
                ;
                document.getElementById("tshirt_selector").style.display = "inline";
                document.getElementById("subscription_header_image").src = '/static/images/subscriptions/header.gif';
            }
        } else {
            if (myform.delivery.value == 1) {
                myform.item_name.value = "$49.95 - 2 Year InkedMag Subscription within the United States (20 Issues)";
                myform.item_amount.value= "49.95" + special_code;
            } else if (myform.delivery.value == 2) {
                myform.item_name.value = "$59.95 - 2 Year InkedMag Subscription to Canada (20 Issues)";
                myform.item_amount.value= "59.95" + special_code;
                document.getElementById("tshirt_selector").style.display = "inline";
                document.getElementById("subscription_header_image").src = '/static/images/subscriptions/header.gif';
            } else {
                myform.item_name.value = "$109.95 - 2 Year InkedMag Subscription Outside of North America (20 Issues)";
                myform.item_amount.value= "109.95" + special_code;
                document.getElementById("tshirt_selector").style.display = "inline";
                document.getElementById("subscription_header_image").src = '/static/images/subscriptions/header.gif';
            }
        }
    }
};

