tplsAd = {

    skipWords : ["pe", "la", "si", "de", "ori", "sau", "ce", "fi", "cand", "in", "sub", "am", "care", "cine", "cu", "ci", "nu"],
    skipTags  : ["NOADS", "A", "SELECT", "SCRIPT", "IFRAME", "COMMENT", "TEXTAREA", "NOSCRIPT", "STYLE"],    
    nodes:[], 
    words:[],   
    adWords:[],
    nodeWords:[],	
    bubble :"",
    tap:"",
    cssClass: "tlsHighlight",
    inlineCssColor: "#99CC33",
    serverUrl: "http://www.afiliati.ro",
    sendWordsScriptUrl: "http://www.afiliati.ro/affiliates/scripts/sendWords.php",
    adWordsScriptUrl:   "http://www.afiliati.ro/affiliates/scripts/getWords.php",
    cssHref : "http://www.afiliati.ro/affiliates/views/contextual.css",
    imagesUrl: "http://www.afiliati.ro/affiliates/images/affiliates/bubble/afiliati/",
    affiliatesScript: "http://www.afiliati.ro/affiliates/scripts/search.php?feedType=html&adSpaceId=",
    adSpaceId :"",
    
    maxAdWidth: 300,
    maxAdHeight: 200,
    screenWidth: "",
    screenHeight: "",     
    tapHDirection:"",
    tapVDirection:"",
    tapPosition:0.3,
    posx:0, 
    posy:0,
    
    cornerTopWidth: 14,    
    cornerTopHeight: 33,
    cornerBottomWidth: 14,    
    cornerBottomHeight: 20,    
    tapHeight: 39,
    tapWidth: 23,
    iFrameWidth:[],
    iFrameHeight:[],
    currentWidth: 200,
    currentHeight: 70,
    logoWidth: 72,    
    logoHeight: 17,    
    buttonWidth: 17,    
    buttonHeight: 17, 
    mouseDistance: 10,
    
    pageParser: 
        function()
        { 			
			this.iFrameWidth[1] = 200;
			this.iFrameWidth[2] = 200;
			this.iFrameWidth[3] = 200;
			this.iFrameWidth[4] = 200;
			this.iFrameWidth[5] = 300;
			this.iFrameWidth[6] = 300;
			
			this.iFrameHeight[1] =  70;
			this.iFrameHeight[2] = 200;
			this.iFrameHeight[3] = 200;
			this.iFrameHeight[4] = 200;
			this.iFrameHeight[5] = 100;
			this.iFrameHeight[6] = 100;
			
			this.adSpaceId = tplsAdSpaceId;
            this.getNodes(document.body);
            this.getWords();            
            this.iframePost();
            setTimeout("tplsAd.callBack()", 2000);
        },   
        
    getNodes:            
        function(currentNode)
        {        	
            if(currentNode.nodeType == 3 && this.trim(currentNode.nodeValue))             					 //text node
            {
                this.nodes.push(currentNode);
                this.nodeWords.push("");
            }
            else
                if(currentNode.nodeType == 1 && !this.inArray(currentNode.nodeName, this.skipTags))           //element node
                {       
                    var node = currentNode.firstChild;      
                    while (node != null)
                    {
                        this.getNodes(node);
                        node = node.nextSibling;
                    } 
                }
        },

    getWords:
        function()
        {
           var n = this.nodes.length;
           var separators = "\\x21-\\x26\\x28-\\x2c\\x2f\\x3a-\\x40\\x5b-\\x5e\\x7b-\\x7f\\x27\\x2d\\x2e\\x5f\\x60";
                      
           for (var i = 0; i < n; i++) 
           {
                var node       = this.nodes[i];
                var nodeVal    = node.nodeValue.toLowerCase();
                nodeVal 	   = this.replace(nodeVal);

                var regExp 	   = new RegExp("\\s*[" + separators + "]+\\s*|\\s+["+separators+"] + \\s * | ["+separators+"] + \\s + | \\s * ["+separators+"] + $","g");
                var wordRegExp = new RegExp("\\s+", "g");
                var tempWords  	= nodeVal.split(regExp);
                var currentWords  = [];
                for (var j = 0; j < tempWords.length; j++)
                {
                	if(tempWords[j])
                	{
                		var sWord = tempWords[j].split(wordRegExp);
              	
                		for (var k = 0; k < sWord.length; k++)
                			if (this.trim(sWord[k]))
                			{                 		                				
                				currentWords.push(this.trim(sWord[k]));
                			}
                	}
                }
                var wordIndex = 0;           
                
                for (var j = 0; j < currentWords.length; j++)
                {
                    var word = this.trim(currentWords[j]);
 
                    if (word)
                    {
                    	var temp = parseInt(word);
                    	if(isNaN(temp))
                    	{
	                        if (word && !this.inArray(word, this.skipWords) && word.length > 2)
	                        {                     	
	                            if (!(this.words[word] && this.words[word].nodeIndex))
	                                this.words[word] = { nodeIndex:[], startPos:[], lastIndex:0};	
	                            
	                        	this.words[word].nodeIndex.push(i);
	                            
	                            var start = nodeVal.indexOf(word);
	                            wordIndex += start;
	                            this.words[word].startPos.push(wordIndex);
	                            wordIndex += word.length;                          
	                            nodeVal = nodeVal.substring(start + word.length); 
	                        }
                    	}    
                    }                    
                }           
           }   
        },
  
	createCorner:
		function (parent, position)
		{
			var attributes = new Object();
			attributes["style"] = "border:0px;padding:0px; margin:0px;display:block; vertical-align:middle;";
			
			switch (position)
			{
				case 0: url = this.imagesUrl + "nw.png"; attributes["style"] += "height:" + this.cornerTopHeight + "px;";attributes["style"] += "width:" + this.cornerTopWidth + "px";break;
				case 1: url = this.imagesUrl + "ne.png"; attributes["style"] += "height:" + this.cornerTopHeight + "px;";attributes["style"] += "width:" + this.cornerTopWidth + "px";break;
				case 2: url = this.imagesUrl + "sw.png"; attributes["style"] += "height:" + this.cornerBottomHeight + "px;";attributes["style"] += "width:" + this.cornerBottomWidth + "px";break;
				case 3: url = this.imagesUrl + "se.png"; attributes["style"] += "height:" + this.cornerBottomHeight + "px;";attributes["style"] += "width:" + this.cornerBottomWidth + "px";break;
			}
			attributes["src"] = url;
			i = this.createObject(parent, "img", attributes, null);	
		},
  
	createTap:
		function (parent, adType)
		{
			var attributes = new Object();	
			
			var bubbleWidth  = this.iFrameWidth[adType]  + 2 * this.cornerTopWidth;       	
        	var bubbleHeight = this.iFrameHeight[adType] + this.cornerBottomHeight + this.cornerTopHeight;
        	var tapPos 		 = this.tapPosition * bubbleWidth;				
			var leftIndex  = (this.tapHDirection == 1) ? tapPos : (bubbleWidth - tapPos) ;
			leftIndex += this.posx ;
			var topIndex   = (this.tapVDirection == 1) ? (this.posy + 8) : (bubbleHeight + this.posy - 5) ;			
			//topIndex = bubbleHeight + this.posy - 3;
			
			attributes["style"]  = " border:0px; padding:0px; margin:0px; position:absolute; z-index=101;";
			attributes["style"] += " height:" + this.tapHeight + "px;";
			attributes["style"] += " width:"  + this.tapWidth + "px;";
			attributes["style"] += " top:" +  topIndex + "px;";
			attributes["style"] += " left:" +  leftIndex + "px;";
			attributes["src"]    = this.imagesUrl + ((this.tapVDirection==2) ? "stap.png" : "ntap.png");

			this.tap = this.createObject(parent, "img", attributes, null);			
		},
		
    createCloseButton:
		function (parent)
		{
			var attributes = new Object();
			var events = new Object();
			attributes["style"] = "border:0px;margin-top:-3px;cursor:pointer; right:10px; z-index:100; float:right; position:absolute; vertical-align:top;";
			attributes["style"] += "height:" + this.buttonHeight + "px;";
			attributes["style"] += "width:"  + this.buttonWidth + "px;";
			
			attributes["src"] = this.imagesUrl + "close.png";
			events["click"] = "tplsAd.removeBubble();";

			i = this.createObject(parent, "img", attributes, events);
		},

    createQuestionButton:
		function (parent)
		{
			var attributes = new Object();
            attributes["href"] = this.serverUrl;			
			attributes["style"]  = "z-index:100;float:right; margin-top:-3px; position:relative; margin-right:15px; vertical-align:top";
			
            attributes["target"] = "blank"; 
            a = this.createObject(parent, "a", attributes, null);
            
   			var attributes = new Object(); 
			attributes["style"] = "border:0px; vertical-align:top;";
			attributes["style"] += "height:" + this.buttonHeight + "px;";
			attributes["style"] += "width:"  + this.buttonWidth + "px;";
			
			attributes["src"] = this.imagesUrl + "info.png";           
			i = this.createObject(a, "img", attributes, null);
		},
            
    createAffliatesLogo:
        function (parent)
        {
			var attributes = new Object();

            attributes["href"] = this.serverUrl;			
			attributes["style"] = "z-index:100;float:left; margin-top:-2px; position:relative; margin-left:-5px; vertical-align:top";
		
            attributes["target"] = "blank"; 
            a = this.createObject(parent, "a", attributes, null);
            
   			var attributes = new Object(); 
			attributes["style"] = "border:0px; vertical-align:top;";
			attributes["src"] = this.imagesUrl + "logo.png";  
			attributes["style"] += "height:" + this.logoHeight + "px;";
			attributes["style"] += "width:"  + this.logoWidth + "px;";				
			i = this.createObject(a, "img", attributes, null);   
        },
    
    createUhostAd:
        function (parent)
        {
			var attributes = new Object();

            attributes["href"] = "http://www.afiliati.ro/affiliates/scripts/hit.php?uic=25360&type=sale";			
			attributes["style"] = "font-size:10px;font-family:Arial,Verdana;padding-top:5px;font-weight:bolder; text-decoration:none;float:right;color:#FFF";
		
            attributes["target"] = "blank"; 
            a = this.createObject(parent, "a", attributes, null);
            
   			var attributes = new Object(); 
			attributes["style"] = "border:0px; vertical-align:top;";
			attributes["src"] = "http://www.afiliati.ro/affiliates/scripts/creative.php?uic=25360&imageType=1&type=sale";  
			i = this.createObject(a, "img", attributes, null);
			
			a.innerHTML = "gazduit de uhost.ro";
        },
        
    createContent:
		function (parent, currentWord, adId, adType)
		{		
            var attributes = new Object();        	
            attributes["src"] = this.affiliatesScript + this.adSpaceId + "&q=" + currentWord + "&adId=" + adId;

            attributes["scrolling"] = "no";              
            attributes["frameBorder"] = "0";             
            attributes["border"] = "0";                    
            attributes["style"] = "height: " + this.iFrameHeight[adType] + "px; width: " + this.iFrameWidth[adType] + "px;padding:0px; margin:0px;left:0px; top:0px;position:relative";
    
			frame = this.createObject(parent, "iframe", attributes, null);			
		},
  
    createCell:
		function (oTR, cellIndex, style, rowIndex)
		{
			var oTD = oTR.insertCell(cellIndex);
			oTD.style.cssText = style;
			if (rowIndex == 0)
    			oTD.setAttribute("vAlign", "middle");
			else
    			oTD.setAttribute("vAlign", "top");

			return oTD;
		},
    	
    createTableRows:
		function createTableRows(oTbl,currentWord, adId, adType)
		{           
		//First line
			oTR = oTbl.insertRow(0);			

			style  = "padding:0px; vertical-align:middle;";
			oTD = this.createCell(oTR, 0, style, 0);
			this.createCorner(oTD, 0);
         
			style = "background:url(" + this.imagesUrl + "n.png" + ")  repeat;padding:0px; vertical-align:middle;";
			oTD = this.createCell(oTR, 1, style, 0);
			this.createAffliatesLogo(oTD);
            this.createQuestionButton(oTD);
			this.createCloseButton(oTD);

			style = "padding:0px; vertical-align:middle;";
			oTD = this.createCell(oTR, 2, style, 0);
			this.createCorner(oTD, 1);

		//Second line
			oTR = oTbl.insertRow(1);		

			style = "background:url(" + this.imagesUrl + "w.png" + ") repeat-y;padding:0px;";
			oTD = this.createCell(oTR, 0, style, 1);		
			oTD.innerHTML = "&nbsp;";

			style = "background-color:white;padding:0px;text-align:justify";
			oTD = this.createCell(oTR, 1, style, 1);
			this.createContent(oTD, currentWord, adId, adType);

			style = "background:url(" + this.imagesUrl + "e.png" + ") repeat-y;padding:0px;";
			oTD = this.createCell(oTR, 2, style, 1);		
			oTD.innerHTML = "&nbsp;";	
			
		//Third line
			var oTR = oTbl.insertRow(2);

			style = "padding:0px;";
			oTD = this.createCell(oTR, 0, style, 1);			
			this.createCorner(oTD, 2);

			style = "background:url(" + this.imagesUrl + "s.png" + ")  repeat-x;padding:0px;";
			oTD = this.createCell(oTR, 1, style, 1);
			this.createUhostAd(oTD);
			//oTD.innerHTML = "&nbsp;";

			style = "padding:0px;";
			oTD = this.createCell(oTR, 2, style, 1);
			this.createCorner(oTD, 3);					
		},
    
     createTable:
        function(parent, currentWord, adId, adType)
        {
        	var attributes = new Object();
        	attributes["cellPadding"] = "0";
        	attributes["cellSpacing"] = "0";
        	attributes["border"] = "0";
        	attributes["width"] = "100%";

        	oTbl = this.createObject(parent, "Table", attributes, null);
        	this.createTableRows(oTbl, currentWord, adId, adType);		
        },

    getDivPosition:
		function (e, adType)
		{
        	var bubbleWidth  = this.iFrameWidth[adType]  + 2 * this.cornerTopWidth;
        	var bubbleHeight = this.iFrameHeight[adType] + this.cornerTopHeight + this.cornerBottomHeight + this.tapHeight;
        	var tapPos 		 = this.tapPosition * bubbleWidth;
        	
			this.getScreenDimensions();
			var xy = this.getMousePosition(e);
			
			mx = xy[0]; my = xy[1];

			if (mx + bubbleWidth - tapPos <= this.screenWidth)
			{	
				this.tapHDirection = 1;
				posx = (mx - tapPos >= 0) ? mx - tapPos : 0;  
			}	
			else
			{
				this.tapHDirection = 2;
				posx = (mx + bubbleWidth - tapPos <= this.screenWidth) ? mx - bubbleWidth + tapPos : (this.screenWidth - bubbleWidth);				
			}

			if (my + bubbleHeight + this.tapHeight <= this.screenHeight)
			{	
				posy = my  + this.mouseDistance;
				this.tapVDirection = 1;
			}	
			else
			{
				posy = my - bubbleHeight - this.mouseDistance;
				this.tapVDirection = 2;
			}

			return [posx, posy];			
		},
           
    removeBubble:        
        function ()
        {
        	if (this.bubble)
        		document.body.removeChild(this.bubble);	
        	if (this.tap)
        		document.body.removeChild(this.tap);

        	this.bubble = null;
        	this.tap = null;
        },
                         
    drawBubble:
        function(e)
        {
        	var attributes  = new Object();
        	var ieVar   	= "srcElement";
        	var mozVar 		= "target";
        	
        	var currentWord = e[mozVar] ? tplsAd.replace(e[mozVar].innerHTML) : tplsAd.replace(e[ieVar].innerHTML);
        	var adId 		= e[mozVar] ? e[mozVar]["linkAdId"]   : e[ieVar]["linkAdId"];
        	var adType 		= e[mozVar] ? e[mozVar]["linkAdType"] : e[ieVar]["linkAdType"];        	        	    		
    		
            if (!e) e = window.event;
        	if (tplsAd.bubble) tplsAd.removeBubble();  
            tplsAd.browser.getBrowserType();            
            
    		var xy = tplsAd.getDivPosition(e, adType);    	
    		tplsAd.posx = xy[0]; tplsAd.posy = xy[1];
	       	
    		topIndex = tplsAd.posy;
    		if (tplsAd.tapVDirection == 1)
    			topIndex += tplsAd.tapHeight;
	       	attributes["style"]  = "position:absolute;z-index:100;left:" + tplsAd.posx + "px; top:" + topIndex + "px;";	       	
	       	attributes["style"] += "width:"  + (tplsAd.iFrameWidth[adType]  + 2 * tplsAd.cornerTopWidth)  + "px;"; 
	       	attributes["style"] += "height:" + (tplsAd.iFrameHeight[adType] + tplsAd.cornerTopHeight + tplsAd.cornerBottomHeight) + "px;";
	  	
        	tplsAd.bubble = tplsAd.createObject(document.body, "div", attributes, null);
    		tplsAd.createTable(tplsAd.bubble, currentWord, adId, adType);
    		tplsAd.createTap(document.body, adType);        		
        },
        
    linksFactory:
        function(response)
        {
        	this.adWords = response.split(";");
  	
        	var attributes = new Object();
	       	attributes["rel"]  = "stylesheet";     
	       	attributes["type"] = "text/css";
	       	attributes["href"] = this.cssHref;
            this.createObject(document.getElementsByTagName("head")[0], "link", attributes, null);
            
            this.chooseNodes();
            this.sortByPosition();
            this.underline();
        },
    
    underline:
        function()
        {
            var n = this.nodes.length; 
            
            for (var i = 0; i < n; i++)
            {        
                 if (this.nodeWords[i])
                 {                 
                    var currentNode 	= this.nodes[i];
                    var currentNodeWord = this.nodeWords[i];
                    var nodeVal 		= currentNode.nodeValue;
                    var m 				= currentNodeWord.length;
                    var attributes 		= new Object();
                    var events	 		= new Object();
                    var currentPos, prevPos = 0;                    

                    for (var j = 0; j < m; j++)
                    {
                        currentPos  = currentNodeWord[j].startPos;
                        prefixNode = document.createTextNode(nodeVal.substring(prevPos, currentPos));
                        currentNode.parentNode.insertBefore(prefixNode, currentNode);                    

                        var wrd  = currentNodeWord[j].word;                        
                        newValue = nodeVal.substring(currentPos, currentPos + currentNodeWord[j].word.length);                        
                        newNode  = document.createTextNode(newValue);
                        newElement = document.createElement("a");
                        attributes["href"] = "#";                        
                       // attributes["style"] = "text-decoration:none;color:" + this.inlineCssColor;
                        attributes["style"] = "display:inline;font-weight:bold;text-decoration:none;border-bottom:3px double " + ((this.adSpaceId == 25593) ? "#FF0000" : "green") + ";color:" + ((this.adSpaceId == 25593) ? "#FF0000" : "green");
                        this.setAttr(newElement, attributes);
                        //newElement.className = this.cssClass;       
                        
                		if (newElement.addEventListener)
                			newElement.addEventListener("mouseover", tplsAd.drawBubble, false);
                		else if (newElement.attachEvent)
                				newElement.attachEvent("onmouseover", tplsAd.drawBubble);                        

                   		newElement.linkAdId    = currentNodeWord[j].adId;
                   		newElement.linkAdType  = currentNodeWord[j].adType;
            			
                        newElement.appendChild(newNode);                                                                        
                        currentNode.parentNode.insertBefore(newElement, currentNode); 

                        prevPos = currentPos + currentNodeWord[j].word.length;                        
                    }
                    if (prevPos < nodeVal.length)
                    {
                    	newValue = nodeVal.substring(prevPos, nodeVal.length);
                    	newNode = document.createTextNode(newValue);
                    	currentNode.parentNode.insertBefore(newNode, currentNode);
                    }	

                    currentNode.parentNode.removeChild(currentNode);
                 }
            }            
        },
            
    sortPos:
        function (x, y)
        {
            if (x.startPos > y.startPos) return 1;
            if (x.startPos < y.startPos) return -1;
            return 0;
        },
        
    sortByPosition:
        function()
        {
            var n = this.nodeWords.length;           
            for (i = 0; i < n; i++)
            {        
                 if (this.nodeWords[i])
                 {
                    this.nodeWords[i] = this.nodeWords[i].sort(this.sortPos);
                 }
            }  
        },
  
    chooseNodes:
        function()
        {
            var words, word, wordCount;           
            var n = this.adWords.length;            

            for (var k = 0; k < n; k++)
            {
                words = this.adWords[k].split(":");
                word  = this.trim(words[0]);
                aId   = words[1];
                aType = words[2];
                
                if(word && this.words[word])
                {
                    var j  = this.words[word].lastIndex;
                    nodeI  = this.words[word].nodeIndex[j];
                    startP = this.words[word].startPos[j];

                    if (this.nodeWords[nodeI] == '')
                        this.nodeWords[nodeI] = [];                                              
                    this.nodeWords[nodeI].push({word:word, startPos:startP, adId:aId, adType:aType});
                    this.words[word].lastIndex++;                                       
                 }
            }
        },

    getQueryString:
        function()
        {  		
        	var queryString = "";

            for (k in this.words) 
            {
            	if (typeof this.words[k] != 'function')		//adaugat datorita includerii prototype.js in site-ul clientului
            		if (this.words[k].nodeIndex && this.words[k].nodeIndex.length)
            			queryString = queryString + k + ":" + this.words[k].nodeIndex.length + ";";            	
            }

            return queryString;     
        },
           
    callBack:
    	function()
    	{
        	var attributes = new Object();
        	attributes["src"]  = this.adWordsScriptUrl;
        	attributes["type"] = "text/javascript";
        	var script = this.createObject(document.getElementsByTagName('head')[0], "script", attributes, null, null);
    	},
          	
	iframePost : 
		function()
        {
        	var queryString = this.getQueryString();       
        	
        	var attributes 		= new Object();
        	attributes["name"] 	= "tplsIFrame";
        	attributes["id"]   	= "tplsIFrame";
        	attributes["style"] = "position:absolute; left: -5000px; top: -5000px; visibility: hidden";        	        	
        	var iframe 	  		= this.createObject(document.body, "iframe", attributes, null);                  	        	
            var iframeWin 		= self.frames["tplsIFrame"];
            var iframeDoc 		= iframeWin.document;                        
            var tmo	   	  		= setTimeout("tplsAd.removeObject(document.body, 'tplsIFrame')", 1000);
               
            if( ! iframeDoc.body)
            {	
                var body = iframeDoc.createElement("body");
            	iframeDoc.appendChild(body);
            }	
            else
            	body = iframeDoc.body;
          
            var attributes 		  = new Object();
            attributes["name"] 	  = "tplsPostForm";
            attributes["action"]  = this.sendWordsScriptUrl;
            attributes["method"]  = "post";
            var form 			  = this.createObject(body, "form", attributes, null, iframeDoc);                    
            var attributes 		  = new Object();            
            attributes["name"]    = "words";
            attributes["type"]    = "hidden";
            attributes["value"]   = queryString;
            var input 			  = this.createObject(form, "input", attributes, null, iframeDoc);              

            form.submit();     
        },
        
    createObject:
    	function (parent, tag, attributes, events, doc)
        {
        	if (!doc) doc = document;
	      	var obj = doc.createElement(tag);
	       	if (attributes)
			     this.setAttr(obj, attributes);		       	
	       	if (events)
			     this.setEvents(obj, events);            
            if (parent)
            	parent.appendChild(obj);
            
            return obj;
	   },
      
	removeObject:
		function (parent, objId)
		{
		   var ok = false;
           var obj = document.getElementById(objId);
           if(obj)
           {
        	   parent.removeChild(obj);
        	   ok = true;
           }		   
           
           return ok;
		},
			
    setAttr:          
    	function (obj, attributes)
    	{
    		for (k in attributes)
    		{
    			if (k == "style")
    			{
    				if( typeof(obj.style.cssText) == 'string' )
    				{
    					obj.style.cssText = attributes[k];
    				}			
    			}	
  				obj.setAttribute(k, attributes[k]);
    		}
    	},

    setEvents:
    	function (obj, events)
    	{
    		if (events != null)
    		{
    			for (k in events)
    			{
    				if (typeof events[k] != 'function')			//adaugat datorita includerii prototype.js in site-ul clientului
    					this.addEvent(obj, k, events[k]);
    			}	
    		}
    	},

	// Add an eventListener to browsers that can do it somehow.
	// Originally by Scott Andrew.
	addEvent:
    	function (obj, evType, fn)
    	{
    		if (typeof(fn) == "string")
    		{
	    		if (obj.addEventListener)
	    		{
	    			obj.addEventListener(evType, new Function(fn), false);
	    			return true;
	    		} else if (obj.attachEvent)
	    			{
		      			var r = obj.attachEvent("on"+evType, new Function(fn));
		      			return r;
		       		} else 
			      	{
				     	return false;
	                }
    		}	
    	},

    getMousePosition:
    	function (event) 
    	{           
 
    		if (this.browser.isIE) 
    		{
    			x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
    			y = window.event.clientY + document.documentElement.scrollTop  + document.body.scrollTop;
    		}
    		if (this.browser.isNS) 
    		{
    			x = event.clientX + window.scrollX;
    			y = event.clientY + window.scrollY;
    		}

    		return [x,y];
    	},	

	// Determine browser and version.
	browser:
    {
        isIE :"",        
        isNS :"",
        version:"",
            
        getBrowserType:
            function()
            {
        		var ua, s, i;

        		this.isIE    = false;
        	   	this.isNS    = false;
        	   	this.version = null;

        		ua = navigator.userAgent;

        		s = "MSIE";
	         	if ((i = ua.indexOf(s)) >= 0) 
	          	{
	           		this.isIE = true;
	       	       	this.version = parseFloat(ua.substr(i + s.length));
	       	    }
                else
                {
                    s = "Netscape6/";
                    if ((i = ua.indexOf(s)) >= 0)
                    {
                        this.isNS = true;
                        this.version = parseFloat(ua.substr(i + s.length));
                    }
                    else
                    {
                        // Treat any other "Gecko" browser as NS 6.1.
                        s = "Gecko";
                        if ((i = ua.indexOf(s)) >= 0) 
                        {
                            this.isNS = true;
                            this.version = 6.1;
                        }
                        else
                        {
                        	s = "Opera";
                            if ((i = ua.indexOf(s)) >= 0) 
                            {
                                this.isNS = true;
                                this.version = parseFloat(ua.substr(i + s.length + 1,4));
                            }                        	
                        }
                    }	
                }
        }
    },

    getScreenDimensions:
    	function ()
    	{              	
	     	if(this.browser.isNS == true )		             //Non-IE
	   	    {
		    	this.screenWidth  = window.innerWidth  + window.scrollX;
		    	this.screenHeight = window.innerHeight + window.scrollY;
            }
            else 
            {
			  if(document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight )) 
                {//IE 6+ in 'standards compliant mode'												  
				  	this.screenWidth = document.documentElement.clientWidth;
				  	this.screenHeight = document.documentElement.clientHeight;			
                }
                else 
				    if(document.body && ( document.body.clientWidth || document.body.clientHeight )) 
    				{//IE 4 compatible					    								
				    	this.screenWidth = document.body.clientWidth;
				    	this.screenHeight = document.body.clientHeight;				
    				}
			  	this.screenWidth  += document.documentElement.scrollLeft + document.body.scrollLeft;
			  	this.screenHeight += document.documentElement.scrollTop  + document.body.scrollTop;
            }		
        },
        
    inArray:
        function (needle, haystack)    
        {            
            for(var i = 0; i < haystack.length; i++)
                if(haystack[i] == needle)
                    return true;
            return false;            
        },

    trim:
        function (str) 
        {
            if (str)
                return str.replace(/^\s+|\s+$/g,"");
        },
        
    replace:
    	function (str)
    	{
        	str	= str.replace(new RegExp("\\x103", "g"), "a");
        	str	= str.replace(new RegExp("ã", "g"), "a");
        	str	= str.replace(new RegExp("â", "g"), "a");
        	str	= str.replace(new RegExp("\\xE2", "g"), "a");
        	str	= str.replace(new RegExp("\\xE3", "g"), "a");
        	str	= str.replace(new RegExp("\\xEE", "g"), "i");
        	str	= str.replace(new RegExp("î", "g"), "a");
        	
        	str	= str.replace(new RegExp("\\x15F", "g"), "s");
        	str	= str.replace(new RegExp("º", "g"), "s");
        	
        	str	= str.replace(new RegExp("\\x163", "g"), "t");
            str	= str.replace(new RegExp("þ", "g"), "t"); 
    
            return str;
    	}
};

tplsAd.pageParser();

