//GENERIC
String.prototype.contains = function(t) { return this.indexOf(t) >= 0 ? true : false; }

//CREATE BANNER OBJECT---------------------------------------------------------------------------
	function ad_obj(id,name,desc,type,loc,url,start,end,trck_o,trck_g){
		this.id = id;
		this.name = name;
		this.desc = desc;
		this.type = type;
		this.loc = loc;
		this.url = url;
		this.start = start;
		this.end = end;
		this.trck_o = trck_o;
		this.trck_g = trck_g;
	}

//DATE---------------------------------------------------------------------------
	var curr_date = new Date();
	var year = curr_date.getYear()
	  if(year<1000) year+=1900
	var t_m = curr_date.getMonth()+1;
	var t_d = curr_date.getDate();

	var ad_date_s = new Array();
	var ad_date_e = new Array();
	function set_formatdate(ad_id,s,e){ ad_date_s[ad_id] = s; ad_date_e[ad_id] = e; }
	function chck_act(ad_id){
		var s_m = (ad[ad_id].start).charAt(0) + (ad[ad_id].start).charAt(1);
		var s_d = (ad[ad_id].start).charAt(2) + (ad[ad_id].start).charAt(3);
		var e_m = (ad[ad_id].end).charAt(0) + (ad[ad_id].end).charAt(1);
		var e_d = (ad[ad_id].end).charAt(2) + (ad[ad_id].end).charAt(3);

		if(s_m.charAt(0) == "0"){ s_m = (s_m.charAt(1)) ; }
		if(s_d.charAt(0) == "0"){ s_d = s_d.charAt(1); }
		if(e_m.charAt(0) == "0"){ e_m = (e_m.charAt(1)) ; }
		if(e_d.charAt(0) == "0"){ e_d = e_d.charAt(1); }

		set_formatdate(ad_id,s_m + "/" + s_d + "/" + year,e_m + "/" + e_d + "/" + year);

		//CAMPAIGN IN MONTH RANGE

		var good_ad_s = "false"; var good_ad_e = "false";

		if ((t_m >= s_m) && (t_m <= e_m)){
			//VERIFY START
			if (t_m == s_m){
				if (t_d >= s_d){
					good_ad_s = "true";
				} else {
					good_ad_s = "false";
				}
			}
			if (t_m > s_m){
				good_ad_s = "true";
			}
			//VERIFY END
			if (t_m == e_m){
				if (t_d <= e_d){
					good_ad_e = "true";
				} else {
					good_ad_e = "false";
				}
			}
			if (t_m < e_m){
				good_ad_e = "true";
			}
		} else {
			good_ad_s = "false";
			good_ad_e = "false";
		}
		if ((good_ad_s == "true") && (good_ad_e == "true")){
			return true;
		} else {
			return false;
		}
	}

//SET BANNER OBJECT VARS---------------------------------------------------------------------------
	var num_bnrs = 0;
	var ad = new Array();
	var loop_timer = 6500;
	var ad_availpos = 6; //REAL NUMBER

	//SET BANNER INFORMATION
	//===================== id | name | desc | type | loc | url | start | end | trck_o | trck_g
	//POS 0 / IMG b1 - HEADER
	//POS 1 / IMG b2 - CATEGORY
	//POS 2 / IMG b3 - PROD DETAIL
	//POS 3 / IMG b4 - HOME TOP
	//POS 4 / IMG b5 - HOME MID
	//POS 5 / IMG b6 - LEFT MENU

	//BANNER SIZES
	var bsize = new Array();
	bsize[0] = 'height="41" ';
	bsize[1] = 'width="207" height="150" ';
	bsize[2] = 'width="382" height="45" ';
	bsize[3] = 'width="396" height="117" ';
	bsize[4] = 'width="382" height="45" ';
	bsize[5] = 'width="143" height="237" ';

//=================================================================================================
//=== ALL EDITS HERE ===

//REMINDER: UPDATE ARCHBANNERS.JS FILE



		ad[0] = new ad_obj("-bv1","june2010","Up to 20% off select collections","sale","1","/promotions/10_year_promotion.aspx","0601","0630","","");
		//ad[1] = new ad_obj("-bv1","playhouse99","Select luxury playhouses ship for $99. Save hundreds! Limited time.","sale","1","/promotions/10_year_promotion.aspx","0305","0315","","");
		//ad[0] = new ad_obj("-bv1","glider20","Glider Sale. 2 Days Left to Save!","sale","1","/Baby-Furniture/Baby-Furniture/Gliders-Chairs/18/208/1316/productlist.aspx","0329","0331","","");
		//ad[1] = new ad_obj("-bv1","ppbgiveaway","10 Year Anniversary Giveaway. Enter to Win!","sale","1","/PoshTots-Giveaway/3348/poshcategory.aspx","0315","0405","","");
		//ad[1] = new ad_obj("-bv1","nurserychklist","Nursery Necessities Checklist and Gift Guide","sale","1","/Interior-Design-Guide/3378/poshcategory.aspx","0405","0430","","");
		//ad[1] = new ad_obj("-bv1","levels10","Save 10% on this colorful collection.","sale","1","/artisans/246/OtherWorks.aspx","0301","0430","","");
		//ad[2] = new ad_obj("-bv1","circlesentiment10","Save 10% on a great gift for Mom.","sale","1","/artisans/535/OtherWorks.aspx","0301","0430","","");
		//ad[0] = new ad_obj("-bv1","mom","We love Moms and we're giving you a great gift of savings.","sale","1","/promotions/promo_mom.aspx","0422","0514","","");
		//ad[0] = new ad_obj("-bv1","memorialday","Memorial Day Celebration. Up to 10% off sitewide.","promo","1","/promotions/promo_memorialday.aspx","0524","0528","","");
		//ad[0] = new ad_obj("-bv1","barbie","Introducing the Generation Barbie & 50th Anniversay Barbie Limited Edition Prints.","sale","1","/Decor/Wall-Art-by-Theme/Adorable-Artwork-Free-Shipping/23/3155/3271/productlist.aspx","0502","0531","","");
		//ad[1] = new ad_obj("-bv1","May2010","Save 10-20% on select collections during the month of May.","sale","1","/promotions/10_year_promotion.aspx","0501","0531","","");
		//ad[1] = new ad_obj("-bv1","roundcrib","Round Cribs up to 35% off.","sale","1","/Baby-Furniture/Baby-Cribs/Round-Cribs/18/2665/2386/productlist.aspx","0501","0630","","");


		//DEFAULT HOUSE AD
		var def_house = new ad_obj("-dh","defhouse","PoshTots 10 Year Anniversary Inspiration Book","house","13","/artisans/47/OtherWorks.aspx","0101","1231","","");

//=== END ALL EDITS ===
//=================================================================================================

	//SET S/E DATES
	for (d=0;d<ad.length;d++){

	}


	//LOC CHECK
	var ad_pos = new Array();
	for (d=0;d<ad_availpos;d++){
		ad_pos[d] = 0;
	}
	var max_ads = 9;
	for (i=0;i<max_ads;i++){
		if (ad[i] && (ad[i].id != "")){
			num_bnrs = i;
			if(ad[i].loc == "all"){
				//COUNT
				for (d=0;d<ad_availpos;d++){
					ad_pos[d] = ad_pos[d] + 1; //COUNT ADS LOOPING IN EACH AVAILABLE POSITION
				}
			} else {
				//COUNT
				if (ad[i].loc.length == 1){
					ad_pos[ad[i].loc]++; //COUNT ADS LOOPING IN SPECIFIC POSITION
				} else {
					for(x=0;x<ad_availpos;x++){
						if(ad[i].loc.charAt(x)){
							ad_pos[ad[i].loc.charAt(x)]++;
						} else {
							break;
						}
					}
				}
			}
		}
	}


//ASSEMBLE BANNER---------------------------------------------------------------------------

	//DEFINE PROMOS
	var promo_loc = new Array();
	function send_adinfo(a_n,pos,status){
		promo_loc[a_n] = banner_type(a_n,pos,status)
		return promo_loc[a_n];
	}
	//ACTIVE DATE SWITCH
	var status;
	function set_promo(adnum,pos){
		if(chck_act(adnum) == true){ status = "active"; } else { status = "expired"; }
		return send_adinfo(adnum,pos,status);
	}

	var this_ad; var img_id; var size_id;
	var b_path = "/_site/_images/banners/";
	function banner_type(bcount,pos,swtch){
		this_ad = "";
		//var tracking = "?cid=pts_banner_" + ad[bcount].name + ad[bcount].id + "&utm_source=PTS&utm_medium=banner_" + ad[bcount].name + "&utm_content=" + ad[bcount].name + ad[bcount].id + "_" + ad[bcount].loc + "&utm_campaign=" + ad[bcount].type + "_" + ad[bcount].name + "-" + ad[bcount].start;
		var tracking = "";

		img_id = "b" + pos + "_";
		size_id = bsize[pos-1];

		if((swtch == "active") && (!pageurl.contains("young-america-by-stanley"))){
			if(ad[bcount].type == "promo"){
				//PROMO SETUP
				if(ad[bcount].url == ""){
					this_ad = '<a href="/promotions/promo_' + ad[bcount].name + '.aspx' + tracking + '"';
				} else {
					this_ad = '<a href="' + ad[bcount].url + tracking + '"';
				}
				this_ad += ' title="' + ad[bcount].desc + ' Use code ' + ad[bcount].name.toUpperCase() + ' at checkout. Offer valid ' + ad_date_s[bcount] + ' through ' + ad_date_e[bcount] + '."><img src="' + b_path + img_id + ad[bcount].name + '.gif?rnd=0210" ' + size_id + 'alt="' + ad[bcount].desc + '. Use code ' + ad[bcount].name.toUpperCase() + ' at checkout. Offer valid ' + ad_date_s[bcount] + ' through ' + ad_date_e[bcount] + '." border="0" /></a>';
			}
			if(ad[bcount].type == "sale"){
				//SALE SETUP
				this_ad = '<a href="' + ad[bcount].url + tracking + '"';
				this_ad += ' title="' + ad[bcount].desc + ' Sale valid ' + ad_date_s[bcount] + ' through ' + ad_date_e[bcount] + '."><img src="' + b_path + img_id + ad[bcount].name + '.gif?rnd=0210" ' + size_id + ' alt="' + ad[bcount].desc + '" border="0" /></a>';
			}
			if(ad[bcount].type == "house"){
				//HOUSE SETUP
				var adurlck = ad[bcount].url;
				this_ad = '<a href="' + ad[bcount].url + tracking + '" ';
				if(adurlck.contains("http://")){
					this_ad += 'target="_blank" ';
				}
				this_ad += 'title="' + ad[bcount].desc + '"><img src="' + b_path + img_id + ad[bcount].name + '.gif?rnd=0210" ' + size_id + ' alt="' + ad[bcount].desc + '" border="0" /></a>';
			}
			var setbevnt = set_bannerevnt(ad[bcount].name,ad[bcount].id);
		} else {
			//DEFAULT HOUSE AD
			pos = "b" + pos + "_";
			this_ad = show_house(pos);
		}
		//return this_ad;
		//**************************//
		return "<div class='banner_cat_bg'>"+ this_ad +"</div>"
	}

	function show_house(p){
		var thissize_id = bsize[p-1];
		var dhouse = '<a href="' + def_house.url + '" title="' + def_house.desc + '"><img src="' + b_path + p + def_house.name + '.gif?rnd=0210"' + thissize_id + ' alt="' + def_house.desc + '" border="0" /></a>';
		var setbevnt = set_bannerevnt(def_house.name,def_house.id);
		return dhouse;
	}

//GA EVENT TRACKING ------------------------
	function set_bannerevnt(bname,bvers){
		var rlVar = new String (document.location.pathname.toLowerCase());
		if((rlVar.contains("pts_bannertest.aspx")) || (rlVar.contains("current_sale_promo.aspx"))){
			//DO NOTHING
		} else {
			pageTracker._trackEvent("PTS_Banners_Site", bname, bvers);
		}
	}


//ROTATE BANNERS---------------------------------------------------------------------------
	var count_ad = 0;

	//CHECK AD TARGETING POSITION
	function check_locs(c_ad,p){
		var ck_c = false;
		var adloclngth = ad[c_ad].loc.length;
		for (lc=0;lc<ad_availpos;lc++){
			if (lc <= adloclngth){
				var adchck = ad[c_ad].loc.charAt(lc);
				if ((adchck == p) && (adchck != "")){
					return ck_c = true;
					break;
				}
			} else {
				break;
			}
		}
	}

	var ini_ad = 1;
	var drep = 0;
	function banner_display(){
		if (count_ad > num_bnrs){ count_ad = 0; }
		for (adp=0;adp<ad_availpos;adp++){
			var thisadid = document.getElementById('ad_'+adp);
			if((ad[count_ad].loc == "all") || (check_locs(count_ad,adp) == true)){
				if(thisadid){
					var cad = set_promo(count_ad,(adp+1));
					var pad = new String(thisadid.innerHTML);
					if(ini_ad != 1){
						if(pad.contains(ad[count_ad].desc) == false){
							ini_ad = 0;
							thisadid.innerHTML = cad;
						}
					} else {
						thisadid.innerHTML = cad;
					}
				}
			} else {
				drep = count_ad - 1;
				if(drep < 0){
					drep = 1;
				}
				if(thisadid){
					if(thisadid.innerHTML == ""){
						if(ad[drep] && ((ad[drep].loc == "all") || (check_locs(drep,adp) == true))){
							if(thisadid){
								ini_ad = false;
								thisadid.innerHTML = set_promo(drep,(adp+1));
							}
						} else if(findreplacead(adp) != "false"){
							ini_ad = false;
							thisadid.innerHTML = set_promo(findreplacead(adp),(adp+1));
						} else {
							ini_ad = false;
							thisadid.innerHTML = show_house("b" + (adp+1) + "_");
						}
					}
				}
			}
		}
		ini_ad = 0;
		count_ad++;
		if (num_bnrs > 0){
			setTimeout('banner_display()',loop_timer);
		}
	}

function findreplacead(x){
	var diss = "false";
	for (i=0;i<ad.length;i++){
		if ((ad[i].loc != "4") && (ad[i].loc == x)){
			diss = i;
			break;
		}
	}
	return diss;
}


//DISPLAY ARTISAN PAGE CONTENT

var xtxt_e = ' For more information contact a Customer Service Representative toll-free at 1-866-POSHTOT (767-4868).</div>';
var info_promo = "";
var dtxt = "";

function show_artisan(xurl){
	//var xtxt_s = '<div class="artisan_xtra">';
	//var txt_art;
	//var promoVar = new String(xurl);
	//for(p=0;p<num_bnrs;p++){
	//	var chk_p = ad[p].url;
	//	if(promoVar.contains(chk_p)){
			//info_promo = ad[p].desc + ' Offer valid ' + ad_date_s[p] + ' through ' + ad_date_e[p];
	//		info_promo = ad[p].desc;
	//		txt_art = info_promo;
	//		if(ad[p].type != "promo"){
	//			xtxt_s += '<strong>*';
	//			dtxt = "</strong>";
	//		} else {
	//			xtxt_s += '<strong>*Special Offer:</strong> &nbsp;';
	//			dtxt = ' Enter code <strong>' + (ad[p].name).toUpperCase() + '</strong> at checkout.';
	//		}

	//		if(chck_act(p) == true){
	//			document.getElementById('spec_text').innerHTML = xtxt_s + txt_art + dtxt + xtxt_e;
	//		}
	//		break;
	//	}
	//}
}

