//Templates output --------------------------------------------------------------------------------------------------------------------------

var affInterfaceOptions = '&amp;pr_code=SIgivFZCrsu6bC4yXhR7L9r61iJwMQ';

function IncludeAffInterface(options,file){
	if(!file) file = 'pr_interface';
	options = affInterfaceOptions + (options ? '&'+options : '');
	document.write('<script type="text/javascript" src="http://www.templatehelp.com/codes/'+file+'.php?'+options+'"><'+'/script>');
}

function Popup(url){
	window.open(
		url,
		'window',
		'width=600, height=600, resizable=yes, scrollbars=yes, location=no,  toolbar=no, menubar=no, status=no'
	);
}
// Hide "www.mytemplatestorage.com" from status bar
function HideStatus(){
	window.status = document.readyState!="complete" ?
		"Loading..." : window.defaultStatus;
}
document.onreadystatechange = HideStatus;

//Templates output --------------------------------------------------------------------------------------------------------------------------

//Code removed from HTML --------------------------------------------------------------------------------------------------------------------
function init() {
    IncludeAffInterface('categories&amp;types','pr_data.js');
}

function typeOutput() {
    document.write('<li><a href="template.php?type=1">Template HTML</a></li><li><a href="template.php?type=9">Template Flash</a></li><li><a href="template.php?type=36">Template Flash CMS</a></li><li><a href="template.php?type=24">Template Joomla</a></li><li><a href="template.php?type=40">Template VirtueMart</a></li><li class="last"><a href="template.php?type=17">Template WordPress</a></li>')
}

function categoryOutput() {
    document.write('<li><a href="template.php?category=2">Affari / Business</a></li><li><a href="template.php?category=16">Industrie / Fabbriche</a></li><li><a href="template.php?category=96">Associazioni / No Profit</a></li><li><a href="template.php?category=121">Energia Alternativa</a></li><li><a href="template.php?category=43">Trasporti / Traslochi</a></li><li><a href="template.php?category=41">Investigazioni / Sicurezza</a></li><li><a href="template.php?category=33">Aziende Agricole</a></li><li><a href="template.php?category=47">Animali / Allevamento</a></li><li><a href="template.php?category=74">Hotel / B&amp;B</a></li><li><a href="template.php?category=6">Servizi Internet</a></li><li><a href="template.php?category=8">Print &amp; Web Design</a></li><li><a href="template.php?category=21">Servizi Hosting</a></li><li><a href="template.php?category=11">Autosaloni / Concessionarie</a></li><li><a href="template.php?category=40">Fotografia / Arte</a></li><li><a href="template.php?category=26">Ingegneria / Architettura</a></li><li><a href="template.php?category=4">Agenzie Immobiliari</a></li><li><a href="template.php?category=27">Agenzie Viaggi / Vacanze</a></li><li><a href="template.php?category=34">Avvocati / Professionisti</a></li><li><a href="template.php?category=65">Partiti / Candidati Politici</a></li><li><a href="template.php?category=24">Arredamento</a></li><li><a href="template.php?category=1">Bellezza / Benessere</a></li><li><a href="template.php?category=35">Dating / Incontri</a></li><li><a href="template.php?category=51">Gioiellerie / Preziosi</a></li><li><a href="template.php?category=46">Scuole / Formazione</a></li><li><a href="template.php?category=14">Sport / Fitness</a></li><li><a href="template.php?category=91">Casino Online</a></li><li><a href="template.php?category=19">Musica / Musicisti</a></li><li><a href="template.php?category=77">Discoteche / Locali</a></li><li><a href="template.php?category=76">Ristoranti / Bar</a></li><li><a href="template.php?category=29">Cucina / Chef</a></li><li><a href="template.php?category=75">Matrimonio / Sposi</a></li><li><a href="template.php?category=49">Moda / Abbigliamento</a></li><li><a href="template.php?category=10">Medicina / Salute</a></li><li class="last"><a href="template.php?category=17">Religione / Chiesa</a></li>')
}

function productOptionOutput() {
    document.write('<option value="1">Template HTML</option><option value="9">Template Flash</option><option value="36">Template Flash CMS</option><option value="24">Template Joomla</option><option value="40">Template VirtueMart</option><option value="17">Template WordPress</option>')
}

function categoryOptionOutput() {
    document.write('<option value="2">Affari / Business</option><option value="16">Industrie / Fabbriche</option><option value="96">Associazioni / No Profit</option><option value="121">Energia Alternativa</option><option value="43">Trasporti / Traslochi</option><option value="41">Investigazioni / Sicurezza</option><option value="33">Aziende Agricole</option><option value="47">Animali / Allevamento</option><option value="74">Hotel / B&amp;B</option><option value="6">Servizi Internet</option><option value="8">Print &amp; Web Design</option><option value="21">Servizi Hosting</option><option value="11">Autosaloni / Concessionarie</option><option value="40">Fotografia / Arte</option><option value="26">Ingegneria / Architettura</option><option value="4">Agenzie Immobiliari</option><option value="27">Agenzie Viaggi / Vacanze</option><option value="34">Avvocati / Professionisti</option><option value="65">Partiti / Candidati Politici</option><option value="24">Arredamento</option><option value="1">Bellezza / Benessere</option><option value="35">Dating / Incontri</option><option value="51">Gioiellerie / Preziosi</option><option value="46">Scuole / Formazione</option><option value="14">Sport / Fitness</option><option value="91">Casino Online</option><option value="19">Musica / Musicisti</option><option value="77">Discoteche / Locali</option><option value="76">Ristoranti / Bar</option><option value="29">Cucina / Chef</option><option value="75">Matrimonio / Sposi</option><option value="49">Moda / Abbigliamento</option><option value="10">Medicina / Salute</option><option value="17">Religione / Chiesa</option>');
}

function clearIn(where) {
    var wordsClicked = false;
    if (where == 'keyword' && !wordsClicked) {
        document.forms['search'].keyword.value = "";
        wordsClicked = true;
    }
}

function searchResultOutput() {
    affInterfaceOptions += '&amp;type=1&amp;cols=4&amp;rows=1&amp;sp=0&amp;iw=680&amp;ih=310&amp;bgcolor=%23ffffff&amp;noscroll=yes';
}

      //Html entity decode function
      function html_entity_decode(str) {
          var ta=document.createElement("textarea");
          ta.innerHTML=str.replace(/</g,"&lt;").replace(/>/g,"&gt;");
          return ta.value;
      }
      //Html entity decode function

      function setActiveMenusForm() {
          var URL=window.location.href;
          var typeValue=0;
          var categoryValue=0;
          var categoriesList=new Array();
          var typesList=new Array();
          URL=URL.substring(URL.indexOf("?")+1);
          URL=decodeURI(URL);

          //Replacing "+" symbols with space
          while (URL.indexOf("+")>=0) {URL=URL.replace("+"," ");}

          //Detect type value begin
          if (URL.match("type=")!=null) {
              var type=URL.substring(URL.indexOf("type="));
              var typeOptions;
              if (type.length>5 & type.match("&")!=null) {
                  type=type.substring(0,type.indexOf("&"));
                  if (type.length>5) {
                      typeValue=type.substring(5);
                      typeOptions=document.getElementById('productSelect').options;
                      for(i=0;i<typeOptions.length;i++) {
                          if (typeOptions[i].value==typeValue) {typeOptions[i].selected=true;
                          }
                      }
                  }
              }
              else {
                  if (type.length>5) {
                      typeValue=type.substring(5);
                      typeOptions=document.getElementById('productSelect').options;
                      for(i=0;i<typeOptions.length;i++) {
                          if (typeOptions[i].value==typeValue) {typeOptions[i].selected=true;}
                      }
                  }
              }
          }
          //Detect type value end

          //Detect category value begin
          if (URL.match("category=")!=null) {
              var category=URL.substring(URL.indexOf("category="));
              var categoryOptions;
              if (category.length>9 & category.match("&")!=null) {
                  category=category.substring(0,category.indexOf("&"));
                  if (category.length>9) {
                      categoryValue=category.substring(9);
                      categoryOptions=document.getElementById('categorySelect').options;
                      for(i=0;i<categoryOptions.length;i++) {
                          if (categoryOptions[i].value==categoryValue) {categoryOptions[i].selected=true;}
                      }
                  }
              }
              else {
                  if (category.length>9) {
                      categoryValue=category.substring(9);
                      categoryOptions=document.getElementById('categorySelect').options;
                      for(i=0;i<categoryOptions.length;i++) {
                          if (categoryOptions[i].value==categoryValue) {categoryOptions[i].selected=true;}
                      }
                  }
              }
          }
          //Detect category value end

          //Detect keyword value begin
          if (URL.match("keyword=")!=null) {
              var keyword=URL.substring(URL.indexOf("keyword="));
              var keywordValue;
              if (keyword.length>8 & keyword.match("&")!=null) {
                  keyword=keyword.substring(0,keyword.indexOf("&"));
                  if (keyword.length>8) {
                      keywordValue=keyword.substring(8);
                      document.getElementById('keywordInput').value=keywordValue;
                  }
              }
              else {
                  if (keyword.length>8) {
                      keywordValue=keyword.substring(8);
                      document.getElementById('keywordInput').value=keywordValue;
                  }
              }
          }
          //Detect keyword value end

          //Set active type
          if (typeValue!=0) {
              var types = document.getElementById('templateTypeMenu').getElementsByTagName('a');
                for(i=0;i<types.length;i++) {
                   var typeUrl = types[i].href;
                   var ti=typeUrl.indexOf("type=");
                   var menuType = typeUrl.substr(ti+5);
                   //Creating array of types
                   typesList[menuType]=types[i].innerHTML;
                   if (typeValue==menuType) {types[i].className='activeType';}
                }
          }

          //Set active category begin
          if (categoryValue!=0) {
               var categories = document.getElementById('templateCategoryMenu').getElementsByTagName('a');
                for(i=0;i<categories.length;i++) {
                   var categoryUrl = categories[i].href;
                   var ci=categoryUrl.indexOf("category=");
                   var menuCategory = categoryUrl.substr(ci+9);
                   //Creating array of categories
                   categoriesList[menuCategory]=categories[i].innerHTML;
                   if (categoryValue==menuCategory) {categories[i].className='activeCategory';}
                }
          }
          //Set active category end

          //Set searchResult title begin
          if (categoryValue!=0 || typeValue!=0) {
              if (categoryValue!=0 && typeValue!=0) {
              }
              else {
                  if (categoryValue!=0) {
                      document.getElementById('searchResultTitle').innerHTML=categoriesList[categoryValue];
                      document.title=html_entity_decode(categoriesList[categoryValue]);
                  }
                  else if (typeValue!=0) {
                      document.getElementById('searchResultTitle').innerHTML=typesList[typeValue];
                      document.title=html_entity_decode(typesList[typeValue]);
                  }
              }
          }
          //Set searchResult title end
    }
     
    function setSearchPage() {
        setActiveMenusForm();
    }
