 
//The JS code foe the MouseOver functionality 
//Once the result is retrieved then the text is displayed as a Tooltip. Another library is used.
//Author: Rajeesh Koroth
//Created on : 11/08/2008
//Modified on: 04/07/2009
//Added support for "App Note:" string multi-lang support. 

//Define  the http object and other variables.
//var http_request = false;
var url = false;
var qr_str = false;
var timeout_id;
var http_request;

var oldXY;

function remToolTip() {
	
	window.ondragdrop = UnTip();

}
//The Browser identification and create the correct object.
function createRequestObject() {

      var http_req = false;

      if (window.ActiveXObject) { // IE

        	try {
         		http_req = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
         		try {
		               http_req = new ActiveXObject("Microsoft.XMLHTTP");
            		} catch (e) {
//				return false;	
			}
       		}
      }
      else if (window.XMLHttpRequest) { // Mozilla, IE7, Safari,...

                http_req = new XMLHttpRequest();
                if (http_req.overrideMimeType) {
                        http_req.overrideMimeType('text/html');
                }

      }

      //Failed on createing the request.	
      if (!http_req) {
      	alert('Cannot create XMLHTTP instance');
	return false;
      }	

return http_req;
}

// Define the Hash keys and values to send the Query the corresponding domain.maxim-ic.com based on the lang selection.
// Firfox/ Mozilla throws the error if the domain part in the url is different than the url passed to the "open" method.
var domain_name = { cn : 'cn',
		    kr : 'korea',
		    jp : 'japan',
		    en : 'www'
		  };

//The base url.	 	
var ajx_path = "/app_notes/abstract/wsi/abstract.ajax";

//Catch string.
var catch_str;
var loading_str;
var app_notes;

//Create the http request asynchronizly.
http_request = createRequestObject();

//This function is being called by the mouseOver.
//The App Note ID,  Lang, Error Strings, Loading String and App Note String.
function sndReq(e, id, lang, catch_string, loading_string, appnote_string) {

var new_url; 

   if ( document.domain == 'www.maxim-ic.com.cn') {
    // Construct the url part.	
    new_url = "http://www.maxim-ic.com.cn" + ajx_path;
		
   }
   else {
    new_url = "http://" + domain_name[lang] + ".maxim-ic.com" + ajx_path;
   }
	
    // This last parameter of "ms" is useful for avoid caching in IE. 
    // This will mimic that the query string/ url is different on each  request.
   qr_str = "id="+id+"&lang="+lang+"&ms="+new Date().getTime();

   catch_str = CFString.decode(catch_string);	
   loading_str = CFString.decode(loading_string);	
   app_notes = trim(CFString.decode(appnote_string));	

   //The title  constuction per see lang.	
   switch (lang) {
	case 'jp': app_notes = app_notes; break;  
	case 'kr': app_notes = app_notes + ' '; break;
	case 'cn': app_notes = app_notes; break; 
	default  : app_notes = app_notes + ' ';  
   }	  

   oldXY = getXY(e);

   try {
    	http_request.open('GET', new_url + "?" + qr_str, true);
	http_request.onreadystatechange = handleResponse;
	http_request.send(null);

    	} catch(err) {
	 Tip(catch_str);
	 http_request.abort();
   }	
}//End of sndReq

function timesUp() {
	http_request.abort();
}

//The callback method which ndow.onmousemovereceives the response content and peroform further actions.
function handleResponse() {
    
	try {	//Outer catch.
	    	// If the response has completed.	
		if (http_request.readyState == 4) {
		
			try { //Inner catch.
				// If the response is successful.
				if( http_request.status == 200) {

					// The Mason code respond with a string. No XML handling.
			        	var response_det = http_request.responseText.split("|");
					printResponse(response_det[0], response_det[1], response_det[2], response_det[3]);	
				}
			} catch(err) {
				//Tip(response_det[0], WIDTH, 300, CLOSEBTN, true, FIX, [oldXY.x, oldXY.y]);
	                	//http_request.abort();

			} //End of Inner catch.
        	}// End of readyState == 4.

		// Shows the loading messages.
	        else if(http_request.readyState == 1){
			
			Tip('<b>'+loading_str+'</b>'+'<img src=http://www.maxim-ic.com/dev/rajeeshk/an-abstract/ajax-loader.gif>', BORDERWIDTH, 0, DELAY, 0, HEIGHT, 20, WIDTH, 120, TEXTALIGN, 'right', BGCOLOR, '#FFFFFF', SHADOWCOLOR, '#DAD4D0');

		} //End of http_request.readyState == 1.	
    	} catch(err) {
                         Tip(catch_str, WIDTH, 250, CLOSEBTN, true, FIX, [oldXY.x, oldXY.y]);
                         http_request.abort();

     	} //End of Outer catch 

}//End of handleResponse.

//Show the App Notes.
function printResponse(response, width_param, id, resp_ln) {

	var w_val = trim(width_param);
	resp_ln = trim(resp_ln);
	var appnote_and_id; 

	//return;
	if (resp_ln == 'en') {

		appnote_and_id = 'App Note: ' + id;		
	}	
	else {
		appnote_and_id = (app_notes + trim(id) ) || "";
	}

	var resp_word_count = response.split(" ");
	// May use for the control of no of char
	// var tip_duration = ((resp_word_count.length * 3) * 1000);

	Tip(response, FOLLOWMOUSE, false, JUMPVERT , false, JUMPHORZ, true, DELAY, 50, WIDTH, eval(w_val), CLOSEBTN, true, TITLE, appnote_and_id, FIX, [oldXY.x, oldXY.y], DURATION, 600000);
}

//Trim all spaces.
function trim(s) {
	var temp = s;
	return temp.replace(/^\s+/,'').replace(/\s+$/,'');
}

function getMousePos(event) { //you need the 'e', although it does NOT need to be defined

  var x = event.pageX;
  var y = event.pageY;

  var newXY = new Object();
  newXY.x = x;
  newXY.y = y;

  var x = document.getElementById('x');
  var y = document.getElementById('y');

   x.innerHtml = x;
   y.innerHtml = y;

return newXY;

}

function getXY(e)
{
	var x,y;
	e = e || window.event;
	if (navigator.appName.indexOf('Microsoft') != -1)
	{
		var parent = e.srcElement;
		x=e.clientX + document.body.scrollLeft;
		y=e.clientY + document.body.scrollTop;
	}
	else
	{
		var parent = e.target;
		x =e.pageX
		y= e.pageY
	}

	var XY = new Object();
	XY.x = x;
	XY.y = y;

return XY;
}

function encode_utf8( s )
{
  return unescape( encodeURIComponent( s ) );
}

function decode_utf8( s )
{
  return decodeURIComponent( escape( s ) );
}

var CFString = {

    // public method for url encoding
    encode : function (string) {
        return escape(this._utf8_encode(string));
    },

    // public method for url decoding
    decode : function (string) {
        return this._utf8_decode(unescape(string));
    },

    // private method for UTF-8 encoding
    _utf8_encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // private method for UTF-8 decoding
    _utf8_decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

}
