
var FCS = 
{
    Ver: "0.5",
    Browser:
    {
        IE:!!(window.attachEvent && !window.opera),
        IE6: false /*@cc_on || @_jscript_version < 5.7 @*/,
        Opera:  !!window.opera,
        FF:  navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1
    }
}     

//Global Objects

function Hash()
{
    
	this.Length = 0;
	this.Items = new Array();
	//this.SortFunc ;
	for (var i = 0; i < arguments.length; i += 2) {
		if (typeof(arguments[i + 1]) != 'undefined') {
			this.Items[arguments[i]] = arguments[i + 1];
			this.Length++;
		}
	}
    this.Reset  = function()
    {
        Length = 0;
        this.Items = new Array();
    }
	this.RemoveItem = function(Key)
	{
		var tmp_value;
		if (typeof(this.Items[Key]) != 'undefined') {
			this.Length--;
			var tmp_value = this.Items[Key];
			delete this.Items[Key];
		}
	   
		return tmp_value;
	}

	this.GetItem = function(Key) {
		return this.Items[Key];
	}

	this.SetItem = function(Key, value)
	{
		if (typeof(value) != 'undefined') {
			if (typeof(this.Items[Key]) == 'undefined') {
				this.Length++;
			}

			this.Items[Key] = value;
		}
	   
		return value;
	}

	this.HasItem = function(Key)
	{
		return typeof(this.Items[Key]) != 'undefined';
	}
	this.Each = function(iterator)
	{
	    for (i in this.Items)
	    {
	        if(typeof(this.Items[i])=="function") continue;
	        iterator(this.Items[i]);
	    }
        
	}
	this.Sort = function(ConFunction)
	{
	    this.SortFunc = ConFunction;
	    //alert(this.SortFunc);
	    var IndexArr = new Array();
	    for (i in this.Items)
	    {
	        if(typeof(this.Items[i])=="function") continue;
	        IndexArr.push([i,this.Items[i]]);
	    }
	    IndexArr.sort(ConFunction);
	    this.Reset();
	    for(var i=0; i<IndexArr.length;i++)
	    {
	        this.Items[IndexArr[i][0]] = IndexArr[i][1];
	    }
	    this.Length = IndexArr.length;
	}
	
	
};

//Global Functions
    Object.extend = function(destObj, srcObj) 
    {
		for (var property in srcObj)
		{
			try
			{	
				destObj[property] = srcObj[property];
			}
			catch(e)
			{
				throw(e);
			}
		}
		return destObj;
    };
        
    function SetCookie_(KeyName,value,expiredays)
    {
        expiredays = expiredays||7;
        var exdate=new Date();
        exdate.setDate(exdate.getDate()+expiredays);
        document.cookie=KeyName+ "=" +escape(value)+ (";expires="+exdate.toGMTString()+";path=/");
    };

    function GetCookie(KeyName)
    {
        if (document.cookie.length>0)
          {
          c_start=document.cookie.indexOf(KeyName + "=");
          if (c_start!=-1)
            { 
            c_start=c_start + KeyName.length+1; 
            c_end=document.cookie.indexOf(";",c_start);
            if (c_end==-1) c_end=document.cookie.length;
            return unescape(document.cookie.substring(c_start,c_end));
            } 
          }
        return "";
    };
    
// Element functions
var PrototypeEleFuncs = 
{
    GetWidth:function(){return this.offsetWidth},
    SetClass:function(ClassName){this.className = ClassName},
    ReplaceInClass:function(strFind,strReplace){this.className = this.className.replace(strFind,strReplace)},
    GetClass:function(){return this.className},
    SetVisible:function(visible){this.style.display=visible?"inline":"none"},
    IsVisible:function(){return this.style.display=="none"?false:true},
    SetVisibility:function(visible){this.style.visibility=visible?"visible":"hidden"},
    Show:function(){this.style.display ="";},
    Hide:function(){this.style.display ='none';},
    Toggle:function(){this.style.display=this.style.display=="none"?"":"none";},
    Focus:function(){if(this.tagName.toLowerCase()!="input") return; this.focus(); this.select();},
    ToggleChk:function(){if(this.tagName.toLowerCase()!="input") return; this.checked = !this.checked},
    RegisterEvt: function(EventType,Listener){
        return new Event.RegisEvent(this,EventType,Listener,false,false);
    },
    GetData:function(key)
    {
        return this.getAttribute("data-" + key);
    },
    Pos:function()
    {
        var obj = this;
        	var curleft = curtop = 0;
            if (obj.offsetParent) 
            {
            do {
			            curleft += obj.offsetLeft;
			            curtop += obj.offsetTop;
            } while (obj = obj.offsetParent);
            }
	            return [curleft,curtop];
    }
};

//prototype Array Function
var PrototypeArrayFuncs = 
    {
    IndexOf:function(obj)
        {
            for(var i=0; i<this.length; i++)
            {
                if(this[i]==obj){return i;}
            }
            return -1;
	        
	    },
	Each:function(fun)
	{
	    var len = this.length;
        if (typeof fun != "function")
          throw new TypeError();

        var thisp = arguments[1];
        for (var i = 0; i < len; i++)
        {
          if (i in this)
            fun.call(thisp, this[i], i, this);
        }
	},
	Delete:function(index)
	{
	    this.splice(index,1);
	}
    };

//Objects functions
var GlobalObjFuncs = 
{
        GetCookieObj:function(KeyName)
                    {
                        return JSON.parse(GetCookie(KeyName));
                    },
        GetCookie:function(KeyName)
            {
                return GetCookie(KeyName);
            },
        IsSet:function(obj)
                 {
                    return((typeof(obj)=='undefined' || obj.length==0)?false:true);
                 },
        Clone:function(object)
            {
                if(object) 
                    return Object.extend({},object);
                else
                    return Object.extend({},this);
            }
        
};
var PrototypeObjFuncs = {};
    
    String.prototype.SetCookie=function(KeyName,expiredays)
                {
                    expiredays=expiredays||7
                    SetCookie_(KeyName,this,expiredays);
                };
    Number.prototype.SetCookie = String.prototype.SetCookie;
    Boolean.prototype.SetCookie = String.prototype.SetCookie;
    String.prototype.IsNumber = function(){return !isNaN(this)};
    

var PrototypeStringFuncs = 
{
    Trim:function() {
   return this.replace(/^\s+|\s+$/g,"");},

    AddAsScript:function(){
            setTimeout("var myscript = document.createElement('script'); myscript.text = \""+this+"\";document.body.appendChild(myscript);",50);
                        },
    AddAsScriptURL: function()
                        {
            setTimeout("var myscript = document.createElement('script'); myscript.src = '"+this+"'; document.body.appendChild(myscript);",50);
                        },
    Include: function(subStr) 
                        {
    return this.indexOf(subStr) > -1;
                        }
};
var GlobalStringFuncs = 
                    {
                    Format:function(str)
                        {      
                        for(var i = 1; i < arguments.length; i++)
                          {
                            str = str.replace(new RegExp('\\{' + (i - 1) + '\\}',"g"), arguments[i]);
                            
                          }
                        return str;
                        },
                    FormatTemplate:function(template,dataObject, isUsingIndex)
                    {
                        if(dataObject.length)
                        {
                            for(var j=0;j<dataObject.length;j++)
                            {
                                for(i in dataObject[j])
	                              {
		                              if(isUsingIndex == true)
		                                template  = template.replace(new RegExp('\\{' + j + '.' + (i) + '\\}',"g"), dataObject[j][i]);
		                              else
		                                template  = template.replace(new RegExp('\\{' + (i) + '\\}',"g"), dataObject[j][i]);
		                              if(i =="AutoInc") dataObject[j][i]++;
	                              }
	                        }
		                  return template;
                        }
                        
                        for(i in dataObject)
		                  {
		                        var replaceText = dataObject[i];
	                            if(replaceText =="{auto}") replaceText = "1";
		                        template  = template.replace(new RegExp('\\{' + (i) + '\\}',"g"), replaceText);
                			
		                  }
		                  return template;
                    },
                    FormatTemplateRepeat:function(template,ArrObject,Index,MergObj)
                    {
                        var result = "";
                        var start=Index?Index[0]:0;
                        var end=Index?Index[1]:ArrObject.length-1;
                        for(var i=start;i<=end;i++)
                        {
                            if(MergObj)
                            result+= this.FormatTemplate(template,[ArrObject[i],MergObj]);
                            else
                            result+= this.FormatTemplate(template,ArrObject[i]);
                        }
                        return result;
                    }
                    };

var GlobalDateFuncs = {
    AddDays:function(DateValue,DayValue)
    {
       var D = DateValue.getDate();
       return new Date(DateValue.setDate(D+ parseInt(DayValue)));
    },
    FormatDate:function(inputDate,Mask) 
    {

	    var FormattedDate = "";
	    var MaskChars = "DMY";

		    // Convert any supported simple masks into "real" masks
	    switch (Mask) {
		    case "short":
			    Mask = "M/D/YY";
		    break;
		    case "medium":
			    Mask = "MMM D, YYYY";
		    break;
		    case "long":
			    Mask = "MMMM D, YYYY";
		    break;
		    case "full":
			    Mask = "DDDD, MMMM D, YYYY";
		    break;
	    };

		    // Tack a temporary space at the end of the mask to ensure that the last character isn't a mask character
	    Mask += " ";

		    // Parse the Mask
	    var CurChar;
	    var MaskPart = "";
	    for ( var Cnt = 0; Cnt < Mask.length; Cnt++ ) {
			    // Get the character
		    CurChar = Mask.charAt(Cnt);
			    // Determine if the character is a mask element
		    if ( ( MaskChars.indexOf(CurChar) == -1 ) || ( MaskPart != "" && CurChar != MaskPart.charAt(MaskPart.length - 1) ) ) {
				    // Determine if we need to parse a MaskPart or not
			    if ( MaskPart != "" ) {
					    // Convert the mask part to the date value
				    switch (MaskPart) {
					    case "D":
						    FormattedDate += inputDate;
						    break;
					    case "DD":
						    FormattedDate += ("0" + inputDate.getDate()).slice(-2);
						    break;
					    case "DDD":
						    FormattedDate += Ref_DayAbbreviation[inputDate.getDay()];
						    break;
					    case "DDDD":
						    FormattedDate += Ref_DayFullName[inputDate.getDay()];
						    break;
					    case "M":
						    FormattedDate += inputDate.getMonth() + 1;
						    break;
					    case "MM":
						    FormattedDate += ("0" + (inputDate.getMonth() + 1)).slice(-2);
						    break;
					    case "MMM":
						    FormattedDate += Ref_MonthAbbreviation[inputDate.getMonth()];
						    break;
					    case "MMMM":
						    FormattedDate += Ref_MonthFullName[inputDate.getMonth()];
						    break;
					    case "YY":
						    FormattedDate += ("0" + inputDate.getFullYear()).slice(-2);
						    break;
					    case "YYYY":
						    FormattedDate += ("000" + inputDate.getFullYear()).slice(-4);
						    break;
				    };
					    // Reset the MaskPart to nothing
				    MaskPart = "";
			    };
				    // If the char is a mask char, start a new mask part, otherwise, dump it to the output
			    if ( MaskChars.indexOf(CurChar) > -1 ) {
				    MaskPart = CurChar;
			    } else {
				    FormattedDate += CurChar;
			    };
		    } else {
				    // Add the current mask character to the MaskPart
			    MaskPart += CurChar;
		    };
	    };

		    // Remove the temporary space from the end of the formatted date
	    FormattedDate = FormattedDate.substring(0,FormattedDate.length - 1);

		    // Return the formatted date
	    return FormattedDate;

    },
    ConvertDate:function(dateStr, sFormat)
    {
        var format = "MDY";
        if(sFormat.substring(0,1)=="D")
            format = "DMY";
        else
            if(sFormat.substring(0,1)=="Y")
                format = "YMD";
       
       if (format.substring(0, 1) == "Y") { // If the year is first
          var reg1 = /^\d{2}(\-|\/|\.)\d{1,2}\1\d{1,2}$/
          var reg2 = /^\d{4}(\-|\/|\.)\d{1,2}\1\d{1,2}$/
       } else if (format.substring(1, 2) == "Y") { // If the year is second
          var reg1 = /^\d{1,2}(\-|\/|\.)\d{2}\1\d{1,2}$/
          var reg2 = /^\d{1,2}(\-|\/|\.)\d{4}\1\d{1,2}$/
       } else { // The year must be third
          var reg1 = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{2}$/
          var reg2 = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/
       }
       // If it doesn't conform to the right format (with either a 2 digit year or 4 digit year), fail
       if ( (reg1.test(dateStr) == false) && (reg2.test(dateStr) == false) ) { return false; }
       var parts = dateStr.split(RegExp.$1); // Split into 3 parts based on what the divider was
       // Check to see if the 3 parts end up making a valid date
       if (format.substring(0, 1) == "M") { var mm = parts[0]; } else 
          if (format.substring(1, 2) == "M") { var mm = parts[1]; } else { var mm = parts[2]; }
       if (format.substring(0, 1) == "D") { var dd = parts[0]; } else 
          if (format.substring(1, 2) == "D") { var dd = parts[1]; } else { var dd = parts[2]; }
       if (format.substring(0, 1) == "Y") { var yy = parts[0]; } else 
          if (format.substring(1, 2) == "Y") { var yy = parts[1]; } else { var yy = parts[2]; }
       if (parseFloat(yy) <= 50) { yy = (parseFloat(yy) + 2000).toString(); }
       if (parseFloat(yy) <= 99) { yy = (parseFloat(yy) + 1900).toString(); }
       var dt = new Date(parseFloat(yy), parseFloat(mm)-1, parseFloat(dd), 0, 0, 0, 0);
       if (parseFloat(dd) != dt.getDate()) { return false; }
       if (parseFloat(mm)-1 != dt.getMonth()) { return false; }
       return dt;
    }

}

Date.prototype.AddDays = function (days) 
    {
        var d = new Date(this.getTime())
        d.setDate (d.getDate() + days)
        return d
    }
//Object.extend(Object.prototype,PrototypeObjFuncs);
Object.extend(Object,GlobalObjFuncs);
Object.extend(Date,GlobalDateFuncs);
Object.extend(String.prototype,PrototypeStringFuncs);
Object.extend(String,GlobalStringFuncs);
Object.extend(Array.prototype,PrototypeArrayFuncs);





//////////////////////////////////
// func global functions
//////////////////////////////////
function List()
    {
        var nCount=0;
        var lstItems={};
        return {
        Count:function(){return nCount;},
        IsExists:function(key){return (key in lstItems)},
        Add:function(Item,Value)
        {
            //if(typeof(Item)=="undefined") Item = "undefined";
            //if(typeof(Value)=="undefined") Value = "undefined";
			var value = Value?Value:Item;
            if(Item in lstItems) return false;
            lstItems[Item] = value;
            nCount++;
            return true;
        },
        AddRange:function(Arr)
        {
            for(var i=0;i<Arr.length;i++)
            {
                this.Add(Arr[i],Arr[i]);
            }
        },
        AddList:function(lstInput,IsRemoveOldItems)
        {
            if(IsRemoveOldItems) this.RemoveAll();
            var Values = lstInput.GetAll();
            var Keys    = lstInput.GetAllKeys();
            for(var i=0;i<Values.length;i++)
            {
                this.Add(Keys[i],Values[i]);
            }
        }
        ,
        GetAllKeys:function(){
            var result = new Array();
            for(var i in lstItems)
            {
                result.push(i);
            }
            return result;
        }
        ,
        GetAll:function(){
            var result = new Array();
            for(var i in lstItems)
            {
                result.push(lstItems[i]);
            }
            if(isNaN(result[0]))
                result.sort();
            else
                result.sort(function(a,b){ return a-b;});
            return result;
        },
        GetItem:function(Key)
        {
            if(Key in lstItems)
            return lstItems[Key]
            else
            return null;
        },
		Remove:function(Key)
		{
			if(Key in lstItems)
			{
			delete lstItems[Key];
			nCount--;
			return true;
			}
			else
			{
				return false;
			}
		},
		RemoveAll:function()
		{
			for(var Key in lstItems)
			{
			    delete lstItems[Key];
			    nCount--;
			}
		}
        };
    }
function $(element)
{
    var result = element;
    if(typeof(element)!="string")
    return Object.extend(result,PrototypeEleFuncs);
    
    if(document.getElementById(element)) 
    {
        result = document.getElementById(element);
        Object.extend(result,PrototypeEleFuncs);
        return result;       
    }
    else
    {
        throw("not found " + element + " [function $]");
    }
};
function $S(element)
{
   
    var result = element;
    if(typeof(element)=="string")
    {
        result = document.getElementById(element);
    }
    return result.style;
};
function GetSameItem(Arr1,Arr2)
{
    var result = [];
    var a = "";
    
    for(var i=0;i<Arr1.length;i++)
    {
        for(var j=0;j<Arr2.length;j++)
        {
            var e=0;
            if(Arr1[i].toLowerCase().Trim()==Arr2[j].toLowerCase().Trim()) 
            result.push(Arr1[i])
        }
    }
    return result;
};
//
function CalDayDuration(n) {
//n:milion seconds
                        var hms = "";
                        var dtm = new Date();
                        dtm.setTime(n);
                        var h = "000" + Math.floor(n / 3600000);
                        var m = "0" + dtm.getMinutes();
                        var s = "0" + dtm.getSeconds();
                        var cs = "0" + Math.round(dtm.getMilliseconds() / 10);
                        hms = h.substr(h.length-4) + ":" + m.substr(m.length-2) + ":";
                        hms += s.substr(s.length-2) + "." + cs.substr(cs.length-2);
                        return Math.round(h/24);
                }

function $$(elementid)
{
    if(document.getElementById(elementid))
    return true;
    return false;
};

function $T(tag)
{
    return document.getElementsByTagName(tag);
}; 
function $TN(tag, name) 
{
     var elem = document.getElementsByTagName(tag);
     var arr = new Array();
     for(i = 0,iarr = 0; i < elem.length; i++) {
          att = elem[i].getAttribute("name");
          if(att == name) {
               arr[iarr] = $(elem[i]);
               iarr++;
          }
     }
     return arr;
}

//Window.Page
//PreLoad

window.Page = {};
Object.extend(window.Page,
{
      Container:"window.Page",
      ScrollSpeech: 15,
      Interval:0,
      getScrollXY:function() 
     {
          var scrOfX = 0, scrOfY = 0;
          if( typeof( window.pageYOffset ) == 'number' ) {
            //Netscape compliant
            scrOfY = window.pageYOffset;
            scrOfX = window.pageXOffset;
          } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
            //DOM compliant
            scrOfY = document.body.scrollTop;
            scrOfX = document.body.scrollLeft;
          } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
            //IE6 standards compliant mode
            scrOfY = document.documentElement.scrollTop;
            scrOfX = document.documentElement.scrollLeft;
          }
          return [ scrOfX, scrOfY ];
        }
      ,
      PreLoadImage : function()
      {
	     for(var i=0;i< arguments.length;i++)
	     {
		    var ExcuteCode = "var tmpIMG = document.createElement(\"img\");tmpIMG.style.display = 'none';tmpIMG.src = \"" + arguments[i]+ "\";document.body.appendChild(tmpIMG)";
		    setTimeout(ExcuteCode,20);
	     }
      },
      PreloadHTML : function(HtmlContent)
      {
	      var ExcuteCode = "var tmpDiv = document.createElement(\"div\");tmpDiv.style.display = 'none';tmpDiv.innerHTML = \"" + HtmlContent +"\"; document.body.appendChild(tmpDiv);";
	      setTimeout(ExcuteCode,20);
      },

    //For Scroller  

      Scroll: function(elementid,speech)
      {
        if(window.Page.Interval!=0)//scrolling
        { 
            clearInterval(window.Page.Interval);
            window.Page.Interval=0;
        }
        var sp = speech?speech:this.ScrollSpeech; 
        window.Page.Interval = setInterval(this.Container+'.DoScroll('+this.Container+'.gy($("'+elementid+'")));',sp);
      },
      StopScroll: function(){
		clearInterval(window.Page.Interval);
		window.Page.Interval=0;
      },
      gy:function (d) 
      {
        gy = d.offsetTop
        if (d.offsetParent) while (d = d.offsetParent) gy += d.offsetTop
        return gy
        },
      scrollTop: function ()
        {
        body=document.body
        d=document.documentElement
        if (body && body.scrollTop) return body.scrollTop
        if (d && d.scrollTop) return d.scrollTop
        if (window.pageYOffset) return window.pageYOffset
        return 0
        },
      DoScroll: function(d)
      {
		if(window.Page.Interval==0)
			return;
        i = window.innerHeight || document.documentElement.clientHeight;
        h=document.body.scrollHeight;
        a = this.scrollTop()
        if(d>a)
        if(h-d>i)
        a+=Math.ceil((d-a)/this.ScrollSpeech)
        else
        a+=Math.ceil((d-a-(h-d))/this.ScrollSpeech)
        else
        a = a+(d-a)/this.ScrollSpeech;
        window.scrollTo(0,a)
        if(a==d || this.offsetTop==a)
        {
            
            clearInterval(window.Page.Interval)
            window.Page.Interval=0; 
        }
        this.offsetTop=a
      },
      SwitchPageStyle :function(css_title)
        {
          var i, linkItem ;
          for (i = 0, linkItem = document.getElementsByTagName("link") ;
            i < linkItem.length ; i++ ) {
            if ((linkItem[i].rel.indexOf( "stylesheet" ) != -1) &&
              linkItem[i].title) {
              linkItem[i].disabled = true ;
              if (linkItem[i].title == css_title) {
                linkItem[i].disabled = false ;
              }
            }
            css_title.SetCookie("PageTheme");
          }
        },
      LoadLastPageStyle : function()
        {
          var css_title = Object.GetCookie("PageTheme");
          if (css_title.length) {
            switch_style( css_title );
          }
        },
      GetWH:function(v) 
        { 
            var z=document.all?Array(document.body.clientHeight,document.body.clientWidth):Array(window.innerHeight,window.innerWidth); 
            return(Object.IsSet(v)?z[v]:z); 
        },
      ScrollerWidth:function() 
        {
            var scr = null;
            var inn = null;
            var wNoScroll = 0;
            var wScroll = 0;

            // Outer scrolling div
            scr = document.createElement('div');
            scr.style.position = 'absolute';
            scr.style.top = '-1000px';
            scr.style.left = '-1000px';
            scr.style.width = '100px';
            scr.style.height = '50px';
            // Start with no scrollbar
            scr.style.overflow = 'hidden';

            // Inner content div
            inn = document.createElement('div');
            inn.style.width = '100%';
            inn.style.height = '200px';

            // Put the inner div in the scrolling div
            scr.appendChild(inn);
            // Append the scrolling div to the doc
            document.body.appendChild(scr);

            // Width of the inner div sans scrollbar
            wNoScroll = inn.offsetWidth;
            // Add the scrollbar
            scr.style.overflow = 'auto';
            // Width of the inner div width scrollbar
            wScroll = inn.offsetWidth;

            // Remove the scrolling div from the doc
            document.body.removeChild(document.body.lastChild);

            // Pixel width of the scroller
            return (wNoScroll - wScroll);
        }
    }
);

///////////////////
// Util Libs
//////////////////
    //AjaxUtil
    function AjaxUtil()
    {
        this.http = false; //HTTP Object
	    this.format = 'text';
	    this.callback = function(data){};
	    this.error = false;
	    this.IsPost = false;
	    this.getHTTPObject = function() 
	    {
		    var http = false;
		    if(typeof ActiveXObject != 'undefined') {
			    try {http = new ActiveXObject("Msxml2.XMLHTTP");}
			    catch (e) {
				    try {http = new ActiveXObject("Microsoft.XMLHTTP");}
				    catch (e) {http = false;}
			    }
		    } else if (XMLHttpRequest) {
			    try {http = new XMLHttpRequest();}
			    catch (e) {http = false;}
		    }
		    return http;
	    };
    	
	    //	url	- Ex.'get.aspx?id=1&ac=9'
	    //	callback - Function that must be called once the data is ready.function(data){alert(data)}
	    //	format - The return type for this function. Could be 'xml','json' or 'text'. Default: "text"
	    this.Load = function (url,callback,param,format) 
	    {
		    this.init(); 
		    if(!this.http||!url) return;
		    if (this.http.overrideMimeType) this.http.overrideMimeType('text/xml');

		    this.callback= callback;
    		//this.timeout = timeout;
    		 var format = "json";
		    if(!format) format = "text";
		    this.format = format.toLowerCase();
		    var ths = this;//Closure
    		
		    //Kill the Cache problem in IE.
		    var now = "";
		    if(!format)
		    now = "uid=" + new Date().getTime();
		    url += (url.indexOf("?")+1) ? "&" : "?";
		    url += now;

		    this.http.open(this.IsPost?"POST":"GET",url, true);
		    this.http.onreadystatechange = function () {
			    if(!ths) return;
			    var http = ths.http;
			    
			        if (http.readyState == 4) 
			        {
				        if(http.status == 200) 
				        {
					        var result = "";
					        if(http.responseText) result = http.responseText;
					        if(ths.format.charAt(0) == "j") 
					        {
						        result = result.replace(/[\n\r]/g,"");
						        result = eval('('+result+')');
					        }
					        
					        if(ths.callback) ths.callback(result);
				        } 
				        else 
				        { 
					        if(ths.error) ths.error()
				        }
			        }
			    
		    }
		    
		    this.http.send(param?param:null);
	    };
	    this.init = function() 
	    {
	        this.abort();
	        this.http = this.getHTTPObject();
	    };
	    this.abort = function()
	    {    
            if(this.http && this.http.readyState!=4)
            {
                this.http.abort();
            }
	    }
    }


if (!window.Event) var Event = { };

Event.RegisEvent =function (elem, type, listener, useCapture, noAutoStart) //http://www.codehouse.com
{
   var proto = arguments.callee.prototype;

   this.ele = elem;
   this.type = type;
   this.cap = useCapture;
   this.l = listener;


   proto.start = function()
   {
      if( this.ele.attachEvent )
      {
         this.ele.attachEvent("on" + this.type, this.l);
      }
      else if( this.ele.addEventListener )
      {
         this.ele.addEventListener(this.type, this.l, this.cap);
      }
   }

   if( ! noAutoStart )
   {
      this.start(elem, type, listener);
   }

   proto.stop = function()
   {
      if( this.ele.detachEvent )
      {
          this.ele.detachEvent("on" + this.type, this.l);
      }
      else if( this.ele.removeEventListener )
      {
          this.ele.removeEventListener(this.type, this.l, this.cap);
      }
   }
};
Event.RegisterEvt= function(Element,EventType,Listener)
            {
                return new Event.RegisEvent(Element,EventType,list,false,false);
            };

var Validator = Object.extend({},
{
    IsNumeric:function(sText)
    {
       var ValidChars = "0123456789.,"; 
       var IsNumber=true;
       var Char;
     
       for (i = 0; i < sText.length && IsNumber == true; i++) 
       { 
            Char = sText.charAt(i); 
            if (ValidChars.indexOf(Char) == -1) 
            {
                IsNumber = false;
            }
       }
       return IsNumber;
    },

    IsValidDate:function(dateStr, sFormat)
    {
        var format = "MDY";
        if(sFormat.substring(0,1)=="d")
            format = "DMY";
        else
            if(sFormat.substring(0,1)=="y")
                format = "YMD";
       
       if (format.substring(0, 1) == "Y") { // If the year is first
          var reg1 = /^\d{2}(\-|\/|\.)\d{1,2}\1\d{1,2}$/
          var reg2 = /^\d{4}(\-|\/|\.)\d{1,2}\1\d{1,2}$/
       } else if (format.substring(1, 2) == "Y") { // If the year is second
          var reg1 = /^\d{1,2}(\-|\/|\.)\d{2}\1\d{1,2}$/
          var reg2 = /^\d{1,2}(\-|\/|\.)\d{4}\1\d{1,2}$/
       } else { // The year must be third
          var reg1 = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{2}$/
          var reg2 = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/
       }
       // If it doesn't conform to the right format (with either a 2 digit year or 4 digit year), fail
       if ( (reg1.test(dateStr) == false) && (reg2.test(dateStr) == false) ) { return false; }
       var parts = dateStr.split(RegExp.$1); // Split into 3 parts based on what the divider was
       // Check to see if the 3 parts end up making a valid date
       if (format.substring(0, 1) == "M") { var mm = parts[0]; } else 
          if (format.substring(1, 2) == "M") { var mm = parts[1]; } else { var mm = parts[2]; }
       if (format.substring(0, 1) == "D") { var dd = parts[0]; } else 
          if (format.substring(1, 2) == "D") { var dd = parts[1]; } else { var dd = parts[2]; }
       if (format.substring(0, 1) == "Y") { var yy = parts[0]; } else 
          if (format.substring(1, 2) == "Y") { var yy = parts[1]; } else { var yy = parts[2]; }
       if (parseFloat(yy) <= 50) { yy = (parseFloat(yy) + 2000).toString(); }
       if (parseFloat(yy) <= 99) { yy = (parseFloat(yy) + 1900).toString(); }
       var dt = new Date(parseFloat(yy), parseFloat(mm)-1, parseFloat(dd), 0, 0, 0, 0);
       if (parseFloat(dd) != dt.getDate()) { return false; }
       if (parseFloat(mm)-1 != dt.getMonth()) { return false; }
       return true;
    },
    IsEmail:function (strInput) {
        var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
        return regex.test(strInput);
    }
}
);

if (window.addEventListener)
/** DOMMouseScroll is for mozilla. */
	window.addEventListener('DOMMouseScroll', window.Page.StopScroll, false);
/** IE/Opera. */
window.onmousewheel = document.onmousewheel = window.Page.StopScroll;
window.onclick = document.onclick = window.Page.StopScroll;
window.onkeydown = document.onkeydown = window.Page.StopScroll;
window.onmousedown = document.onmousedown = window.Page.StopScroll;
// Object Currency
var ObjCurrency = 
{   
    CurName:"EUR",
    CurRate:1,
    ChangeCurrencyInTag : function(tag)
    {
        var tags = $T(tag);
        for (var i=0;i<tags.length;i++)
        {
            if ($(tags[i]).GetData('type')=='Cur')
            {
                var result = Math.round(parseFloat($(tags[i]).GetData("eur"))*_arrCR[ObjCurrency.CurName]);
                if($(tags[i]).innerHTML.IsNumber()!=true) result += (" " + ObjCurrency.CurName);
                tags[i].innerHTML=result;
            }
        }
    },
    ChangeCurrency : function(num)
    {
        return Math.round(parseFloat(num*_arrCR[ObjCurrency.CurName]));
    }
   
    ,
    Update:function()
    {
        this.CurName = GetCookie("currency")==""?'EUR':Object.GetCookie("currency");
        this.CurRate = _arrCR[ObjCurrency.CurName];
    }
}

function LoadDataToCbBox(id, arr, dfvalue)
{
    var index=0;
    for(var i=0;i<arr.length;i++)
    {
        id.options[i] = new Option(arr[i][1], arr[i][0]);
        if (arr[i][0] == dfvalue)
            index = i;
    }
    id.selectedIndex = index;
}
// It 's used for currency
function LoadCurToCbBox(id, arr, dfvalue)
{
    var index=0;
    for(var i=0;i<arr.length;i++)
    {
        id.options[i] = new Option(arr[i], arr[i]);
        if (arr[i] == dfvalue)
            index=i;
    }
    id.selectedIndex = index;
}
function LoadMonth(ddl, dfvalue)
{
    ddl.length = _months.length;
    var index = 0;
    for(var i=0;i<_months.length;i++)
    {
		if(i==0)
            ddl.options[i] = new Option(_months[i][2], _months[i][0] + "-" + _months[i][1]);
        else
            ddl.options[i] = new Option(_months[i][2] + ", " + _months[i][0], _months[i][0] + "-" + _months[i][1]);
        if (ddl.options[i].value == dfvalue)
            index = i;
    }
    ddl.selectedIndex = index;
}
function ChangeCurrency(rate, tagnames)
{
    var fares = document.getElementsByName(tagnames);
    var tmpfare = 0;
    for (var i=0;i<fares.length;i++)
    {
        fares[i].innerHTML=Math.round(parseFloat(fares[i].innerHTML)*ObjCurrency.CurRate)+ " " + ObjCurrency.CurName;
    }
}

function thisMovie(movieName)
{
	if (window.document[movieName]) 
	{
	  return window.document[movieName];
	}
	if (navigator.appName.indexOf("Microsoft Internet")==-1)
	{
	if (document.embeds && document.embeds[movieName])
	  return document.embeds[movieName]; 
	}
	else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
	{
	return document.getElementById(movieName);
	}
}

function TransparentPNG()
{
	var arVersion = navigator.appVersion.split("MSIE")
	var version = parseFloat(arVersion[1])

	if ((version >= 5.5) && (document.body.filters)) 
	{
	   for(var i=0; i<document.images.length; i++)
	   {
		  var img = document.images[i]
		  var imgName = img.src.toUpperCase()
		  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
		  {
			 var imgID = (img.id) ? "id='" + img.id + "' " : ""
			 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
			 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
			 var imgStyle = "display:inline-block;" + img.style.cssText 
			 if (img.align == "left") imgStyle = "float:left;" + imgStyle
			 if (img.align == "right") imgStyle = "float:right;" + imgStyle
			 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
			 var strNewHTML = "<span " + imgID + imgClass + imgTitle
			 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
			 + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			 + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
			 img.outerHTML = strNewHTML
			 i = i-1
		  }
	   }
	}
}

// email validation
function IsValidEmailAddress(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
	    return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	    return false
	 }
	
	 if (str.indexOf(" ")!=-1){
	    return false
	 }

	 return true					
}
function bookmark(title, url)
{
  if (window.sidebar) // firefox
  {
     window.sidebar.addPanel(title, url, "");
  }
  else if (window.opera && window.print) // opera
  {
     var element = document.createElement("a");
     element.setAttribute("href", url);
     element.setAttribute("title", title);
     element.setAttribute("rel", "sidebar");
     element.click();
  } 
  else if (document.all) // ie
  {
     window.external.AddFavorite(url, title);
  }
}

function GetDomain(str)
{
	if (str == null || str.length == 0)
	return "";
	
	str = str.toLowerCase();
	var i = str.indexOf("//");
	if(i>-1)
	{
		str = str.substring(i+2, str.length);
	}
	
	i = str.indexOf("/");
	if(i>-1)
	{
		str = str.substring(0, i);
	}
	
	if(str.indexOf("www.") == 0)
		str = str.replace("www.", "");
	
	return str;
}
//handler for master page: search pane, menubar, lanuagebar, header, footer,..
var MasterStartUp=new Array();
var MasterPageHandler = 
{
    HandleShowSearchForm:function(isShow)
    {
        $(MasterPageEleNames.SearchFormContainerID1).SetVisible(isShow);
        $(MasterPageEleNames.SearchFormContainerID2).SetVisible(isShow);
           
    }
    ,
    HandleSearchFormChoose : function(ChooseLeft)
    {
        var div01 = $(MasterPageEleNames.TabTitleName01);
        var div02 = $(MasterPageEleNames.TabTitleName02);

        var SearchForm01 = $(MasterPageEleNames.SearchFormContainerID1);
        var SearchForm02 = $(MasterPageEleNames.SearchFormContainerID2);
        var hdActiveForm = $(MasterPageEleNames.HDActivatingSearchFormID);

        if(ChooseLeft)
        {
           new Number(1).SetCookie(MasterPageCookieKeys.ActiveForm);
           hdActiveForm.value = 1;
           SearchForm01.Show();
           SearchForm02.Hide();
           div01.SetClass(MasterPageConfig.SearchTitleSelectedStyle);
           div02.SetClass(MasterPageConfig.SearchTitleNormalStyle);
           window.Page.SwitchPageStyle(MasterPageConfig.Theme01Title);
           $(SearchByDayHeaderControlEleNames.ApfromTextField).Focus();
        }
        else
        {
           new Number(2).SetCookie(MasterPageCookieKeys.ActiveForm);
           hdActiveForm.value=2;
           SearchForm01.Hide();
           SearchForm02.Show();
           div01.SetClass(MasterPageConfig.SearchTitleNormalStyle);
           div02.SetClass(MasterPageConfig.SearchTitleSelectedStyle);
           window.Page.SwitchPageStyle(MasterPageConfig.Theme02Title);
           $(SG_Elements.txtApfrom).Focus();
        }
    },
    HideSearchFlow : function()
    {
        $(MasterPageEleNames.SearchFlowContainer).Hide();
    },
    ShowSearchFlow : function()
    {
        $(MasterPageEleNames.SearchFlowContainer).Show();
    },
    HighLightFinalFlow: function()
    {
        if($$(MasterPageEleNames.SearchFlow04))
        {
            $(MasterPageEleNames.SearchFlow04).SetClass(MasterPageConfig.SearchFlowHighLighStyle);
            $(MasterPageEleNames.SearchFlow03).SetClass(MasterPageConfig.SearchFlowCompletedStyle);
        }
    },
    SetFocus:function()
    {
        if($(MasterPageEleNames.SearchFormContainerID1).style.display=="none")
            FlightSearchGraphPanelHandler.Focus();
        else
            FlightSearchPanelHandler.Focus();
    }
    ,
    RegisEleEvt:function()
    {
		document.onkeypress=function(ev)
		{
			var key = (window.event) ? window.event.keyCode : ev.keyCode;
			if(key==27)
			{
				if(typeof(ResultPageHdl) != "undefined")
					ResultPageHdl.HidePopup();
				if(typeof(MultiDestSearchPanelHandler) != "undefined")
					MultiDestSearchPanelHandler.Hide();
				if(typeof(hotelManager) != "undefined")
					hotelManager.HidePopup();
			}
		}
    },
    StartUp:function()
    {        
        MasterPageHandler.RegisEleEvt();
    },
    AddStartUp:function(functionName)
    {
        MasterStartUp.push(functionName);
    },
    GlobalStartUp:function()
    {
        for(var i=0;i<MasterStartUp.length;i++)
        {	
            eval(MasterStartUp[i]);
        }
    }
};

MasterPageHandler.AddStartUp("MasterPageHandler.StartUp()");
var Url = {
 
	// 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;
	}
 
}
 
function actb(obj, ca, callerwidth, pMaskID, url, target)
{
	/* ---- Public Variables ---- */
//	if(obj.offsetWidth != 0)
//		actb.prototype.actbWidth = obj.offsetWidth;
	this.actbWidth = obj.offsetWidth;
	if(typeof(this.actbWidth)=="string")
		this.actbWidth = this.actbWidth.replace("px","");
	this.MaskID = pMaskID;
	this.actb_timeOut = -1; // Autocomplete Timeout in ms (-1: autocomplete never time out)
	this.actb_lim = 10;    // Number of elements autocomplete can show (-1: no limit)
	this.actb_firstText = false; // should the auto complete be limited to the beginning of keyword?
	this.actb_mouse = true; // Enable Mouse Support
	this.actb_delimiter = new Array();  // Delimiter for multiple autocomplete. Set it to empty array for single autocomplete
	this.actb_startcheck = 1; // Show widget only after this number of characters is typed in.
	this.actb_http = new AjaxUtil();
	this.actb_keywords = new Array();
	this.actb_target = target;
	this.actb_tabname = "tat_table_" + target;
	this.actb_pos = 0;
	/* ---- Public Variables ---- */

	/* --- Styles --- */
	this.actb_bgColor = '#ffffff';
	this.actb_textColor = '#565656';
	this.actb_hColor = '#cecece';
	this.actb_fFamily = 'Verdana';
	this.actb_fSize = '11px';
	this.actb_hStyle = 'color:#35899c;font-weight:bold;font-size:11px;';
	/* --- Styles --- */

	/* ---- Private Variables ---- */
	var actb_delimwords = new Array();
	var actb_cdelimword = 0;
	var actb_delimchar = new Array();
	var actb_display = false;
	//var actb_pos = 0;
	var actb_total = 0;
	var actb_curr = null;
	var actb_rangeu = 0;
	var actb_ranged = 0;
	var actb_bool = new Array();
	var actb_pre = 0;
	var actb_toid;
	var actb_tomake = false;
	var actb_getpre = "";
	var actb_mouse_on_list = 1;
	var actb_kwcount = 0;
	var actb_caretmove = false;
	var actb_oldword = "";
	var actb_url = url;
	/* ---- Private Variables---- */
	
	//this.actb_keywords = ca;
	var actb_self = this;

	actb_curr = obj;
	
	addEvent(actb_curr,"focus",actb_setup);
	function actb_setup()
	{
		addEvent(document,"keydown",actb_checkkey);
		addEvent(actb_curr,"blur",actb_clear);
		addEvent(document,"keypress",actb_keypress);
	}

	function actb_clear(evt)
	{
		//return;
		if (!evt) evt = event;
		removeEvent(document,"keydown",actb_checkkey);
		removeEvent(actb_curr,"blur",actb_clear);
		removeEvent(document,"keypress",actb_keypress);
		actb_removedisp();
	}
	function actb_parse(n){
		if (actb_self.actb_delimiter.length > 0){
			var t = actb_delimwords[actb_cdelimword].trim().addslashes();
			var plen = actb_delimwords[actb_cdelimword].trim().length;
		}else{
			var t = actb_curr.value.addslashes();
			var plen = actb_curr.value.length;
		}
		var tobuild = '';
		var i;

		if (actb_self.actb_firstText){
			var re = new RegExp("^" + t, "i");
		}else{
			var re = new RegExp(t, "i");
		}
		var p = n.search(re);
				
		for (i=0;i<p;i++){
			tobuild += n.substr(i,1);
		}
		tobuild += "<font style='"+(actb_self.actb_hStyle)+"'>"
		for (i=p;i<plen+p;i++){
			tobuild += n.substr(i,1);
		}
		tobuild += "</font>";
			for (i=plen+p;i<n.length;i++){
			tobuild += n.substr(i,1);
		}
		
		var arrKeys = tobuild.split(',');
		var sCityAirport = "";
		for(var k=0; k<arrKeys.length-1; k++)
		{
			if(k<arrKeys.length-2)
				sCityAirport += arrKeys[k] + ', ';
			else
				sCityAirport += arrKeys[k];
		}
		var sCountry = arrKeys[arrKeys.length-1];
		
		tobuild = '<span style="float:left;width:70%">' + sCityAirport + '</span>' + '<span style="float:right;width:30%; text-align:right">' + sCountry + '</span>';
		
		return tobuild;
	}
	function showCompleteMask()
	{
	    var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
        if(!IE6)return;
        var mask = getActivingMask();
	    if(mask)
	    {
	        mask.style.display = "";
	    }
	    
	}
	function getActivingMask()
	{
        if(actb_self.MaskID == "") return null;
	    var mask = document.getElementById(actb_self.MaskID);
	    return mask
	}
	
	function hideCompleteMask()
	{
//	    var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
//        if(!IE6)return;
	    var mask = getActivingMask();
	    if(mask != null)
	    {
	        mask.style.display = "none";
	    }
	}
	function actb_generate(){
		// check if obj lost focus (blur)
		switch(actb_self.actb_target)
		{
			case "hotel":
				if(!HotelSearchPanelHandler.IsFocusCity)
				{
					HotelSearchPanelHandler.FillData();
					return;
				}
				break;
			case "apfrom":
				if(!FlightSearchPanelHandler.IsFocusApfrom)
				{
					FlightSearchPanelHandler.FillData("from");
					return;
				}
				break;
			case "apto":
				if(!FlightSearchPanelHandler.IsFocusApto)
				{
					FlightSearchPanelHandler.FillData("to");
					return;
				}
				break;
			case "apifrom":
				if(!API_RegisterHdl.IsFocusApfrom)
				{
					API_RegisterHdl.FillData("from");
					return;
				}
				break;
			case "apito":
				if(!API_RegisterHdl.IsFocusApto)
				{
					API_RegisterHdl.FillData("to");
					return;
				}
				break;
			case "fa_from":
				if(!FareAlertHandler.IsFocusApfrom)
				{
					FareAlertHandler.FillData("from");
					return;
				}
				break;
			case "fa_to":
				if(!FareAlertHandler.IsFocusApto)
				{
					FareAlertHandler.FillData("to");
					return;
				}
				break;
		}
		
		// multi destinations
		var sIndex = actb_self.actb_target[actb_self.actb_target.length - 1];
		var sTarget = actb_self.actb_target.substring(0, actb_self.actb_target.length - 1);
		if(!isNaN(parseInt(sIndex)))
		{
			var index = parseInt(sIndex);
			if((sTarget == "apfrom") && (MultiDestSearchPanelHandler.FocusFrom[index - 1] == false))
			{
				MultiDestSearchPanelHandler.FillData(sTarget, parseInt(sIndex));
				return;
			}
			if((sTarget == "apto") && (MultiDestSearchPanelHandler.FocusTo[index - 1] == false))
			{
				MultiDestSearchPanelHandler.FillData(sTarget, parseInt(sIndex));
				return;
			}
		}
		/////////////////////
		
	    showCompleteMask();
		if (document.getElementById(actb_self.actb_tabname))
		{ 
			actb_display = false;
			document.body.removeChild(document.getElementById(actb_self.actb_tabname));
		} 
		if (actb_kwcount == 0)
		{
			actb_display = false;
			return;
		}
		var a = document.createElement('table');
		a.width = actb_self.actbWidth+"px";
		a.cellSpacing='1px';
		a.cellPadding='2px';
		a.style.position='absolute';
		a.style.top = eval(curTop(actb_curr) + actb_curr.offsetHeight) + "px";
		a.style.left = curLeft(actb_curr) + "px";
		a.style.textAlign = "left";
		//if(document.all)
		//a.style.width = "360px";
		//else
		//a.style.width = "325px";
		
		a.style.border = "1px solid #999999";
		//a.style.whitespace: "nowrap";
		a.style.backgroundColor=actb_self.actb_bgColor;
		a.style.zIndex = "99999";
		a.id = actb_self.actb_tabname;
		
		if (navigator.appName.indexOf('Microsoft') == -1){document.body.appendChild(a);}
		else {document.body.insertBefore(a, document.body.firstChild);}
		var i;
		var first = true;
		var j = 1;
		if (actb_self.actb_mouse){
			a.onmouseout = actb_table_unfocus;
			a.onmouseover = actb_table_focus;
		}
		var counter = 0;
		for (i=0;i<actb_self.actb_keywords.length;i++){
			if (actb_bool[i]){
				counter++;
				r = a.insertRow(-1);
				if (first && !actb_tomake){
					r.style.backgroundColor = actb_self.actb_hColor;
					first = false;
					actb_self.actb_pos = counter;
				}else if(actb_pre == i){
					r.style.backgroundColor = actb_self.actb_hColor;
					first = false;
					actb_self.actb_pos = counter;
				}else{
					r.style.backgroundColor = actb_self.actb_bgColor;
				}
				r.id = 'tat_tr'+(j);
				c = r.insertCell(-1);
				c.style.color = actb_self.actb_textColor;
				c.style.fontFamily = actb_self.actb_fFamily;
				c.style.fontSize = actb_self.actb_fSize;
				// inner HTML here
				c.innerHTML = actb_parse(actb_self.actb_keywords[i]);
				c.id = 'tat_td'+(j);
				c.setAttribute('pos',j);
				if (actb_self.actb_mouse){
					c.style.cursor = 'pointer';
					c.onclick=actb_mouseclick;
					c.onmouseover = actb_table_highlight;
				}
				j++;
			}
			
			if (j - 1 == actb_self.actb_lim && j < actb_total)
			{
				r = a.insertRow(-1);
				r.style.backgroundColor = actb_self.actb_bgColor;
				c = r.insertCell(-1);
				c.style.backgroundColor = "#f2f2f2";
			    c.style.color = "Gray";
			    c.style.fontFamily = 'arial narrow';
			    c.style.fontSize = actb_self.actb_fSize;
			    c.align='center';
			    //replaceHTML(c,'\\/');
			    //replaceHTML(c,);
			    c.innerHTML = '&#9660;';
				if (actb_self.actb_mouse){
					c.style.cursor = 'pointer';
					c.onclick = actb_mouse_down;
				}
				break;
			}
		}
		actb_rangeu = 1;
		actb_ranged = j-1;
		actb_display = true;
		if (actb_self.actb_pos <= 0) actb_self.actb_pos = 1;
	}
	function actb_remake(){
		if(document.getElementById(actb_self.actb_tabname)!=null)
			document.body.removeChild(document.getElementById(actb_self.actb_tabname));
		var a = document.createElement('table');
		a.cellSpacing='1px';
		a.cellPadding='2px';
		a.style.position='absolute';
		a.style.top = eval(curTop(actb_curr) + actb_curr.offsetHeight) + "px";
		a.style.left = curLeft(actb_curr) + "px";
		a.style.textAlign = "left";
//		if(document.all)
//		a.style.width = "360px";
//		else
//		a.style.width = "325px";
        a.style.width = actb_self.actbWidth + "px";
		a.style.border = "1px solid #999999";
		a.style.backgroundColor=actb_self.actb_bgColor;
		a.style.zIndex = "99999";
		a.id = actb_self.actb_tabname;
		
		if (actb_self.actb_mouse){
			a.onmouseout= actb_table_unfocus;
			a.onmouseover=actb_table_focus;
		}
		if (navigator.appName.indexOf('Microsoft') == -1){document.body.appendChild(a);}
		else {document.body.insertBefore(a, document.body.firstChild);}
		var i;
		var first = true;
		var j = 1;
		if (actb_rangeu > 1){
			r = a.insertRow(-1);
			r.style.backgroundColor = actb_self.actb_bgColor;
			c = r.insertCell(-1);
			c.style.backgroundColor = "#f2f2f2";
			c.style.color = "Gray";
			c.style.fontFamily = 'arial narrow';
			c.style.fontSize = actb_self.actb_fSize;
			c.align='center';
			//replaceHTML(c,'/\\');
			c.innerHTML = "&#9650;";
			if (actb_self.actb_mouse){
				c.style.cursor = 'pointer';
				c.onclick = actb_mouse_up;
			}
		}
		for (i=0;i<actb_self.actb_keywords.length;i++){
			if (actb_bool[i]){
				if (j >= actb_rangeu && j <= actb_ranged){
					r = a.insertRow(-1);
					r.style.backgroundColor = actb_self.actb_bgColor;
					r.id = 'tat_tr'+(j);
					c = r.insertCell(-1);
					c.style.color = actb_self.actb_textColor;
					c.style.fontFamily = actb_self.actb_fFamily;
					c.style.fontSize = actb_self.actb_fSize;
					// inner HTML here
					c.innerHTML = actb_parse(actb_self.actb_keywords[i]);
					c.id = 'tat_td'+(j);
					c.setAttribute('pos',j);
					if (actb_self.actb_mouse){
						c.style.cursor = 'pointer';
						c.onclick=actb_mouseclick;
						c.onmouseover = actb_table_highlight;
					}
					j++;
				}else{
					j++;
				}
			}
			if (j > actb_ranged) break;
		}
		if (j-1 < actb_total){
			r = a.insertRow(-1);
			r.style.backgroundColor = actb_self.actb_bgColor;
			c = r.insertCell(-1);
			c.style.backgroundColor = "#f2f2f2";
			c.style.color = "Gray";
			c.style.fontFamily = 'arial narrow';
			c.style.fontSize = actb_self.actb_fSize;
			c.align='center';
			//replaceHTML(c,'\\/');
			c.innerHTML = '&#9660;';
			if (actb_self.actb_mouse){
				c.style.cursor = 'pointer';
				c.onclick = actb_mouse_down;
			}
		}
	}
	function actb_goup(){
		if (!actb_display) return;
		if (actb_self.actb_pos == 1) return;
		if(document.getElementById('tat_tr'+actb_self.actb_pos)==null) return;
		document.getElementById('tat_tr'+actb_self.actb_pos).style.backgroundColor = actb_self.actb_bgColor;
		actb_self.actb_pos--;
		if (actb_self.actb_pos < actb_rangeu) actb_moveup();
		document.getElementById('tat_tr'+actb_self.actb_pos).style.backgroundColor = actb_self.actb_hColor;
		if (actb_toid) clearTimeout(actb_toid);
		if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list=0;actb_removedisp();},actb_self.actb_timeOut);
	}
	function actb_godown(){
		if (!actb_display) return;
		if (actb_self.actb_pos >= actb_total) return;
		if(document.getElementById('tat_tr'+actb_self.actb_pos)==null) return;
		document.getElementById('tat_tr'+actb_self.actb_pos).style.backgroundColor = actb_self.actb_bgColor;
		actb_self.actb_pos++;
		if (actb_self.actb_pos > actb_ranged) actb_movedown();
		document.getElementById('tat_tr'+actb_self.actb_pos).style.backgroundColor = actb_self.actb_hColor;
		if (actb_toid) clearTimeout(actb_toid);
		if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list=0;actb_removedisp();},actb_self.actb_timeOut);
	}
	function actb_movedown(){
		actb_rangeu++;
		actb_ranged++;
		actb_remake();
	}
	function actb_moveup(){
		actb_rangeu--;
		actb_ranged--;
		actb_remake();
	}

	/* Mouse */
	function actb_mouse_down(){
		document.getElementById('tat_tr'+actb_self.actb_pos).style.backgroundColor = actb_self.actb_bgColor;
		actb_self.actb_pos++;
		actb_movedown();
		document.getElementById('tat_tr'+actb_self.actb_pos).style.backgroundColor = actb_self.actb_hColor;
		actb_curr.focus();
		actb_mouse_on_list = 0;
		if (actb_toid) clearTimeout(actb_toid);
		if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list=0;actb_removedisp();},actb_self.actb_timeOut);
		
	}
	function actb_mouse_up(evt){
	    
		if (!evt) evt = event;
		if (evt.stopPropagation){
			evt.stopPropagation();
		}else{
			evt.cancelBubble = true;
		}
		document.getElementById('tat_tr'+actb_self.actb_pos).style.backgroundColor = actb_self.actb_bgColor;
		actb_self.actb_pos--;
		actb_moveup();
		document.getElementById('tat_tr'+actb_self.actb_pos).style.backgroundColor = actb_self.actb_hColor;
		actb_curr.focus();
		actb_mouse_on_list = 0;
		if (actb_toid) clearTimeout(actb_toid);
		if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list=0;actb_removedisp();},actb_self.actb_timeOut);
		//
	}
	function actb_mouseclick(evt){
		
		if (!evt) evt = event;
		if (!actb_display) return;
		actb_mouse_on_list = 0;
		actb_self.actb_pos = this.getAttribute('pos');
		actb_penter();
		
	}
	function actb_table_focus(){
		actb_mouse_on_list = 1;
	}
	function actb_table_unfocus(){
		actb_mouse_on_list = 0;
		if (actb_toid) clearTimeout(actb_toid);
		if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list = 0;actb_removedisp();},actb_self.actb_timeOut);
	}
	function actb_table_highlight(){
		actb_mouse_on_list = 1;
		document.getElementById('tat_tr'+actb_self.actb_pos).style.backgroundColor = actb_self.actb_bgColor;
		actb_self.actb_pos = this.getAttribute('pos');
		while (actb_self.actb_pos < actb_rangeu) actb_moveup();
		while (actb_self.actb_pos > actb_ranged) actb_movedown();
		document.getElementById('tat_tr'+actb_self.actb_pos).style.backgroundColor = actb_self.actb_hColor;
		if (actb_toid) clearTimeout(actb_toid);
		if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list = 0;actb_removedisp();},actb_self.actb_timeOut);
	}
	/* ---- */

	function actb_insertword(a){
		if (actb_self.actb_delimiter.length > 0){
			str = '';
			l=0;
			for (i=0;i<actb_delimwords.length;i++){
				if (actb_cdelimword == i){
					prespace = postspace = '';
					gotbreak = false;
					for (j=0;j<actb_delimwords[i].length;++j){
						if (actb_delimwords[i].charAt(j) != ' '){
							gotbreak = true;
							break;
						}
						prespace += ' ';
					}
					for (j=actb_delimwords[i].length-1;j>=0;--j){
						if (actb_delimwords[i].charAt(j) != ' ') break;
						postspace += ' ';
					}
					str += prespace;
					str += a;
					l = str.length;
					if (gotbreak) str += postspace;
				}else{
					str += actb_delimwords[i];
				}
				if (i != actb_delimwords.length - 1){
					str += actb_delimchar[i];
				}
			}
			actb_curr.value = str;
			setCaret(actb_curr,l);
		}else{
			if(a.indexOf(" - ")==0)
				actb_curr.value = a.replace(" - ", "");
			else
				actb_curr.value = a
		}
		actb_mouse_on_list = 0;
		actb_removedisp();
	}
	function actb_penter(){
		if (!actb_display) return;
		actb_display = false;
		var word = '';
		var c = 0;
		for (var i=0;i<=actb_self.actb_keywords.length;i++){
			if (actb_bool[i]) c++;
			if (c == actb_self.actb_pos){
				word = actb_self.actb_keywords[i];
				break;
			}
		}
		actb_insertword(word);
		l = getCaretStart(actb_curr);
	}
	function actb_removedisp(){
		if (actb_mouse_on_list==0)
		{
			actb_display = 0;
			if (document.getElementById(actb_self.actb_tabname))
			{ 
				setTimeout("document.body.removeChild(document.getElementById('" + actb_self.actb_tabname + "'))", 100);
				hideCompleteMask();
			}
			if (actb_toid) clearTimeout(actb_toid);
		}
	}
	function actb_keypress(e){
		if (actb_caretmove) stopEvent(e);
		return !actb_caretmove;
	}
	function actb_checkkey(evt){
		if (!evt) evt = event;
		
		var a = evt.keyCode;
		
		if(a==20 || a==16 || a==17 || a==18) return;
		caret_pos_start = getCaretStart(actb_curr);
		actb_caretmove = false;
		switch (a){
			case 38:
				actb_goup();
				actb_caretmove = true;
				//alert(caret_pos_start);
				return false;
				break;
			case 40:
				actb_godown();
				actb_caretmove = true;
				return false;
				break;
			case 27:
				hideCompleteMask();
//				break;
			case 9: // TAB
				hideCompleteMask();
				break;
			case 13: // ENTER
				if (actb_display){
					actb_caretmove = true;
					actb_penter();
					return false;
				}else{
					return true;
				}
				break;
			default:
				setTimeout(function(){actb_request(a)},50);
				
				break;
		}
	}
	
	function actb_request(kc)
	{
		if (kc == 38 || kc == 40 || kc == 13)
		{	
			return;
		}
		if(actb_curr.value.length < 3)
		{
			return;
		}
//		if((kc == 65) && (actb_curr.value[actb_curr.value.length-1] != 'a' || actb_curr.value[actb_curr.value.length-1] != 'A'))
//		{alert(actb_curr.value[actb_curr.value.length-1]);  return;}
		
		var newword = actb_curr.value.substring(0, 3);
		newword = newword.toUpperCase();
		newword = Url.encode(newword);
		if (actb_oldword == newword)
		{
			actb_tocomplete(null);
		}
		else
		{
			// reset
			actb_self.actb_keywords = new Array();
			
			// make ajax request
			actb_self.actb_http.Load(actb_url + newword, actb_tocomplete, null);
			actb_oldword = newword;
		}
	}
	
	function actb_tocomplete(data){
//		actb_self.actb_keywords = _atc;
		if(data != null)
			actb_self.actb_keywords = eval(data);
		//alert(actb_self.actb_keywords.Data);
		var i;
		if (actb_display){ 
			var word = 0;
			var c = 0;
			for (var i=0;i<=actb_self.actb_keywords.length;i++){
				if (actb_bool[i]) c++;
				if (c == actb_self.actb_pos){
					word = i;
					break;
				}
			}
			actb_pre = word;
		}else{ actb_pre = -1};
		
		if (actb_curr.value == ''){
			actb_mouse_on_list = 0;
			actb_removedisp();
			return;
		}
		if (actb_self.actb_delimiter.length > 0){
			caret_pos_start = getCaretStart(actb_curr);
			caret_pos_end = getCaretEnd(actb_curr);
			
			delim_split = '';
			for (i=0;i<actb_self.actb_delimiter.length;i++){
				delim_split += actb_self.actb_delimiter[i];
			}
			delim_split = delim_split.addslashes();
			delim_split_rx = new RegExp("(["+delim_split+"])");
			c = 0;
			actb_delimwords = new Array();
			actb_delimwords[0] = '';
			for (i=0,j=actb_curr.value.length;i<actb_curr.value.length;i++,j--){
				if (actb_curr.value.substr(i,j).search(delim_split_rx) == 0){
					ma = actb_curr.value.substr(i,j).match(delim_split_rx);
					actb_delimchar[c] = ma[1];
					c++;
					actb_delimwords[c] = '';
				}else{
					actb_delimwords[c] += actb_curr.value.charAt(i);
				}
			}

			var l = 0;
			actb_cdelimword = -1;
			for (i=0;i<actb_delimwords.length;i++){
				if (caret_pos_end >= l && caret_pos_end <= l + actb_delimwords[i].length){
					actb_cdelimword = i;
				}
				l+=actb_delimwords[i].length + 1;
			}
			var ot = actb_delimwords[actb_cdelimword].trim(); 
			var t = actb_delimwords[actb_cdelimword].addslashes().trim();
		}else{
			var ot = actb_curr.value;
			var t = actb_curr.value.addslashes();
		}
		if (ot.length == 0){
			actb_mouse_on_list = 0;
			actb_removedisp();
		}
		if (ot.length < actb_self.actb_startcheck) return this;
		if (actb_self.actb_firstText){
			var re = new RegExp("^" + t, "i");
		}else{
			var re = new RegExp(t, "i");
		}

		actb_total = 0;
		actb_tomake = false;
		actb_kwcount = 0;
		for (i=0;i<actb_self.actb_keywords.length;i++){
			actb_bool[i] = false;
			if (re.test(actb_self.actb_keywords[i])){
				actb_total++;
				actb_bool[i] = true;
				actb_kwcount++;
				if (actb_pre == i) actb_tomake = true;
			}
		}

		if (actb_toid) clearTimeout(actb_toid);
		if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list = 0;actb_removedisp();},actb_self.actb_timeOut);
		actb_generate();
		
		if(actb_total==0) hideCompleteMask();
	}
	return this;
}

/* Event Functions */

// Add an event to the obj given
// event_name refers to the event trigger, without the "on", like click or mouseover
// func_name refers to the function callback when event is triggered
function addEvent(obj,event_name,func_name){
	if (obj.attachEvent){
		obj.attachEvent("on"+event_name, func_name);
	}else if(obj.addEventListener){
		obj.addEventListener(event_name,func_name,true);
	}else{
		obj["on"+event_name] = func_name;
	}
}

// Removes an event from the object
function removeEvent(obj,event_name,func_name){
	if (obj.detachEvent){
		obj.detachEvent("on"+event_name,func_name);
	}else if(obj.removeEventListener){
		obj.removeEventListener(event_name,func_name,true);
	}else{
		obj["on"+event_name] = null;
	}
}

// Stop an event from bubbling up the event DOM
function stopEvent(evt){
	evt || window.event;
	if (evt.stopPropagation){
		evt.stopPropagation();
		evt.preventDefault();
	}else if(typeof evt.cancelBubble != "undefined"){
		evt.cancelBubble = true;
		evt.returnValue = false;
	}
	return false;
}

// Get the obj that starts the event
function getElement(evt){
	if (window.event){
		return window.event.srcElement;
	}else{
		return evt.currentTarget;
	}
}
// Get the obj that triggers off the event
function getTargetElement(evt){
	if (window.event){
		return window.event.srcElement;
	}else{
		return evt.target;
	}
}
// For IE only, stops the obj from being selected
function stopSelect(obj){
	if (typeof obj.onselectstart != 'undefined'){
		addEvent(obj,"selectstart",function(){ return false;});
	}
}

/*    Caret Functions     */

// Get the end position of the caret in the object. Note that the obj needs to be in focus first
function getCaretEnd(obj){
	if(typeof obj.selectionEnd != "undefined"){
		return obj.selectionEnd;
	}else if(document.selection&&document.selection.createRange){
		var M=document.selection.createRange();
		try{
			var Lp = M.duplicate();
			Lp.moveToElementText(obj);
		}catch(e){
			var Lp=obj.createTextRange();
		}
		Lp.setEndPoint("EndToEnd",M);
		var rb=Lp.text.length;
		if(rb>obj.value.length){
			return -1;
		}
		return rb;
	}
}
// Get the start position of the caret in the object
function getCaretStart(obj){
	if(typeof obj.selectionStart != "undefined"){
		return obj.selectionStart;
	}else if(document.selection&&document.selection.createRange){
		var M=document.selection.createRange();
		try{
			var Lp = M.duplicate();
			Lp.moveToElementText(obj);
		}catch(e){
			var Lp=obj.createTextRange();
		}
		try
		{
			Lp.setEndPoint("EndToStart",M);
		}
		catch(e)
		{}
		var rb=Lp.text.length;
		if(rb>obj.value.length){
			return -1;
		}
		return rb;
	}
}
// sets the caret position to l in the object
function setCaret(obj,l){
	obj.focus();
	if (obj.setSelectionRange){
		obj.setSelectionRange(l,l);
	}else if(obj.createTextRange){
		m = obj.createTextRange();		
		m.moveStart('character',l);
		m.collapse();
		m.select();
	}
}
// sets the caret selection from s to e in the object
function setSelection(obj,s,e){
	obj.focus();
	if (obj.setSelectionRange){
		obj.setSelectionRange(s,e);
	}else if(obj.createTextRange){
		m = obj.createTextRange();		
		m.moveStart('character',s);
		m.moveEnd('character',e);
		m.select();
	}
}

/*    Escape function   */
String.prototype.addslashes = function(){
	return this.replace(/(["\\\.\|\[\]\^\*\+\?\$\(\)])/g, '\\$1');
}
String.prototype.trim = function () {
    return this.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
};
/* --- Escape --- */

/* Offset position from top of the screen */
function curTop(obj){
	toreturn = 0;
	while(obj){
		toreturn += obj.offsetTop;
		obj = obj.offsetParent;
	}
	return toreturn;
}
function curLeft(obj){
	toreturn = 0;
	while(obj){
		toreturn += obj.offsetLeft;
		obj = obj.offsetParent;
	}
	return toreturn;
}
/* ------ End of Offset function ------- */

/* Types Function */

// is a given input a number?
function isNumber(a) {
    return typeof a == 'number' && isFinite(a);
}

/* Object Functions */

function replaceHTML(obj,text)
{
	while(el = obj.childNodes[0])
	{
		obj.removeChild(el);
	};
	obj.appendChild(document.createTextNode(text));
}
