// JavaScript Document

window.onload = loadView;

function loadView() {
	if(document.cookie != undefined && document.cookie.split("menustyle=")[1] != undefined && document.getElementById("goIconMenu")) {
		//var menustyle = document.cookie.split("menustyle=")[1].split(";")[0];
		setIconMenu(document.getElementById(menustyle), "goIconMenu", true);
	}

	externalLinks();
}

// Move an element directly on top of another element (and optionally
// make it the same size)
function Cover(bottom, top, ignoreSize) {
    var location = Sys.UI.DomElement.getLocation(bottom);
    top.style.position = 'absolute';
    top.style.top = location.y + 'px';
    top.style.left = location.x + 'px';
    if (!ignoreSize) {
        top.style.height = bottom.offsetHeight + 'px';
        top.style.width = bottom.offsetWidth + 'px';
    }
}

function openChat(){
 window.open('http://extranet.allwest.net/chatsupport/chatSupportInit.jsp?cid=1', 'chat','toolbar=no,width=460,height=332,scrollbars=yes,toolbar=no,resizable=no', 'js:');
}

function toggleme(obj)
{
    if (typeof(obj) == "string")
    {
        obj = document.getElementById(obj);
    }
    if (obj != null)
    {
        if (obj.style.display == "none")
	    {
	        obj.style.display = "block";
	    }
	    else if (obj.style.display == "block")
	    {
	        obj.style.display = "none";
	    } 
	    else if (obj.className == 'hide')
	    {
	        obj.className = 'show';
	    }
	    else if (obj.className == "show")
	    {
	        obj.className = 'hide';
	    }
	}
}

function hideme(obj)
{
    if (typeof(obj) == "string")
    {
        obj = document.getElementById(obj);
    }
    if (obj != null)
    {
        if (obj.style.display == "block")
	    {
	        obj.style.display = "none";
	    } 
	    else if (obj.className == 'show')
	    {
	        obj.className = 'hide';
	    }
	}

}

function showme(obj)
{
    if (typeof(obj) == "string")
    {
        obj = document.getElementById(obj);
    }
    if (obj != null)
    {
        if (obj.style.display == "none")
	    {
	        obj.style.display = "block";
	    } 
	    else if (obj.className == 'hide')
	    {
	        obj.className = 'show';
	    }
	}
}

 //pop up function default
function openNewWindow(URLtoOpen, windowName, windowFeatures) 
{
    newWindow=window.open(URLtoOpen, windowName, windowFeatures); 
}

function Browser() {
  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));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}

var browser = new Browser();
if (browser.isNS) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;

// Temporary variables to hold mouse x-y pos.s
var tempX = 0
var tempY = 0

// Main function to retrieve mouse x-y pos.s

function getMouseXY(e) {
  if (browser.isIE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX;// + document.body.scrollLeft;
    tempY = event.clientY;// + document.body.scrollTop;
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  
  return true
}

function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5 && version < 7) && (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 
            var imgStyle = "" + 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');\" onmouseout=\"slideshowout('" + img.id + "');\"></span>" 
            img.outerHTML = strNewHTML
            i = i-1
         }
      }
   }       
}

function popvideo(file)
{
	var day = new Date();
	var id = day.getTime();
	var url = "videopopup.aspx?filename=" + file;
	eval("page" + id + " = window.open(url, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=630,height=415,left = 332.5,top = 304.5');");

}

/* Character Counter */
function charCounter(id, maxlimit) {
	if (!$('counter-' + id)) {
		$(id).insert({ after: '<div id="counter-' + id + '"></div>' });
	}

	if ($F(id).length >= maxlimit) {
		$(id).value = $F(id).substring(0, maxlimit);
		$('counter-' + id).addClassName('charcount-limit');
		$('counter-' + id).removeClassName('charcount-safe');
	}
	else {
		$('counter-' + id).removeClassName('charcount-limit');
		$('counter-' + id).addClassName('charcount-safe');
	}

	$('counter-' + id).update($F(id).length + '/' + maxlimit);
}

function makeItCount(id, maxsize) {
	if ($(id)) {
		Event.observe($(id), 'keyup', function() { charCounter(id, maxsize); }, false);
		Event.observe($(id), 'keydown', function() { charCounter(id, maxsize); }, false);
		charCounter(id, maxsize);
	}
}

/* XHTML Compliant Open Window */
function externalLinks() {
	if (typeof Prototype == 'undefined') {
		// alert('Prototype library not available');
		// Do nothing
	}
	else {
		var anchors = $$('.external');

		if (anchors) {
			for (var i = 0; i < anchors.length; i++) {
				anchors[i].target = "_blank";
			}
		}
	}
}