//------------------------------------------------------------------------Categories RUN------------------------------------------------------------------------------------------------------------------------------------------------------------- 

var timerID = null;
var nOption = 0;
var Arr=new Array()
var sLast=0
var LastText=""

var tt=""

var pp="http://www.topxtop.com/frames/"
var pp2="http://www.topxtop.com"
	
//var pp="http://LocalHost/site_WinHTTP/frames/"
//var pp2="http://LocalHost/site_WinHTTP"
	
//to unicode	
 function ToUnicode(unicode)
	{

     var tstr = unicode
     var bstr = '';
      for(i=0; i < tstr.length; i++)
      {
       //if(tstr.charCodeAt(i)>127) 
       // {
         bstr += '&#' + tstr.charCodeAt(i) + ';';
       // } 
      //else 
      // {
      //  bstr += tstr.charAt(i);
      // }
      }
      return (bstr);
	  
    }	 

//trim
function Trim(stringToTrim) 
{
	return stringToTrim.replace(/^\s*|\s*$/g ,"");
}

// scroll categories in search
function initScrollCategories(xx)
 {
    tt=xx
	var p
	var q = document.body.innerHTML
	if(q!="")
	{	
		var qq=q
		q=q.toUpperCase()
		var p=q.indexOf('<DIV ID="XSCRIPT">')+18
		if (p==17) p=q.indexOf('<DIV ID=XSCRIPT>')+16
		qq=qq.substring(p , qq.length)
		q=qq.toUpperCase()
		qq=qq.substring(0,q.lastIndexOf("</DIV>")-6)	
		
		var x= new RegExp("&amp;","g")
		p=qq.replace(x,"&")
		Arr=p.split(";;")
		if (LastText!="")
			{
				document.getElementById("idSearchText").value=LastText
				sLast=1
			} 

		if (sLast==0 ) 	startclock();
	}	
 }

 
 //timer list cattgories in search
function startclock()
	{
		++nOption
		if (nOption<Arr.length-1)
			{
				document.getElementById("idSearchText").value =Trim(Arr[nOption])
			}  
		else
			{
				nOption = 0;
			}

		timerID = setTimeout("startclock()",2000)
	}

// search lost focus new timer	
function xBlur()
     {
	   if (document.getElementById("idSearchText").value =="")  
	    {
	     startclock()
		 sLast=0
		} 
     }	 	

//clear from search	
function xFocus()
	{
	  if (sLast==0)
	   {
	    document.getElementById("idSearchText").value =""
	    clearTimeout(timerID);
	   }	
	}

	
function PressSearchEnter(e)
 {
 	//enter
	if(e.keyCode==13 || e=='13')  
		{
			if (document.getElementById("idSearchText").value!="")
				{
					sLast=1
					//window.open(pp2 + "/index_1.asp?a=1&IDCLIENT=" + tt + "&search=1&keyword=" + encodeURIComponent(document.getElementById("idSearchText").value) + "&keyword2=" + encodeURIComponent(ToUnicode(document.getElementById("idSearchText").value)))
					//document.F2.method="post" 
					document.F2.action=pp2 + "/index_1.asp?a=1&IDCLIENT=" + tt + "&search=1&keyword=" + encodeURIComponent(document.getElementById("idSearchText").value) + "&keyword2=" + encodeURIComponent(ToUnicode(document.getElementById("idSearchText").value))
					//document.F2.target="_blank"
					//document.F2.submit()
					return true
				}	
		}	
	else if (e.keyCode!=13 && e!='13')  
		{
			sLast=1
		}
	 
	else if (document.getElementById("idSearchText").value=="") sLast=0					
 }

 
 

 // id for new  record in grid
 function NewId()
 {
	var d = new Date()
	var rr=new String(d.getFullYear().toString() + d.getMonth().toString() + d.getDay().toString() + d.getHours().toString() + d.getMinutes().toString() + d.getSeconds().toString() + d.getMilliseconds().toString() + d.getUTCDate().toString())
	return (rr)
 }

//----------------------------------------------------------------------------------------------Our Window--------------------------------------------------------------------------------------------------------------------------------------- 
//create new frame for client
function createFrame()
 {
	var xx= window.location.hostname 
   	var p=pp + "getData.asp?Param=5&DATA1=" + idClient  + "&DATA2=" + idScript + "&DATA3=" + xx.toString() 
	var c2=NewId()+NewId()
	
	switch (idScript)
	{
	case "1":	
		document.write('<div><iframe id="' + c2 + '" width="174px" height="79px"  frameborder="0"  scrolling="no" src="' + p + '"></iframe></div>');
	break;

	case "2":
		document.write('<div><iframe id="' + c2 + '" width="174px" height="95px"  frameborder="0"  scrolling="no" src="' + p + '"></iframe></div>');
	break;

	case "3":
		document.write('<div><iframe id="' + c2 + '" width="174px" height="104px"  frameborder="0"  scrolling="no" src="' + p + '"></iframe></div>');
	break;

	case "6":
		document.write('<div><iframe id="' + c2 + '" width="200px" height="124px"  frameborder="0"  scrolling="no" src="' + p + '"></iframe></div>');
	break;
	}
  }	


