﻿
// =====================================================
// SEARCH BOX FUNCTIONS
// =====================================================
function NestleSearch()
{		
	if (mysearch())
	{
		document.forms[0].action = "http://searches.nestle.co.jp/";
		document.forms[0].submit();
	}	
}

function EnterSearchBox() {
	var val = document.forms[0].kw;
	if (val) {
		if (val.value.toLowerCase() == "keyword") {val.value = "";}
	}
}
function LeaveSearchBox() {


	var val = document.forms[0].kw;
	if (val) {
		if (val.value == "") 
			{val.value = "keyword";}		
	}

}
/*
// Do search...
function DoSearch() {

	var val = document.forms[0].kw;	
	if (val) {
		url = "/jp.09purina.template/Utility/SearchResults.aspx?stext="+(encodeURI(val.value));	
		document.location = url;		
	}
	
}
*/
// Catch enter key for search submission
function CatchEnter(event) {

	if ((window.event && window.event.keyCode == 13) || 
		(event && event.which == 13)) {
		NestleSearch();
	} else {
		return true;
	}
	return false;
}
// =====================================================

// BEGIN RSS 

 var http_request = false;
  function makeRequest(url) {

    http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
           http_request.overrideMimeType('text/xml');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
		
		http_request.onreadystatechange = alertContents;
		
		http_request.open('GET', url, true);
		http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");	
		http_request.setRequestHeader("Connection", "close");
		http_request.send(null);	

  }
  

  function alertContents() {	

    if (http_request.readyState == 4) {
      if (http_request.status == 200) {   			
			xmlMicoxRSS(http_request); 
      } else {
        alert('There was a problem with the request.');        
      }
    }   
    
  }
  
  
  function xmlMicoxRSS(xmlNode){
	
		 //by Micox: http://elmicoxcodes.blogspot.com
		 var retorno = 	"<table width='100%'  cellspacing='0' callpadding='0'  ><tr height=2><th></th><td></td></tr>";
	
		 var xmlDocument;
		 
		if (window.XMLHttpRequest) { // Mozilla, Safari,...
			 xmlDocument = xmlNode.responseXML;
         }
		if (window.ActiveXObject)//IE
		{						               
			    xmlDocument = new ActiveXObject('Microsoft.XMLDOM');
			    xmlDocument.async = false;
			    	    
                //The responseText is loaded into XML document
			    xmlDocument.loadXML(xmlNode.responseText);
		}

		 var objNodeList = xmlDocument.getElementsByTagName('item');
	
		 for(var i=0;i<objNodeList.length;i++){
		  var strTitulo = ""
		  var strURL = ""
		  var strpubDate = ""
		  var objNode = objNodeList[i];
		  if(objNode.nodeType == 1){//ignore white spaces
		   for(var j=0;j<objNode.childNodes.length;j++){
		    var objNode2 = objNode.childNodes[j];
		    if(objNode2.nodeType == 1){//ignore white spaces
		     switch (objNode2.nodeName) {
		      case "title": 	
		       strTitulo = objNode2.firstChild.nodeValue; 
		       break;
		      case "link": 
		       strURL = objNode2.firstChild.nodeValue; 
		       break;
		      case "pubDate": 
		       strpubDate = objNode2.firstChild.nodeValue; 
		       break;
		     }
		    }
		   }
		   
		   retorno += "<tr><th class=rssText width=150 height=30 nowrap>"+  strpubDate + "</th><td class=rssText><a target=_blank href='" + strURL + "'>" + strTitulo + "</a></td></tr>";
		  }
		 }
		 retorno +=  "</table>";		 
		 document.getElementById('div_alvo').innerHTML= retorno;		 
	}
 
   function getRSSInterval(){
   
		setInterval('getRSS()',30*60*1000); 
   }
   
   function getRSS(){			
		makeRequest('/jp.09purina.template/Utility/outputRSS.aspx'); //load xml
   }  
/// END RSS

