
// Search Box Jscript v1.0 May 20 2009 by G.S. //



/* F.S. encoding functions for chinese characters */




var unreserved = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_.~";
var reserved = "!*'();:@&=+$,/?%#[]";
var allowed = unreserved + reserved;
var hexchars = "0123456789ABCDEFabcdef";




// This function returns a percent sign followed by two hexadecimal digits.
// Input is a decimal value not greater than 255.
function gethex(decimal) {
  return "%" + hexchars.charAt(decimal >> 4) + hexchars.charAt(decimal & 0xF);
  }

function encode(toEncode,encodingType) {
  var decoded = toEncode;
  var encoded = "";

  // ---------------- If ASCII character encoding was chosen: ----------------

  if (encodingType == "ascii") {

    // Remember non-ASCII characters, which will not be encoded:
    var notascii = "";

    for (var i = 0; i < decoded.length; i++ ) {
      var ch = decoded.charAt(i);
      // Check if character is an unreserved character:
      if (unreserved.indexOf(ch) != -1) {
        encoded = encoded + ch;
      } else {
        // If position in the Unicode table is smaller than 128, then we have
        // an ASCII character:
        var charcode = decoded.charCodeAt(i);
        if (charcode < 128) {
          encoded = encoded + gethex(charcode);
        } else {
          encoded = encoded + ch;
          notascii = notascii + ch + " ";
        }
      }
    }

    // Display warning message if necessary:
    if (notascii != "") alert("Warning: Non-ASCII characters in decoded text!\n\nThus, these characters have not been encoded:\n" + notascii);
  }

  // ---------------- If UTF-8 character encoding was chosen: ----------------

  if (encodingType == "utf8") {
    for (var i = 0; i < decoded.length; i++ ) {
      var ch = decoded.charAt(i);
      // Check if character is an unreserved character:
      if (unreserved.indexOf(ch) != -1) {
        encoded = encoded + ch;
      } else {

        // The position in the Unicode table tells us how many bytes are needed.
        // Note that if we talk about first, second, etc. in the following, we are
        // counting from left to right:
        //
        //   Position in   |  Bytes needed   | Binary representation
        //  Unicode table  |   for UTF-8     |       of UTF-8
        // ----------------------------------------------------------
        //     0 -     127 |    1 byte       | 0XXX.XXXX
        //   128 -    2047 |    2 bytes      | 110X.XXXX 10XX.XXXX
        //  2048 -   65535 |    3 bytes      | 1110.XXXX 10XX.XXXX 10XX.XXXX
        // 65536 - 2097151 |    4 bytes      | 1111.0XXX 10XX.XXXX 10XX.XXXX 10XX.XXXX

        var charcode = decoded.charCodeAt(i);

        // Position 0 - 127 is equal to percent-encoding with an ASCII character encoding:
        if (charcode < 128) {
          encoded = encoded + gethex(charcode);
        }

        // Position 128 - 2047: two bytes for UTF-8 character encoding.
        if (charcode > 127 && charcode < 2048) {
          // First UTF byte: Mask the first five bits of charcode with binary 110X.XXXX:
          encoded = encoded + gethex((charcode >> 6) | 0xC0);
          // Second UTF byte: Get last six bits of charcode and mask them with binary 10XX.XXXX:
          encoded = encoded + gethex((charcode & 0x3F) | 0x80);
        }

        // Position 2048 - 65535: three bytes for UTF-8 character encoding.
        if (charcode > 2047 && charcode < 65536) {
          // First UTF byte: Mask the first four bits of charcode with binary 1110.XXXX:
          encoded = encoded + gethex((charcode >> 12) | 0xE0);
          // Second UTF byte: Get the next six bits of charcode and mask them binary 10XX.XXXX:
          encoded = encoded + gethex(((charcode >> 6) & 0x3F) | 0x80);
          // Third UTF byte: Get the last six bits of charcode and mask them binary 10XX.XXXX:
          encoded = encoded + gethex((charcode & 0x3F) | 0x80);
        }

        // Position 65536 - : four bytes for UTF-8 character encoding.
        if (charcode > 65535) {
          // First UTF byte: Mask the first three bits of charcode with binary 1111.0XXX:
          encoded = encoded + gethex((charcode >> 18) | 0xF0);
          // Second UTF byte: Get the next six bits of charcode and mask them binary 10XX.XXXX:
          encoded = encoded + gethex(((charcode >> 12) & 0x3F) | 0x80);
          // Third UTF byte: Get the last six bits of charcode and mask them binary 10XX.XXXX:
          encoded = encoded + gethex(((charcode >> 6) & 0x3F) | 0x80);
          // Fourth UTF byte: Get the last six bits of charcode and mask them binary 10XX.XXXX:
          encoded = encoded + gethex((charcode & 0x3F) | 0x80);
        }

      }

    }  // end of for ...
	return encoded;
  }
}

/* End encoding */


// Keyword search
function tasto_key(){
var browser=navigator.appName;
if (browser!="Microsoft Internet Explorer"){
document.searchbox.q.onkeyup = function(event){
codice = (event)?event.keyCode:window.event.keyCode;
if(codice==13){
    stop();
    var encodedValue = encode(document.searchbox.q.value,"utf8");
    popup_sel("../../com/search/search.jsp?q="+encodedValue+"&entqr=3&entsp=a&output=xml_no_dtd&sort=date:D:L:d1&client=ST_China_frontend_v2&ud=1&oe=UTF-8&ie=UTF-8&proxystylesheet=ST_China_frontend_v2&site=ST_COM|NEW_ST_CHINA");
}
}
}
}

function tasto_part(){
var browser=navigator.appName;
if (browser!="Microsoft Internet Explorer"){
document.searchbox.pnumber.onkeyup = function(event){
codice = (event)?event.keyCode:window.event.keyCode;
if(codice==13){
    stop();
    popup_sel("../../com/xref/crossref.jsp?partNum="+document.searchbox.pnumber.value);
}
}
}
}

function tasto_cross(){
var browser=navigator.appName;
if (browser!="Microsoft Internet Explorer"){
document.searchbox.standard.onkeyup = function(event){
codice = (event)?event.keyCode:window.event.keyCode;
if(codice==13){
    stop();
   popup_sel("../../com/xref/crossref.jsp?partNum="+document.searchbox.standard.value);
}
}
}
}

function bottone (){
if (document.searchbox.q.value!="\u5173\u952E\u5B57")
{
    var encodedValue2 = encode(document.searchbox.q.value,"utf8");
    popup_sel("../../com/search/search.jsp?q="+encodedValue2+"&entqr=3&entsp=a&output=xml_no_dtd&sort=date:D:L:d1&client=ST_China_frontend_v2&ud=1&oe=UTF-8&ie=UTF-8&proxystylesheet=ST_China_frontend_v2&site=ST_COM|NEW_ST_CHINA");
}
else
{ 
 if (document.searchbox.pnumber.value!="\u4EA7\u54C1\u578B\u53F7")
	 popup_sel("/stonline/stappl/productcatalog/app?page=productSelector&search="+document.searchbox.pnumber.value);
    else
	if (document.searchbox.standard.value!="\u76F8\u4E92\u53C2\u7167")
	    popup_sel("../../com/xref/crossref.jsp?partNum="+document.searchbox.standard.value);
}
}


function keyword_focus()
{
if(document.searchbox.q.value=='\u5173\u952E\u5B57')
{
document.searchbox.q.value='';
document.searchbox.q.style.color= '#028ac8';
document.searchbox.standard.value='\u76F8\u4E92\u53C2\u7167';
document.searchbox.standard.style.color= '#666666';
document.searchbox.pnumber.value='\u4EA7\u54C1\u578B\u53F7';
document.searchbox.pnumber.style.color= '#666666';

//document.searchbox.target= "mia";
//document.searchbox.action = 'javascript:popup_sel(\'http://www.st.com/search/?q=\'+document.searchbox.q.value)';
//document.searchbox.action = 'java-script:popup_sel(\'http://www.st.com/search?q=\'+document.searchbox.standard.value+\'&entqr=3&entsp=a&&output=xml_no_dtd&sort=date:D:L:d1&client=ST_COM_frontend&ud=1&oe=&&UTF-8&ie=&UTF-8&proxystylesheet=ST_COM_frontend&site=ST_COM\')';
//document.searchbox.action ="http://www.st.com/search?q="+document.searchbox.standard.value+"&entqr=3&entsp=a&&output=xml_no_dtd&sort=date:D:L:d1&client=ST_COM_frontend&ud=1&oe=&&UTF-8&ie=&UTF-8&proxystylesheet=ST_COM_frontend&site=ST_COM";
}
}



function keyword_change()
{
document.searchbox.entqr.disabled=false;
document.searchbox.entsp.disabled=false;
document.searchbox.output.disabled=false;
document.searchbox.sort.disabled=false;
document.searchbox.client.disabled=false;
document.searchbox.ud.disabled=false;
document.searchbox.oe.disabled=false;
document.searchbox.ie.disabled=false;
document.searchbox.proxystylesheet.disabled=false;
document.searchbox.site.disabled=false;
}

function keyword_blur()
{
if(document.searchbox.q.value=='')
{
document.searchbox.q.value='\u5173\u952E\u5B57';
document.searchbox.q.style.color= '#666666';
}
}



// Part number search
function pn_focus()
{
if(document.searchbox.pnumber.value=='\u4EA7\u54C1\u578B\u53F7');
{
document.searchbox.pnumber.value='';
document.searchbox.pnumber.style.color= '#028ac8';
document.searchbox.standard.value='\u76F8\u4E92\u53C2\u7167';
document.searchbox.standard.style.color= '#666666';
document.searchbox.q.value='\u5173\u952E\u5B57';
document.searchbox.q.style.color= '#666666';
//document.searchbox.target= "mia";
//document.searchbox.action = 'javascript:popup_sel(\'http://www.st.com/stonline/bin/pnsearch/?search=\'+document.searchbox.pnumber.value)';
//document.searchbox.action ="http://www.st.com/stonline/bin/pnsearch/?search="+document.searchbox.pnumber.value;
document.getElementById('pnumber').name = 'search'
}
}

function pn_change()
{
document.searchbox.entqr.disabled=true;
document.searchbox.entsp.disabled=true;
document.searchbox.output.disabled=true;
document.searchbox.sort.disabled=true;
document.searchbox.client.disabled=true;
document.searchbox.ud.disabled=true;
document.searchbox.oe.disabled=true;
document.searchbox.ie.disabled=true;
document.searchbox.proxystylesheet.disabled=true;
document.searchbox.site.disabled=true;
}

function pn_blur()
{
if(document.searchbox.pnumber.value=='')
{
document.searchbox.pnumber.value='\u4EA7\u54C1\u578B\u53F7';
document.searchbox.pnumber.style.color= '#666666'
}
}




// Cross Reference search
function xref_focus()
{
if(document.searchbox.pnumber.value=='\u76F8\u4E92\u53C2\u7167');
{
document.searchbox.standard.value='';
document.searchbox.standard.style.color= '#028ac8';
document.searchbox.pnumber.value='\u4EA7\u54C1\u578B\u53F7';
document.searchbox.pnumber.style.color= '#666666';
document.searchbox.q.value='\u5173\u952E\u5B57';
document.searchbox.q.style.color= '#666666';
//document.searchbox.target= "mia";
//document.searchbox.action = 'javascript:popup_sel(\'http://www.st.com/stonline/bin/xsearch/?standard=\'+document.searchbox.standard.value)';
//document.searchbox.action = "http://www.st.com/stonline/bin/xsearch/?standard="+document.searchbox.standard.value;
}
}

function xref_change()
{
document.searchbox.entqr.disabled=true;
document.searchbox.entsp.disabled=true;
document.searchbox.output.disabled=true;
document.searchbox.sort.disabled=true;
document.searchbox.client.disabled=true;
document.searchbox.ud.disabled=true;
document.searchbox.oe.disabled=true;
document.searchbox.ie.disabled=true;
document.searchbox.proxystylesheet.disabled=true;
document.searchbox.site.disabled=true;
}

function xref_blur()
{
if(document.searchbox.standard.value=='')
{
document.searchbox.standard.value='\u76F8\u4E92\u53C2\u7167';
document.searchbox.standard.style.color= '#666666'
}
}


