var code_approved = false;

// Hashtable for One Year Codes
var valid_code1 = new Array();   // ONE YEAR
    valid_code1['fb995'] = 9.95; // as of 21_oct-10 by DH
    valid_code1['mad'] = 9.95; // no free 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['fb995'] = 19.90; // as of 21_oct-10 by DH
    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

// EXPIRED CODES
//    valid_code1['newprofile'] = 14.95;
//    valid_code1['kat'] = 14.95;
//    valid_code1['top friends'] = 14.95;
//    valid_code1['inkednation'] = 14.95;
//    valid_code1['inked nation'] = 14.95;
//    valid_code1['myspace'] = 19.95;
//    valid_code1['google'] = 19.95;
//    valid_code1['london'] = 15.95;
//    valid_code1['miami'] = 16.95;
//    valid_code1['network'] = 14.95;
//
// Hashtable for Two Year Codes
//var valid_code2 = new Array();
//    valid_code2['newprofile'] = 29.95;
//    valid_code2['kat'] = 29.95;
//    valid_code2['top friends'] = 29.95;
//    valid_code2['inkednation'] = 29.95;
//    valid_code2['inked nation'] = 29.95;
//    valid_code2['myspace'] = 39.95;
//    valid_code2['google'] = 39.95;
//    valid_code2['london'] = 30.95;
//    valid_code2['miami'] = 32.95;
//    valid_code1['network'] = 29.95;

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() == "fb995" ||
    myform.specialcode.value.toLowerCase() == "inkandirontee" ||
	myform.specialcode.value.toLowerCase() == "popunder" ||
	myform.specialcode.value.toLowerCase() == "intee" ||
	myform.specialcode.value.toLowerCase() == "tftee" ||
	myform.specialcode.value.toLowerCase() == "tattee" ||	
	myform.specialcode.value.toLowerCase() == "roxxtee" ||	
	myform.specialcode.value.toLowerCase() == "bijulestee" ||
  myform.specialcode.value.toLowerCase() == "mad" ||
	myform.specialcode.value.toLowerCase() == "brinkt" ||
	myform.specialcode.value.toLowerCase() == "jrogers" ||
	myform.specialcode.value.toLowerCase() == "rogerstee" ||
	myform.specialcode.value.toLowerCase() == "newyork" ||
	myform.specialcode.value.toLowerCase() == "new york" ||
	myform.specialcode.value.toLowerCase() == "philly" ||
	myform.specialcode.value.toLowerCase() == "gxtee" ||
	myform.specialcode.value.toLowerCase() == "sgtee" ||
	myform.specialcode.value.toLowerCase() == "inked" ||
	myform.specialcode.value.toLowerCase() == "fbtee" ||	
	myform.specialcode.value.toLowerCase() == "jules" ||	
	myform.specialcode.value.toLowerCase() == "imtee" ||
	myform.specialcode.value.toLowerCase() == "tmtee" ||	
	myform.specialcode.value.toLowerCase() == "cltee" ||
	myform.specialcode.value.toLowerCase() == "dcmatee" ||
	myform.specialcode.value.toLowerCase() == "fitee" ||
	myform.specialcode.value.toLowerCase() == "bestdeal" ||
	myform.specialcode.value.toLowerCase() == "best deal" ||
	myform.specialcode.value.toLowerCase() == "spin" ||
	myform.specialcode.value.toLowerCase() == '\"gq\"' ||
	myform.specialcode.value.toLowerCase() == "gq" ||
	myform.specialcode.value.toLowerCase() == "tommylee" ||
	myform.specialcode.value.toLowerCase() == "fiink" ||
	myform.specialcode.value.toLowerCase() == "tattoodreams tee" ||
	myform.specialcode.value.toLowerCase() == "msdiscount" ||
	myform.specialcode.value.toLowerCase() == "indiscount" ||
	myform.specialcode.value.toLowerCase() == "inked" ||	
	myform.specialcode.value.toLowerCase() == "myspace" ||
	myform.specialcode.value.toLowerCase() == "twinkie" ||
	myform.specialcode.value.toLowerCase() == "moment" ||
	myform.specialcode.value.toLowerCase() == "live free" ||
	myform.specialcode.value.toLowerCase() == "teecivet" ||
	myform.specialcode.value.toLowerCase() == "civet" ||
	myform.specialcode.value.toLowerCase() == "inkedgirls" ||
	myform.specialcode.value.toLowerCase() == "live free" ||
	myform.specialcode.value.toLowerCase() == "katvond" ||
	myform.specialcode.value.toLowerCase() == "tilatee" ||
	myform.specialcode.value.toLowerCase() == "lipstick" ||
	myform.specialcode.value.toLowerCase() == "becker" ||
	myform.specialcode.value.toLowerCase() == "junker" ||
	myform.specialcode.value.toLowerCase() == "agatha" ||
	myform.specialcode.value.toLowerCase() == "booth" ||
	myform.specialcode.value.toLowerCase() == "lucky" ||
	myform.specialcode.value.toLowerCase() == "tequila" ||
	myform.specialcode.value.toLowerCase() == "fitee" ||
	myform.specialcode.value.toLowerCase() == "prisonhearts" ||
	myform.specialcode.value.toLowerCase() == "cldiscount") {
  	  document.getElementById("specialcoderesults").innerHTML = 'Code Accepted, Discount Applied!';
	  code_approved = true;
	  special_code = ' - Special Code: '+document.forms["paypal_form"].specialcode.value.toUpperCase();
  	 sc_contents = myform.specialcode.value.toLowerCase();

	if (sc_contents.substring((sc_contents.length)-3,sc_contents.length) == "tee") {
	   document.getElementById("tshirt_selector").style.display = "block";
	   document.getElementById("subscription_header_image").src = '/static/images/subscriptions/header-shirt.jpg';
	}

	if (sc_contents == "bestdeal") {
	   document.getElementById("tshirt_selector").style.display = "block";
	   document.getElementById("subscription_header_image").src = '/static/images/subscriptions/header-shirt.jpg';
        }

	if (sc_contents == "spin") {
	   document.getElementById("tshirt_selector").style.display = "block";
	   document.getElementById("subscription_header_image").src = '/static/images/subscriptions/header-shirt.jpg';
        }

	if (sc_contents == "tommylee") {
	   document.getElementById("tshirt_selector").style.display = "block";
	   document.getElementById("subscription_header_image").src = '/static/images/subscriptions/header-shirt.jpg';
        }

	if (sc_contents == "fiink") {
	   document.getElementById("tshirt_selector").style.display = "block";
	   document.getElementById("subscription_header_image").src = '/static/images/subscriptions/header-shirt.jpg';
	}
	
	if (sc_contents == "brinkt") {
	   document.getElementById("tshirt_selector").style.display = "block";
	   document.getElementById("subscription_header_image").src = '/static/images/subscriptions/header-shirt.jpg';
	}

    } 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 = "none";
	   code_approved = true;
	} else {
      	   //document.getElementById("tshirt_selector").style.display = "none";
	   //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 InkedGirlsMag 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 InkedGirlsMag Subscription within the United States (6 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 InkedGirlsMag Subscription to Canada ($10 S&H Included) " + 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 InkedGirlsMag Subscription to Canada (6 Issues) ($10 S&H Included) " + special_code;
        	myform.item_amount.value= valid_code1[myform.specialcode.value]+10;
	        //document.getElementById("tshirt_selector").style.display = "none";
	        //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 InkedGirlsMag Subscription Outside of North America ($60 S&H Included) " + 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 InkedGirlsMag Subscription Outside of North America ($60 S&H Included) (6 Issues)" + special_code;
        	myform.item_amount.value= valid_code1[myform.specialcode.value]+60;
	        //document.getElementById("tshirt_selector").style.display = "none";
	     	//document.getElementById("subscription_header_image").src = '/static/images/subscriptions/header.gif';
	  }
	}
      } else {
	if (myform.delivery.value == 1) {
	        myform.item_name.value = "US - $19.95 - 1 Year Subscription to Inked Girl (6 Issues)";
        	myform.item_amount.value= "19.95" + special_code;
	} else if (myform.delivery.value == 2) {
	        myform.item_name.value = "Canada - $19.95 (+$10.00 S&H) - 1 Year Subscription to Inked Girl (6 Issues)";
        	myform.item_amount.value= "29.95" + special_code;
	        //document.getElementById("tshirt_selector").style.display = "none";
	        //document.getElementById("subscription_header_image").src = '/static/images/subscriptions/header.gif';
	} else {
	        myform.item_name.value = "Outside North America - $19.95 (+$60.00 S&H) - 1 Year Subscription to Inked Girl (6 Issues)";
        	myform.item_amount.value= "79.95" + special_code;
                //document.getElementById("tshirt_selector").style.display = "none";
   	        //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 InkedGirlsMag Subscription within the United States (8 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 InkedGirlsMag Subscription (Includes S&H) to Canada (8 Issues)" + special_code;
        	myform.item_amount.value= valid_code2[myform.specialcode.value]+10;
	        //document.getElementById("tshirt_selector").style.display = "none";
	        //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 InkedGirlsMag Subscription (Includes S&H) Outside of North America (8 Issues)" + special_code;
        	myform.item_amount.value= valid_code2[myform.specialcode.value]+60;;
	        //document.getElementById("tshirt_selector").style.display = "none";
	        //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 InkedGirlsMag Subscription within the United States (8 Issues)";
        	myform.item_amount.value= "49.95" + special_code;
	} else if (myform.delivery.value == 2) {
	        myform.item_name.value = "$59.95 - 2 Year InkedGirlsMag Subscription to Canada (8 Issues)";
        	myform.item_amount.value= "59.95" + special_code;
	        //document.getElementById("tshirt_selector").style.display = "none";
	        //document.getElementById("subscription_header_image").src = '/static/images/subscriptions/header.gif';
	} else {
	        myform.item_name.value = "$109.95 - 2 Year InkedGirlsMag Subscription Outside of North America (8 Issues)";
        	myform.item_amount.value= "109.95" + special_code;
	        //document.getElementById("tshirt_selector").style.display = "none";
	        //document.getElementById("subscription_header_image").src = '/static/images/subscriptions/header.gif';
	}
      }
    }
};

