﻿document.write('<style type="text/css">');
document.write('.tabcontainer { background-color:'+theme+'; }');
document.write('.cheader { border-bottom: 2px solid '+theme+'; }');
document.write('.bheader { background-color: '+theme+'; }');
document.write('</style>');


//Country language selector function help

function check_language_content(the_form) {
	var the_element = the_form.altLangSelect;
	var h = location.href;
	if (h.indexOf(".html") < 1) {
		// this is the live CDA - pick up redirect URL from the option
		if (the_element.options[the_element.selectedIndex].value==-1 || the_element.options[the_element.selectedIndex].value=='') {
			for ( i=0; i<the_element.options.length; i++	) {
				if ( the_element.options[i].id=='en_UK' ) {
					location.href=the_element.options[i].value;
					return false; 
				}
			}
			var msg ='Please select a country';
			the_form.Country.focus();
			alert(msg);
			return false;
		}else{
			location.href=the_element.options[the_element.selectedIndex].value;
			return false; 
		}
	} else {
		// this is the static site
		var my_page = h.substr(h.lastIndexOf('/')+1);
		var url_base = h.substr(0, h.lastIndexOf('/')-6);

		// pick up new locale from the selected value parameter
		if (the_element.options[the_element.selectedIndex].value==-1 || the_element.options[the_element.selectedIndex].value=='') {
			new_locale = 'en_UK';
		} else {
			new_locale = the_element.options[the_element.selectedIndex].id;
		}
		new_locale = new_locale.toLowerCase();

		new_url = '/' + new_locale.substr(3,2) + '/' + new_locale.substr(0,2) + '/' + my_page;

		location.href = url_base + new_url;
	}
}	

//finish caountry language selector helper

//Read values from URL
function URL_getParameter(paramName) {
    queryString = window.document.URL.toString();
 
    var parameterName = paramName + "=";
 
    if (queryString.length > 0) {
        begin = queryString.indexOf(parameterName);
        if (begin != -1) {
            begin += parameterName.length;
            end = queryString.indexOf("&", begin);
            if (end == -1) {
                end = queryString.length;
            }
            var param = unescape(queryString.substring(begin, end));
			return param.toLowerCase();
        }
    return "null";
    }
}


	var g_cc = URL_getParameter("cc");
	var g_ll = URL_getParameter("ll");
	var g_seg = URL_getParameter("segment");
	
	if(g_cc == "null") {
		g_cc = URL_getParameter("CC");
	}
	if(g_ll == "null") {
		g_ll = URL_getParameter("LL");
	}
	if(g_seg == "null") {
		g_seg = URL_getParameter("SEGMENT");
	}


var tab = {
  
  activeTab: null,
    
  rssurl: null, //path to xml (set in onload-func)
  entries: new Array(), //Array for the entries from XML
  categories: new Array(),
  banners: new Array(),
  feed: null,  
  
//cata test


//cata test finished 

 //RSS FEED
  Init:function(_rssurl, cat){
  var _this = this;
  this.rssurl = _rssurl;
  this.cat = cat;
    new Ajax.Request(_rssurl, {
      method: 'get',
      onSuccess: function(transport) {
        _this.feed=transport.responseXML;
        _this.parsefeed();
      }
    });
  },
  
  parsefeed:function(){
    
    var _this = this;
    
	var homeBanner = this.feed.getElementsByTagName('PromoHomeImage')[0];
	if(!homeBanner) {
		var homeBanner = this.feed.getElementsByTagName('HPPromoRSS:PromoHomeImage')[0];
		//alert("this is the home banner object: "+homeBanner);
	}
	var homeBannerLink = homeBanner.getAttribute('bannerUrl');
	//alert("this is the link for banner: "+ homeBannerLink);
	var homeBanner_img = homeBanner.firstChild.nodeValue;
	$('bannerImage').src = homeBanner_img;
	//alert('this is the second time homeBannerLink: '+ homeBannerLink);
	if((homeBannerLink != null)&&(homeBannerLink.length > 3)){
	//alert('before grabbing the banner div: '+homeBannerLink);
	$('bannerLink').href = homeBannerLink;
	//alert(homeBannerLink);
	}
	
	var titleText = this.feed.getElementsByTagName('title')[0];
	if(!titleText) {
		var titleText = this.feed.getElementsByTagName('title')[0];
	}
	titleText = titleText.firstChild.nodeValue;
	$('titleText').innerHTML = titleText;
    
	var subTitleText = this.feed.getElementsByTagName('promosubtitle')[0];
	//alert('y');
	if(!subTitleText){
		var subTitleText = this.feed.getElementsByTagName('HPPromoRSS:promosubtitle')[0];
	//alert('x');
	}
	
	//alert("This is the subtitleobject: " + subTitleText);
	//alert("subtitle text length is : " + subTitleText.hasChildNodes());
	
	if((subTitleText != undefined)&&(subTitleText.hasChildNodes() == true)){
		
	
	var subTitleLink = subTitleText.getAttribute('subtitlelink');
	//alert( "This is the subtitle link: " + subTitleLink );
	//alert(subTitleText.firstChild.nodeValue)
	//alert('end');
	subTitleText = subTitleText.firstChild.nodeValue;
	//alert( "This is the subtitle text: " + subTitleText );

	if((subTitleLink != null)&&(subTitleLink.length > 3 )){
	//alert('inside subtitle text if');
	$('subtitleText').innerHTML = '<a href="' +subTitleLink+'"> &raquo&nbsp ' + subTitleText + '</a>';
	}else{
		$('subtitleText').innerHTML = subTitleText;
	}
	}
	

    var items = this.feed.getElementsByTagName('item');
    
    $A(items).each(
      function(element){
        //get all Categories
        var categoryName = element.getElementsByTagName('category')[0].firstChild.nodeValue;
		if(categoryName.search('_template') == -1) {
			var banner = element.getElementsByTagName('categoryImage')[0];
			if(!banner) {
				var banner = element.getElementsByTagName('HPPromoRSS:categoryImage')[0];
			}
			banner = banner.firstChild.nodeValue;
			
		        if (!_this.categories[categoryName]){
		          _this.categories[categoryName] = new Array();
		        }
		        _this.categories[categoryName].push(element);
			if (!_this.banners[categoryName]){
		          _this.banners[categoryName] = new Array();
			  _this.banners[categoryName].push(banner);
		        }
			else if(_this.banners[categoryName] == "") {
				_this.banners[categoryName].push(banner);
			}
		}
      }
    );
    
    // create DOM
    

    this.tabcontainer = document.createElement('div');
    this.tabcontainer.className='tabcontainer';
    this.appendChild(this.tabcontainer);
		
		
		var clearer = document.createElement('div');
        clearer.className="clearer";
        
        var offercontainer = document.createElement('div');
        offercontainer.id = 'oc_homepage';
        offercontainer.className = 'offercontainer';
        $(offercontainer).hide();
        
        var tabdiv = document.createElement('div');
        tabdiv.className='tabdiv colorFFFFFF';
		
        var catlink = document.createElement('a');
        catlink.className='catlink themelink';
        catlink.id = 'cl_homepage';
		
		//catlink.setAttribute('href', '/price_cat_rss/index.php?cc=uk&ll=en&segment=smb2');
		
			//Static link for SE
			
		// if(g_cc == 'se' && g_ll == 'sv') {
			
			// catlink.setAttribute('href', 'http://h41140.www4.hp.com/se/sv/promotions/');
		// }
		// else {
			catlink.setAttribute('href', '/price_cat_rss/index.php?cc=' + g_cc + '&ll=' + g_ll + '&segment=' +  g_seg);
						
		// }
		
		
        var completelink = document.createElement('div');
		
		var country;
		var language;
		var translation_hot_offers;
		var see_all_offers;
		var default_translation;
		var subHeaderLocalisation;  // Subheader localization var
		
		if ( (g_cc=="uk") && (g_ll=="en" ) ) {
			translation_hot_offers = "Best Offers";
			see_all_offers = "see all offers in ";
			subHeaderLocalization = "Best Offer";
			default_translation = 1;
		}
		
		if ( (g_cc=="no") && (g_ll=="no" ) ) {
			translation_hot_offers = "HP Pluss-tilbud";
			see_all_offers = "Se alle tilbud på ";
			subHeaderLocalization = "HP Pluss-tilbud";
			default_translation = 1;
		}
		
		if ( (g_cc=="hr") && (g_ll=="hr" ) ) {
			translation_hot_offers = "Najbolja ponuda";
			see_all_offers = "Pogledajte sve ponude za ";
			subHeaderLocalization = "Najbolja ponuda";
			default_translation = 1;
		}
		
		if ( (g_cc=="pt") && (g_ll=="pt" ) ) {
			translation_hot_offers = "Promoções";
			see_all_offers = "Ver todas as ofertas de ";
			subHeaderLocalization = "Em Destaque";
			default_translation = 1;
		}
		
		if ( (g_cc=="emea_africa") && (g_ll=="en" ) ) {
			translation_hot_offers = "Hot Offers";
			see_all_offers = "see all offers in ";
			subHeaderLocalization = "Best Offer";
			default_translation = 1;
		}
		
		if ( (g_cc=="ie") && (g_ll=="en" ) ) {
			translation_hot_offers = "Best Offers";
			see_all_offers = "see all offers in ";
			subHeaderLocalization = "Best Offer";
			default_translation = 1;
		}
		
		if ( (g_cc=="at") && (g_ll=="de" ) ) {
			translation_hot_offers = "Topangebot";
			see_all_offers = "Weitere ";
			subHeaderLocalization = "Topangebot";
			default_translation = 1;
		}
		
		if ( (g_cc=="de") && (g_ll=="de" ) ) {
			translation_hot_offers = "Topangebot";
			see_all_offers = "Weitere ";
			subHeaderLocalization = "Topangebot";
			default_translation = 1;
		}
		
		if ( (g_cc=="ch") && (g_ll=="de" ) ) {
			translation_hot_offers = "Golden Offers Home";
			see_all_offers = "Weitere ";
			subHeaderLocalization = "Topangebot";
			default_translation = 1;
		}
		
		if ( (g_cc=="ch") && (g_ll=="fr" ) ) {
			translation_hot_offers = "Golden Offers Home";
			see_all_offers = "Découvrez toutes les offres de ";
			subHeaderLocalization = "Top Promo";
			default_translation = 1;
		}
		
		if ( (g_cc=="fr") && (g_ll=="fr" ) ) {
			translation_hot_offers = "Top Promos";
			see_all_offers = "Toutes les offres ";
			subHeaderLocalization = "Top Promo";
			default_translation = 1;
		}
		
		if ( (g_cc=="be") && (g_ll=="fr" ) ) {
			translation_hot_offers = "Hot offers";
			see_all_offers = "Découvrez toutes les offres de ";
			subHeaderLocalization = "Hot Offer";
			default_translation = 1;
		}
		
		if ( (g_cc=="emea_africa") && (g_ll=="fr" ) ) {
			translation_hot_offers = "Top Promos";
			see_all_offers = "Découvrez toutes les offres de ";
			subHeaderLocalization = "Top Promo";
			default_translation = 1;
		}
		
		if ( (g_cc=="ma") && (g_ll=="fr" ) ) {
			translation_hot_offers = "Top Promos";
			see_all_offers = "Découvrez toutes les offres de ";
			subHeaderLocalization = "Top Promo";
			default_translation = 1;
		}
		
		if ( (g_cc=="dz") && (g_ll=="fr" ) ) {
			translation_hot_offers = "Top Promos";
			see_all_offers = "Découvrez toutes les offres de ";
			subHeaderLocalization = "Top Promo";
			default_translation = 1;
		}
		
		if ( (g_cc=="tn") && (g_ll=="fr" ) ) {
			translation_hot_offers = "Top Promos";
			see_all_offers = "Découvrez toutes les offres de ";
			subHeaderLocalization = "Top Promo";
			default_translation = 1;
		}
		
		if ( (g_cc=="ke") && (g_ll=="en" ) ) {
			translation_hot_offers = "Best Offers";
			see_all_offers = "see all offers in ";
			subHeaderLocalization = "Best Offer";
			default_translation = 1;
		}
		
		if ( (g_cc=="ng") && (g_ll=="en" ) ) {
			translation_hot_offers = "Best Offers";
			see_all_offers = "see all offers in ";
			subHeaderLocalization = "Best Offer";
			default_translation = 1;
		}
		
		if ( (g_cc=="za") && (g_ll=="en" ) ) {
			translation_hot_offers = "Best Offers";
			see_all_offers = "see all offers in ";
			subHeaderLocalization = "Best Offer";
			default_translation = 1;
		}
		
		if ( (g_cc=="be") && (g_ll=="nl" ) ) {
			translation_hot_offers = "Hot offers";
			see_all_offers = "Ontdek alle aanbiedingen voor ";
			subHeaderLocalization = "Hot offer";
			default_translation = 1;
		}
		
		if ( (g_cc=="nl") && (g_ll=="nl" ) ) {
			translation_hot_offers = "Beste aanbiedingen";
			see_all_offers = "Zie alle aanbiedingen van ";
			subHeaderLocalization = "Beste aanbiedingen";
			default_translation = 1;
		}
		
		if ( (g_cc=="dk") && (g_ll=="da" ) ) {
			translation_hot_offers = "Tilbud og kampagner";
			see_all_offers = "Se alle kampagner til ";
			subHeaderLocalization = "Hot Pris";
			default_translation = 1;
		}
		
		if ( (g_cc=="es") && (g_ll=="es" ) ) {
			translation_hot_offers = "Ofertas destacadas";
			see_all_offers = "Ver todas las ofertas de ";
			subHeaderLocalization = " Promoción especial ";
			default_translation = 1;
		}
		
		if ( (g_cc=="hr") && (g_ll=="hr" ) ) {
			translation_hot_offers = "Najnovije ponude";
			see_all_offers = "Se alle tilbud på ";
			subHeaderLocalization = "Najnovije ponude";
			default_translation = 1;
		}
		
		if ( (g_cc=="hu") && (g_ll=="hu" ) ) {
			translation_hot_offers = "Kiemelt ajánlatok";
			see_all_offers = "összes ajánlat : ";
			subHeaderLocalization = "Kiemelt ajánlatok";
			default_translation = 1;
		}
		
		if ( (g_cc=="ro") && (g_ll=="ro" ) ) {
			translation_hot_offers = "Super-oferte";
			subHeaderLocalization = "Cea mai bună ofertă";
			see_all_offers = "vezi toate ofertele în  ";
			default_translation = 1;
		}
		
		if ( (g_cc=="sk") && (g_ll=="sk" ) ) {
			translation_hot_offers = "Top ponuky";
			subHeaderLocalization = "Top ponuky";
			see_all_offers = "Všetky ponuky v kategórii  ";
			default_translation = 1;
		}
		
		if ( (g_cc=="ru") && (g_ll=="ru" ) ) {
			translation_hot_offers = "Специальные предложения";
			subHeaderLocalization = "Специальные предложения";
			see_all_offers = "все предложения в ";
			default_translation = 1;
		}

		if ( (g_cc=="ua") && (g_ll=="ru" ) ) {
			translation_hot_offers = "Специальные предложения";
			subHeaderLocalization = "Специальные предложения";
			see_all_offers = "все предложения в ";
			default_translation = 1;
		}

		if ( (g_cc=="pl") && (g_ll=="pl" ) ) {
			translation_hot_offers = "Najlepsze oferty";
			subHeaderLocalization = "Najlepsza oferta";
			see_all_offers = "Wszystkie oferty w kategorii ";
			default_translation = 1;
		}

		if ( (g_cc=="cz") && (g_ll=="cs" ) ) {
			translation_hot_offers = "Aktuální nabídka";
			subHeaderLocalization = "Skvělá cena";
			see_all_offers = "Všechny nabídky v kategorii ";
			default_translation = 1;
		}

		if ( (g_cc=="il") && (g_ll=="he" ) ) {
			translation_hot_offers = "מוצרים ומבצעים מומלצים";
			subHeaderLocalization = "המומלצים";
			see_all_offers = "צפה בכל ההצעות ב ";
			default_translation = 1;
		}
		
		//waiting for translation		
		if ( (g_cc=="it") && (g_ll=="it" ) ) {
			translation_hot_offers = "Offerte Speciali";
			see_all_offers = "vedi tutte le offerte di ";
			subHeaderLocalization = " Offerta Speciale ";
			default_translation = 1;
		}
				
		if ( (g_cc=="fi") && (g_ll=="fi" ) ) {
			translation_hot_offers = "Parhaat tarjoukset";
			see_all_offers = "kaikki tuoteryhmän tarjoukset ";
			subHeaderLocalization = " Paras tarjous ";
			default_translation = 1;
		}
		
		if ( (g_cc=="se") && (g_ll=="sv" ) ) {
			translation_hot_offers = "Erbjudanden från HP";
			see_all_offers = "Alla erbjudanden för ";
			subHeaderLocalization = " Bra köp ";
			default_translation = 1;
		}
		

		// if no CC LL found, default translation is EN
		if ( default_translation != 1 ) {
			translation_hot_offers = "Hot Offers";
			subHeaderLocalization = "Best Offer";
			see_all_offers = "see all offers in ";
		}

	
	        catlink.appendChild(document.createTextNode(translation_hot_offers));


        	tabdiv.appendChild(document.createTextNode("» "));
	        tabdiv.appendChild(catlink);
        
	        this.tabcontainer.appendChild(tabdiv);
	
		
		
    for (catName in this.categories){
        if (typeof this.categories[catName] != 'object'){
          continue;
        }
       
        var clearer = document.createElement('div');
        clearer.className="clearer";
        
        var offercontainer = document.createElement('div');
        offercontainer.id = 'oc_'+catName;
        offercontainer.className = 'offercontainer';
        $(offercontainer).hide();
        
        var tabdiv = document.createElement('div');
        tabdiv.className='tabdiv colorFFFFFF';
		
        var catlink = document.createElement('a');
        catlink.className='catlink themelink';
		
		

	// check if category is having "staticlink" property... if yes, than catlink should have href..!
	var catlink_href="";

	this.categories[catName].each(
		function(item, index) {
			if (item.getElementsByTagName('category')[0] != null) catlink_href = item.getElementsByTagName('category')[0].getAttribute('staticlink');
		}
	)

	// if the result of the above check for catlink_href is not empty, show a static link
	if (catlink_href != "" && catlink_href != null) {
		catlink.href = catlink_href;
	        catlink.id = 'cl_staticlink_';
	}
	else {
		// regular link, give it proper ID
	        catlink.id = 'cl_homepage';
        	catlink.id = 'cl_'+catName;
	}
        
        var completelink = document.createElement('div');
        
	//alert(catName);
	if(catName == "Ver todos los portátiles"){
		//alert (catName);
		boldText = document.createElement('b');
		boldText.appendChild(document.createTextNode(catName));
		catlink.appendChild(boldText);
	
	}else{
	
        catlink.appendChild(document.createTextNode(catName));
        }
	
        tabdiv.appendChild(document.createTextNode('» '));
        tabdiv.appendChild(catlink);
        
        this.tabcontainer.appendChild(tabdiv);
        
        //new line after 3 offers and half width for oneandonly offer
        var numelements = this.categories[catName].length;
        if (numelements > 3) {
          numelements = 3;
        } else if (numelements == 1) {
          numelements = 2;
        } else {
          numelements = this.categories[catName].length;
        }
		
        
        //Link Tabs
	catlink.tabswitch = function(){
		// do not switch tabs when link is external static link ( id = 'cl_staticlink_' ):
		if (this.getAttribute('id') != 'cl_staticlink_') {
			if (this.parentNode.parentNode.parentNode.parentNode.activeTab) {
				$(this.parentNode.parentNode.parentNode.parentNode.activeTab.parentNode).removeClassName('activelink');
				$('oc_'+this.parentNode.parentNode.parentNode.parentNode.activeTab.lastChild.nodeValue).hide();
			}
			else if ($('oc_home')) {
				$('oc_home').hide();
			}

			this.parentNode.parentNode.parentNode.parentNode.activeTab = this;
			$(this.parentNode.parentNode.parentNode.parentNode.activeTab.parentNode).addClassName('activelink');
			$('oc_'+this.lastChild.nodeValue).show();
			
			//Make inactive link after click
			//this.parentNode.parentNode.parentNode.parentNode.activeTab.parentNode.lastChild.id = "inactive";
			//var linkInactive = this.parentNode.parentNode.parentNode.parentNode.activeTab.parentNode.lastChild.id
			
			/*alert(this.parentNode.parentNode.parentNode.parentNode.activeTab.innerHTML);
			
			var inactiveLink = document.createElement('span');
			inactiveLink.className = 'catlink themelink';
			alert(catName);
			inactiveLink.innerHTML = '&raquo;&nbsp; ' + this.parentNode.parentNode.parentNode.parentNode.activeTab.innerHTML;
		
			if ( this.parentNode.parentNode.parentNode.parentNode.activeTab.parentNode.className == 'tabdiv colorFFFFFF activelink') {
			alert();
			this.parentNode.parentNode.parentNode.parentNode.activeTab.parentNode.appendChild(inactiveLink);
			}
			*/
			
			
			
			$('bannerImage').src = _this.banners[this.lastChild.nodeValue];
			$('bannerLink').href = '/price_cat_rss/index.php?cc=' + g_cc + '&ll=' + g_ll + '&segment=' +  g_seg;
		}
        }
        
        Event.observe(catlink, 'click', function(e){
          var catlink = Event.element(e);
          catlink.tabswitch();
        });
        
        //calculate width of offerdiv
        var width = Math.round((700/numelements))-10;
        
        this.categories[catName].each(
        function(item, index)
        {
          var title = "";
	  var lk = "";
	  var desc = "";
          if (item.getElementsByTagName('title')[0].firstChild != null) title = item.getElementsByTagName('title')[0].firstChild.nodeValue;
          if (item.getElementsByTagName('link')[0].firstChild != null) lk = item.getElementsByTagName('link')[0].firstChild.nodeValue;
          if (item.getElementsByTagName('description')[0].firstChild != null) desc = item.getElementsByTagName('description')[0].firstChild.nodeValue;
         
          var tempimage = item.getElementsByTagName('ItemImage')[0];
          var tempprice = item.getElementsByTagName('PriceMessage')[0];
		  var tempshowonhomepage = item.getElementsByTagName('HomePageProduct')[0];
          
          if (!tempimage && !tempprice && !tempshowonhomepage) {
            tempimage = item.getElementsByTagName('HPPromoRSS:ItemImage')[0];
            tempprice = item.getElementsByTagName('HPPromoRSS:PriceMessage')[0];
	    tempshowonhomepage = item.getElementsByTagName('HPPromoRSS:HomePageProduct')[0];
          }
                    
          var rssimage = "";
          var rssprice = "";
	  var showonhomepage = "no";
          if (tempimage.firstChild != null) rssimage = tempimage.firstChild.nodeValue;
          if (tempprice.firstChild != null) rssprice = tempprice.firstChild.nodeValue;
	  if (tempshowonhomepage.firstChild != null) showonhomepage = tempshowonhomepage.firstChild.nodeValue;
          
          desc = desc.replace(/align=left/, ''); // image in XMLS please not float!

          var div = document.createElement('div');
          div.className='offer';
	  if (showonhomepage == 'yes') div.id = 'homepage'; // if this is the offer to show on home page, give it an id
          //Subheader for product which are on homepage
		  
		  var bheader = document.createElement('div');
		  bheader.className='bheader';
		  var bh2 = document.createElement('h2');
		  bh2.className='themeheader bold';
		                        
		            //Changes on home page the subheader in cathegory names and adds a link to cathegory page.
					
					/*var bheaderlink = document.createElement('a');
					bheaderlink.className='themeheaderlink';
					bheaderlink.href='#';
					bheaderlink.appendChild(document.createTextNode(catName));*/
		                        
		  bh2.appendChild(document.createTextNode(subHeaderLocalization ));
					//bh2.appendChild(bheaderlink);
		            
		  bheader.appendChild(bh2);
		  if ( div.id == "homepage" )
		  {
			//alert (div.childNodes.length);
		    div.appendChild(bheader);
		  }
		  //subheader clsoed
		  
		  var h3 = document.createElement('h3');
          h3.className='color003366bld';
		  
		 // OLD CODE
		//	var image = document.createElement('img');
		//	image.src=rssimage;
		
			var newimg = document.createElement('img');
			newimg.src = rssimage;
			newimg.alt = title;
			newimg.setAttribute("border", 0); 
		  
		  
          var price = document.createElement('div');
          //price.className='price';
          var descr = document.createElement('div');
          descr.className='offer_text';

	  // if XML has product link defined, create <a href>, otherwise, create div which will contain only the product name (no link)
          if ( lk != "" ) {
            var titlelink = document.createElement('a');
            titlelink.className='color003366bld';
            titlelink.href=lk;
          }
	  else {
	    var titlelink = document.createElement('div');
	  }
           
          var cheader = document.createElement('div');
          cheader.className='cheader color003366bld';
          cheader.appendChild(h3);
           
          div.appendChild(cheader);
          //div.appendChild(h3);
	  // if XML has product link defined, add >>
	  if ( lk != "" ) {
            h3.appendChild(document.createTextNode('» '));
	  }
          h3.appendChild(titlelink);
          titlelink.appendChild(document.createTextNode(title));
		  
		//	old code
		//	div.appendChild(image);
		  
		  
		  	//link for image
			if ( lk != "" ) {
				var newa = document.createElement('a');
				newa.href = lk;
			}
			else {
				var newa = document.createElement('div');
			}
			
			newa.appendChild(newimg);
			div.appendChild(newa);
			//end link for image
		  

          // if XML does not have price message add the star with the text
          if (rssprice != "") {
			var price_text = document.createElement('div');
			//price_text.className='price_text';
			price_text.id='pricemsg_middle';
			var ttext = document.createElement('div');
			ttext.appendChild(document.createTextNode(rssprice));
			ttext.id='pricemsg_inner';
			price.id='pricemsg_outer';
			div.appendChild(price);
            price.appendChild(price_text);
			price_text.appendChild(ttext);
          }
          div.appendChild(descr);
          
          descr.innerHTML = desc;

          offercontainer.appendChild(div);
          div.style.width=width+'px';
          
          if (numelements >= 3 && (index+1) % 3 == 0){
            
            offercontainer.appendChild(clearer.cloneNode(true));
          }
        }
      );
      
      this.appendChild(offercontainer);
    }
    
    
    // show every first offer from each category on homepage
    var starttab = $('cl_'+this.cat);
    if (starttab) {
      starttab.tabswitch();
    } else {
        var offercontainer = document.createElement('div');
        offercontainer.id = 'oc_home';
        offercontainer.className = 'offercontainer';
        for (catName in this.categories){
          var container = $('oc_'+catName);
          if (container){
                        
            //var temp = container.firstChild.cloneNode(true);
            // For category, clone the container with id "homepage":
	    var tmp_hashomeproduct = false;
            var tempconts = container.getElementsByTagName("*");
            $A(tempconts).each(
              function(element){
                if (element.id == 'homepage') {
					temp = element.cloneNode(true);
					tmp_hashomeproduct = true;
					
					
					var bheader = document.createElement('div');
		            bheader.className='bheader';
		            
					
					
		            var bh2 = document.createElement('h2');
		            bh2.className='themeheader bold';
		                        
		            //Changes on home page the subheader in cathegory names and adds a link to cathegory page.
					
					/*var bheaderlink = document.createElement('a');
					bheaderlink.className='themeheaderlink';
					bheaderlink.href='#';
					bheaderlink.appendChild(document.createTextNode(catName));*/
						
					
					bh2.appendChild(document.createTextNode(subHeaderLocalization ));
					//bh2.appendChild(bheaderlink);
		            
					bheader.appendChild(bh2);
		            
					Element.addClassName(temp, 'home');
					temp.style.width = '223px';
					temp.style.height = '290px';
					
					var viewall = document.createElement('a');
					viewall.href='#';

					viewall.appendChild(document.createTextNode(see_all_offers))
					
					// EMEA variable
					//if ( (URL_getParameter("cc") != "hr") && (URL_getParameter("ll") != "hr") && (URL_getParameter("segment") !="smb" )) {
					//	viewall.appendChild(document.createTextNode(catName));
					//}
					//else {
						viewall.appendChild(document.createTextNode(catName));	
					//}
		            
					var homelinks = document.createElement('div');
					homelinks.className='color003366 homelinks';
					homelinks.appendChild(document.createTextNode('» '));
					homelinks.appendChild(viewall);
					
					//Removes the subheader for products in cathegory view
					temp.removeChild(temp.childNodes[0]);
					//end the remove 
					
					temp.insertBefore(bheader, temp.firstChild);
					offercontainer.appendChild(temp);
					temp.appendChild(homelinks);
		            
					/*Event.observe(bheaderlink, 'click', function(e){
						$('cl_'+Event.element(e).firstChild.nodeValue).tabswitch();
					});*/
		            
					
					Event.observe(viewall, 'click', function(e) {
						//if ( (URL_getParameter("cc")=="fi") && (URL_getParameter("ll")=="fi" ) ) {
							//new code
						//	$('cl_'+bheaderlink.firstChild.nodeValue).tabswitch();
						//}
						//else {
							$('cl_'+Event.element(e).lastChild.nodeValue).tabswitch();
						//}
					});
					
				}
              }
            );
   
            // check if there was home product defined for that category, if yes, add stuff to the cloned container
	    //if ( tmp_hashomeproduct ) {
        //      
        //    }
          }
        }
      this.appendChild(offercontainer);
    }
  }
}

function geturlparam( name ) {
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

//Event.observe(window,'load',function(){
function startticker() {
/* 
  uricategory=window.location.href.substr(window.location.href.indexOf("="));
  category = uricategory.split('='); 

  if(category.length <= 1){
    category = null;
  } else {
    category = category[1];
  }
*/

  

  var category = unescape(geturlparam("showcat"));

//  if((g_cc=="ch")&&((g_ll=="fr")||(g_ll=="de"))){
//	category = "Golden Offers Home";
//  }

  Object.extend($('tabs'), tab);
    $('loading').style.display = 'none';
//  $('tabs').Init('/price_cat_rss/es/es/offers.xml',category);
//  $('tabs').Init('/price_cat_rss/rss_dl.php?cc=uk&ll=en&segment=smb2',category);

//server XML coment or uncoment
	$('tabs').Init('/price_cat_rss/rss_dl.php?cc=' + g_cc + '&ll=' + g_ll + '&segment=' + g_seg, category);
  	//alert(category);
	
	//for debugging purpose local XML load
	//$('tabs').Init('/price_cat_rss/XML/SMB/rss_promo_index_de_de_smb.xml',category);
	//finish debugging
	  
//test
	//$('tabs').Init('/price_cat_rss/rss_promo_index_ie_en_' + URL_getParameter("segment") + '.xml',category);
 
  
//  $('tabs').Init('http://127.0.0.1/price_cat_rss/es/es/offers.xml',category);
//  $('tabs').Init('/price_cat_rss/es/es/offers3.xml',category);
}//);
