var xmlhttp;
 
	function loadXMLDoc(url){
		xmlhttp=null;
		if (window.XMLHttpRequest){// code for IE7, Firefox, Mozilla, etc.
			xmlhttp=new XMLHttpRequest();
		}else if (window.ActiveXObject){// code for IE5, IE6
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		if (xmlhttp!=null){
			xmlhttp.onreadystatechange=onResponse;
			xmlhttp.open("GET",url,true);
			xmlhttp.send(null);
		}else{
			alert("Your browser does not support XMLHTTP.");
		}
	}
	
	function onResponse(){

		if(xmlhttp.readyState!=4) return;
		if(xmlhttp.status!=200){
			alert("Problem retrieving XML data");
			return;
		}	
	
		type = xmlhttp.responseXML.documentElement.getElementsByTagName("type");	
		category = xmlhttp.responseXML.documentElement.getElementsByTagName("category");
		brand = xmlhttp.responseXML.documentElement.getElementsByTagName("brand");
		style = xmlhttp.responseXML.documentElement.getElementsByTagName("style");
		title = xmlhttp.responseXML.documentElement.getElementsByTagName("title");
		img = xmlhttp.responseXML.documentElement.getElementsByTagName("img");
		view = xmlhttp.responseXML.documentElement.getElementsByTagName("view");
		email = xmlhttp.responseXML.documentElement.getElementsByTagName("email");	
		
		var txt = '';
		var titlecount = title.length;
		
		txt += '<a name="brands"></a>';
		txt += '<img id="header" src="images/03b_h_promote_brands.gif"><br/>';
		txt += '<div class="brandsText">Use these pre-built emails to introduce these brands to your customers. Each of these emails will link to a brand specific website'; 
		txt += ' featuring those styles. As always there is no mention of Bodek and Rhodes.</div><br/>';
		
			for(i=0; i<titlecount; i++){
				
				if(i % 3 == 0 && i > 1){
					//txt += '<div style="clear: both;" /><br/>';
				}
				
				if(type[i].childNodes[0].nodeValue == "Web"){
					txt += dispPromo();
				}
				
			}	
		
		txt += '<a name="promotions"></a>';
		txt += '<img id="header" src="images/03b_h_promote_styles.gif"><br/>';
		txt += '<div class="prodText">Use these pre-built emails to promote these individual styles to your customers. As always there is no mention'; 
		txt += ' of Bodek and Rhodes.</div><br/>';
		
			for(i=0; i<titlecount; i++){
				
				/*if(i % 3 == 0 && i > 1){
					//txt += '<div style="clear: both;" /><br/>';
				}*/
				var count;
				if(count % 3 == 0 && count > 1){
					txt3 += '<div style="clear: both;" /><br/><br/>';
				}
				
				if(type[i].childNodes[0].nodeValue == "Email"){
					count++;
					txt += dispPromo();
				}
				
			}	
		
		document.getElementById("termsTxt").innerHTML = txt;
	}

	function dispPromo(){
		
		var txt2 = '';
	
		txt2 += '<div class="promote">';
		txt2 += '<div class="headBG"><span class="headerText">' + title[i].childNodes[0].nodeValue + '</span></div>';
		txt2 += '<a href="' + view[i].childNodes[0].nodeValue + '"><img src="images/' + img[i].childNodes[0].nodeValue + '"></a><br/>';
		txt2 += '&nbsp;<a href="' + view[i].childNodes[0].nodeValue + '"><img src="images/03b_b_preview.gif"></a>';
		txt2 += '&nbsp;&nbsp; <a href="' + email[i].childNodes[0].nodeValue + '"><img src="images/03b_b_email.gif"></a>';
		txt2 += '</div>';
				
		txt = txt2;
		return txt;
	}
	
	function showDD(dd, cat, brand){
		var dd;
		var cat;
		var brand;
		
		document.getElementById(dd).style.display="inline";
		if(dd == "brand_dd"){
			showBrandDD(cat);
		}
		
		if(dd == "style_dd"){
			showStyleDD(cat, brand);
		}
	}
	
	function hideStyleDD(){
		document.getElementById("style_dd").style.display="none";
	}
	
	function showCategory(cat){
	
		var cat;
		//alert(cat);
		hideStyleDD();
		
		if(cat == "None"){
			onResponse();
			//hideStyleDD();
		}else{
		
		showDD("brand_dd", cat, "");
		
		type = xmlhttp.responseXML.documentElement.getElementsByTagName("type");	
		category = xmlhttp.responseXML.documentElement.getElementsByTagName("category");
		title = xmlhttp.responseXML.documentElement.getElementsByTagName("title");
		
		var txt3 = '';
		var titlecount = title.length;
		var show;
		
		for(i=0; i<titlecount; i++){
			if(type[i].childNodes[0].nodeValue == "Web"){
				if(category[i].childNodes[0].nodeValue == cat){
					show = true;
				}
			}
		}
		
		if(show == true){
			txt3 += '<a name="brands"></a>';
			txt3 += '<img id="header" src="images/03b_h_promote_brands.gif"><br/>';
			txt3 += '<div class="brandsText">Use these pre-built emails to introduce these brands to your customers. Each of these emails will link to a brand specific website featuring those styles. As always there is no mention of Bodek and Rhodes.</div>';
		}
		
			for(i=0; i<titlecount; i++){
				
				if(i % 3 == 0 && i > 1){
					txt3 += '<div style="clear: both;"></div>';
				}
				
				if(type[i].childNodes[0].nodeValue == "Web"){
					if(category[i].childNodes[0].nodeValue == cat){
						show = true;
						//alert(category[i].childNodes[0].nodeValue);
						txt3 += dispPromo();
					}else{
						txt3 += '';
					}
				}
				
			}	
			
		var showPromo;
		
		for(i=0; i<titlecount; i++){
			if(type[i].childNodes[0].nodeValue == "Email"){
				if(category[i].childNodes[0].nodeValue == cat || cat == "Email"){ //category[i].childNodes[0].nodeValue != "Website"){
					showPromo = true;
				}
			}
		}
		
		if(showPromo == true){
			txt3 += '<a name="promotions"></a>';
			txt3 += '<img id="header" src="images/03b_h_promote_styles.gif"><br/>';
			txt3 += '<div class="prodText">Use these pre-built emails to promote these individual styles to your customers. As always there is no mention'; 
			txt3 += ' of Bodek and Rhodes.</div>';
		}
		
			for(i=0; i<titlecount; i++){
				var count;
				if(count % 3 == 0 && count > 1){
					txt3 += '<div style="clear: both;" /><br/><br/>';
				}
				
				if(type[i].childNodes[0].nodeValue == "Email"){
					if(category[i].childNodes[0].nodeValue == cat || cat == "Email"){ //category[i].childNodes[0].nodeValue != "Website"){
						count++;
						//alert(category[i].childNodes[0].nodeValue);
						txt3 += dispPromo();
					}else{
						txt3 += '';
					}
				}
				
			}
		
		document.getElementById("termsTxt").innerHTML = txt3;
		
		}
	}
	
	//remove duplicates
	function stripDuplicates(arrayName){
		
        var newArray=new Array();
        label: for(var i=0; i<arrayName.length;i++ )
        {  
          for(var j=0; j<newArray.length;j++ )
          {
            if(newArray[j]==arrayName[i]) 
            continue label;
          }
          newArray[newArray.length] = arrayName[i];
        }
        return newArray;
      
   }
	
	function showBrandDD(cat){
		
		var cat;
		
		/*if(cat == "None"){
			onResponse();
		}else{*/
		
		type = xmlhttp.responseXML.documentElement.getElementsByTagName("type");	
		category = xmlhttp.responseXML.documentElement.getElementsByTagName("category");
		brand = xmlhttp.responseXML.documentElement.getElementsByTagName("brand");
		title = xmlhttp.responseXML.documentElement.getElementsByTagName("title");
		
		var txt4 = '';
		var titlecount = title.length;
		var show;
		var brandArray = [];
		
		txt4 += '<select name="brand_select" id="brand_select" onchange="showBrand(this.value, \'' + cat + '\')">';
		txt4 += '<option>Select a brand</option>';
		
			for(i=0; i<titlecount; i++){
				
				/*if(i % 3 == 0 && i > 1){
					txt4 += '<div style="clear: both;" />';
				}*/

				if(category[i].childNodes[0].nodeValue == cat || cat == "Email"){ //category[i].childNodes[0].nodeValue != "Website"){
					brandArray[i] = brand[i].childNodes[0].nodeValue;	
					//txt4 += '<option value="' + brand[i].childNodes[0].nodeValue + '">' + brand[i].childNodes[0].nodeValue + '</option>';
				/*}else{
					txt4 += '';
				}*/	
				}
			}	
				
		
		brandArray = stripDuplicates(brandArray);	
		for(var j=0; j<brandArray.length; j++){
			//alert(brandArray[j]);
			//if(category[j].childNodes[0].nodeValue == cat){
			if(brandArray[j] == undefined){
				txt4 += '';
			}else{
				txt4 += '<option value="' + brandArray[j] + '">' + brandArray[j] + '</option>';
			}
		}		
	
		txt4 += '</select>';
		
		document.getElementById("brand_dd").innerHTML = txt4;
		
		//}
	}
	
	
	
	function showBrand(dd_brand, cat){
	
		var dd_brand;
		var cat;
	
		//alert("brand is " + dd_brand + "\ncategory is " + cat);
		//alert(dd_brand + cat);
		
		type = xmlhttp.responseXML.documentElement.getElementsByTagName("type");	
		category = xmlhttp.responseXML.documentElement.getElementsByTagName("category");
		title = xmlhttp.responseXML.documentElement.getElementsByTagName("title");
		brand = xmlhttp.responseXML.documentElement.getElementsByTagName("brand");
		//style = xmlhttp.responseXML.documentElement.getElementsByTagName("style");
		
		showDD("style_dd", cat, dd_brand);
		
		var txt5 = '';
		var titlecount = title.length;
		var show;
		
		for(i=0; i<titlecount; i++){
			if(type[i].childNodes[0].nodeValue == "Web"){
				if(category[i].childNodes[0].nodeValue == cat){
					if(brand[i].childNodes[0].nodeValue == dd_brand){
						show = true;
					}
				}
			}
		}
		
		if(show == true){
			txt5 += '<a name="brands"></a>';
			txt5 += '<img id="header" src="images/03b_h_promote_brands.gif"><br/>';
			txt5 += '<div class="brandsText">Use these pre-built emails to introduce these brands to your customers. Each of these emails will link to a brand specific website '; 
			txt5 += 'featuring those styles. As always there is no mention of Bodek and Rhodes.</div>';
		}
		
		var count = 0;
		for(i=0; i<titlecount; i++){
				
			
			if(count % 3 == 0 && count > 1){
				txt5 += '<div style="clear: both;"></div><br/>';
			}
				
			if(type[i].childNodes[0].nodeValue == "Web"){
				if(category[i].childNodes[0].nodeValue == cat){
					if(brand[i].childNodes[0].nodeValue == dd_brand ){
						
						//alert(category[i].childNodes[0].nodeValue);
						//alert(brand[i].childNodes[0].nodeValue);
						//alert(dd_brand);
						
						count++;
						txt5 += dispPromo();
					}else{
						txt5 += '';
					}
				}	
			}
			
		}	
			
		var showPromo;
		
		for(i=0; i<titlecount; i++){
			if(type[i].childNodes[0].nodeValue == "Email"){
				if(category[i].childNodes[0].nodeValue == cat || cat == "Email"){ // category[i].childNodes[0].nodeValue != "Website"){
					if(brand[i].childNodes[0].nodeValue == dd_brand){
						showPromo = true;
					}
				}
			}
		}
		
		if(showPromo == true){
			txt5 += '<a name="promotions"></a>';
			txt5 += '<img id="header" src="images/03b_h_promote_styles.gif"><br/>';
			txt5 += '<div class="prodText">Use these pre-built emails to promote these individual styles to your customers. As always there is no mention'; 
			txt5 += ' of Bodek and Rhodes.</div>';
		}
		
			for(i=0; i<titlecount; i++){
				var count;
				if(count % 3 == 0 && count > 1){
					txt5 += '<div style="clear: both;" /><br/>';
				}
				
				if(type[i].childNodes[0].nodeValue == "Email"){
					if(category[i].childNodes[0].nodeValue == cat || cat == "Email"){ //category[i].childNodes[0].nodeValue != "Website"){
						if(brand[i].childNodes[0].nodeValue == dd_brand){
							count++;
							//alert(category[i].childNodes[0].nodeValue);
							txt5 += dispPromo();
						}else{
							txt5 += '';
						}
					}
				}
				
			}
		
		document.getElementById("termsTxt").innerHTML = txt5;
		
		//}
	}

	function showStyleDD(cat, brand_val){
		
		var cat;
		var brand_val;
		
		//alert(cat + " " + brand_val);
		type = xmlhttp.responseXML.documentElement.getElementsByTagName("type");	
		category = xmlhttp.responseXML.documentElement.getElementsByTagName("category");
		brand = xmlhttp.responseXML.documentElement.getElementsByTagName("brand");
		title = xmlhttp.responseXML.documentElement.getElementsByTagName("title");
		style = xmlhttp.responseXML.documentElement.getElementsByTagName("style");
		
		var txt6 = '';
		var titlecount = title.length;
		//var show;
		var styleArray = [];
		
		txt6 += '<select id="style_select" onchange="showStyle(this.value, \'' + cat + '\', \'' + brand_val + '\')">';
		//txt4 += '<select onchange="showBrand(this.value)">';
		txt6 += '<option>Select a style</option>';
		
			for(i=0; i<titlecount; i++){
				
				/*if(i % 3 == 0 && i > 1){
					txt6 += '<div style="clear: both;"></div>';
				}*/
			
				if(category[i].childNodes[0].nodeValue == cat || cat == "Email"){// category[i].childNodes[0].nodeValue != "Website"){
					if(brand[i].childNodes[0].nodeValue == brand_val){
						styleArray[i] = style[i].childNodes[0].nodeValue;
						//txt6 += '<option value="' + style[i].childNodes[0].nodeValue + '">' + style[i].childNodes[0].nodeValue + '</option>';
					}
				}/*else{
					txt6 += '';
				}	*/
			}	
		
		styleArray = stripDuplicates(styleArray);	
		for(var j=0; j<styleArray.length; j++){
			if(styleArray[j] == undefined){
				txt6 += '';
			}else{
				txt6 += '<option value="' + styleArray[j] + '">' + styleArray[j] + '</option>';
			}
		}		
		
		txt6 += '</select>';
		
		document.getElementById("style_dd").innerHTML = txt6;
		
	}

	function showStyle(dd_style, cat, brand_val){

		type = xmlhttp.responseXML.documentElement.getElementsByTagName("type");	
		category = xmlhttp.responseXML.documentElement.getElementsByTagName("category");
		title = xmlhttp.responseXML.documentElement.getElementsByTagName("title");
		brand = xmlhttp.responseXML.documentElement.getElementsByTagName("brand");
		style = xmlhttp.responseXML.documentElement.getElementsByTagName("style");
		
		//alert(dd_style + cat + brand_val);
		
		var txt7 = '';
		var titlecount = title.length;
		var show;
		
		for(i=0; i<titlecount; i++){
			if(type[i].childNodes[0].nodeValue == "Web"){
				if(category[i].childNodes[0].nodeValue == cat){
					if(brand[i].childNodes[0].nodeValue == brand_val){
						if(style[i].childNodes[0].nodeValue == dd_style){
							show = true;
						}
					}
				}
			}
		}
		
		if(show == true){
			txt7 += '<a name="brands"></a>';
			txt7 += '<img id="header" src="images/03b_h_promote_brands.gif"><br/>';
			txt7 += '<div class="brandsText">Use these pre-built emails to introduce these brands to your customers. Each of these emails will link to a brand specific website '; 
			txt7 += 'featuring those styles. As always there is no mention of Bodek and Rhodes.</div>';
		}
		
			for(i=0; i<titlecount; i++){
				
				if(i % 3 == 0 && i > 1){
					txt7 += '<div style="clear: both;" />';
				}
				
				if(type[i].childNodes[0].nodeValue == "Web"){
					if(category[i].childNodes[0].nodeValue == cat){
						if(brand[i].childNodes[0].nodeValue == brand_val ){
							if(style[i].childNodes[0].nodeValue == dd_style){
								show = true;
							//alert(category[i].childNodes[0].nodeValue);
								txt7 += dispPromo();
							}else{
								txt7 += '';
							}
						}
					}	
				}
				
			}	
			
		var showPromo;
		
		for(i=0; i<titlecount; i++){
			if(type[i].childNodes[0].nodeValue == "Email"){
				if(category[i].childNodes[0].nodeValue == cat || cat == "Email"){ //category[i].childNodes[0].nodeValue != "Website"){
					if(brand[i].childNodes[0].nodeValue == brand_val){
						if(style[i].childNodes[0].nodeValue == dd_style){
							showPromo = true;
						}
					}
				}
			}
		}
		
		if(showPromo == true){
			txt7 += '<a name="promotions"></a>';
			txt7 += '<img id="header" src="images/03b_h_promote_styles.gif"><br/>';
			txt7 += '<div class="prodText">Use these pre-built emails to promote these individual styles to your customers. As always there is no mention'; 
			txt7 += ' of Bodek and Rhodes.</div>';
		}
		
			for(i=0; i<titlecount; i++){
				var count;
				if(count % 3 == 0 && count > 1){
					txt7 += '<div style="clear: both;" /><br/><br/>';
				}
				
				if(type[i].childNodes[0].nodeValue == "Email"){
					if(category[i].childNodes[0].nodeValue == cat || cat == "Email"){ //category[i].childNodes[0].nodeValue != "Website"){
						if(brand[i].childNodes[0].nodeValue == brand_val){
							if(style[i].childNodes[0].nodeValue == dd_style){
								count++;
								//alert(category[i].childNodes[0].nodeValue);
								txt7 += dispPromo();
							}else{
								txt7 += '';
							}
						}
					}
				}
				
			}
		
		document.getElementById("termsTxt").innerHTML = txt7;
		
		//}
	}
