function cookieObject(name, expires, accessPath) {
var i, j
this.name = name
this.fieldSeparator = "#"
this.found = false
this.expires = expires
this.accessPath = accessPath
this.rawValue = ""
this.fields = new Array()
this.fieldnames = new Array() 
if (arguments.length > 3) { // field name(s) specified
  j = 0
  for (i = 3; i < arguments.length; i++) {
    this.fieldnames[j] = arguments[i]    
    j++
  }
  this.fields.length = this.fieldnames.length 
}
this.read = ucRead

this.write = ucWrite

this.remove = ucDelete
this.get = ucFieldGet
this.put = ucFieldPut
this.namepos = ucNamePos
this.read()
}


function ucFieldGet(fieldname) {
var i = this.namepos(fieldname)
if (i >=0) {
  return this.fields[i]
} else {
  return "BadFieldName!"
}
}

function ucFieldPut (fieldname, fieldval) {
var i = this.namepos(fieldname)
if (i >=0) {
  this.fields[i] = fieldval
  return true
} else {
  return false
}
}

function ucNamePos(fieldname) {
var i 
for (i = 0; i < this.fieldnames.length; i++) {
  if (fieldname == this.fieldnames[i]) {
    return i
  }
}
return -1
}


function ucWrite() {      
  var cookietext = this.name + "=" 
if (this.fields.length == 1) {
  cookietext += escape(this.fields[0])
  } else {
    for (i= 0; i < this.fields.length; i++) {
      cookietext += escape(this.fields[i]) + this.fieldSeparator }
  }

    if (this.expires != null) {  
      if (typeof(this.expires) == "number") { 
        var today=new Date()     
        var expiredate = new Date()      
        expiredate.setTime(today.getTime() + 1000*60*60*24*this.expires)
        cookietext += "; expires=" + expiredate.toGMTString()
      } else { 
        cookietext +=  "; expires=" + this.expires.toGMTString()
      } 
    } 
   
   if (this.accessPath != null) {
   cookietext += "; PATH="+this.accessPath }
   document.cookie = cookietext 
   return null  
}


function ucRead() {
  var search = this.name + "="                       
  var CookieString = document.cookie            
  this.rawValue = null
  this.found = false     
  if (CookieString.length > 0) {                
    offset = CookieString.indexOf(search)       
    if (offset != -1) {                         
      offset += search.length                   
      end = CookieString.indexOf(";", offset)   
      if (end == -1) {
       end = CookieString.length }              
      this.rawValue = CookieString.substring(offset, end)                                   
      this.found = true 
      } 
    }
   
if (this.rawValue != null) {
  var sl = this.rawValue.length
  var startidx = 0
  var endidx = 0
  var i = 0

if (this.rawValue.substr(sl-1, 1) != this.fieldSeparator) {
  this.fields[0] = unescape(this.rawValue)
  } else {

  do  
  {
   endidx = this.rawValue.indexOf(this.fieldSeparator, startidx)
   if (endidx !=-1) {
     this.fields[i] = unescape(this.rawValue.substring(startidx, endidx))
     i++
     startidx = endidx + 1}
  }
  while (endidx !=-1 & endidx != (this.rawValue.length -1));
}
} 
  return this.found
} 


function ucDelete() {
  this.expires = -10
  this.write()
  return this.read()
}
function findCookieObject(cName, cObjArray) {

var cpointer = null, i
for (i in cObjArray) {
  if (cName == cObjArray[i].name) {
    cpointer = cObjArray[i]
  }
}
return cpointer
}


function cookieList() {
var i = 0, rawstring, offset = 0, start, newname
cpointers = new Array()
rawstring = document.cookie
if (rawstring.length > 0) {
  do {
   start = rawstring.indexOf("=", offset)
   if (start != -1) {
     newname = rawstring.substring(0, start) 
     if (offset > 0) {
       newname = newname.substring(newname.lastIndexOf(";")+2, start)
     }     
     cpointers[i] = new cookieObject(newname)
     offset = start + 1
     i++
   }
  } while (start != -1)
} 
return cpointers
} 
/*
var MWJ_img_cache = new Object();
for( var i = 0; i < 2; i++ ) {
	var ar = i ? ( document.getElementsByTagName ? document.getElementsByTagName('input') : ( document.all ? document.all.tags('INPUT') : [] ) ) : document.images;
	for( var x = 0; ar[x]; x++ ) {
		var im = ar[x];
		if( im.getAttribute ) { im.hoversrc = im.getAttribute('hoversrc'); im.activesrc = im.getAttribute('activesrc'); }
		if( im.hoversrc || im.activesrc ) {
			if( !MWJ_img_cache[im.src] ) { MWJ_img_cache[im.src] = new Image(); MWJ_img_cache[im.src].src = im.src; }
			im.rootsrc = im.src;
			im.onmouseout = function () { this.src = this.rootsrc; };
		}
		if( im.hoversrc ) {
			if( !MWJ_img_cache[im.hoversrc] ) { MWJ_img_cache[im.hoversrc] = new Image(); MWJ_img_cache[im.hoversrc].src = im.hoversrc; }
			im.onmouseover = function () { this.src = this.hoversrc; };
		}
		if( im.activesrc ) {
			if( !MWJ_img_cache[im.activesrc] ) { MWJ_img_cache[im.activesrc] = new Image(); MWJ_img_cache[im.activesrc].src = im.activesrc; }
			im.onmousedown = function (e) {
				e = e ? e : window.event;
				if( e.button > 1 || e.which > 1 ) { return; }
				this.src = this.activesrc;
			};
			im.onmouseup = function (e) {
				e = e ? e : window.event;
				if( e.button > 1 || e.which > 1 ) { return; }
				this.src = this.hoversrc ? this.hoversrc : this.rootsrc;
			};
		}
	}
}
*/
function Querystring(qs) {
	this.params = new Object()
	this.get=Querystring_get
	
	if (qs == null)
		qs=location.search.substring(1,location.search.length)

	if (qs.length == 0) return

	qs = qs.replace(/\+/g, ' ')
	var args = qs.split('&')
	
	for (var i=0;i<args.length;i++) {
		var value;
		var pair = args[i].split('=')
		var name = unescape(pair[0])

		if (pair.length == 2)
			value = unescape(pair[1])
		else
			value = name
		
		this.params[name] = value
	}
}

function Querystring_get(key, default_) {
	if (default_ == null) default_ = null;
	
	var value=this.params[key]
	if (value==null) value=default_;
	
	return value
}

/*
function OnSaveCompleted(){
    __doPostBack('','')
}
function OnSaveCompleted2(){
        __doPostBack('ctl00$lnbWeather','')
}
function OnProfileFailed(){
    alert('save failed');
}

function OnLoadCompleted(numProperties, userContext, methodName){
    var theme =  Sys.Services.ProfileService.properties.theme;
    if (theme == 'black')
        $get('imgblack').src = 'images/skin/black_skin_f2.gif';
    if (theme == 'blue')
        $get('imgblue').src = 'images/skin/blue_skin_f2.gif';
}
*/

function showHideLayers() { //v9.0
  var i,p,v,obj,args=showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function Isbrowser(){
    if (window.external.ultrabrowser != undefined || window.external.terrabrowser != undefined || window.external.pasitobrowser != undefined)
        return true;
    else
        return false;
}

var start = (new Date()).getTime();
var THRESHOLD = 7000000; // a number we will calculate below
function speedTest() {
    var duration = (new Date()).getTime() - start;
    if (duration < THRESHOLD) {
       performcheck(true); // fast connection (display flash)
    }
    else {
       performcheck(false); // slow connection (do nothing?)
    }
}

function TestBandwidth(){
    var _customize = new cookieObject("customize", 365, "/", "theme", "weather","news","IsBrowser","IsBroadBand","override","speedtest")
    if (_customize.found){
        var _TimeTested = _customize.get("speedtest") || (new Date().getTime() - (3600 * 1000));
        if (_TimeTested > (new Date().getTime()))
            performcheck((_customize.get("IsBroadBand") == 'y'?true:false));
        else {
            _customize.put("theme",_customize.get("theme"));
            _customize.put("IsBrowser",_customize.get("IsBrowser"));
            _customize.put("IsBroadBand",_customize.get("IsBroadBand"));
            _customize.put("weather",_customize.get("weather"));
            _customize.put("news",_customize.get("news"));
            _customize.put("speedtest",(new Date().getTime() + (3600 * 1000)));
            _customize.write();
            var testImage = new Image();
            testImage.onload = speedTest;
            testImage.src = "testspeed.jpg?random=" + Math.random();    
        }
    }
}
function converttftoyn(val){
    return (val == true)?'y':'n';
}